2020-01-13 19:17:30 +00:00
|
|
|
package gethbridge
|
|
|
|
|
|
|
|
import (
|
2023-01-26 16:29:00 +00:00
|
|
|
"context"
|
2020-01-13 19:17:30 +00:00
|
|
|
"crypto/ecdsa"
|
2021-06-16 20:19:45 +00:00
|
|
|
"errors"
|
2020-01-13 19:17:30 +00:00
|
|
|
"time"
|
|
|
|
|
2023-02-22 21:58:17 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
2024-08-16 18:24:21 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2023-02-22 21:58:17 +00:00
|
|
|
|
2021-11-26 12:30:35 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2024-08-16 18:24:21 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2022-12-09 16:16:21 +00:00
|
|
|
"github.com/status-im/status-go/connection"
|
2020-01-13 19:17:30 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/waku"
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
wakucommon "github.com/status-im/status-go/waku/common"
|
2020-01-13 19:17:30 +00:00
|
|
|
)
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
type GethWakuWrapper struct {
|
2020-01-13 19:17:30 +00:00
|
|
|
waku *waku.Waku
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGethWakuWrapper returns an object that wraps Geth's Waku in a types interface
|
|
|
|
func NewGethWakuWrapper(w *waku.Waku) types.Waku {
|
|
|
|
if w == nil {
|
|
|
|
panic("waku cannot be nil")
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
return &GethWakuWrapper{
|
2020-01-13 19:17:30 +00:00
|
|
|
waku: w,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGethWhisperFrom retrieves the underlying whisper Whisper struct from a wrapped Whisper interface
|
|
|
|
func GetGethWakuFrom(m types.Waku) *waku.Waku {
|
2024-02-06 20:20:19 +00:00
|
|
|
return m.(*GethWakuWrapper).waku
|
2020-01-13 19:17:30 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) PublicWakuAPI() types.PublicWakuAPI {
|
2020-01-13 19:17:30 +00:00
|
|
|
return NewGethPublicWakuAPIWrapper(waku.NewPublicWakuAPI(w.waku))
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) Version() uint {
|
2021-07-21 19:02:50 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2021-08-30 14:57:28 +00:00
|
|
|
// Added for compatibility with waku V2
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) PeerCount() int {
|
2021-08-30 14:57:28 +00:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2021-11-22 13:40:14 +00:00
|
|
|
// Added for compatibility with waku V2
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) StartDiscV5() error {
|
2021-11-22 13:40:14 +00:00
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Added for compatibility with waku V2
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) StopDiscV5() error {
|
2021-11-22 13:40:14 +00:00
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2021-08-30 14:57:28 +00:00
|
|
|
// PeerCount function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) AddStorePeer(address multiaddr.Multiaddr) (peer.ID, error) {
|
2021-09-10 17:06:06 +00:00
|
|
|
return "", errors.New("not available in WakuV1")
|
2021-08-30 14:57:28 +00:00
|
|
|
}
|
|
|
|
|
2023-05-22 21:38:02 +00:00
|
|
|
// SubscribeToPubsubTopic function only added for compatibility with waku V2
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) SubscribeToPubsubTopic(topic string, optPublicKey *ecdsa.PublicKey) error {
|
2023-05-22 21:38:02 +00:00
|
|
|
// not available in WakuV1
|
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) UnsubscribeFromPubsubTopic(topic string) error {
|
2024-01-30 17:56:59 +00:00
|
|
|
// not available in WakuV1
|
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) RetrievePubsubTopicKey(topic string) (*ecdsa.PrivateKey, error) {
|
2023-10-12 19:21:49 +00:00
|
|
|
// not available in WakuV1
|
|
|
|
return nil, errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) StorePubsubTopicKey(topic string, privKey *ecdsa.PrivateKey) error {
|
2023-10-12 19:21:49 +00:00
|
|
|
// not available in WakuV1
|
2023-05-22 21:38:02 +00:00
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) RemovePubsubTopicKey(topic string) error {
|
2024-01-30 17:56:59 +00:00
|
|
|
// not available in WakuV1
|
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2021-08-30 14:57:28 +00:00
|
|
|
// AddRelayPeer function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) AddRelayPeer(address multiaddr.Multiaddr) (peer.ID, error) {
|
2021-09-10 17:06:06 +00:00
|
|
|
return "", errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DialPeer function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) DialPeer(address multiaddr.Multiaddr) error {
|
2021-09-10 17:06:06 +00:00
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DialPeerByID function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) DialPeerByID(peerID peer.ID) error {
|
2021-08-30 14:57:28 +00:00
|
|
|
return errors.New("not available in WakuV1")
|
2022-11-24 21:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListenAddresses function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) ListenAddresses() ([]multiaddr.Multiaddr, error) {
|
2022-11-24 21:27:46 +00:00
|
|
|
return nil, errors.New("not available in WakuV1")
|
2021-08-30 14:57:28 +00:00
|
|
|
}
|
|
|
|
|
2024-07-01 15:37:54 +00:00
|
|
|
func (w *GethWakuWrapper) RelayPeersByTopic(topic string) (*types.PeerList, error) {
|
|
|
|
return nil, errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2024-06-18 19:48:49 +00:00
|
|
|
// ENR function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) ENR() (*enode.Node, error) {
|
|
|
|
return nil, errors.New("not available in WakuV1")
|
2024-06-18 19:48:49 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 14:57:28 +00:00
|
|
|
// PeerCount function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) DropPeer(peerID peer.ID) error {
|
2021-08-30 14:57:28 +00:00
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) SubscribeToConnStatusChanges() (*types.ConnStatusSubscription, error) {
|
2022-01-12 16:02:01 +00:00
|
|
|
return nil, errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2024-08-21 17:45:32 +00:00
|
|
|
func (w *GethWakuWrapper) SetCriteriaForMissingMessageVerification(peerID peer.ID, pubsubTopic string, contentTopics []types.TopicType) error {
|
2024-06-26 18:25:44 +00:00
|
|
|
return errors.New("not available in WakuV1")
|
|
|
|
}
|
|
|
|
|
2021-08-30 14:57:28 +00:00
|
|
|
// Peers function only added for compatibility with waku V2
|
2024-08-16 18:24:21 +00:00
|
|
|
func (w *GethWakuWrapper) Peers() types.PeerStats {
|
|
|
|
p := make(types.PeerStats)
|
2021-08-30 14:57:28 +00:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-01-13 19:17:30 +00:00
|
|
|
// MinPow returns the PoW value required by this node.
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) MinPow() float64 {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.MinPow()
|
|
|
|
}
|
|
|
|
|
2020-11-03 12:42:42 +00:00
|
|
|
// MaxMessageSize returns the MaxMessageSize set
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) MaxMessageSize() uint32 {
|
2020-11-03 12:42:42 +00:00
|
|
|
return w.waku.MaxMessageSize()
|
|
|
|
}
|
|
|
|
|
2020-01-13 19:17:30 +00:00
|
|
|
// BloomFilter returns the aggregated bloom filter for all the topics of interest.
|
|
|
|
// The nodes are required to send only messages that match the advertised bloom filter.
|
|
|
|
// If a message does not match the bloom, it will tantamount to spam, and the peer will
|
|
|
|
// be disconnected.
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) BloomFilter() []byte {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.BloomFilter()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCurrentTime returns current time.
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) GetCurrentTime() time.Time {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.CurrentTime()
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) SubscribeEnvelopeEvents(eventsProxy chan<- types.EnvelopeEvent) types.Subscription {
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
events := make(chan wakucommon.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper
|
2020-01-13 19:17:30 +00:00
|
|
|
go func() {
|
|
|
|
for e := range events {
|
|
|
|
eventsProxy <- *NewWakuEnvelopeEventWrapper(&e)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return NewGethSubscriptionWrapper(w.waku.SubscribeEnvelopeEvents(events))
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error) {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.GetPrivateKey(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddKeyPair imports a asymmetric private key and returns a deterministic identifier.
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) AddKeyPair(key *ecdsa.PrivateKey) (string, error) {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.AddKeyPair(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteKeyPair deletes the key with the specified ID if it exists.
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) DeleteKeyPair(keyID string) bool {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.DeleteKeyPair(keyID)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) AddSymKeyDirect(key []byte) (string, error) {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.AddSymKeyDirect(key)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) AddSymKeyFromPassword(password string) (string, error) {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.AddSymKeyFromPassword(password)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) DeleteSymKey(id string) bool {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.DeleteSymKey(id)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) GetSymKey(id string) ([]byte, error) {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.GetSymKey(id)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) Subscribe(opts *types.SubscriptionOptions) (string, error) {
|
2020-01-13 19:17:30 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
keyAsym *ecdsa.PrivateKey
|
|
|
|
keySym []byte
|
|
|
|
)
|
|
|
|
|
|
|
|
if opts.SymKeyID != "" {
|
|
|
|
keySym, err = w.GetSymKey(opts.SymKeyID)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if opts.PrivateKeyID != "" {
|
|
|
|
keyAsym, err = w.GetPrivateKey(opts.PrivateKeyID)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := w.createFilterWrapper("", keyAsym, keySym, opts.PoW, opts.Topics)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := w.waku.Subscribe(GetWakuFilterFrom(f))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
f.(*wakuFilterWrapper).id = id
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) GetStats() types.StatsSummary {
|
2021-08-03 19:27:15 +00:00
|
|
|
return w.waku.GetStats()
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) GetFilter(id string) types.Filter {
|
2020-01-13 19:17:30 +00:00
|
|
|
return NewWakuFilterWrapper(w.waku.GetFilter(id), id)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) Unsubscribe(ctx context.Context, id string) error {
|
2020-01-13 19:17:30 +00:00
|
|
|
return w.waku.Unsubscribe(id)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) UnsubscribeMany(ids []string) error {
|
2021-01-14 22:15:13 +00:00
|
|
|
return w.waku.UnsubscribeMany(ids)
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) createFilterWrapper(id string, keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, topics [][]byte) (types.Filter, error) {
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
return NewWakuFilterWrapper(&wakucommon.Filter{
|
2020-01-13 19:17:30 +00:00
|
|
|
KeyAsym: keyAsym,
|
|
|
|
KeySym: keySym,
|
|
|
|
PoW: pow,
|
|
|
|
AllowP2P: true,
|
|
|
|
Topics: topics,
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
Messages: wakucommon.NewMemoryMessageStore(),
|
2020-01-13 19:17:30 +00:00
|
|
|
}, id), nil
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) SendMessagesRequest(peerID []byte, r types.MessagesRequest) error {
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
return w.waku.SendMessagesRequest(peerID, wakucommon.MessagesRequest{
|
2020-01-13 19:17:30 +00:00
|
|
|
ID: r.ID,
|
|
|
|
From: r.From,
|
|
|
|
To: r.To,
|
|
|
|
Limit: r.Limit,
|
|
|
|
Cursor: r.Cursor,
|
|
|
|
Bloom: r.Bloom,
|
2023-05-22 21:38:02 +00:00
|
|
|
Topics: r.ContentTopics,
|
2020-01-13 19:17:30 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestHistoricMessages sends a message with p2pRequestCode to a specific peer,
|
|
|
|
// which is known to implement MailServer interface, and is supposed to process this
|
|
|
|
// request and respond with a number of peer-to-peer messages (possibly expired),
|
|
|
|
// which are not supposed to be forwarded any further.
|
|
|
|
// The whisper protocol is agnostic of the format and contents of envelope.
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) RequestHistoricMessagesWithTimeout(peerID []byte, envelope types.Envelope, timeout time.Duration) error {
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
return w.waku.RequestHistoricMessagesWithTimeout(peerID, envelope.Unwrap().(*wakucommon.Envelope), timeout)
|
2020-01-13 19:17:30 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) ProcessingP2PMessages() bool {
|
2021-11-26 12:30:35 +00:00
|
|
|
return w.waku.ProcessingP2PMessages()
|
|
|
|
}
|
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) MarkP2PMessageAsProcessed(hash common.Hash) {
|
2021-11-26 12:30:35 +00:00
|
|
|
w.waku.MarkP2PMessageAsProcessed(hash)
|
|
|
|
}
|
|
|
|
|
2024-07-30 18:28:27 +00:00
|
|
|
func (w *GethWakuWrapper) RequestStoreMessages(ctx context.Context, peerID []byte, r types.MessagesRequest, processEnvelopes bool) (types.StoreRequestCursor, int, error) {
|
2023-12-15 19:50:12 +00:00
|
|
|
return nil, 0, errors.New("not implemented")
|
2021-06-16 20:19:45 +00:00
|
|
|
}
|
2023-12-15 16:16:18 +00:00
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) ConnectionChanged(_ connection.State) {}
|
2021-06-16 20:19:45 +00:00
|
|
|
|
2024-02-06 20:20:19 +00:00
|
|
|
func (w *GethWakuWrapper) ClearEnvelopesCache() {
|
2024-01-30 13:43:34 +00:00
|
|
|
w.waku.ClearEnvelopesCache()
|
|
|
|
}
|
|
|
|
|
2020-01-13 19:17:30 +00:00
|
|
|
type wakuFilterWrapper struct {
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
filter *wakucommon.Filter
|
2020-01-13 19:17:30 +00:00
|
|
|
id string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewWakuFilterWrapper returns an object that wraps Geth's Filter in a types interface
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
func NewWakuFilterWrapper(f *wakucommon.Filter, id string) types.Filter {
|
2020-01-13 19:17:30 +00:00
|
|
|
if f.Messages == nil {
|
|
|
|
panic("Messages should not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &wakuFilterWrapper{
|
|
|
|
filter: f,
|
|
|
|
id: id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWakuFilterFrom retrieves the underlying whisper Filter struct from a wrapped Filter interface
|
Move networking code for waku under `v0` namespace
Why make the change?
As discussed previously, the way we will move across versions is to maintain completely separate
codebases and eventually remove those that are not supported anymore.
This has the drawback of some code duplication, but the advantage is that is more
explicit what each version requires, and changes in one version will not
impact the other, so we won't pile up backward compatible code.
This is the same strategy used by `whisper` in go ethereum and is influenced by
https://www.youtube.com/watch?v=oyLBGkS5ICk .
All the code that is used for the networking protocol is now under `v0/`.
Some of the common parts might still be refactored out.
The main namespace `waku` deals with `host`->`waku` interactions (through RPC),
while `v0` deals with `waku`->`remote-waku` interactions.
In order to support `v1`, the namespace `v0` will be copied over, and changed to
support `v1`. Once `v0` will be not used anymore, the whole namespace will be removed.
This PR does not actually implement `v1`, I'd rather get things looked over to
make sure the structure is what we would like before implementing the changes.
What has changed?
- Moved all code for the common parts under `waku/common/` namespace
- Moved code used for bloomfilters in `waku/common/bloomfilter.go`
- Removed all version specific code from `waku/common/const` (`ProtocolVersion`, status-codes etc)
- Added interfaces for `WakuHost` and `Peer` under `waku/common/protocol.go`
Things still to do
Some tests in `waku/` are still testing by stubbing components of a particular version (`v0`).
I started moving those tests to instead of stubbing using the actual component, which increases
the testing surface. Some other tests that can't be easily ported should be likely moved under
`v0` instead. Ideally no version specif code should be exported from a version namespace (for
example the various codes, as those might change across versions). But this will be a work-in-progress.
Some code that will be common in `v0`/`v1` could still be extract to avoid duplication, and duplicated only
when implementations diverge across versions.
2020-04-21 12:40:30 +00:00
|
|
|
func GetWakuFilterFrom(f types.Filter) *wakucommon.Filter {
|
2020-01-13 19:17:30 +00:00
|
|
|
return f.(*wakuFilterWrapper).filter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the filter ID
|
|
|
|
func (w *wakuFilterWrapper) ID() string {
|
|
|
|
return w.id
|
|
|
|
}
|
2024-06-11 07:45:01 +00:00
|
|
|
|
|
|
|
func (w *GethWakuWrapper) ConfirmMessageDelivered(hashes []common.Hash) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *GethWakuWrapper) SetStorePeerID(peerID peer.ID) {
|
|
|
|
}
|
2024-08-01 03:27:43 +00:00
|
|
|
|
|
|
|
func (w *GethWakuWrapper) PeerID() peer.ID {
|
|
|
|
panic("not implemented")
|
|
|
|
}
|