Add LogToStdout config option, improve tag decoding, and fix ID tracking in event handling
This commit is contained in:
@@ -29,6 +29,7 @@ type C struct {
|
|||||||
Port int `env:"ORLY_PORT" default:"3334" usage:"port to listen on"`
|
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"`
|
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"`
|
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"`
|
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"`
|
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"`
|
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)
|
PrintHelp(cfg, os.Stderr)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
if cfg.LogToStdout {
|
||||||
|
lol.Writer = os.Stdout
|
||||||
|
}
|
||||||
lol.SetLogLevel(cfg.LogLevel)
|
lol.SetLogLevel(cfg.LogLevel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// if e tags are found, delete them if the author is signer, or one of
|
||||||
// the owners is signer
|
// the owners is signer
|
||||||
if utils.FastEqual(t.Key(), []byte("e")) {
|
if utils.FastEqual(t.Key(), []byte("e")) {
|
||||||
var dst []byte
|
val := t.Value()
|
||||||
if _, err = hex.DecBytes(dst, t.Value()); chk.E(err) {
|
if len(val) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
var dst []byte
|
||||||
|
if b, e := hex.Dec(string(val)); chk.E(e) {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
dst = b
|
||||||
|
}
|
||||||
f := &filter.F{
|
f := &filter.F{
|
||||||
Ids: tag.NewFromBytesSlice(dst),
|
Ids: tag.NewFromBytesSlice(dst),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,8 +113,6 @@ privCheck:
|
|||||||
events = tmp
|
events = tmp
|
||||||
seen := make(map[string]struct{})
|
seen := make(map[string]struct{})
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
// track the IDs we've sent
|
|
||||||
seen[string(ev.ID)] = struct{}{}
|
|
||||||
var res *eventenvelope.Result
|
var res *eventenvelope.Result
|
||||||
if res, err = eventenvelope.NewResultWith(
|
if res, err = eventenvelope.NewResultWith(
|
||||||
env.Subscription, ev,
|
env.Subscription, ev,
|
||||||
@@ -124,6 +122,8 @@ privCheck:
|
|||||||
if err = res.Write(l); chk.E(err) {
|
if err = res.Write(l); chk.E(err) {
|
||||||
return
|
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
|
// write the EOSE to signal to the client that all events found have been
|
||||||
// sent.
|
// sent.
|
||||||
@@ -143,11 +143,11 @@ privCheck:
|
|||||||
} else {
|
} else {
|
||||||
// remove the IDs that we already sent
|
// remove the IDs that we already sent
|
||||||
var notFounds [][]byte
|
var notFounds [][]byte
|
||||||
for _, ev := range events {
|
for _, id := range f.Ids.T {
|
||||||
if _, ok := seen[string(ev.ID)]; ok {
|
if _, ok := seen[hex.Enc(id)]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
notFounds = append(notFounds, ev.ID)
|
notFounds = append(notFounds, id)
|
||||||
}
|
}
|
||||||
// if all were found, don't add to subbedFilters
|
// if all were found, don't add to subbedFilters
|
||||||
if len(notFounds) == 0 {
|
if len(notFounds) == 0 {
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ if ! command -v "relay-tester" &> /dev/null; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
rm -rf ~/.local/share/ORLY
|
rm -rf ~/.local/share/ORLY
|
||||||
export ORLY_LOG_LEVEL=off
|
export ORLY_LOG_LEVEL=trace
|
||||||
|
export ORLY_LOG_TO_STDOUT=true
|
||||||
export ORLY_LISTEN=127.0.0.1
|
export ORLY_LISTEN=127.0.0.1
|
||||||
export ORLY_PORT=3334
|
export ORLY_PORT=3334
|
||||||
export ORLY_IP_WHITELIST=127.0.0
|
export ORLY_IP_WHITELIST=127.0.0
|
||||||
export ORLY_ADMINS=nsec12l4072hvvyjpmkyjtdxn48xf8qj299zw60u7ddg58s2aphv3rpjqtg0tvr,nsec1syvtjgqauyeezgrev5nqrp36d87apjk87043tgu2usgv8umyy6wq4yl6tu
|
export ORLY_ADMINS=8118b9201de133912079652601863a69fdd0cac7f3eb15a38ae410c3f364269c,57eaff2aec61241dd8925b4d3a9cc93824a2944ed3f9e6b5143c15d0dd911864
|
||||||
|
export ORLY_ACL_MODE=none
|
||||||
go run . &
|
go run . &
|
||||||
sleep 2
|
sleep 2
|
||||||
relay-tester ws://127.0.0.1:3334 nsec12l4072hvvyjpmkyjtdxn48xf8qj299zw60u7ddg58s2aphv3rpjqtg0tvr nsec1syvtjgqauyeezgrev5nqrp36d87apjk87043tgu2usgv8umyy6wq4yl6tu
|
relay-tester ws://127.0.0.1:3334 nsec12l4072hvvyjpmkyjtdxn48xf8qj299zw60u7ddg58s2aphv3rpjqtg0tvr nsec1syvtjgqauyeezgrev5nqrp36d87apjk87043tgu2usgv8umyy6wq4yl6tu
|
||||||
|
|||||||
Reference in New Issue
Block a user