Merge pull request #10149 from FlattestWhite/richard/make-user-agent-dependency-injectable

feat: Allow libp2p user agent to be overriden
This commit is contained in:
Łukasz Magiera 2023-02-01 19:12:08 +01:00 committed by GitHub
commit 7060150bdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -67,9 +67,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

View File

@ -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)
}