Skip to content

Commit e01ef31

Browse files
committedJul 26, 2023
fix: ignore peers with invalid multiaddrs (libp2p#1873)
1 parent 7debe03 commit e01ef31

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed
 

‎packages/libp2p/src/libp2p.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,19 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
9898

9999
components.events.addEventListener('peer:update', evt => {
100100
// if there was no peer previously in the peer store this is a new peer
101-
if (evt.detail.previous == null) {
102-
this.safeDispatchEvent('peer:discovery', { detail: evt.detail.peer })
101+
if (evt.detail.previous === null) {
102+
103+
if(evt.detail.peer.addresses.length === 0) {
104+
throw new CodeError('peer must have at least one multiaddr', codes.ERR_INVALID_MULTIADDR)
105+
}
106+
107+
const peerInfo: PeerInfo = {
108+
id: evt.detail.peer.id,
109+
multiaddrs: evt.detail.peer.addresses.map(a => a.multiaddr),
110+
protocols: evt.detail.peer.protocols
111+
}
112+
113+
this.safeDispatchEvent('peer:discovery', { detail: peerInfo})
103114
}
104115
})
105116

0 commit comments

Comments
 (0)
Please sign in to comment.