refactor(core) switch style to type assertions
@jbenet cool with this?
Brian Tiger Chow committed
Jan 17, 2015 at 02:59 UTC
a025fc9adffefed5e9d25a0f8421ec6c8b5ea03d
2 files changed
+11
-12
core/core.go
+11
-11
@@ -84,10 +84,6 @@ type IpfsNode struct {
84
85
ctxgroup.ContextGroup
86
87
- // dht allows node to Bootstrap when dht is present
88
- // TODO privatize before merging. This is here temporarily during the
89
- // migration of the TestNet constructor
90
- DHT *dht.IpfsDHT
87
mode mode
88
}
89
@@ -227,7 +223,6 @@ func (n *IpfsNode) StartOnlineServices(ctx context.Context) error {
223
if err != nil {
224
return debugerror.Wrap(err)
225
}
230
- n.DHT = dhtRouting
226
n.Routing = dhtRouting
227
228
// setup exchange service
@@ -255,11 +250,12 @@ func (n *IpfsNode) StartOnlineServices(ctx context.Context) error {
250
}
251
bootstrapPeers = append(bootstrapPeers, p)
252
}
258
- go superviseConnections(ctx, n.PeerHost, n.DHT, n.Peerstore, bootstrapPeers)
253
260
- // Start up reprovider system
254
+ go superviseConnections(ctx, n.PeerHost, dhtRouting, n.Peerstore, bootstrapPeers)
255
+
256
n.Reprovider = rp.NewReprovider(n.Routing, n.Blockstore)
257
go n.Reprovider.ProvideEvery(ctx, time.Hour*12)
258
+
259
return nil
260
}
261
@@ -272,8 +268,10 @@ func (n *IpfsNode) teardown() error {
268
if n.Repo != nil {
269
closers = append(closers, n.Repo)
270
}
275
- if n.DHT != nil {
276
- closers = append(closers, n.DHT)
271
+ if n.Routing != nil {
272
+ if dht, ok := n.Routing.(*dht.IpfsDHT); ok {
273
+ closers = append(closers, dht)
274
+ }
275
}
276
if n.PeerHost != nil {
277
closers = append(closers, n.PeerHost)
@@ -310,8 +308,10 @@ func (n *IpfsNode) Bootstrap(ctx context.Context, peers []peer.PeerInfo) error {
308
309
// TODO what should return value be when in offlineMode?
310
313
- if n.DHT != nil {
314
- return bootstrap(ctx, n.PeerHost, n.DHT, n.Peerstore, peers)
311
+ if n.Routing != nil {
312
+ if dht, ok := n.Routing.(*dht.IpfsDHT); ok {
313
+ return bootstrap(ctx, n.PeerHost, dht, n.Peerstore, peers)
314
+ }
315
}
316
return nil
317
}
test/epictest/core.go
-1
@@ -46,7 +46,6 @@ func MocknetTestRepo(p peer.ID, h host.Host, conf testutil.LatencyConfig) core.C
46
PeerHost: h,
47
Routing: dhtt,
48
Identity: p,
49
- DHT: dhtt,
49
}, nil
50
}
51
}