Compare commits

...

2 Commits

Author SHA1 Message Date
fiatjaf
a103353254 fix development mess. 2024-08-01 12:41:27 -03:00
fiatjaf
5f0f9eec99 .PreventBroadcast slice of functions for controlling what events get broadcasted and to whom.
addresses https://t.me/nip29_temp/303
2024-07-31 10:34:53 -03:00
4 changed files with 9 additions and 3 deletions

4
go.mod
View File

@@ -5,7 +5,7 @@ go 1.21.4
require (
github.com/fasthttp/websocket v1.5.7
github.com/fiatjaf/eventstore v0.5.1
github.com/nbd-wtf/go-nostr v0.34.3
github.com/nbd-wtf/go-nostr v0.34.5
github.com/puzpuzpuz/xsync/v3 v3.0.2
github.com/rs/cors v1.7.0
)
@@ -54,5 +54,3 @@ require (
golang.org/x/sys v0.20.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
replace github.com/nbd-wtf/go-nostr => ../go-nostr

2
go.sum
View File

@@ -113,6 +113,8 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI=
github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/nbd-wtf/go-nostr v0.34.5 h1:vti8WqvGWbVoWAPniaz7li2TpCyC+7ZS62Gmy7ib/z0=
github.com/nbd-wtf/go-nostr v0.34.5/go.mod h1:NZQkxl96ggbO8rvDpVjcsojJqKTPwqhP4i82O7K5DJs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

View File

@@ -86,6 +86,11 @@ func (rl *Relay) removeListenerId(ws *WebSocket, id string) {
func (rl *Relay) notifyListeners(event *nostr.Event) {
for _, listener := range rl.listeners {
if listener.filter.Matches(event) {
for _, pb := range rl.PreventBroadcast {
if pb(listener.ws, event) {
return
}
}
listener.ws.WriteJSON(nostr.EventEnvelope{SubscriptionID: &listener.subscriptionId, Event: *event})
}
}

View File

@@ -64,6 +64,7 @@ type Relay struct {
OnDisconnect []func(ctx context.Context)
OverwriteRelayInformation []func(ctx context.Context, r *http.Request, info nip11.RelayInformationDocument) nip11.RelayInformationDocument
OverwriteResponseEvent []func(ctx context.Context, event *nostr.Event)
PreventBroadcast []func(ws *WebSocket, event *nostr.Event) bool
// these are used when this relays acts as a router
routes []Route