Skip to content

Commit

Permalink
fix: ping return
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Jan 8, 2024
1 parent 0436a35 commit babefc7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core/src/lib/base_protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export class BaseProtocol implements IBaseProtocol {
filteredPeers
);

if (sortedFilteredPeers.length === 0) {
throw new Error("No peers found");
}

return sortedFilteredPeers;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/libp2p/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function sortPeersByLatency(
peers.map(async (peer) => {
try {
const pingBytes = (await peerStore.get(peer.id)).metadata.get("ping");
if (!pingBytes) return null;
if (!pingBytes) return { peer, ping: Infinity };

const ping = Number(bytesToUtf8(pingBytes));
return isNaN(ping) ? null : { peer, ping };
Expand Down

0 comments on commit babefc7

Please sign in to comment.