From a6a785640f9d8fc8ceabd003ba2dc46c36122f24 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 29 Sep 2021 19:15:04 +0100 Subject: [PATCH] Better error message when listening on DHT --- README.md | 2 +- crates/dht/src/dht.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c4b66c..0cadede 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Use a regex here to select files by their names. Below points are all easily fixable, PRs welcome. - The CLI support only one mode of operation: download one torrent to a given folder. -- If you try to run multiple instances, there's some port conflicts (already listening on port) +- If you try to run multiple instances, there's some port conflicts (already listening on port). This happens because DHT stores persistence information on disk, and that includes the port it last listened on. So all instances try to listen on the same port. Which means we need to add support for managing multiple torrents rather than trying to run the client multiple times. Or at least add a switch like --disable-dht-persistence. - HTTP API is rudimentary, mostly for looking at stats. E.g. you can't add a torrent through it. - Only supports BitTorrent V1 over TCP - As this was created for personal needs, and for educational purposes, documentation, commit message quality etc. leave a lot to be desired. diff --git a/crates/dht/src/dht.rs b/crates/dht/src/dht.rs index da9a025..ef56727 100644 --- a/crates/dht/src/dht.rs +++ b/crates/dht/src/dht.rs @@ -624,10 +624,13 @@ impl Dht { } pub async fn with_config(config: DhtConfig) -> anyhow::Result { let socket = match config.listen_addr { - Some(addr) => UdpSocket::bind(addr).await, - None => UdpSocket::bind("0.0.0.0:0").await, - } - .context("error binding socket")?; + Some(addr) => UdpSocket::bind(addr) + .await + .with_context(|| format!("error binding socket, address {}", addr)), + None => UdpSocket::bind("0.0.0.0:0") + .await + .context("error binding socket, address 0.0.0.0:0"), + }?; let listen_addr = socket .local_addr()