mirror of https://github.com/waku-org/js-waku.git
chore(peer-exchange): refactor/fix compliance test (#1478)
* use `peer:identify` instead of `peer:update` * dial the peer after initialising peer-exchange
This commit is contained in:
parent
d97579bf53
commit
1548a4f8e4
|
@ -1,4 +1,4 @@
|
|||
import type { PeerUpdate } from "@libp2p/interface-libp2p";
|
||||
import type { IdentifyResult } from "@libp2p/interface-libp2p";
|
||||
import type {
|
||||
PeerDiscovery,
|
||||
PeerDiscoveryEvents,
|
||||
|
@ -61,11 +61,10 @@ export class PeerExchangeDiscovery
|
|||
private queryAttempts: Map<string, number> = new Map();
|
||||
|
||||
private readonly handleDiscoveredPeer = (
|
||||
event: CustomEvent<PeerUpdate>,
|
||||
event: CustomEvent<IdentifyResult>,
|
||||
): void => {
|
||||
const {
|
||||
peer: { protocols, id: peerId },
|
||||
} = event.detail;
|
||||
const { protocols, peerId } = event.detail;
|
||||
|
||||
if (
|
||||
!protocols.includes(PeerExchangeCodec) ||
|
||||
this.queryingPeers.has(peerId.toString())
|
||||
|
@ -98,7 +97,7 @@ export class PeerExchangeDiscovery
|
|||
|
||||
// might be better to use "peer:identify" or "peer:update"
|
||||
this.components.events.addEventListener(
|
||||
"peer:update",
|
||||
"peer:identify",
|
||||
this.handleDiscoveredPeer,
|
||||
);
|
||||
}
|
||||
|
@ -112,7 +111,7 @@ export class PeerExchangeDiscovery
|
|||
this.isStarted = false;
|
||||
this.queryingPeers.clear();
|
||||
this.components.events.removeEventListener(
|
||||
"peer:update",
|
||||
"peer:identify",
|
||||
this.handleDiscoveredPeer,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -117,7 +117,11 @@ describe("Peer Exchange", () => {
|
|||
await waku.start();
|
||||
|
||||
const nwaku2Ma = await nwaku2.getMultiaddrWithId();
|
||||
await waku.libp2p.dialProtocol(nwaku2Ma, PeerExchangeCodec);
|
||||
|
||||
// we do this because we want peer-exchange discovery to get initialised before we dial the peer which contains info about the other peer
|
||||
setTimeout(() => {
|
||||
void waku.libp2p.dialProtocol(nwaku2Ma, PeerExchangeCodec);
|
||||
}, 1000);
|
||||
|
||||
return new PeerExchangeDiscovery(waku.libp2p.components);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue