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

Migrate go-kademlia state machines #893

Merged
merged 11 commits into from
Sep 13, 2023
Merged

Migrate go-kademlia state machines #893

merged 11 commits into from
Sep 13, 2023

Conversation

iand
Copy link

@iand iand commented Sep 12, 2023

I also took the opportunity to remove usage of NodeInfo/Address and replace with a generic NodeID

I tidied up some naming and made everything more consistent. I plan to move the behaviours into the routing and query directories too and do some more cleanup next.

@iand iand added the v2 All issues related to the v2 rewrite label Sep 12, 2023
@iand iand self-assigned this Sep 12, 2023
// This function will panic if id's underlying type is not kadt.PeerID
func NodeIDToAddrInfo(id kad.NodeID[KadKey]) peer.AddrInfo {
func KadPeerIDToAddrInfo(id kad.NodeID[KadKey]) peer.AddrInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still in use?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, but I can double check. I iiterated on checking whether I could remove these helpers after each round of refactoring.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In use in a few places. Hopefully we can straighten out the types and have fewer conversion functions in the future

@@ -324,7 +324,7 @@ func (c *Coordinator) GetClosestNodes(ctx context.Context, k KadKey, n int) ([]N
closest := c.rt.NearestNodes(k, n)
nodes := make([]Node, 0, len(closest))
for _, id := range closest {
nh, err := c.networkBehaviour.getNodeHandler(ctx, NodeIDToPeerID(id))
nh, err := c.networkBehaviour.getNodeHandler(ctx, peer.ID(id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from this call, it looks liek getNodeHandler is operating on a peer.ID.

As a general separation, I think it would be great if most of the things in coord only operated on kadt.PeerID. Not sure if there is anything prohibiting that in this case here - just a general idea.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that sounds sensible, will check usage here before merging

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed this specific usage and converted the self fields for the coordiinator and behaviours to kadt.PeerID, but doing more means touching the Router interface so let's do that in a later PR.

@@ -38,7 +37,7 @@ func LinearTopology(n int, clk clock.Clock) (*Topology, []*Node, error) {
nodes[i] = &Node{
NodeInfo: ai,
Router: NewRouter(ai.ID, top),
RoutingTable: simplert.New[key.Key256, kad.NodeID[key.Key256]](kadt.PeerID(ai.ID), 20),
RoutingTable: simplert.New[key.Key256, kadt.PeerID](kadt.PeerID(ai.ID), 20),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes we're using key.Key256 and sometimes the alias KadKey in coord. It would be great if we could be consistent and use either everywhere.

  1. use key.Key256 everywhere
  2. move coord.KadKey to, e.g., kadt.Key and use it from there
  3. (make the coordinator generic on the key type and use K everywhere)

Intuitively I would have done 2 🤷‍♂️ but don't have a strong opinion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on 2. I just missed this one. Will do another iteration of search and replace :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may make the coordinator generic in the same way the state machines are. It might be cleaner, but might not be worth the effort at this stage.

v2/coord/network.go Outdated Show resolved Hide resolved
@dennis-tra
Copy link
Contributor

Thanks for already doing the type changes! I only remarked nits and stuff that I can do in a separate PR for example.

@iand iand merged commit 77dbff0 into v2-develop Sep 13, 2023
8 of 18 checks passed
@dennis-tra dennis-tra deleted the v2-gokademlia-migration branch September 13, 2023 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 All issues related to the v2 rewrite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants