forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peering.go
34 lines (30 loc) · 790 Bytes
/
peering.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package node
import (
"context"
"github.com/tonyHup/go-ipfs/peering"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-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)
}
})
}