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

kademlia: be louder about the kind of mode we are operating in #4310

Closed
4 tasks
thomaseizinger opened this issue Aug 10, 2023 · 7 comments · Fixed by #4503
Closed
4 tasks

kademlia: be louder about the kind of mode we are operating in #4310

thomaseizinger opened this issue Aug 10, 2023 · 7 comments · Fixed by #4503

Comments

@thomaseizinger
Copy link
Contributor

thomaseizinger commented Aug 10, 2023

Description

The whole client/server mode functionality is quite involved and hard to understand for newcomers. We should find a way to be loud about it without spamming people's logs.

Are you planning to do it yourself in a pull request?

No but maybe @dhuseby wants to land his first contribution to rust-libp2p :)

Tasks

@thomaseizinger thomaseizinger changed the title kademlia: be more verbose about the kind of mode we are operating in kademlia: be louder about the kind of mode we are operating in Aug 10, 2023
@dhuseby
Copy link
Contributor

dhuseby commented Aug 15, 2023

I think the best way to make this newb-friendly would be to add network behavior events that reflect the current state of the kademlia behavior. AFAICT, the kademlia behavior has roughly these states:

  1. initialized but not participating because it doesn't have an external address
  2. external address has been confirmed
  3. kademlia protocol has been added to list of local protocols for Identify to send out
  4. received KAD messages from external peers

I think there are valid transitions from 1 to 2 to 3 to 4 and then from 3 to 1 and 4 to 1 whenever the external address goes away and also 3 to 2 and 4 to 2 whenever the external address changes. All transitions should have kademlia events associated with them so that an app can monitor the status of the peer's kademlia participation and reflect that in the logs/UI.

The only way to be 100% certain that a peer is participating in a KAD DHT is to receive KAD messags from external peers. There is no notion of a "session" with confirmation from other peers. So state 4 is important to have as well as an event for the state transition from 3 to 4.

@dhuseby
Copy link
Contributor

dhuseby commented Aug 15, 2023

@thomaseizinger do you have any more specifics about what it would look like to "be louder" about the state of the kademlia behavior? Are my four states the ones that would suffice?

@thomaseizinger
Copy link
Contributor Author

Perhaps a single event ModeChanged would also suffice?

I don't think we should fire that when the mode is set manually. I am also not sure we should fire it initially because the mode technically hasn't changed, we always start in client-mode.

So maybe it needs several individual improvements.

I am of the opinion that we can expect users to read some documentation. Like what the default mode is and perhaps even how the algorithm works for determining it automatically.

Overall, what I find tricky to balance here is:

  • Making the API as minimal as possible. Each symbol adds complexity which also makes things harder to understand.
  • Staying/being modular. If we want to be a modular networking library, we need to work with multiple usecases. Every API element we add should make sense in all cases.
  • Documentation vs code. Some code can be self-explaining and guide the user. But some things are just better expressed as docs.

@dhuseby
Copy link
Contributor

dhuseby commented Aug 16, 2023

I think it is useful to know when the kademlia behavior switches, both from client to server and back. I guess a single ModeChanged with the new mode as an enum would suffice. There's no other way to know what mode it is in.

@mxinden
Copy link
Member

mxinden commented Aug 17, 2023

Perhaps a single event ModeChanged would also suffice?

In favor of this. Especially since we can then expose the Mode as a Prometheus metric in libp2p-metrics.

@thomaseizinger
Copy link
Contributor Author

I'll update the PR description!

@dhuseby dhuseby self-assigned this Aug 18, 2023
@dhuseby
Copy link
Contributor

dhuseby commented Aug 18, 2023

this would be useful.

@mergify mergify bot closed this as completed in #4503 Oct 20, 2023
mergify bot pushed a commit that referenced this issue Oct 20, 2023
Previously, the kademlia protocol would only log changes to the internal mode. With this patch, we now also emit an event which allows users to code against the internal state of the kademlia protocol.

Fixes #4310.

Pull-Request: #4503.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment