Skip to content

Commit

Permalink
refactor(clippy): fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kurnevsky committed Apr 25, 2021
1 parent 28e494c commit ffbfd93
Show file tree
Hide file tree
Showing 28 changed files with 185 additions and 185 deletions.
2 changes: 1 addition & 1 deletion tox_core/src/dht/dht_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl From<PackedNode> for DhtNode {
}
}

impl HasPK for DhtNode {
impl HasPk for DhtNode {
fn pk(&self) -> PublicKey {
self.pk
}
Expand Down
20 changes: 10 additions & 10 deletions tox_core/src/dht/kbucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,24 @@ impl Distance for PublicKey {
}

/// Anything that has `PublicKey`.
pub trait HasPK {
pub trait HasPk {
/// `PublicKey`.
fn pk(&self) -> PublicKey;
}

impl HasPK for PackedNode {
impl HasPk for PackedNode {
fn pk(&self) -> PublicKey {
self.pk
}
}

/// Node that can be stored in a `Kbucket`.
pub trait KbucketNode : Sized + HasPK {
pub trait KbucketNode : Sized + HasPk {
/// The type of nodes that can be added to a `Kbucket`.
type NewNode: HasPK;
type NewNode: HasPk;
/// The type of nodes that can be checked if they can be added to a
/// `Kbucket`.
type CheckNode: HasPK;
type CheckNode: HasPk;

/// Check if the node can be updated with a new one.
fn is_outdated(&self, other: &Self::CheckNode) -> bool;
Expand Down Expand Up @@ -143,9 +143,9 @@ pub struct Kbucket<Node> {
pub nodes: Vec<Node>,
}

impl<Node> Into<Vec<Node>> for Kbucket<Node> {
fn into(self) -> Vec<Node> {
self.nodes
impl<Node> From<Kbucket<Node>> for Vec<Node> {
fn from(kbucket: Kbucket<Node>) -> Self {
kbucket.nodes
}
}

Expand All @@ -154,8 +154,8 @@ pub const KBUCKET_DEFAULT_SIZE: u8 = 8;

impl<NewNode, CheckNode, Node> Kbucket<Node>
where
NewNode: HasPK,
CheckNode: HasPK,
NewNode: HasPk,
CheckNode: HasPk,
Node: KbucketNode<NewNode = NewNode, CheckNode = CheckNode> + From<NewNode>
{
/** Create a new `Kbucket` to store nodes close to the `PublicKey`.
Expand Down
32 changes: 16 additions & 16 deletions tox_core/src/dht/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,15 +1375,15 @@ impl Server {

if let (ip_port, None) = payload {
match ip_port.protocol {
ProtocolType::UDP => {
ProtocolType::Udp => {
let next_packet = match packet.payload {
InnerOnionResponse::OnionAnnounceResponse(inner) => Packet::OnionAnnounceResponse(inner),
InnerOnionResponse::OnionDataResponse(inner) => Packet::OnionDataResponse(inner),
};
self.send_to(ip_port.to_saddr(), next_packet).await
.map_err(|e| e.context(HandlePacketErrorKind::SendTo).into())
},
ProtocolType::TCP => {
ProtocolType::Tcp => {
if let Some(ref tcp_onion_sink) = self.tcp_onion_sink {
tcp_onion_sink.clone().send((packet.payload, ip_port.to_saddr())).await
.map_err(|e| e.context(HandlePacketErrorKind::OnionResponseRedirect).into())
Expand Down Expand Up @@ -2359,7 +2359,7 @@ mod tests {
let temporary_pk = gen_keypair().0;
let inner = vec![42; 123];
let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2411,7 +2411,7 @@ mod tests {
let temporary_pk = gen_keypair().0;
let inner = vec![42; 123];
let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2474,7 +2474,7 @@ mod tests {
payload: vec![42; 123]
};
let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2516,7 +2516,7 @@ mod tests {
payload: vec![42; 123]
};
let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2721,7 +2721,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2786,7 +2786,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2814,7 +2814,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2879,7 +2879,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2907,7 +2907,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2941,7 +2941,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -2979,7 +2979,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::TCP,
protocol: ProtocolType::Tcp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -3010,7 +3010,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::TCP,
protocol: ProtocolType::Tcp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -3063,7 +3063,7 @@ mod tests {
let onion_symmetric_key = alice.onion_symmetric_key.read().await;

let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down Expand Up @@ -3201,7 +3201,7 @@ mod tests {
let temporary_pk = gen_keypair().0;
let payload = vec![42; 123];
let ip_port = IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: "5.6.7.8".parse().unwrap(),
port: 12345
};
Expand Down
12 changes: 6 additions & 6 deletions tox_core/src/net_crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ impl From<StatusPacket> for Packet {
}
}

impl Into<DhtPacket> for Packet {
fn into(self) -> DhtPacket {
match self {
impl From<Packet> for DhtPacket {
fn from(packet: Packet) -> Self {
match packet {
Packet::CookieRequest(packet) => DhtPacket::CookieRequest(packet),
Packet::CryptoHandshake(packet) => DhtPacket::CryptoHandshake(packet),
Packet::CryptoData(packet) => DhtPacket::CryptoData(packet),
}
}
}

impl Into<TcpDataPayload> for Packet {
fn into(self) -> TcpDataPayload {
match self {
impl From<Packet> for TcpDataPayload {
fn from(packet: Packet) -> Self {
match packet {
Packet::CookieRequest(packet) => TcpDataPayload::CookieRequest(packet),
Packet::CryptoHandshake(packet) => TcpDataPayload::CryptoHandshake(packet),
Packet::CryptoData(packet) => TcpDataPayload::CryptoData(packet),
Expand Down
30 changes: 15 additions & 15 deletions tox_core/src/onion/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct OnionNode {
announce_status: AnnounceStatus,
}

impl HasPK for OnionNode {
impl HasPk for OnionNode {
fn pk(&self) -> PublicKey {
self.pk
}
Expand Down Expand Up @@ -393,14 +393,14 @@ impl OnionClient {
async fn send_onion_request(&self, path: OnionPath, inner_onion_request: InnerOnionRequest, saddr: SocketAddr)
-> Result<(), mpsc::SendError> {
match path.path_type {
OnionPathType::TCP => {
OnionPathType::Tcp => {
let onion_request = path.create_tcp_onion_request(saddr, inner_onion_request);
// TODO: can we handle errors better? Right now we can try send a
// request to a non-existent or suspended node which returns an error
self.tcp_connections.send_onion(path.nodes[0].public_key, onion_request).await.ok();
Ok(())
},
OnionPathType::UDP => {
OnionPathType::Udp => {
let onion_request =
path.create_udp_onion_request(saddr, inner_onion_request);
let mut tx = self.dht.tx.clone();
Expand Down Expand Up @@ -549,12 +549,12 @@ impl OnionClient {

for node in dht_pk_announce.nodes.into_iter() {
match node.ip_port.protocol {
ProtocolType::UDP => {
ProtocolType::Udp => {
let packed_node = PackedNode::new(node.ip_port.to_saddr(), &node.pk);
self.dht.ping_node(&packed_node).await
.map_err(|e| e.context(HandleDhtPkAnnounceErrorKind::PingNode))?;
},
ProtocolType::TCP => {
ProtocolType::Tcp => {
self.tcp_connections.add_relay_connection(node.ip_port.to_saddr(), node.pk, dht_pk_announce.dht_pk).await
.map_err(|e| e.context(HandleDhtPkAnnounceErrorKind::AddRelay))?;
}
Expand Down Expand Up @@ -979,7 +979,7 @@ mod tests {
saddr,
path_id: OnionPathId {
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
path_type: OnionPathType::UDP,
path_type: OnionPathType::Udp,
},
ping_id: None,
data_pk: None,
Expand All @@ -1005,7 +1005,7 @@ mod tests {
saddr: "127.0.0.1:12345".parse().unwrap(),
path_id: OnionPathId {
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
path_type: OnionPathType::UDP,
path_type: OnionPathType::Udp,
},
ping_id: None,
data_pk: None,
Expand All @@ -1019,7 +1019,7 @@ mod tests {
let saddr = "127.0.0.1:12346".parse().unwrap();
let path_id = OnionPathId {
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
path_type: OnionPathType::UDP,
path_type: OnionPathType::Udp,
};
let ping_id = sha256::hash(&[1, 2, 3]);
let data_pk = gen_keypair().0;
Expand Down Expand Up @@ -1060,7 +1060,7 @@ mod tests {
saddr: "127.0.0.1:12345".parse().unwrap(),
path_id: OnionPathId {
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
path_type: OnionPathType::UDP,
path_type: OnionPathType::Udp,
},
ping_id: None,
data_pk: None,
Expand Down Expand Up @@ -1509,7 +1509,7 @@ mod tests {
saddr,
path_id: OnionPathId {
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
path_type: OnionPathType::UDP,
path_type: OnionPathType::Udp,
},
friend_pk: Some(friend_pk),
};
Expand Down Expand Up @@ -1553,7 +1553,7 @@ mod tests {
saddr,
path_id: OnionPathId {
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
path_type: OnionPathType::UDP,
path_type: OnionPathType::Udp,
},
friend_pk: Some(friend_pk),
};
Expand Down Expand Up @@ -1661,7 +1661,7 @@ mod tests {
let dht_pk_announce_payload = DhtPkAnnouncePayload::new(friend_dht_pk, vec![
TcpUdpPackedNode {
ip_port: IpPort {
protocol: ProtocolType::UDP,
protocol: ProtocolType::Udp,
ip_addr: saddr.ip(),
port: saddr.port(),
},
Expand Down Expand Up @@ -1723,7 +1723,7 @@ mod tests {
let dht_pk_announce_payload = DhtPkAnnouncePayload::new(friend_dht_pk, vec![
TcpUdpPackedNode {
ip_port: IpPort {
protocol: ProtocolType::TCP,
protocol: ProtocolType::Tcp,
ip_addr: "127.0.0.2".parse().unwrap(),
port: 12346,
},
Expand Down Expand Up @@ -2353,7 +2353,7 @@ mod tests {
PackedNode::new("127.0.0.1:12346".parse().unwrap(), &gen_keypair().0),
PackedNode::new("127.0.0.1:12347".parse().unwrap(), &gen_keypair().0),
PackedNode::new("127.0.0.1:12348".parse().unwrap(), &gen_keypair().0),
], OnionPathType::UDP);
], OnionPathType::Udp);
let saddr = "127.0.0.1:12345".parse().unwrap();
onion_client.send_onion_request(path, inner_onion_request, saddr).await.unwrap();

Expand Down Expand Up @@ -2381,7 +2381,7 @@ mod tests {
PackedNode::new("127.0.0.1:12346".parse().unwrap(), &relay_pk),
PackedNode::new("127.0.0.1:12347".parse().unwrap(), &gen_keypair().0),
PackedNode::new("127.0.0.1:12348".parse().unwrap(), &gen_keypair().0),
], OnionPathType::TCP);
], OnionPathType::Tcp);
let saddr = "127.0.0.1:12345".parse().unwrap();
onion_client.send_onion_request(path, inner_onion_request, saddr).await.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions tox_core/src/onion/client/nodes_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl NodesPool {
break;
}
}
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::UDP))
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::Udp))
}

/// Build new random onion path with first TCP node.
Expand All @@ -95,7 +95,7 @@ impl NodesPool {
break;
}
}
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::TCP))
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::Tcp))
}
}

Expand Down
Loading

0 comments on commit ffbfd93

Please sign in to comment.