pubsub.go 911 Bytes
Newer Older
tavit ohanian's avatar
tavit ohanian committed
1
package dms3p2p
2 3

import (
tavit ohanian's avatar
tavit ohanian committed
4 5 6
	"gitlab.dms3.io/p2p/go-p2p-core/discovery"
	"gitlab.dms3.io/p2p/go-p2p-core/host"
	pubsub "gitlab.dms3.io/p2p/go-p2p-pubsub"
7 8
	"go.uber.org/fx"

tavit ohanian's avatar
tavit ohanian committed
9
	"gitlab.dms3.io/dms3/go-dms3/core/node/helpers"
10 11 12
)

func FloodSub(pubsubOptions ...pubsub.Option) interface{} {
13 14
	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))...)
15 16 17 18
	}
}

func GossipSub(pubsubOptions ...pubsub.Option) interface{} {
19
	return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, disc discovery.Discovery) (service *pubsub.PubSub, err error) {
Steven Allen's avatar
Steven Allen committed
20 21 22 23 24
		return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, append(
			pubsubOptions,
			pubsub.WithDiscovery(disc),
			pubsub.WithFloodPublish(true))...,
		)
25 26
	}
}