mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
When publishing a value, flood. This ensures that our messages make it to the network even if some of our peers are bad and/or overloaded.
27 lines
912 B
Go
27 lines
912 B
Go
package libp2p
|
|
|
|
import (
|
|
"github.com/libp2p/go-libp2p-core/discovery"
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
"go.uber.org/fx"
|
|
|
|
"github.com/ipfs/go-ipfs/core/node/helpers"
|
|
)
|
|
|
|
func FloodSub(pubsubOptions ...pubsub.Option) interface{} {
|
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, disc discovery.Discovery) (service *pubsub.PubSub, err error) {
|
|
return pubsub.NewFloodSub(helpers.LifecycleCtx(mctx, lc), host, append(pubsubOptions, pubsub.WithDiscovery(disc))...)
|
|
}
|
|
}
|
|
|
|
func GossipSub(pubsubOptions ...pubsub.Option) interface{} {
|
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, disc discovery.Discovery) (service *pubsub.PubSub, err error) {
|
|
return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, append(
|
|
pubsubOptions,
|
|
pubsub.WithDiscovery(disc),
|
|
pubsub.WithFloodPublish(true))...,
|
|
)
|
|
}
|
|
}
|