Skip to content

Commit

Permalink
fix: addr update
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Oct 16, 2023
1 parent 2ef7e73 commit dde1138
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion examples/basic2/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module basic2

go 1.19
go 1.20

replace github.com/waku-org/go-waku => ../..

Expand Down
2 changes: 1 addition & 1 deletion examples/chat2/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module chat2

go 1.19
go 1.20

replace github.com/waku-org/go-waku => ../..

Expand Down
2 changes: 1 addition & 1 deletion examples/filter2/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module filter2

go 1.19
go 1.20

replace github.com/waku-org/go-waku => ../..

Expand Down
2 changes: 1 addition & 1 deletion examples/noise/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module noise

go 1.19
go 1.20

replace github.com/waku-org/go-waku => ../..

Expand Down
2 changes: 1 addition & 1 deletion examples/rln/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module rln

go 1.19
go 1.20

replace github.com/waku-org/go-waku => ../..

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
25 changes: 9 additions & 16 deletions waku/v2/node/wakunode2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -304,30 +305,22 @@ 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 {
select {
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 {
Expand Down
8 changes: 8 additions & 0 deletions waku/v2/utils/multiaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit dde1138

Please sign in to comment.