From 14437566824581b7e872118827d6dc2fb3dd04b6 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Sat, 30 Nov 2024 13:48:11 +0000 Subject: [PATCH] fix: use isPrivate to detect private multiaddrs To prevent throwing when non-thin waist addresses are encountered, use `isPrivate` instead of converting the multiaddr to a node address. --- packages/protocol-identify/src/identify.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol-identify/src/identify.ts b/packages/protocol-identify/src/identify.ts index c6d96332dc..88b7076077 100644 --- a/packages/protocol-identify/src/identify.ts +++ b/packages/protocol-identify/src/identify.ts @@ -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' @@ -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')