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

gossipsub: refactor booleans in Handler to state machine #3655

Closed
thomaseizinger opened this issue Mar 22, 2023 · 3 comments
Closed

gossipsub: refactor booleans in Handler to state machine #3655

thomaseizinger opened this issue Mar 22, 2023 · 3 comments

Comments

@thomaseizinger
Copy link
Contributor

Description

Currently, we use a combination of booleans and enums to represent how the remote peer supports gossipsub:

/// 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.

@Shubham8287
Copy link

looking to engage with libp2p, and would love to contribute to it or other beginner-friendly , If provided some help and pointers. Just wanted to ask if you are open for contribution as there is no Contribution.md

@thomaseizinger
Copy link
Contributor Author

looking to engage with libp2p, and would love to contribute to it or other beginner-friendly , If provided some help and pointers. Just wanted to ask if you are open for contribution as there is no Contribution.md

Definitely open to contributions, thank you!

Check out the issues labelled with getting-started and one that matches the difficulty you are after.

Writing a contribution guide is ironically also an open task: #3743

@thomaseizinger
Copy link
Contributor Author

I think @mxinden ended up fixing this particular issue in #3625 so I am gonna close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants