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.
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.
Hi @raul - thanks for this reply. I actually tried what you said but stumbled across this issue - the type of the stream object don’t match between a stream created using host.NewStream and what is found using host.Network().ConnsToPeer(id) and then conn.GetStreams().
NewStream returns - *basichost.streamWrapper while latter returns *swarm.Stream.
Is that as expected and can they be used interchangeably?
thanks
@vishal hey! Both of them return structs that conform to the network.Stream interface. See godocs:
You shouldn’t be needed to access the actual implementation type. Do you have a code sample you can post? Or maybe we can pair on this? (ping me via email)