protocol

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: 16 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 shardIDs allocation and other magic numbers refer to RFC 51

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 = "/waku/2/rs"

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

Variables

View Source
var (
	ErrTooManyShards     = errors.New("too many shards")
	ErrInvalidShard      = errors.New("invalid shard")
	ErrInvalidShardCount = errors.New("invalid shard count")
	ErrExpected130Bytes  = errors.New("invalid data: expected 130 bytes")
)
View Source
var ErrInvalidFormat = errors.New("invalid content topic 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")
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 ErrNotShardPubsubTopic = errors.New("not a shard pubsub topic")

shard pubsub topic errors

View Source
var ErrNotWakuPubsubTopic = errors.New("not a waku pubsub topic")

waku pubsub topic errors

Functions

func ContentFilterToPubSubTopicMap added in v0.9.0

func ContentFilterToPubSubTopicMap(contentFilter ContentFilter) (map[PubsubTopicStr][]ContentTopicStr, error)

This function converts a contentFilter into a map of pubSubTopics and corresponding contentTopics

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 GeneratePubsubToContentTopicMap added in v0.9.0

func GeneratePubsubToContentTopicMap(pubsubTopic string, contentTopics []string) (map[string][]string, error)

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 ContentFilter added in v0.8.1

type ContentFilter struct {
	PubsubTopic   string          `json:"pubsubTopic"`
	ContentTopics ContentTopicSet `json:"contentTopics"`
}

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

func (ContentFilter) Equals added in v0.9.0

func (cf ContentFilter) Equals(cf1 ContentFilter) bool

type ContentTopic

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

ContentTopic is used for content based.

func NewContentTopic

func NewContentTopic(applicationName string, applicationVersion string,
	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. Note that this is recommended to be used for autosharding where contentTopic format is enforced as per https://rfc.vac.dev/spec/51/#content-topics-format-for-autosharding

func StringToContentTopic

func StringToContentTopic(s string) (ContentTopic, error)

StringToContentTopic can be used to create a ContentTopic object from a string Note that this has to be used only when following the rfc format of contentTopic, which is currently validated only for Autosharding. For static and named-sharding, contentTopic can be of any format and hence it is not recommended to use this function. This can be updated if required to handle such a case.

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

func (ContentTopicSet) ToList added in v0.9.0

func (cf ContentTopicSet) ToList() []string

type ContentTopicStr added in v0.9.0

type ContentTopicStr = string

type DefaultPubsubTopic

type DefaultPubsubTopic struct{}

func (DefaultPubsubTopic) String added in v0.9.0

func (DefaultPubsubTopic) String() string

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 PubsubTopicStr added in v0.9.0

type PubsubTopicStr = string

type RelayShards added in v0.6.0

type RelayShards struct {
	ClusterID uint16   `json:"clusterID"`
	ShardIDs  []uint16 `json:"shardIDs"`
}

func FromBitVector added in v0.6.0

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

Generate a RelayShards from a byte slice

func FromShardList added in v0.9.0

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

func NewRelayShards added in v0.6.0

func NewRelayShards(clusterID uint16, shardIDs ...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) ContainsShardPubsubTopic added in v0.9.0

func (rs RelayShards) ContainsShardPubsubTopic(topic WakuPubSubTopic) bool

func (RelayShards) ContainsTopic added in v0.6.0

func (rs RelayShards) ContainsTopic(topic string) bool

func (RelayShards) ShardList added in v0.9.0

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

func (RelayShards) Topics added in v0.6.0

func (rs RelayShards) Topics() []WakuPubSubTopic

type StaticShardingPubsubTopic added in v0.5.2

type StaticShardingPubsubTopic struct {
	// 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 ToShardPubsubTopic added in v0.9.0

func ToShardPubsubTopic(topic WakuPubSubTopic) (StaticShardingPubsubTopic, error)

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) 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.

type WakuPubSubTopic added in v0.9.0

type WakuPubSubTopic interface {
	String() string
}

func ToWakuPubsubTopic added in v0.9.0

func ToWakuPubsubTopic(topic string) (WakuPubSubTopic, error)

ToWakuPubsubTopic takes a pubSub topic string and creates a WakuPubsubTopic object.

Jump to

Keyboard shortcuts

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