Skip to content

Commit

Permalink
wip: try marco's fx foo
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed May 5, 2023
1 parent a6f446a commit 8dba254
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
fx.Provide(libp2p.RelayTransport(enableRelayTransport)),
fx.Provide(libp2p.RelayService(enableRelayService, cfg.Swarm.RelayService)),
fx.Provide(libp2p.Transports(cfg.Swarm.Transports)),
fx.Invoke(libp2p.StartListening(cfg.Addresses.Swarm)),
fx.Provide(libp2p.ListenOn(cfg.Addresses.Swarm)),
fx.Invoke(libp2p.SetupDiscovery(cfg.Discovery.MDNS.Enabled)),
fx.Provide(libp2p.ForceReachability(cfg.Internal.Libp2pForceReachability)),
fx.Provide(libp2p.HolePunching(cfg.Swarm.EnableHolePunching, enableRelayClient)),
Expand Down
38 changes: 6 additions & 32 deletions core/node/libp2p/addrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/host"
p2pbhost "github.com/libp2p/go-libp2p/p2p/host/basic"
ma "github.com/multiformats/go-multiaddr"
mamask "github.com/whyrusleeping/multiaddr-filter"
Expand Down Expand Up @@ -99,37 +98,12 @@ func AddrsFactory(announce []string, appendAnnouce []string, noAnnounce []string
}
}

func listenAddresses(addresses []string) ([]ma.Multiaddr, error) {
listen := make([]ma.Multiaddr, len(addresses))
for i, addr := range addresses {
maddr, err := ma.NewMultiaddr(addr)
if err != nil {
return nil, fmt.Errorf("failure to parse config.Addresses.Swarm: %s", addresses)
}
listen[i] = maddr
}

return listen, nil
}

func StartListening(addresses []string) func(host host.Host) error {
return func(host host.Host) error {
listenAddrs, err := listenAddresses(addresses)
if err != nil {
return err
}

// Actually start listening:
if err := host.Network().Listen(listenAddrs...); err != nil {
return err
}

// list out our addresses
addrs, err := host.Network().InterfaceListenAddresses()
if err != nil {
return err
func ListenOn(addresses []string) interface{} {
return func() (opts Libp2pOpts) {
return Libp2pOpts{
Opts: []libp2p.Option{
libp2p.ListenAddrStrings(addresses...),
},
}
log.Infof("Swarm listening at: %s", addrs)
return nil
}
}

0 comments on commit 8dba254

Please sign in to comment.