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
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
)
|
|
|
|
|
2020-05-14 07:49:06 +00:00
|
|
|
// Peer represents a remote Waku client with which the local host waku instance exchanges data / messages.
|
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
|
|
|
type Peer interface {
|
|
|
|
// Start performs the handshake and initialize the broadcasting of messages
|
|
|
|
Start() error
|
|
|
|
Stop()
|
|
|
|
// Run start the polling loop
|
|
|
|
Run() error
|
|
|
|
|
|
|
|
// NotifyAboutPowRequirementChange notifies the peer that POW for the host has changed
|
|
|
|
NotifyAboutPowRequirementChange(float64) error
|
|
|
|
// NotifyAboutBloomFilterChange notifies the peer that bloom filter for the host has changed
|
|
|
|
NotifyAboutBloomFilterChange([]byte) error
|
|
|
|
// NotifyAboutTopicInterestChange notifies the peer that topics for the host have changed
|
|
|
|
NotifyAboutTopicInterestChange([]TopicType) error
|
|
|
|
|
|
|
|
// SetPeerTrusted sets the value of trusted, meaning we will
|
|
|
|
// allow p2p messages from them, which is necessary to interact
|
|
|
|
// with mailservers.
|
|
|
|
SetPeerTrusted(bool)
|
|
|
|
// SetRWWriter sets the socket to read/write
|
|
|
|
SetRWWriter(p2p.MsgReadWriter)
|
|
|
|
|
|
|
|
RequestHistoricMessages(*Envelope) error
|
|
|
|
SendHistoricMessageResponse([]byte) error
|
|
|
|
SendP2PMessages([]*Envelope) error
|
|
|
|
SendRawP2PDirect([]rlp.RawValue) error
|
|
|
|
|
2021-08-03 19:27:15 +00:00
|
|
|
SendBundle(bundle []*Envelope) (rst common.Hash, err 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
|
|
|
// Mark marks an envelope known to the peer so that it won't be sent back.
|
|
|
|
Mark(*Envelope)
|
|
|
|
// Marked checks if an envelope is already known to the remote peer.
|
|
|
|
Marked(*Envelope) bool
|
|
|
|
|
|
|
|
ID() []byte
|
|
|
|
IP() net.IP
|
|
|
|
EnodeID() enode.ID
|
|
|
|
|
|
|
|
PoWRequirement() float64
|
|
|
|
BloomFilter() []byte
|
|
|
|
ConfirmationsEnabled() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// WakuHost is the local instance of waku, which both interacts with remote clients
|
|
|
|
// (peers) and local clients (through RPC API)
|
|
|
|
type WakuHost interface {
|
2020-04-29 18:05:09 +00:00
|
|
|
// HandlePeer handles the connection of a new peer
|
|
|
|
HandlePeer(Peer, p2p.MsgReadWriter) 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
|
|
|
// MaxMessageSize returns the maximum accepted message size.
|
|
|
|
MaxMessageSize() uint32
|
|
|
|
// LightClientMode returns whether the host is running in light client mode
|
|
|
|
LightClientMode() bool
|
|
|
|
// Mailserver returns whether the host is running a mailserver
|
|
|
|
Mailserver() bool
|
|
|
|
// LightClientModeConnectionRestricted indicates that connection to light client in light client mode not allowed
|
|
|
|
LightClientModeConnectionRestricted() bool
|
|
|
|
// ConfirmationsEnabled returns true if message confirmations are enabled.
|
|
|
|
ConfirmationsEnabled() bool
|
2020-06-09 07:21:13 +00:00
|
|
|
// PacketRateLimits returns the current rate limits for the host
|
|
|
|
PacketRateLimits() RateLimits
|
|
|
|
// BytesRateLimits returns the current rate limits for the host
|
|
|
|
BytesRateLimits() RateLimits
|
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
|
|
|
// MinPow returns the MinPow for the host
|
|
|
|
MinPow() float64
|
|
|
|
// BloomFilterMode returns whether the host is using bloom filter
|
|
|
|
BloomFilterMode() bool
|
|
|
|
// BloomFilter returns the bloom filter for the host
|
|
|
|
BloomFilter() []byte
|
|
|
|
//TopicInterest returns the topics for the host
|
|
|
|
TopicInterest() []TopicType
|
|
|
|
// IsEnvelopeCached checks if envelope with specific hash has already been received and cached.
|
|
|
|
IsEnvelopeCached(common.Hash) bool
|
|
|
|
// Envelopes returns all the envelopes queued
|
|
|
|
Envelopes() []*Envelope
|
|
|
|
SendEnvelopeEvent(EnvelopeEvent) int
|
|
|
|
// OnNewEnvelopes handles newly received envelopes from a peer
|
|
|
|
OnNewEnvelopes([]*Envelope, Peer) ([]EnvelopeError, error)
|
|
|
|
// OnNewP2PEnvelopes handles envelopes received though the P2P
|
|
|
|
// protocol (i.e from a mailserver in most cases)
|
2020-05-01 18:14:01 +00:00
|
|
|
OnNewP2PEnvelopes([]*Envelope) 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
|
|
|
// OnMessagesResponse handles when the peer receive a message response
|
|
|
|
// from a mailserver
|
|
|
|
OnMessagesResponse(MessagesResponse, Peer) error
|
|
|
|
// OnMessagesRequest handles when the peer receive a message request
|
|
|
|
// this only works if the peer is a mailserver
|
|
|
|
OnMessagesRequest(MessagesRequest, Peer) error
|
2020-05-12 13:05:24 +00:00
|
|
|
// OnDeprecatedMessagesRequest handles when the peer receive a message request
|
2022-07-17 13:37:14 +00:00
|
|
|
// using the *Envelope format. Currently the only production client (status-mobile)
|
2020-05-12 13:05:24 +00:00
|
|
|
// is exclusively using this one.
|
|
|
|
OnDeprecatedMessagesRequest(*Envelope, Peer) 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
|
|
|
OnBatchAcknowledged(common.Hash, Peer) error
|
|
|
|
OnP2PRequestCompleted([]byte, Peer) error
|
|
|
|
}
|