Skip to content

Type updates#118

Draft
dennis-tra wants to merge 4 commits into
mainfrom
type-updates
Draft

Type updates#118
dennis-tra wants to merge 4 commits into
mainfrom
type-updates

Conversation

@dennis-tra
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread kad/kad.go
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants