From 28c0013d5ba7437b609b4cfa9cf5f6ed5b88ef5c Mon Sep 17 00:00:00 2001 From: requilence Date: Thu, 25 Apr 2019 13:49:08 +0200 Subject: [PATCH] Fix AutoNAT service for private network License: MIT Signed-off-by: Roman Khafizianov --- core/node/libp2p/libp2p.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/node/libp2p/libp2p.go b/core/node/libp2p/libp2p.go index ad350501e01..95497386fa7 100644 --- a/core/node/libp2p/libp2p.go +++ b/core/node/libp2p/libp2p.go @@ -524,16 +524,23 @@ func PubsubRouter(mctx helpers.MetricsCtx, lc fx.Lifecycle, in p2pPSRoutingIn) ( }, psRouter } -func AutoNATService(mctx helpers.MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host host.Host) error { +func AutoNATService(repo repo.Repo, mctx helpers.MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host host.Host) error { if !cfg.Swarm.EnableAutoNATService { return nil } - var opts []libp2p.Option + + // collect private net option in case swarm.key is presented + opts, _, err := PNet(repo) + if err != nil { + // swarm key exists but was failed to decode + return err + } + if cfg.Experimental.QUIC { - opts = append(opts, libp2p.DefaultTransports, libp2p.Transport(libp2pquic.NewTransport)) + opts.Opts = append(opts.Opts, libp2p.DefaultTransports, libp2p.Transport(libp2pquic.NewTransport)) } - _, err := autonat.NewAutoNATService(helpers.LifecycleCtx(mctx, lc), host, opts...) + _, err = autonat.NewAutoNATService(helpers.LifecycleCtx(mctx, lc), host, opts.Opts...) return err }