node

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: 72 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLibP2POptions = []libp2p.Option{
	libp2p.ChainOptions(
		libp2p.Transport(tcp.NewTCPTransport),
		libp2p.Transport(quic.NewTransport),
		libp2p.Transport(libp2pwebtransport.New),
	),
	libp2p.UserAgent(userAgent),
	libp2p.ChainOptions(
		libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport),
		libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport),
	),
	libp2p.EnableNATService(),
	libp2p.ConnectionManager(newConnManager(200, 300, connmgr.WithGracePeriod(0))),
	libp2p.EnableHolePunching(),
}

Default options used in the libp2p node

Default options used in the libp2p node

View Source
var GitCommit string

GitCommit is a commit hash.

View Source
var Version string

Version is the version of go-waku at the time of compilation

Functions

func GetNodesFromDNSDiscovery added in v0.9.0

func GetNodesFromDNSDiscovery(logger *zap.Logger, ctx context.Context, nameServer string, discoveryURLs []string) []dnsdisc.DiscoveredNode

Types

type ConnStatus

type ConnStatus struct {
	IsOnline   bool
	HasHistory bool
	Peers      PeerStats
}

ConnStatus is used to indicate if the node is online, has access to history and also see the list of peers the node is aware of

type ConnectionNotifier

type ConnectionNotifier struct {
	DisconnectChan chan peer.ID
	// contains filtered or unexported fields
}

ConnectionNotifier is a custom Notifier to be used to display when a peer connects or disconnects to the node

func NewConnectionNotifier

func NewConnectionNotifier(ctx context.Context, h host.Host, connNotifCh chan<- PeerConnection, metrics Metrics, log *zap.Logger) ConnectionNotifier

NewConnectionNotifier creates an instance of ConnectionNotifier to react to peer connection changes

func (ConnectionNotifier) Close

func (c ConnectionNotifier) Close()

Close quits the ConnectionNotifier

func (ConnectionNotifier) ClosedStream

func (c ConnectionNotifier) ClosedStream(n network.Network, s network.Stream)

ClosedStream is called when a stream closed

func (ConnectionNotifier) Connected

func (c ConnectionNotifier) Connected(n network.Network, cc network.Conn)

Connected is called when a connection is opened

func (ConnectionNotifier) Disconnected

func (c ConnectionNotifier) Disconnected(n network.Network, cc network.Conn)

Disconnected is called when a connection closed

func (ConnectionNotifier) Listen

func (c ConnectionNotifier) Listen(n network.Network, m multiaddr.Multiaddr)

Listen is called when network starts listening on an addr

func (ConnectionNotifier) ListenClose

func (c ConnectionNotifier) ListenClose(n network.Network, m multiaddr.Multiaddr)

ListenClose is called when network stops listening on an address

func (ConnectionNotifier) OpenedStream

func (c ConnectionNotifier) OpenedStream(n network.Network, s network.Stream)

OpenedStream is called when a stream opened

type IdentityCredential added in v0.6.0

type IdentityCredential = struct {
	IDTrapdoor   byte32 `json:"idTrapdoor"`
	IDNullifier  byte32 `json:"idNullifier"`
	IDSecretHash byte32 `json:"idSecretHash"`
	IDCommitment byte32 `json:"idCommitment"`
}

type Metrics added in v0.8.0

type Metrics interface {
	RecordVersion(version string, commit string)
	RecordDial()
	RecordPeerConnected()
	RecordPeerDisconnected()
}

Metrics exposes the functions required to update prometheus metrics for the waku node

type Peer

type Peer struct {
	ID        peer.ID        `json:"peerID"`
	Protocols []protocol.ID  `json:"protocols"`
	Addrs     []ma.Multiaddr `json:"addrs"`
	Connected bool           `json:"connected"`
}

type PeerConnection added in v0.6.0

type PeerConnection struct {
	PeerID    peer.ID
	Connected bool
}

type PeerStats

type PeerStats map[peer.ID][]protocol.ID

PeerStatis is a map of peer IDs to supported protocols

type RLNRelay

type RLNRelay interface {
	IdentityCredential() (IdentityCredential, error)
	MembershipIndex() uint
	AppendRLNProof(msg *pb.WakuMessage, senderEpochTime time.Time) error
	Validator(spamHandler SpamHandler) func(ctx context.Context, message *pb.WakuMessage, topic string) bool
	Start(ctx context.Context) error
	Stop() error
	IsReady(ctx context.Context) (bool, error)
}

type ReceptorService added in v0.4.0

type ReceptorService interface {
	SetHost(h host.Host)
	Stop()
	Start(context.Context, *relay.Subscription) error
}

type Service added in v0.4.0

type Service interface {
	SetHost(h host.Host)
	Start(context.Context) error
	Stop()
}

type SpamHandler added in v0.8.0

type SpamHandler = func(message *pb.WakuMessage, topic string) error

type VersionInfo

type VersionInfo struct {
	Version string
	Commit  string
	System  string
	Golang  string
}

func GetVersionInfo

func GetVersionInfo() VersionInfo

func (VersionInfo) String

func (v VersionInfo) String() string

type WakuNode

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

func New

func New(opts ...WakuNodeOption) (*WakuNode, error)

New is used to instantiate a WakuNode using a set of WakuNodeOptions

func (*WakuNode) AddDiscoveredPeer added in v0.8.0

func (w *WakuNode) AddDiscoveredPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubsubTopics []string, connectNow bool)

AddDiscoveredPeer to add a discovered peer to the node peerStore

func (*WakuNode) AddPeer

func (w *WakuNode) AddPeer(address ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) (peer.ID, error)

AddPeer is used to add a peer and the protocols it support to the node peerstore TODO: Need to update this for autosharding, to only take contentTopics and optional pubSubTopics or provide an alternate API only for contentTopics.

func (*WakuNode) Broadcaster

func (w *WakuNode) Broadcaster() relay.Broadcaster

Broadcaster is used to access the message broadcaster that is used to push messages to different protocols

func (*WakuNode) ClosePeerByAddress

func (w *WakuNode) ClosePeerByAddress(address string) error

ClosePeerByAddress is used to disconnect from a peer using its multiaddress

func (*WakuNode) ClosePeerById

func (w *WakuNode) ClosePeerById(id peer.ID) error

ClosePeerById is used to close a connection to a peer

func (*WakuNode) DialPeer

func (w *WakuNode) DialPeer(ctx context.Context, address string) error

DialPeer is used to connect to a peer using a string containing a multiaddress

func (*WakuNode) DialPeerByID

func (w *WakuNode) DialPeerByID(ctx context.Context, peerID peer.ID) error

DialPeerByID is used to connect to an already known peer

func (*WakuNode) DialPeerWithInfo added in v0.6.0

func (w *WakuNode) DialPeerWithInfo(ctx context.Context, peerInfo peer.AddrInfo) error

DialPeerWithInfo is used to connect to a peer using its address information

func (*WakuNode) DialPeerWithMultiAddress

func (w *WakuNode) DialPeerWithMultiAddress(ctx context.Context, address ma.Multiaddr) error

DialPeerWithMultiAddress is used to connect to a peer using a multiaddress

func (*WakuNode) DiscV5

func (w *WakuNode) DiscV5() *discv5.DiscoveryV5

DiscV5 is used to access any operation related to DiscoveryV5

func (*WakuNode) ENR

func (w *WakuNode) ENR() *enode.Node

ENR returns the ENR address of the node

func (*WakuNode) FilterFullNode added in v0.8.0

func (w *WakuNode) FilterFullNode() *filter.WakuFilterFullNode

FilterLightnode is used to access any operation related to Waku Filter protocol Full node feature

func (*WakuNode) FilterLightnode added in v0.6.0

func (w *WakuNode) FilterLightnode() *filter.WakuFilterLightNode

FilterFullNode is used to access any operation related to Waku Filter protocol Light node feature

func (*WakuNode) Host

func (w *WakuNode) Host() host.Host

Host returns the libp2p Host used by the WakuNode

func (*WakuNode) ID

func (w *WakuNode) ID() string

ID returns the base58 encoded ID from the host

func (*WakuNode) LegacyFilter added in v0.6.0

func (w *WakuNode) LegacyFilter() *legacy_filter.WakuFilter

LegacyFilter is used to access any operation related to Waku LegacyFilter protocol

func (*WakuNode) Lightpush

func (w *WakuNode) Lightpush() *lightpush.WakuLightPush

Lightpush is used to access any operation related to Waku Lightpush protocol

func (*WakuNode) ListenAddresses

func (w *WakuNode) ListenAddresses() []ma.Multiaddr

ListenAddresses returns all the multiaddresses used by the host

func (*WakuNode) PeerCount

func (w *WakuNode) PeerCount() int

PeerCount return the number of connected peers

func (*WakuNode) PeerExchange

func (w *WakuNode) PeerExchange() *peer_exchange.WakuPeerExchange

PeerExchange is used to access any operation related to Peer Exchange

func (*WakuNode) PeerManager added in v0.9.0

func (w *WakuNode) PeerManager() *peermanager.PeerManager

PeerManager for getting peer filterv2 protocol

func (*WakuNode) PeerStats

func (w *WakuNode) PeerStats() PeerStats

PeerStats returns a list of peers and the protocols supported by them

func (*WakuNode) Peers

func (w *WakuNode) Peers() ([]*Peer, error)

Peers return the list of peers, addresses, protocols supported and connection status

func (*WakuNode) PeersByContentTopic added in v0.8.1

func (w *WakuNode) PeersByContentTopic(contentTopic string) peer.IDSlice

PeersByContentTopics filters peers based on contentTopic

func (*WakuNode) PeersByStaticShard added in v0.8.1

func (w *WakuNode) PeersByStaticShard(cluster uint16, shard uint16) peer.IDSlice

PeersByShard filters peers based on shard information following static sharding

func (*WakuNode) RLNRelay

func (w *WakuNode) RLNRelay() RLNRelay

RLNRelay is used to access any operation related to Waku RLN protocol

func (*WakuNode) Relay

func (w *WakuNode) Relay() *relay.WakuRelay

Relay is used to access any operation related to Waku Relay protocol

func (*WakuNode) Rendezvous added in v0.8.0

func (w *WakuNode) Rendezvous() *rendezvous.Rendezvous

Rendezvous is used to access any operation related to Rendezvous

func (*WakuNode) SetDiscV5Bootnodes

func (w *WakuNode) SetDiscV5Bootnodes(nodes []*enode.Node) error

Set the bootnodes on discv5

func (*WakuNode) Start

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

Start initializes all the protocols that were setup in the WakuNode

func (*WakuNode) Status

func (w *WakuNode) Status() (isOnline bool, hasHistory bool)

Status returns the current status of the node (online or not) and if the node has access to history nodes or not

func (*WakuNode) Stop

func (w *WakuNode) Stop()

Stop stops the WakuNode and closess all connections to the host

func (*WakuNode) Store

func (w *WakuNode) Store() store.Store

Store is used to access any operation related to Waku Store protocol

func (*WakuNode) Timesource

func (w *WakuNode) Timesource() timesource.Timesource

Timesource returns the timesource used by this node to obtain the current wall time Depending on the configuration it will be the local time or a ntp syncd time

type WakuNodeOption

type WakuNodeOption func(*WakuNodeParameters) error

func GetDiscv5Option added in v0.9.0

func GetDiscv5Option(dnsDiscoveredNodes []dnsdisc.DiscoveredNode, discv5Nodes []string, port uint, autoUpdate bool) (WakuNodeOption, error)

func WithAdvertiseAddresses added in v0.5.0

func WithAdvertiseAddresses(advertiseAddrs ...multiaddr.Multiaddr) WakuNodeOption

WithAdvertiseAddresses is a WakuNodeOption that allows overriding the address used in the waku node with custom value

func WithCircuitRelayParams added in v0.8.1

func WithCircuitRelayParams(minInterval time.Duration, bootDelay time.Duration) WakuNodeOption

func WithClusterID added in v0.9.0

func WithClusterID(clusterID uint16) WakuNodeOption

WithClusterID is used to set the node's ClusterID

func WithConnectionNotification added in v0.6.0

func WithConnectionNotification(ch chan<- PeerConnection) WakuNodeOption

func WithConnectionStatusChannel

func WithConnectionStatusChannel(connStatus chan ConnStatus) WakuNodeOption

WithConnectionStatusChannel is a WakuNodeOption used to set a channel where the connection status changes will be pushed to. It's useful to identify when peer connections and disconnections occur

func WithDNS4Domain added in v0.8.0

func WithDNS4Domain(dns4Domain string) WakuNodeOption

WithDNS4Domain is a WakuNodeOption that adds a custom domain name to listen

func WithDiscoveryV5

func WithDiscoveryV5(udpPort uint, bootnodes []*enode.Node, autoUpdate bool) WakuNodeOption

WithDiscoveryV5 is a WakuOption used to enable DiscV5 peer discovery

func WithDynamicRLNRelay added in v0.8.0

func WithDynamicRLNRelay(keystorePath string, keystorePassword string, treePath string, membershipContract common.Address, membershipIndex *uint, spamHandler rln.SpamHandler, ethClientAddress string) WakuNodeOption

WithDynamicRLNRelay enables the Waku V2 RLN protocol in onchain mode.

func WithExternalIP added in v0.6.0

func WithExternalIP(ip net.IP) WakuNodeOption

WithExternalIP is a WakuNodeOption that allows overriding the advertised external IP used in the waku node with custom value

func WithHostAddress

func WithHostAddress(hostAddr *net.TCPAddr) WakuNodeOption

WithHostAddress is a WakuNodeOption that configures libp2p to listen on a specific address

func WithKeepAlive

func WithKeepAlive(t time.Duration) WakuNodeOption

WithKeepAlive is a WakuNodeOption used to set the interval of time when each peer will be ping to keep the TCP connection alive

func WithLegacyWakuFilter added in v0.6.0

func WithLegacyWakuFilter(fullnode bool, filterOpts ...legacy_filter.Option) WakuNodeOption

WithLegacyWakuFilter enables the legacy Waku Filter protocol. This WakuNodeOption accepts a list of WakuFilter gossipsub options to setup the protocol

func WithLibP2POptions

func WithLibP2POptions(opts ...libp2p.Option) WakuNodeOption

WithLibP2POptions is a WakuNodeOption used to configure the libp2p node. This can potentially override any libp2p config that was set with other WakuNodeOption

func WithLightPush

func WithLightPush() WakuNodeOption

WithLightPush is a WakuNodeOption that enables the lightpush protocol

func WithLogLevel added in v0.5.0

func WithLogLevel(lvl zapcore.Level) WakuNodeOption

WithLogLevel is a WakuNodeOption that sets the log level for go-waku

func WithLogger

func WithLogger(l *zap.Logger) WakuNodeOption

WithLogger is a WakuNodeOption that adds a custom logger

func WithMaxPeerConnections added in v0.8.0

func WithMaxPeerConnections(maxPeers int) WakuNodeOption

func WithMessageProvider

func WithMessageProvider(s store.MessageProvider) WakuNodeOption

WithMessageProvider is a WakuNodeOption that sets the MessageProvider used to store and retrieve persisted messages

func WithMultiaddress

func WithMultiaddress(addresses ...multiaddr.Multiaddr) WakuNodeOption

WithMultiaddress is a WakuNodeOption that configures libp2p to listen on a list of multiaddresses

func WithNTP

func WithNTP(ntpURLs ...string) WakuNodeOption

WithNTP is used to use ntp for any operation that requires obtaining time A list of ntp servers can be passed but if none is specified, some defaults will be used

func WithPeerExchange

func WithPeerExchange() WakuNodeOption

WithPeerExchange is a WakuOption used to enable Peer Exchange

func WithPeerStore added in v0.7.0

func WithPeerStore(ps peerstore.Peerstore) WakuNodeOption

func WithPeerStoreCapacity added in v0.8.1

func WithPeerStoreCapacity(capacity int) WakuNodeOption

func WithPrivateKey

func WithPrivateKey(privKey *ecdsa.PrivateKey) WakuNodeOption

WithPrivateKey is used to set an ECDSA private key in a libp2p node

func WithPrometheusRegisterer added in v0.8.0

func WithPrometheusRegisterer(reg prometheus.Registerer) WakuNodeOption

WithPrometheusRegisterer configures go-waku to use reg as the Registerer for all metrics subsystems

func WithRendezvous added in v0.6.0

func WithRendezvous(db *rendezvous.DB) WakuNodeOption

WithRendezvous is a WakuOption used to set the node as a rendezvous point, using an specific storage for the peer information

func WithSecureWebsockets

func WithSecureWebsockets(address string, port int, certPath string, keyPath string) WakuNodeOption

WithSecureWebsockets is a WakuNodeOption used to enable secure websockets support

func WithStaticRLNRelay added in v0.8.0

func WithStaticRLNRelay(memberIndex *r.MembershipIndex, spamHandler rln.SpamHandler) WakuNodeOption

WithStaticRLNRelay enables the Waku V2 RLN protocol in offchain mode

func WithWakuFilterFullNode added in v0.6.0

func WithWakuFilterFullNode(filterOpts ...filter.Option) WakuNodeOption

WithWakuFilterFullNode enables the Waku Filter V2 protocol full node functionality. This WakuNodeOption accepts a list of WakuFilter options to setup the protocol

func WithWakuFilterLightNode added in v0.6.0

func WithWakuFilterLightNode() WakuNodeOption

WithWakuFilter enables the Waku Filter V2 protocol for lightnode functionality

func WithWakuRelay

func WithWakuRelay(opts ...pubsub.Option) WakuNodeOption

WithWakuRelay enables the Waku V2 Relay protocol. This WakuNodeOption accepts a list of WakuRelay gossipsub option to setup the protocol

func WithWakuRelayAndMinPeers

func WithWakuRelayAndMinPeers(minRelayPeersToPublish int, opts ...pubsub.Option) WakuNodeOption

WithWakuRelayAndMinPeers enables the Waku V2 Relay protocol. This WakuNodeOption accepts a min peers require to publish and a list of WakuRelay gossipsub option to setup the protocol

func WithWakuStore

func WithWakuStore() WakuNodeOption

WithWakuStore enables the Waku V2 Store protocol and if the messages should be stored or not in a message provider.

func WithWakuStoreFactory

func WithWakuStoreFactory(factory storeFactory) WakuNodeOption

WithWakuStoreFactory is used to replace the default WakuStore with a custom implementation that implements the store.Store interface

func WithWebsockets

func WithWebsockets(address string, port int) WakuNodeOption

WithWebsockets is a WakuNodeOption used to enable websockets support

type WakuNodeParameters

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

func (WakuNodeParameters) AddressFactory

func (w WakuNodeParameters) AddressFactory() basichost.AddrsFactory

AddressFactory returns the address factory used by the node's host

func (*WakuNodeParameters) GetPrivKey

func (w *WakuNodeParameters) GetPrivKey() *crypto.PrivKey

GetPrivKey returns the private key used in the node

func (WakuNodeParameters) Identity

func (w WakuNodeParameters) Identity() config.Option

Identity returns a libp2p option containing the identity used by the node

func (WakuNodeParameters) MultiAddresses

func (w WakuNodeParameters) MultiAddresses() []multiaddr.Multiaddr

MultiAddresses return the list of multiaddresses configured in the node

func (WakuNodeParameters) TLSConfig

func (w WakuNodeParameters) TLSConfig() *tls.Config

TLSConfig returns the TLS config used for setting up secure websockets

Jump to

Keyboard shortcuts

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