Skip to content

Commit ffbfd93

Browse files
committed
refactor(clippy): fix warnings
1 parent 28e494c commit ffbfd93

28 files changed

+185
-185
lines changed

tox_core/src/dht/dht_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl From<PackedNode> for DhtNode {
195195
}
196196
}
197197

198-
impl HasPK for DhtNode {
198+
impl HasPk for DhtNode {
199199
fn pk(&self) -> PublicKey {
200200
self.pk
201201
}

tox_core/src/dht/kbucket.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,24 @@ impl Distance for PublicKey {
6666
}
6767

6868
/// Anything that has `PublicKey`.
69-
pub trait HasPK {
69+
pub trait HasPk {
7070
/// `PublicKey`.
7171
fn pk(&self) -> PublicKey;
7272
}
7373

74-
impl HasPK for PackedNode {
74+
impl HasPk for PackedNode {
7575
fn pk(&self) -> PublicKey {
7676
self.pk
7777
}
7878
}
7979

8080
/// Node that can be stored in a `Kbucket`.
81-
pub trait KbucketNode : Sized + HasPK {
81+
pub trait KbucketNode : Sized + HasPk {
8282
/// The type of nodes that can be added to a `Kbucket`.
83-
type NewNode: HasPK;
83+
type NewNode: HasPk;
8484
/// The type of nodes that can be checked if they can be added to a
8585
/// `Kbucket`.
86-
type CheckNode: HasPK;
86+
type CheckNode: HasPk;
8787

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

146-
impl<Node> Into<Vec<Node>> for Kbucket<Node> {
147-
fn into(self) -> Vec<Node> {
148-
self.nodes
146+
impl<Node> From<Kbucket<Node>> for Vec<Node> {
147+
fn from(kbucket: Kbucket<Node>) -> Self {
148+
kbucket.nodes
149149
}
150150
}
151151

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

155155
impl<NewNode, CheckNode, Node> Kbucket<Node>
156156
where
157-
NewNode: HasPK,
158-
CheckNode: HasPK,
157+
NewNode: HasPk,
158+
CheckNode: HasPk,
159159
Node: KbucketNode<NewNode = NewNode, CheckNode = CheckNode> + From<NewNode>
160160
{
161161
/** Create a new `Kbucket` to store nodes close to the `PublicKey`.

tox_core/src/dht/server/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,15 +1375,15 @@ impl Server {
13751375

13761376
if let (ip_port, None) = payload {
13771377
match ip_port.protocol {
1378-
ProtocolType::UDP => {
1378+
ProtocolType::Udp => {
13791379
let next_packet = match packet.payload {
13801380
InnerOnionResponse::OnionAnnounceResponse(inner) => Packet::OnionAnnounceResponse(inner),
13811381
InnerOnionResponse::OnionDataResponse(inner) => Packet::OnionDataResponse(inner),
13821382
};
13831383
self.send_to(ip_port.to_saddr(), next_packet).await
13841384
.map_err(|e| e.context(HandlePacketErrorKind::SendTo).into())
13851385
},
1386-
ProtocolType::TCP => {
1386+
ProtocolType::Tcp => {
13871387
if let Some(ref tcp_onion_sink) = self.tcp_onion_sink {
13881388
tcp_onion_sink.clone().send((packet.payload, ip_port.to_saddr())).await
13891389
.map_err(|e| e.context(HandlePacketErrorKind::OnionResponseRedirect).into())
@@ -2359,7 +2359,7 @@ mod tests {
23592359
let temporary_pk = gen_keypair().0;
23602360
let inner = vec![42; 123];
23612361
let ip_port = IpPort {
2362-
protocol: ProtocolType::UDP,
2362+
protocol: ProtocolType::Udp,
23632363
ip_addr: "5.6.7.8".parse().unwrap(),
23642364
port: 12345
23652365
};
@@ -2411,7 +2411,7 @@ mod tests {
24112411
let temporary_pk = gen_keypair().0;
24122412
let inner = vec![42; 123];
24132413
let ip_port = IpPort {
2414-
protocol: ProtocolType::UDP,
2414+
protocol: ProtocolType::Udp,
24152415
ip_addr: "5.6.7.8".parse().unwrap(),
24162416
port: 12345
24172417
};
@@ -2474,7 +2474,7 @@ mod tests {
24742474
payload: vec![42; 123]
24752475
};
24762476
let ip_port = IpPort {
2477-
protocol: ProtocolType::UDP,
2477+
protocol: ProtocolType::Udp,
24782478
ip_addr: "5.6.7.8".parse().unwrap(),
24792479
port: 12345
24802480
};
@@ -2516,7 +2516,7 @@ mod tests {
25162516
payload: vec![42; 123]
25172517
};
25182518
let ip_port = IpPort {
2519-
protocol: ProtocolType::UDP,
2519+
protocol: ProtocolType::Udp,
25202520
ip_addr: "5.6.7.8".parse().unwrap(),
25212521
port: 12345
25222522
};
@@ -2721,7 +2721,7 @@ mod tests {
27212721
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
27222722

27232723
let ip_port = IpPort {
2724-
protocol: ProtocolType::UDP,
2724+
protocol: ProtocolType::Udp,
27252725
ip_addr: "5.6.7.8".parse().unwrap(),
27262726
port: 12345
27272727
};
@@ -2786,7 +2786,7 @@ mod tests {
27862786
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
27872787

27882788
let ip_port = IpPort {
2789-
protocol: ProtocolType::UDP,
2789+
protocol: ProtocolType::Udp,
27902790
ip_addr: "5.6.7.8".parse().unwrap(),
27912791
port: 12345
27922792
};
@@ -2814,7 +2814,7 @@ mod tests {
28142814
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
28152815

28162816
let ip_port = IpPort {
2817-
protocol: ProtocolType::UDP,
2817+
protocol: ProtocolType::Udp,
28182818
ip_addr: "5.6.7.8".parse().unwrap(),
28192819
port: 12345
28202820
};
@@ -2879,7 +2879,7 @@ mod tests {
28792879
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
28802880

28812881
let ip_port = IpPort {
2882-
protocol: ProtocolType::UDP,
2882+
protocol: ProtocolType::Udp,
28832883
ip_addr: "5.6.7.8".parse().unwrap(),
28842884
port: 12345
28852885
};
@@ -2907,7 +2907,7 @@ mod tests {
29072907
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
29082908

29092909
let ip_port = IpPort {
2910-
protocol: ProtocolType::UDP,
2910+
protocol: ProtocolType::Udp,
29112911
ip_addr: "5.6.7.8".parse().unwrap(),
29122912
port: 12345
29132913
};
@@ -2941,7 +2941,7 @@ mod tests {
29412941
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
29422942

29432943
let ip_port = IpPort {
2944-
protocol: ProtocolType::UDP,
2944+
protocol: ProtocolType::Udp,
29452945
ip_addr: "5.6.7.8".parse().unwrap(),
29462946
port: 12345
29472947
};
@@ -2979,7 +2979,7 @@ mod tests {
29792979
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
29802980

29812981
let ip_port = IpPort {
2982-
protocol: ProtocolType::TCP,
2982+
protocol: ProtocolType::Tcp,
29832983
ip_addr: "5.6.7.8".parse().unwrap(),
29842984
port: 12345
29852985
};
@@ -3010,7 +3010,7 @@ mod tests {
30103010
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
30113011

30123012
let ip_port = IpPort {
3013-
protocol: ProtocolType::TCP,
3013+
protocol: ProtocolType::Tcp,
30143014
ip_addr: "5.6.7.8".parse().unwrap(),
30153015
port: 12345
30163016
};
@@ -3063,7 +3063,7 @@ mod tests {
30633063
let onion_symmetric_key = alice.onion_symmetric_key.read().await;
30643064

30653065
let ip_port = IpPort {
3066-
protocol: ProtocolType::UDP,
3066+
protocol: ProtocolType::Udp,
30673067
ip_addr: "5.6.7.8".parse().unwrap(),
30683068
port: 12345
30693069
};
@@ -3201,7 +3201,7 @@ mod tests {
32013201
let temporary_pk = gen_keypair().0;
32023202
let payload = vec![42; 123];
32033203
let ip_port = IpPort {
3204-
protocol: ProtocolType::UDP,
3204+
protocol: ProtocolType::Udp,
32053205
ip_addr: "5.6.7.8".parse().unwrap(),
32063206
port: 12345
32073207
};

tox_core/src/net_crypto/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,19 @@ impl From<StatusPacket> for Packet {
117117
}
118118
}
119119

120-
impl Into<DhtPacket> for Packet {
121-
fn into(self) -> DhtPacket {
122-
match self {
120+
impl From<Packet> for DhtPacket {
121+
fn from(packet: Packet) -> Self {
122+
match packet {
123123
Packet::CookieRequest(packet) => DhtPacket::CookieRequest(packet),
124124
Packet::CryptoHandshake(packet) => DhtPacket::CryptoHandshake(packet),
125125
Packet::CryptoData(packet) => DhtPacket::CryptoData(packet),
126126
}
127127
}
128128
}
129129

130-
impl Into<TcpDataPayload> for Packet {
131-
fn into(self) -> TcpDataPayload {
132-
match self {
130+
impl From<Packet> for TcpDataPayload {
131+
fn from(packet: Packet) -> Self {
132+
match packet {
133133
Packet::CookieRequest(packet) => TcpDataPayload::CookieRequest(packet),
134134
Packet::CryptoHandshake(packet) => TcpDataPayload::CryptoHandshake(packet),
135135
Packet::CryptoData(packet) => TcpDataPayload::CryptoData(packet),

tox_core/src/onion/client/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct OnionNode {
186186
announce_status: AnnounceStatus,
187187
}
188188

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

550550
for node in dht_pk_announce.nodes.into_iter() {
551551
match node.ip_port.protocol {
552-
ProtocolType::UDP => {
552+
ProtocolType::Udp => {
553553
let packed_node = PackedNode::new(node.ip_port.to_saddr(), &node.pk);
554554
self.dht.ping_node(&packed_node).await
555555
.map_err(|e| e.context(HandleDhtPkAnnounceErrorKind::PingNode))?;
556556
},
557-
ProtocolType::TCP => {
557+
ProtocolType::Tcp => {
558558
self.tcp_connections.add_relay_connection(node.ip_port.to_saddr(), node.pk, dht_pk_announce.dht_pk).await
559559
.map_err(|e| e.context(HandleDhtPkAnnounceErrorKind::AddRelay))?;
560560
}
@@ -979,7 +979,7 @@ mod tests {
979979
saddr,
980980
path_id: OnionPathId {
981981
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
982-
path_type: OnionPathType::UDP,
982+
path_type: OnionPathType::Udp,
983983
},
984984
ping_id: None,
985985
data_pk: None,
@@ -1005,7 +1005,7 @@ mod tests {
10051005
saddr: "127.0.0.1:12345".parse().unwrap(),
10061006
path_id: OnionPathId {
10071007
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
1008-
path_type: OnionPathType::UDP,
1008+
path_type: OnionPathType::Udp,
10091009
},
10101010
ping_id: None,
10111011
data_pk: None,
@@ -1019,7 +1019,7 @@ mod tests {
10191019
let saddr = "127.0.0.1:12346".parse().unwrap();
10201020
let path_id = OnionPathId {
10211021
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
1022-
path_type: OnionPathType::UDP,
1022+
path_type: OnionPathType::Udp,
10231023
};
10241024
let ping_id = sha256::hash(&[1, 2, 3]);
10251025
let data_pk = gen_keypair().0;
@@ -1060,7 +1060,7 @@ mod tests {
10601060
saddr: "127.0.0.1:12345".parse().unwrap(),
10611061
path_id: OnionPathId {
10621062
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
1063-
path_type: OnionPathType::UDP,
1063+
path_type: OnionPathType::Udp,
10641064
},
10651065
ping_id: None,
10661066
data_pk: None,
@@ -1509,7 +1509,7 @@ mod tests {
15091509
saddr,
15101510
path_id: OnionPathId {
15111511
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
1512-
path_type: OnionPathType::UDP,
1512+
path_type: OnionPathType::Udp,
15131513
},
15141514
friend_pk: Some(friend_pk),
15151515
};
@@ -1553,7 +1553,7 @@ mod tests {
15531553
saddr,
15541554
path_id: OnionPathId {
15551555
keys: [gen_keypair().0, gen_keypair().0, gen_keypair().0],
1556-
path_type: OnionPathType::UDP,
1556+
path_type: OnionPathType::Udp,
15571557
},
15581558
friend_pk: Some(friend_pk),
15591559
};
@@ -1661,7 +1661,7 @@ mod tests {
16611661
let dht_pk_announce_payload = DhtPkAnnouncePayload::new(friend_dht_pk, vec![
16621662
TcpUdpPackedNode {
16631663
ip_port: IpPort {
1664-
protocol: ProtocolType::UDP,
1664+
protocol: ProtocolType::Udp,
16651665
ip_addr: saddr.ip(),
16661666
port: saddr.port(),
16671667
},
@@ -1723,7 +1723,7 @@ mod tests {
17231723
let dht_pk_announce_payload = DhtPkAnnouncePayload::new(friend_dht_pk, vec![
17241724
TcpUdpPackedNode {
17251725
ip_port: IpPort {
1726-
protocol: ProtocolType::TCP,
1726+
protocol: ProtocolType::Tcp,
17271727
ip_addr: "127.0.0.2".parse().unwrap(),
17281728
port: 12346,
17291729
},
@@ -2353,7 +2353,7 @@ mod tests {
23532353
PackedNode::new("127.0.0.1:12346".parse().unwrap(), &gen_keypair().0),
23542354
PackedNode::new("127.0.0.1:12347".parse().unwrap(), &gen_keypair().0),
23552355
PackedNode::new("127.0.0.1:12348".parse().unwrap(), &gen_keypair().0),
2356-
], OnionPathType::UDP);
2356+
], OnionPathType::Udp);
23572357
let saddr = "127.0.0.1:12345".parse().unwrap();
23582358
onion_client.send_onion_request(path, inner_onion_request, saddr).await.unwrap();
23592359

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

tox_core/src/onion/client/nodes_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl NodesPool {
7878
break;
7979
}
8080
}
81-
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::UDP))
81+
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::Udp))
8282
}
8383

8484
/// Build new random onion path with first TCP node.
@@ -95,7 +95,7 @@ impl NodesPool {
9595
break;
9696
}
9797
}
98-
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::TCP))
98+
Some(OnionPath::new([node_1, node_2, node_3], OnionPathType::Tcp))
9999
}
100100
}
101101

0 commit comments

Comments
 (0)