-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Description
Currently, we use a combination of booleans and enums to represent how the remote peer supports gossipsub:
rust-libp2p/protocols/gossipsub/src/handler.rs
Lines 109 to 122 in 0e46865
/// The type of peer this handler is associated to. | |
peer_kind: Option<PeerKind>, | |
/// Keeps track on whether we have sent the peer kind to the behaviour. | |
// | |
// NOTE: Use this flag rather than checking the substream count each poll. | |
peer_kind_sent: bool, | |
/// If the peer doesn't support the gossipsub protocol we do not immediately disconnect. | |
/// Rather, we disable the handler and prevent any incoming or outgoing substreams from being | |
/// established. | |
/// | |
/// This value is set to true to indicate the peer doesn't support gossipsub. | |
protocol_unsupported: bool, |
We can simplify this by narrowing down the possible state combinations. For example, currently the type system allows peer_kind
to be Some
and peer_kind_sent
to be true
which is not possible.
Something similar can likely be done with the current outbound stream and the outbound_substream_establishing
flag. It could be an enum:
enum OutboundStream {
Establishing,
Some(S),
None
}
Motivation
- Less complexity in understanding the possible states of the handler
- Use the type system to our advantage
Current Implementation
Are you planning to do it yourself in a pull request?
No.