提交 ca8190a8 作者: Brian Tiger Chow

refactor(core): isolate complex DHT initialization

上级 eb6c40d5
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58" b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
ctxgroup "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup" ctxgroup "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
datastore "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
bstore "github.com/jbenet/go-ipfs/blocks/blockstore" bstore "github.com/jbenet/go-ipfs/blocks/blockstore"
...@@ -201,11 +202,12 @@ func (n *IpfsNode) StartOnlineServices() error { ...@@ -201,11 +202,12 @@ func (n *IpfsNode) StartOnlineServices() error {
n.Diagnostics = diag.NewDiagnostics(n.Identity, n.PeerHost) n.Diagnostics = diag.NewDiagnostics(n.Identity, n.PeerHost)
// setup routing service // setup routing service
dhtRouting := dht.NewDHT(ctx, n.PeerHost, n.Datastore) dhtRouting, err := constructDHTRouting(ctx, n.ContextGroup, n.PeerHost, n.Datastore)
dhtRouting.Validators[IpnsValidatorTag] = namesys.ValidateIpnsRecord if err != nil {
n.Routing = dhtRouting return debugerror.Wrap(err)
}
n.DHT = dhtRouting n.DHT = dhtRouting
n.AddChildGroup(dhtRouting) n.Routing = dhtRouting
// setup exchange service // setup exchange service
const alwaysSendToPeer = true // use YesManStrategy const alwaysSendToPeer = true // use YesManStrategy
...@@ -232,7 +234,7 @@ func (n *IpfsNode) StartOnlineServices() error { ...@@ -232,7 +234,7 @@ func (n *IpfsNode) StartOnlineServices() error {
} }
bootstrapPeers = append(bootstrapPeers, p) bootstrapPeers = append(bootstrapPeers, p)
} }
go superviseConnections(ctx, n.PeerHost, dhtRouting, n.Peerstore, bootstrapPeers) go superviseConnections(ctx, n.PeerHost, n.DHT, n.Peerstore, bootstrapPeers)
return nil return nil
} }
...@@ -381,3 +383,10 @@ func constructPeerHost(ctx context.Context, ctxg ctxgroup.ContextGroup, cfg *con ...@@ -381,3 +383,10 @@ func constructPeerHost(ctx context.Context, ctxg ctxgroup.ContextGroup, cfg *con
ps.AddAddresses(id, addrs) ps.AddAddresses(id, addrs)
return peerhost, nil return peerhost, nil
} }
func constructDHTRouting(ctx context.Context, ctxg ctxgroup.ContextGroup, host p2phost.Host, ds datastore.ThreadSafeDatastore) (*dht.IpfsDHT, error) {
dhtRouting := dht.NewDHT(ctx, host, ds)
dhtRouting.Validators[IpnsValidatorTag] = namesys.ValidateIpnsRecord
ctxg.AddChildGroup(dhtRouting)
return dhtRouting, nil
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论