mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-01-02 14:03:10 +00:00
Adding changes to waku files to remove wrappers
This commit is contained in:
parent
167e3e7add
commit
1878db0e12
9
go.mod
9
go.mod
@ -35,10 +35,13 @@ require (
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/crypto v0.26.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
google.golang.org/protobuf v1.34.2
|
||||
)
|
||||
|
||||
require github.com/waku-org/go-waku v0.8.1-0.20241028194639-dd82c24e0057
|
||||
require (
|
||||
github.com/sirupsen/logrus v1.2.0
|
||||
github.com/waku-org/go-waku v0.8.1-0.20241028194639-dd82c24e0057
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
@ -56,6 +59,7 @@ require (
|
||||
github.com/ipfs/go-log/v2 v2.5.1 // indirect
|
||||
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
|
||||
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
|
||||
github.com/libp2p/go-msgio v0.3.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
@ -79,6 +83,7 @@ require (
|
||||
golang.org/x/net v0.28.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.24.0 // indirect
|
||||
golang.org/x/term v0.23.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
lukechampine.com/blake3 v1.3.0 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@ -297,6 +297,7 @@ github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS
|
||||
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg=
|
||||
github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0=
|
||||
github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk=
|
||||
@ -514,6 +515,7 @@ github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
@ -732,6 +734,8 @@ golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
|
||||
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
|
||||
39
waku/logging.go
Normal file
39
waku/logging.go
Normal file
@ -0,0 +1,39 @@
|
||||
package waku
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
instance *logrus.Logger
|
||||
)
|
||||
|
||||
// GetLogger ensures we always return the same logger instance
|
||||
func GetLogger() *logrus.Logger {
|
||||
once.Do(func() {
|
||||
instance = logrus.New()
|
||||
instance.SetFormatter(&logrus.TextFormatter{
|
||||
FullTimestamp: true,
|
||||
})
|
||||
instance.SetLevel(logrus.DebugLevel) // Set default log level
|
||||
})
|
||||
return instance
|
||||
}
|
||||
|
||||
// Debug logs a debug message
|
||||
func Debug(msg string, args ...interface{}) {
|
||||
GetLogger().WithFields(logrus.Fields{}).Debugf(msg, args...)
|
||||
}
|
||||
|
||||
// Info logs an info message
|
||||
func Info(msg string, args ...interface{}) {
|
||||
GetLogger().WithFields(logrus.Fields{}).Infof(msg, args...)
|
||||
}
|
||||
|
||||
// Error logs an error message
|
||||
func Error(msg string, args ...interface{}) {
|
||||
GetLogger().WithFields(logrus.Fields{}).Errorf(msg, args...)
|
||||
}
|
||||
@ -1306,3 +1306,37 @@ func GetFreePortIfNeeded(tcpPort int, discV5UDPPort int, logger *zap.Logger) (in
|
||||
|
||||
return tcpPort, discV5UDPPort, nil
|
||||
}
|
||||
|
||||
func StartWakuNode(customCfg *WakuConfig) (*WakuNode, error) {
|
||||
logrusLogger := GetLogger()
|
||||
logger := logrusToZap(logrusLogger)
|
||||
|
||||
logger.Debug("Initializing Waku node")
|
||||
|
||||
var nodeCfg WakuConfig
|
||||
if customCfg == nil {
|
||||
nodeCfg = DefaultWakuConfig // Use the default configuration
|
||||
} else {
|
||||
nodeCfg = *customCfg
|
||||
}
|
||||
|
||||
// Assign dynamically generated ports
|
||||
nodeCfg.Discv5UdpPort = GenerateUniquePort()
|
||||
nodeCfg.TcpPort = GenerateUniquePort()
|
||||
|
||||
logger.Debug("Creating Waku node")
|
||||
node, err := NewWakuNode(&nodeCfg, logger)
|
||||
if err != nil {
|
||||
logger.Error("Failed to create Waku node", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger.Debug("Starting Waku node")
|
||||
if err := node.Start(); err != nil {
|
||||
logger.Error("Failed to start Waku node", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger.Debug("Successfully started Waku node")
|
||||
return node, nil
|
||||
}
|
||||
|
||||
@ -7,9 +7,13 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/exp/rand"
|
||||
)
|
||||
|
||||
type NwakuInfo struct {
|
||||
@ -17,6 +21,31 @@ type NwakuInfo struct {
|
||||
EnrUri string `json:"enrUri"`
|
||||
}
|
||||
|
||||
func logrusToZap(log *logrus.Logger) *zap.Logger {
|
||||
config := zap.NewDevelopmentConfig()
|
||||
config.EncoderConfig.TimeKey = "" // Remove timestamp duplication
|
||||
config.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
|
||||
zapLogger, _ := config.Build()
|
||||
return zapLogger
|
||||
}
|
||||
|
||||
func GenerateUniquePort() int {
|
||||
rng := rand.New(rand.NewSource(uint64(time.Now().UnixNano()))) // Local RNG instance
|
||||
|
||||
for {
|
||||
port := rng.Intn(MaxPort-MinPort+1) + MinPort
|
||||
|
||||
portsMutex.Lock()
|
||||
if !usedPorts[port] {
|
||||
usedPorts[port] = true
|
||||
portsMutex.Unlock()
|
||||
return port
|
||||
}
|
||||
portsMutex.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func GetNwakuInfo(host *string, port *int) (NwakuInfo, error) {
|
||||
nwakuRestPort := 8645
|
||||
if port != nil {
|
||||
|
||||
31
waku/test_data.go
Normal file
31
waku/test_data.go
Normal file
@ -0,0 +1,31 @@
|
||||
package waku
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const ConnectPeerTimeout = 10 * time.Second //default timeout for node to connect to another node
|
||||
|
||||
var DefaultPubsubTopic = "/waku/2/rs/16/64"
|
||||
var (
|
||||
MinPort = 1024 // Minimum allowable port (exported)
|
||||
MaxPort = 65535 // Maximum allowable port (exported)
|
||||
usedPorts = make(map[int]bool) // Tracks used ports (internal to package)
|
||||
portsMutex sync.Mutex // Ensures thread-safe access to usedPorts
|
||||
)
|
||||
|
||||
// Default configuration values
|
||||
var DefaultWakuConfig = WakuConfig{
|
||||
Relay: false,
|
||||
LogLevel: "DEBUG",
|
||||
Discv5Discovery: true,
|
||||
ClusterID: 16,
|
||||
Shards: []uint16{64},
|
||||
PeerExchange: false,
|
||||
Store: false,
|
||||
Filter: false,
|
||||
Lightpush: false,
|
||||
Discv5UdpPort: GenerateUniquePort(),
|
||||
TcpPort: GenerateUniquePort(),
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user