Remove unused disconnect method and integrate configuration into server

- **app/relay/disconnect.go**:
  - Deleted unused `disconnect` method that was no longer referenced in code.

- **app/relay/server.go**:
  - Integrated server configuration (`config.C`) directly into the `Server` struct.
  - Refactored `authRequired` and `publicReadable` fields to derive from the configuration.

- **app/relay/server-impl.go**:
  - Removed references to the obsolete `disconnect` method.
  - Updated methods to retrieve authentication and readability settings from configuration.

- **app/relay/handleRelayinfo.go**:
  - Adjusted `handleRelayinfo` to use `config.C.AuthRequired` for showing relay limitations.

- **app/config/config.go**:
  - Added default values for the `SpiderSeeds` field for consistent initialization.
  - Logged configuration details upon loading for better debugging visibility.

- **interfaces/server/server.go**:
  - Removed `Disconnect` method from `server.I`, as it was no longer needed.

- **main.go**:
  - Modified `relay.ServerParams` to pass the configuration as a pointer (`config.C`).
  - Simplified initialization by removing redundant fields replaced by configuration integration.

- **protocol/socketapi/handleEvent.go**:
  - Standardized and clarified comments for parameter descriptions.
This commit is contained in:
2025-07-17 11:22:53 +01:00
parent 49bdf3f5d7
commit 43404d6a07
8 changed files with 40 additions and 64 deletions

View File

@@ -38,7 +38,7 @@ type C struct {
Pprof bool `env:"ORLY_PPROF" default:"false" usage:"enable pprof on 127.0.0.1:6060"`
AuthRequired bool `env:"ORLY_AUTH_REQUIRED" default:"false" usage:"require authentication for all requests"`
PublicReadable bool `env:"ORLY_PUBLIC_READABLE" default:"true" usage:"allow public read access to the whether or not authed"`
SpiderSeeds []string `env:"ORLY_SPIDER_SEEDS" usage:"seeds to use for the spider (relays that are looked up initially to find owner relay lists) (comma separated)"`
SpiderSeeds []string `env:"ORLY_SPIDER_SEEDS" usage:"seeds to use for the spider (relays that are looked up initially to find owner relay lists) (comma separated)" default:"wss://nostr.band/,wss://relay.damus.io/,wss://nostr.wine/,wss://nostr.land/"`
Owners []string `env:"ORLY_OWNERS" usage:"list of users whose follow lists designate whitelisted users who can publish events, and who can read if public readable is false (comma separated)"`
}
@@ -71,6 +71,7 @@ func New() (cfg *C, err error) {
lol.SetLogLevel(cfg.LogLevel)
log.I.F("loaded configuration from %s", envPath)
}
log.I.S(cfg)
return
}

View File

@@ -1,12 +0,0 @@
package relay
import (
"orly.dev/utils/log"
)
func (s *Server) disconnect() {
for client := range s.clients {
log.I.F("closing client %s", client.RemoteAddr())
client.Close()
}
}

View File

@@ -42,7 +42,7 @@ func (s *Server) handleRelayInfo(w http.ResponseWriter, r *http.Request) {
Nips: supportedNIPs, Software: version.URL,
Version: version.V,
Limitation: relayinfo.Limits{
AuthRequired: s.authRequired,
AuthRequired: s.C.AuthRequired,
},
Icon: "https://cdn.satellite.earth/ac9778868fbf23b63c47c769a74e163377e6ea94d3f0f31711931663d035c4f6.png",
}

View File

@@ -12,14 +12,12 @@ func (s *Server) Storage() store.I { return s.relay.Storage() }
func (s *Server) Relay() relay.I { return s.relay }
func (s *Server) Disconnect() { s.disconnect() }
func (s *Server) Publisher() *publish.S { return s.listeners }
func (s *Server) Context() context.T { return s.Ctx }
func (s *Server) AuthRequired() bool { return s.authRequired }
func (s *Server) AuthRequired() bool { return s.C.AuthRequired }
func (s *Server) PublicReadable() bool { return s.publicReadable }
func (s *Server) PublicReadable() bool { return s.C.PublicReadable }
var _ server.I = &Server{}

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/http"
"orly.dev/app/config"
"orly.dev/app/relay/helpers"
"orly.dev/app/relay/options"
"orly.dev/app/relay/publish"
@@ -14,10 +15,8 @@ import (
"orly.dev/utils/chk"
"orly.dev/utils/log"
"strconv"
"sync"
"time"
"github.com/fasthttp/websocket"
"github.com/rs/cors"
"orly.dev/interfaces/signer"
@@ -26,30 +25,26 @@ import (
)
type Server struct {
Ctx context.T
Cancel context.F
options *options.T
relay relay.I
clientsMu sync.Mutex
clients map[*websocket.Conn]struct{}
Addr string
mux *servemux.S
httpServer *http.Server
listeners *publish.S
authRequired bool
publicReadable bool
Ctx context.T
Cancel context.F
options *options.T
relay relay.I
Addr string
mux *servemux.S
httpServer *http.Server
listeners *publish.S
*config.C
}
type ServerParams struct {
Ctx context.T
Cancel context.F
Rl relay.I
DbPath string
MaxLimit int
Admins []signer.I
Owners [][]byte
AuthRequired bool
PublicReadable bool
Ctx context.T
Cancel context.F
Rl relay.I
DbPath string
MaxLimit int
Admins []signer.I
Owners [][]byte
*config.C
}
func NewServer(sp *ServerParams, opts ...options.O) (s *Server, err error) {
@@ -64,17 +59,13 @@ func NewServer(sp *ServerParams, opts ...options.O) (s *Server, err error) {
}
serveMux := servemux.NewServeMux()
s = &Server{
Ctx: sp.Ctx,
Cancel: sp.Cancel,
relay: sp.Rl,
clients: make(map[*websocket.Conn]struct{}),
mux: serveMux,
options: op,
listeners: publish.New(
socketapi.New(),
),
authRequired: sp.AuthRequired,
publicReadable: sp.PublicReadable,
Ctx: sp.Ctx,
Cancel: sp.Cancel,
relay: sp.Rl,
mux: serveMux,
options: op,
listeners: publish.New(socketapi.New()),
C: sp.C,
}
go func() {
if err := s.relay.Init(); chk.E(err) {

View File

@@ -27,7 +27,6 @@ type I interface {
message []byte,
)
Context() context.T
Disconnect()
Publisher() *publish.S
Publish(c context.T, evt *event.E) (err error)
Relay() relay.I

13
main.go
View File

@@ -59,13 +59,12 @@ func main() {
go app.MonitorResources(c)
var server *relay.Server
serverParams := &relay.ServerParams{
Ctx: c,
Cancel: cancel,
Rl: r,
DbPath: cfg.DataDir,
MaxLimit: 512, // Default max limit for events
AuthRequired: cfg.AuthRequired,
PublicReadable: cfg.PublicReadable,
Ctx: c,
Cancel: cancel,
Rl: r,
DbPath: cfg.DataDir,
MaxLimit: 512, // Default max limit for events
C: cfg,
}
var opts []options.O
if server, err = relay.NewServer(serverParams, opts...); chk.E(err) {

View File

@@ -24,18 +24,18 @@ import (
//
// Parameters:
//
// - c: A context object used for managing deadlines, cancellation signals,
// - c: a context object used for managing deadlines, cancellation signals,
// and other request-scoped values.
//
// - req: A byte slice representing the raw request containing the event
// - req: a byte slice representing the raw request containing the event
// details to be processed.
//
// - srv: An interface representing the server context, providing access to
// - srv: an interface representing the server context, providing access to
// storage and other server-level utilities.
//
// Return values:
//
// - msg: A byte slice representing the response message generated by the
// - msg: a byte slice representing the response message generated by the
// method. The content depends on the processing outcome.
//
// Expected behavior: