diff options
author | hozan23 <hozan23@proton.me> | 2024-03-13 03:35:09 +0100 |
---|---|---|
committer | hozan23 <hozan23@proton.me> | 2024-03-13 03:35:09 +0100 |
commit | 76e952830302271e07a4be9df6dfaa1c11e3e675 (patch) | |
tree | 41202b50d07821caeee8fc2332bf9b5cc0f5f413 /p2p | |
parent | 5f403823fa3c2ef0c85dd81fe3601d084d0067e5 (diff) |
net: pass `Endpoint` to dial and listen functions
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/src/discovery/refresh.rs | 5 | ||||
-rw-r--r-- | p2p/src/listener.rs | 4 |
2 files changed, 6 insertions, 3 deletions
diff --git a/p2p/src/discovery/refresh.rs b/p2p/src/discovery/refresh.rs index ed111fb..882a93e 100644 --- a/p2p/src/discovery/refresh.rs +++ b/p2p/src/discovery/refresh.rs @@ -195,7 +195,8 @@ impl RefreshService { /// specified in the Config, with backoff between each retry. async fn connect(&self, entry: &Entry) -> Result<()> { let mut retry = 0; - let conn = dial_udp(&entry.addr, &entry.discovery_port).await?; + let endpoint = Endpoint::Ws(entry.addr.clone(), entry.discovery_port); + let conn = dial_udp(&endpoint).await?; let backoff = Backoff::new(100, 5000); while retry < self.config.refresh_connect_retries { match self.send_ping_msg(&conn).await { @@ -217,7 +218,7 @@ impl RefreshService { /// peers. async fn listen_loop(self: Arc<Self>, addr: Addr, port: Port) -> Result<()> { let endpoint = Endpoint::Udp(addr.clone(), port); - let conn = match listen_udp(&addr, &port).await { + let conn = match listen_udp(&endpoint).await { Ok(c) => { self.monitor .notify(&ConnEvent::Listening(endpoint.clone()).into()) diff --git a/p2p/src/listener.rs b/p2p/src/listener.rs index ab6f7c1..254e4e6 100644 --- a/p2p/src/listener.rs +++ b/p2p/src/listener.rs @@ -155,7 +155,9 @@ impl Listener { async fn listend(&self, endpoint: &Endpoint) -> Result<Box<dyn ConnListener>> { if self.enable_tls { let tls_config = tls_server_config(&self.key_pair)?; - tls::listen(endpoint, tls_config).await + tls::listen_tls(endpoint, tls_config) + .await + .map(|l| Box::new(l) as Box<dyn ConnListener>) } else { listen(endpoint).await } |