aboutsummaryrefslogtreecommitdiffstats
path: root/internal/handler/websocket
diff options
context:
space:
mode:
authorClawd <ai@clawd.bot>2026-02-22 14:08:54 -0800
committerClawd <ai@clawd.bot>2026-02-22 14:08:54 -0800
commit5195d8031b7930069ba5441a6cd1e7a59c21c546 (patch)
tree50a110dd565cc1c9330c61dea6f4cc720e1efbd0 /internal/handler/websocket
parent3b760256768e45ddb2965aab2a60f11327972e63 (diff)
NIP-11: make relay info configurable
- Add relay config section (name, description, pubkey, contact, icon) - Wire config to NIP-11 handler - AuthRequired/RestrictedWrites now reflect actual auth config - Add NIP-42 to supported_nips list - Update example config
Diffstat (limited to 'internal/handler/websocket')
-rw-r--r--internal/handler/websocket/handler.go27
-rw-r--r--internal/handler/websocket/nip11.go56
2 files changed, 63 insertions, 20 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go
index 6eb8763..b11171d 100644
--- a/internal/handler/websocket/handler.go
+++ b/internal/handler/websocket/handler.go
@@ -49,6 +49,14 @@ type AuthConfig struct {
49 WriteAllowedPubkeys []string 49 WriteAllowedPubkeys []string
50} 50}
51 51
52type RelayInfoConfig struct {
53 Name string
54 Description string
55 Pubkey string
56 Contact string
57 Icon string
58}
59
52type connState struct { 60type connState struct {
53 authenticatedPubkey string 61 authenticatedPubkey string
54 authChallenge string 62 authChallenge string
@@ -56,13 +64,14 @@ type connState struct {
56} 64}
57 65
58type Handler struct { 66type Handler struct {
59 store EventStore 67 store EventStore
60 auth AuthStore 68 auth AuthStore
61 subs *subscription.Manager 69 subs *subscription.Manager
62 metrics MetricsRecorder 70 metrics MetricsRecorder
63 limiter RateLimiter 71 limiter RateLimiter
64 authConfig *AuthConfig 72 authConfig *AuthConfig
65 indexData IndexData 73 relayConfig *RelayInfoConfig
74 indexData IndexData
66} 75}
67 76
68func NewHandler(store EventStore, subs *subscription.Manager) *Handler { 77func NewHandler(store EventStore, subs *subscription.Manager) *Handler {
@@ -88,6 +97,10 @@ func (h *Handler) SetAuthConfig(cfg *AuthConfig) {
88 h.authConfig = cfg 97 h.authConfig = cfg
89} 98}
90 99
100func (h *Handler) SetRelayConfig(cfg *RelayInfoConfig) {
101 h.relayConfig = cfg
102}
103
91// SetIndexData sets the addresses for the index page 104// SetIndexData sets the addresses for the index page
92func (h *Handler) SetIndexData(grpcAddr, httpAddr, wsAddr string) { 105func (h *Handler) SetIndexData(grpcAddr, httpAddr, wsAddr string) {
93 h.indexData = IndexData{ 106 h.indexData = IndexData{
diff --git a/internal/handler/websocket/nip11.go b/internal/handler/websocket/nip11.go
index 8de95a2..f51faa6 100644
--- a/internal/handler/websocket/nip11.go
+++ b/internal/handler/websocket/nip11.go
@@ -6,14 +6,15 @@ import (
6) 6)
7 7
8type RelayInfo struct { 8type RelayInfo struct {
9 Name string `json:"name"` 9 Name string `json:"name"`
10 Description string `json:"description"` 10 Description string `json:"description"`
11 Pubkey string `json:"pubkey,omitempty"` 11 Pubkey string `json:"pubkey,omitempty"`
12 Contact string `json:"contact,omitempty"` 12 Contact string `json:"contact,omitempty"`
13 SupportedNIPs []int `json:"supported_nips"` 13 Icon string `json:"icon,omitempty"`
14 Software string `json:"software"` 14 SupportedNIPs []int `json:"supported_nips"`
15 Version string `json:"version"` 15 Software string `json:"software"`
16 Limitation *Limits `json:"limitation,omitempty"` 16 Version string `json:"version"`
17 Limitation *Limits `json:"limitation,omitempty"`
17} 18}
18 19
19type Limits struct { 20type Limits struct {
@@ -31,10 +32,39 @@ type Limits struct {
31} 32}
32 33
33func (h *Handler) ServeNIP11(w http.ResponseWriter, r *http.Request) { 34func (h *Handler) ServeNIP11(w http.ResponseWriter, r *http.Request) {
35 // Defaults
36 name := "muxstr relay"
37 description := "High-performance Nostr relay with gRPC, Connect, and WebSocket support"
38 var pubkey, contact, icon string
39
40 // Override from config if set
41 if h.relayConfig != nil {
42 if h.relayConfig.Name != "" {
43 name = h.relayConfig.Name
44 }
45 if h.relayConfig.Description != "" {
46 description = h.relayConfig.Description
47 }
48 pubkey = h.relayConfig.Pubkey
49 contact = h.relayConfig.Contact
50 icon = h.relayConfig.Icon
51 }
52
53 // Determine auth status from authConfig
54 authRequired := false
55 restrictedWrites := false
56 if h.authConfig != nil {
57 authRequired = h.authConfig.ReadEnabled
58 restrictedWrites = h.authConfig.WriteEnabled
59 }
60
34 info := RelayInfo{ 61 info := RelayInfo{
35 Name: "muxstr relay", 62 Name: name,
36 Description: "High-performance Nostr relay with gRPC, Connect, and WebSocket support", 63 Description: description,
37 SupportedNIPs: []int{1, 9, 11}, 64 Pubkey: pubkey,
65 Contact: contact,
66 Icon: icon,
67 SupportedNIPs: []int{1, 9, 11, 42},
38 Software: "northwest.io/muxstr", 68 Software: "northwest.io/muxstr",
39 Version: "0.1.0", 69 Version: "0.1.0",
40 Limitation: &Limits{ 70 Limitation: &Limits{
@@ -45,9 +75,9 @@ func (h *Handler) ServeNIP11(w http.ResponseWriter, r *http.Request) {
45 MaxSubidLength: 64, 75 MaxSubidLength: 64,
46 MaxEventTags: 2000, 76 MaxEventTags: 2000,
47 MaxContentLength: 65536, 77 MaxContentLength: 65536,
48 AuthRequired: false, 78 AuthRequired: authRequired,
49 PaymentRequired: false, 79 PaymentRequired: false,
50 RestrictedWrites: false, 80 RestrictedWrites: restrictedWrites,
51 }, 81 },
52 } 82 }
53 83