relay

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 30 Imported by: 4

Documentation

Index

Constants

View Source
const (
	PEER_JOINED = iota
	PEER_LEFT
)
View Source
const WakuRelayENRField = uint8(1 << 0)
View Source
const WakuRelayID_v200 = protocol.ID("/vac/waku/relay/2.0.0")

WakuRelayID_v200 is the current protocol ID used for WakuRelay

Variables

View Source
var DefaultRelaySubscriptionBufferSize int = 1024
View Source
var DefaultWakuTopic string = waku_proto.DefaultPubsubTopic{}.String()

DefaultWakuTopic is the default pubsub topic used across all Waku protocols

Functions

func NewBroadcaster added in v0.6.0

func NewBroadcaster(bufLen int) *broadcaster

NewBroadcaster creates a new instance of a broadcaster

func SignMessage added in v0.6.0

func SignMessage(privKey *ecdsa.PrivateKey, msg *pb.WakuMessage, pubsubTopic string) error

SignMessage adds an ECDSA signature to a WakuMessage as an opt-in mechanism for DoS prevention

Types

type Broadcaster added in v0.6.0

type Broadcaster interface {
	Start(ctx context.Context) error
	Stop()
	Register(contentFilter protocol.ContentFilter, opts ...BroadcasterOption) *Subscription
	RegisterForAll(opts ...BroadcasterOption) *Subscription
	UnRegister(pubsubTopic string)
	Submit(*protocol.Envelope)
}

Broadcaster is used to create a fanout for an envelope that will be received by any subscriber interested in the topic of the message

type BroadcasterOption added in v0.9.0

type BroadcasterOption func(*BroadcasterParameters)

func DefaultBroadcasterOptions added in v0.9.0

func DefaultBroadcasterOptions() []BroadcasterOption

DefaultBroadcasterOptions specifies default options for broadcaster

func DontConsume added in v0.9.0

func DontConsume() BroadcasterOption

WithoutConsumer option let's a user subscribe to a broadcaster without consuming messages received. This is useful for a relayNode where only a subscribe is required in order to relay messages in gossipsub network.

func WithBufferSize added in v0.9.0

func WithBufferSize(size int) BroadcasterOption

WithBufferSize option let's a user set channel buffer to be set.

func WithConsumerOption added in v0.9.0

func WithConsumerOption(dontConsume bool) BroadcasterOption

type BroadcasterParameters added in v0.9.0

type BroadcasterParameters struct {
	// contains filtered or unexported fields
}

type EvtPeerTopic added in v0.8.1

type EvtPeerTopic struct {
	PubsubTopic string
	PeerID      peer.ID
	State       PeerTopicState
}

type EvtRelaySubscribed added in v0.8.0

type EvtRelaySubscribed struct {
	Topic     string
	TopicInst *pubsub.Topic
}

EvtRelaySubscribed is an event emitted when a new subscription to a pubsub topic is created

type EvtRelayUnsubscribed added in v0.8.0

type EvtRelayUnsubscribed struct {
	Topic string
}

EvtRelayUnsubscribed is an event emitted when a subscription to a pubsub topic is closed

type Metrics added in v0.8.0

type Metrics interface {
	RecordMessage(envelope *waku_proto.Envelope)
}

Metrics exposes the functions required to update prometheus metrics for relay protocol

type PeerTopicState added in v0.8.1

type PeerTopicState int

type PublishOption added in v0.9.0

type PublishOption func(*publishParameters)

PublishOption is the type of options accepted when publishing WakuMessages

func WithDefaultPubsubTopic added in v0.9.0

func WithDefaultPubsubTopic() PublishOption

WithPubSubTopic is used to indicate that the message should be broadcasted in the default pubsub topic

func WithPubSubTopic added in v0.9.0

func WithPubSubTopic(pubsubTopic string) PublishOption

WithPubSubTopic is used to specify the pubsub topic on which a WakuMessage will be broadcasted

type RelaySubscribeOption added in v0.9.0

type RelaySubscribeOption func(*RelaySubscribeParameters) error

func WithCacheSize added in v0.9.0

func WithCacheSize(size uint) RelaySubscribeOption

func WithoutConsumer added in v0.9.0

func WithoutConsumer() RelaySubscribeOption

WithoutConsumer option let's a user subscribe to relay without consuming messages received. This is useful for a relayNode where only a subscribe is required in order to relay messages in gossipsub network.

type RelaySubscribeParameters added in v0.9.0

type RelaySubscribeParameters struct {
	// contains filtered or unexported fields
}

type Subscription

type Subscription struct {
	ID          int
	Unsubscribe func() //for internal use only. For relay Subscription use relay protocol's unsubscribe
	Ch          chan *protocol.Envelope
	// contains filtered or unexported fields
}

Subscription handles the details of a particular Topic subscription. There may be many subscriptions for a given topic.

func NewSubscription added in v0.9.0

func NewSubscription(contentFilter protocol.ContentFilter) *Subscription

NewSubscription creates a subscription that will only receive messages based on the contentFilter

func (*Subscription) Submit added in v0.9.0

func (s *Subscription) Submit(ctx context.Context, msg *protocol.Envelope)

Submit allows a message to be submitted for a subscription

type SubscriptionType added in v0.9.0

type SubscriptionType int
const (
	SpecificContentTopics SubscriptionType = iota
	AllContentTopics
)

type Subscriptions added in v0.9.0

type Subscriptions struct {
	// contains filtered or unexported fields
}

type WakuRelay

type WakuRelay struct {
	*service.CommonService
	// contains filtered or unexported fields
}

WakuRelay is the implementation of the Waku Relay protocol

func NewWakuRelay

func NewWakuRelay(bcaster Broadcaster, minPeersToPublish int, timesource timesource.Timesource,
	reg prometheus.Registerer, log *zap.Logger, opts ...pubsub.Option) *WakuRelay

NewWakuRelay returns a new instance of a WakuRelay struct

func (*WakuRelay) AddSignedTopicValidator added in v0.6.0

func (w *WakuRelay) AddSignedTopicValidator(topic string, publicKey *ecdsa.PublicKey) error

AddSignedTopicValidator registers a gossipsub validator for a topic which will check that messages Meta field contains a valid ECDSA signature for the specified pubsub topic. This is used as a DoS prevention mechanism

func (*WakuRelay) CreateEventEmitters added in v0.9.0

func (w *WakuRelay) CreateEventEmitters() error

func (*WakuRelay) EnoughPeersToPublish

func (w *WakuRelay) EnoughPeersToPublish() bool

EnoughPeersToPublish returns whether there are enough peers connected in the default waku pubsub topic

func (*WakuRelay) EnoughPeersToPublishToTopic

func (w *WakuRelay) EnoughPeersToPublishToTopic(topic string) bool

EnoughPeersToPublish returns whether there are enough peers connected in a pubsub topic

func (*WakuRelay) Events added in v0.8.0

func (w *WakuRelay) Events() event.Bus

Events returns the event bus on which WakuRelay events will be emitted

func (*WakuRelay) GetSubscription added in v0.9.0

func (w *WakuRelay) GetSubscription(contentTopic string) (*Subscription, error)

GetSubscription fetches subscription matching a contentTopic(via autosharding)

func (*WakuRelay) GetSubscriptionWithPubsubTopic added in v0.9.0

func (w *WakuRelay) GetSubscriptionWithPubsubTopic(pubsubTopic string, contentTopic string) (*Subscription, error)

GetSubscriptionWithPubsubTopic fetches subscription matching pubsub and contentTopic

func (*WakuRelay) IsSubscribed added in v0.6.0

func (w *WakuRelay) IsSubscribed(topic string) bool

IsSubscribed indicates whether the node is subscribed to a pubsub topic or not

func (*WakuRelay) Params added in v0.7.0

func (w *WakuRelay) Params() pubsub.GossipSubParams

Params returns the gossipsub configuration parameters used by WakuRelay

func (*WakuRelay) PubSub

func (w *WakuRelay) PubSub() *pubsub.PubSub

PubSub returns the implementation of the pubsub system

func (*WakuRelay) Publish

func (w *WakuRelay) Publish(ctx context.Context, message *pb.WakuMessage, opts ...PublishOption) ([]byte, error)

PublishToTopic is used to broadcast a WakuMessage to a pubsub topic. The pubsubTopic is derived from contentTopic specified in the message via autosharding. To publish to a specific pubsubTopic, the `WithPubSubTopic` option should be provided

func (*WakuRelay) RegisterDefaultValidator added in v0.8.0

func (w *WakuRelay) RegisterDefaultValidator(fn validatorFn)

func (*WakuRelay) RegisterTopicValidator added in v0.8.0

func (w *WakuRelay) RegisterTopicValidator(topic string, fn validatorFn)

func (*WakuRelay) RemoveTopicValidator added in v0.8.0

func (w *WakuRelay) RemoveTopicValidator(topic string)

func (*WakuRelay) SetHost added in v0.6.0

func (w *WakuRelay) SetHost(h host.Host)

SetHost sets the host to be able to mount or consume a protocol

func (*WakuRelay) SetPubSub

func (w *WakuRelay) SetPubSub(pubSub *pubsub.PubSub)

SetPubSub is used to set an implementation of the pubsub system

func (*WakuRelay) Start added in v0.4.0

func (w *WakuRelay) Start(ctx context.Context) error

Start initiates the WakuRelay protocol

func (*WakuRelay) Stop

func (w *WakuRelay) Stop()

Stop unmounts the relay protocol and stops all subscriptions

func (*WakuRelay) Subscribe

func (w *WakuRelay) Subscribe(ctx context.Context, contentFilter waku_proto.ContentFilter, opts ...RelaySubscribeOption) ([]*Subscription, error)

Subscribe returns a Subscription to receive messages as per contentFilter contentFilter can contain pubSubTopic and contentTopics or only contentTopics(in case of autosharding)

func (*WakuRelay) Topics

func (w *WakuRelay) Topics() []string

Topics returns a list of all the pubsub topics currently subscribed to

func (*WakuRelay) Unsubscribe

func (w *WakuRelay) Unsubscribe(ctx context.Context, contentFilter waku_proto.ContentFilter) error

Unsubscribe closes a subscription to a pubsub topic

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL