ipfs-shipyard / ipfs-pubsub-1on1

1-to-1 communication channel over IPFS Pubsub between two peers
25 stars 11 forks source link

waitingForPeers waits forever #35

Open haydenyoung opened 1 year ago

haydenyoung commented 1 year ago

When direct connection is connecting, it calls waitForPeers to check that call peers listening for db updates are subscribed to the corresponding pubsub direct channel topic.

However, waitForPeers never returns. It gets stuck waiting for peers because of this line:

const hasAllPeers = peersToWait.map((e) => peers.includes(e)).filter((e) => e === false).length === 0

e should be the address of the peer as a hash, eg. 0x1234567890, but it appears in newer versions of libp2p, the peer is represented by an object called Ed25519PeerIdImpl and so the above checks fail because object comparison is not possible. Ed25519PeerIdImpl, does, however, expose the peer id as a string if Ed25519PeerIdImpl is explicitly cast to the String object.

The proposed fix is to map the peersToWait AND the peers arrays to string versions of each peer, resulting in an array of peer address strings, E.g.

const hasAllPeers = peersToWait.map(e => String(e)).map((e) => peers.map(e => String(e)).includes(e)).filter((e) => e === false).length === 0