diff options
| -rw-r--r-- | cmd/relay/main.go | 8 | ||||
| -rw-r--r-- | config.example.yaml | 7 | ||||
| -rw-r--r-- | internal/config/config.go | 13 | ||||
| -rw-r--r-- | internal/handler/websocket/handler.go | 27 | ||||
| -rw-r--r-- | internal/handler/websocket/nip11.go | 56 | ||||
| -rwxr-xr-x | relay | bin | 0 -> 27787846 bytes |
6 files changed, 91 insertions, 20 deletions
diff --git a/cmd/relay/main.go b/cmd/relay/main.go index 86a29cb..78ee469 100644 --- a/cmd/relay/main.go +++ b/cmd/relay/main.go | |||
| @@ -116,6 +116,14 @@ func main() { | |||
| 116 | }() | 116 | }() |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | wsHandler.SetRelayConfig(&wshandler.RelayInfoConfig{ | ||
| 120 | Name: cfg.Relay.Name, | ||
| 121 | Description: cfg.Relay.Description, | ||
| 122 | Pubkey: cfg.Relay.Pubkey, | ||
| 123 | Contact: cfg.Relay.Contact, | ||
| 124 | Icon: cfg.Relay.Icon, | ||
| 125 | }) | ||
| 126 | |||
| 119 | if cfg.Auth.Read.Enabled || cfg.Auth.Write.Enabled { | 127 | if cfg.Auth.Read.Enabled || cfg.Auth.Write.Enabled { |
| 120 | wsHandler.SetAuth(store) | 128 | wsHandler.SetAuth(store) |
| 121 | wsHandler.SetAuthConfig(&wshandler.AuthConfig{ | 129 | wsHandler.SetAuthConfig(&wshandler.AuthConfig{ |
diff --git a/config.example.yaml b/config.example.yaml index 93f6000..5618b7e 100644 --- a/config.example.yaml +++ b/config.example.yaml | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | relay: | ||
| 2 | name: "muxstr relay" | ||
| 3 | description: "High-performance Nostr relay with gRPC, Connect, and WebSocket support" | ||
| 4 | pubkey: "" # operator's hex pubkey (optional) | ||
| 5 | contact: "" # admin contact email (optional) | ||
| 6 | icon: "" # relay icon URL (optional) | ||
| 7 | |||
| 1 | server: | 8 | server: |
| 2 | grpc_addr: "localhost:50051" | 9 | grpc_addr: "localhost:50051" |
| 3 | http_addr: "localhost:8007" | 10 | http_addr: "localhost:8007" |
diff --git a/internal/config/config.go b/internal/config/config.go index 7eca750..36d3e1e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go | |||
| @@ -14,6 +14,7 @@ import ( | |||
| 14 | ) | 14 | ) |
| 15 | 15 | ||
| 16 | type Config struct { | 16 | type Config struct { |
| 17 | Relay RelayConfig `yaml:"relay"` | ||
| 17 | Server ServerConfig `yaml:"server"` | 18 | Server ServerConfig `yaml:"server"` |
| 18 | Database DatabaseConfig `yaml:"database"` | 19 | Database DatabaseConfig `yaml:"database"` |
| 19 | Auth AuthConfig `yaml:"auth"` | 20 | Auth AuthConfig `yaml:"auth"` |
| @@ -23,6 +24,14 @@ type Config struct { | |||
| 23 | Storage StorageConfig `yaml:"storage"` | 24 | Storage StorageConfig `yaml:"storage"` |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 27 | type RelayConfig struct { | ||
| 28 | Name string `yaml:"name"` | ||
| 29 | Description string `yaml:"description"` | ||
| 30 | Pubkey string `yaml:"pubkey"` | ||
| 31 | Contact string `yaml:"contact"` | ||
| 32 | Icon string `yaml:"icon"` | ||
| 33 | } | ||
| 34 | |||
| 26 | type ServerConfig struct { | 35 | type ServerConfig struct { |
| 27 | GrpcAddr string `yaml:"grpc_addr"` | 36 | GrpcAddr string `yaml:"grpc_addr"` |
| 28 | HttpAddr string `yaml:"http_addr"` | 37 | HttpAddr string `yaml:"http_addr"` |
| @@ -90,6 +99,10 @@ type StorageConfig struct { | |||
| 90 | // Default returns the default configuration. | 99 | // Default returns the default configuration. |
| 91 | func Default() *Config { | 100 | func Default() *Config { |
| 92 | return &Config{ | 101 | return &Config{ |
| 102 | Relay: RelayConfig{ | ||
| 103 | Name: "muxstr relay", | ||
| 104 | Description: "High-performance Nostr relay with gRPC, Connect, and WebSocket support", | ||
| 105 | }, | ||
| 93 | Server: ServerConfig{ | 106 | Server: ServerConfig{ |
| 94 | GrpcAddr: ":50051", | 107 | GrpcAddr: ":50051", |
| 95 | HttpAddr: ":8080", | 108 | HttpAddr: ":8080", |
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 | ||
| 52 | type RelayInfoConfig struct { | ||
| 53 | Name string | ||
| 54 | Description string | ||
| 55 | Pubkey string | ||
| 56 | Contact string | ||
| 57 | Icon string | ||
| 58 | } | ||
| 59 | |||
| 52 | type connState struct { | 60 | type 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 | ||
| 58 | type Handler struct { | 66 | type 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 | ||
| 68 | func NewHandler(store EventStore, subs *subscription.Manager) *Handler { | 77 | func 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 | ||
| 100 | func (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 |
| 92 | func (h *Handler) SetIndexData(grpcAddr, httpAddr, wsAddr string) { | 105 | func (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 | ||
| 8 | type RelayInfo struct { | 8 | type 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 | ||
| 19 | type Limits struct { | 20 | type Limits struct { |
| @@ -31,10 +32,39 @@ type Limits struct { | |||
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | func (h *Handler) ServeNIP11(w http.ResponseWriter, r *http.Request) { | 34 | func (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 | ||
| Binary files differ | |||
