Skip to content

Commit

Permalink
Merge pull request #10149 from FlattestWhite/richard/make-user-agent-…
Browse files Browse the repository at this point in the history
…dependency-injectable

feat: Allow libp2p user agent to be overriden
  • Loading branch information
magik6k authored Feb 1, 2023
2 parents b8e7262 + 45ceb5d commit 7060150
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions node/modules/lp2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 7060150

Please # to comment.