- pkg/database/save-event.go - Added `noVerify` parameter to `SaveEvent` function - Added check for existing event using `GetSerialById` when `noVerify` is false - Modified logic to handle event verification based on `noVerify` flag - pkg/app/relay/server-publish.go - Added `false` as third argument to `SaveEvent` calls - pkg/database/export_test.go - Added `false` as third argument to `SaveEvent` call - pkg/database/query-for-tags_test.go - Added `false` as third argument to `SaveEvent` call - pkg/database/query-for-kinds-authors_test.go - Added `false` as third argument to `SaveEvent` call - pkg/database/query-for-kinds-tags_test.go - Added `false` as third argument to `SaveEvent` call - pkg/database/query-for-serials_test.go - Added `false` as third argument to `SaveEvent` call - main.go - Modified pprof handling to support different profiling types (cpu, memory, allocation) - Changed `Pprof` configuration from boolean to string with enum values - pkg/app/config/config.go - Changed `Pprof` field type from `bool` to `string` with enum values - pkg/database/query-for-kinds-authors-tags_test.go - Added `false` as third argument to `SaveEvent` call - pkg/version/version - Bumped version from v0.2.12 to v0.2.13 - pkg/database/fetch-event-by-serial_test.go - Added `false` as third argument to `SaveEvent` call - pkg/database/query-for-kinds_test.go - Added `false` as third argument to `SaveEvent` call - pkg/database/get-serials-by-range_test.go - Added `false` as third argument to `SaveEvent` call - pkg/database/query-events-multiple-param-replaceable_test.go - Added `false` as third argument to `SaveEvent` calls - pkg/database/query-events_test.go - Added `false` as third argument to `SaveEvent` calls - pkg/interfaces/store/store_interface.go - Updated `Saver` interface to include `noVerify` parameter in `SaveEvent` method - Added `SerialByIder` interface with `GetSerialById` method - pkg/database/save-event_test.go - Added `false` as third argument to `SaveEvent` calls - Added new test case for saving existing event - pkg/database/query-for-ids_test.go - Added `false` as third argument to `SaveEvent` call - pkg/protocol/ws/client.go - Changed comment about context cancellation from "context is canceled" to "context is cancelled" - pkg/app/relay/spider-fetch.go - Added signature checker for WebSocket connections - Modified logic to check for existing events before saving - Added logging and memory optimization improvements
100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
// Package main is a nostr relay with a simple follow/mute list authentication
|
|
// scheme and the new HTTP REST-based protocol. Configuration is via environment
|
|
// variables or an optional .env file.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/pkg/profile"
|
|
_ "net/http/pprof"
|
|
app2 "orly.dev/pkg/app"
|
|
"orly.dev/pkg/app/config"
|
|
"orly.dev/pkg/app/relay"
|
|
"orly.dev/pkg/app/relay/options"
|
|
"orly.dev/pkg/database"
|
|
"orly.dev/pkg/protocol/openapi"
|
|
"orly.dev/pkg/protocol/servemux"
|
|
"orly.dev/pkg/utils/chk"
|
|
"orly.dev/pkg/utils/context"
|
|
"orly.dev/pkg/utils/interrupt"
|
|
"orly.dev/pkg/utils/log"
|
|
"orly.dev/pkg/utils/lol"
|
|
"orly.dev/pkg/version"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
var err error
|
|
var cfg *config.C
|
|
if cfg, err = config.New(); chk.T(err) {
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
|
|
}
|
|
config.PrintHelp(cfg, os.Stderr)
|
|
os.Exit(0)
|
|
}
|
|
log.I.F("starting %s %s", cfg.AppName, version.V)
|
|
if config.GetEnv() {
|
|
config.PrintEnv(cfg, os.Stdout)
|
|
os.Exit(0)
|
|
}
|
|
if config.HelpRequested() {
|
|
config.PrintHelp(cfg, os.Stderr)
|
|
os.Exit(0)
|
|
}
|
|
lol.SetLogLevel(cfg.LogLevel)
|
|
if cfg.Pprof != "" {
|
|
switch cfg.Pprof {
|
|
case "cpu":
|
|
prof := profile.Start(profile.CPUProfile)
|
|
defer prof.Stop()
|
|
case "memory":
|
|
prof := profile.Start(profile.MemProfile)
|
|
defer prof.Stop()
|
|
case "allocation":
|
|
prof := profile.Start(profile.MemProfileAllocs)
|
|
defer prof.Stop()
|
|
}
|
|
}
|
|
c, cancel := context.Cancel(context.Bg())
|
|
var storage *database.D
|
|
if storage, err = database.New(
|
|
c, cancel, cfg.DataDir, cfg.DbLogLevel,
|
|
); chk.E(err) {
|
|
os.Exit(1)
|
|
}
|
|
r := &app2.Relay{C: cfg, Store: storage}
|
|
go app2.MonitorResources(c)
|
|
var server *relay.Server
|
|
serverParams := &relay.ServerParams{
|
|
Ctx: c,
|
|
Cancel: cancel,
|
|
Rl: r,
|
|
DbPath: cfg.DataDir,
|
|
MaxLimit: 512, // Default max limit for events
|
|
C: cfg,
|
|
}
|
|
var opts []options.O
|
|
serveMux := servemux.NewServeMux()
|
|
if server, err = relay.NewServer(
|
|
serverParams, serveMux, opts...,
|
|
); chk.E(err) {
|
|
os.Exit(1)
|
|
}
|
|
openapi.New(
|
|
server,
|
|
cfg.AppName,
|
|
version.V,
|
|
version.Description,
|
|
"/api",
|
|
serveMux,
|
|
)
|
|
if err != nil {
|
|
log.F.F("failed to create server: %v", err)
|
|
}
|
|
interrupt.AddHandler(func() { server.Shutdown() })
|
|
if err = server.Start(cfg.Listen, cfg.Port); chk.E(err) {
|
|
log.F.F("server terminated: %v", err)
|
|
}
|
|
}
|