Skip to content

Commit a41d25d

Browse files
maschadachingbrain
andauthored
fix: ignore peers with invalid multiaddrs (#1902)
It's necessary to convert `.addresses` to `.multiaddrs` to conform to the `PeerInfo` interface. Closes #1873 --------- Co-authored-by: Alex Potsides <alex@achingbrain.net>
1 parent 57c3272 commit a41d25d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/libp2p/src/libp2p.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
9999
components.events.addEventListener('peer:update', evt => {
100100
// if there was no peer previously in the peer store this is a new peer
101101
if (evt.detail.previous == null) {
102-
this.safeDispatchEvent('peer:discovery', { detail: evt.detail.peer })
102+
const peerInfo: PeerInfo = {
103+
id: evt.detail.peer.id,
104+
multiaddrs: evt.detail.peer.addresses.map(a => a.multiaddr),
105+
protocols: evt.detail.peer.protocols
106+
}
107+
108+
this.safeDispatchEvent('peer:discovery', { detail: peerInfo })
103109
}
104110
})
105111

0 commit comments

Comments
 (0)