Skip to content

Commit 00b7977

Browse files
committed
feat: timeout for relay connection
1 parent 9a69ac4 commit 00b7977

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

settings.tpl.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ payment_retries_interval = 60
2121
[nostr]
2222
nsec_privkey = 'nsec1...'
2323
relays = ['ws://localhost:7000']
24+
# Seconds to wait for relay connections at startup before continuing (default: 5)
25+
# relay_connection_timeout_secs = 5
2426

2527
[mostro]
2628
# NIP-01 Kind 0 Metadata (optional)

src/app/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ pub mod test_utils {
262262
nsec_privkey: "nsec13as48eum93hkg7plv526r9gjpa0uc52zysqm93pmnkca9e69x6tsdjmdxd"
263263
.to_string(),
264264
relays: vec!["wss://relay.test".to_string()],
265+
relay_connection_timeout_secs: 5,
265266
},
266267
mostro: MostroSettings::default(),
267268
lightning: LightningSettings::default(),

src/config/types.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ pub struct NostrSettings {
129129
pub nsec_privkey: String,
130130
/// Nostr relays list
131131
pub relays: Vec<String>,
132+
/// Seconds to wait for relay connections at startup before continuing (default: 5)
133+
#[serde(default = "default_relay_connection_timeout_secs")]
134+
pub relay_connection_timeout_secs: u64,
135+
}
136+
137+
fn default_relay_connection_timeout_secs() -> u64 {
138+
5
132139
}
133140
/// RPC configuration settings
134141
#[derive(Debug, Deserialize, Clone)]

src/util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,10 @@ pub async fn connect_nostr() -> Result<Client, MostroError> {
779779
.map_err(|e| MostroInternalErr(ServiceError::NostrError(e.to_string())))?;
780780
}
781781

782-
// Connect to relays and keep connection alive
782+
let timeout =
783+
std::time::Duration::from_secs(nostr_settings.relay_connection_timeout_secs);
783784
client.connect().await;
785+
client.wait_for_connection(timeout).await;
784786

785787
Ok(client)
786788
}

0 commit comments

Comments
 (0)