Relay.AssumeValid

This commit is contained in:
fiatjaf
2023-03-14 17:07:22 -03:00
parent 483f40a596
commit 02759120ea

View File

@@ -48,6 +48,10 @@ type Relay struct {
ConnectionError chan error ConnectionError chan error
okCallbacks s.MapOf[string, func(bool)] okCallbacks s.MapOf[string, func(bool)]
// custom things that aren't often used
//
AssumeValid bool // this will skip verifying signatures for events received from this relay
} }
// RelayConnect returns a relay object connected to url. // RelayConnect returns a relay object connected to url.
@@ -146,14 +150,15 @@ func (r *Relay) Connect(ctx context.Context) error {
json.Unmarshal(jsonMessage[2], &event) json.Unmarshal(jsonMessage[2], &event)
// check signature of all received events, ignore invalid // check signature of all received events, ignore invalid
ok, err := event.CheckSignature() if !r.AssumeValid {
if !ok { if ok, err := event.CheckSignature(); !ok {
errmsg := "" errmsg := ""
if err != nil { if err != nil {
errmsg = err.Error() errmsg = err.Error()
}
log.Printf("bad signature: %s", errmsg)
continue
} }
log.Printf("bad signature: %s", errmsg)
continue
} }
// check if the event matches the desired filter, ignore otherwise // check if the event matches the desired filter, ignore otherwise