Skip to content

Commit e6048c8

Browse files
committed
fmt and clippy
1 parent e3e74c0 commit e6048c8

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

misc/peer-store/src/connection_store.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::collections::{HashMap, HashSet};
21
use libp2p_core::{ConnectedPoint, PeerId};
32
use libp2p_swarm::ConnectionId;
3+
use std::collections::{HashMap, HashSet};
44

55
/// Events emitted by the connection tracker behaviour.
66
#[derive(Debug, Clone)]
@@ -41,7 +41,7 @@ impl ConnectionStore {
4141
peer_id: &PeerId,
4242
connection_id: &ConnectionId,
4343
) -> bool {
44-
let connections = self.connected.entry(*peer_id).or_insert_with(HashSet::new);
44+
let connections = self.connected.entry(*peer_id).or_default();
4545
let is_first_connection = connections.is_empty();
4646
connections.insert(*connection_id);
4747
is_first_connection
@@ -55,11 +55,11 @@ impl ConnectionStore {
5555
connection_id: &ConnectionId,
5656
remaining_established: &usize,
5757
) -> bool {
58-
if let Some(connections) = self.connected.get_mut(&peer_id) {
59-
connections.remove(&connection_id);
58+
if let Some(connections) = self.connected.get_mut(peer_id) {
59+
connections.remove(connection_id);
6060

6161
if *remaining_established == 0 {
62-
self.connected.remove(&peer_id);
62+
self.connected.remove(peer_id);
6363
return true;
6464
}
6565
}
@@ -88,4 +88,4 @@ impl ConnectionStore {
8888
.map(|connections| connections.len())
8989
.unwrap_or(0)
9090
}
91-
}
91+
}

misc/peer-store/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
//! or provide information to PeerStore.
1919
2020
mod behaviour;
21+
pub mod connection_store;
2122
pub mod memory_store;
2223
mod store;
23-
pub mod connection_store;
2424

2525
pub use behaviour::Behaviour;
2626
pub use store::Store;

misc/peer-store/src/memory_store.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
//! let behaviour = Behaviour::new(store);
99
//! ```
1010
11+
use super::Store;
12+
use crate::connection_store::ConnectionStore;
13+
use libp2p_core::{Multiaddr, PeerId};
14+
use libp2p_swarm::{behaviour::ConnectionEstablished, ConnectionClosed, DialError, FromSwarm};
15+
use lru::LruCache;
1116
use std::{
1217
collections::{HashMap, VecDeque},
1318
num::NonZeroUsize,
1419
task::{Poll, Waker},
1520
};
16-
use std::collections::HashSet;
17-
use libp2p_core::{Multiaddr, PeerId};
18-
use libp2p_swarm::{behaviour::ConnectionEstablished, ConnectionClosed, ConnectionId, DialError, FromSwarm};
19-
use lru::LruCache;
2021
use tracing::{debug, trace};
21-
use crate::connection_store::ConnectionStore;
22-
use super::{connection_store, Store};
2322

2423
/// Event emitted from the [`MemoryStore`] to the [`Swarm`](libp2p_swarm::Swarm).
2524
#[derive(Debug, Clone)]
@@ -222,12 +221,12 @@ impl<T> Store for MemoryStore<T> {
222221
self.add_address_inner(&info.peer_id, info.addr, false);
223222
}
224223
FromSwarm::ConnectionEstablished(ConnectionEstablished {
225-
peer_id,
224+
peer_id,
226225
connection_id,
227226
failed_addresses,
228227
endpoint,
229228
..
230-
}) => {
229+
}) => {
231230
if endpoint.is_dialer() {
232231
if self.config.remove_addr_on_dial_error {
233232
for failed_addr in *failed_addresses {
@@ -239,7 +238,9 @@ impl<T> Store for MemoryStore<T> {
239238

240239
trace!(%peer_id, ?connection_id, "Connection established");
241240

242-
let is_first_connection = self.connection_store.connection_established(peer_id, connection_id);
241+
let is_first_connection = self
242+
.connection_store
243+
.connection_established(peer_id, connection_id);
243244

244245
if is_first_connection {
245246
debug!(?peer_id, "Peer connected");
@@ -251,16 +252,18 @@ impl<T> Store for MemoryStore<T> {
251252
}
252253
}
253254
FromSwarm::ConnectionClosed(ConnectionClosed {
254-
peer_id,
255-
connection_id,
256-
remaining_established,
257-
..
258-
}) => {
255+
peer_id,
256+
connection_id,
257+
remaining_established,
258+
..
259+
}) => {
259260
trace!(%peer_id, ?connection_id, remaining_established, "Connection closed");
260261

261-
let is_last_connection =
262-
self.connection_store
263-
.connection_closed(peer_id, connection_id, remaining_established);
262+
let is_last_connection = self.connection_store.connection_closed(
263+
peer_id,
264+
connection_id,
265+
remaining_established,
266+
);
264267

265268
if is_last_connection {
266269
debug!(%peer_id, "Peer disconnected");

0 commit comments

Comments
 (0)