mirror of
https://github.com/fiatjaf/nak.git
synced 2025-09-01 06:20:46 -04:00
connect to relays once per call instead of in each iteration and fail early if no connection works.
This commit is contained in:
16
helpers.go
16
helpers.go
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -99,6 +100,21 @@ func validate32BytesHex(target string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func connectToAllRelays(ctx context.Context, relayUrls []string) (*nostr.SimplePool, []*nostr.Relay) {
|
||||
relays := make([]*nostr.Relay, 0, len(relayUrls))
|
||||
pool := nostr.NewSimplePool(ctx)
|
||||
for _, url := range relayUrls {
|
||||
fmt.Fprintf(os.Stderr, "connecting to %s... ", url)
|
||||
if relay, err := pool.EnsureRelay(url); err == nil {
|
||||
relays = append(relays, relay)
|
||||
fmt.Fprintf(os.Stderr, "ok.\n")
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, err.Error()+"\n")
|
||||
}
|
||||
}
|
||||
return pool, relays
|
||||
}
|
||||
|
||||
func lineProcessingError(c *cli.Context, msg string, args ...any) {
|
||||
c.Context = context.WithValue(c.Context, LINE_PROCESSING_ERROR, true)
|
||||
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
||||
|
Reference in New Issue
Block a user