mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
MVP for #6097 This feature will repeatedly reconnect (with a randomized exponential backoff) to peers in a set of "peered" peers. In the future, this should be extended to: 1. Include a CLI for modifying this list at runtime. 2. Include additional options for peers we want to _protect_ but not connect to. 3. Allow configuring timeouts, backoff, etc. 4. Allow groups? Possibly through textile threads. 5. Allow for runtime-only peering rules. 6. Different reconnect policies. But this MVP should be a significant step forward.
35 lines
787 B
Go
35 lines
787 B
Go
package node
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ipfs/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)
|
|
}
|
|
})
|
|
}
|