Type updates#118
Conversation
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
}
No description provided.