Skip to content

Commit 126255c

Browse files
committed
fix: move authCallbackTimeout to NdkConfig
1 parent af73035 commit 126255c

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

packages/ndk/lib/config/request_defaults.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ class RequestDefaults {
2424

2525
/// default User-Agent header value used for websocket connections
2626
static const String DEFAULT_USER_AGENT = "dart-NDK/$packageVersion";
27+
28+
/// default timeout for AUTH callbacks (how long to wait for AUTH OK)
29+
static const Duration DEFAULT_AUTH_CALLBACK_TIMEOUT = Duration(seconds: 30);
2730
}

packages/ndk/lib/domain_layer/usecases/relay_manager.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:rxdart/rxdart.dart';
55

66
import '../../config/bootstrap_relays.dart';
77
import '../../config/relay_defaults.dart';
8+
import '../../config/request_defaults.dart';
89
import '../../shared/decode_nostr_msg/decode_nostr_msg.dart';
910
import '../../shared/helpers/relay_helper.dart';
1011
import '../../shared/isolates/isolate_manager.dart';
@@ -51,7 +52,7 @@ class RelayManager<T> {
5152
final Map<String, Timer> _pendingAuthTimers = {};
5253

5354
/// timeout for AUTH callbacks (how long to wait for AUTH OK)
54-
static const Duration _authCallbackTimeout = Duration(seconds: 30);
55+
final Duration authCallbackTimeout;
5556

5657
/// nostr transport factory, to create new transports (usually websocket)
5758
final NostrTransportFactory nostrTransportFactory;
@@ -82,6 +83,7 @@ class RelayManager<T> {
8283
List<String>? bootstrapRelays,
8384
allowReconnect = true,
8485
this.eagerAuth = false,
86+
this.authCallbackTimeout = RequestDefaults.DEFAULT_AUTH_CALLBACK_TIMEOUT,
8587
}) : _accounts = accounts {
8688
allowReconnectRelays = allowReconnect;
8789
_connectSeedRelays(urls: bootstrapRelays ?? DEFAULT_BOOTSTRAP_RELAYS);
@@ -779,7 +781,7 @@ class RelayManager<T> {
779781
};
780782

781783
// Start timeout timer to clean up orphaned callbacks
782-
_pendingAuthTimers[signedAuth.id] = Timer(_authCallbackTimeout, () {
784+
_pendingAuthTimers[signedAuth.id] = Timer(authCallbackTimeout, () {
783785
Logger.log.w(
784786
"AUTH callback timeout for ${signedAuth.id} on ${relayConnectivity.url}");
785787
_pendingAuthCallbacks.remove(signedAuth.id);
@@ -854,7 +856,7 @@ class RelayManager<T> {
854856
};
855857

856858
// Start timeout timer to clean up orphaned callbacks
857-
_pendingAuthTimers[signedAuth.id] = Timer(_authCallbackTimeout, () {
859+
_pendingAuthTimers[signedAuth.id] = Timer(authCallbackTimeout, () {
858860
Logger.log.w(
859861
"AUTH callback timeout for ${signedAuth.id} on ${relayConnectivity.url}");
860862
_pendingAuthCallbacks.remove(signedAuth.id);

packages/ndk/lib/presentation_layer/init.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Initialization {
108108
nostrTransportFactory: _webSocketNostrTransportFactory,
109109
bootstrapRelays: _ndkConfig.bootstrapRelays,
110110
eagerAuth: _ndkConfig.eagerAuth,
111+
authCallbackTimeout: _ndkConfig.authCallbackTimeout,
111112
);
112113

113114
engine = RelaySetsEngine(
@@ -125,6 +126,7 @@ class Initialization {
125126
bootstrapRelays: _ndkConfig.bootstrapRelays,
126127
engineAdditionalDataFactory: JitEngineRelayConnectivityDataFactory(),
127128
eagerAuth: _ndkConfig.eagerAuth,
129+
authCallbackTimeout: _ndkConfig.authCallbackTimeout,
128130
);
129131

130132
engine = JitEngine(

packages/ndk/lib/presentation_layer/ndk_config.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class NdkConfig {
6666
/// False is more privacy-respecting as it doesn't reveal identity until necessary.
6767
bool eagerAuth;
6868

69+
/// Timeout for AUTH callbacks (how long to wait for AUTH OK response).
70+
/// Defaults to 30 seconds.
71+
Duration authCallbackTimeout;
72+
6973
/// Creates a new instance of [NdkConfig].
7074
///
7175
/// [eventVerifier] The verifier used to validate Nostr events. \
@@ -92,6 +96,7 @@ class NdkConfig {
9296
this.userAgent = RequestDefaults.DEFAULT_USER_AGENT,
9397
this.fetchedRangesEnabled = false,
9498
this.eagerAuth = false,
99+
this.authCallbackTimeout = RequestDefaults.DEFAULT_AUTH_CALLBACK_TIMEOUT,
95100
});
96101
}
97102

0 commit comments

Comments
 (0)