From 4a4d0c97ecedf2e521b55fefc1c6f6ffa705e3fc Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 22 Apr 2021 16:42:44 -0400 Subject: [PATCH] docs. pt-2 --- waku/v2/node/waku_payload.go | 4 ++++ waku/v2/node/wakuoptions.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/waku/v2/node/waku_payload.go b/waku/v2/node/waku_payload.go index 49253d2..6736867 100644 --- a/waku/v2/node/waku_payload.go +++ b/waku/v2/node/waku_payload.go @@ -47,6 +47,8 @@ type KeyInfo struct { } +// Encodes a payload depending on the version parameter. +// 0 for raw unencrypted data, and 1 for using WakuV1 encoding. func (payload Payload) Encode(version uint32) ([]byte, error) { switch version { case 0: @@ -86,6 +88,8 @@ func (payload Payload) Encode(version uint32) ([]byte, error) { return nil, errors.New("Unsupported WakuMessage version") } +// Decodes a WakuMessage depending on the version parameter. +// 0 for raw unencrypted data, and 1 for using WakuV1 decoding func DecodePayload(message *pb.WakuMessage, keyInfo *KeyInfo) (*DecodedPayload, error) { switch message.Version { case uint32(0): diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index 3b299ac..5fe3b9d 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -28,6 +28,7 @@ type WakuNodeParameters struct { type WakuNodeOption func(*WakuNodeParameters) error +// WithHostAddress is a WakuNodeOption that configures libp2p to listen on a list of net endpoint addresses func WithHostAddress(hostAddr []net.Addr) WakuNodeOption { return func(params *WakuNodeParameters) error { var multiAddresses []ma.Multiaddr @@ -45,6 +46,7 @@ func WithHostAddress(hostAddr []net.Addr) WakuNodeOption { } } +// WithMultiaddress is a WakuNodeOption that configures libp2p to listen on a list of multiaddresses func WithMultiaddress(addresses []ma.Multiaddr) WakuNodeOption { return func(params *WakuNodeParameters) error { params.multiAddr = append(params.multiAddr, addresses...) @@ -52,6 +54,7 @@ func WithMultiaddress(addresses []ma.Multiaddr) WakuNodeOption { } } +// WithPrivateKey is used to set an ECDSA private key in a libp2p node func WithPrivateKey(privKey *ecdsa.PrivateKey) WakuNodeOption { return func(params *WakuNodeParameters) error { privk := crypto.PrivKey((*crypto.Secp256k1PrivateKey)(privKey)) @@ -60,6 +63,9 @@ func WithPrivateKey(privKey *ecdsa.PrivateKey) 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 WithLibP2POptions(opts ...libp2p.Option) WakuNodeOption { return func(params *WakuNodeParameters) error { params.libP2POpts = opts @@ -67,6 +73,8 @@ func WithLibP2POptions(opts ...libp2p.Option) WakuNodeOption { } } +// WithWakuRelay enables the Waku V2 Relay protocol. This WakuNodeOption +// accepts a list of WakuRelay gossipsub option to setup the protocol func WithWakuRelay(opts ...wakurelay.Option) WakuNodeOption { return func(params *WakuNodeParameters) error { params.enableRelay = true @@ -75,6 +83,8 @@ func WithWakuRelay(opts ...wakurelay.Option) WakuNodeOption { } } +// WithWakuStore enables the Waku V2 Store protocol and if the messages should +// be stored or not in a message provider func WithWakuStore(shouldStoreMessages bool) WakuNodeOption { return func(params *WakuNodeParameters) error { params.enableStore = true @@ -84,6 +94,8 @@ func WithWakuStore(shouldStoreMessages bool) WakuNodeOption { } } +// WithMessageProvider is a WakuNodeOption that sets the MessageProvider +// used to store and retrieve persisted messages func WithMessageProvider(s store.MessageProvider) WakuNodeOption { return func(params *WakuNodeParameters) error { if params.store != nil { @@ -95,6 +107,7 @@ func WithMessageProvider(s store.MessageProvider) WakuNodeOption { } } +// Default options used in the libp2p node var DefaultLibP2POptions = []libp2p.Option{ libp2p.DefaultTransports, libp2p.NATPortMap(), // Attempt to open ports using uPNP for NATed hosts.