From 45b4f829953bfdeb85b9b2948275784ec98ca81f Mon Sep 17 00:00:00 2001 From: mleku Date: Tue, 30 Sep 2025 18:07:42 +0100 Subject: [PATCH] Enable additional NIP support, improve tag handling validation, and simplify WebSocket message processing. --- app/handle-relayinfo.go | 10 +++++----- app/handle-websocket.go | 2 +- pkg/encoders/tag/tags.go | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/handle-relayinfo.go b/app/handle-relayinfo.go index e529f55..7db9030 100644 --- a/app/handle-relayinfo.go +++ b/app/handle-relayinfo.go @@ -35,7 +35,7 @@ func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request) { supportedNIPs := relayinfo.GetList( relayinfo.BasicProtocol, relayinfo.Authentication, - // relayinfo.EncryptedDirectMessage, + relayinfo.EncryptedDirectMessage, relayinfo.EventDeletion, relayinfo.RelayInformationDocument, relayinfo.GenericTagQueries, @@ -43,7 +43,7 @@ func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request) { relayinfo.EventTreatment, // relayinfo.CommandResults, relayinfo.ParameterizedReplaceableEvents, - // relayinfo.ExpirationTimestamp, + relayinfo.ExpirationTimestamp, relayinfo.ProtectedEvents, relayinfo.RelayListMetadata, ) @@ -51,7 +51,7 @@ func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request) { supportedNIPs = relayinfo.GetList( relayinfo.BasicProtocol, relayinfo.Authentication, - // relayinfo.EncryptedDirectMessage, + relayinfo.EncryptedDirectMessage, relayinfo.EventDeletion, relayinfo.RelayInformationDocument, relayinfo.GenericTagQueries, @@ -69,7 +69,7 @@ func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request) { // Construct description with dashboard URL dashboardURL := s.DashboardURL(r) description := version.Description + " dashboard: " + dashboardURL - + // Get relay identity pubkey as hex var relayPubkey string if skb, err := s.D.GetRelayIdentitySecret(); err == nil && len(skb) == 32 { @@ -78,7 +78,7 @@ func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request) { relayPubkey = hex.Enc(sign.Pub()) } } - + info = &relayinfo.T{ Name: s.Config.AppName, Description: description, diff --git a/app/handle-websocket.go b/app/handle-websocket.go index 282204e..f0a092e 100644 --- a/app/handle-websocket.go +++ b/app/handle-websocket.go @@ -153,7 +153,7 @@ whitelist: continue } // log.T.F("received message from %s: %s", remote, string(msg)) - go listener.HandleMessage(msg, remote) + listener.HandleMessage(msg, remote) } } diff --git a/pkg/encoders/tag/tags.go b/pkg/encoders/tag/tags.go index e2b2b10..b5d7457 100644 --- a/pkg/encoders/tag/tags.go +++ b/pkg/encoders/tag/tags.go @@ -147,6 +147,9 @@ func (s *S) Unmarshal(b []byte) (r []byte, err error) { // GetFirst returns the first tag.T that has the same Key as t. func (s *S) GetFirst(t []byte) (first *T) { + if s == nil || len(*s) < 1 { + return + } for _, tt := range *s { if tt.Len() == 0 { continue @@ -159,7 +162,13 @@ func (s *S) GetFirst(t []byte) (first *T) { } func (s *S) GetAll(t []byte) (all []*T) { + if s == nil || len(*s) < 1 { + return + } for _, tt := range *s { + if len(tt.T) < 1 { + continue + } if utils.FastEqual(tt.T[0], t) { all = append(all, tt) }