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

Type updates #118

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Type updates #118

wants to merge 4 commits into from

Conversation

dennis-tra
Copy link
Contributor

No description provided.

type RecordProtocol[K Key[K], N NodeID[K]] interface {
Get(ctx context.Context, to N, target K) ([]Record, []N, error)
Put(ctx context.Context, to N, record Record) error
CloserNodes() []N
Copy link
Contributor

@iand iand Sep 8, 2023

Choose a reason for hiding this comment

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

This is the part that seems like we would want to change back one day. A useful Kademlia library needs to support getting addresses for nodes in the network.

Here's an alternative.

Keep Request/Response, Address and NodeInfo.

Create a new type that just represents a set of nodes assumed to be close to a key:

type KeyNodes[K Key[K], N NodeID[K]] struct {
    Key K
    Nodes []N
} 

Use this new type in all the routing and query state machines instead of Request. Response/Request can still be used in endpoint and simplequery.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another idea: let's rename NodeID[K] to Node[K] and let the implementation of Node[K] carry additional information. go-kademlia doesn't need to know anything about it.

Copy link
Contributor

@iand iand Sep 11, 2023

Choose a reason for hiding this comment

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

Suggestion from a private conversation.

Define

type Node[K kad.Key, P any] interface {
  Key() K
  Preimage() P
}

So a PeerNode in libp2p is a Node[key.Key256, peer.ID]

It might even be better as a struct:

type Node[K kad.Key, P any] struct {
  Key K
  Preimage P
}

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

Successfully merging this pull request may close these issues.

None yet

2 participants