refactor(routing) expose Bootstrap() error on routing interface
Brian Tiger Chow committed
Feb 3, 2015 at 13:50 UTC
9dd12922b341d891a2365beb10d0142fd10fb235
5 files changed
+22
-2
core/bootstrap.go
+1
-1
@@ -106,7 +106,7 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
106
proc.Go(periodic) // run one right now.
107
108
// kick off dht bootstrapping.
109
- dbproc, err := thedht.Bootstrap(dht.DefaultBootstrapConfig)
109
+ dbproc, err := thedht.BootstrapWithConfig(dht.DefaultBootstrapConfig)
110
if err != nil {
111
proc.Close()
112
return nil, err
routing/dht/dht_bootstrap.go
+7
-1
@@ -4,6 +4,7 @@ package dht
4
5
import (
6
"crypto/rand"
7
+ "errors"
8
"fmt"
9
"sync"
10
"time"
@@ -44,13 +45,18 @@ var DefaultBootstrapConfig = BootstrapConfig{
45
Timeout: time.Duration(20 * time.Second),
46
}
47
48
+func (dht *IpfsDHT) Bootstrap(context.Context) error {
49
+ // Bootstrap satisfies the routing interface
50
+ return errors.New("TODO: perform DHT bootstrap")
51
+}
52
+
53
// Bootstrap ensures the dht routing table remains healthy as peers come and go.
54
// it builds up a list of peers by requesting random peer IDs. The Bootstrap
55
// process will run a number of queries each time, and run every time signal fires.
56
// These parameters are configurable.
57
//
58
// Bootstrap returns a process, so the user can stop it.
53
-func (dht *IpfsDHT) Bootstrap(config BootstrapConfig) (goprocess.Process, error) {
59
+func (dht *IpfsDHT) BootstrapWithConfig(config BootstrapConfig) (goprocess.Process, error) {
60
sig := time.Tick(config.Period)
61
return dht.BootstrapOnSignal(config, sig)
62
}
routing/mock/centralized_client.go
+4
@@ -84,4 +84,8 @@ func (c *client) Ping(ctx context.Context, p peer.ID) (time.Duration, error) {
84
return 0, nil
85
}
86
87
+func (c *client) Bootstrap(context.Context) error {
88
+ return nil
89
+}
90
+
91
var _ routing.IpfsRouting = &client{}
routing/offline/offline.go
+4
@@ -89,5 +89,9 @@ func (c *offlineRouting) Ping(ctx context.Context, p peer.ID) (time.Duration, er
89
return 0, ErrOffline
90
}
91
92
+func (c *offlineRouting) Bootstrap(context.Context) (error) {
93
+ return nil
94
+}
95
+
96
// ensure offlineRouting matches the IpfsRouting interface
97
var _ routing.IpfsRouting = &offlineRouting{}
routing/routing.go
+6
@@ -40,4 +40,10 @@ type IpfsRouting interface {
40
41
// Ping a peer, log the time it took
42
Ping(context.Context, peer.ID) (time.Duration, error)
43
+
44
+ // Bootstrap allows callers to hint to the routing system to get into a
45
+ // Boostrapped state
46
+ Bootstrap(context.Context) error
47
+
48
+ // TODO expose io.Closer or plain-old Close error
49
}