Skip to content

Commit 442a835

Browse files
authored
fix: switch informational logging to trace logging (#2727)
Where logging is very verbose, switch informational logs to trace logging
1 parent 80fb47f commit 442a835

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

packages/multistream-select/src/handle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
9696
continue
9797
}
9898

99-
options.log('handle: respond with "na" for "%s"', protocol)
99+
options.log.trace('handle: respond with "na" for "%s"', protocol)
100100
await multistream.write(lp, uint8ArrayFromString('na\n'), options)
101101
options.log('handle: responded with "na" for "%s"', protocol)
102102
}

packages/protocol-identify/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@libp2p/interface-internal": "^2.0.4",
5858
"@libp2p/peer-id": "^5.0.4",
5959
"@libp2p/peer-record": "^8.0.4",
60+
"@libp2p/utils": "^6.0.4",
6061
"@multiformats/multiaddr": "^12.2.3",
6162
"@multiformats/multiaddr-matcher": "^1.2.1",
6263
"it-drain": "^3.0.7",

packages/protocol-identify/src/identify-push.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ export class IdentifyPush extends AbstractIdentify implements Startable, Identif
145145
return
146146
}
147147

148-
this.log('handled push from %p', connection.remotePeer)
148+
this.log.trace('handled push from %p', connection.remotePeer)
149149
}
150150
}

packages/protocol-identify/src/identify.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable complexity */
22

33
import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys'
4-
import { InvalidMessageError, serviceCapabilities, setMaxListeners } from '@libp2p/interface'
4+
import { InvalidMessageError, UnsupportedProtocolError, serviceCapabilities, setMaxListeners } from '@libp2p/interface'
55
import { peerIdFromCID } from '@libp2p/peer-id'
66
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
7+
import { isPrivateIp } from '@libp2p/utils/private-ip'
78
import { protocols } from '@multiformats/multiaddr'
89
import { IP_OR_DOMAIN } from '@multiformats/multiaddr-matcher'
910
import { pbStream } from 'it-protobuf-stream'
@@ -29,7 +30,15 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
2930
// When a new connection happens, trigger identify
3031
components.events.addEventListener('connection:open', (evt) => {
3132
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+
})
3342
})
3443
}
3544
}
@@ -67,7 +76,6 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
6776

6877
return message
6978
} catch (err: any) {
70-
this.log.error('error while reading identify message', err)
7179
stream?.abort(err)
7280
throw err
7381
}
@@ -100,12 +108,16 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
100108
const cleanObservedAddr = getCleanMultiaddr(observedAddr)
101109

102110
this.log('identify completed for peer %p and protocols %o', id, protocols)
103-
this.log('our observed address is %a', cleanObservedAddr)
104111

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+
}
109121
}
110122

111123
return consumeIdentifyMessage(this.peerStore, this.events, this.log, connection, message)

packages/protocol-identify/src/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function consumeIdentifyMessage (peerStore: PeerStore, events: Type
8888

8989
// if the peer record has been sent, prefer the addresses in the record as they are signed by the remote peer
9090
if (message.signedPeerRecord != null) {
91-
log('received signedPeerRecord from %p', connection.remotePeer)
91+
log.trace('received signedPeerRecord from %p', connection.remotePeer)
9292

9393
let peerRecordEnvelope = message.signedPeerRecord
9494
const envelope = await RecordEnvelope.openAndCertify(peerRecordEnvelope, PeerRecord.DOMAIN)
@@ -150,7 +150,7 @@ export async function consumeIdentifyMessage (peerStore: PeerStore, events: Type
150150
log('%p did not send a signed peer record', connection.remotePeer)
151151
}
152152

153-
log('patching %p with', connection.remotePeer, peer)
153+
log.trace('patching %p with', connection.remotePeer, peer)
154154
await peerStore.patch(connection.remotePeer, peer)
155155

156156
if (message.agentVersion != null || message.protocolVersion != null) {
@@ -164,7 +164,7 @@ export async function consumeIdentifyMessage (peerStore: PeerStore, events: Type
164164
metadata.ProtocolVersion = uint8ArrayFromString(message.protocolVersion)
165165
}
166166

167-
log('merging %p metadata', connection.remotePeer, metadata)
167+
log.trace('merging %p metadata', connection.remotePeer, metadata)
168168
await peerStore.merge(connection.remotePeer, {
169169
metadata
170170
})

0 commit comments

Comments
 (0)