提交 30e4cc9d 作者: vyzo 提交者: Steven Allen

explicitly enable autorelay

License: MIT
Signed-off-by: 's avatarvyzo <vyzo@hackzen.org>
上级 38da46e4
...@@ -261,13 +261,16 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin ...@@ -261,13 +261,16 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
libp2pOpts = append(libp2pOpts, libp2p.Transport(quic.NewTransport)) libp2pOpts = append(libp2pOpts, libp2p.Transport(quic.NewTransport))
} }
// enable routing and autorelay // enable routing
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
}))
// enable autorelay
if cfg.Swarm.EnableAutoRelay { if cfg.Swarm.EnableAutoRelay {
libp2pOpts = append(libp2pOpts, libp2p.Routing(func(h p2phost.Host) (routing.PeerRouting, error) { libp2pOpts = append(libp2pOpts, libp2p.EnableAutoRelay())
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...) peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, libp2pOpts...)
...@@ -522,10 +525,8 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost ...@@ -522,10 +525,8 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
n.PubSub = service n.PubSub = service
} }
// this code is necessary as the host is constructed with routing only if autorelay // this code is necessary as the host is necessary for tests: mock network constructions
// is enabled. // ignore the libp2p options that actually construct the routing!
// it is also necessary for tests: mock network constructions ignore the libp2p options
// that actually construct the routing!
if n.Routing == nil { if n.Routing == nil {
r, err := routingOption(ctx, host, n.Repo.Datastore(), n.RecordValidator) r, err := routingOption(ctx, host, n.Repo.Datastore(), n.RecordValidator)
if err != nil { if err != nil {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论