gate autorelay with config option
License: MIT Signed-off-by: vyzo <vyzo@hackzen.org>
vyzo committed
Nov 28, 2018 at 14:54 UTC
b514820f215118686099ea9f1760541fc09565bf
1 file changed
+10
-7
core/core.go
+10
-7
@@ -260,11 +260,13 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
260
}
261
262
// enable routing and autorelay
263
- libp2pOpts = append(libp2pOpts, libp2p.Routing(func(h p2phost.Host) (routing.PeerRouting, error) {
264
- r, err := routingOption(ctx, h, n.Repo.Datastore(), n.RecordValidator)
265
- n.Routing = r
266
- return r, err
267
- }))
263
+ if cfg.Swarm.EnableAutoRelay {
264
+ libp2pOpts = append(libp2pOpts, libp2p.Routing(func(h p2phost.Host) (routing.PeerRouting, error) {
265
+ r, err := routingOption(ctx, h, n.Repo.Datastore(), n.RecordValidator)
266
+ n.Routing = r
267
+ return r, err
268
+ }))
269
+ }
270
271
peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, libp2pOpts...)
272
@@ -505,8 +507,9 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
507
n.PubSub = service
508
}
509
508
- // sadly, this code is necessary just for tests:
509
- // it is necessary for mock network constructions that ignore the libp2p options
510
+ // this code is necessary as the host is constructed with routing only if autorelay
511
+ // is enabled.
512
+ // it is also necessary for tests: mock network constructions ignore the libp2p options
513
// that actually construct the routing!
514
if n.Routing == nil {
515
r, err := routingOption(ctx, host, n.Repo.Datastore(), n.RecordValidator)