mirror of
https://github.com/logos-messaging/logos-messaging-go.git
synced 2026-01-15 20:33:07 +00:00
fix: code review
This commit is contained in:
parent
dbfb9e2716
commit
434111f66c
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"sync"
|
||||
@ -48,7 +49,7 @@ type peerRecord struct {
|
||||
}
|
||||
|
||||
type discV5Parameters struct {
|
||||
autoupdate bool
|
||||
autoUpdate bool
|
||||
bootnodes []*enode.Node
|
||||
udpPort int
|
||||
tcpPort int
|
||||
@ -62,9 +63,9 @@ type WakuEnrBitfield = uint8
|
||||
|
||||
type DiscoveryV5Option func(*discV5Parameters)
|
||||
|
||||
func WithAutoUpdate(autoupdate bool) DiscoveryV5Option {
|
||||
func WithAutoUpdate(autoUpdate bool) DiscoveryV5Option {
|
||||
return func(params *discV5Parameters) {
|
||||
params.autoupdate = autoupdate
|
||||
params.autoUpdate = autoUpdate
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,8 +159,18 @@ func newLocalnode(priv *ecdsa.PrivateKey, ipAddr net.IP, udpPort int, tcpPort in
|
||||
localnode.SetFallbackUDP(udpPort)
|
||||
localnode.Set(enr.WithEntry(WakuENRField, wakuFlags))
|
||||
localnode.Set(enr.IP(ipAddr))
|
||||
localnode.Set(enr.UDP(udpPort))
|
||||
localnode.Set(enr.TCP(tcpPort))
|
||||
|
||||
if udpPort > 0 && udpPort <= math.MaxUint16 {
|
||||
localnode.Set(enr.UDP(uint16(udpPort)))
|
||||
} else {
|
||||
log.Error("could not set udpPort ", udpPort)
|
||||
}
|
||||
|
||||
if tcpPort > 0 && tcpPort <= math.MaxUint16 {
|
||||
localnode.Set(enr.TCP(uint16(tcpPort)))
|
||||
} else {
|
||||
log.Error("could not set tcpPort ", tcpPort)
|
||||
}
|
||||
|
||||
if advertiseAddr != nil {
|
||||
localnode.SetStaticIP(*advertiseAddr)
|
||||
@ -232,7 +243,7 @@ func IsPrivate(ip net.IP) bool {
|
||||
}
|
||||
|
||||
func (d *DiscoveryV5) UpdateAddr(addr net.IP) error {
|
||||
if !d.params.autoupdate {
|
||||
if !d.params.autoUpdate {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -81,7 +81,6 @@ func TestDiscV5(t *testing.T) {
|
||||
foundHost2 := false
|
||||
foundHost3 := false
|
||||
for p := range peerChan {
|
||||
fmt.Println(p)
|
||||
if p.Addrs[0].String() == host2.Addrs()[0].String() {
|
||||
foundHost2 = true
|
||||
}
|
||||
|
||||
@ -159,13 +159,17 @@ func (w *WakuNode) onAddrChange() {
|
||||
for m := range w.addrChan {
|
||||
ipStr, err := m.ValueForProtocol(ma.P_IP4)
|
||||
if err != nil {
|
||||
log.Error("could not extract ip from ma %s: %s", m, err.Error())
|
||||
log.Error(fmt.Sprintf("could not extract ip from ma %s: %s", m, err.Error()))
|
||||
continue
|
||||
}
|
||||
ip := net.ParseIP(ipStr)
|
||||
if !ip.IsLoopback() && !ip.IsUnspecified() {
|
||||
if w.opts.enableDiscV5 {
|
||||
w.discoveryV5.UpdateAddr(ip)
|
||||
err := w.discoveryV5.UpdateAddr(ip)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("could not update DiscV5 address with IP %s: %s", ip, err.Error()))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -357,7 +361,7 @@ func (w *WakuNode) mountDiscV5() error {
|
||||
discV5Options := []discv5.DiscoveryV5Option{
|
||||
discv5.WithBootnodes(w.opts.discV5bootnodes),
|
||||
discv5.WithUDPPort(w.opts.udpPort),
|
||||
discv5.WithAutoUpdate(w.opts.discV5autoupdate),
|
||||
discv5.WithAutoUpdate(w.opts.discV5autoUpdate),
|
||||
}
|
||||
|
||||
addr := w.ListenAddresses()[0]
|
||||
|
||||
@ -52,7 +52,7 @@ type WakuNodeParameters struct {
|
||||
udpPort int
|
||||
discV5bootnodes []*enode.Node
|
||||
discV5Opts []pubsub.DiscoverOpt
|
||||
discV5autoupdate bool
|
||||
discV5autoUpdate bool
|
||||
|
||||
keepAliveInterval time.Duration
|
||||
|
||||
@ -167,7 +167,7 @@ func WithDiscoveryV5(udpPort int, bootnodes []*enode.Node, autoUpdate bool, disc
|
||||
params.udpPort = udpPort
|
||||
params.discV5bootnodes = bootnodes
|
||||
params.discV5Opts = discoverOpts
|
||||
params.discV5autoupdate = autoUpdate
|
||||
params.discV5autoUpdate = autoUpdate
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user