mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 11:43:43 +00:00
Tunstenite and reqwest connect timeout
This commit is contained in:
parent
a5c5627749
commit
0d503a5857
@ -42,6 +42,9 @@ pub enum Error {
|
||||
#[error("SQL: {0}")]
|
||||
Sql(#[from] rusqlite::Error),
|
||||
|
||||
#[error("Timeout: {0}")]
|
||||
Timeout(#[from] tokio::time::error::Elapsed),
|
||||
|
||||
#[error("URL has empty hostname")]
|
||||
UrlHasEmptyHostname,
|
||||
|
||||
|
@ -92,13 +92,15 @@ impl Minion {
|
||||
return Err(Error::UrlHasEmptyHostname);
|
||||
}
|
||||
|
||||
// Read NIP-11 information
|
||||
if let Ok(response) = reqwest::Client::new()
|
||||
.get(&format!("https://{}", host))
|
||||
let request_nip11_future = reqwest::Client::new()
|
||||
.get(format!("https://{}", host))
|
||||
.header("Host", host)
|
||||
.header("Accept", "application/nostr+json")
|
||||
.send()
|
||||
.await
|
||||
.send();
|
||||
|
||||
// Read NIP-11 information
|
||||
if let Ok(response) =
|
||||
tokio::time::timeout(std::time::Duration::new(15, 0), request_nip11_future).await?
|
||||
{
|
||||
match response.json::<RelayInformationDocument>().await {
|
||||
Ok(nip11) => {
|
||||
@ -130,8 +132,11 @@ impl Minion {
|
||||
accept_unmasked_frames: true, // default is false which is the standard
|
||||
};
|
||||
|
||||
let (websocket_stream, _response) =
|
||||
tokio_tungstenite::connect_async_with_config(req, Some(config)).await?;
|
||||
let (websocket_stream, _response) = tokio::time::timeout(
|
||||
std::time::Duration::new(15, 0),
|
||||
tokio_tungstenite::connect_async_with_config(req, Some(config)),
|
||||
)
|
||||
.await??;
|
||||
info!("Connected to {}", &self.url);
|
||||
|
||||
websocket_stream
|
||||
|
Loading…
Reference in New Issue
Block a user