package node import ( "context" "gitlab.dms3.io/dms3/go-dms3/peering" "gitlab.dms3.io/p2p/go-p2p-core/host" "gitlab.dms3.io/p2p/go-p2p-core/peer" "go.uber.org/fx" ) // Peering constructs the peering service and hooks it into fx's lifetime // management system. func Peering(lc fx.Lifecycle, host host.Host) *peering.PeeringService { ps := peering.NewPeeringService(host) lc.Append(fx.Hook{ OnStart: func(context.Context) error { return ps.Start() }, OnStop: func(context.Context) error { return ps.Stop() }, }) return ps } // PeerWith configures the peering service to peer with the specified peers. func PeerWith(peers ...peer.AddrInfo) fx.Option { return fx.Invoke(func(ps *peering.PeeringService) { for _, ai := range peers { ps.AddPeer(ai) } }) }