From ee6bda5bccbcefbafc4a5d3b8bf465282de870c7 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 24 Nov 2022 17:27:46 -0400 Subject: [PATCH] feat: add wakuext_listenAddresses --- eth-node/bridge/geth/waku.go | 5 +++++ eth-node/bridge/geth/wakuv2.go | 4 ++++ eth-node/types/waku.go | 2 ++ protocol/messenger_peers.go | 4 ++++ protocol/transport/transport.go | 4 ++++ services/ext/api.go | 4 ++++ wakuv2/waku.go | 9 +++++++++ 7 files changed, 32 insertions(+) diff --git a/eth-node/bridge/geth/waku.go b/eth-node/bridge/geth/waku.go index abff353d3..2158006d8 100644 --- a/eth-node/bridge/geth/waku.go +++ b/eth-node/bridge/geth/waku.go @@ -74,6 +74,11 @@ func (w *gethWakuWrapper) DialPeerByID(peerID string) error { return errors.New("not available in WakuV1") } +// ListenAddresses function only added for compatibility with waku V2 +func (w *gethWakuWrapper) ListenAddresses() ([]string, error) { + return nil, errors.New("not available in WakuV1") +} + // PeerCount function only added for compatibility with waku V2 func (w *gethWakuWrapper) DropPeer(peerID string) error { return errors.New("not available in WakuV1") diff --git a/eth-node/bridge/geth/wakuv2.go b/eth-node/bridge/geth/wakuv2.go index d48c6f98a..84f0f52a5 100644 --- a/eth-node/bridge/geth/wakuv2.go +++ b/eth-node/bridge/geth/wakuv2.go @@ -253,6 +253,10 @@ func (w *gethWakuV2Wrapper) DialPeerByID(peerID string) error { return w.waku.DialPeerByID(peerID) } +func (w *gethWakuV2Wrapper) ListenAddresses() ([]string, error) { + return w.waku.ListenAddresses(), nil +} + func (w *gethWakuV2Wrapper) DropPeer(peerID string) error { return w.waku.DropPeer(peerID) } diff --git a/eth-node/types/waku.go b/eth-node/types/waku.go index 63506e534..aefeac717 100644 --- a/eth-node/types/waku.go +++ b/eth-node/types/waku.go @@ -76,6 +76,8 @@ type Waku interface { // PeerCount PeerCount() int + ListenAddresses() ([]string, error) + Peers() map[string]WakuV2Peer StartDiscV5() error diff --git a/protocol/messenger_peers.go b/protocol/messenger_peers.go index d0b9c6812..eb4dee9ed 100644 --- a/protocol/messenger_peers.go +++ b/protocol/messenger_peers.go @@ -25,3 +25,7 @@ func (m *Messenger) DropPeer(peerID string) error { func (m *Messenger) Peers() map[string]types.WakuV2Peer { return m.transport.Peers() } + +func (m *Messenger) ListenAddresses() ([]string, error) { + return m.transport.ListenAddresses() +} diff --git a/protocol/transport/transport.go b/protocol/transport/transport.go index d34336d2b..7f6b2c60d 100644 --- a/protocol/transport/transport.go +++ b/protocol/transport/transport.go @@ -619,6 +619,10 @@ func (t *Transport) StopDiscV5() error { return t.waku.StopDiscV5() } +func (t *Transport) ListenAddresses() ([]string, error) { + return t.waku.ListenAddresses() +} + func (t *Transport) AddStorePeer(address string) (string, error) { return t.waku.AddStorePeer(address) } diff --git a/services/ext/api.go b/services/ext/api.go index 7b155c9de..3999cc990 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -1163,6 +1163,10 @@ func (api *PublicAPI) Peers() map[string]types.WakuV2Peer { return api.service.messenger.Peers() } +func (api *PublicAPI) ListenAddresses() ([]string, error) { + return api.service.messenger.ListenAddresses() +} + func (api *PublicAPI) ChangeIdentityImageShowTo(showTo settings.ProfilePicturesShowToType) error { err := api.service.accountsDB.SaveSettingField(settings.ProfilePicturesShowTo, showTo) if err != nil { diff --git a/wakuv2/waku.go b/wakuv2/waku.go index 53466172e..e76be321d 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -1125,6 +1125,15 @@ func (w *Waku) Peers() map[string]types.WakuV2Peer { return FormatPeerStats(w.node, w.node.PeerStats()) } +func (w *Waku) ListenAddresses() []string { + addrs := w.node.ListenAddresses() + var result []string + for _, addr := range addrs { + result = append(result, addr.String()) + } + return result +} + func (w *Waku) StartDiscV5() error { if w.node.DiscV5() == nil { return errors.New("discv5 is not setup")