diff --git a/count.go b/count.go index d4c0993..482a9e9 100644 --- a/count.go +++ b/count.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "strings" - "time" "fiatjaf.com/nostr" "fiatjaf.com/nostr/nip45" @@ -67,7 +66,7 @@ var count = &cli.Command{ nm := nostr.NormalizeURL(relayUrl) relay, ok := sys.Pool.Relays.Load(nm) if !ok || relay == nil || !relay.IsConnected() { - ct, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ct, cancel := context.WithTimeout(context.Background(), connectTimeout) var err error relay, err = nostr.RelayConnect(ct, relayUrl, sys.Pool.RelayOptions) cancel() diff --git a/event.go b/event.go index b62137d..63ecc21 100644 --- a/event.go +++ b/event.go @@ -548,7 +548,7 @@ func publishFlow(ctx context.Context, c *cli.Command, kr nostr.Signer, evt nostr relays[i] = r relay = r } else { - ct, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ct, cancel := context.WithTimeout(context.Background(), connectTimeout) new_, err := nostr.RelayConnect(ct, relay.URL, sys.Pool.RelayOptions) cancel() if err == nil { diff --git a/group.go b/group.go index d5918ac..55c3366 100644 --- a/group.go +++ b/group.go @@ -246,7 +246,7 @@ var group = &cli.Command{ nm := nostr.NormalizeURL(relay) r, ok := sys.Pool.Relays.Load(nm) if !ok || r == nil || !r.IsConnected() { - ct, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ct, cancel := context.WithTimeout(context.Background(), connectTimeout) var err error r, err = nostr.RelayConnect(ct, relay, sys.Pool.RelayOptions) cancel() @@ -327,7 +327,7 @@ var group = &cli.Command{ nm := nostr.NormalizeURL(relay) r, ok := sys.Pool.Relays.Load(nm) if !ok || r == nil || !r.IsConnected() { - ct, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ct, cancel := context.WithTimeout(context.Background(), connectTimeout) var err error r, err = nostr.RelayConnect(ct, relay, sys.Pool.RelayOptions) cancel() @@ -493,7 +493,7 @@ write your forum post nm := nostr.NormalizeURL(relay) r, ok := sys.Pool.Relays.Load(nm) if !ok || r == nil || !r.IsConnected() { - ct, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ct, cancel := context.WithTimeout(context.Background(), connectTimeout) var err error r, err = nostr.RelayConnect(ct, relay, sys.Pool.RelayOptions) cancel() @@ -608,7 +608,7 @@ write your forum post nm := nostr.NormalizeURL(relay) r, ok := sys.Pool.Relays.Load(nm) if !ok || r == nil || !r.IsConnected() { - ct, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ct, cancel := context.WithTimeout(context.Background(), connectTimeout) var err error r, err = nostr.RelayConnect(ct, relay, sys.Pool.RelayOptions) cancel() @@ -941,7 +941,7 @@ func publishModerationEvent(ctx context.Context, c *cli.Command, kind nostr.Kind nm := nostr.NormalizeURL(relay) r, ok := sys.Pool.Relays.Load(nm) if !ok || r == nil || !r.IsConnected() { - ct, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ct, cancel := context.WithTimeout(context.Background(), connectTimeout) var err error r, err = nostr.RelayConnect(ct, relay, sys.Pool.RelayOptions) cancel() diff --git a/helpers.go b/helpers.go index 5adbffc..7dcb120 100644 --- a/helpers.go +++ b/helpers.go @@ -48,6 +48,8 @@ var ( stdout = func(args ...any) { fmt.Fprintln(color.Output, args...) } ) +var connectTimeout = 2 * time.Second + func isPiped() bool { stat, err := os.Stdin.Stat() if err != nil { @@ -272,7 +274,7 @@ func connectToSingleRelay( relay, ok := sys.Pool.Relays.Load(nm) if !ok || relay == nil || !relay.IsConnected() { - connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + connectCtx, cancel := context.WithTimeout(context.Background(), connectTimeout) defer cancel() var err error diff --git a/main.go b/main.go index 623afd8..a6ce429 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strings" + "time" "fiatjaf.com/nostr" "fiatjaf.com/nostr/nip42" @@ -42,6 +43,7 @@ var defaultKeyFlags = []cli.Flag{ Name: "prompt-sec", Usage: "prompt the user to paste a hex or nsec with which to sign the event", Category: CATEGORY_SIGNER, + Hidden: true, }, &SecretKeyFlag{ Name: "connect-as", @@ -50,6 +52,7 @@ var defaultKeyFlags = []cli.Flag{ Sources: cli.EnvVars("NOSTR_CLIENT_KEY"), Value: defaultKey(), DefaultText: "the default key (see `nak key default`)", + Hidden: true, }, } @@ -128,6 +131,7 @@ var app = &cli.Command{ } return nil }, + Hidden: true, }, &cli.BoolFlag{ Name: "verbose", @@ -141,6 +145,17 @@ var app = &cli.Command{ } return nil }, + Hidden: true, + }, + &cli.DurationFlag{ + Name: "connect-timeout", + Usage: "timeout for connecting to relays", + Value: connectTimeout, + Action: func(ctx context.Context, c *cli.Command, d time.Duration) error { + connectTimeout = d + return nil + }, + Hidden: true, }, }, defaultKeyFlags,