swarm: Design utility type for tracking pending stream openings #4510
Labels
decision-pending
Marks issues where a decision is pending before we can move forward.
difficulty:hard
In #4275, we made a big effort towards #3268 but it became apparent that for more complex protocols like relay, having to re-code the state tracking for pending outbound streams is cumbersome and should be dealt with more proper.
I've captured some ideas in https://github.com/libp2p/rust-libp2p/pull/4275/files/f3d01ba56731b378a65778d2e2b3d0a2a3bad468#r1314359395 but they should be no means be taken literally. Very likely, this needs a few iterations before we know what this type should look like and offer.
A rough design could be:
The problem we want to solve is that users of this struct should have it easy in terms of correctly tracking the "info" state. The crucial bit here is that there should always be 1
TInfo
instance per pending stream but a pending stream can result in a stream or an error!Currently, those are two different events:
rust-libp2p/swarm/src/handler.rs
Lines 208 to 223 in f5e644d
FullyNegotiatedOutbound
DialUpgradeError
Users must remember that they need to
pop
off an instance of their pendingTInfo
s for either event. The above API design has two functions for this:on_new_stream
andon_stream_error
. This makes it a bit easier but I think overall, it would be better to redesign these events to be something like:Note how the above design only issues a single event for success and error cases. This would allow us to dispatch to a single callback on
OutboundStreams
and do the proper accounting ofTInfo
s in there for the user.The text was updated successfully, but these errors were encountered: