diff --git a/core/bootstrap.go b/core/bootstrap.go index 1162260287974559b8d60ded255ad2c0819684e1..83eddde7c3248384ff6dc4b4b1992da7d6722793 100644 --- a/core/bootstrap.go +++ b/core/bootstrap.go @@ -106,7 +106,7 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) { proc.Go(periodic) // run one right now. // kick off dht bootstrapping. - dbproc, err := thedht.Bootstrap(dht.DefaultBootstrapConfig) + dbproc, err := thedht.BootstrapWithConfig(dht.DefaultBootstrapConfig) if err != nil { proc.Close() return nil, err diff --git a/routing/dht/dht_bootstrap.go b/routing/dht/dht_bootstrap.go index f2cc50f9a79f716e76857bda53cc911820533d17..18451f1c3ac98abbc8051f7fd0c11a694fcf2139 100644 --- a/routing/dht/dht_bootstrap.go +++ b/routing/dht/dht_bootstrap.go @@ -4,6 +4,7 @@ package dht import ( "crypto/rand" + "errors" "fmt" "sync" "time" @@ -44,13 +45,18 @@ var DefaultBootstrapConfig = BootstrapConfig{ Timeout: time.Duration(20 * time.Second), } +func (dht *IpfsDHT) Bootstrap(context.Context) error { + // Bootstrap satisfies the routing interface + return errors.New("TODO: perform DHT bootstrap") +} + // Bootstrap ensures the dht routing table remains healthy as peers come and go. // it builds up a list of peers by requesting random peer IDs. The Bootstrap // process will run a number of queries each time, and run every time signal fires. // These parameters are configurable. // // Bootstrap returns a process, so the user can stop it. -func (dht *IpfsDHT) Bootstrap(config BootstrapConfig) (goprocess.Process, error) { +func (dht *IpfsDHT) BootstrapWithConfig(config BootstrapConfig) (goprocess.Process, error) { sig := time.Tick(config.Period) return dht.BootstrapOnSignal(config, sig) } diff --git a/routing/mock/centralized_client.go b/routing/mock/centralized_client.go index 4a9b63b01d724cc37730685b0fd20a03bf8d5918..6d358f52b7c05702218a51c01011252fb038e8e9 100644 --- a/routing/mock/centralized_client.go +++ b/routing/mock/centralized_client.go @@ -84,4 +84,8 @@ func (c *client) Ping(ctx context.Context, p peer.ID) (time.Duration, error) { return 0, nil } +func (c *client) Bootstrap(context.Context) error { + return nil +} + var _ routing.IpfsRouting = &client{} diff --git a/routing/offline/offline.go b/routing/offline/offline.go index 63fb14441083a69c670ffe3ddd3558b30f6bf2d7..c73d73391854d95a5c08362ae1b8ade752da076a 100644 --- a/routing/offline/offline.go +++ b/routing/offline/offline.go @@ -89,5 +89,9 @@ func (c *offlineRouting) Ping(ctx context.Context, p peer.ID) (time.Duration, er return 0, ErrOffline } +func (c *offlineRouting) Bootstrap(context.Context) (error) { + return nil +} + // ensure offlineRouting matches the IpfsRouting interface var _ routing.IpfsRouting = &offlineRouting{} diff --git a/routing/routing.go b/routing/routing.go index 8238aa45c476ea88e3bcc2042143b67b3dcd9336..3dea2feb616c21d9af2a3b3eb57b2730e776ae1f 100644 --- a/routing/routing.go +++ b/routing/routing.go @@ -40,4 +40,10 @@ type IpfsRouting interface { // Ping a peer, log the time it took Ping(context.Context, peer.ID) (time.Duration, error) + + // Bootstrap allows callers to hint to the routing system to get into a + // Boostrapped state + Bootstrap(context.Context) error + + // TODO expose io.Closer or plain-old Close error }