feat: functions to add peers and dial (#2345)

This commit is contained in:
RichΛrd 2021-09-10 13:06:06 -04:00
parent f8cc8b23b2
commit 7d148272e1
7 changed files with 79 additions and 19 deletions

View File

@ -44,12 +44,22 @@ func (w *gethWakuWrapper) PeerCount() int {
} }
// PeerCount function only added for compatibility with waku V2 // PeerCount function only added for compatibility with waku V2
func (w *gethWakuWrapper) AddStorePeer(address string) error { func (w *gethWakuWrapper) AddStorePeer(address string) (string, error) {
return errors.New("not available in WakuV1") return "", errors.New("not available in WakuV1")
} }
// AddRelayPeer function only added for compatibility with waku V2 // AddRelayPeer function only added for compatibility with waku V2
func (w *gethWakuWrapper) AddRelayPeer(address string) error { func (w *gethWakuWrapper) AddRelayPeer(address string) (string, error) {
return "", errors.New("not available in WakuV1")
}
// DialPeer function only added for compatibility with waku V2
func (w *gethWakuWrapper) DialPeer(address string) error {
return errors.New("not available in WakuV1")
}
// DialPeerByID function only added for compatibility with waku V2
func (w *gethWakuWrapper) DialPeerByID(peerID string) error {
return errors.New("not available in WakuV1") return errors.New("not available in WakuV1")
} }

View File

@ -222,11 +222,11 @@ func (w *gethWakuV2Wrapper) RequestHistoricMessagesWithTimeout(peerID []byte, en
return errors.New("DEPRECATED") return errors.New("DEPRECATED")
} }
func (w *gethWakuV2Wrapper) AddStorePeer(address string) error { func (w *gethWakuV2Wrapper) AddStorePeer(address string) (string, error) {
return w.waku.AddStorePeer(address) return w.waku.AddStorePeer(address)
} }
func (w *gethWakuV2Wrapper) AddRelayPeer(address string) error { func (w *gethWakuV2Wrapper) AddRelayPeer(address string) (string, error) {
return w.waku.AddRelayPeer(address) return w.waku.AddRelayPeer(address)
} }
@ -234,6 +234,14 @@ func (w *gethWakuV2Wrapper) Peers() map[string][]string {
return w.waku.Peers() return w.waku.Peers()
} }
func (w *gethWakuV2Wrapper) DialPeer(address string) error {
return w.waku.DialPeer(address)
}
func (w *gethWakuV2Wrapper) DialPeerByID(peerID string) error {
return w.waku.DialPeerByID(peerID)
}
func (w *gethWakuV2Wrapper) DropPeer(peerID string) error { func (w *gethWakuV2Wrapper) DropPeer(peerID string) error {
return w.waku.DropPeer(peerID) return w.waku.DropPeer(peerID)
} }

View File

@ -18,9 +18,13 @@ type Waku interface {
Peers() map[string][]string Peers() map[string][]string
AddStorePeer(address string) error AddStorePeer(address string) (string, error)
AddRelayPeer(address string) error AddRelayPeer(address string) (string, error)
DialPeer(address string) error
DialPeerByID(peerID string) error
DropPeer(peerID string) error DropPeer(peerID string) error

View File

@ -1,13 +1,21 @@
package protocol package protocol
func (m *Messenger) AddStorePeer(address string) error { func (m *Messenger) AddStorePeer(address string) (string, error) {
return m.transport.AddStorePeer(address) return m.transport.AddStorePeer(address)
} }
func (m *Messenger) AddRelayPeer(address string) error { func (m *Messenger) AddRelayPeer(address string) (string, error) {
return m.transport.AddStorePeer(address) return m.transport.AddStorePeer(address)
} }
func (m *Messenger) DialPeer(address string) error {
return m.transport.DialPeer(address)
}
func (m *Messenger) DialPeerByID(peerID string) error {
return m.transport.DialPeerByID(peerID)
}
func (m *Messenger) DropPeer(peerID string) error { func (m *Messenger) DropPeer(peerID string) error {
return m.transport.DropPeer(peerID) return m.transport.DropPeer(peerID)
} }

View File

@ -594,14 +594,22 @@ func PubkeyToHex(key *ecdsa.PublicKey) string {
return types.EncodeHex(crypto.FromECDSAPub(key)) return types.EncodeHex(crypto.FromECDSAPub(key))
} }
func (t *Transport) AddStorePeer(address string) error { func (t *Transport) AddStorePeer(address string) (string, error) {
return t.waku.AddStorePeer(address) return t.waku.AddStorePeer(address)
} }
func (t *Transport) AddRelayPeer(address string) error { func (t *Transport) AddRelayPeer(address string) (string, error) {
return t.waku.AddRelayPeer(address) return t.waku.AddRelayPeer(address)
} }
func (t *Transport) DialPeer(address string) error {
return t.waku.DialPeer(address)
}
func (t *Transport) DialPeerByID(peerID string) error {
return t.waku.DialPeerByID(peerID)
}
func (t *Transport) DropPeer(peerID string) error { func (t *Transport) DropPeer(peerID string) error {
return t.waku.DropPeer(peerID) return t.waku.DropPeer(peerID)
} }

View File

@ -904,14 +904,22 @@ func (api *PublicAPI) BloomFilter() string {
return hexutil.Encode(api.service.messenger.BloomFilter()) return hexutil.Encode(api.service.messenger.BloomFilter())
} }
func (api *PublicAPI) AddStorePeer(address string) error { func (api *PublicAPI) AddStorePeer(address string) (string, error) {
return api.service.messenger.AddStorePeer(address) return api.service.messenger.AddStorePeer(address)
} }
func (api *PublicAPI) AddRelayPeer(address string) error { func (api *PublicAPI) AddRelayPeer(address string) (string, error) {
return api.service.messenger.AddRelayPeer(address) return api.service.messenger.AddRelayPeer(address)
} }
func (api *PublicAPI) DialPeer(address string) error {
return api.service.messenger.DialPeer(address)
}
func (api *PublicAPI) DialPeerByID(peerID string) error {
return api.service.messenger.DialPeerByID(peerID)
}
func (api *PublicAPI) DropPeer(peerID string) error { func (api *PublicAPI) DropPeer(peerID string) error {
return api.service.messenger.DropPeer(peerID) return api.service.messenger.DropPeer(peerID)
} }

View File

@ -722,14 +722,28 @@ func (w *Waku) Peers() map[string][]string {
return FormatPeerStats(w.node.Peers()) return FormatPeerStats(w.node.Peers())
} }
func (w *Waku) AddStorePeer(address string) error { func (w *Waku) AddStorePeer(address string) (string, error) {
_, err := w.node.AddStorePeer(address) peerID, err := w.node.AddStorePeer(address)
return err if err != nil {
return "", err
}
return string(*peerID), nil
} }
func (w *Waku) AddRelayPeer(address string) error { func (w *Waku) AddRelayPeer(address string) (string, error) {
// TODO: peerID, err := w.node.AddRelayPeer(address)
return nil if err != nil {
return "", err
}
return string(*peerID), nil
}
func (w *Waku) DialPeer(address string) error {
return w.node.DialPeer(address)
}
func (w *Waku) DialPeerByID(peerID string) error {
return w.node.DialPeerByID(peer.ID(peerID))
} }
func (w *Waku) DropPeer(peerID string) error { func (w *Waku) DropPeer(peerID string) error {