提交 b14907b7 作者: vyzo 提交者: Steven Allen

use libp2p.Routing in constructor for routing host construction and autorelay

License: MIT
Signed-off-by: 's avatarvyzo <vyzo@hackzen.org>
上级 a14f2033
......@@ -259,12 +259,21 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
libp2pOpts = append(libp2pOpts, libp2p.Transport(quic.NewTransport))
}
// enable routing and autorelay
libp2pOpts = append(libp2pOpts, libp2p.Routing(func(h p2phost.Host) (routing.PeerRouting, error) {
r, err := routingOption(ctx, h, n.Repo.Datastore(), n.RecordValidator)
n.Routing = r
return r, err
}))
peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, libp2pOpts...)
if err != nil {
return err
}
n.PeerHost = peerhost
if err := n.startOnlineServicesWithHost(ctx, peerhost, routingOption, pubsub, ipnsps); err != nil {
return err
}
......@@ -496,12 +505,17 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
n.PubSub = service
}
// setup routing service
r, err := routingOption(ctx, host, n.Repo.Datastore(), n.RecordValidator)
if err != nil {
return err
// sadly, this code is necessary just for tests:
// it is necessary for mock network constructions that ignore the libp2p options
// that actually construct the routing!
if n.Routing == nil {
r, err := routingOption(ctx, host, n.Repo.Datastore(), n.RecordValidator)
if err != nil {
return err
}
n.Routing = r
n.PeerHost = rhost.Wrap(host, n.Routing)
}
n.Routing = r
// TODO: I'm not a fan of type assertions like this but the
// `RoutingOption` system doesn't currently provide access to the
......@@ -516,7 +530,7 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
// PSRouter case below.
// 3. Introduce some kind of service manager? (my personal favorite but
// that requires a fair amount of work).
if dht, ok := r.(*dht.IpfsDHT); ok {
if dht, ok := n.Routing.(*dht.IpfsDHT); ok {
n.DHT = dht
}
......@@ -543,9 +557,6 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
}
}
// Wrap standard peer host with routing system to allow unknown peer lookups
n.PeerHost = rhost.Wrap(host, n.Routing)
// setup exchange service
bitswapNetwork := bsnet.NewFromIpfsHost(n.PeerHost, n.Routing)
n.Exchange = bitswap.New(ctx, bitswapNetwork, n.Blockstore)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论