diff --git a/auth/nip42.go b/auth/nip42.go index 8b77961..2a5b130 100644 --- a/auth/nip42.go +++ b/auth/nip42.go @@ -53,7 +53,7 @@ var ( // The result of the validation is encoded in the ok bool. func Validate(ev *event.T, challenge []byte, relayURL string) (ok bool, err error) { // log.T.ToSliceOfBytes("relayURL '%s'", relayURL) - log.I.S(ev) + // log.I.S(ev) if ev.Kind.K != kind.ClientAuthentication.K { err = log.E.Err("event incorrect kind for auth: %d %s", ev.Kind.K, kind.GetString(ev.Kind)) diff --git a/realy/acceptevent.go b/realy/acceptevent.go index b784ac7..7f6e11d 100644 --- a/realy/acceptevent.go +++ b/realy/acceptevent.go @@ -7,7 +7,6 @@ import ( "realy.lol/context" "realy.lol/ec/schnorr" "realy.lol/event" - "realy.lol/hex" "realy.lol/kind" "realy.lol/log" "realy.lol/tag" @@ -51,14 +50,15 @@ func (s *Server) acceptEvent(c context.T, evt *event.T, authedPubkey []byte, // // note that some clients hide this info in the kind 10000 mute list, unfortunately. // such as jumble. use old nostrudel or similar which still gives public readable info. - for pk := range s.muted { - if bytes.Equal(evt.Pubkey, []byte(pk)) { - notice = "rejecting event with pubkey " + hex.Enc(evt.Pubkey) + - " because on owner mute list" - log.I.F("%s %s", remote, notice) - return false, notice, nil - } - } + // log.I.S(s.muted) + // for pk := range s.muted { + // if bytes.Equal(evt.Pubkey, []byte(pk)) { + // notice = "rejecting event with pubkey " + hex.Enc(evt.Pubkey) + + // " because on owner mute list" + // log.I.F("%s %s", remote, notice) + // return false, notice, nil + // } + // } // for _, o := range s.owners { // log.T.F("%0x,%0x", o, evt.Pubkey) // if bytes.Equal(o, evt.Pubkey) { diff --git a/realy/init.go b/realy/init.go index 02ca6e5..bffd905 100644 --- a/realy/init.go +++ b/realy/init.go @@ -47,7 +47,7 @@ func (s *Server) ZeroLists() { s.followed = make(map[string]struct{}) s.ownersFollowed = make(map[string]struct{}) s.ownersFollowLists = s.ownersFollowLists[:0] - s.muted = make(map[string]struct{}) + // s.muted = make(map[string]struct{}) s.ownersMuteLists = s.ownersMuteLists[:0] } @@ -114,37 +114,37 @@ func (s *Server) CheckOwnerLists(c context.T) { } evs = nil } - if len(s.muted) < 1 { - log.D.Ln("regenerating owners mute lists") - s.muted = make(map[string]struct{}) - if evs, err = s.Store.QueryEvents(c, - &filter.T{Authors: tag.New(s.owners...), - Kinds: kinds.New(kind.MuteList)}); chk.E(err) { - } - for _, ev := range evs { - s.ownersMuteLists = append(s.ownersMuteLists, ev.Id) - for _, t := range ev.Tags.ToSliceOfTags() { - if bytes.Equal(t.Key(), []byte("p")) { - var p []byte - if p, err = hex.Dec(string(t.Value())); chk.E(err) { - continue - } - // log.I.F("muted %0x", p) - s.muted[string(p)] = struct{}{} - } - } - } - evs = nil - } - // remove muted from the followed list - for m := range s.muted { - for f := range s.followed { - if f == m { - // delete muted element from followed list - delete(s.followed, m) - } - } - } - log.I.F("%d allowed npubs, %d blocked", len(s.followed), len(s.muted)) + // if len(s.muted) < 1 { + // log.D.Ln("regenerating owners mute lists") + // s.muted = make(map[string]struct{}) + // if evs, err = s.Store.QueryEvents(c, + // &filter.T{Authors: tag.New(s.owners...), + // Kinds: kinds.New(kind.MuteList)}); chk.E(err) { + // } + // for _, ev := range evs { + // s.ownersMuteLists = append(s.ownersMuteLists, ev.Id) + // for _, t := range ev.Tags.ToSliceOfTags() { + // if bytes.Equal(t.Key(), []byte("p")) { + // var p []byte + // if p, err = hex.Dec(string(t.Value())); chk.E(err) { + // continue + // } + // // log.I.F("muted %0x", p) + // s.muted[string(p)] = struct{}{} + // } + // } + // } + // evs = nil + // } + // // remove muted from the followed list + // for m := range s.muted { + // for f := range s.followed { + // if f == m { + // // delete muted element from followed list + // delete(s.followed, m) + // } + // } + // } + log.I.F("%d allowed npubs ", len(s.followed)) } } diff --git a/realy/server.go b/realy/server.go index 077eaa5..e7228dc 100644 --- a/realy/server.go +++ b/realy/server.go @@ -47,9 +47,9 @@ type Server struct { // OwnersFollowed are "guests" of the followed and have full access but with // rate limiting enabled. ownersFollowed list.L - // muted are on Owners' mute lists and do not have write access to the relay, - // even if they would be in the OwnersFollowed list, they can only read. - muted list.L + // // muted are on Owners' mute lists and do not have write access to the relay, + // // even if they would be in the OwnersFollowed list, they can only read. + // muted list.L // ownersFollowLists are the event IDs of owners follow lists, which must not be // deleted, only replaced. ownersFollowLists [][]byte diff --git a/socketapi/handleAuth.go b/socketapi/handleAuth.go index fa1f341..f5bead4 100644 --- a/socketapi/handleAuth.go +++ b/socketapi/handleAuth.go @@ -3,6 +3,7 @@ package socketapi import ( "realy.lol/auth" "realy.lol/chk" + "realy.lol/context" "realy.lol/envelopes/authenvelope" "realy.lol/envelopes/okenvelope" "realy.lol/log" @@ -45,6 +46,13 @@ func (a *A) HandleAuth(b []byte, srv interfaces.Server) (msg []byte) { } log.D.F("%s authed to pubkey,%0x", a.Listener.RealRemote(), env.Event.Pubkey) a.Listener.SetAuthed(string(env.Event.Pubkey)) + evs := a.Listener.GetPendingEvents() + sto := a.Storage() + for _, ev := range evs { + if err = sto.SaveEvent(context.Bg(), ev); chk.E(err) { + } + log.I.F("saved event %0x", ev.Id) + } } } return diff --git a/socketapi/handleEvent.go b/socketapi/handleEvent.go index 8d30368..c23a5b6 100644 --- a/socketapi/handleEvent.go +++ b/socketapi/handleEvent.go @@ -109,6 +109,7 @@ func (a *A) HandleRejectEvent(env *eventenvelope.Submission, notice string) (err if err = authenvelope.NewChallengeWith(a.Listener.Challenge()).Write(a.Listener); chk.T(err) { return } + a.Listener.AddPendingEvent(env.T) return } if err = Ok.Invalid(a, env, notice); chk.E(err) { diff --git a/socketapi/main.go b/socketapi/main.go index 4262d32..fec6335 100644 --- a/socketapi/main.go +++ b/socketapi/main.go @@ -10,6 +10,7 @@ import ( "realy.lol/chk" "realy.lol/context" "realy.lol/envelopes/authenvelope" + "realy.lol/event" "realy.lol/log" "realy.lol/publish" "realy.lol/realy/helpers" @@ -27,8 +28,9 @@ const ( ) type A struct { - Ctx context.T - Listener *ws.Listener + Ctx context.T + Listener *ws.Listener + AwaitingAuth *event.T interfaces.Server } diff --git a/tags/tags.go b/tags/tags.go index 06566b6..97a056f 100644 --- a/tags/tags.go +++ b/tags/tags.go @@ -100,7 +100,7 @@ func (t *T) AddCap(i, c int) (tt *T) { // ToStringsSlice converts a tags.T to a slice of slice of strings. func (t *T) ToStringsSlice() (b [][]string) { if t == nil { - log.I.F("nil tags %s", lol.GetNLoc(7)) + // log.I.F("nil tags %s", lol.GetNLoc(7)) return nil } b = make([][]string, 0, len(t.element)) diff --git a/ws/listener.go b/ws/listener.go index 1e6a7a2..0f0f854 100644 --- a/ws/listener.go +++ b/ws/listener.go @@ -9,6 +9,7 @@ import ( "github.com/fasthttp/websocket" "realy.lol/atomic" + "realy.lol/event" "realy.lol/log" ) @@ -21,6 +22,7 @@ type Listener struct { remote atomic.String authed atomic.String authRequested atomic.Bool + pendingEvents []*event.T } // NewListener creates a new Listener for listening for inbound connections for a relay. @@ -127,3 +129,13 @@ func (ws *Listener) Req() *http.Request { return ws.Request } // Close the Listener connection from the Listener side. func (ws *Listener) Close() (err error) { return ws.Conn.Close() } + +func (ws *Listener) AddPendingEvent(ev *event.T) { + ws.pendingEvents = append(ws.pendingEvents, ev) +} + +func (ws *Listener) GetPendingEvents() (evs []*event.T) { + evs = ws.pendingEvents + ws.pendingEvents = nil + return +}