Skip to content

Commit

Permalink
dht: fix build wrong
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaobo Liu <[email protected]>
  • Loading branch information
cppcoffee committed Feb 21, 2023
1 parent 68e6b7c commit 14ed8d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ description = "A sniffer of DHT"
[dependencies]
env_logger = "0.7"
log = "0.4"
thiserror = "1.0"
thiserror = "1"
anyhow = "1.0"
rand = "0.7"
sha1 = "0.6"
async-std = { version = "1.6", features = ["unstable"] }
lru-cache = "0.1"
structopt = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_json = "1"
bencode = { path = "bencode" }
9 changes: 5 additions & 4 deletions src/dht.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::collections::HashMap;
use std::time::Duration;

use async_std::channel::{Receiver, Sender};
use async_std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
use async_std::sync::{channel, Arc, Receiver, Sender};
use async_std::task;
use async_std::sync::Arc;
use async_std::{channel, task};
use bencode::Value;
use log::{debug, info};
use rand::prelude::*;
Expand Down Expand Up @@ -50,7 +51,7 @@ impl DHT {
let sock = UdpSocket::bind(self.laddr.as_ref()).await?;
self.socket = Arc::new(Some(sock));

let (tx, rx) = channel(self.peers);
let (tx, rx) = channel::bounded(self.peers);

self.start_message_handler(tx);
self.start_join();
Expand Down Expand Up @@ -240,7 +241,7 @@ impl DHT {
info!("channel is full, skip.");
} else {
let ac = self.summarize(v, addr)?;
tx.send(ac).await;
tx.send(ac).await.map_err(|e| Error::Send(e.into_inner()))?;
}

Ok(())
Expand Down
7 changes: 7 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::Message;
use async_std::io::Error as AsyncIoError;
use bencode::Error as BencodeError;
use thiserror::Error as ThisError;
Expand All @@ -6,10 +7,16 @@ use thiserror::Error as ThisError;
pub enum Error {
#[error(transparent)]
AsyncIo(#[from] AsyncIoError),

#[error(transparent)]
Bencode(#[from] BencodeError),

#[error("send fail, message: {0:?}")]
Send(Message),

#[error("bencode dict not found '{0}'")]
DictNotFound(String),

#[error("{0}")]
Other(String),
}
Expand Down

0 comments on commit 14ed8d1

Please sign in to comment.