fix: addr update

This commit is contained in:
Richard Ramos 2023-10-16 12:28:54 -04:00 committed by richΛrd
parent ee94581d0a
commit d4abe15634
14 changed files with 31 additions and 33 deletions

View File

@ -1,5 +1,5 @@
# BUILD IMAGE --------------------------------------------------------
FROM golang:1.19 as builder
FROM golang:1.20 as builder
WORKDIR /app
COPY . .

View File

@ -5,7 +5,7 @@ A Go implementation of the [Waku v2 protocol](https://rfc.vac.dev/spec/10).
<p align="left">
<a href="https://goreportcard.com/report/github.com/waku-org/go-waku"><img src="https://goreportcard.com/badge/github.com/waku-org/go-waku" /></a>
<a href="https://godoc.org/github.com/waku-org/go-waku"><img src="http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square" /></a>
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.19.0-orange.svg?style=flat-square" /></a>
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.20.0-orange.svg?style=flat-square" /></a>
<a href="https://codeclimate.com/github/waku-org/go-waku/maintainability"><img src="https://api.codeclimate.com/v1/badges/426bdff6a339ff4d536b/maintainability" /></a>
<br>
</p>
@ -106,7 +106,7 @@ Thank you for considering to help out with the source code! We welcome contribut
If you'd like to contribute to go-waku, please fork, fix, commit and send a pull request. If you wish to submit more complex changes though, please check up with the core devs first to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.
To build and test this repository, you need:
- [Go](https://golang.org/) (version 1.19 or 1.20)
- [Go](https://golang.org/) (version 1.20)
- [protoc](https://grpc.io/docs/protoc-installation/)
- [protoc-gen-go](https://protobuf.dev/getting-started/gotutorial/#compiling-protocol-buffers)

View File

@ -1,6 +1,6 @@
module basic2
go 1.19
go 1.20
replace github.com/waku-org/go-waku => ../..

View File

@ -1,6 +1,6 @@
module chat2
go 1.19
go 1.20
replace github.com/waku-org/go-waku => ../..

View File

@ -1,6 +1,6 @@
module filter2
go 1.19
go 1.20
replace github.com/waku-org/go-waku => ../..

View File

@ -1,6 +1,6 @@
module noise
go 1.19
go 1.20
replace github.com/waku-org/go-waku => ../..

View File

@ -1,6 +1,6 @@
module rln
go 1.19
go 1.20
replace github.com/waku-org/go-waku => ../..

View File

@ -18,7 +18,7 @@
pkgs = nixpkgsFor.${system};
commit = builtins.substring 0 7 (self.rev or "dirty");
version = builtins.readFile ./VERSION;
in pkgs.buildGo119Module {
in pkgs.buildGo120Module {
name = "go-waku";
src = self;
inherit subPackages;

4
go.mod
View File

@ -1,6 +1,6 @@
module github.com/waku-org/go-waku
go 1.19
go 1.20
replace github.com/ethereum/go-ethereum v1.10.26 => github.com/status-im/go-ethereum v1.10.25-status.4
@ -160,7 +160,7 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0

View File

@ -11,6 +11,7 @@ import (
golog "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p"
"go.uber.org/zap"
"golang.org/x/exp/maps"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/enode"
@ -306,7 +307,8 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) {
func (w *WakuNode) watchMultiaddressChanges(ctx context.Context) {
defer w.wg.Done()
addrs := w.ListenAddresses()
addrsSet := utils.MultiAddrSet(w.ListenAddresses()...)
first := make(chan struct{}, 1)
first <- struct{}{}
for {
@ -314,22 +316,13 @@ func (w *WakuNode) watchMultiaddressChanges(ctx context.Context) {
case <-ctx.Done():
return
case <-first:
w.log.Info("listening", logging.MultiAddrs("multiaddr", addrs...))
addr := maps.Keys(addrsSet)
w.log.Info("listening", logging.MultiAddrs("multiaddr", addr...))
case <-w.addressChangesSub.Out():
newAddrs := w.ListenAddresses()
diff := false
if len(addrs) != len(newAddrs) {
diff = true
} else {
for i := range newAddrs {
if addrs[i].String() != newAddrs[i].String() {
diff = true
break
}
}
}
if diff {
addrs = newAddrs
newAddrs := utils.MultiAddrSet(w.ListenAddresses()...)
if !maps.Equal(addrsSet, newAddrs) {
addrsSet = newAddrs
addrs := maps.Keys(addrsSet)
w.log.Info("listening addresses update received", logging.MultiAddrs("multiaddr", addrs...))
err := w.setupENR(ctx, addrs)
if err != nil {
@ -889,7 +882,6 @@ func (w *WakuNode) findRelayNodes(ctx context.Context) {
}
// Shuffle peers
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(peers), func(i, j int) { peers[i], peers[j] = peers[j], peers[i] })
for _, p := range peers {

View File

@ -7,7 +7,6 @@ import (
crand "crypto/rand"
"encoding/binary"
"fmt"
mrand "math/rand"
"errors"
"strconv"
@ -282,7 +281,7 @@ func generateSecureRandomData(length int) ([]byte, error) {
} else if !validateDataIntegrity(x, length) {
return nil, errors.New("crypto/rand failed to generate secure random data")
}
_, err = mrand.Read(y)
_, err = crand.Read(y)
if err != nil {
return nil, err
} else if !validateDataIntegrity(y, length) {

View File

@ -3,6 +3,7 @@ package payload
import (
"crypto/aes"
"crypto/cipher"
crand "crypto/rand"
mrand "math/rand"
"testing"
@ -84,7 +85,7 @@ func singlePaddingTest(t *testing.T, padSize int) {
Key: keyInfo,
}
_, err = mrand.Read(p.Padding) // nolint: gosec
_, err = crand.Read(p.Padding) // nolint: gosec
require.NoError(t, err)
encodedPayload, err := p.Encode(1)

View File

@ -7,7 +7,6 @@ import (
"math"
"math/rand"
"net"
"time"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
@ -28,7 +27,6 @@ func WithMultiaddress(multiaddrs ...multiaddr.Multiaddr) ENROption {
return func(localnode *enode.LocalNode) (err error) {
// Randomly shuffle multiaddresses
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(multiaddrs), func(i, j int) { multiaddrs[i], multiaddrs[j] = multiaddrs[j], multiaddrs[i] })
// Adding extra multiaddresses. Should probably not exceed the enr max size of 300bytes

View File

@ -16,3 +16,11 @@ func EncapsulatePeerID(peerID peer.ID, addrs ...multiaddr.Multiaddr) []multiaddr
}
return result
}
func MultiAddrSet(addr ...multiaddr.Multiaddr) map[multiaddr.Multiaddr]struct{} {
r := make(map[multiaddr.Multiaddr]struct{})
for _, a := range addr {
r[a] = struct{}{}
}
return r
}