@@ -172,6 +172,9 @@ pub(crate) struct Identify {
172
172
// Public key of the local node, filled by `Litep2p`.
173
173
public : PublicKey ,
174
174
175
+ /// Local peer ID.
176
+ local_peer_id : PeerId ,
177
+
175
178
/// Protocol version.
176
179
protocol_version : String ,
177
180
@@ -191,11 +194,15 @@ pub(crate) struct Identify {
191
194
impl Identify {
192
195
/// Create new [`Identify`] protocol.
193
196
pub ( crate ) fn new ( service : TransportService , config : Config ) -> Self {
197
+ let public = config. public . expect ( "public key to be supplied" ) ;
198
+ let local_peer_id = public. to_peer_id ( ) ;
199
+
194
200
Self {
195
201
service,
196
202
tx : config. tx_event ,
197
203
peers : HashMap :: new ( ) ,
198
- public : config. public . expect ( "public key to be supplied" ) ,
204
+ public,
205
+ local_peer_id,
199
206
protocol_version : config. protocol_version ,
200
207
user_agent : config. user_agent . unwrap_or ( DEFAULT_AGENT . to_string ( ) ) ,
201
208
pending_inbound : FuturesStream :: new ( ) ,
@@ -313,6 +320,8 @@ impl Identify {
313
320
"outbound substream opened"
314
321
) ;
315
322
323
+ let local_peer_id = self . local_peer_id . clone ( ) ;
324
+
316
325
self . pending_outbound . push ( Box :: pin ( async move {
317
326
let payload =
318
327
match tokio:: time:: timeout ( Duration :: from_secs ( 10 ) , substream. next ( ) ) . await {
@@ -361,7 +370,23 @@ impl Identify {
361
370
. collect ( ) ;
362
371
363
372
let observed_address =
364
- info. observed_addr . and_then ( |address| Multiaddr :: try_from ( address) . ok ( ) ) ;
373
+ info. observed_addr . and_then ( |address| {
374
+ let address = Multiaddr :: try_from ( address) . ok ( ) ?;
375
+
376
+ if address. is_empty ( ) {
377
+ return None ;
378
+ }
379
+
380
+ if let Some ( multiaddr:: Protocol :: P2p ( peer_id) ) = address. iter ( ) . last ( ) {
381
+ if peer_id != local_peer_id. into ( ) {
382
+ tracing:: debug!( target: LOG_TARGET , ?peer, ?address, "peer identified provided invalid address" ) ;
383
+ return None ;
384
+ }
385
+ }
386
+
387
+ Some ( address)
388
+ } ) ;
389
+
365
390
let protocol_version = info. protocol_version ;
366
391
let user_agent = info. agent_version ;
367
392
0 commit comments