Skip to content

Commit

Permalink
constructor: drop P2P prefix from libp2p related units
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Apr 23, 2019
1 parent 38fb008 commit a52f361
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
38 changes: 19 additions & 19 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import (
)

var BaseLibP2P = fx.Options(
fx.Provide(libp2p.P2PAddrFilters),
fx.Provide(libp2p.P2PBandwidthCounter),
fx.Provide(libp2p.P2PPNet),
fx.Provide(libp2p.P2PAddrsFactory),
fx.Provide(libp2p.P2PConnectionManager),
fx.Provide(libp2p.P2PNatPortMap),
fx.Provide(libp2p.P2PRelay),
fx.Provide(libp2p.P2PAutoRealy),
fx.Provide(libp2p.P2PDefaultTransports),
fx.Provide(libp2p.P2PQUIC),
fx.Provide(libp2p.AddrFilters),
fx.Provide(libp2p.BandwidthCounter),
fx.Provide(libp2p.PNet),
fx.Provide(libp2p.AddrsFactory),
fx.Provide(libp2p.ConnectionManager),
fx.Provide(libp2p.NatPortMap),
fx.Provide(libp2p.Relay),
fx.Provide(libp2p.AutoRealy),
fx.Provide(libp2p.DefaultTransports),
fx.Provide(libp2p.QUIC),

fx.Provide(libp2p.P2PHost),
fx.Provide(libp2p.Host),

fx.Provide(libp2p.NewDiscoveryHandler),
fx.Provide(libp2p.DiscoveryHandler),

fx.Invoke(libp2p.AutoNATService),
fx.Invoke(libp2p.P2PPNetChecker),
fx.Invoke(libp2p.PNetChecker),
fx.Invoke(libp2p.StartListening),
fx.Invoke(libp2p.SetupDiscovery),
)
Expand All @@ -39,13 +39,13 @@ func LibP2P(cfg *BuildCfg) fx.Option {
opts := fx.Options(
BaseLibP2P,

fx.Provide(libp2p.P2PSecurity(!cfg.DisableEncryptedConnections)),
fx.Provide(libp2p.Security(!cfg.DisableEncryptedConnections)),
maybeProvide(libp2p.Pubsub, cfg.getOpt("pubsub") || cfg.getOpt("ipnsps")),

fx.Provide(libp2p.P2PSmuxTransport(cfg.getOpt("mplex"))),
fx.Provide(libp2p.P2PRouting),
fx.Provide(libp2p.P2PBaseRouting),
maybeProvide(libp2p.P2PPubsubRouter, cfg.getOpt("ipnsps")),
fx.Provide(libp2p.SmuxTransport(cfg.getOpt("mplex"))),
fx.Provide(libp2p.Routing),
fx.Provide(libp2p.BaseRouting),
maybeProvide(libp2p.PubsubRouter, cfg.getOpt("ipnsps")),
)

return opts
Expand Down Expand Up @@ -85,7 +85,7 @@ func Online(cfg *BuildCfg) fx.Option {

fx.Invoke(IpnsRepublisher),

fx.Provide(p2p.NewP2P),
fx.Provide(p2p.New),

LibP2P(cfg),
Providers,
Expand Down
2 changes: 1 addition & 1 deletion core/node/libp2p/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (dh *discoveryHandler) HandlePeerFound(p peerstore.PeerInfo) {
}
}

func NewDiscoveryHandler(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) *discoveryHandler {
func DiscoveryHandler(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) *discoveryHandler {
return &discoveryHandler{
ctx: helpers.LifecycleCtx(mctx, lc),
host: host,
Expand Down
40 changes: 20 additions & 20 deletions core/node/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Peerstore(id peer.ID, sk crypto.PrivKey) (peerstore.Peerstore, error) {
return ps, nil
}

func P2PAddrFilters(cfg *config.Config) (opts Libp2pOpts, err error) {
func AddrFilters(cfg *config.Config) (opts Libp2pOpts, err error) {
for _, s := range cfg.Swarm.AddrFilters {
f, err := mamask.NewMask(s)
if err != nil {
Expand All @@ -113,7 +113,7 @@ func P2PAddrFilters(cfg *config.Config) (opts Libp2pOpts, err error) {
return opts, nil
}

func P2PBandwidthCounter(cfg *config.Config) (opts Libp2pOpts, reporter metrics.Reporter) {
func BandwidthCounter(cfg *config.Config) (opts Libp2pOpts, reporter metrics.Reporter) {
reporter = metrics.NewBandwidthCounter()

if !cfg.Swarm.DisableBandwidthMetrics {
Expand All @@ -130,7 +130,7 @@ type Libp2pOpts struct {

type PNetFingerprint []byte

func P2PPNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) {
func PNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) {
swarmkey, err := repo.SwarmKey()
if err != nil || swarmkey == nil {
return opts, nil, err
Expand All @@ -146,7 +146,7 @@ func P2PPNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) {
return opts, fp, nil
}

func P2PPNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error {
func PNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error {
// TODO: better check?
swarmkey, err := repo.SwarmKey()
if err != nil || swarmkey == nil {
Expand Down Expand Up @@ -229,7 +229,7 @@ func makeAddrsFactory(cfg config.Addresses) (p2pbhost.AddrsFactory, error) {
}, nil
}

func P2PAddrsFactory(cfg *config.Config) (opts Libp2pOpts, err error) {
func AddrsFactory(cfg *config.Config) (opts Libp2pOpts, err error) {
addrsFactory, err := makeAddrsFactory(cfg.Addresses)
if err != nil {
return opts, err
Expand All @@ -238,7 +238,7 @@ func P2PAddrsFactory(cfg *config.Config) (opts Libp2pOpts, err error) {
return
}

func P2PConnectionManager(cfg *config.Config) (opts Libp2pOpts, err error) {
func ConnectionManager(cfg *config.Config) (opts Libp2pOpts, err error) {
grace := config.DefaultConnMgrGracePeriod
low := config.DefaultConnMgrHighWater
high := config.DefaultConnMgrHighWater
Expand Down Expand Up @@ -308,21 +308,21 @@ func makeSmuxTransportOption(mplexExp bool) libp2p.Option {
return libp2p.ChainOptions(opts...)
}

func P2PSmuxTransport(mplex bool) func() (opts Libp2pOpts, err error) {
func SmuxTransport(mplex bool) func() (opts Libp2pOpts, err error) {
return func() (opts Libp2pOpts, err error) {
opts.Opts = append(opts.Opts, makeSmuxTransportOption(mplex))
return
}
}

func P2PNatPortMap(cfg *config.Config) (opts Libp2pOpts, err error) {
func NatPortMap(cfg *config.Config) (opts Libp2pOpts, err error) {
if !cfg.Swarm.DisableNatPortMap {
opts.Opts = append(opts.Opts, libp2p.NATPortMap())
}
return
}

func P2PRelay(cfg *config.Config) (opts Libp2pOpts, err error) {
func Relay(cfg *config.Config) (opts Libp2pOpts, err error) {
if cfg.Swarm.DisableRelay {
// Enabled by default.
opts.Opts = append(opts.Opts, libp2p.DisableRelay())
Expand All @@ -336,27 +336,27 @@ func P2PRelay(cfg *config.Config) (opts Libp2pOpts, err error) {
return
}

func P2PAutoRealy(cfg *config.Config) (opts Libp2pOpts, err error) {
func AutoRealy(cfg *config.Config) (opts Libp2pOpts, err error) {
// enable autorelay
if cfg.Swarm.EnableAutoRelay {
opts.Opts = append(opts.Opts, libp2p.EnableAutoRelay())
}
return
}

func P2PDefaultTransports() (opts Libp2pOpts, err error) {
func DefaultTransports() (opts Libp2pOpts, err error) {
opts.Opts = append(opts.Opts, libp2p.DefaultTransports)
return
}

func P2PQUIC(cfg *config.Config) (opts Libp2pOpts, err error) {
func QUIC(cfg *config.Config) (opts Libp2pOpts, err error) {
if cfg.Experimental.QUIC {
opts.Opts = append(opts.Opts, libp2p.Transport(libp2pquic.NewTransport))
}
return
}

func P2PSecurity(enabled bool) interface{} {
func Security(enabled bool) interface{} {
if !enabled {
return func() (opts Libp2pOpts) {
// TODO: shouldn't this be Errorf to guarantee visibility?
Expand Down Expand Up @@ -389,15 +389,15 @@ type P2PHostIn struct {
Opts [][]libp2p.Option `group:"libp2p"`
}

type BaseRouting routing.IpfsRouting
type BaseIpfsRouting routing.IpfsRouting
type P2PHostOut struct {
fx.Out

Host host.Host
Routing BaseRouting
Routing BaseIpfsRouting
}

func P2PHost(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut, err error) {
func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut, err error) {
opts := []libp2p.Option{libp2p.NoListenAddrs}
for _, o := range params.Opts {
opts = append(opts, o...)
Expand Down Expand Up @@ -448,7 +448,7 @@ type p2pRouterOut struct {
Router Router `group:"routers"`
}

func P2PBaseRouting(lc fx.Lifecycle, in BaseRouting) (out p2pRouterOut, dr *dht.IpfsDHT) {
func BaseRouting(lc fx.Lifecycle, in BaseIpfsRouting) (out p2pRouterOut, dr *dht.IpfsDHT) {
if dht, ok := in.(*dht.IpfsDHT); ok {
dr = dht

Expand All @@ -474,7 +474,7 @@ type p2pOnlineRoutingIn struct {
Validator record.Validator
}

func P2PRouting(in p2pOnlineRoutingIn) routing.IpfsRouting {
func Routing(in p2pOnlineRoutingIn) routing.IpfsRouting {
routers := in.Routers

sort.SliceStable(routers, func(i, j int) bool {
Expand All @@ -495,14 +495,14 @@ func P2PRouting(in p2pOnlineRoutingIn) routing.IpfsRouting {
type p2pPSRoutingIn struct {
fx.In

BaseRouting BaseRouting
BaseRouting BaseIpfsRouting
Repo repo.Repo
Validator record.Validator
Host host.Host
PubSub *pubsub.PubSub `optional:"true"`
}

func P2PPubsubRouter(mctx helpers.MetricsCtx, lc fx.Lifecycle, in p2pPSRoutingIn) (p2pRouterOut, *namesys.PubsubValueStore) {
func PubsubRouter(mctx helpers.MetricsCtx, lc fx.Lifecycle, in p2pPSRoutingIn) (p2pRouterOut, *namesys.PubsubValueStore) {
psRouter := namesys.NewPubsubValueStore(
helpers.LifecycleCtx(mctx, lc),
in.Host,
Expand Down
4 changes: 2 additions & 2 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type P2P struct {
peerstore pstore.Peerstore
}

// NewP2P creates new P2P struct
func NewP2P(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore) *P2P {
// New creates new P2P struct
func New(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore) *P2P {
return &P2P{
identity: identity,
peerHost: peerHost,
Expand Down

2 comments on commit a52f361

@GitCop
Copy link

@GitCop GitCop commented on a52f361 Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend can often help you quickly improve the commit message.
Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.


This message was auto-generated by https://gitcop.com

@GitCop
Copy link

@GitCop GitCop commented on a52f361 Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend can often help you quickly improve the commit message.
Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.


This message was auto-generated by https://gitcop.com

Please sign in to comment.