add save-after-auth and eliminate mute list

This commit is contained in:
2025-05-24 18:28:01 +01:00
parent 0b467c35c7
commit 56ecfe11a8
9 changed files with 72 additions and 49 deletions

View File

@@ -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))

View File

@@ -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) {

View File

@@ -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))
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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))

View File

@@ -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
}