Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: do not append peer id to advertised addresses
Browse files Browse the repository at this point in the history
The libp2p address manager does this so we can just treat the
addresses as opaque here.

Fixes libp2p/js-libp2p#1673
  • Loading branch information
achingbrain committed Apr 7, 2023
1 parent d09bd34 commit 0551eb6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
}

log.trace('received incoming mDNS query')
const localPeerId = this.components.peerId
query.gotQuery(
event,
this.mdns,
this.peerName,
this.components.addressManager.getAddresses().map((ma) => ma.encapsulate('/p2p/' + localPeerId.toString())),
this.components.addressManager.getAddresses(),
this.serviceTag,
this.broadcast)
}
Expand All @@ -109,7 +108,7 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
const foundPeer = query.gotResponse(event, this.peerName, this.serviceTag)

if (foundPeer != null) {
log('discovered peer in mDNS qeury response %p', foundPeer.id)
log('discovered peer in mDNS query response %p', foundPeer.id)

this.dispatchEvent(new CustomEvent<PeerInfo>('peer', {
detail: foundPeer
Expand Down
2 changes: 1 addition & 1 deletion test/multicast-dns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { start, stop } from '@libp2p/interfaces/startable'

function getComponents (peerId: PeerId, multiaddrs: Multiaddr[]): { peerId: PeerId, addressManager: StubbedInstance<AddressManager> } {
const addressManager = stubInterface<AddressManager>()
addressManager.getAddresses.returns(multiaddrs)
addressManager.getAddresses.returns(multiaddrs.map(ma => ma.encapsulate(`/p2p/${peerId.toString()}`)))

return { peerId, addressManager }
}
Expand Down

0 comments on commit 0551eb6

Please sign in to comment.