node

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 56 Imported by: 0

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.UserAgent(clientId),
	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))),
}

Default options used in the libp2p node

View Source
var DefaultWakuNodeOptions = []WakuNodeOption{
	WithLogger(utils.Logger()),
	WithWakuRelay(),
}

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 DecodePayloadV2 added in v0.2.0

func DecodePayloadV2(message *pb.WakuMessage) (*noise.PayloadV2, error)

Decodes a WakuMessage to a PayloadV2 Currently, this is just a wrapper over deserializePayloadV2 and encryption/decryption is done on top (no KeyInfo)

func DecodeWakuMessage

func DecodeWakuMessage(message *pb.WakuMessage, keyInfo *KeyInfo) error

func EncodePayloadV2 added in v0.2.0

func EncodePayloadV2(payload2 *noise.PayloadV2) (*pb.WakuMessage, error)

Encodes a PayloadV2 to a WakuMessage Currently, this is just a wrapper over serializePayloadV2 and encryption/decryption is done on top (no KeyInfo)

func EncodeWakuMessage

func EncodeWakuMessage(message *pb.WakuMessage, keyInfo *KeyInfo) error

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, log *zap.Logger) ConnectionNotifier

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

Listen is called when network starts listening on an addr

func (ConnectionNotifier) ListenClose

func (c ConnectionNotifier) ListenClose(n network.Network, m ma.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 DecodedPayload

type DecodedPayload struct {
	Data      []byte           // Decoded message payload
	Padding   []byte           // Used to align data size, since data size alone might reveal important metainformation.
	PubKey    *ecdsa.PublicKey // The public key that signed the payload
	Signature []byte
}

DecodedPayload contains the data of the received message after decrypting it

func DecodePayload

func DecodePayload(message *pb.WakuMessage, keyInfo *KeyInfo) (*DecodedPayload, error)

DecodePayload decodes a WakuMessage depending on the version parameter. 0 for raw unencrypted data, and 1 for using WakuV1 decoding

type KeyInfo

type KeyInfo struct {
	Kind    KeyKind           // Indicates the type of encryption to use
	SymKey  []byte            // If the encryption is Symmetric, a Symmetric key must be specified
	PubKey  ecdsa.PublicKey   // If the encryption is Asymmetric, the public key of the message receptor must be specified
	PrivKey *ecdsa.PrivateKey // Set a privkey if the message requires a signature
}

type KeyKind

type KeyKind string

KeyKind indicates the type of encryption to apply

const (
	Symmetric  KeyKind = "Symmetric"
	Asymmetric KeyKind = "Asymmetric"
	None       KeyKind = "None"
)

type MembershipKeyPair added in v0.2.0

type MembershipKeyPair = struct {
	IDKey        [32]byte
	IDCommitment [32]byte
}

type Payload

type Payload struct {
	Data    []byte   // Raw message payload
	Padding []byte   // Used to align data size, since data size alone might reveal important metainformation.
	Key     *KeyInfo // Contains the type of encryption to apply and the private key to use for signing the message
}

Payload contains the data of the message to encode

func (Payload) Encode

func (payload Payload) Encode(version uint32) ([]byte, error)

Encode encodes a payload depending on the version parameter. 0 for raw unencrypted data, and 1 for using WakuV1 encoding.

type Peer

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

type PeerStats

type PeerStats map[peer.ID][]string

PeerStatis is a map of peer IDs to supported protocols

type RLNRelay added in v0.2.0

type RLNRelay interface {
	MembershipKeyPair() MembershipKeyPair
	MembershipIndex() uint
	AppendRLNProof(msg *pb.WakuMessage, senderEpochTime time.Time) error
	Stop()
}

type WakuNode

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

func New

func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, error)

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

func (*WakuNode) AddPeer

func (w *WakuNode) AddPeer(address ma.Multiaddr, protocols ...string) (*peer.ID, error)

AddPeer is used to add a peer and the protocols it support to the node peerstore

func (*WakuNode) Broadcaster

func (w *WakuNode) Broadcaster() v2.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) 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 added in v0.1.0

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

ENR returns the ENR address of the node

func (*WakuNode) Filter

func (w *WakuNode) Filter() *filter.WakuFilter

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

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

func (w *WakuNode) Publish(ctx context.Context, msg *pb.WakuMessage) error

Publish will attempt to publish a message via WakuRelay if there are enough peers available, otherwise it will attempt to publish via Lightpush protocol

func (*WakuNode) RLNRelay added in v0.2.0

func (w *WakuNode) RLNRelay() RLNRelay

func (*WakuNode) Relay

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

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

func (*WakuNode) Start

func (w *WakuNode) Start() 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

type WakuNodeOption

type WakuNodeOption func(*WakuNodeParameters) error

func WithAdvertiseAddress

func WithAdvertiseAddress(address *net.TCPAddr) WakuNodeOption

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

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 WithDiscoveryV5

func WithDiscoveryV5(udpPort int, bootnodes []*enode.Node, autoUpdate bool, discoverOpts ...pubsub.DiscoverOpt) WakuNodeOption

WithDiscoveryV5 is a WakuOption used to enable DiscV5 peer discovery

func WithDns4Domain

func WithDns4Domain(dns4Domain string) WakuNodeOption

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

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 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 WithLogger

func WithLogger(l *zap.Logger) WakuNodeOption

WithLogger is a WakuNodeOption that adds a custom logger

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 WithPrivateKey

func WithPrivateKey(privKey *ecdsa.PrivateKey) WakuNodeOption

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

func WithRendezvous

func WithRendezvous(discoverOpts ...pubsub.DiscoverOpt) WakuNodeOption

WithRendezvous is a WakuOption used to enable go-waku-rendezvous discovery. It accepts an optional list of DiscoveryOpt options

func WithRendezvousServer

func WithRendezvousServer(storage rendezvous.Storage) WakuNodeOption

WithRendezvousServer 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 WithWakuFilter

func WithWakuFilter(fullNode bool, filterOpts ...filter.Option) WakuNodeOption

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

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(shouldStoreMessages bool, shouldResume bool) 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 WithWakuSwap

func WithWakuSwap(mode int, disconnectThreshold, paymentThreshold int) WakuNodeOption

WithWakuSwap set the option of the Waku V2 Swap protocol

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

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