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

Protocol interface refinement #98

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions kad/kad.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,22 @@ type Response[K Key[K], A Address[A]] interface {
CloserNodes() []NodeInfo[K, A]
}

// RoutingProtocol defines the methods necessary for routing in a network.
type RoutingProtocol[K Key[K], N NodeID[K], A Address[A]] interface {
FindNode(ctx context.Context, to N, target K) (NodeInfo[K, A], []N, error)
// FindNode sends a message to a node requesting that it return its closest nodes to the target key.
FindNode(ctx context.Context, to N, target K) ([]NodeInfo[K, A], error)

// Ping sends a message to a node to perform a liveness check.
Ping(ctx context.Context, to N) error
}

type RecordProtocol[K Key[K], N NodeID[K]] interface {
Get(ctx context.Context, to N, target K) ([]Record, []N, error)
// RecordProtocol defines the methods for storing and retrieving records in a network.
type RecordProtocol[K Key[K], N NodeID[K], A Address[A]] interface {
// Get sends a message to a node requesting that it return the records associated with the target key.
// The node may also return a list of closer nodes that may also store records for that key.
Get(ctx context.Context, to N, target K) ([]Record, []NodeInfo[K, A], error)

// Put sends a message to a node requesting that it store the record.
Put(ctx context.Context, to N, record Record) error
}

Expand Down
Loading