chore: improve docs

This commit is contained in:
Richard Ramos 2022-07-25 11:28:17 -04:00
parent 03d6614b70
commit e2b04570c1
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
14 changed files with 49 additions and 25 deletions

View File

@ -1,14 +1,3 @@
---
slug: #
title: #/GOWAKU-BINDINGS
name: Go-Waku v2 C Bindings
status: draft
tags: go-waku
editor: Richard Ramos <richard@status.im>
contributors:
---
This specification describes the API for consuming go-waku when built as a dynamic or static library This specification describes the API for consuming go-waku when built as a dynamic or static library
@ -441,9 +430,7 @@ Query historic messages using waku store protocol.
"startTime": 1234, // optional, unix epoch time in nanoseconds "startTime": 1234, // optional, unix epoch time in nanoseconds
"endTime": 1234, // optional, unix epoch time in nanoseconds "endTime": 1234, // optional, unix epoch time in nanoseconds
"contentFilters": [ // optional "contentFilters": [ // optional
{ "contentTopic1", "contentTopic2" ...
"contentTopic": "..."
}, ...
], ],
"pagingOptions": { // optional pagination information "pagingOptions": { // optional pagination information
"pageSize": 40, // number "pageSize": 40, // number

View File

@ -1,3 +1,4 @@
// Set of functions that are exported when go-waku is built as a static/dynamic library
package main package main
/* /*

View File

@ -14,9 +14,7 @@ import (
// "startTime": 1234, // optional, unix epoch time in nanoseconds // "startTime": 1234, // optional, unix epoch time in nanoseconds
// "endTime": 1234, // optional, unix epoch time in nanoseconds // "endTime": 1234, // optional, unix epoch time in nanoseconds
// "contentFilters": [ // optional // "contentFilters": [ // optional
// { // "contentTopic1", "contentTopic2" ...
// "contentTopic": "..."
// }, ...
// ], // ],
// "pagingOptions": {// optional pagination information // "pagingOptions": {// optional pagination information
// "pageSize": 40, // number // "pageSize": 40, // number

View File

@ -1,3 +1,5 @@
// Implements gomobile bindings for go-waku. Contains a set of functions that
// are exported when go-waku is exported as libraries for mobile devices
package gowaku package gowaku
import ( import (

View File

@ -1 +1,2 @@
// Contains resources or utils for test units
package tests package tests

View File

@ -6,16 +6,22 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// RendezvousOptions are settings for enabling the rendezvous protocol for
// discovering new nodes
type RendezvousOptions struct { type RendezvousOptions struct {
Enable bool Enable bool
Nodes cli.StringSlice Nodes cli.StringSlice
} }
// RendezvousServerOptions are settings to enable the waku node to act as a
// rendezvous server
type RendezvousServerOptions struct { type RendezvousServerOptions struct {
Enable bool Enable bool
DBPath string DBPath string
} }
// DiscV5Options are settings to enable a modified version of Ethereums Node
// Discovery Protocol v5 as a means for ambient node discovery.
type DiscV5Options struct { type DiscV5Options struct {
Enable bool Enable bool
Nodes cli.StringSlice Nodes cli.StringSlice
@ -23,6 +29,9 @@ type DiscV5Options struct {
AutoUpdate bool AutoUpdate bool
} }
// RelayOptions are settings to enable the relay protocol which is a pubsub
// approach to peer-to-peer messaging with a strong focus on privacy,
// censorship-resistance, security and scalability.
type RelayOptions struct { type RelayOptions struct {
Enable bool Enable bool
Topics cli.StringSlice Topics cli.StringSlice
@ -30,6 +39,10 @@ type RelayOptions struct {
MinRelayPeersToPublish int MinRelayPeersToPublish int
} }
// FilterOptions are settings used to enable filter protocol. This is a protocol
// that enables subscribing to messages that a peer receives. This is a more
// lightweight version of WakuRelay specifically designed for bandwidth
// restricted devices.
type FilterOptions struct { type FilterOptions struct {
Enable bool Enable bool
DisableFullNode bool DisableFullNode bool
@ -98,6 +111,8 @@ type RPCServerOptions struct {
Private bool Private bool
} }
// WSOptions are settings used for enabling websockets and secure websockets
// support
type WSOptions struct { type WSOptions struct {
Enable bool Enable bool
Port int Port int

View File

@ -71,6 +71,8 @@ func WithDriver(driverName string, datasourceName string) DBOption {
} }
} }
// WithRetentionPolicy is a DBOption that specifies the max number of messages
// to be stored and duration before they're removed from the message store
func WithRetentionPolicy(maxMessages int, maxDuration time.Duration) DBOption { func WithRetentionPolicy(maxMessages int, maxDuration time.Duration) DBOption {
return func(d *DBStore) error { return func(d *DBStore) error {
d.maxDuration = maxDuration d.maxDuration = maxDuration
@ -182,14 +184,14 @@ func (d *DBStore) checkForOlderRecords(t time.Duration) {
} }
} }
// Closes a DB connection // Stop closes a DB connection
func (d *DBStore) Stop() { func (d *DBStore) Stop() {
d.quit <- struct{}{} d.quit <- struct{}{}
d.wg.Wait() d.wg.Wait()
d.db.Close() d.db.Close()
} }
// Inserts a WakuMessage into the DB // Put inserts a WakuMessage into the DB
func (d *DBStore) Put(env *protocol.Envelope) error { func (d *DBStore) Put(env *protocol.Envelope) error {
stmt, err := d.db.Prepare("INSERT INTO message (id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version) VALUES (?, ?, ?, ?, ?, ?, ?)") stmt, err := d.db.Prepare("INSERT INTO message (id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version) VALUES (?, ?, ?, ?, ?, ?, ?)")
if err != nil { if err != nil {
@ -211,6 +213,7 @@ func (d *DBStore) Put(env *protocol.Envelope) error {
return nil return nil
} }
// Query retrieves messages from the DB
func (d *DBStore) Query(query *pb.HistoryQuery) ([]StoredMessage, error) { func (d *DBStore) Query(query *pb.HistoryQuery) ([]StoredMessage, error) {
start := time.Now() start := time.Now()
defer func() { defer func() {
@ -319,6 +322,8 @@ func (d *DBStore) Query(query *pb.HistoryQuery) ([]StoredMessage, error) {
return result, nil return result, nil
} }
// MostRecentTimestamp returns an unix timestamp with the most recent senderTimestamp
// in the message table
func (d *DBStore) MostRecentTimestamp() (int64, error) { func (d *DBStore) MostRecentTimestamp() (int64, error) {
result := sql.NullInt64{} result := sql.NullInt64{}
@ -329,7 +334,7 @@ func (d *DBStore) MostRecentTimestamp() (int64, error) {
return result.Int64, nil return result.Int64, nil
} }
// Returns all the stored WakuMessages // GetAll returns all the stored WakuMessages
func (d *DBStore) GetAll() ([]StoredMessage, error) { func (d *DBStore) GetAll() ([]StoredMessage, error) {
start := time.Now() start := time.Now()
defer func() { defer func() {
@ -364,7 +369,8 @@ func (d *DBStore) GetAll() ([]StoredMessage, error) {
return result, nil return result, nil
} }
func (d *DBStore) GetStoredMessage(rows *sql.Rows) (StoredMessage, error) { // GetStoredMessage is a helper function used to convert a `*sql.Rows` into a `StoredMessage`
func (d *DBStore) GetStoredMessage(row *sql.Rows) (StoredMessage, error) {
var id []byte var id []byte
var receiverTimestamp int64 var receiverTimestamp int64
var senderTimestamp int64 var senderTimestamp int64
@ -373,7 +379,7 @@ func (d *DBStore) GetStoredMessage(rows *sql.Rows) (StoredMessage, error) {
var version uint32 var version uint32
var pubsubTopic string var pubsubTopic string
err := rows.Scan(&id, &receiverTimestamp, &senderTimestamp, &contentTopic, &pubsubTopic, &payload, &version) err := row.Scan(&id, &receiverTimestamp, &senderTimestamp, &contentTopic, &pubsubTopic, &payload, &version)
if err != nil { if err != nil {
d.log.Error("scanning messages from db", zap.Error(err)) d.log.Error("scanning messages from db", zap.Error(err))
return StoredMessage{}, err return StoredMessage{}, err

View File

@ -17,7 +17,7 @@ type dnsDiscoveryParameters struct {
type DnsDiscoveryOption func(*dnsDiscoveryParameters) type DnsDiscoveryOption func(*dnsDiscoveryParameters)
// WithMultiaddress is a WakuNodeOption that configures libp2p to listen on a list of multiaddresses // WithNameserver is a DnsDiscoveryOption that configures the nameserver to use
func WithNameserver(nameserver string) DnsDiscoveryOption { func WithNameserver(nameserver string) DnsDiscoveryOption {
return func(params *dnsDiscoveryParameters) { return func(params *dnsDiscoveryParameters) {
params.nameserver = nameserver params.nameserver = nameserver

View File

@ -18,6 +18,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// LightPushID_v20beta1 is the current Waku Lightpush protocol identifier
const LightPushID_v20beta1 = libp2pProtocol.ID("/vac/waku/lightpush/2.0.0-beta1") const LightPushID_v20beta1 = libp2pProtocol.ID("/vac/waku/lightpush/2.0.0-beta1")
var ( var (

View File

@ -19,12 +19,15 @@ type LightPushParameters struct {
type LightPushOption func(*LightPushParameters) type LightPushOption func(*LightPushParameters)
// WithPeer is an option used to specify the peerID to push a waku message to
func WithPeer(p peer.ID) LightPushOption { func WithPeer(p peer.ID) LightPushOption {
return func(params *LightPushParameters) { return func(params *LightPushParameters) {
params.selectedPeer = p params.selectedPeer = p
} }
} }
// WithAutomaticPeerSelection is an option used to randomly select a peer from the peer store
// to push a waku message to
func WithAutomaticPeerSelection(host host.Host) LightPushOption { func WithAutomaticPeerSelection(host host.Host) LightPushOption {
return func(params *LightPushParameters) { return func(params *LightPushParameters) {
p, err := utils.SelectPeer(host, string(LightPushID_v20beta1), params.log) p, err := utils.SelectPeer(host, string(LightPushID_v20beta1), params.log)
@ -36,6 +39,8 @@ func WithAutomaticPeerSelection(host host.Host) LightPushOption {
} }
} }
// WithFastestPeerSelection is an option used to select a peer from the peer store
// with the lowest ping
func WithFastestPeerSelection(ctx context.Context) LightPushOption { func WithFastestPeerSelection(ctx context.Context) LightPushOption {
return func(params *LightPushParameters) { return func(params *LightPushParameters) {
p, err := utils.SelectPeerWithLowestRTT(ctx, params.host, string(LightPushID_v20beta1), params.log) p, err := utils.SelectPeerWithLowestRTT(ctx, params.host, string(LightPushID_v20beta1), params.log)
@ -47,18 +52,23 @@ func WithFastestPeerSelection(ctx context.Context) LightPushOption {
} }
} }
// WithRequestId is an option to set a specific request ID to be used when
// publishing a message
func WithRequestId(requestId []byte) LightPushOption { func WithRequestId(requestId []byte) LightPushOption {
return func(params *LightPushParameters) { return func(params *LightPushParameters) {
params.requestId = requestId params.requestId = requestId
} }
} }
// WithAutomaticRequestId is an option to automatically generate a request ID
// when publishing a message
func WithAutomaticRequestId() LightPushOption { func WithAutomaticRequestId() LightPushOption {
return func(params *LightPushParameters) { return func(params *LightPushParameters) {
params.requestId = protocol.GenerateRequestId() params.requestId = protocol.GenerateRequestId()
} }
} }
// DefaultOptions are the default options to be used when using the lightpush protocol
func DefaultOptions(host host.Host) []LightPushOption { func DefaultOptions(host host.Host) []LightPushOption {
return []LightPushOption{ return []LightPushOption{
WithAutomaticRequestId(), WithAutomaticRequestId(),

View File

@ -279,7 +279,7 @@ func WithPeer(p peer.ID) HistoryRequestOption {
} }
} }
// WithAutomaticPeerSelection is an option used to randomly select a peer from the store // WithAutomaticPeerSelection is an option used to randomly select a peer from the peer store
// to request the message history // to request the message history
func WithAutomaticPeerSelection() HistoryRequestOption { func WithAutomaticPeerSelection() HistoryRequestOption {
return func(params *HistoryRequestParameters) { return func(params *HistoryRequestParameters) {

View File

@ -7,6 +7,7 @@ import (
"github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/crypto"
) )
// EcdsaPubKeyToSecp256k1PublicKey converts an `ecdsa.PublicKey` into a libp2p `crypto.Secp256k1PublicKey``
func EcdsaPubKeyToSecp256k1PublicKey(pubKey *ecdsa.PublicKey) *crypto.Secp256k1PublicKey { func EcdsaPubKeyToSecp256k1PublicKey(pubKey *ecdsa.PublicKey) *crypto.Secp256k1PublicKey {
xFieldVal := &btcec.FieldVal{} xFieldVal := &btcec.FieldVal{}
yFieldVal := &btcec.FieldVal{} yFieldVal := &btcec.FieldVal{}
@ -15,6 +16,7 @@ func EcdsaPubKeyToSecp256k1PublicKey(pubKey *ecdsa.PublicKey) *crypto.Secp256k1P
return (*crypto.Secp256k1PublicKey)(btcec.NewPublicKey(xFieldVal, yFieldVal)) return (*crypto.Secp256k1PublicKey)(btcec.NewPublicKey(xFieldVal, yFieldVal))
} }
// EcdsaPubKeyToSecp256k1PublicKey converts an `ecdsa.PrivateKey` into a libp2p `crypto.Secp256k1PrivateKey``
func EcdsaPrivKeyToSecp256k1PrivKey(privKey *ecdsa.PrivateKey) *crypto.Secp256k1PrivateKey { func EcdsaPrivKeyToSecp256k1PrivKey(privKey *ecdsa.PrivateKey) *crypto.Secp256k1PrivateKey {
privK, _ := btcec.PrivKeyFromBytes(privKey.D.Bytes()) privK, _ := btcec.PrivKeyFromBytes(privKey.D.Bytes())
return (*crypto.Secp256k1PrivateKey)(privK) return (*crypto.Secp256k1PrivateKey)(privK)

View File

@ -206,6 +206,7 @@ func Multiaddress(node *enode.Node) ([]ma.Multiaddr, error) {
return result, nil return result, nil
} }
// EnodeToPeerInfo extracts the peer ID and multiaddresses defined in an ENR
func EnodeToPeerInfo(node *enode.Node) (*peer.AddrInfo, error) { func EnodeToPeerInfo(node *enode.Node) (*peer.AddrInfo, error) {
addresses, err := Multiaddress(node) addresses, err := Multiaddress(node)
if err != nil { if err != nil {
@ -218,5 +219,4 @@ func EnodeToPeerInfo(node *enode.Node) (*peer.AddrInfo, error) {
} }
return &res[0], nil return &res[0], nil
} }

View File

@ -29,6 +29,7 @@ func Logger() *zap.Logger {
return log return log
} }
// InitLogger initializes a global logger using an specific encoding
func InitLogger(encoding string) { func InitLogger(encoding string) {
cfg := zap.Config{ cfg := zap.Config{
Encoding: encoding, Encoding: encoding,