diff --git a/coord/coordinator.go b/coord/coordinator.go index 1f0e4b2..a68a2da 100644 --- a/coord/coordinator.go +++ b/coord/coordinator.go @@ -55,6 +55,10 @@ func (q *eventQueue[E]) Dequeue(ctx context.Context) (E, bool) { } } +// FindNodeRequestFunc is a function that creates a request to find the supplied node id +// TODO: consider this being a first class method of the Endpoint +type FindNodeRequestFunc[K kad.Key[K], A kad.Address[A]] func(kad.NodeID[K]) (address.ProtocolID, kad.Request[K, A]) + // A Coordinator coordinates the state machines that comprise a Kademlia DHT // Currently this is only queries and bootstrapping but will expand to include other state machines such as // routing table refresh, and reproviding. @@ -559,14 +563,10 @@ func (c *Coordinator[K, A]) AddNodes(ctx context.Context, infos []kad.NodeInfo[K return nil } -// FindNodeRequestFunc is a function that creates a request to find the supplied node id -// TODO: consider this being a first class method of the Endpoint -type FindNodeRequestFunc[K kad.Key[K], A kad.Address[A]] func(kad.NodeID[K]) (address.ProtocolID, kad.Request[K, A]) - // Bootstrap instructs the coordinator to begin bootstrapping the routing table. // While bootstrap is in progress, no other queries will make progress. -func (c *Coordinator[K, A]) Bootstrap(ctx context.Context, seeds []kad.NodeID[K], fn FindNodeRequestFunc[K, A]) error { - protoID, msg := fn(c.self) +func (c *Coordinator[K, A]) Bootstrap(ctx context.Context, seeds []kad.NodeID[K]) error { + protoID, msg := c.findNodeFn(c.self) bev := &routing.EventBootstrapStart[K, A]{ ProtocolID: protoID, diff --git a/coord/coordinator_test.go b/coord/coordinator_test.go index eefbbd8..79dbc39 100644 --- a/coord/coordinator_test.go +++ b/coord/coordinator_test.go @@ -349,7 +349,7 @@ func TestBootstrap(t *testing.T) { seeds := []kad.NodeID[key.Key8]{ nodes[1].ID(), } - err = c.Bootstrap(ctx, seeds, findNodeFn) + err = c.Bootstrap(ctx, seeds) require.NoError(t, err) // the query run by the coordinator should have received a response from nodes[1]