Merge branch 'master' into Test_utils_P2

This commit is contained in:
aya 2025-02-26 12:55:20 +02:00
commit deed0df10a
6 changed files with 116 additions and 24 deletions

View File

@ -5,7 +5,7 @@ THIRD_PARTY_DIR := ../third_party
NWAKU_REPO := https://github.com/waku-org/nwaku
NWAKU_DIR := $(THIRD_PARTY_DIR)/nwaku
.PHONY: all clean prepare build
.PHONY: all clean prepare build-libwaku build
# Default target
all: build
@ -22,12 +22,14 @@ prepare:
else \
echo "nwaku repository already exists."; \
fi
# Build libwaku
build-libwaku: prepare
@echo "Building libwaku..."
@cd $(NWAKU_DIR) && make libwaku
# Build Waku Go Bindings
build: prepare
build: build-libwaku
@echo "Building Waku Go Bindings..."
go build ./...

36
waku/common/config.go Normal file
View File

@ -0,0 +1,36 @@
package common
type WakuConfig struct {
Host string `json:"host,omitempty"`
Nodekey string `json:"nodekey,omitempty"`
Relay bool `json:"relay"`
Store bool `json:"store,omitempty"`
LegacyStore bool `json:"legacyStore"`
Storenode string `json:"storenode,omitempty"`
StoreMessageRetentionPolicy string `json:"storeMessageRetentionPolicy,omitempty"`
StoreMessageDbUrl string `json:"storeMessageDbUrl,omitempty"`
StoreMessageDbVacuum bool `json:"storeMessageDbVacuum,omitempty"`
StoreMaxNumDbConnections int `json:"storeMaxNumDbConnections,omitempty"`
StoreResume bool `json:"storeResume,omitempty"`
Filter bool `json:"filter,omitempty"`
Filternode string `json:"filternode,omitempty"`
FilterSubscriptionTimeout int64 `json:"filterSubscriptionTimeout,omitempty"`
FilterMaxPeersToServe uint32 `json:"filterMaxPeersToServe,omitempty"`
FilterMaxCriteria uint32 `json:"filterMaxCriteria,omitempty"`
Lightpush bool `json:"lightpush,omitempty"`
LightpushNode string `json:"lightpushnode,omitempty"`
LogLevel string `json:"logLevel,omitempty"`
DnsDiscovery bool `json:"dnsDiscovery,omitempty"`
DnsDiscoveryUrl string `json:"dnsDiscoveryUrl,omitempty"`
MaxMessageSize string `json:"maxMessageSize,omitempty"`
Staticnodes []string `json:"staticnodes,omitempty"`
Discv5BootstrapNodes []string `json:"discv5BootstrapNodes,omitempty"`
Discv5Discovery bool `json:"discv5Discovery,omitempty"`
Discv5UdpPort int `json:"discv5UdpPort,omitempty"`
ClusterID uint16 `json:"clusterId,omitempty"`
Shards []uint16 `json:"shards,omitempty"`
PeerExchange bool `json:"peerExchange,omitempty"`
PeerExchangeNode string `json:"peerExchangeNode,omitempty"`
TcpPort int `json:"tcpPort,omitempty"`
RateLimits RateLimitsConfig `json:"rateLimits,omitempty"`
}

View File

@ -35,5 +35,10 @@ func (h MessageHash) String() string {
}
func (h MessageHash) Bytes() ([]byte, error) {
return hex.DecodeString(string(h))
s := string(h)
// Remove 0x prefix if present
if len(s) >= 2 && s[:2] == "0x" {
s = s[2:]
}
return hex.DecodeString(s)
}

47
waku/common/rate_limit.go Normal file
View File

@ -0,0 +1,47 @@
package common
import (
"encoding/json"
"fmt"
)
type RateLimitsConfig struct {
Filter *RateLimit `json:"-"`
Lightpush *RateLimit `json:"-"`
PeerExchange *RateLimit `json:"-"`
}
type RateLimit struct {
Volume int // Number of allowed messages per period
Period int // Length of each rate-limit period (in TimeUnit)
TimeUnit RateLimitTimeUnit // Time unit of the period
}
type RateLimitTimeUnit string
const Hour RateLimitTimeUnit = "h"
const Minute RateLimitTimeUnit = "m"
const Second RateLimitTimeUnit = "s"
const Millisecond RateLimitTimeUnit = "ms"
func (rl RateLimit) String() string {
return fmt.Sprintf("%d/%d%s", rl.Volume, rl.Period, rl.TimeUnit)
}
func (rl RateLimit) MarshalJSON() ([]byte, error) {
return json.Marshal(rl.String())
}
func (rlc RateLimitsConfig) MarshalJSON() ([]byte, error) {
output := []string{}
if rlc.Filter != nil {
output = append(output, fmt.Sprintf("filter:%s", rlc.Filter.String()))
}
if rlc.Lightpush != nil {
output = append(output, fmt.Sprintf("lightpush:%s", rlc.Lightpush.String()))
}
if rlc.PeerExchange != nil {
output = append(output, fmt.Sprintf("px:%s", rlc.PeerExchange.String()))
}
return json.Marshal(output)
}

View File

@ -37,7 +37,7 @@ func TestBasicWaku(t *testing.T) {
// ctx := context.Background()
nwakuConfig := WakuConfig{
nwakuConfig := common.WakuConfig{
Nodekey: "11d0dcea28e86f81937a3bd1163473c7fbc0a0db54fd72914849bc47bdf78710",
Relay: true,
LogLevel: "DEBUG",
@ -190,7 +190,7 @@ func TestPeerExchange(t *testing.T) {
tcpPort, udpPort, err := GetFreePortIfNeeded(0, 0)
require.NoError(t, err)
// start node that will be discovered by PeerExchange
discV5NodeWakuConfig := WakuConfig{
discV5NodeWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: true,
@ -215,7 +215,7 @@ func TestPeerExchange(t *testing.T) {
require.NoError(t, err)
// start node which serves as PeerExchange server
pxServerWakuConfig := WakuConfig{
pxServerWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: true,
@ -264,7 +264,7 @@ func TestPeerExchange(t *testing.T) {
require.NoError(t, err)
// start light node which uses PeerExchange to discover peers
pxClientWakuConfig := WakuConfig{
pxClientWakuConfig := common.WakuConfig{
Relay: false,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -324,7 +324,7 @@ func TestDnsDiscover(t *testing.T) {
require.NoError(t, err)
nameserver := "8.8.8.8"
nodeWakuConfig := WakuConfig{
nodeWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
ClusterID: 16,
@ -353,7 +353,7 @@ func TestDial(t *testing.T) {
require.NoError(t, err)
// start node that will initiate the dial
dialerNodeWakuConfig := WakuConfig{
dialerNodeWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -371,7 +371,7 @@ func TestDial(t *testing.T) {
require.NoError(t, err)
// start node that will receive the dial
receiverNodeWakuConfig := WakuConfig{
receiverNodeWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -418,7 +418,7 @@ func TestRelay(t *testing.T) {
require.NoError(t, err)
// start node that will send the message
senderNodeWakuConfig := WakuConfig{
senderNodeWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -436,7 +436,7 @@ func TestRelay(t *testing.T) {
require.NoError(t, err)
// start node that will receive the message
receiverNodeWakuConfig := WakuConfig{
receiverNodeWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -502,7 +502,7 @@ func TestTopicHealth(t *testing.T) {
require.NoError(t, err)
// start node1
wakuConfig1 := WakuConfig{
wakuConfig1 := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -520,7 +520,7 @@ func TestTopicHealth(t *testing.T) {
require.NoError(t, err)
// start node2
wakuConfig2 := WakuConfig{
wakuConfig2 := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -575,7 +575,7 @@ func TestConnectionChange(t *testing.T) {
require.NoError(t, err)
// start node1
wakuConfig1 := WakuConfig{
wakuConfig1 := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -593,7 +593,7 @@ func TestConnectionChange(t *testing.T) {
require.NoError(t, err)
// start node2
wakuConfig2 := WakuConfig{
wakuConfig2 := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -662,7 +662,7 @@ func TestStore(t *testing.T) {
require.NoError(t, err)
// start node that will send the message
senderNodeWakuConfig := WakuConfig{
senderNodeWakuConfig := common.WakuConfig{
Relay: true,
Store: true,
LogLevel: "DEBUG",
@ -682,7 +682,7 @@ func TestStore(t *testing.T) {
require.NoError(t, err)
// start node that will receive the message
receiverNodeWakuConfig := WakuConfig{
receiverNodeWakuConfig := common.WakuConfig{
Relay: true,
Store: true,
LogLevel: "DEBUG",
@ -845,7 +845,7 @@ func TestParallelPings(t *testing.T) {
require.NoError(t, err)
// start node that will initiate the dial
dialerNodeWakuConfig := WakuConfig{
dialerNodeWakuConfig := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -862,7 +862,7 @@ func TestParallelPings(t *testing.T) {
tcpPort, udpPort, err = GetFreePortIfNeeded(0, 0)
require.NoError(t, err)
receiverNodeWakuConfig1 := WakuConfig{
receiverNodeWakuConfig1 := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -883,7 +883,7 @@ func TestParallelPings(t *testing.T) {
tcpPort, udpPort, err = GetFreePortIfNeeded(0, 0)
require.NoError(t, err)
receiverNodeWakuConfig2 := WakuConfig{
receiverNodeWakuConfig2 := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,
@ -904,7 +904,7 @@ func TestParallelPings(t *testing.T) {
tcpPort, udpPort, err = GetFreePortIfNeeded(0, 0)
require.NoError(t, err)
receiverNodeWakuConfig3 := WakuConfig{
receiverNodeWakuConfig3 := common.WakuConfig{
Relay: true,
LogLevel: "DEBUG",
Discv5Discovery: false,

View File

@ -2,9 +2,11 @@ package waku
import (
"time"
"github.com/waku-org/waku-go-bindings/waku/common"
)
var DefaultWakuConfig WakuConfig
var DefaultWakuConfig common.WakuConfig
func init() {