protocol

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 17 Imported by: 12

README

Waku v2 protocol

This folder contains implementations of Waku v2 protocols.

Documentation

Index

Constants

View Source
const ClusterIndex = 1

ClusterIndex is the clusterID used in sharding space. For indices allocation and other magic numbers refer to RFC 51

View Source
const DefaultContentTopic = "/waku/2/default-content/proto"

DefaultContentTopic is the default content topic used in Waku network if no content topic is specified.

View Source
const GenerationZeroShardsCount = 8

GenerationZeroShardsCount is number of shards supported in generation-0

View Source
const GossipSubOptimalFullMeshSize = 6
View Source
const MaxShardIndex = uint16(1023)
View Source
const StaticShardingPubsubTopicPrefix = Waku2PubsubTopicPrefix + "/rs"

StaticShardingPubsubTopicPrefix is the expected prefix to be used for static sharding pubsub topics

View Source
const Waku2PubsubTopicPrefix = "/waku/2"

Waku2PubsubTopicPrefix is the expected prefix to be used for pubsub topics

Variables

View Source
var ErrAlreadyStarted = errors.New("already started")
View Source
var ErrInvalidFormat = errors.New("invalid format")
View Source
var ErrInvalidGeneration = errors.New("generation should be a number")
View Source
var ErrInvalidNumberFormat = errors.New("only 2^16 numbers are allowed")

ErrInvalidNumberFormat indicates that a number exceeds the allowed range

View Source
var ErrInvalidShardedTopicPrefix = errors.New("must start with " + StaticShardingPubsubTopicPrefix)
View Source
var ErrInvalidStructure = errors.New("invalid topic structure")

ErrInvalidStructure indicates that the pubsub topic is malformed

View Source
var ErrInvalidTopicPrefix = errors.New("must start with " + Waku2PubsubTopicPrefix)

ErrInvalidTopicPrefix indicates that the pubsub topic is missing the prefix /waku/2

View Source
var ErrMissingClusterIndex = errors.New("missing shard_cluster_index")
View Source
var ErrMissingGeneration = errors.New("missing part: generation")
View Source
var ErrMissingShardNumber = errors.New("missing shard_number")
View Source
var ErrMissingTopicName = errors.New("missing topic-name")
View Source
var ErrNotStarted = errors.New("not started")

Functions

func FulltextMatch

func FulltextMatch(expectedProtocol string) func(string) bool

FulltextMatch is the default matching function used for checking if a peer supports a protocol or not

func GenerateRequestID added in v0.8.0

func GenerateRequestID() []byte

GenerateRequestID generates a random 32 byte slice that can be used for creating requests inf the filter, store and lightpush protocols

func GetPubSubTopicFromContentTopic added in v0.8.1

func GetPubSubTopicFromContentTopic(cTopicString string) (string, error)

func PrefixTextMatch

func PrefixTextMatch(prefix string) func(protocol.ID) bool

PrefixTextMatch is a matching function used for checking if a peer's supported protocols begin with a particular prefix

Types

type CommonService added in v0.8.0

type CommonService struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

this is common layout for all the services that require mutex protection and a guarantee that all running goroutines will be finished before stop finishes execution. This guarantee comes from waitGroup all one has to use CommonService.WaitGroup() in the goroutines that should finish by the end of stop function.

func NewCommonService added in v0.8.0

func NewCommonService() *CommonService

func (*CommonService) Context added in v0.8.0

func (sp *CommonService) Context() context.Context

func (*CommonService) ErrOnNotRunning added in v0.8.0

func (sp *CommonService) ErrOnNotRunning() error

This is not a mutex protected function, it is up to the caller to use it in a mutex protected context

func (*CommonService) Start added in v0.8.0

func (sp *CommonService) Start(ctx context.Context, fn func() error) error

mutex protected start function creates internal context over provided context and runs fn safely fn is excerpt to be executed to start the protocol

func (*CommonService) Stop added in v0.8.0

func (sp *CommonService) Stop(fn func())

mutex protected stop function

func (*CommonService) WaitGroup added in v0.8.0

func (sp *CommonService) WaitGroup() *sync.WaitGroup

type ContentFilter added in v0.8.1

type ContentFilter struct {
	PubsubTopic   string
	ContentTopics ContentTopicSet
}

ContentFilter is used to specify the filter to be applied for a FilterNode. Topic means pubSubTopic - optional in case of using contentTopics that following Auto sharding, mandatory in case of named or static sharding. ContentTopics - Specify list of content topics to be filtered under a pubSubTopic (for named and static sharding), or a list of contentTopics (in case ofAuto sharding) If pubSub topic is not specified, then content-topics are used to derive the shard and corresponding pubSubTopic using autosharding algorithm

func NewContentFilter added in v0.8.1

func NewContentFilter(pubsubTopic string, contentTopics ...string) ContentFilter

func (ContentFilter) ContentTopicsList added in v0.8.1

func (cf ContentFilter) ContentTopicsList() []string

type ContentTopic

type ContentTopic struct {
	ContentTopicParams
	ApplicationName    string
	ApplicationVersion uint32
	ContentTopicName   string
	Encoding           string
}

ContentTopic is used for content based.

func NewContentTopic

func NewContentTopic(applicationName string, applicationVersion uint32,
	contentTopicName string, encoding string, opts ...ContentTopicOption) (ContentTopic, error)

NewContentTopic creates a new content topic based on params specified. Returns ErrInvalidGeneration if an unsupported generation is specified.

func StringToContentTopic

func StringToContentTopic(s string) (ContentTopic, error)

StringToContentTopic can be used to create a ContentTopic object from a string

func (ContentTopic) Equal

func (ct ContentTopic) Equal(ct2 ContentTopic) bool

Equal to compare 2 content topics.

func (ContentTopic) String

func (ct ContentTopic) String() string

String formats a content topic in string format as per RFC 23.

type ContentTopicOption added in v0.8.0

type ContentTopicOption func(*ContentTopicParams)

ContentTopicOption is following the options pattern to define optional params

func DefaultOptions added in v0.8.0

func DefaultOptions() []ContentTopicOption

DefaultOptions sets default values for contentTopic optional params.

func WithGeneration added in v0.8.0

func WithGeneration(generation int) ContentTopicOption

WithGeneration option can be used to specify explicitly a generation for contentTopic

type ContentTopicParams added in v0.8.0

type ContentTopicParams struct {
	Generation int
}

ContentTopicParams contains all the optional params for a content topic

func (ContentTopicParams) Equal added in v0.8.0

func (ctp ContentTopicParams) Equal(ctp2 ContentTopicParams) bool

Equal method used to compare 2 contentTopicParams

type ContentTopicSet added in v0.8.1

type ContentTopicSet map[string]struct{}

func NewContentTopicSet added in v0.8.1

func NewContentTopicSet(contentTopics ...string) ContentTopicSet

type Envelope

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

Envelope contains information about the pubsub topic of a WakuMessage and a hash used to identify a message based on the bytes of a WakuMessage protobuffer

func NewEnvelope

func NewEnvelope(msg *wpb.WakuMessage, receiverTime int64, pubSubTopic string) *Envelope

NewEnvelope creates a new Envelope that contains a WakuMessage It's used as a way to know to which Pubsub topic belongs a WakuMessage as well as generating a hash based on the bytes that compose the message

func (*Envelope) Hash

func (e *Envelope) Hash() []byte

Hash returns a 32 byte hash calculated from the WakuMessage bytes

func (*Envelope) Index

func (e *Envelope) Index() *pb.Index

func (*Envelope) Message

func (e *Envelope) Message() *wpb.WakuMessage

Message returns the WakuMessage associated to an Envelope

func (*Envelope) PubsubTopic

func (e *Envelope) PubsubTopic() string

PubsubTopic returns the topic on which a WakuMessage was received

type NamedShardingPubsubTopic added in v0.5.2

type NamedShardingPubsubTopic struct {
	NamespacedPubsubTopic
	// contains filtered or unexported fields
}

NamedShardingPubsubTopic is object for a NamedSharding type pubSub topic

func (NamedShardingPubsubTopic) Equal added in v0.5.2

Equal compares NamedShardingPubsubTopic

func (NamedShardingPubsubTopic) Kind added in v0.5.2

Kind returns the type of PubsubTopic whether it is StaticShared or NamedSharded

func (NamedShardingPubsubTopic) Name added in v0.5.2

Name is the name of the NamedSharded pubsub topic.

func (*NamedShardingPubsubTopic) Parse added in v0.5.2

func (n *NamedShardingPubsubTopic) Parse(topic string) error

Parse parses a topic string into a NamedShardingPubsubTopic

func (NamedShardingPubsubTopic) String added in v0.5.2

func (n NamedShardingPubsubTopic) String() string

String formats NamedShardingPubsubTopic to RFC 23 specific string format for pubsub topic.

type NamespacedPubsubTopic added in v0.6.0

type NamespacedPubsubTopic interface {
	String() string
	Kind() NamespacedPubsubTopicKind
	Equal(NamespacedPubsubTopic) bool
}

NamespacedPubsubTopic is an interface for namespace based pubSub topic

func DefaultPubsubTopic

func DefaultPubsubTopic() NamespacedPubsubTopic

DefaultPubsubTopic is the default pubSub topic used in waku

func NewNamedShardingPubsubTopic added in v0.5.2

func NewNamedShardingPubsubTopic(name string) NamespacedPubsubTopic

NewNamedShardingPubsubTopic creates a new NamedShardingPubSubTopic

func ToShardedPubsubTopic added in v0.5.2

func ToShardedPubsubTopic(topic string) (NamespacedPubsubTopic, error)

ToShardedPubsubTopic takes a pubSub topic string and creates a NamespacedPubsubTopic object.

type NamespacedPubsubTopicKind added in v0.5.2

type NamespacedPubsubTopicKind int

NamespacedPubsubTopicKind used to represent kind of NamespacedPubsubTopicKind

const (
	StaticSharding NamespacedPubsubTopicKind = iota
	NamedSharding
)

type RelayShards added in v0.6.0

type RelayShards struct {
	Cluster uint16   `json:"cluster"`
	Indices []uint16 `json:"indices"`
}

func FromBitVector added in v0.6.0

func FromBitVector(buf []byte) (RelayShards, error)

Generate a RelayShards from a byte slice

func FromIndicesList added in v0.6.0

func FromIndicesList(buf []byte) (RelayShards, error)

func NewRelayShards added in v0.6.0

func NewRelayShards(cluster uint16, indices ...uint16) (RelayShards, error)

func TopicsToRelayShards added in v0.7.0

func TopicsToRelayShards(topic ...string) ([]RelayShards, error)

func (RelayShards) BitVector added in v0.6.0

func (rs RelayShards) BitVector() []byte

func (RelayShards) Contains added in v0.6.0

func (rs RelayShards) Contains(cluster uint16, index uint16) bool

func (RelayShards) ContainsNamespacedTopic added in v0.6.0

func (rs RelayShards) ContainsNamespacedTopic(topic NamespacedPubsubTopic) bool

func (RelayShards) ContainsTopic added in v0.6.0

func (rs RelayShards) ContainsTopic(topic string) bool

func (RelayShards) IndicesList added in v0.6.0

func (rs RelayShards) IndicesList() ([]byte, error)

func (RelayShards) Topics added in v0.6.0

func (rs RelayShards) Topics() []NamespacedPubsubTopic

type StaticShardingPubsubTopic added in v0.5.2

type StaticShardingPubsubTopic struct {
	NamespacedPubsubTopic
	// contains filtered or unexported fields
}

StaticShardingPubsubTopic describes a pubSub topic as per StaticSharding

func GetShardFromContentTopic added in v0.8.0

func GetShardFromContentTopic(topic ContentTopic, shardCount int) StaticShardingPubsubTopic

GetShardFromContentTopic runs Autosharding logic and returns a pubSubTopic This is based on Autosharding algorithm defined in RFC 51

func NewStaticShardingPubsubTopic added in v0.5.2

func NewStaticShardingPubsubTopic(cluster uint16, shard uint16) StaticShardingPubsubTopic

NewStaticShardingPubsubTopic creates a new pubSub topic

func (StaticShardingPubsubTopic) Cluster added in v0.5.2

func (s StaticShardingPubsubTopic) Cluster() uint16

Cluster returns the sharded cluster index

func (StaticShardingPubsubTopic) Equal added in v0.5.2

Equal compares StaticShardingPubsubTopic

func (StaticShardingPubsubTopic) Kind added in v0.5.2

Kind returns the type of PubsubTopic whether it is StaticShared or NamedSharded

func (*StaticShardingPubsubTopic) Parse added in v0.5.2

func (s *StaticShardingPubsubTopic) Parse(topic string) error

Parse parses a topic string into a StaticShardingPubsubTopic

func (StaticShardingPubsubTopic) Shard added in v0.5.2

Shard returns the shard number

func (StaticShardingPubsubTopic) String added in v0.5.2

func (s StaticShardingPubsubTopic) String() string

String formats StaticShardingPubsubTopic to RFC 23 specific string format for pubsub topic.

Jump to

Keyboard shortcuts

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