Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(peer-exchange): refactor/fix compliance test #1478

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/peer-exchange/src/waku_peer_exchange_discovery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PeerUpdate } from "@libp2p/interface-libp2p";
import type { IdentifyResult } from "@libp2p/interface-libp2p";
import type {
PeerDiscovery,
PeerDiscoveryEvents,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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,
);
}
Expand All @@ -112,7 +111,7 @@ export class PeerExchangeDiscovery
this.isStarted = false;
this.queryingPeers.clear();
this.components.events.removeEventListener(
"peer:update",
"peer:identify",
this.handleDiscoveredPeer,
);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/tests/tests/peer_exchange.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
Loading