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

gate autorelay with config option

License: MIT
Signed-off-by: 's avatarvyzo <vyzo@hackzen.org>
上级 b14907b7
......@@ -260,11 +260,13 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
}
// 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
}))
if cfg.Swarm.EnableAutoRelay {
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...)
......@@ -505,8 +507,9 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
n.PubSub = service
}
// sadly, this code is necessary just for tests:
// it is necessary for mock network constructions that ignore the libp2p options
// this code is necessary as the host is constructed with routing only if autorelay
// is enabled.
// it is also necessary for tests: mock network constructions ignore the libp2p options
// that actually construct the routing!
if n.Routing == nil {
r, err := routingOption(ctx, host, n.Repo.Datastore(), n.RecordValidator)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论