How to check if a stream is already open with peer

Hey, I was wondering how to check if a stream with a certain protocol is already open with a peer.

I’ve been trying to open streams to peers but getting stream reset errors, so I’m guessing they have already opened a stream with me. Let me know if there is perhaps some other issue causing stream reset.

Thanks!

Hey @noot, what implementation of libp2p is this? go-libp2p? One way of doing this is: host.Network().ConnsToPeer(id). For each connection, iterate through streams via conn.GetStreams() and call the Protocol() getter on the stream.

Yep go-libp2p. That works for me, thank you!

I was wondering, what will cause a stream reset when trying to read from a stream? Is it if the other side closes/reopens the stream?

@noot do you mind opening another discussion for that? It’ll be useful for future visitors to headline that answer separately.

1 Like

I’ve opened another thread here What causes a "stream reset"? :slight_smile: