fix: adding missing config settings
This commit is contained in:
parent
724689086c
commit
faf8f34fef
2
go.mod
2
go.mod
|
@ -54,7 +54,7 @@ require (
|
||||||
github.com/russolsen/same v0.0.0-20160222130632-f089df61f51d // indirect
|
github.com/russolsen/same v0.0.0-20160222130632-f089df61f51d // indirect
|
||||||
github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a
|
github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a
|
||||||
github.com/status-im/doubleratchet v3.0.0+incompatible
|
github.com/status-im/doubleratchet v3.0.0+incompatible
|
||||||
github.com/status-im/go-waku v0.0.0-20220323131654-8468323cd349
|
github.com/status-im/go-waku v0.0.0-20220401012237-ce5d6ec38236
|
||||||
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432
|
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432
|
||||||
github.com/status-im/markdown v0.0.0-20210405121740-32e5a5055fb6
|
github.com/status-im/markdown v0.0.0-20210405121740-32e5a5055fb6
|
||||||
github.com/status-im/migrate/v4 v4.6.2-status.2
|
github.com/status-im/migrate/v4 v4.6.2-status.2
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1214,8 +1214,8 @@ github.com/status-im/go-ethereum v1.10.4-status.4 h1:Cs0MoHEhF0LEwii2R8U8jMSEW/g
|
||||||
github.com/status-im/go-ethereum v1.10.4-status.4/go.mod h1:GvIhpdCOgMHI6i5xVPEZOrv/qSMeOFHbZh77AoyZUoE=
|
github.com/status-im/go-ethereum v1.10.4-status.4/go.mod h1:GvIhpdCOgMHI6i5xVPEZOrv/qSMeOFHbZh77AoyZUoE=
|
||||||
github.com/status-im/go-multiaddr-ethv4 v1.2.1 h1:09v9n6426NAojNOvdgegqrAotgffWW/UPDwrpJ85DNE=
|
github.com/status-im/go-multiaddr-ethv4 v1.2.1 h1:09v9n6426NAojNOvdgegqrAotgffWW/UPDwrpJ85DNE=
|
||||||
github.com/status-im/go-multiaddr-ethv4 v1.2.1/go.mod h1:SlBebvQcSUM5+/R/YfpfMuu5WyraW47XFmIqLYBmlKU=
|
github.com/status-im/go-multiaddr-ethv4 v1.2.1/go.mod h1:SlBebvQcSUM5+/R/YfpfMuu5WyraW47XFmIqLYBmlKU=
|
||||||
github.com/status-im/go-waku v0.0.0-20220323131654-8468323cd349 h1:1aER9CYT/4SDbic0O+nFRhzh84ChTQA2wBYI2fa/pkQ=
|
github.com/status-im/go-waku v0.0.0-20220401012237-ce5d6ec38236 h1:rqFAobv30OTxOoQu4pOm/oRRuho1pRKQUWhrA2IiHVw=
|
||||||
github.com/status-im/go-waku v0.0.0-20220323131654-8468323cd349/go.mod h1:brdbk2SAE5B5E7Av4RyxiKXLUbCKrJkIv0l32KtQUa4=
|
github.com/status-im/go-waku v0.0.0-20220401012237-ce5d6ec38236/go.mod h1:1LeilRpyb6PelO78PlnyBTa40T36/UUQYbIagd7IFks=
|
||||||
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432 h1:cbNFU38iimo9fY4B7CdF/fvIF6tNPJIZjBbpfmW2EY4=
|
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432 h1:cbNFU38iimo9fY4B7CdF/fvIF6tNPJIZjBbpfmW2EY4=
|
||||||
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432/go.mod h1:A8t3i0CUGtXCA0aiLsP7iyikmk/KaD/2XVvNJqGCU20=
|
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432/go.mod h1:A8t3i0CUGtXCA0aiLsP7iyikmk/KaD/2XVvNJqGCU20=
|
||||||
github.com/status-im/gomoji v1.1.3-0.20220213022530-e5ac4a8732d4 h1:CtobZoiNdHpx+xurFxnuJ1xsGm3oKMfcZkB3vmomJmA=
|
github.com/status-im/gomoji v1.1.3-0.20220213022530-e5ac4a8732d4 h1:CtobZoiNdHpx+xurFxnuJ1xsGm3oKMfcZkB3vmomJmA=
|
||||||
|
|
|
@ -285,6 +285,8 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig) (*wakuv2.Waku,
|
||||||
PersistPeers: nodeConfig.WakuV2Config.PersistPeers,
|
PersistPeers: nodeConfig.WakuV2Config.PersistPeers,
|
||||||
DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes,
|
DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes,
|
||||||
EnableDiscV5: nodeConfig.WakuV2Config.EnableDiscV5,
|
EnableDiscV5: nodeConfig.WakuV2Config.EnableDiscV5,
|
||||||
|
UDPPort: nodeConfig.WakuV2Config.UDPPort,
|
||||||
|
AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
if nodeConfig.WakuV2Config.MaxMessageSize > 0 {
|
if nodeConfig.WakuV2Config.MaxMessageSize > 0 {
|
||||||
|
|
|
@ -3,10 +3,12 @@ package discv5
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -16,6 +18,7 @@ import (
|
||||||
"github.com/libp2p/go-libp2p-core/discovery"
|
"github.com/libp2p/go-libp2p-core/discovery"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
"github.com/status-im/go-discover/discover"
|
"github.com/status-im/go-discover/discover"
|
||||||
"github.com/status-im/go-waku/waku/v2/utils"
|
"github.com/status-im/go-waku/waku/v2/utils"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -40,6 +43,12 @@ type DiscoveryV5 struct {
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
|
|
||||||
peerCache peerCache
|
peerCache peerCache
|
||||||
|
|
||||||
|
// Used for those weird cases where updateAddress
|
||||||
|
// receives the same external address twice both with the original port
|
||||||
|
// and the nat port. Ideally this atribute should be removed by doing
|
||||||
|
// hole punching before starting waku
|
||||||
|
ogTCPPort int
|
||||||
}
|
}
|
||||||
|
|
||||||
type peerCache struct {
|
type peerCache struct {
|
||||||
|
@ -57,7 +66,6 @@ type discV5Parameters struct {
|
||||||
autoUpdate bool
|
autoUpdate bool
|
||||||
bootnodes []*enode.Node
|
bootnodes []*enode.Node
|
||||||
udpPort int
|
udpPort int
|
||||||
tcpPort int
|
|
||||||
advertiseAddr *net.IP
|
advertiseAddr *net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +101,7 @@ func DefaultOptions() []DiscoveryV5Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDiscoveryV5(host host.Host, ipAddr net.IP, tcpPort int, priv *ecdsa.PrivateKey, wakuFlags utils.WakuEnrBitfield, log *zap.SugaredLogger, opts ...DiscoveryV5Option) (*DiscoveryV5, error) {
|
func NewDiscoveryV5(host host.Host, addresses []ma.Multiaddr, priv *ecdsa.PrivateKey, wakuFlags utils.WakuEnrBitfield, log *zap.SugaredLogger, opts ...DiscoveryV5Option) (*DiscoveryV5, error) {
|
||||||
params := new(discV5Parameters)
|
params := new(discV5Parameters)
|
||||||
optList := DefaultOptions()
|
optList := DefaultOptions()
|
||||||
optList = append(optList, opts...)
|
optList = append(optList, opts...)
|
||||||
|
@ -103,9 +111,12 @@ func NewDiscoveryV5(host host.Host, ipAddr net.IP, tcpPort int, priv *ecdsa.Priv
|
||||||
|
|
||||||
logger := log.Named("discv5")
|
logger := log.Named("discv5")
|
||||||
|
|
||||||
params.tcpPort = tcpPort
|
ipAddr, err := selectIPAddr(addresses)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
localnode, err := newLocalnode(priv, ipAddr, params.udpPort, tcpPort, wakuFlags, params.advertiseAddr, logger)
|
localnode, err := newLocalnode(priv, ipAddr, params.udpPort, wakuFlags, params.advertiseAddr, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -140,20 +151,21 @@ func NewDiscoveryV5(host host.Host, ipAddr net.IP, tcpPort int, priv *ecdsa.Priv
|
||||||
IP: net.IPv4zero,
|
IP: net.IPv4zero,
|
||||||
Port: params.udpPort,
|
Port: params.udpPort,
|
||||||
},
|
},
|
||||||
log: logger,
|
log: logger,
|
||||||
|
ogTCPPort: ipAddr.Port,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLocalnode(priv *ecdsa.PrivateKey, ipAddr net.IP, udpPort int, tcpPort int, wakuFlags utils.WakuEnrBitfield, advertiseAddr *net.IP, log *zap.SugaredLogger) (*enode.LocalNode, error) {
|
func newLocalnode(priv *ecdsa.PrivateKey, ipAddr *net.TCPAddr, udpPort int, wakuFlags utils.WakuEnrBitfield, advertiseAddr *net.IP, log *zap.SugaredLogger) (*enode.LocalNode, error) {
|
||||||
db, err := enode.OpenDB("")
|
db, err := enode.OpenDB("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
localnode := enode.NewLocalNode(db, priv)
|
localnode := enode.NewLocalNode(db, priv)
|
||||||
localnode.SetFallbackIP(net.IP{127, 0, 0, 1})
|
|
||||||
localnode.SetFallbackUDP(udpPort)
|
localnode.SetFallbackUDP(udpPort)
|
||||||
localnode.Set(enr.WithEntry(utils.WakuENRField, wakuFlags))
|
localnode.Set(enr.WithEntry(utils.WakuENRField, wakuFlags))
|
||||||
localnode.Set(enr.IP(ipAddr))
|
localnode.SetFallbackIP(net.IP{127, 0, 0, 1})
|
||||||
|
localnode.SetStaticIP(ipAddr.IP)
|
||||||
|
|
||||||
if udpPort > 0 && udpPort <= math.MaxUint16 {
|
if udpPort > 0 && udpPort <= math.MaxUint16 {
|
||||||
localnode.Set(enr.UDP(uint16(udpPort))) // lgtm [go/incorrect-integer-conversion]
|
localnode.Set(enr.UDP(uint16(udpPort))) // lgtm [go/incorrect-integer-conversion]
|
||||||
|
@ -161,10 +173,10 @@ func newLocalnode(priv *ecdsa.PrivateKey, ipAddr net.IP, udpPort int, tcpPort in
|
||||||
log.Error("could not set udpPort ", udpPort)
|
log.Error("could not set udpPort ", udpPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tcpPort > 0 && tcpPort <= math.MaxUint16 {
|
if ipAddr.Port > 0 && ipAddr.Port <= math.MaxUint16 {
|
||||||
localnode.Set(enr.TCP(uint16(tcpPort))) // lgtm [go/incorrect-integer-conversion]
|
localnode.Set(enr.TCP(uint16(ipAddr.Port))) // lgtm [go/incorrect-integer-conversion]
|
||||||
} else {
|
} else {
|
||||||
log.Error("could not set tcpPort ", tcpPort)
|
log.Error("could not set tcpPort ", ipAddr.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
if advertiseAddr != nil {
|
if advertiseAddr != nil {
|
||||||
|
@ -200,7 +212,7 @@ func (d *DiscoveryV5) listen() error {
|
||||||
|
|
||||||
d.listener = listener
|
d.listener = listener
|
||||||
|
|
||||||
d.log.Info(fmt.Sprintf("Started Discovery V5 at %s:%d, advertising IP: %s:%d", d.udpAddr.IP, d.udpAddr.Port, d.localnode.Node().IP(), d.params.tcpPort))
|
d.log.Info(fmt.Sprintf("Started Discovery V5 at %s:%d, advertising IP: %s:%d", d.udpAddr.IP, d.udpAddr.Port, d.localnode.Node().IP(), d.localnode.Node().TCP()))
|
||||||
d.log.Info("Discovery V5 ", d.localnode.Node())
|
d.log.Info("Discovery V5 ", d.localnode.Node())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -236,31 +248,7 @@ func (d *DiscoveryV5) Stop() {
|
||||||
d.wg.Wait()
|
d.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPrivate reports whether ip is a private address, according to
|
func (d *DiscoveryV5) UpdateAddr(addr *net.TCPAddr) error {
|
||||||
// RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses).
|
|
||||||
// Copied/Adapted from https://go-review.googlesource.com/c/go/+/272668/11/src/net/ip.go
|
|
||||||
// Copyright (c) The Go Authors. All rights reserved.
|
|
||||||
// @TODO: once Go 1.17 is released in Q42021, remove this function as it will become part of the language
|
|
||||||
func IsPrivate(ip net.IP) bool {
|
|
||||||
if ip4 := ip.To4(); ip4 != nil {
|
|
||||||
// Following RFC 4193, Section 3. Local IPv6 Unicast Addresses which says:
|
|
||||||
// The Internet Assigned Numbers Authority (IANA) has reserved the
|
|
||||||
// following three blocks of the IPv4 address space for private internets:
|
|
||||||
// 10.0.0.0 - 10.255.255.255 (10/8 prefix)
|
|
||||||
// 172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
|
|
||||||
// 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
|
|
||||||
return ip4[0] == 10 ||
|
|
||||||
(ip4[0] == 172 && ip4[1]&0xf0 == 16) ||
|
|
||||||
(ip4[0] == 192 && ip4[1] == 168)
|
|
||||||
}
|
|
||||||
// Following RFC 4193, Section 3. Private Address Space which says:
|
|
||||||
// The Internet Assigned Numbers Authority (IANA) has reserved the
|
|
||||||
// following block of the IPv6 address space for local internets:
|
|
||||||
// FC00:: - FDFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF (FC00::/7 prefix)
|
|
||||||
return len(ip) == net.IPv6len && ip[0]&0xfe == 0xfc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DiscoveryV5) UpdateAddr(addr net.IP) error {
|
|
||||||
if !d.params.autoUpdate {
|
if !d.params.autoUpdate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -268,18 +256,21 @@ func (d *DiscoveryV5) UpdateAddr(addr net.IP) error {
|
||||||
d.Lock()
|
d.Lock()
|
||||||
defer d.Unlock()
|
defer d.Unlock()
|
||||||
|
|
||||||
if addr.IsUnspecified() || d.localnode.Node().IP().Equal(addr) {
|
// TODO: This code is not elegant and should be improved
|
||||||
|
|
||||||
|
if !isExternal(addr) && !isExternal(&net.TCPAddr{IP: d.localnode.Node().IP()}) {
|
||||||
|
if !((d.localnode.Node().IP().IsLoopback() && isPrivate(addr)) || (isPrivate(&net.TCPAddr{IP: d.localnode.Node().IP()}) && isExternal(addr))) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if addr.IP.IsUnspecified() || (d.localnode.Node().IP().Equal(addr.IP) && addr.Port == d.ogTCPPort) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: improve this logic to determine if an address should be replaced or not
|
d.localnode.SetStaticIP(addr.IP)
|
||||||
if !(d.localnode.Node().IP().IsLoopback() && IsPrivate(addr)) && !(IsPrivate(d.localnode.Node().IP()) && !addr.IsLoopback() && !IsPrivate(addr)) {
|
d.localnode.Set(enr.TCP(uint16(addr.Port))) // lgtm [go/incorrect-integer-conversion]
|
||||||
return nil
|
d.log.Info(fmt.Sprintf("Updated Discovery V5 node: %s:%d", d.localnode.Node().IP(), d.localnode.Node().TCP()))
|
||||||
}
|
|
||||||
|
|
||||||
d.localnode.Set(enr.IP(addr))
|
|
||||||
|
|
||||||
d.log.Info(fmt.Sprintf("Updated Discovery V5 node IP: %s", d.localnode.Node().IP()))
|
|
||||||
d.log.Info("Discovery V5 ", d.localnode.Node())
|
d.log.Info("Discovery V5 ", d.localnode.Node())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -479,3 +470,82 @@ func (d *DiscoveryV5) FindPeers(ctx context.Context, topic string, opts ...disco
|
||||||
|
|
||||||
return chPeer, err
|
return chPeer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPrivate reports whether ip is a private address, according to
|
||||||
|
// RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses).
|
||||||
|
// Copied/Adapted from https://go-review.googlesource.com/c/go/+/272668/11/src/net/ip.go
|
||||||
|
// Copyright (c) The Go Authors. All rights reserved.
|
||||||
|
// @TODO: once Go 1.17 is released in Q42021, remove this function as it will become part of the language
|
||||||
|
func isPrivate(ip *net.TCPAddr) bool {
|
||||||
|
if ip4 := ip.IP.To4(); ip4 != nil {
|
||||||
|
// Following RFC 4193, Section 3. Local IPv6 Unicast Addresses which says:
|
||||||
|
// The Internet Assigned Numbers Authority (IANA) has reserved the
|
||||||
|
// following three blocks of the IPv4 address space for private internets:
|
||||||
|
// 10.0.0.0 - 10.255.255.255 (10/8 prefix)
|
||||||
|
// 172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
|
||||||
|
// 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
|
||||||
|
return ip4[0] == 10 ||
|
||||||
|
(ip4[0] == 172 && ip4[1]&0xf0 == 16) ||
|
||||||
|
(ip4[0] == 192 && ip4[1] == 168)
|
||||||
|
}
|
||||||
|
// Following RFC 4193, Section 3. Private Address Space which says:
|
||||||
|
// The Internet Assigned Numbers Authority (IANA) has reserved the
|
||||||
|
// following block of the IPv6 address space for local internets:
|
||||||
|
// FC00:: - FDFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF (FC00::/7 prefix)
|
||||||
|
return len(ip.IP) == net.IPv6len && ip.IP[0]&0xfe == 0xfc
|
||||||
|
}
|
||||||
|
|
||||||
|
func isExternal(ip *net.TCPAddr) bool {
|
||||||
|
return !isPrivate(ip) && !ip.IP.IsLoopback() && !ip.IP.IsUnspecified()
|
||||||
|
}
|
||||||
|
|
||||||
|
func isLoopback(ip *net.TCPAddr) bool {
|
||||||
|
return ip.IP.IsLoopback()
|
||||||
|
}
|
||||||
|
func filter(ss []*net.TCPAddr, fn func(*net.TCPAddr) bool) (ret []*net.TCPAddr) {
|
||||||
|
for _, s := range ss {
|
||||||
|
if fn(s) {
|
||||||
|
ret = append(ret, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func selectIPAddr(addresses []ma.Multiaddr) (*net.TCPAddr, error) {
|
||||||
|
var ipAddrs []*net.TCPAddr
|
||||||
|
for _, addr := range addresses {
|
||||||
|
ipStr, err := addr.ValueForProtocol(ma.P_IP4)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
portStr, err := addr.ValueForProtocol(ma.P_TCP)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
port, err := strconv.Atoi(portStr)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ipAddrs = append(ipAddrs, &net.TCPAddr{
|
||||||
|
IP: net.ParseIP(ipStr),
|
||||||
|
Port: port,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
externalIPs := filter(ipAddrs, isExternal)
|
||||||
|
if len(externalIPs) > 0 {
|
||||||
|
return externalIPs[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
privateIPs := filter(ipAddrs, isPrivate)
|
||||||
|
if len(privateIPs) > 0 {
|
||||||
|
return privateIPs[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
loopback := filter(ipAddrs, isLoopback)
|
||||||
|
if len(loopback) > 0 {
|
||||||
|
return loopback[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("could not obtain ip address")
|
||||||
|
}
|
||||||
|
|
|
@ -189,12 +189,29 @@ func (w *WakuNode) onAddrChange() {
|
||||||
w.log.Error(fmt.Sprintf("could not extract ip from ma %s: %s", m, err.Error()))
|
w.log.Error(fmt.Sprintf("could not extract ip from ma %s: %s", m, err.Error()))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ip := net.ParseIP(ipStr)
|
|
||||||
if !ip.IsLoopback() && !ip.IsUnspecified() {
|
portStr, err := m.ValueForProtocol(ma.P_TCP)
|
||||||
|
if err != nil {
|
||||||
|
w.log.Error(fmt.Sprintf("could not extract port from ma %s: %s", m, err.Error()))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
port, err := strconv.Atoi(portStr)
|
||||||
|
if err != nil {
|
||||||
|
w.log.Error(fmt.Sprintf("could not convert port to int: %s", err.Error()))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
addr := &net.TCPAddr{
|
||||||
|
IP: net.ParseIP(ipStr),
|
||||||
|
Port: port,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !addr.IP.IsLoopback() && !addr.IP.IsUnspecified() {
|
||||||
if w.opts.enableDiscV5 {
|
if w.opts.enableDiscV5 {
|
||||||
err := w.discoveryV5.UpdateAddr(ip)
|
err := w.discoveryV5.UpdateAddr(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.log.Error(fmt.Sprintf("could not update DiscV5 address with IP %s: %s", ip, err.Error()))
|
w.log.Error(fmt.Sprintf("could not update DiscV5 address with IP %s:%d %s", addr.IP, addr.Port, err.Error()))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,24 +468,8 @@ func (w *WakuNode) mountDiscV5() error {
|
||||||
discV5Options = append(discV5Options, discv5.WithAdvertiseAddr(*w.opts.advertiseAddr))
|
discV5Options = append(discV5Options, discv5.WithAdvertiseAddr(*w.opts.advertiseAddr))
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := w.ListenAddresses()[0]
|
var err error
|
||||||
|
w.discoveryV5, err = discv5.NewDiscoveryV5(w.Host(), w.ListenAddresses(), w.opts.privKey, w.wakuFlag, w.log, discV5Options...)
|
||||||
ipStr, err := addr.ValueForProtocol(ma.P_IP4)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
portStr, err := addr.ValueForProtocol(ma.P_TCP)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
port, err := strconv.Atoi(portStr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
w.discoveryV5, err = discv5.NewDiscoveryV5(w.Host(), net.ParseIP(ipStr), port, w.opts.privKey, w.wakuFlag, w.log, discV5Options...)
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,7 +455,7 @@ github.com/status-im/go-discover/discover/v4wire
|
||||||
github.com/status-im/go-discover/discover/v5wire
|
github.com/status-im/go-discover/discover/v5wire
|
||||||
# github.com/status-im/go-multiaddr-ethv4 v1.2.1
|
# github.com/status-im/go-multiaddr-ethv4 v1.2.1
|
||||||
github.com/status-im/go-multiaddr-ethv4
|
github.com/status-im/go-multiaddr-ethv4
|
||||||
# github.com/status-im/go-waku v0.0.0-20220323131654-8468323cd349
|
# github.com/status-im/go-waku v0.0.0-20220401012237-ce5d6ec38236
|
||||||
github.com/status-im/go-waku/waku/persistence
|
github.com/status-im/go-waku/waku/persistence
|
||||||
github.com/status-im/go-waku/waku/try
|
github.com/status-im/go-waku/waku/try
|
||||||
github.com/status-im/go-waku/waku/v2
|
github.com/status-im/go-waku/waku/v2
|
||||||
|
|
|
@ -198,6 +198,7 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger, appDB *sql.DB) (*Waku,
|
||||||
|
|
||||||
libp2pOpts := node.DefaultLibP2POptions
|
libp2pOpts := node.DefaultLibP2POptions
|
||||||
libp2pOpts = append(libp2pOpts, libp2p.BandwidthReporter(waku.bandwidthCounter))
|
libp2pOpts = append(libp2pOpts, libp2p.BandwidthReporter(waku.bandwidthCounter))
|
||||||
|
libp2pOpts = append(libp2pOpts, libp2p.NATPortMap())
|
||||||
|
|
||||||
if cfg.PersistPeers {
|
if cfg.PersistPeers {
|
||||||
if appDB == nil {
|
if appDB == nil {
|
||||||
|
@ -268,6 +269,10 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger, appDB *sql.DB) (*Waku,
|
||||||
return nil, fmt.Errorf("failed to start go-waku node: %v", err)
|
return nil, fmt.Errorf("failed to start go-waku node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.EnableDiscV5 {
|
||||||
|
waku.node.DiscV5().Start()
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Reference in New Issue