8
8
//! let behaviour = Behaviour::new(store);
9
9
//! ```
10
10
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 ;
11
16
use std:: {
12
17
collections:: { HashMap , VecDeque } ,
13
18
num:: NonZeroUsize ,
14
19
task:: { Poll , Waker } ,
15
20
} ;
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 ;
20
21
use tracing:: { debug, trace} ;
21
- use crate :: connection_store:: ConnectionStore ;
22
- use super :: { connection_store, Store } ;
23
22
24
23
/// Event emitted from the [`MemoryStore`] to the [`Swarm`](libp2p_swarm::Swarm).
25
24
#[ derive( Debug , Clone ) ]
@@ -222,12 +221,12 @@ impl<T> Store for MemoryStore<T> {
222
221
self . add_address_inner ( & info. peer_id , info. addr , false ) ;
223
222
}
224
223
FromSwarm :: ConnectionEstablished ( ConnectionEstablished {
225
- peer_id,
224
+ peer_id,
226
225
connection_id,
227
226
failed_addresses,
228
227
endpoint,
229
228
..
230
- } ) => {
229
+ } ) => {
231
230
if endpoint. is_dialer ( ) {
232
231
if self . config . remove_addr_on_dial_error {
233
232
for failed_addr in * failed_addresses {
@@ -239,7 +238,9 @@ impl<T> Store for MemoryStore<T> {
239
238
240
239
trace ! ( %peer_id, ?connection_id, "Connection established" ) ;
241
240
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) ;
243
244
244
245
if is_first_connection {
245
246
debug ! ( ?peer_id, "Peer connected" ) ;
@@ -251,16 +252,18 @@ impl<T> Store for MemoryStore<T> {
251
252
}
252
253
}
253
254
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
+ } ) => {
259
260
trace ! ( %peer_id, ?connection_id, remaining_established, "Connection closed" ) ;
260
261
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
+ ) ;
264
267
265
268
if is_last_connection {
266
269
debug ! ( %peer_id, "Peer disconnected" ) ;
0 commit comments