3
3
4
4
import { TypedEventEmitter } from '@libp2p/interface/events'
5
5
import { start , stop } from '@libp2p/interface/startable'
6
- import { mockConnectionGater , mockRegistrar , mockUpgrader , connectionPair , mockStream } from '@libp2p/interface-compliance-tests/mocks'
6
+ import { mockConnectionGater , mockRegistrar , mockUpgrader , connectionPair , mockStream , streamPair } from '@libp2p/interface-compliance-tests/mocks'
7
7
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
8
8
import { PeerRecord , RecordEnvelope } from '@libp2p/peer-record'
9
9
import { PersistentPeerStore } from '@libp2p/peer-store'
@@ -13,6 +13,7 @@ import { MemoryDatastore } from 'datastore-core/memory'
13
13
import delay from 'delay'
14
14
import drain from 'it-drain'
15
15
import * as lp from 'it-length-prefixed'
16
+ import { duplexPair } from 'it-pair/duplex'
16
17
import { pipe } from 'it-pipe'
17
18
import { pbStream } from 'it-protobuf-stream'
18
19
import { pushable } from 'it-pushable'
@@ -581,4 +582,29 @@ describe('identify', () => {
581
582
582
583
expect ( localPeerStorePatchSpy . called ) . to . be . false ( 'patch was called when public key was invalid' )
583
584
} )
585
+
586
+ it ( 'should not send unroutable observed addresses' , async ( ) => {
587
+ const localIdentify = new DefaultIdentifyService ( localComponents , defaultInit )
588
+
589
+ const duplex = duplexPair < any > ( )
590
+ const streams = streamPair ( {
591
+ duplex : duplex [ 0 ]
592
+ } , {
593
+ duplex : duplex [ 1 ]
594
+ } )
595
+
596
+ const data : IncomingStreamData = {
597
+ stream : streams [ 0 ] ,
598
+ connection : stubInterface < Connection > ( {
599
+ remoteAddr : multiaddr ( '/webrtc/p2p/QmR5VwgsL7jyfZHAGyp66tguVrQhCRQuRc3NokocsCZ3fA' )
600
+ } )
601
+ }
602
+
603
+ await localIdentify . _handleIdentify ( data )
604
+
605
+ const pb = pbStream ( duplex [ 1 ] )
606
+ const result = await pb . read ( Identify )
607
+
608
+ expect ( result . observedAddr ) . to . be . undefined ( )
609
+ } )
584
610
} )
0 commit comments