library

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: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPeer

func AddPeer(address string, protocolID string) (string, error)

AddPeer adds a node multiaddress and protocol to the wakunode peerstore

func Connect

func Connect(address string, ms int) error

Connect is used to connect to a peer at multiaddress. if ms > 0, cancel the function execution if it takes longer than N milliseconds

func ConnectPeerID

func ConnectPeerID(peerID string, ms int) error

ConnectPeerID is usedd to connect to a known peer by peerID. if ms > 0, cancel the function execution if it takes longer than N milliseconds

func ContentTopic

func ContentTopic(applicationName string, applicationVersion string, contentTopicName string, encoding string) string

ContentTopic creates a content topic string according to RFC 23

func DNSDiscovery

func DNSDiscovery(url string, nameserver string, ms int) (string, error)

DNSDiscovery executes dns discovery on an url and returns a list of nodes

func DecodeAsymmetric

func DecodeAsymmetric(messageJSON string, privateKey string) (string, error)

DecodeAsymmetric decodes a waku message using a secp256k1 private key. The key must be a hex encoded string with "0x" prefix

func DecodeSymmetric

func DecodeSymmetric(messageJSON string, symmetricKey string) (string, error)

DecodeSymmetric decodes a waku message using a 32 bytes symmetric key. The key must be a hex encoded string with "0x" prefix

func DefaultPubsubTopic

func DefaultPubsubTopic() string

DefaultPubsubTopic returns the default pubsub topic used in waku2: /waku/2/default-waku/proto

func Disconnect

func Disconnect(peerID string) error

Disconnect closes a connection to a known peer by peerID

func EncodeAsymmetric

func EncodeAsymmetric(messageJSON string, publicKey string, optionalSigningKey string) (string, error)

func EncodeSymmetric

func EncodeSymmetric(messageJSON string, symmetricKey string, optionalSigningKey string) (string, error)

func FilterPing

func FilterPing(peerID string, ms int) error

FilterPing is used to determine if a peer has an active subscription

func FilterSubscribe

func FilterSubscribe(filterJSON string, peerID string, ms int) (string, error)

FilterSubscribe is used to create a subscription to a filter node to receive messages

func FilterUnsubscribe

func FilterUnsubscribe(filterJSON string, peerID string, ms int) error

FilterUnsubscribe is used to remove a filter criteria from an active subscription with a filter node

func FilterUnsubscribeAll

func FilterUnsubscribeAll(peerID string, ms int) (string, error)

FilterUnsubscribeAll is used to remove an active subscription to a peer. If no peerID is defined, it will stop all active filter subscriptions

func IsStarted

func IsStarted() bool

IsStarted is used to determine is a node is started or not

func LegacyFilterSubscribe

func LegacyFilterSubscribe(filterJSON string, peerID string, ms int) error

LegacyFilterSubscribe is used to create a subscription to a filter node to receive messages Deprecated: Use FilterSubscribe instead

func LegacyFilterUnsubscribe

func LegacyFilterUnsubscribe(filterJSON string, ms int) error

LegacyFilterUnsubscribe is used to remove a filter criteria from an active subscription with a filter node Deprecated: Use FilterUnsubscribe or FilterUnsubscribeAll instead

func LightpushPublish

func LightpushPublish(messageJSON string, pubsubTopic string, peerID string, ms int) (string, error)

LightpushPublish is used to publish a WakuMessage in a pubsub topic using Lightpush protocol

func ListenAddresses

func ListenAddresses() (string, error)

ListenAddresses returns the multiaddresses the wakunode is listening to

func NewNode

func NewNode(configJSON string) error

NewNode initializes a waku node. Receives a JSON string containing the configuration, and use default values for those config items not specified

func PeerCnt

func PeerCnt() (int, error)

PeerCnt returns the number of connected peers

func PeerID

func PeerID() (string, error)

PeerID is used to obtain the peer ID of the waku node

func Peers

func Peers() (string, error)

Peers retrieves the list of peers known by the waku node

func RelayEnoughPeers

func RelayEnoughPeers(topic string) (bool, error)

RelayEnoughPeers determines if there are enough peers to publish a message on a topic

func RelayPublish

func RelayPublish(messageJSON string, topic string, ms int) (string, error)

RelayPublish publishes a message using waku relay and returns the message ID

func RelaySubscribe

func RelaySubscribe(contentFilterJSON string) error

RelaySubscribe subscribes to a WakuRelay topic.

func RelayTopics

func RelayTopics() (string, error)

RelayTopics returns a list of pubsub topics the node is subscribed to in WakuRelay

func RelayUnsubscribe

func RelayUnsubscribe(contentFilterJSON string) error

RelayUnsubscribe closes the pubsub subscription to a pubsub topic

func SetBootnodes

func SetBootnodes(bootnodes string) error

SetBootnodes is used to update the bootnodes receiving a JSON array of ENRs

func SetEventCallback

func SetEventCallback(cb unsafe.Pointer)

SetEventCallback is to set a callback in order to receive application signals which are used to react to asynchronous events in waku.

func SetMobileSignalHandler

func SetMobileSignalHandler(m MobileSignalHandler)

SetMobileSignalHandler sets the callback to be executed when a signal is received in a mobile device

func Start

func Start() error

Start starts the waku node

func StartDiscoveryV5

func StartDiscoveryV5() error

StartDiscoveryV5 starts discv5 discovery

func Stop

func Stop() error

Stop stops a waku node

func StopDiscoveryV5

func StopDiscoveryV5() error

StopDiscoveryV5 stops discv5 discovery

func StoreLocalQuery

func StoreLocalQuery(queryJSON string) (string, error)

StoreLocalQuery is used to retrieve historic messages stored in the localDB using waku store protocol.

func StoreQuery

func StoreQuery(queryJSON string, peerID string, ms int) (string, error)

StoreQuery is used to retrieve historic messages using waku store protocol.

Types

type GossipSubParams

type GossipSubParams struct {

	// D sets the optimal degree for a GossipSub topic mesh. For example, if D == 6,
	// each peer will want to have about six peers in their mesh for each topic they're subscribed to.
	// D should be set somewhere between Dlo and Dhi.
	D *int `json:"d,omitempty"`

	// Dlo sets the lower bound on the number of peers we keep in a GossipSub topic mesh.
	// If we have fewer than Dlo peers, we will attempt to graft some more into the mesh at
	// the next heartbeat.
	Dlo *int `json:"d_low,omitempty"`

	// Dhi sets the upper bound on the number of peers we keep in a GossipSub topic mesh.
	// If we have more than Dhi peers, we will select some to prune from the mesh at the next heartbeat.
	Dhi *int `json:"d_high,omitempty"`

	// Dscore affects how peers are selected when pruning a mesh due to over subscription.
	// At least Dscore of the retained peers will be high-scoring, while the remainder are
	// chosen randomly.
	Dscore *int `json:"d_score,omitempty"`

	// Dout sets the quota for the number of outbound connections to maintain in a topic mesh.
	// When the mesh is pruned due to over subscription, we make sure that we have outbound connections
	// to at least Dout of the survivor peers. This prevents sybil attackers from overwhelming
	// our mesh with incoming connections.
	//
	// Dout must be set below Dlo, and must not exceed D / 2.
	Dout *int `json:"dOut,omitempty"`

	// HistoryLength controls the size of the message cache used for gossip.
	// The message cache will remember messages for HistoryLength heartbeats.
	HistoryLength *int `json:"historyLength,omitempty"`

	// HistoryGossip controls how many cached message ids we will advertise in
	// IHAVE gossip messages. When asked for our seen message IDs, we will return
	// only those from the most recent HistoryGossip heartbeats. The slack between
	// HistoryGossip and HistoryLength allows us to avoid advertising messages
	// that will be expired by the time they're requested.
	//
	// HistoryGossip must be less than or equal to HistoryLength to
	// avoid a runtime panic.
	HistoryGossip *int `json:"historyGossip,omitempty"`

	// Dlazy affects how many peers we will emit gossip to at each heartbeat.
	// We will send gossip to at least Dlazy peers outside our mesh. The actual
	// number may be more, depending on GossipFactor and how many peers we're
	// connected to.
	Dlazy *int `json:"dLazy,omitempty"`

	// GossipFactor affects how many peers we will emit gossip to at each heartbeat.
	// We will send gossip to GossipFactor * (total number of non-mesh peers), or
	// Dlazy, whichever is greater.
	GossipFactor *float64 `json:"gossipFactor,omitempty"`

	// GossipRetransmission controls how many times we will allow a peer to request
	// the same message id through IWANT gossip before we start ignoring them. This is designed
	// to prevent peers from spamming us with requests and wasting our resources.
	GossipRetransmission *int `json:"gossipRetransmission,omitempty"`

	// HeartbeatInitialDelayMs is the short delay before the heartbeat timer begins
	// after the router is initialized.
	HeartbeatInitialDelayMs *int `json:"heartbeatInitialDelayMs,omitempty"`

	// HeartbeatIntervalSeconds controls the time between heartbeats.
	HeartbeatIntervalSeconds *int `json:"heartbeatIntervalSeconds,omitempty"`

	// SlowHeartbeatWarning is the duration threshold for heartbeat processing before emitting
	// a warning; this would be indicative of an overloaded peer.
	SlowHeartbeatWarning *float64 `json:"slowHeartbeatWarning,omitempty"`

	// FanoutTTLSeconds controls how long we keep track of the fanout state. If it's been
	// FanoutTTLSeconds since we've published to a topic that we're not subscribed to,
	// we'll delete the fanout map for that topic.
	FanoutTTLSeconds *int `json:"fanoutTTLSeconds,omitempty"`

	// PrunePeers controls the number of peers to include in prune Peer eXchange.
	// When we prune a peer that's eligible for PX (has a good score, etc), we will try to
	// send them signed peer records for up to PrunePeers other peers that we
	// know of.
	PrunePeers *int `json:"prunePeers,omitempty"`

	// PruneBackoffSeconds controls the backoff time for pruned peers. This is how long
	// a peer must wait before attempting to graft into our mesh again after being pruned.
	// When pruning a peer, we send them our value of PruneBackoff so they know
	// the minimum time to wait. Peers running older versions may not send a backoff time,
	// so if we receive a prune message without one, we will wait at least PruneBackoff
	// before attempting to re-graft.
	PruneBackoffSeconds *int `json:"pruneBackoffSeconds,omitempty"`

	// UnsubscribeBackoffSeconds controls the backoff time to use when unsuscribing
	// from a topic. A peer should not resubscribe to this topic before this
	// duration.
	UnsubscribeBackoffSeconds *int `json:"unsubscribeBackoffSeconds,omitempty"`

	// Connectors controls the number of active connection attempts for peers obtained through PX.
	Connectors *int `json:"connectors,omitempty"`

	// MaxPendingConnections sets the maximum number of pending connections for peers attempted through px.
	MaxPendingConnections *int `json:"maxPendingConnections,omitempty"`

	// ConnectionTimeoutSeconds controls the timeout for connection attempts.
	ConnectionTimeoutSeconds *int `json:"connectionTimeoutSeconds,omitempty"`

	// DirectConnectTicks is the number of heartbeat ticks for attempting to reconnect direct peers
	// that are not currently connected.
	DirectConnectTicks *uint64 `json:"directConnectTicks,omitempty"`

	// DirectConnectInitialDelaySeconds is the initial delay before opening connections to direct peers
	DirectConnectInitialDelaySeconds *int `json:"directConnectInitialDelaySeconds,omitempty"`

	// OpportunisticGraftTicks is the number of heartbeat ticks for attempting to improve the mesh
	// with opportunistic grafting. Every OpportunisticGraftTicks we will attempt to select some
	// high-scoring mesh peers to replace lower-scoring ones, if the median score of our mesh peers falls
	// below a threshold (see https://godoc.org/github.com/libp2p/go-libp2p-pubsub#PeerScoreThresholds).
	OpportunisticGraftTicks *uint64 `json:"opportunisticGraftTicks,omitempty"`

	// OpportunisticGraftPeers is the number of peers to opportunistically graft.
	OpportunisticGraftPeers *int `json:"opportunisticGraftPeers,omitempty"`

	// If a GRAFT comes before GraftFloodThresholdSeconds has elapsed since the last PRUNE,
	// then there is an extra score penalty applied to the peer through P7.
	GraftFloodThresholdSeconds *int `json:"graftFloodThresholdSeconds,omitempty"`

	// MaxIHaveLength is the maximum number of messages to include in an IHAVE message.
	// Also controls the maximum number of IHAVE ids we will accept and request with IWANT from a
	// peer within a heartbeat, to protect from IHAVE floods. You should adjust this value from the
	// default if your system is pushing more than 5000 messages in HistoryGossip heartbeats;
	// with the defaults this is 1666 messages/s.
	MaxIHaveLength *int `json:"maxIHaveLength,omitempty"`

	// MaxIHaveMessages is the maximum number of IHAVE messages to accept from a peer within a heartbeat.
	MaxIHaveMessages *int `json:"maxIHaveMessages,omitempty"`

	// Time to wait for a message requested through IWANT following an IHAVE advertisement.
	// If the message is not received within this window, a broken promise is declared and
	// the router may apply bahavioural penalties.
	IWantFollowupTimeSeconds *int `json:"iWantFollowupTimeSeconds,omitempty"`

	// configures when a previously seen message ID can be forgotten about
	SeenMessagesTTLSeconds *int `json:"seenMessagesTTLSeconds"`
}

GossipSubParams defines all the gossipsub specific parameters.

type MobileSignalHandler

type MobileSignalHandler func([]byte)

MobileSignalHandler is a simple callback function that gets called when any signal is received

type WakuConfig

type WakuConfig struct {
	Host                   *string          `json:"host,omitempty"`
	Port                   *int             `json:"port,omitempty"`
	AdvertiseAddress       *string          `json:"advertiseAddr,omitempty"`
	NodeKey                *string          `json:"nodeKey,omitempty"`
	LogLevel               *string          `json:"logLevel,omitempty"`
	KeepAliveInterval      *int             `json:"keepAliveInterval,omitempty"`
	EnableRelay            *bool            `json:"relay"`
	RelayTopics            []string         `json:"relayTopics,omitempty"`
	GossipSubParams        *GossipSubParams `json:"gossipsubParams,omitempty"`
	EnableLegacyFilter     *bool            `json:"legacyFilter,omitempty"`
	MinPeersToPublish      *int             `json:"minPeersToPublish,omitempty"`
	DNSDiscoveryURLs       []string         `json:"dnsDiscoveryURLs,omitempty"`
	DNSDiscoveryNameServer string           `json:"dnsDiscoveryNameServer,omitempty"`
	EnableDiscV5           *bool            `json:"discV5,omitempty"`
	DiscV5BootstrapNodes   []string         `json:"discV5BootstrapNodes,omitempty"`
	DiscV5UDPPort          *uint            `json:"discV5UDPPort,omitempty"`
	EnableStore            *bool            `json:"store,omitempty"`
	DatabaseURL            *string          `json:"databaseURL,omitempty"`
	RetentionMaxMessages   *int             `json:"storeRetentionMaxMessages,omitempty"`
	RetentionTimeSeconds   *int             `json:"storeRetentionTimeSeconds,omitempty"`
	DNS4DomainName         string           `json:"dns4DomainName,omitempty"`
	Websockets             *WebsocketConfig `json:"websockets,omitempty"`
}

WakuConfig contains all the configuration settings exposed to users of mobile and c libraries

type WakuState

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

WakuState represents the state of the waku node

type WebsocketConfig

type WebsocketConfig struct {
	Enabled  bool   `json:"enabled,omitempty"`
	Host     string `json:"host,omitempty"`
	Port     *int   `json:"port,omitempty"`
	Secure   bool   `json:"secure,omitempty"`
	CertPath string `json:"certPath"`
	KeyPath  string `json:"keyPath"`
}

WebsocketConfig contains all the settings required to setup websocket support in waku

Directories

Path Synopsis
c
Set of functions that are exported when go-waku is built as a static/dynamic library
Set of functions that are exported when go-waku is built as a static/dynamic library
Package gowaku implements gomobile bindings for go-waku.
Package gowaku implements gomobile bindings for go-waku.

Jump to

Keyboard shortcuts

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