From a8dace0f2382925fee8c5704d1ffabdd92dbe61d Mon Sep 17 00:00:00 2001 From: Richard Guan Date: Tue, 31 Jan 2023 21:40:55 +0900 Subject: [PATCH 1/2] make libp2p user agent overridable --- node/builder.go | 3 ++- node/modules/lp2p/host.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/node/builder.go b/node/builder.go index eaf932e2e65..4c2608937ae 100644 --- a/node/builder.go +++ b/node/builder.go @@ -66,9 +66,10 @@ var ( ConnectionManagerKey = special{9} // Libp2p option AutoNATSvcKey = special{10} // Libp2p option BandwidthReporterKey = special{11} // Libp2p option - ConnGaterKey = special{12} // libp2p option + ConnGaterKey = special{12} // Libp2p option DAGStoreKey = special{13} // constructor returns multiple values ResourceManagerKey = special{14} // Libp2p option + UserAgentKey = special{15} // Libp2p option ) type invoke int diff --git a/node/modules/lp2p/host.go b/node/modules/lp2p/host.go index 2d441eb3f29..79e9df534ea 100644 --- a/node/modules/lp2p/host.go +++ b/node/modules/lp2p/host.go @@ -114,3 +114,10 @@ func NilRouting(mctx helpers.MetricsCtx) (BaseIpfsRouting, error) { func RoutedHost(rh RawHost, r BaseIpfsRouting) host.Host { return routedhost.Wrap(rh, r) } + +func UserAgentOption(agent string) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + opts.Opts = append(opts.Opts, libp2p.UserAgent(agent)) + return + } +} From 45ceb5d297895ff0a75b4dae9de7f4d4c86c24d3 Mon Sep 17 00:00:00 2001 From: Richard Guan Date: Tue, 31 Jan 2023 21:46:24 +0900 Subject: [PATCH 2/2] move UserAgentOption upwards --- node/modules/lp2p/host.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/node/modules/lp2p/host.go b/node/modules/lp2p/host.go index 79e9df534ea..f529574f71e 100644 --- a/node/modules/lp2p/host.go +++ b/node/modules/lp2p/host.go @@ -69,6 +69,13 @@ func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (RawHost, return h, nil } +func UserAgentOption(agent string) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + opts.Opts = append(opts.Opts, libp2p.UserAgent(agent)) + return + } +} + func MockHost(mn mocknet.Mocknet, id peer.ID, ps peerstore.Peerstore) (RawHost, error) { return mn.AddPeerWithPeerstore(id, ps) } @@ -114,10 +121,3 @@ func NilRouting(mctx helpers.MetricsCtx) (BaseIpfsRouting, error) { func RoutedHost(rh RawHost, r BaseIpfsRouting) host.Host { return routedhost.Wrap(rh, r) } - -func UserAgentOption(agent string) func() (opts Libp2pOpts, err error) { - return func() (opts Libp2pOpts, err error) { - opts.Opts = append(opts.Opts, libp2p.UserAgent(agent)) - return - } -}