Integrate Nimbus status-protocol-go
This commit is contained in:
parent
c199c8f342
commit
2dd74da23d
|
@ -14,12 +14,12 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
|
|
||||||
"github.com/status-im/status-go/account/generator"
|
"github.com/status-im/status-go/account/generator"
|
||||||
"github.com/status-im/status-go/extkeys"
|
"github.com/status-im/status-go/extkeys"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// errors
|
// errors
|
||||||
|
@ -325,7 +325,7 @@ func (m *Manager) ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, password
|
||||||
return address, "", err
|
return address, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
pubKey = hexutil.Encode(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
|
pubKey = statusproto.EncodeHex(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ func (m *Manager) importExtendedKey(keyPurpose extkeys.KeyPurpose, extKey *extke
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return address, "", err
|
return address, "", err
|
||||||
}
|
}
|
||||||
pubKey = hexutil.Encode(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
|
pubKey = statusproto.EncodeHex(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateAddress() (address, pubKey, privKey string, err error) {
|
func CreateAddress() (address, pubKey, privKey string, err error) {
|
||||||
|
@ -15,8 +15,8 @@ func CreateAddress() (address, pubKey, privKey string, err error) {
|
||||||
pubKeyBytes := crypto.FromECDSAPub(&key.PublicKey)
|
pubKeyBytes := crypto.FromECDSAPub(&key.PublicKey)
|
||||||
addressBytes := crypto.PubkeyToAddress(key.PublicKey)
|
addressBytes := crypto.PubkeyToAddress(key.PublicKey)
|
||||||
|
|
||||||
privKey = hexutil.Encode(privKeyBytes)
|
privKey = statusproto.EncodeHex(privKeyBytes)
|
||||||
pubKey = hexutil.Encode(pubKeyBytes)
|
pubKey = statusproto.EncodeHex(pubKeyBytes)
|
||||||
address = addressBytes.Hex()
|
address = addressBytes.Hex()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -3,9 +3,9 @@ package generator
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/status-im/status-go/extkeys"
|
"github.com/status-im/status-go/extkeys"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type account struct {
|
type account struct {
|
||||||
|
@ -14,7 +14,7 @@ type account struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *account) toAccountInfo() AccountInfo {
|
func (a *account) toAccountInfo() AccountInfo {
|
||||||
publicKeyHex := hexutil.Encode(crypto.FromECDSAPub(&a.privateKey.PublicKey))
|
publicKeyHex := statusproto.EncodeHex(crypto.FromECDSAPub(&a.privateKey.PublicKey))
|
||||||
addressHex := crypto.PubkeyToAddress(a.privateKey.PublicKey).Hex()
|
addressHex := crypto.PubkeyToAddress(a.privateKey.PublicKey).Hex()
|
||||||
|
|
||||||
return AccountInfo{
|
return AccountInfo{
|
||||||
|
|
|
@ -3,11 +3,11 @@ package account
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
"github.com/status-im/status-go/account/generator"
|
"github.com/status-im/status-go/account/generator"
|
||||||
"github.com/status-im/status-go/extkeys"
|
"github.com/status-im/status-go/extkeys"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OnboardingAccount is returned during onboarding and contains its ID and the mnemonic to re-generate the same account Info keys.
|
// OnboardingAccount is returned during onboarding and contains its ID and the mnemonic to re-generate the same account Info keys.
|
||||||
|
@ -107,7 +107,7 @@ func (o *Onboarding) deriveAccount(masterExtendedKey *extkeys.ExtendedKey, purpo
|
||||||
|
|
||||||
privateKeyECDSA := extendedKey.ToECDSA()
|
privateKeyECDSA := extendedKey.ToECDSA()
|
||||||
address := crypto.PubkeyToAddress(privateKeyECDSA.PublicKey)
|
address := crypto.PubkeyToAddress(privateKeyECDSA.PublicKey)
|
||||||
publicKeyHex := hexutil.Encode(crypto.FromECDSAPub(&privateKeyECDSA.PublicKey))
|
publicKeyHex := statusproto.EncodeHex(crypto.FromECDSAPub(&privateKeyECDSA.PublicKey))
|
||||||
|
|
||||||
return address.Hex(), publicKeyHex, nil
|
return address.Hex(), publicKeyHex, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ import (
|
||||||
"github.com/status-im/status-go/services/wallet"
|
"github.com/status-im/status-go/services/wallet"
|
||||||
"github.com/status-im/status-go/signal"
|
"github.com/status-im/status-go/signal"
|
||||||
"github.com/status-im/status-go/transactions"
|
"github.com/status-im/status-go/transactions"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -76,7 +77,7 @@ type StatusBackend struct {
|
||||||
allowAllRPC bool // used only for tests, disables api method restrictions
|
allowAllRPC bool // used only for tests, disables api method restrictions
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStatusBackend create a new NewStatusBackend instance
|
// NewStatusBackend create a new StatusBackend instance
|
||||||
func NewStatusBackend() *StatusBackend {
|
func NewStatusBackend() *StatusBackend {
|
||||||
defer log.Info("Status backend initialized", "version", params.Version, "commit", params.GitCommit)
|
defer log.Info("Status backend initialized", "version", params.Version, "commit", params.GitCommit)
|
||||||
|
|
||||||
|
@ -153,7 +154,7 @@ func (b *StatusBackend) GetAccounts() ([]multiaccounts.Account, error) {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
defer b.mu.Unlock()
|
||||||
if b.multiaccountsDB == nil {
|
if b.multiaccountsDB == nil {
|
||||||
return nil, errors.New("accoutns db wasn't initialized")
|
return nil, errors.New("accounts db wasn't initialized")
|
||||||
}
|
}
|
||||||
return b.multiaccountsDB.GetAccounts()
|
return b.multiaccountsDB.GetAccounts()
|
||||||
}
|
}
|
||||||
|
@ -162,7 +163,7 @@ func (b *StatusBackend) SaveAccount(account multiaccounts.Account) error {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
defer b.mu.Unlock()
|
||||||
if b.multiaccountsDB == nil {
|
if b.multiaccountsDB == nil {
|
||||||
return errors.New("accoutns db wasn't initialized")
|
return errors.New("accounts db wasn't initialized")
|
||||||
}
|
}
|
||||||
return b.multiaccountsDB.SaveAccount(account)
|
return b.multiaccountsDB.SaveAccount(account)
|
||||||
}
|
}
|
||||||
|
@ -1021,6 +1022,6 @@ func (b *StatusBackend) SignHash(hexEncodedHash string) (string, error) {
|
||||||
return "", fmt.Errorf("SignHash: could not sign the hash: %v", err)
|
return "", fmt.Errorf("SignHash: could not sign the hash: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
hexEncodedSignature := hexutil.Encode(signature)
|
hexEncodedSignature := statusproto.EncodeHex(signature)
|
||||||
return hexEncodedSignature, nil
|
return hexEncodedSignature, nil
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -31,7 +31,7 @@ require (
|
||||||
github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a
|
github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a
|
||||||
github.com/status-im/migrate/v4 v4.6.2-status.2
|
github.com/status-im/migrate/v4 v4.6.2-status.2
|
||||||
github.com/status-im/rendezvous v1.3.0
|
github.com/status-im/rendezvous v1.3.0
|
||||||
github.com/status-im/status-protocol-go v0.5.1
|
github.com/status-im/status-protocol-go v0.5.2
|
||||||
github.com/status-im/tcp-shaker v0.0.0-20191114194237-215893130501
|
github.com/status-im/tcp-shaker v0.0.0-20191114194237-215893130501
|
||||||
github.com/status-im/whisper v1.6.1
|
github.com/status-im/whisper v1.6.1
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
|
|
7
go.sum
7
go.sum
|
@ -416,6 +416,9 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
|
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
|
||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
github.com/mattn/go-pointer v0.0.0-20190911064623-a0a44394634f h1:QTRRO+ozoYgT3CQRIzNVYJRU3DB8HRnkZv6mr4ISmMA=
|
||||||
|
github.com/mattn/go-pointer v0.0.0-20190911064623-a0a44394634f/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
|
||||||
|
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
|
||||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
|
@ -596,8 +599,8 @@ github.com/status-im/migrate/v4 v4.6.2-status.2 h1:SdC+sMDl/aI7vUlwD2qj2p7KsK4T6
|
||||||
github.com/status-im/migrate/v4 v4.6.2-status.2/go.mod h1:c/kc90n47GZu/58nnz1OMLTf7uE4Da4gZP5qmU+A/v8=
|
github.com/status-im/migrate/v4 v4.6.2-status.2/go.mod h1:c/kc90n47GZu/58nnz1OMLTf7uE4Da4gZP5qmU+A/v8=
|
||||||
github.com/status-im/rendezvous v1.3.0 h1:7RK/MXXW+tlm0asKm1u7Qp7Yni6AO29a7j8+E4Lbjg4=
|
github.com/status-im/rendezvous v1.3.0 h1:7RK/MXXW+tlm0asKm1u7Qp7Yni6AO29a7j8+E4Lbjg4=
|
||||||
github.com/status-im/rendezvous v1.3.0/go.mod h1:+hzjuP+j/XzLPeF6E50b88pWOTLdTcwjvNYt+Gh1W1s=
|
github.com/status-im/rendezvous v1.3.0/go.mod h1:+hzjuP+j/XzLPeF6E50b88pWOTLdTcwjvNYt+Gh1W1s=
|
||||||
github.com/status-im/status-protocol-go v0.5.1 h1:mCqYJrL/zWMScFjSLdboL5WANLn01Cz8bAxBwPxww7k=
|
github.com/status-im/status-protocol-go v0.5.2 h1:C6m6N6TLzJbuJmV4u8iNzs0cj+Q1CfBWdS0LZLtGkN8=
|
||||||
github.com/status-im/status-protocol-go v0.5.1/go.mod h1:KR/eihnrUq2dZegUOVjrA/1poSNhasA/o82VYyRgeB0=
|
github.com/status-im/status-protocol-go v0.5.2/go.mod h1:L5/7fKnycEBOiLm3TuCHDUNcn0kNNhSNsYLkqbUQngg=
|
||||||
github.com/status-im/tcp-shaker v0.0.0-20191114194237-215893130501 h1:oa0KU5jJRNtXaM/P465MhvSFo/HM2O8qi2DDuPcd7ro=
|
github.com/status-im/tcp-shaker v0.0.0-20191114194237-215893130501 h1:oa0KU5jJRNtXaM/P465MhvSFo/HM2O8qi2DDuPcd7ro=
|
||||||
github.com/status-im/tcp-shaker v0.0.0-20191114194237-215893130501/go.mod h1:RYo/itke1oU5k/6sj9DNM3QAwtE5rZSgg5JnkOv83hk=
|
github.com/status-im/tcp-shaker v0.0.0-20191114194237-215893130501/go.mod h1:RYo/itke1oU5k/6sj9DNM3QAwtE5rZSgg5JnkOv83hk=
|
||||||
github.com/status-im/whisper v1.5.2 h1:26NgiKusmPic38eQdtXnaY+iaQ/LuQ3Dh0kCGYT/Uxs=
|
github.com/status-im/whisper v1.5.2 h1:26NgiKusmPic38eQdtXnaY+iaQ/LuQ3Dh0kCGYT/Uxs=
|
||||||
|
|
|
@ -24,20 +24,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/status-im/status-go/account"
|
"github.com/status-im/status-go/account"
|
||||||
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||||
"github.com/status-im/status-go/signal"
|
"github.com/status-im/status-go/signal"
|
||||||
. "github.com/status-im/status-go/t/utils" //nolint: golint
|
. "github.com/status-im/status-go/t/utils" //nolint: golint
|
||||||
"github.com/status-im/status-go/transactions"
|
"github.com/status-im/status-go/transactions"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/event"
|
|
||||||
)
|
|
||||||
import (
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const initJS = `
|
const initJS = `
|
||||||
|
@ -463,7 +461,7 @@ func testLoginWithKeycard(t *testing.T, feed *event.Feed) bool { //nolint: gocyc
|
||||||
t.Errorf("whisper service not running: %v", err)
|
t.Errorf("whisper service not running: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
chatPubKeyHex := hexutil.Encode(crypto.FromECDSAPub(&chatPrivKey.PublicKey))
|
chatPubKeyHex := statusproto.EncodeHex(crypto.FromECDSAPub(&chatPrivKey.PublicKey))
|
||||||
if whisperService.HasKeyPair(chatPubKeyHex) {
|
if whisperService.HasKeyPair(chatPubKeyHex) {
|
||||||
t.Error("identity already present in whisper")
|
t.Error("identity already present in whisper")
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -5,8 +5,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
whisper "github.com/status-im/whisper/whisperv6"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
|
@ -117,8 +118,8 @@ func testMessagesCount(t *testing.T, expected int, s *WMailServer) {
|
||||||
func countMessages(t *testing.T, db DB) int {
|
func countMessages(t *testing.T, db DB) int {
|
||||||
var (
|
var (
|
||||||
count int
|
count int
|
||||||
zero common.Hash
|
zero statusproto.Hash
|
||||||
emptyTopic whisper.TopicType
|
emptyTopic whispertypes.TopicType
|
||||||
)
|
)
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
|
@ -4,14 +4,14 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DBKeyLength is a size of the envelope key.
|
// DBKeyLength is a size of the envelope key.
|
||||||
DBKeyLength = common.HashLength + timestampLength + whisper.TopicLength
|
DBKeyLength = statusproto.HashLength + timestampLength + whispertypes.TopicLength
|
||||||
CursorLength = common.HashLength + timestampLength
|
CursorLength = statusproto.HashLength + timestampLength
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -30,12 +30,12 @@ func (k *DBKey) Bytes() []byte {
|
||||||
return k.raw
|
return k.raw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *DBKey) Topic() whisper.TopicType {
|
func (k *DBKey) Topic() whispertypes.TopicType {
|
||||||
return whisper.BytesToTopic(k.raw[timestampLength+common.HashLength:])
|
return whispertypes.BytesToTopic(k.raw[timestampLength+statusproto.HashLength:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *DBKey) EnvelopeHash() common.Hash {
|
func (k *DBKey) EnvelopeHash() statusproto.Hash {
|
||||||
return common.BytesToHash(k.raw[timestampLength : common.HashLength+timestampLength])
|
return statusproto.BytesToHash(k.raw[timestampLength : statusproto.HashLength+timestampLength])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *DBKey) Cursor() []byte {
|
func (k *DBKey) Cursor() []byte {
|
||||||
|
@ -44,11 +44,11 @@ func (k *DBKey) Cursor() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDBKey creates a new DBKey with the given values.
|
// NewDBKey creates a new DBKey with the given values.
|
||||||
func NewDBKey(timestamp uint32, topic whisper.TopicType, h common.Hash) *DBKey {
|
func NewDBKey(timestamp uint32, topic whispertypes.TopicType, h statusproto.Hash) *DBKey {
|
||||||
var k DBKey
|
var k DBKey
|
||||||
k.raw = make([]byte, DBKeyLength)
|
k.raw = make([]byte, DBKeyLength)
|
||||||
binary.BigEndian.PutUint32(k.raw, timestamp)
|
binary.BigEndian.PutUint32(k.raw, timestamp)
|
||||||
copy(k.raw[timestampLength:], h[:])
|
copy(k.raw[timestampLength:], h[:])
|
||||||
copy(k.raw[timestampLength+common.HashLength:], topic[:])
|
copy(k.raw[timestampLength+statusproto.HashLength:], topic[:])
|
||||||
return &k
|
return &k
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package mailserver
|
package mailserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewDBKey(t *testing.T) {
|
func TestNewDBKey(t *testing.T) {
|
||||||
topic := whisper.BytesToTopic([]byte{0x01, 0x02, 0x03, 0x04})
|
topic := whispertypes.BytesToTopic([]byte{0x01, 0x02, 0x03, 0x04})
|
||||||
|
|
||||||
hash := common.BytesToHash([]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32})
|
hash := statusproto.BytesToHash([]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32})
|
||||||
dbKey := NewDBKey(0xabcdef12, topic, hash)
|
dbKey := NewDBKey(0xabcdef12, topic, hash)
|
||||||
expected := []byte{0xab, 0xcd, 0xef, 0x12, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32, 0x01, 0x02, 0x03, 0x04}
|
expected := []byte{0xab, 0xcd, 0xef, 0x12, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32, 0x01, 0x02, 0x03, 0x04}
|
||||||
require.Equal(t, expected, dbKey.Bytes())
|
require.Equal(t, expected, dbKey.Bytes())
|
||||||
|
|
|
@ -30,6 +30,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/status-im/status-go/params"
|
"github.com/status-im/status-go/params"
|
||||||
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
whisper "github.com/status-im/whisper/whisperv6"
|
||||||
|
|
||||||
prom "github.com/prometheus/client_golang/prometheus"
|
prom "github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -197,7 +199,7 @@ func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
requestID := request.Hash()
|
requestID := statusproto.Hash(request.Hash())
|
||||||
peerID := peerIDString(peer)
|
peerID := peerIDString(peer)
|
||||||
|
|
||||||
log.Info("[mailserver:DeliverMail] delivering mail",
|
log.Info("[mailserver:DeliverMail] delivering mail",
|
||||||
|
@ -336,7 +338,7 @@ func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope)
|
||||||
"last", lastEnvelopeHash,
|
"last", lastEnvelopeHash,
|
||||||
"next", nextPageCursor)
|
"next", nextPageCursor)
|
||||||
|
|
||||||
if err := s.sendHistoricMessageResponse(peer, request.Hash(), lastEnvelopeHash, nextPageCursor); err != nil {
|
if err := s.sendHistoricMessageResponse(peer, requestID, lastEnvelopeHash, nextPageCursor); err != nil {
|
||||||
deliveryFailuresCounter.WithLabelValues("historic_msg_resp").Inc()
|
deliveryFailuresCounter.WithLabelValues("historic_msg_resp").Inc()
|
||||||
log.Error("[mailserver:DeliverMail] error sending historic message response",
|
log.Error("[mailserver:DeliverMail] error sending historic message response",
|
||||||
"err", err,
|
"err", err,
|
||||||
|
@ -354,7 +356,7 @@ func (s *WMailServer) Deliver(peer *whisper.Peer, r whisper.MessagesRequest) {
|
||||||
deliveryAttemptsCounter.Inc()
|
deliveryAttemptsCounter.Inc()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
requestIDHash = common.BytesToHash(r.ID)
|
requestIDHash = statusproto.BytesToHash(r.ID)
|
||||||
requestIDStr = requestIDHash.String()
|
requestIDStr = requestIDHash.String()
|
||||||
peerID = peerIDString(peer)
|
peerID = peerIDString(peer)
|
||||||
err error
|
err error
|
||||||
|
@ -590,8 +592,8 @@ func (s *WMailServer) exceedsPeerRequests(peer []byte) bool {
|
||||||
|
|
||||||
func (s *WMailServer) createIterator(lower, upper uint32, cursor []byte, bloom []byte, limit uint32) (Iterator, error) {
|
func (s *WMailServer) createIterator(lower, upper uint32, cursor []byte, bloom []byte, limit uint32) (Iterator, error) {
|
||||||
var (
|
var (
|
||||||
emptyHash common.Hash
|
emptyHash statusproto.Hash
|
||||||
emptyTopic whisper.TopicType
|
emptyTopic whispertypes.TopicType
|
||||||
ku, kl *DBKey
|
ku, kl *DBKey
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -618,7 +620,7 @@ func (s *WMailServer) processRequestInBundles(
|
||||||
requestID string,
|
requestID string,
|
||||||
output chan<- []rlp.RawValue,
|
output chan<- []rlp.RawValue,
|
||||||
cancel <-chan struct{},
|
cancel <-chan struct{},
|
||||||
) ([]byte, common.Hash) {
|
) ([]byte, statusproto.Hash) {
|
||||||
timer := prom.NewTimer(requestsInBundlesDuration)
|
timer := prom.NewTimer(requestsInBundlesDuration)
|
||||||
defer timer.ObserveDuration()
|
defer timer.ObserveDuration()
|
||||||
|
|
||||||
|
@ -629,7 +631,7 @@ func (s *WMailServer) processRequestInBundles(
|
||||||
processedEnvelopes int
|
processedEnvelopes int
|
||||||
processedEnvelopesSize int64
|
processedEnvelopesSize int64
|
||||||
nextCursor []byte
|
nextCursor []byte
|
||||||
lastEnvelopeHash common.Hash
|
lastEnvelopeHash statusproto.Hash
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Info("[mailserver:processRequestInBundles] processing request",
|
log.Info("[mailserver:processRequestInBundles] processing request",
|
||||||
|
@ -758,14 +760,14 @@ func (s *WMailServer) sendRawEnvelopes(peer *whisper.Peer, envelopes []rlp.RawVa
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WMailServer) sendHistoricMessageResponse(peer *whisper.Peer, requestID, lastEnvelopeHash common.Hash, cursor []byte) error {
|
func (s *WMailServer) sendHistoricMessageResponse(peer *whisper.Peer, requestID, lastEnvelopeHash statusproto.Hash, cursor []byte) error {
|
||||||
payload := whisper.CreateMailServerRequestCompletedPayload(requestID, lastEnvelopeHash, cursor)
|
payload := whisper.CreateMailServerRequestCompletedPayload(common.Hash(requestID), common.Hash(lastEnvelopeHash), cursor)
|
||||||
return s.w.SendHistoricMessageResponse(peer, payload)
|
return s.w.SendHistoricMessageResponse(peer, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this method doesn't return an error because it is already in the error handling chain
|
// this method doesn't return an error because it is already in the error handling chain
|
||||||
func (s *WMailServer) trySendHistoricMessageErrorResponse(peer *whisper.Peer, requestID common.Hash, errorToReport error) {
|
func (s *WMailServer) trySendHistoricMessageErrorResponse(peer *whisper.Peer, requestID statusproto.Hash, errorToReport error) {
|
||||||
payload := whisper.CreateMailServerRequestFailedPayload(requestID, errorToReport)
|
payload := whisper.CreateMailServerRequestFailedPayload(common.Hash(requestID), errorToReport)
|
||||||
|
|
||||||
err := s.w.SendHistoricMessageResponse(peer, payload)
|
err := s.w.SendHistoricMessageResponse(peer, payload)
|
||||||
// if we can't report an error, probably something is wrong with p2p connection,
|
// if we can't report an error, probably something is wrong with p2p connection,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type DB interface {
|
type DB interface {
|
||||||
Close() error
|
Close() error
|
||||||
// SaveEnvelope stores an envelope
|
// SaveEnvelope stores an envelope
|
||||||
SaveEnvelope(*whisper.Envelope) error
|
SaveEnvelope(*whisper.Envelope) error // TODO: Migrate to whispertypes.Envelope
|
||||||
// GetEnvelope returns an rlp encoded envelope from the datastore
|
// GetEnvelope returns an rlp encoded envelope from the datastore
|
||||||
GetEnvelope(*DBKey) ([]byte, error)
|
GetEnvelope(*DBKey) ([]byte, error)
|
||||||
// Prune removes envelopes older than time
|
// Prune removes envelopes older than time
|
||||||
|
|
|
@ -2,16 +2,18 @@ package mailserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/status-im/status-go/params"
|
"github.com/status-im/status-go/params"
|
||||||
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
whisper "github.com/status-im/whisper/whisperv6"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
"github.com/syndtr/goleveldb/leveldb/errors"
|
"github.com/syndtr/goleveldb/leveldb/errors"
|
||||||
"github.com/syndtr/goleveldb/leveldb/iterator"
|
"github.com/syndtr/goleveldb/leveldb/iterator"
|
||||||
"github.com/syndtr/goleveldb/leveldb/util"
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LevelDB struct {
|
type LevelDB struct {
|
||||||
|
@ -46,9 +48,9 @@ func (i *LevelDBIterator) GetEnvelope(bloom []byte) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
envelopeBloom = whisper.TopicToBloom(key.Topic())
|
envelopeBloom = whispertypes.TopicToBloom(key.Topic())
|
||||||
}
|
}
|
||||||
if !whisper.BloomFilterMatch(bloom, envelopeBloom) {
|
if !whispertypes.BloomFilterMatch(bloom, envelopeBloom) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return rawValue, nil
|
return rawValue, nil
|
||||||
|
@ -88,8 +90,8 @@ func (db *LevelDB) GetEnvelope(key *DBKey) ([]byte, error) {
|
||||||
func (db *LevelDB) Prune(t time.Time, batchSize int) (int, error) {
|
func (db *LevelDB) Prune(t time.Time, batchSize int) (int, error) {
|
||||||
defer recoverLevelDBPanics("Prune")
|
defer recoverLevelDBPanics("Prune")
|
||||||
|
|
||||||
var zero common.Hash
|
var zero statusproto.Hash
|
||||||
var emptyTopic whisper.TopicType
|
var emptyTopic whispertypes.TopicType
|
||||||
kl := NewDBKey(0, emptyTopic, zero)
|
kl := NewDBKey(0, emptyTopic, zero)
|
||||||
ku := NewDBKey(uint32(t.Unix()), emptyTopic, zero)
|
ku := NewDBKey(uint32(t.Unix()), emptyTopic, zero)
|
||||||
query := CursorQuery{
|
query := CursorQuery{
|
||||||
|
@ -138,7 +140,7 @@ func (db *LevelDB) Prune(t time.Time, batchSize int) (int, error) {
|
||||||
func (db *LevelDB) SaveEnvelope(env *whisper.Envelope) error {
|
func (db *LevelDB) SaveEnvelope(env *whisper.Envelope) error {
|
||||||
defer recoverLevelDBPanics("SaveEnvelope")
|
defer recoverLevelDBPanics("SaveEnvelope")
|
||||||
|
|
||||||
key := NewDBKey(env.Expiry-env.TTL, env.Topic, env.Hash())
|
key := NewDBKey(env.Expiry-env.TTL, whispertypes.TopicType(env.Topic), statusproto.Hash(env.Hash()))
|
||||||
rawEnvelope, err := rlp.EncodeToBytes(env)
|
rawEnvelope, err := rlp.EncodeToBytes(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("rlp.EncodeToBytes failed: %s", err))
|
log.Error(fmt.Sprintf("rlp.EncodeToBytes failed: %s", err))
|
||||||
|
|
|
@ -9,13 +9,14 @@ import (
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"github.com/status-im/migrate/v4"
|
"github.com/status-im/migrate/v4"
|
||||||
"github.com/status-im/migrate/v4/database/postgres"
|
"github.com/status-im/migrate/v4/database/postgres"
|
||||||
"github.com/status-im/migrate/v4/source/go_bindata"
|
bindata "github.com/status-im/migrate/v4/source/go_bindata"
|
||||||
"github.com/status-im/status-go/mailserver/migrations"
|
"github.com/status-im/status-go/mailserver/migrations"
|
||||||
"github.com/status-im/status-go/params"
|
"github.com/status-im/status-go/params"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
whisper "github.com/status-im/whisper/whisperv6"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -158,8 +159,8 @@ func (i *PostgresDB) GetEnvelope(key *DBKey) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *PostgresDB) Prune(t time.Time, batch int) (int, error) {
|
func (i *PostgresDB) Prune(t time.Time, batch int) (int, error) {
|
||||||
var zero common.Hash
|
var zero statusproto.Hash
|
||||||
var emptyTopic whisper.TopicType
|
var emptyTopic whispertypes.TopicType
|
||||||
kl := NewDBKey(0, emptyTopic, zero)
|
kl := NewDBKey(0, emptyTopic, zero)
|
||||||
ku := NewDBKey(uint32(t.Unix()), emptyTopic, zero)
|
ku := NewDBKey(uint32(t.Unix()), emptyTopic, zero)
|
||||||
statement := "DELETE FROM envelopes WHERE id BETWEEN $1 AND $2"
|
statement := "DELETE FROM envelopes WHERE id BETWEEN $1 AND $2"
|
||||||
|
@ -178,7 +179,8 @@ func (i *PostgresDB) Prune(t time.Time, batch int) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *PostgresDB) SaveEnvelope(env *whisper.Envelope) error {
|
func (i *PostgresDB) SaveEnvelope(env *whisper.Envelope) error {
|
||||||
key := NewDBKey(env.Expiry-env.TTL, env.Topic, env.Hash())
|
topic := whispertypes.TopicType(env.Topic)
|
||||||
|
key := NewDBKey(env.Expiry-env.TTL, topic, statusproto.Hash(env.Hash()))
|
||||||
rawEnvelope, err := rlp.EncodeToBytes(env)
|
rawEnvelope, err := rlp.EncodeToBytes(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("rlp.EncodeToBytes failed: %s", err))
|
log.Error(fmt.Sprintf("rlp.EncodeToBytes failed: %s", err))
|
||||||
|
@ -198,7 +200,7 @@ func (i *PostgresDB) SaveEnvelope(env *whisper.Envelope) error {
|
||||||
_, err = stmt.Exec(
|
_, err = stmt.Exec(
|
||||||
key.Bytes(),
|
key.Bytes(),
|
||||||
rawEnvelope,
|
rawEnvelope,
|
||||||
topicToByte(env.Topic),
|
topicToByte(topic),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -212,7 +214,7 @@ func (i *PostgresDB) SaveEnvelope(env *whisper.Envelope) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func topicToByte(t whisper.TopicType) []byte {
|
func topicToByte(t whispertypes.TopicType) []byte {
|
||||||
return []byte{t[0], t[1], t[2], t[3]}
|
return []byte{t[0], t[1], t[2], t[3]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/status-im/status-go/params"
|
"github.com/status-im/status-go/params"
|
||||||
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
whisper "github.com/status-im/whisper/whisperv6"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
@ -44,7 +46,7 @@ var seed = time.Now().Unix()
|
||||||
var testPayload = []byte("test payload")
|
var testPayload = []byte("test payload")
|
||||||
|
|
||||||
type ServerTestParams struct {
|
type ServerTestParams struct {
|
||||||
topic whisper.TopicType
|
topic whispertypes.TopicType
|
||||||
birth uint32
|
birth uint32
|
||||||
low uint32
|
low uint32
|
||||||
upp uint32
|
upp uint32
|
||||||
|
@ -257,7 +259,7 @@ func (s *MailserverSuite) TestArchive() {
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
|
|
||||||
s.server.Archive(env)
|
s.server.Archive(env)
|
||||||
key := NewDBKey(env.Expiry-env.TTL, env.Topic, env.Hash())
|
key := NewDBKey(env.Expiry-env.TTL, whispertypes.TopicType(env.Topic), statusproto.Hash(env.Hash()))
|
||||||
archivedEnvelope, err := s.server.db.GetEnvelope(key)
|
archivedEnvelope, err := s.server.db.GetEnvelope(key)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
|
|
||||||
|
@ -277,8 +279,8 @@ func (s *MailserverSuite) TestManageLimits() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MailserverSuite) TestDBKey() {
|
func (s *MailserverSuite) TestDBKey() {
|
||||||
var h common.Hash
|
var h statusproto.Hash
|
||||||
var emptyTopic whisper.TopicType
|
var emptyTopic whispertypes.TopicType
|
||||||
i := uint32(time.Now().Unix())
|
i := uint32(time.Now().Unix())
|
||||||
k := NewDBKey(i, emptyTopic, h)
|
k := NewDBKey(i, emptyTopic, h)
|
||||||
s.Equal(len(k.Bytes()), DBKeyLength, "wrong DB key length")
|
s.Equal(len(k.Bytes()), DBKeyLength, "wrong DB key length")
|
||||||
|
@ -305,7 +307,7 @@ func (s *MailserverSuite) TestRequestPaginationLimit() {
|
||||||
env, err := generateEnvelope(sentTime)
|
env, err := generateEnvelope(sentTime)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.server.Archive(env)
|
s.server.Archive(env)
|
||||||
key := NewDBKey(env.Expiry-env.TTL, env.Topic, env.Hash())
|
key := NewDBKey(env.Expiry-env.TTL, whispertypes.TopicType(env.Topic), statusproto.Hash(env.Hash()))
|
||||||
archiveKeys = append(archiveKeys, fmt.Sprintf("%x", key.Cursor()))
|
archiveKeys = append(archiveKeys, fmt.Sprintf("%x", key.Cursor()))
|
||||||
sentEnvelopes = append(sentEnvelopes, env)
|
sentEnvelopes = append(sentEnvelopes, env)
|
||||||
sentHashes = append(sentHashes, env.Hash())
|
sentHashes = append(sentHashes, env.Hash())
|
||||||
|
@ -421,7 +423,7 @@ func (s *MailserverSuite) TestMailServer() {
|
||||||
s.Equal(tc.params.low, lower)
|
s.Equal(tc.params.low, lower)
|
||||||
s.Equal(tc.params.upp, upper)
|
s.Equal(tc.params.upp, upper)
|
||||||
s.Equal(tc.params.limit, limit)
|
s.Equal(tc.params.limit, limit)
|
||||||
s.Equal(whisper.TopicToBloom(tc.params.topic), bloom)
|
s.Equal(whispertypes.TopicToBloom(tc.params.topic), bloom)
|
||||||
s.Equal(tc.expect, s.messageExists(env, tc.params.low, tc.params.upp, bloom, tc.params.limit))
|
s.Equal(tc.expect, s.messageExists(env, tc.params.low, tc.params.upp, bloom, tc.params.limit))
|
||||||
|
|
||||||
src[0]++
|
src[0]++
|
||||||
|
@ -452,7 +454,7 @@ func (s *MailserverSuite) TestDecodeRequest() {
|
||||||
srcKey, err := s.shh.GetPrivateKey(id)
|
srcKey, err := s.shh.GetPrivateKey(id)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
env := s.createEnvelope(whisper.TopicType{0x01}, data, srcKey)
|
env := s.createEnvelope(whispertypes.TopicType{0x01}, data, srcKey)
|
||||||
|
|
||||||
decodedPayload, err := s.server.decodeRequest(nil, env)
|
decodedPayload, err := s.server.decodeRequest(nil, env)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -478,7 +480,7 @@ func (s *MailserverSuite) TestDecodeRequestNoUpper() {
|
||||||
srcKey, err := s.shh.GetPrivateKey(id)
|
srcKey, err := s.shh.GetPrivateKey(id)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
env := s.createEnvelope(whisper.TopicType{0x01}, data, srcKey)
|
env := s.createEnvelope(whispertypes.TopicType{0x01}, data, srcKey)
|
||||||
|
|
||||||
decodedPayload, err := s.server.decodeRequest(nil, env)
|
decodedPayload, err := s.server.decodeRequest(nil, env)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -684,7 +686,7 @@ func (s *MailserverSuite) defaultServerParams(env *whisper.Envelope) *ServerTest
|
||||||
birth := env.Expiry - env.TTL
|
birth := env.Expiry - env.TTL
|
||||||
|
|
||||||
return &ServerTestParams{
|
return &ServerTestParams{
|
||||||
topic: env.Topic,
|
topic: whispertypes.TopicType(env.Topic),
|
||||||
birth: birth,
|
birth: birth,
|
||||||
low: birth - 1,
|
low: birth - 1,
|
||||||
upp: birth + 1,
|
upp: birth + 1,
|
||||||
|
@ -694,7 +696,7 @@ func (s *MailserverSuite) defaultServerParams(env *whisper.Envelope) *ServerTest
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MailserverSuite) createRequest(p *ServerTestParams) *whisper.Envelope {
|
func (s *MailserverSuite) createRequest(p *ServerTestParams) *whisper.Envelope {
|
||||||
bloom := whisper.TopicToBloom(p.topic)
|
bloom := whispertypes.TopicToBloom(p.topic)
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint32(data, p.low)
|
binary.BigEndian.PutUint32(data, p.low)
|
||||||
binary.BigEndian.PutUint32(data[4:], p.upp)
|
binary.BigEndian.PutUint32(data[4:], p.upp)
|
||||||
|
@ -709,7 +711,7 @@ func (s *MailserverSuite) createRequest(p *ServerTestParams) *whisper.Envelope {
|
||||||
return s.createEnvelope(p.topic, data, p.key)
|
return s.createEnvelope(p.topic, data, p.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MailserverSuite) createEnvelope(topic whisper.TopicType, data []byte, srcKey *ecdsa.PrivateKey) *whisper.Envelope {
|
func (s *MailserverSuite) createEnvelope(topic whispertypes.TopicType, data []byte, srcKey *ecdsa.PrivateKey) *whisper.Envelope {
|
||||||
key, err := s.shh.GetSymKey(keyID)
|
key, err := s.shh.GetSymKey(keyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.T().Fatalf("failed to retrieve sym key with seed %d: %s.", seed, err)
|
s.T().Fatalf("failed to retrieve sym key with seed %d: %s.", seed, err)
|
||||||
|
@ -717,7 +719,7 @@ func (s *MailserverSuite) createEnvelope(topic whisper.TopicType, data []byte, s
|
||||||
|
|
||||||
params := &whisper.MessageParams{
|
params := &whisper.MessageParams{
|
||||||
KeySym: key,
|
KeySym: key,
|
||||||
Topic: topic,
|
Topic: whisper.TopicType(topic),
|
||||||
Payload: data,
|
Payload: data,
|
||||||
PoW: powRequirement * 2,
|
PoW: powRequirement * 2,
|
||||||
WorkTime: 2,
|
WorkTime: 2,
|
||||||
|
@ -769,7 +771,7 @@ func generateEnvelope(sentTime time.Time) (*whisper.Envelope, error) {
|
||||||
|
|
||||||
func processRequestAndCollectHashes(
|
func processRequestAndCollectHashes(
|
||||||
server *WMailServer, lower, upper uint32, cursor []byte, bloom []byte, limit int,
|
server *WMailServer, lower, upper uint32, cursor []byte, bloom []byte, limit int,
|
||||||
) ([]common.Hash, []byte, common.Hash) {
|
) ([]common.Hash, []byte, statusproto.Hash) {
|
||||||
iter, _ := server.createIterator(lower, upper, cursor, nil, 0)
|
iter, _ := server.createIterator(lower, upper, cursor, nil, 0)
|
||||||
defer iter.Release()
|
defer iter.Release()
|
||||||
bundles := make(chan []rlp.RawValue, 10)
|
bundles := make(chan []rlp.RawValue, 10)
|
||||||
|
|
84
node/node.go
84
node/node.go
|
@ -30,10 +30,10 @@ import (
|
||||||
"github.com/status-im/status-go/services/personal"
|
"github.com/status-im/status-go/services/personal"
|
||||||
"github.com/status-im/status-go/services/shhext"
|
"github.com/status-im/status-go/services/shhext"
|
||||||
"github.com/status-im/status-go/services/status"
|
"github.com/status-im/status-go/services/status"
|
||||||
|
"github.com/status-im/status-go/services/whisperbridge"
|
||||||
"github.com/status-im/status-go/static"
|
"github.com/status-im/status-go/static"
|
||||||
"github.com/status-im/status-go/timesource"
|
"github.com/status-im/status-go/timesource"
|
||||||
gethbridge "github.com/status-im/status-protocol-go/bridge/geth"
|
gethbridge "github.com/status-im/status-protocol-go/bridge/geth"
|
||||||
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
whisper "github.com/status-im/whisper/whisperv6"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
)
|
)
|
||||||
|
@ -272,11 +272,11 @@ func activateStatusService(stack *node.Node, config *params.NodeConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
var whisper *whisper.Whisper
|
var service *whisperbridge.WhisperService
|
||||||
if err := ctx.Service(&whisper); err != nil {
|
if err := ctx.Service(&service); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
svc := status.New(whisper)
|
svc := status.New(service.Whisper)
|
||||||
return svc, nil
|
return svc, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -310,26 +310,55 @@ func activateShhService(stack *node.Node, config *params.NodeConfig, db *leveldb
|
||||||
}
|
}
|
||||||
|
|
||||||
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
|
return createShhService(ctx, &config.WhisperConfig, &config.ClusterConfig)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register Whisper status-protocol-go bridge
|
||||||
|
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
|
var whisper *whisper.Whisper
|
||||||
|
if err := ctx.Service(&whisper); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &whisperbridge.WhisperService{Whisper: gethbridge.NewGethWhisperWrapper(whisper)}, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(dshulyak) add a config option to enable it by default, but disable if app is started from statusd
|
||||||
|
return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
|
var service *whisperbridge.WhisperService
|
||||||
|
if err := ctx.Service(&service); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return shhext.New(service.Whisper, shhext.EnvelopeSignalHandler{}, db, config.ShhextConfig), nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func createShhService(ctx *node.ServiceContext, whisperConfig *params.WhisperConfig, clusterConfig *params.ClusterConfig) (*whisper.Whisper, error) {
|
||||||
whisperServiceConfig := &whisper.Config{
|
whisperServiceConfig := &whisper.Config{
|
||||||
MaxMessageSize: whisper.DefaultMaxMessageSize,
|
MaxMessageSize: whisper.DefaultMaxMessageSize,
|
||||||
MinimumAcceptedPOW: params.WhisperMinimumPoW,
|
MinimumAcceptedPOW: params.WhisperMinimumPoW,
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.WhisperConfig.MaxMessageSize > 0 {
|
if whisperConfig.MaxMessageSize > 0 {
|
||||||
whisperServiceConfig.MaxMessageSize = config.WhisperConfig.MaxMessageSize
|
whisperServiceConfig.MaxMessageSize = whisperConfig.MaxMessageSize
|
||||||
}
|
}
|
||||||
if config.WhisperConfig.MinimumPoW > 0 {
|
if whisperConfig.MinimumPoW > 0 {
|
||||||
whisperServiceConfig.MinimumAcceptedPOW = config.WhisperConfig.MinimumPoW
|
whisperServiceConfig.MinimumAcceptedPOW = whisperConfig.MinimumPoW
|
||||||
}
|
}
|
||||||
|
|
||||||
whisperService := whisper.New(whisperServiceConfig)
|
whisperService := whisper.New(whisperServiceConfig)
|
||||||
|
|
||||||
if config.WhisperConfig.EnableRateLimiter {
|
if whisperConfig.EnableRateLimiter {
|
||||||
r := whisperRateLimiter(config)
|
r := whisperRateLimiter(whisperConfig, clusterConfig)
|
||||||
whisperService.SetRateLimiter(r)
|
whisperService.SetRateLimiter(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.WhisperConfig.EnableNTPSync {
|
if whisperConfig.EnableNTPSync {
|
||||||
timesource, err := whisperTimeSource(ctx)
|
timesource, err := whisperTimeSource(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -338,13 +367,13 @@ func activateShhService(stack *node.Node, config *params.NodeConfig, db *leveldb
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable mail service
|
// enable mail service
|
||||||
if config.WhisperConfig.EnableMailServer {
|
if whisperConfig.EnableMailServer {
|
||||||
if err := registerMailServer(whisperService, &config.WhisperConfig); err != nil {
|
if err := registerMailServer(whisperService, whisperConfig); err != nil {
|
||||||
return nil, fmt.Errorf("failed to register MailServer: %v", err)
|
return nil, fmt.Errorf("failed to register MailServer: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.WhisperConfig.LightClient {
|
if whisperConfig.LightClient {
|
||||||
emptyBloomFilter := make([]byte, 64)
|
emptyBloomFilter := make([]byte, 64)
|
||||||
if err := whisperService.SetBloomFilter(emptyBloomFilter); err != nil {
|
if err := whisperService.SetBloomFilter(emptyBloomFilter); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -352,19 +381,6 @@ func activateShhService(stack *node.Node, config *params.NodeConfig, db *leveldb
|
||||||
}
|
}
|
||||||
|
|
||||||
return whisperService, nil
|
return whisperService, nil
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(dshulyak) add a config option to enable it by default, but disable if app is started from statusd
|
|
||||||
return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
|
||||||
var whisper *whisper.Whisper
|
|
||||||
if err := ctx.Service(&whisper); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return shhext.New(gethbridge.NewGethWhisperWrapper(whisper), shhext.EnvelopeSignalHandler{}, db, config.ShhextConfig), nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// activateIncentivisationService configures Whisper and adds it to the given node.
|
// activateIncentivisationService configures Whisper and adds it to the given node.
|
||||||
|
@ -382,7 +398,7 @@ func activateIncentivisationService(stack *node.Node, config *params.NodeConfig)
|
||||||
logger.Info("activating incentivisation")
|
logger.Info("activating incentivisation")
|
||||||
// TODO(dshulyak) add a config option to enable it by default, but disable if app is started from statusd
|
// TODO(dshulyak) add a config option to enable it by default, but disable if app is started from statusd
|
||||||
return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
var w whispertypes.Whisper
|
var w *whisperbridge.WhisperService
|
||||||
if err := ctx.Service(&w); err != nil {
|
if err := ctx.Service(&w); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -406,7 +422,7 @@ func activateIncentivisationService(stack *node.Node, config *params.NodeConfig)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return incentivisation.New(privateKey, w.PublicWhisperAPI(), incentivisationConfig, contract), nil
|
return incentivisation.New(privateKey, w.Whisper.PublicWhisperAPI(), incentivisationConfig, contract), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,10 +473,10 @@ func whisperTimeSource(ctx *node.ServiceContext) (func() time.Time, error) {
|
||||||
return timeSource.Now, nil
|
return timeSource.Now, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func whisperRateLimiter(config *params.NodeConfig) *whisper.PeerRateLimiter {
|
func whisperRateLimiter(whisperConfig *params.WhisperConfig, clusterConfig *params.ClusterConfig) *whisper.PeerRateLimiter {
|
||||||
enodes := append(
|
enodes := append(
|
||||||
parseNodes(config.ClusterConfig.StaticNodes),
|
parseNodes(clusterConfig.StaticNodes),
|
||||||
parseNodes(config.ClusterConfig.TrustedMailServers)...,
|
parseNodes(clusterConfig.TrustedMailServers)...,
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
ips []string
|
ips []string
|
||||||
|
@ -473,8 +489,8 @@ func whisperRateLimiter(config *params.NodeConfig) *whisper.PeerRateLimiter {
|
||||||
return whisper.NewPeerRateLimiter(
|
return whisper.NewPeerRateLimiter(
|
||||||
&whisper.MetricsRateLimiterHandler{},
|
&whisper.MetricsRateLimiterHandler{},
|
||||||
&whisper.PeerRateLimiterConfig{
|
&whisper.PeerRateLimiterConfig{
|
||||||
LimitPerSecIP: config.WhisperConfig.RateLimitIP,
|
LimitPerSecIP: whisperConfig.RateLimitIP,
|
||||||
LimitPerSecPeerID: config.WhisperConfig.RateLimitPeerID,
|
LimitPerSecPeerID: whisperConfig.RateLimitPeerID,
|
||||||
WhitelistedIPs: ips,
|
WhitelistedIPs: ips,
|
||||||
WhitelistedPeerIDs: peerIDs,
|
WhitelistedPeerIDs: peerIDs,
|
||||||
},
|
},
|
||||||
|
|
|
@ -442,7 +442,7 @@ func (s *Service) postPing() (hexutil.Bytes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Payload = payload
|
msg.Payload = payload
|
||||||
msg.Sig = s.whisperKeyID
|
msg.SigID = s.whisperKeyID
|
||||||
msg.SymKeyID = s.whisperSymKeyID
|
msg.SymKeyID = s.whisperSymKeyID
|
||||||
|
|
||||||
return s.w.Post(context.TODO(), msg)
|
return s.w.Post(context.TODO(), msg)
|
||||||
|
|
|
@ -739,7 +739,7 @@ func createBloomFilter(r MessagesRequest) []byte {
|
||||||
return topicsToBloom(r.Topics...)
|
return topicsToBloom(r.Topics...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return whisper.TopicToBloom(whisper.TopicType(r.Topic))
|
return whispertypes.TopicToBloom(r.Topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func topicsToBloom(topics ...whispertypes.TopicType) []byte {
|
func topicsToBloom(topics ...whispertypes.TopicType) []byte {
|
||||||
|
@ -749,9 +749,9 @@ func topicsToBloom(topics ...whispertypes.TopicType) []byte {
|
||||||
i.Or(i, new(big.Int).SetBytes(bloom[:]))
|
i.Or(i, new(big.Int).SetBytes(bloom[:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
combined := make([]byte, whisper.BloomFilterSize)
|
combined := make([]byte, whispertypes.BloomFilterSize)
|
||||||
data := i.Bytes()
|
data := i.Bytes()
|
||||||
copy(combined[whisper.BloomFilterSize-len(data):], data[:])
|
copy(combined[whispertypes.BloomFilterSize-len(data):], data[:])
|
||||||
|
|
||||||
return combined
|
return combined
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,7 @@ import (
|
||||||
|
|
||||||
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
statusproto "github.com/status-im/status-protocol-go/types"
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/status-im/status-go/mailserver"
|
"github.com/status-im/status-go/mailserver"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -64,7 +62,7 @@ func TestMessagesRequest_setDefaults(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMakeMessagesRequestPayload(t *testing.T) {
|
func TestMakeMessagesRequestPayload(t *testing.T) {
|
||||||
var emptyTopic whisper.TopicType
|
var emptyTopic whispertypes.TopicType
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
Name string
|
Name string
|
||||||
Req MessagesRequest
|
Req MessagesRequest
|
||||||
|
@ -83,7 +81,7 @@ func TestMakeMessagesRequestPayload(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "valid cursor",
|
Name: "valid cursor",
|
||||||
Req: MessagesRequest{
|
Req: MessagesRequest{
|
||||||
Cursor: hex.EncodeToString(mailserver.NewDBKey(123, emptyTopic, common.Hash{}).Cursor()),
|
Cursor: hex.EncodeToString(mailserver.NewDBKey(123, emptyTopic, statusproto.Hash{}).Cursor()),
|
||||||
},
|
},
|
||||||
Err: "",
|
Err: "",
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package whisperutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
|
||||||
)
|
|
||||||
|
|
||||||
var discoveryTopic = "contact-discovery"
|
|
||||||
var DiscoveryTopicBytes = ToTopic(discoveryTopic)
|
|
||||||
|
|
||||||
func ToTopic(s string) whisper.TopicType {
|
|
||||||
return whisper.BytesToTopic(crypto.Keccak256([]byte(s)))
|
|
||||||
}
|
|
|
@ -245,4 +245,3 @@ func (_Example *ExampleSession) Verify(v uint8, r [32]byte, s [32]byte) (*types.
|
||||||
func (_Example *ExampleTransactorSession) Verify(v uint8, r [32]byte, s [32]byte) (*types.Transaction, error) {
|
func (_Example *ExampleTransactorSession) Verify(v uint8, r [32]byte, s [32]byte) (*types.Transaction, error) {
|
||||||
return _Example.Contract.Verify(&_Example.TransactOpts, v, r, s)
|
return _Example.Contract.Verify(&_Example.TransactOpts, v, r, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ func WatchAccountsChanges(ctx context.Context, feed *event.Feed, initial []commo
|
||||||
log.Error("accounts watcher subscription failed", "error", err)
|
log.Error("accounts watcher subscription failed", "error", err)
|
||||||
}
|
}
|
||||||
case n := <-accounts:
|
case n := <-accounts:
|
||||||
log.Debug("wallet received updated list of accoutns", "accounts", n)
|
log.Debug("wallet received updated list of accounts", "accounts", n)
|
||||||
restart := false
|
restart := false
|
||||||
for _, acc := range n {
|
for _, acc := range n {
|
||||||
_, exist := listen[acc.Address]
|
_, exist := listen[acc.Address]
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package whisperbridge
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/node"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Make sure that WhisperService implements node.Service interface.
|
||||||
|
var _ node.Service = (*WhisperService)(nil)
|
||||||
|
|
||||||
|
type WhisperService struct {
|
||||||
|
Whisper whispertypes.Whisper
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protocols returns a new protocols list. In this case, there are none.
|
||||||
|
func (w *WhisperService) Protocols() []p2p.Protocol {
|
||||||
|
return []p2p.Protocol{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIs returns a list of new APIs.
|
||||||
|
func (w *WhisperService) APIs() []rpc.API {
|
||||||
|
return []rpc.API{
|
||||||
|
{
|
||||||
|
Namespace: "status",
|
||||||
|
Version: "1.0",
|
||||||
|
Service: w.Whisper,
|
||||||
|
Public: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start is run when a service is started.
|
||||||
|
// It does nothing in this case but is required by `node.Service` interface.
|
||||||
|
func (w *WhisperService) Start(server *p2p.Server) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop is run when a service is stopped.
|
||||||
|
// It does nothing in this case but is required by `node.Service` interface.
|
||||||
|
func (w *WhisperService) Stop() error {
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -363,4 +363,3 @@ func (_Eventer *EventerFilterer) WatchMessage(opts *bind.WatchOpts, sink chan<-
|
||||||
}
|
}
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ vendor:
|
||||||
|
|
||||||
install-linter:
|
install-linter:
|
||||||
# install linter
|
# install linter
|
||||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.19.0
|
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.21.0
|
||||||
.PHONY: install-linter
|
.PHONY: install-linter
|
||||||
|
|
||||||
install-dev:
|
install-dev:
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
package gethbridge
|
package gethbridge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
|
||||||
|
|
||||||
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
whisper "github.com/status-im/whisper/whisperv6"
|
||||||
)
|
)
|
||||||
|
|
||||||
type gethFilterWrapper struct {
|
type gethFilterWrapper struct {
|
||||||
filter *whisper.Filter
|
filter *whisper.Filter
|
||||||
|
id string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGethFilterWrapper returns an object that wraps Geth's Filter in a whispertypes interface
|
// NewGethFilterWrapper returns an object that wraps Geth's Filter in a whispertypes interface
|
||||||
func NewGethFilterWrapper(f *whisper.Filter) whispertypes.Filter {
|
func NewGethFilterWrapper(f *whisper.Filter, id string) whispertypes.Filter {
|
||||||
if f.Messages == nil {
|
if f.Messages == nil {
|
||||||
panic("Messages should not be nil")
|
panic("Messages should not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &gethFilterWrapper{
|
return &gethFilterWrapper{
|
||||||
filter: f,
|
filter: f,
|
||||||
|
id: id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,12 +27,7 @@ func GetGethFilterFrom(f whispertypes.Filter) *whisper.Filter {
|
||||||
return f.(*gethFilterWrapper).filter
|
return f.(*gethFilterWrapper).filter
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyAsym returns the private Key of recipient
|
// ID returns the filter ID
|
||||||
func (w *gethFilterWrapper) KeyAsym() *ecdsa.PrivateKey {
|
func (w *gethFilterWrapper) ID() string {
|
||||||
return w.filter.KeyAsym
|
return w.id
|
||||||
}
|
|
||||||
|
|
||||||
// KeySym returns the key associated with the Topic
|
|
||||||
func (w *gethFilterWrapper) KeySym() []byte {
|
|
||||||
return w.filter.KeySym
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
package gethbridge
|
|
||||||
|
|
||||||
import (
|
|
||||||
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
|
||||||
)
|
|
||||||
|
|
||||||
type gethMessageStoreWrapper struct {
|
|
||||||
messageStore whisper.MessageStore
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewGethMessageStoreWrapper returns an object that wraps Geth's MessageStore in a whispertypes interface
|
|
||||||
func NewGethMessageStoreWrapper(messageStore whisper.MessageStore) whispertypes.MessageStore {
|
|
||||||
if messageStore == nil {
|
|
||||||
panic("messageStore cannot be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &gethMessageStoreWrapper{
|
|
||||||
messageStore: messageStore,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGethMessageStoreFrom retrieves the underlying whisper MessageStore interface from a wrapped MessageStore interface
|
|
||||||
func GetGethMessageStoreFrom(m whispertypes.MessageStore) whisper.MessageStore {
|
|
||||||
return m.(*gethMessageStoreWrapper).messageStore
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *gethMessageStoreWrapper) Add(m whispertypes.ReceivedMessage) error {
|
|
||||||
return w.messageStore.Add(GetGethReceivedMessageFrom(m))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *gethMessageStoreWrapper) Pop() ([]whispertypes.ReceivedMessage, error) {
|
|
||||||
msgs, err := w.messageStore.Pop()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
wrappedMsgs := make([]whispertypes.ReceivedMessage, len(msgs))
|
|
||||||
for index, m := range msgs {
|
|
||||||
wrappedMsgs[index] = NewGethReceivedMessageWrapper(m)
|
|
||||||
}
|
|
||||||
return wrappedMsgs, err
|
|
||||||
}
|
|
2
vendor/github.com/status-im/status-protocol-go/bridge/geth/public_whisper_api.go
generated
vendored
2
vendor/github.com/status-im/status-protocol-go/bridge/geth/public_whisper_api.go
generated
vendored
|
@ -90,7 +90,7 @@ func (w *gethPublicWhisperAPIWrapper) Post(ctx context.Context, req whispertypes
|
||||||
msg := whisper.NewMessage{
|
msg := whisper.NewMessage{
|
||||||
SymKeyID: req.SymKeyID,
|
SymKeyID: req.SymKeyID,
|
||||||
PublicKey: req.PublicKey,
|
PublicKey: req.PublicKey,
|
||||||
Sig: req.Sig,
|
Sig: req.SigID, // Sig is really a SigID
|
||||||
TTL: req.TTL,
|
TTL: req.TTL,
|
||||||
Topic: whisper.TopicType(req.Topic),
|
Topic: whisper.TopicType(req.Topic),
|
||||||
Payload: req.Payload,
|
Payload: req.Payload,
|
||||||
|
|
26
vendor/github.com/status-im/status-protocol-go/bridge/geth/received_message.go
generated
vendored
26
vendor/github.com/status-im/status-protocol-go/bridge/geth/received_message.go
generated
vendored
|
@ -1,26 +0,0 @@
|
||||||
package gethbridge
|
|
||||||
|
|
||||||
import (
|
|
||||||
whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types"
|
|
||||||
whisper "github.com/status-im/whisper/whisperv6"
|
|
||||||
)
|
|
||||||
|
|
||||||
type gethReceivedMessageWrapper struct {
|
|
||||||
receivedMessage *whisper.ReceivedMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewGethReceivedMessageWrapper returns an object that wraps Geth's ReceivedMessage in a whispertypes interface
|
|
||||||
func NewGethReceivedMessageWrapper(receivedMessage *whisper.ReceivedMessage) whispertypes.ReceivedMessage {
|
|
||||||
if receivedMessage == nil {
|
|
||||||
panic("receivedMessage cannot be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &gethReceivedMessageWrapper{
|
|
||||||
receivedMessage: receivedMessage,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGethReceivedMessageFrom retrieves the underlying whisper ReceivedMessage struct from a wrapped ReceivedMessage interface
|
|
||||||
func GetGethReceivedMessageFrom(m whispertypes.ReceivedMessage) *whisper.ReceivedMessage {
|
|
||||||
return m.(*gethReceivedMessageWrapper).receivedMessage
|
|
||||||
}
|
|
|
@ -32,8 +32,8 @@ func (w *gethWhisperWrapper) PublicWhisperAPI() whispertypes.PublicWhisperAPI {
|
||||||
return NewGethPublicWhisperAPIWrapper(whisper.NewPublicWhisperAPI(w.whisper))
|
return NewGethPublicWhisperAPIWrapper(whisper.NewPublicWhisperAPI(w.whisper))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWhisperWrapper) NewMessageStore() whispertypes.MessageStore {
|
func (w *gethWhisperWrapper) Poll() {
|
||||||
return NewGethMessageStoreWrapper(w.whisper.NewMessageStore())
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinPow returns the PoW value required by this node.
|
// MinPow returns the PoW value required by this node.
|
||||||
|
@ -112,27 +112,57 @@ func (w *gethWhisperWrapper) GetSymKey(id string) ([]byte, error) {
|
||||||
return w.whisper.GetSymKey(id)
|
return w.whisper.GetSymKey(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWhisperWrapper) Subscribe(f whispertypes.Filter) (string, error) {
|
func (w *gethWhisperWrapper) Subscribe(opts *whispertypes.SubscriptionOptions) (string, error) {
|
||||||
return w.whisper.Subscribe(GetGethFilterFrom(f))
|
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.whisper.Subscribe(GetGethFilterFrom(f))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
f.(*gethFilterWrapper).id = id
|
||||||
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWhisperWrapper) GetFilter(id string) whispertypes.Filter {
|
func (w *gethWhisperWrapper) GetFilter(id string) whispertypes.Filter {
|
||||||
return NewGethFilterWrapper(w.whisper.GetFilter(id))
|
return NewGethFilterWrapper(w.whisper.GetFilter(id), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWhisperWrapper) Unsubscribe(id string) error {
|
func (w *gethWhisperWrapper) Unsubscribe(id string) error {
|
||||||
return w.whisper.Unsubscribe(id)
|
return w.whisper.Unsubscribe(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWhisperWrapper) CreateFilterWrapper(keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, topics [][]byte, messages whispertypes.MessageStore) whispertypes.Filter {
|
func (w *gethWhisperWrapper) createFilterWrapper(id string, keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, topics [][]byte) (whispertypes.Filter, error) {
|
||||||
return NewGethFilterWrapper(&whisper.Filter{
|
return NewGethFilterWrapper(&whisper.Filter{
|
||||||
KeyAsym: keyAsym,
|
KeyAsym: keyAsym,
|
||||||
KeySym: keySym,
|
KeySym: keySym,
|
||||||
PoW: pow,
|
PoW: pow,
|
||||||
AllowP2P: true,
|
AllowP2P: true,
|
||||||
Topics: topics,
|
Topics: topics,
|
||||||
Messages: GetGethMessageStoreFrom(messages),
|
Messages: whisper.NewMemoryMessageStore(),
|
||||||
})
|
}, id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWhisperWrapper) SendMessagesRequest(peerID []byte, r whispertypes.MessagesRequest) error {
|
func (w *gethWhisperWrapper) SendMessagesRequest(peerID []byte, r whispertypes.MessagesRequest) error {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
statusproto "github.com/status-im/status-protocol-go/types"
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
protocol "github.com/status-im/status-protocol-go/v1"
|
protocol "github.com/status-im/status-protocol-go/v1"
|
||||||
|
@ -195,7 +194,7 @@ func stringSliceToPublicKeys(slice []string, prefixed bool) ([]*ecdsa.PublicKey,
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if prefixed {
|
if prefixed {
|
||||||
b, err = hexutil.Decode(item)
|
b, err = statusproto.DecodeHex(item)
|
||||||
} else {
|
} else {
|
||||||
b, err = hex.DecodeString(item)
|
b, err = hex.DecodeString(item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ require (
|
||||||
github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8
|
github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8
|
||||||
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 // indirect
|
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.0.2
|
github.com/lucasb-eyer/go-colorful v1.0.2
|
||||||
|
github.com/mattn/go-pointer v0.0.0-20190911064623-a0a44394634f
|
||||||
github.com/minio/sha256-simd v0.1.1 // indirect
|
github.com/minio/sha256-simd v0.1.1 // indirect
|
||||||
github.com/multiformats/go-multihash v0.0.8 // indirect
|
github.com/multiformats/go-multihash v0.0.8 // indirect
|
||||||
github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f
|
github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f
|
||||||
|
|
|
@ -212,6 +212,8 @@ github.com/mattn/go-isatty v0.0.0-20180830101745-3fb116b82035/go.mod h1:M+lRXTBq
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
|
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
|
||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
github.com/mattn/go-pointer v0.0.0-20190911064623-a0a44394634f h1:QTRRO+ozoYgT3CQRIzNVYJRU3DB8HRnkZv6mr4ISmMA=
|
||||||
|
github.com/mattn/go-pointer v0.0.0-20190911064623-a0a44394634f/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
|
||||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"reflect"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
@ -330,7 +329,7 @@ func (p *messageProcessor) Process(shhMessage *whispertypes.Message) ([]*protoco
|
||||||
default:
|
default:
|
||||||
hlogger.Error(
|
hlogger.Error(
|
||||||
"skipped a public message of unsupported type",
|
"skipped a public message of unsupported type",
|
||||||
zap.String("type", reflect.TypeOf(m).String()),
|
zap.Any("value", statusMessage.ParsedMessage),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -499,7 +497,7 @@ func (m *Messenger) AddMembersToChat(ctx context.Context, chat *Chat, members []
|
||||||
}
|
}
|
||||||
encodedMembers := make([]string, len(members))
|
encodedMembers := make([]string, len(members))
|
||||||
for idx, member := range members {
|
for idx, member := range members {
|
||||||
encodedMembers[idx] = hexutil.Encode(crypto.FromECDSAPub(member))
|
encodedMembers[idx] = statusproto.EncodeHex(crypto.FromECDSAPub(member))
|
||||||
}
|
}
|
||||||
event := protocol.NewMembersAddedEvent(encodedMembers, group.NextClockValue())
|
event := protocol.NewMembersAddedEvent(encodedMembers, group.NextClockValue())
|
||||||
err = group.ProcessEvent(&m.identity.PublicKey, event)
|
err = group.ProcessEvent(&m.identity.PublicKey, event)
|
||||||
|
|
|
@ -478,13 +478,11 @@ func (s *filtersManager) addSymmetric(chatID string) (*whisperFilter, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f := s.whisper.CreateFilterWrapper(
|
id, err := s.whisper.Subscribe(&whispertypes.SubscriptionOptions{
|
||||||
nil, symKey,
|
SymKeyID: symKeyID,
|
||||||
minPow,
|
PoW: minPow,
|
||||||
topics,
|
Topics: topics,
|
||||||
s.whisper.NewMessageStore())
|
})
|
||||||
|
|
||||||
id, err := s.whisper.Subscribe(f)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -511,13 +509,16 @@ func (s *filtersManager) addAsymmetric(chatID string, listen bool) (*whisperFilt
|
||||||
topic := toTopic(chatID)
|
topic := toTopic(chatID)
|
||||||
topics := [][]byte{topic}
|
topics := [][]byte{topic}
|
||||||
|
|
||||||
f := s.whisper.CreateFilterWrapper(
|
privateKeyID, err := s.whisper.AddKeyPair(s.privateKey)
|
||||||
s.privateKey, nil,
|
if err != nil {
|
||||||
pow,
|
return nil, err
|
||||||
topics,
|
}
|
||||||
s.whisper.NewMessageStore())
|
|
||||||
|
|
||||||
id, err := s.whisper.Subscribe(f)
|
id, err := s.whisper.Subscribe(&whispertypes.SubscriptionOptions{
|
||||||
|
PrivateKeyID: privateKeyID,
|
||||||
|
PoW: pow,
|
||||||
|
Topics: topics,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/envelopes.go
generated
vendored
2
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/envelopes.go
generated
vendored
|
@ -41,7 +41,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// EnvelopeTimeNotSynced represents the code passed to notify of a clock skew situation
|
||||||
EnvelopeTimeNotSynced uint = 1000
|
EnvelopeTimeNotSynced uint = 1000
|
||||||
|
// EnvelopeOtherError represents the code passed to notify of a generic error situation
|
||||||
EnvelopeOtherError
|
EnvelopeOtherError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
13
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/filter.go
generated
vendored
13
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/filter.go
generated
vendored
|
@ -1,17 +1,6 @@
|
||||||
package whispertypes
|
package whispertypes
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/ecdsa"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Filter represents a Whisper message filter
|
// Filter represents a Whisper message filter
|
||||||
type Filter interface {
|
type Filter interface {
|
||||||
KeyAsym() *ecdsa.PrivateKey // Private Key of recipient
|
ID() string
|
||||||
KeySym() []byte // Key associated with the Topic
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageStore defines the interface for a temporary message store.
|
|
||||||
type MessageStore interface {
|
|
||||||
Add(ReceivedMessage) error
|
|
||||||
Pop() ([]ReceivedMessage, error)
|
|
||||||
}
|
}
|
||||||
|
|
3
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/mailserver.go
generated
vendored
3
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/mailserver.go
generated
vendored
|
@ -7,6 +7,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// MaxLimitInMessagesRequest represents the maximum number of messages
|
||||||
|
// that can be requested from the mailserver
|
||||||
MaxLimitInMessagesRequest = 1000
|
MaxLimitInMessagesRequest = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +30,7 @@ type MessagesRequest struct {
|
||||||
Bloom []byte `json:"bloom"`
|
Bloom []byte `json:"bloom"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetDefaults sets the From and To defaults
|
||||||
func (r *MessagesRequest) SetDefaults(now time.Time) {
|
func (r *MessagesRequest) SetDefaults(now time.Time) {
|
||||||
// set From and To defaults
|
// set From and To defaults
|
||||||
if r.To == 0 {
|
if r.To == 0 {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NegotiatedSecret represents a negotiated secret (both public and private keys)
|
||||||
type NegotiatedSecret struct {
|
type NegotiatedSecret struct {
|
||||||
PublicKey *ecdsa.PublicKey
|
PublicKey *ecdsa.PublicKey
|
||||||
Key []byte
|
Key []byte
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package whispertypes
|
|
||||||
|
|
||||||
// ReceivedMessage represents a data packet to be received through the
|
|
||||||
// Whisper protocol and successfully decrypted.
|
|
||||||
type ReceivedMessage interface {
|
|
||||||
}
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type NewMessage struct {
|
type NewMessage struct {
|
||||||
SymKeyID string `json:"symKeyID"`
|
SymKeyID string `json:"symKeyID"`
|
||||||
PublicKey []byte `json:"pubKey"`
|
PublicKey []byte `json:"pubKey"`
|
||||||
Sig string `json:"sig"`
|
SigID string `json:"sig"`
|
||||||
TTL uint32 `json:"ttl"`
|
TTL uint32 `json:"ttl"`
|
||||||
Topic TopicType `json:"topic"`
|
Topic TopicType `json:"topic"`
|
||||||
Payload []byte `json:"payload"`
|
Payload []byte `json:"payload"`
|
||||||
|
|
5
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/topic.go
generated
vendored
5
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/topic.go
generated
vendored
|
@ -8,7 +8,8 @@ import (
|
||||||
const (
|
const (
|
||||||
// TopicLength is the expected length of the topic, in bytes
|
// TopicLength is the expected length of the topic, in bytes
|
||||||
TopicLength = 4
|
TopicLength = 4
|
||||||
BloomFilterSize = 64 // in bytes
|
// BloomFilterSize is the expected length of a bloom filter byte array, in bytes
|
||||||
|
BloomFilterSize = 64
|
||||||
)
|
)
|
||||||
|
|
||||||
// TopicType represents a cryptographically secure, probabilistic partial
|
// TopicType represents a cryptographically secure, probabilistic partial
|
||||||
|
@ -63,6 +64,7 @@ func TopicToBloom(topic TopicType) []byte {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BloomFilterMatch returns true if a sample matches a bloom filter
|
||||||
func BloomFilterMatch(filter, sample []byte) bool {
|
func BloomFilterMatch(filter, sample []byte) bool {
|
||||||
if filter == nil {
|
if filter == nil {
|
||||||
return true
|
return true
|
||||||
|
@ -79,6 +81,7 @@ func BloomFilterMatch(filter, sample []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MakeFullNodeBloom returns a bloom filter which matches all topics
|
||||||
func MakeFullNodeBloom() []byte {
|
func MakeFullNodeBloom() []byte {
|
||||||
bloom := make([]byte, BloomFilterSize)
|
bloom := make([]byte, BloomFilterSize)
|
||||||
for i := 0; i < BloomFilterSize; i++ {
|
for i := 0; i < BloomFilterSize; i++ {
|
||||||
|
|
24
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/whisper.go
generated
vendored
24
vendor/github.com/status-im/status-protocol-go/transport/whisper/types/whisper.go
generated
vendored
|
@ -5,11 +5,29 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// PubKeyLength represents the length (in bytes) of an uncompressed public key
|
||||||
|
PubKeyLength = 512 / 8
|
||||||
|
// AesKeyLength represents the length (in bytes) of an private key
|
||||||
|
AesKeyLength = 256 / 8
|
||||||
|
)
|
||||||
|
|
||||||
|
// SubscriptionOptions represents the parameters passed to Whisper.Subscribe
|
||||||
|
// to customize the subscription behavior
|
||||||
|
type SubscriptionOptions struct {
|
||||||
|
PrivateKeyID string
|
||||||
|
SymKeyID string
|
||||||
|
PoW float64
|
||||||
|
Topics [][]byte
|
||||||
|
}
|
||||||
|
|
||||||
// Whisper represents a dark communication interface through the Ethereum
|
// Whisper represents a dark communication interface through the Ethereum
|
||||||
// network, using its very own P2P communication layer.
|
// network, using its very own P2P communication layer.
|
||||||
type Whisper interface {
|
type Whisper interface {
|
||||||
PublicWhisperAPI() PublicWhisperAPI
|
PublicWhisperAPI() PublicWhisperAPI
|
||||||
NewMessageStore() MessageStore
|
|
||||||
|
// Poll must be run periodically on the main thread by the host application
|
||||||
|
Poll()
|
||||||
|
|
||||||
// MinPow returns the PoW value required by this node.
|
// MinPow returns the PoW value required by this node.
|
||||||
MinPow() float64
|
MinPow() float64
|
||||||
|
@ -43,12 +61,10 @@ type Whisper interface {
|
||||||
DeleteSymKey(id string) bool
|
DeleteSymKey(id string) bool
|
||||||
GetSymKey(id string) ([]byte, error)
|
GetSymKey(id string) ([]byte, error)
|
||||||
|
|
||||||
Subscribe(f Filter) (string, error)
|
Subscribe(opts *SubscriptionOptions) (string, error)
|
||||||
GetFilter(id string) Filter
|
GetFilter(id string) Filter
|
||||||
Unsubscribe(id string) error
|
Unsubscribe(id string) error
|
||||||
|
|
||||||
CreateFilterWrapper(keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, topics [][]byte, messages MessageStore) Filter
|
|
||||||
|
|
||||||
// RequestHistoricMessages sends a message with p2pRequestCode to a specific peer,
|
// RequestHistoricMessages sends a message with p2pRequestCode to a specific peer,
|
||||||
// which is known to implement MailServer interface, and is supposed to process this
|
// 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),
|
// request and respond with a number of peer-to-peer messages (possibly expired),
|
||||||
|
|
2
vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper_service.go
generated
vendored
2
vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper_service.go
generated
vendored
|
@ -366,7 +366,7 @@ func (a *WhisperServiceTransport) addSig(newMessage *whispertypes.NewMessage) er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newMessage.Sig = sigID
|
newMessage.SigID = sigID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
vendor/github.com/status-im/status-protocol-go/v1/membership_update_message.go
generated
vendored
10
vendor/github.com/status-im/status-protocol-go/v1/membership_update_message.go
generated
vendored
|
@ -11,11 +11,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
gethcrypto "github.com/ethereum/go-ethereum/crypto"
|
gethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/status-im/status-protocol-go/crypto"
|
"github.com/status-im/status-protocol-go/crypto"
|
||||||
|
statusproto "github.com/status-im/status-protocol-go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -94,7 +94,7 @@ func (u *MembershipUpdate) extractFrom() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to extract signature")
|
return errors.Wrap(err, "failed to extract signature")
|
||||||
}
|
}
|
||||||
u.From = hexutil.Encode(gethcrypto.FromECDSAPub(publicKey))
|
u.From = statusproto.EncodeHex(gethcrypto.FromECDSAPub(publicKey))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ type Group struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupChatID(creator *ecdsa.PublicKey) string {
|
func groupChatID(creator *ecdsa.PublicKey) string {
|
||||||
return uuid.New().String() + "-" + hexutil.Encode(gethcrypto.FromECDSAPub(creator))
|
return uuid.New().String() + "-" + statusproto.EncodeHex(gethcrypto.FromECDSAPub(creator))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupWithMembershipUpdates(chatID string, updates []MembershipUpdate) (*Group, error) {
|
func NewGroupWithMembershipUpdates(chatID string, updates []MembershipUpdate) (*Group, error) {
|
||||||
|
@ -396,7 +396,7 @@ func (g *Group) ProcessEvents(from *ecdsa.PublicKey, events []MembershipUpdateEv
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) ProcessEvent(from *ecdsa.PublicKey, event MembershipUpdateEvent) error {
|
func (g *Group) ProcessEvent(from *ecdsa.PublicKey, event MembershipUpdateEvent) error {
|
||||||
fromHex := hexutil.Encode(gethcrypto.FromECDSAPub(from))
|
fromHex := statusproto.EncodeHex(gethcrypto.FromECDSAPub(from))
|
||||||
if !g.validateEvent(fromHex, event) {
|
if !g.validateEvent(fromHex, event) {
|
||||||
return fmt.Errorf("invalid event %#+v from %s", event, from)
|
return fmt.Errorf("invalid event %#+v from %s", event, from)
|
||||||
}
|
}
|
||||||
|
@ -523,7 +523,7 @@ func stringSliceEquals(slice1, slice2 []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func publicKeyToString(publicKey *ecdsa.PublicKey) string {
|
func publicKeyToString(publicKey *ecdsa.PublicKey) string {
|
||||||
return hexutil.Encode(gethcrypto.FromECDSAPub(publicKey))
|
return statusproto.EncodeHex(gethcrypto.FromECDSAPub(publicKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
type stringSet struct {
|
type stringSet struct {
|
||||||
|
|
|
@ -150,7 +150,7 @@ func (m *StatusMessage) HandleApplicationMetadata() error {
|
||||||
func (m *StatusMessage) HandleApplication() error {
|
func (m *StatusMessage) HandleApplication() error {
|
||||||
value, err := decodeTransitMessage(m.DecryptedPayload)
|
value, err := decodeTransitMessage(m.DecryptedPayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[message::DecodeMessage] could not decode message: %#x", m.Hash)
|
log.Printf("[message::DecodeMessage] could not decode message: %#x, err: %v", m.Hash, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.ParsedMessage = value
|
m.ParsedMessage = value
|
||||||
|
|
|
@ -367,7 +367,7 @@ github.com/status-im/migrate/v4/source/go_bindata
|
||||||
github.com/status-im/rendezvous
|
github.com/status-im/rendezvous
|
||||||
github.com/status-im/rendezvous/protocol
|
github.com/status-im/rendezvous/protocol
|
||||||
github.com/status-im/rendezvous/server
|
github.com/status-im/rendezvous/server
|
||||||
# github.com/status-im/status-protocol-go v0.5.1
|
# github.com/status-im/status-protocol-go v0.5.2
|
||||||
github.com/status-im/status-protocol-go
|
github.com/status-im/status-protocol-go
|
||||||
github.com/status-im/status-protocol-go/applicationmetadata
|
github.com/status-im/status-protocol-go/applicationmetadata
|
||||||
github.com/status-im/status-protocol-go/bridge/geth
|
github.com/status-im/status-protocol-go/bridge/geth
|
||||||
|
|
Loading…
Reference in New Issue