Skip to content

Commit

Permalink
fix: ignore peers with invalid multiaddrs (#1902)
Browse files Browse the repository at this point in the history
It's necessary to convert `.addresses` to `.multiaddrs` to conform to the `PeerInfo` interface.

Closes #1873

---------

Co-authored-by: Alex Potsides <alex@achingbrain.net>
  • Loading branch information
maschad and achingbrain authored Jul 30, 2023
1 parent 57c3272 commit a41d25d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/libp2p/src/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
components.events.addEventListener('peer:update', evt => {
// if there was no peer previously in the peer store this is a new peer
if (evt.detail.previous == null) {
this.safeDispatchEvent('peer:discovery', { detail: evt.detail.peer })
const peerInfo: PeerInfo = {
id: evt.detail.peer.id,
multiaddrs: evt.detail.peer.addresses.map(a => a.multiaddr),
protocols: evt.detail.peer.protocols
}

this.safeDispatchEvent('peer:discovery', { detail: peerInfo })
}
})

Expand Down

0 comments on commit a41d25d

Please sign in to comment.