Skip to content

Commit

Permalink
fix: switch informational logging to trace logging (#2727)
Browse files Browse the repository at this point in the history
Where logging is very verbose, switch informational logs to trace logging
  • Loading branch information
achingbrain authored Sep 25, 2024
1 parent 80fb47f commit 442a835
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/multistream-select/src/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
continue
}

options.log('handle: respond with "na" for "%s"', protocol)
options.log.trace('handle: respond with "na" for "%s"', protocol)
await multistream.write(lp, uint8ArrayFromString('na\n'), options)
options.log('handle: responded with "na" for "%s"', protocol)
}
Expand Down
1 change: 1 addition & 0 deletions packages/protocol-identify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@libp2p/interface-internal": "^2.0.4",
"@libp2p/peer-id": "^5.0.4",
"@libp2p/peer-record": "^8.0.4",
"@libp2p/utils": "^6.0.4",
"@multiformats/multiaddr": "^12.2.3",
"@multiformats/multiaddr-matcher": "^1.2.1",
"it-drain": "^3.0.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-identify/src/identify-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ export class IdentifyPush extends AbstractIdentify implements Startable, Identif
return
}

this.log('handled push from %p', connection.remotePeer)
this.log.trace('handled push from %p', connection.remotePeer)
}
}
28 changes: 20 additions & 8 deletions packages/protocol-identify/src/identify.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable complexity */

import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys'
import { InvalidMessageError, serviceCapabilities, setMaxListeners } from '@libp2p/interface'
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 { protocols } from '@multiformats/multiaddr'
import { IP_OR_DOMAIN } from '@multiformats/multiaddr-matcher'
import { pbStream } from 'it-protobuf-stream'
Expand All @@ -29,7 +30,15 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
// When a new connection happens, trigger identify
components.events.addEventListener('connection:open', (evt) => {
const connection = evt.detail
this.identify(connection).catch(err => { this.log.error('error during identify trigged by connection:open', err) })
this.identify(connection)
.catch(err => {
if (err.name === UnsupportedProtocolError.name) {
// the remote did not support identify, ignore the error
return
}

this.log.error('error during identify trigged by connection:open', err)
})
})
}
}
Expand Down Expand Up @@ -67,7 +76,6 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt

return message
} catch (err: any) {
this.log.error('error while reading identify message', err)
stream?.abort(err)
throw err
}
Expand Down Expand Up @@ -100,12 +108,16 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
const cleanObservedAddr = getCleanMultiaddr(observedAddr)

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

if (cleanObservedAddr != null &&
this.addressManager.getObservedAddrs().length < (this.maxObservedAddresses ?? Infinity)) {
this.log('storing our observed address %a', cleanObservedAddr)
this.addressManager.addObservedAddr(cleanObservedAddr)
if (cleanObservedAddr != null) {
this.log('our observed address was %a', cleanObservedAddr)

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

return consumeIdentifyMessage(this.peerStore, this.events, this.log, connection, message)
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol-identify/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function consumeIdentifyMessage (peerStore: PeerStore, events: Type

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

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

log('patching %p with', connection.remotePeer, peer)
log.trace('patching %p with', connection.remotePeer, peer)
await peerStore.patch(connection.remotePeer, peer)

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

log('merging %p metadata', connection.remotePeer, metadata)
log.trace('merging %p metadata', connection.remotePeer, metadata)
await peerStore.merge(connection.remotePeer, {
metadata
})
Expand Down

0 comments on commit 442a835

Please sign in to comment.