2023-10-30 16:30:25 +00:00
|
|
|
package relay
|
|
|
|
|
2024-01-03 01:36:41 +00:00
|
|
|
import pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
|
|
|
2023-10-30 16:30:25 +00:00
|
|
|
type publishParameters struct {
|
|
|
|
pubsubTopic string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PublishOption is the type of options accepted when publishing WakuMessages
|
|
|
|
type PublishOption func(*publishParameters)
|
|
|
|
|
|
|
|
// WithPubSubTopic is used to specify the pubsub topic on which a WakuMessage will be broadcasted
|
|
|
|
func WithPubSubTopic(pubsubTopic string) PublishOption {
|
|
|
|
return func(params *publishParameters) {
|
|
|
|
params.pubsubTopic = pubsubTopic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-22 11:35:20 +00:00
|
|
|
// WithDefaultPubsubTopic is used to indicate that the message should be broadcasted in the default pubsub topic
|
2023-10-30 16:30:25 +00:00
|
|
|
func WithDefaultPubsubTopic() PublishOption {
|
|
|
|
return func(params *publishParameters) {
|
|
|
|
params.pubsubTopic = DefaultWakuTopic
|
|
|
|
}
|
|
|
|
}
|
2024-01-03 01:36:41 +00:00
|
|
|
|
|
|
|
type relayParameters struct {
|
|
|
|
pubsubOpts []pubsub.Option
|
|
|
|
maxMsgSizeBytes int
|
|
|
|
}
|
|
|
|
|
|
|
|
type RelayOption func(*relayParameters)
|
|
|
|
|
|
|
|
func WithPubSubOptions(opts []pubsub.Option) RelayOption {
|
|
|
|
return func(params *relayParameters) {
|
|
|
|
params.pubsubOpts = append(params.pubsubOpts, opts...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMaxMsgSize(maxMsgSizeBytes int) RelayOption {
|
|
|
|
return func(params *relayParameters) {
|
|
|
|
if maxMsgSizeBytes == 0 {
|
|
|
|
maxMsgSizeBytes = defaultMaxMsgSizeBytes
|
|
|
|
}
|
|
|
|
params.maxMsgSizeBytes = maxMsgSizeBytes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultOptions() []RelayOption {
|
|
|
|
return []RelayOption{
|
|
|
|
WithMaxMsgSize(defaultMaxMsgSizeBytes),
|
|
|
|
}
|
|
|
|
}
|