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: fix pubsub interop tests #2191

Merged
merged 1 commit into from
Nov 2, 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
5 changes: 4 additions & 1 deletion packages/libp2p/test/interop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ async function createJsPeer (options: SpawnOptions): Promise<Daemon> {
},
transports: [tcp(), circuitRelayTransport()],
streamMuxers: [],
connectionEncryption: [noise()]
connectionEncryption: [noise()],
connectionManager: {
minConnections: 0
}
}

const services: ServiceFactoryMap = {
Expand Down
13 changes: 10 additions & 3 deletions packages/pubsub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export abstract class PubSubBaseProtocol<Events extends Record<string, any> = Pu
log('connected %p', peerId)

// if this connection is already in use for pubsub, ignore it
if (conn.streams.find(stream => stream.protocol != null && this.multicodecs.includes(stream.protocol)) != null) {
if (conn.streams.find(stream => stream.direction === 'outbound' && stream.protocol != null && this.multicodecs.includes(stream.protocol)) != null) {
log('outbound pubsub streams already present on connection from %p', peerId)
return
}

Expand Down Expand Up @@ -533,8 +534,14 @@ export abstract class PubSubBaseProtocol<Events extends Record<string, any> = Pu
sendRpc (peer: PeerId, rpc: PubSubRPC): void {
const peerStreams = this.peers.get(peer)

if (peerStreams == null || !peerStreams.isWritable) {
log.error('Cannot send RPC to %p as there is no open stream to it available', peer)
if (peerStreams == null) {
log.error('Cannot send RPC to %p as there are no streams to it available', peer)

return
}

if (!peerStreams.isWritable) {
log.error('Cannot send RPC to %p as there is no outbound stream to it available', peer)

return
}
Expand Down
Loading