Set default value for LogToStdout, enhance logging for request handling, query events, and filters, and fix ID handling in relaytester-test.sh.

This commit is contained in:
2025-09-10 16:29:55 +01:00
parent fe3893addf
commit 9e59d5f72b
6 changed files with 86 additions and 25 deletions

View File

@@ -25,13 +25,14 @@ import (
)
func (l *Listener) HandleReq(msg []byte) (err error) {
log.T.F("HandleReq: from %s", l.remote)
var rem []byte
env := reqenvelope.New()
if rem, err = env.Unmarshal(msg); chk.E(err) {
return normalize.Error.Errorf(err.Error())
}
if len(rem) > 0 {
log.I.F("extra '%s'", rem)
log.I.F("REQ extra bytes: '%s'", rem)
}
// send a challenge to the client to auth if an ACL is active
if acl.Registry.Active.Load() != "none" {
@@ -55,8 +56,40 @@ func (l *Listener) HandleReq(msg []byte) (err error) {
// user has read access or better, continue
log.D.F("user has %s access", accessLevel)
}
var events event.S
for _, f := range *env.Filters {
var events event.S
for _, f := range *env.Filters {
idsLen := 0; kindsLen := 0; authorsLen := 0; tagsLen := 0
if f != nil {
if f.Ids != nil { idsLen = f.Ids.Len() }
if f.Kinds != nil { kindsLen = f.Kinds.Len() }
if f.Authors != nil { authorsLen = f.Authors.Len() }
if f.Tags != nil { tagsLen = f.Tags.Len() }
}
log.T.F("REQ %s: filter summary ids=%d kinds=%d authors=%d tags=%d", env.Subscription, idsLen, kindsLen, authorsLen, tagsLen)
if f != nil && f.Authors != nil && f.Authors.Len() > 0 {
var authors []string
for _, a := range f.Authors.T { authors = append(authors, hex.Enc(a)) }
log.T.F("REQ %s: authors=%v", env.Subscription, authors)
}
if f != nil && f.Kinds != nil && f.Kinds.Len() > 0 {
log.T.F("REQ %s: kinds=%v", env.Subscription, f.Kinds.ToUint16())
}
if f != nil && f.Ids != nil && f.Ids.Len() > 0 {
var ids []string
for _, id := range f.Ids.T {
ids = append(ids, hex.Enc(id))
}
var lim any
if pointers.Present(f.Limit) {
lim = *f.Limit
} else {
lim = nil
}
log.T.F(
"REQ %s: ids filter count=%d ids=%v limit=%v", env.Subscription,
f.Ids.Len(), ids, lim,
)
}
if pointers.Present(f.Limit) {
if *f.Limit == 0 {
continue
@@ -113,6 +146,10 @@ privCheck:
events = tmp
seen := make(map[string]struct{})
for _, ev := range events {
log.T.F(
"REQ %s: sending EVENT id=%s kind=%d", env.Subscription,
hex.Enc(ev.ID), ev.Kind,
)
var res *eventenvelope.Result
if res, err = eventenvelope.NewResultWith(
env.Subscription, ev,
@@ -135,6 +172,7 @@ privCheck:
// if the query was for just Ids, we know there can't be any more results,
// so cancel the subscription.
cancel := true
log.T.F("REQ %s: computing cancel/subscription; events_sent=%d", env.Subscription, len(events))
var subbedFilters filter.S
for _, f := range *env.Filters {
if f.Ids.Len() < 1 {
@@ -149,6 +187,7 @@ privCheck:
}
notFounds = append(notFounds, id)
}
log.T.F("REQ %s: ids outstanding=%d of %d", env.Subscription, len(notFounds), f.Ids.Len())
// if all were found, don't add to subbedFilters
if len(notFounds) == 0 {
continue