Skip to content

Commit

Permalink
fix: use isPrivate to detect private multiaddrs (#2868)
Browse files Browse the repository at this point in the history
To prevent throwing when non-thin waist addresses are encountered,
use `isPrivate` instead of converting the multiaddr to a node address.
  • Loading branch information
achingbrain authored Nov 30, 2024
1 parent 99f5f27 commit 2c182d2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/protocol-identify/src/identify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys'
import { InvalidMessageError, UnsupportedProtocolError, serviceCapabilities, setMaxListeners } from '@libp2p/interface'
import { peerIdFromCID } from '@libp2p/peer-id'
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
import { isPrivateIp } from '@libp2p/utils/private-ip'
import { isPrivate } from '@libp2p/utils/multiaddr/is-private'
import { protocols } from '@multiformats/multiaddr'
import { IP_OR_DOMAIN } from '@multiformats/multiaddr-matcher'
import { pbStream } from 'it-protobuf-stream'
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
if (cleanObservedAddr != null) {
this.log('our observed address was %a', cleanObservedAddr)

if (isPrivateIp(cleanObservedAddr?.nodeAddress().address) === true) {
if (isPrivate(cleanObservedAddr)) {
this.log('our observed address was private')
} else if (this.addressManager.getObservedAddrs().length < (this.maxObservedAddresses ?? Infinity)) {
this.log('storing our observed address')
Expand Down

0 comments on commit 2c182d2

Please sign in to comment.