1
1
/* eslint-disable complexity */
2
2
3
3
import { publicKeyFromProtobuf , publicKeyToProtobuf } from '@libp2p/crypto/keys'
4
- import { InvalidMessageError , serviceCapabilities , setMaxListeners } from '@libp2p/interface'
4
+ import { InvalidMessageError , UnsupportedProtocolError , serviceCapabilities , setMaxListeners } from '@libp2p/interface'
5
5
import { peerIdFromCID } from '@libp2p/peer-id'
6
6
import { RecordEnvelope , PeerRecord } from '@libp2p/peer-record'
7
+ import { isPrivateIp } from '@libp2p/utils/private-ip'
7
8
import { protocols } from '@multiformats/multiaddr'
8
9
import { IP_OR_DOMAIN } from '@multiformats/multiaddr-matcher'
9
10
import { pbStream } from 'it-protobuf-stream'
@@ -29,7 +30,15 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
29
30
// When a new connection happens, trigger identify
30
31
components . events . addEventListener ( 'connection:open' , ( evt ) => {
31
32
const connection = evt . detail
32
- this . identify ( connection ) . catch ( err => { this . log . error ( 'error during identify trigged by connection:open' , err ) } )
33
+ this . identify ( connection )
34
+ . catch ( err => {
35
+ if ( err . name === UnsupportedProtocolError . name ) {
36
+ // the remote did not support identify, ignore the error
37
+ return
38
+ }
39
+
40
+ this . log . error ( 'error during identify trigged by connection:open' , err )
41
+ } )
33
42
} )
34
43
}
35
44
}
@@ -67,7 +76,6 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
67
76
68
77
return message
69
78
} catch ( err : any ) {
70
- this . log . error ( 'error while reading identify message' , err )
71
79
stream ?. abort ( err )
72
80
throw err
73
81
}
@@ -100,12 +108,16 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
100
108
const cleanObservedAddr = getCleanMultiaddr ( observedAddr )
101
109
102
110
this . log ( 'identify completed for peer %p and protocols %o' , id , protocols )
103
- this . log ( 'our observed address is %a' , cleanObservedAddr )
104
111
105
- if ( cleanObservedAddr != null &&
106
- this . addressManager . getObservedAddrs ( ) . length < ( this . maxObservedAddresses ?? Infinity ) ) {
107
- this . log ( 'storing our observed address %a' , cleanObservedAddr )
108
- this . addressManager . addObservedAddr ( cleanObservedAddr )
112
+ if ( cleanObservedAddr != null ) {
113
+ this . log ( 'our observed address was %a' , cleanObservedAddr )
114
+
115
+ if ( isPrivateIp ( cleanObservedAddr ?. nodeAddress ( ) . address ) === true ) {
116
+ this . log ( 'our observed address was private' )
117
+ } else if ( this . addressManager . getObservedAddrs ( ) . length < ( this . maxObservedAddresses ?? Infinity ) ) {
118
+ this . log ( 'storing our observed address' )
119
+ this . addressManager . addObservedAddr ( cleanObservedAddr )
120
+ }
109
121
}
110
122
111
123
return consumeIdentifyMessage ( this . peerStore , this . events , this . log , connection , message )
0 commit comments