Skip to content

Commit b9dd459

Browse files
committed
refactor(clippy): fix warnings
1 parent 49195f8 commit b9dd459

File tree

23 files changed

+36
-45
lines changed

23 files changed

+36
-45
lines changed

examples/echo.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ async fn main() -> Result<(), Error> {
104104
net_crypto.set_tcp_sink(net_crypto_tcp_tx).await;
105105

106106
let friend_connections = FriendConnections::new(
107-
real_sk,
108-
real_pk,
109107
dht_server.clone(),
110108
tcp_connections.clone(),
111109
onion_client.clone(),

tox_core/src/dht/kbucket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ where
249249
if self.is_full() {
250250
debug!(target: "Kbucket",
251251
"No free space left in the kbucket, the last (bad) node removed.");
252-
let eviction_index = Node::eviction_index(&self.nodes).unwrap_or_else(|| self.nodes.len() - 1);
252+
let eviction_index = Node::eviction_index(&self.nodes).unwrap_or(self.nodes.len() - 1);
253253
self.nodes.remove(eviction_index);
254254
let index = index - if eviction_index < index { 1 } else { 0 };
255255
self.nodes.insert(index, new_node.into());

tox_core/src/dht/server/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ pub const PRECOMPUTED_LRU_CACHE_SIZE: usize = KBUCKET_DEFAULT_SIZE as usize * KB
7171
/// How often DHT main loop should be called.
7272
const MAIN_LOOP_INTERVAL: u64 = 1;
7373

74+
type MotdCallback = dyn Fn(&Server) -> Vec<u8> + Send + Sync;
75+
7476
/// Struct that contains necessary data for `BootstrapInfo` packet.
7577
#[derive(Clone)]
7678
struct ServerBootstrapInfo {
7779
/// Version of tox core which will be sent with `BootstrapInfo` packet.
7880
version: u32,
7981
/// Callback to get the message of the day which will be sent with
8082
/// `BootstrapInfo` packet.
81-
motd_cb: Arc<dyn Fn(&Server) -> Vec<u8> + Send + Sync>,
83+
motd_cb: Arc<MotdCallback>,
8284
}
8385

8486
/// DHT server state.
@@ -1358,7 +1360,7 @@ impl Server {
13581360
}
13591361

13601362
/// Set toxcore version and message of the day callback.
1361-
pub fn set_bootstrap_info(&mut self, version: u32, motd_cb: Box<dyn Fn(&Server) -> Vec<u8> + Send + Sync>) {
1363+
pub fn set_bootstrap_info(&mut self, version: u32, motd_cb: Box<MotdCallback>) {
13621364
self.bootstrap_info = Some(ServerBootstrapInfo {
13631365
version,
13641366
motd_cb: motd_cb.into(),

tox_core/src/friend_connection/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ impl Friend {
9090
/// Friend connections module that handles friends and their connections.
9191
#[derive(Clone)]
9292
pub struct FriendConnections {
93-
/// Our long term `SecretKey`.
94-
real_sk: SecretKey,
95-
/// Our long term `PublicKey`.
96-
real_pk: PublicKey,
9793
/// List of friends we want to be connected to.
9894
friends: Arc<RwLock<HashMap<PublicKey, Friend>>>,
9995
/// Sink to send a connection status when it becomes connected or
@@ -112,16 +108,12 @@ pub struct FriendConnections {
112108
impl FriendConnections {
113109
/// Create new `FriendConnections`.
114110
pub fn new(
115-
real_sk: SecretKey,
116-
real_pk: PublicKey,
117111
dht: DhtServer,
118112
tcp_connections: TcpConnections,
119113
onion_client: OnionClient,
120114
net_crypto: NetCrypto,
121115
) -> Self {
122116
FriendConnections {
123-
real_sk,
124-
real_pk,
125117
friends: Arc::new(RwLock::new(HashMap::new())),
126118
connection_status_tx: Arc::new(RwLock::new(None)),
127119
dht,
@@ -450,13 +442,11 @@ mod tests {
450442
lossy_tx,
451443
dht_pk,
452444
dht_sk,
453-
real_pk: real_pk.clone(),
454-
real_sk: real_sk.clone(),
445+
real_pk,
446+
real_sk,
455447
precomputed_keys,
456448
});
457449
let friend_connections = FriendConnections::new(
458-
real_sk,
459-
real_pk,
460450
dht,
461451
tcp_connections,
462452
onion_client,
@@ -961,7 +951,7 @@ mod tests {
961951
let run_future = friend_connections.run()
962952
.map(Result::unwrap);
963953

964-
let precomputed_key = SalsaBox::new(&friend_connections.real_pk, &friend_sk);
954+
let precomputed_key = SalsaBox::new(friend_connections.net_crypto.real_pk(), &friend_sk);
965955
let cookie = friend_connections.net_crypto.get_cookie(&mut rng, friend_pk.clone(), friend_dht_pk);
966956
let sent_nonce = SalsaBox::generate_nonce(&mut rng).into();
967957
let friend_session_sk = SecretKey::generate(&mut rng);

tox_core/src/net_crypto/crypto_connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl RecvPacket {
228228
}
229229

230230
/// UDP address of a connection with the time when last UDP packet was received
231-
#[derive(Clone, Debug, PartialEq)]
231+
#[derive(Clone, Debug, PartialEq, Eq)]
232232
pub struct ConnectionAddr<T: Into<SocketAddr> + Copy> {
233233
/// Address to send UDP packets directly to the peer
234234
pub addr: T,

tox_core/src/net_crypto/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,10 @@ mod tests {
11351135
use crypto_box::{SalsaBox, aead::{AeadCore, generic_array::typenum::marker_traits::Unsigned}};
11361136

11371137
impl NetCrypto {
1138+
pub fn real_pk(&self) -> &PublicKey {
1139+
&self.real_pk
1140+
}
1141+
11381142
pub async fn has_friend(&self, pk: &PublicKey) -> bool {
11391143
self.friends.read().await.contains(pk)
11401144
}

tox_core/src/relay/client/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const CLIENT_CHANNEL_SIZE: usize = 2;
2828

2929
/// Packet that can be received from a TCP relay and should be handled outside
3030
/// of connections module.
31-
#[derive(Debug, PartialEq, Clone)]
31+
#[derive(Debug, PartialEq, Eq, Clone)]
3232
pub enum IncomingPacket {
3333
/// Data packet with sender's `PublicKey`.
3434
Data(PublicKey, DataPayload),

tox_core/src/relay/handshake/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn create_client_handshake(client_pk: &PublicKey,
3333

3434
let common_key = SalsaBox::new(server_pk, client_sk);
3535
let nonce = SalsaBox::generate_nonce(&mut rand::thread_rng());
36-
let encrypted_payload = common_key.encrypt(&nonce, &serialized_payload[..]).unwrap();
36+
let encrypted_payload = common_key.encrypt(&nonce, &*serialized_payload).unwrap();
3737

3838
let handshake = ClientHandshake {
3939
pk: client_pk.clone(),
@@ -70,7 +70,7 @@ pub fn handle_client_handshake(server_sk: &SecretKey,
7070
let (serialized_payload, _) = server_payload.to_bytes((&mut serialized_payload, 0)).unwrap();
7171

7272
let nonce = SalsaBox::generate_nonce(&mut rand::thread_rng());
73-
let server_encrypted_payload = common_key.encrypt(&nonce, &serialized_payload[..]).unwrap();
73+
let server_encrypted_payload = common_key.encrypt(&nonce, &*serialized_payload).unwrap();
7474

7575
let server_handshake = ServerHandshake {
7676
nonce: nonce.into(),

tox_core/src/relay/handshake/packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Length | Contents
2121
2222
*/
2323

24-
#[derive(PartialEq, Debug, Clone)]
24+
#[derive(PartialEq, Eq, Debug, Clone)]
2525
pub struct ClientHandshake {
2626
/// Client's Public Key
2727
pub pk: PublicKey,
@@ -68,7 +68,7 @@ Length | Contents
6868
6969
*/
7070

71-
#[derive(PartialEq, Debug, Clone)]
71+
#[derive(PartialEq, Eq, Debug, Clone)]
7272
pub struct ServerHandshake {
7373
/// Nonce of the encrypted payload
7474
pub nonce: Nonce,

tox_core/src/relay/links.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::collections::HashMap;
99
pub const MAX_LINKS_N: u8 = 240;
1010

1111
/// The status of the Link
12-
#[derive(Debug, PartialEq, Clone, Copy)]
12+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
1313
pub enum LinkStatus {
1414
/// The link is registered on one side only.
1515
///

0 commit comments

Comments
 (0)