Add LogToStdout config option, improve tag decoding, and fix ID tracking in event handling

This commit is contained in:
2025-09-10 15:16:33 +01:00
parent 5eb192f208
commit fe3893addf
4 changed files with 21 additions and 9 deletions

View File

@@ -29,6 +29,7 @@ type C struct {
Port int `env:"ORLY_PORT" default:"3334" usage:"port to listen on"`
LogLevel string `env:"ORLY_LOG_LEVEL" default:"info" usage:"relay log level: fatal error warn info debug trace"`
DBLogLevel string `env:"ORLY_DB_LOG_LEVEL" default:"info" usage:"database log level: fatal error warn info debug trace"`
LogToStdout bool `env:"ORLY_LOG_TO_STDOUT" usage:"log to stdout instead of stderr"`
Pprof string `env:"ORLY_PPROF" usage:"enable pprof in modes: cpu,memory,allocation"`
IPWhitelist []string `env:"ORLY_IP_WHITELIST" usage:"comma-separated list of IP addresses to allow access from, matches on prefixes to allow private subnets, eg 10.0.0 = 10.0.0.0/8"`
Admins []string `env:"ORLY_ADMINS" usage:"comma-separated list of admin npubs"`
@@ -73,6 +74,9 @@ func New() (cfg *C, err error) {
PrintHelp(cfg, os.Stderr)
os.Exit(0)
}
if cfg.LogToStdout {
lol.Writer = os.Stdout
}
lol.SetLogLevel(cfg.LogLevel)
return
}

View File

@@ -87,10 +87,16 @@ func (l *Listener) HandleDelete(env *eventenvelope.Submission) {
// if e tags are found, delete them if the author is signer, or one of
// the owners is signer
if utils.FastEqual(t.Key(), []byte("e")) {
var dst []byte
if _, err = hex.DecBytes(dst, t.Value()); chk.E(err) {
val := t.Value()
if len(val) == 0 {
continue
}
var dst []byte
if b, e := hex.Dec(string(val)); chk.E(e) {
continue
} else {
dst = b
}
f := &filter.F{
Ids: tag.NewFromBytesSlice(dst),
}

View File

@@ -113,8 +113,6 @@ privCheck:
events = tmp
seen := make(map[string]struct{})
for _, ev := range events {
// track the IDs we've sent
seen[string(ev.ID)] = struct{}{}
var res *eventenvelope.Result
if res, err = eventenvelope.NewResultWith(
env.Subscription, ev,
@@ -124,6 +122,8 @@ privCheck:
if err = res.Write(l); chk.E(err) {
return
}
// track the IDs we've sent (use hex encoding for stable key)
seen[hex.Enc(ev.ID)] = struct{}{}
}
// write the EOSE to signal to the client that all events found have been
// sent.
@@ -143,11 +143,11 @@ privCheck:
} else {
// remove the IDs that we already sent
var notFounds [][]byte
for _, ev := range events {
if _, ok := seen[string(ev.ID)]; ok {
for _, id := range f.Ids.T {
if _, ok := seen[hex.Enc(id)]; ok {
continue
}
notFounds = append(notFounds, ev.ID)
notFounds = append(notFounds, id)
}
// if all were found, don't add to subbedFilters
if len(notFounds) == 0 {