-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
policies merged in, aliases moved to separate file
- Loading branch information
Showing
7 changed files
with
128 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package replicatr | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"sync" | ||
|
||
"github.com/fasthttp/websocket" | ||
"github.com/nbd-wtf/go-nostr" | ||
"github.com/nbd-wtf/go-nostr/nip11" | ||
"github.com/puzpuzpuz/xsync/v2" | ||
) | ||
|
||
// aliases so we can swap out to another package with only here changed | ||
type ( | ||
Ctx = context.Context | ||
Info = nip11.RelayInformationDocument | ||
Event = nostr.Event | ||
Filter = nostr.Filter | ||
Filters = nostr.Filters | ||
TagMap = nostr.TagMap | ||
EventEnvelope = nostr.EventEnvelope | ||
OKEnvelope = nostr.OKEnvelope | ||
CountEnvelope = nostr.CountEnvelope | ||
ClosedEnvelope = nostr.ClosedEnvelope | ||
ReqEnvelope = nostr.ReqEnvelope | ||
EOSEEnvelope = nostr.EOSEEnvelope | ||
CloseEnvelope = nostr.CloseEnvelope | ||
AuthEnvelope = nostr.AuthEnvelope | ||
NoticeEnvelope = nostr.NoticeEnvelope | ||
Conn = websocket.Conn | ||
Request = http.Request | ||
ResponseWriter = http.ResponseWriter | ||
Mutex = sync.Mutex | ||
WaitGroup = sync.WaitGroup | ||
CancelCauseFunc = context.CancelCauseFunc | ||
ListenerMap = *xsync.MapOf[string, *Listener] | ||
Timestamp = nostr.Timestamp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package replicatr | ||
|
||
import ( | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
// RejectKind04Snoopers prevents reading NIP-04 messages from people not | ||
// involved in the conversation. | ||
func RejectKind04Snoopers(ctx Ctx, filter *Filter) (bool, string) { | ||
// prevent kind-4 events from being returned to unauthed users, only when | ||
// authentication is a thing | ||
if !slices.Contains(filter.Kinds, 4) { | ||
return false, "" | ||
} | ||
ws := GetConnection(ctx) | ||
s := filter.Authors | ||
r, _ := filter.Tags["p"] | ||
switch { | ||
case ws.AuthedPublicKey == "": | ||
// not authenticated | ||
return true, "restricted: this relay does not serve kind-4 to " + | ||
"unauthenticated users, does your client implement NIP-42?" | ||
case len(s) == 1 && len(r) < 2 && (s[0] == ws.AuthedPublicKey): | ||
// allowed filter: ws.authed is sole sender (filter specifies one or all | ||
// r) | ||
return false, "" | ||
case len(r) == 1 && len(s) < 2 && (r[0] == ws.AuthedPublicKey): | ||
// allowed filter: ws.authed is sole receiver (filter specifies one or | ||
// all senders) | ||
return false, "" | ||
default: | ||
// restricted filter: do not return any events, even if other elements | ||
// in filters array were not restricted). client should know better. | ||
return true, "restricted: authenticated user does not have " + | ||
"authorization for requested filters." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters