@@ -15,7 +15,7 @@ use std::{
15
15
} ;
16
16
17
17
use libp2p_core:: { Multiaddr , PeerId } ;
18
- use libp2p_swarm:: { DialError , FromSwarm } ;
18
+ use libp2p_swarm:: { behaviour :: ConnectionEstablished , DialError , FromSwarm } ;
19
19
use lru:: LruCache ;
20
20
21
21
use super :: Store ;
@@ -191,21 +191,23 @@ impl<T> Store for MemoryStore<T> {
191
191
self . push_event_and_wake ( crate :: store:: Event :: RecordUpdated ( info. peer_id ) ) ;
192
192
}
193
193
}
194
- FromSwarm :: ConnectionEstablished ( info) => {
194
+ FromSwarm :: ConnectionEstablished ( ConnectionEstablished {
195
+ peer_id,
196
+ failed_addresses,
197
+ endpoint,
198
+ ..
199
+ } ) if endpoint. is_dialer ( ) => {
195
200
let mut is_record_updated = false ;
196
201
if self . config . remove_addr_on_dial_error {
197
- for failed_addr in info . failed_addresses {
202
+ for failed_addr in * failed_addresses {
198
203
is_record_updated |=
199
- self . remove_address_silent ( & info . peer_id , failed_addr, false ) ;
204
+ self . remove_address_silent ( peer_id, failed_addr, false ) ;
200
205
}
201
206
}
202
- is_record_updated |= self . update_address_silent (
203
- & info. peer_id ,
204
- info. endpoint . get_remote_address ( ) ,
205
- false ,
206
- ) ;
207
+ is_record_updated |=
208
+ self . update_address_silent ( peer_id, endpoint. get_remote_address ( ) , false ) ;
207
209
if is_record_updated {
208
- self . push_event_and_wake ( crate :: store:: Event :: RecordUpdated ( info . peer_id ) ) ;
210
+ self . push_event_and_wake ( crate :: store:: Event :: RecordUpdated ( * peer_id) ) ;
209
211
}
210
212
}
211
213
FromSwarm :: DialFailure ( info) => {
@@ -302,9 +304,7 @@ impl Config {
302
304
}
303
305
/// If set to `true`, the store will remove addresses if the swarm indicates a dial failure.
304
306
/// More specifically:
305
- /// - Failed dials indicated in
306
- /// [`ConnectionEstablished`](libp2p_swarm::behaviour::ConnectionEstablished)'s
307
- /// `failed_addresses` will be removed.
307
+ /// - Failed dials indicated in [`ConnectionEstablished`]'s `failed_addresses` will be removed.
308
308
/// - [`DialError::LocalPeerId`] causes the full peer entry to be removed.
309
309
/// - On [`DialError::WrongPeerId`], the address will be removed from the incorrect peer's
310
310
/// record and re-added to the correct peer's record.
@@ -499,6 +499,7 @@ mod test {
499
499
rt. block_on ( async {
500
500
let ( listen_addr, _) = swarm1. listen ( ) . with_memory_addr_external ( ) . await ;
501
501
let swarm1_peer_id = * swarm1. local_peer_id ( ) ;
502
+ let swarm2_peer_id = * swarm2. local_peer_id ( ) ;
502
503
swarm2. dial ( listen_addr. clone ( ) ) . expect ( "dial to succeed" ) ;
503
504
let handle = spawn_wait_conn_established ( swarm1) ;
504
505
swarm2
@@ -508,12 +509,17 @@ mod test {
508
509
} )
509
510
. await ;
510
511
let mut swarm1 = handle. await . expect ( "future to complete" ) ;
512
+ expect_record_update ( & mut swarm2, swarm1_peer_id) . await ;
511
513
assert ! ( swarm2
512
514
. behaviour( )
513
515
. address_of_peer( & swarm1_peer_id)
514
516
. expect( "swarm should be connected and record about it should be created" )
515
517
. any( |addr| * addr == listen_addr) ) ;
516
- expect_record_update ( & mut swarm1, * swarm2. local_peer_id ( ) ) . await ;
518
+ // Address from connection is not stored on the listener side.
519
+ assert ! ( swarm1
520
+ . behaviour( )
521
+ . address_of_peer( & swarm2_peer_id)
522
+ . is_none( ) ) ;
517
523
let ( new_listen_addr, _) = swarm1. listen ( ) . with_memory_addr_external ( ) . await ;
518
524
let handle = spawn_wait_conn_established ( swarm1) ;
519
525
swarm2
@@ -590,15 +596,18 @@ mod test {
590
596
. await
591
597
. expect ( "future to complete" ) ;
592
598
let mut swarm1 = handle. await . expect ( "future to complete" ) ;
593
- // expexting update from direct connection.
594
599
expect_record_update ( & mut swarm2, swarm1_peer_id) . await ;
595
600
assert ! ( swarm2
596
601
. behaviour( )
597
602
. peer_store
598
603
. address_of_peer( & swarm1_peer_id)
599
604
. expect( "swarm should be connected and record about it should be created" )
600
605
. any( |addr| * addr == listen_addr) ) ;
601
- expect_record_update ( & mut swarm1, * swarm2. local_peer_id ( ) ) . await ;
606
+ assert ! ( swarm1
607
+ . behaviour( )
608
+ . peer_store
609
+ . address_of_peer( & swarm2_peer_id)
610
+ . is_none( ) ) ;
602
611
swarm1. next_swarm_event ( ) . await ; // skip `identify::Event::Sent`
603
612
swarm1. next_swarm_event ( ) . await ; // skip `identify::Event::Received`
604
613
let ( new_listen_addr, _) = swarm1. listen ( ) . with_memory_addr_external ( ) . await ;
0 commit comments