diff --git a/VERSION b/VERSION index d2e2400ee94..e06193879b8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.39.1 +0.39.2 diff --git a/appdatabase/migrations/bindata.go b/appdatabase/migrations/bindata.go index adf04d6aade..8464daa057d 100644 --- a/appdatabase/migrations/bindata.go +++ b/appdatabase/migrations/bindata.go @@ -90,7 +90,7 @@ func _0001_appDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_app.down.sql", size: 387, mode: os.FileMode(0644), modTime: time.Unix(1568971614, 0)} + info := bindataFileInfo{name: "0001_app.down.sql", size: 387, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xbc, 0x9c, 0xd2, 0xe1, 0x1d, 0x8, 0x34, 0x6a, 0xc8, 0x37, 0x13, 0xb3, 0x9f, 0x26, 0x23, 0x33, 0xd4, 0x25, 0x8, 0xed, 0x53, 0xe6, 0xd, 0x46, 0xc9, 0xf4, 0x24, 0xf8, 0x1, 0x1f, 0xf5, 0xc8}} return a, nil } @@ -110,7 +110,7 @@ func _0001_appUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_app.up.sql", size: 3088, mode: os.FileMode(0644), modTime: time.Unix(1577451469, 0)} + info := bindataFileInfo{name: "0001_app.up.sql", size: 3088, mode: os.FileMode(0644), modTime: time.Unix(1576661249, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x93, 0xb8, 0x68, 0x17, 0x49, 0x51, 0xc0, 0xe8, 0xbc, 0x36, 0xa4, 0x29, 0xc9, 0x93, 0x6c, 0x3e, 0xdf, 0x3d, 0x23, 0x22, 0xab, 0x18, 0x49, 0xbd, 0x6, 0xf, 0xc5, 0xec, 0xf8, 0xcf, 0x1b, 0x6a}} return a, nil } @@ -130,7 +130,7 @@ func _0002_tokensDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0002_tokens.down.sql", size: 19, mode: os.FileMode(0644), modTime: time.Unix(1577451469, 0)} + info := bindataFileInfo{name: "0002_tokens.down.sql", size: 19, mode: os.FileMode(0644), modTime: time.Unix(1576226192, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd1, 0x31, 0x2, 0xcc, 0x2f, 0x38, 0x90, 0xf7, 0x58, 0x37, 0x47, 0xf4, 0x18, 0xf7, 0x72, 0x74, 0x67, 0x14, 0x7e, 0xf3, 0xb1, 0xd6, 0x5f, 0xb0, 0xd5, 0xe7, 0x91, 0xf4, 0x26, 0x77, 0x8e, 0x68}} return a, nil } @@ -150,7 +150,7 @@ func _0002_tokensUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0002_tokens.up.sql", size: 248, mode: os.FileMode(0644), modTime: time.Unix(1577451469, 0)} + info := bindataFileInfo{name: "0002_tokens.up.sql", size: 248, mode: os.FileMode(0644), modTime: time.Unix(1576226192, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xcc, 0xd6, 0xde, 0xd3, 0x7b, 0xee, 0x92, 0x11, 0x38, 0xa4, 0xeb, 0x84, 0xca, 0xcb, 0x37, 0x75, 0x5, 0x77, 0x7f, 0x14, 0x39, 0xee, 0xa1, 0x8b, 0xd4, 0x5c, 0x6e, 0x55, 0x6, 0x50, 0x16, 0xd4}} return a, nil } @@ -170,7 +170,7 @@ func _0003_settingsDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0003_settings.down.sql", size: 118, mode: os.FileMode(0644), modTime: time.Unix(1577451469, 0)} + info := bindataFileInfo{name: "0003_settings.down.sql", size: 118, mode: os.FileMode(0644), modTime: time.Unix(1578050942, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe5, 0xa6, 0xf5, 0xc0, 0x60, 0x64, 0x77, 0xe2, 0xe7, 0x3c, 0x9b, 0xb1, 0x52, 0xa9, 0x95, 0x16, 0xf8, 0x60, 0x2f, 0xa5, 0xeb, 0x46, 0xb9, 0xb9, 0x8f, 0x4c, 0xf4, 0xfd, 0xbb, 0xe7, 0xe5, 0xe5}} return a, nil } @@ -190,7 +190,7 @@ func _0003_settingsUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0003_settings.up.sql", size: 1311, mode: os.FileMode(0644), modTime: time.Unix(1577752862, 0)} + info := bindataFileInfo{name: "0003_settings.up.sql", size: 1311, mode: os.FileMode(0644), modTime: time.Unix(1578050942, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xea, 0x35, 0x0, 0xeb, 0xe2, 0x33, 0x68, 0xb9, 0xf4, 0xf6, 0x8e, 0x9e, 0x10, 0xe9, 0x58, 0x68, 0x28, 0xb, 0xcd, 0xec, 0x74, 0x71, 0xa7, 0x9a, 0x5a, 0x77, 0x59, 0xb1, 0x13, 0x1c, 0xa1, 0x5b}} return a, nil } @@ -210,7 +210,7 @@ func docGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1568971614, 0)} + info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x7c, 0x28, 0xcd, 0x47, 0xf2, 0xfa, 0x7c, 0x51, 0x2d, 0xd8, 0x38, 0xb, 0xb0, 0x34, 0x9d, 0x4c, 0x62, 0xa, 0x9e, 0x28, 0xc3, 0x31, 0x23, 0xd9, 0xbb, 0x89, 0x9f, 0xa0, 0x89, 0x1f, 0xe8}} return a, nil } diff --git a/eth-node/core/types/transaction.go b/eth-node/core/types/transaction.go new file mode 100644 index 00000000000..bc41ec86061 --- /dev/null +++ b/eth-node/core/types/transaction.go @@ -0,0 +1,39 @@ +package types + +import ( + "github.com/status-im/status-go/eth-node/types" + "math/big" +) + +type Message struct { + to *types.Address + from types.Address + nonce uint64 + amount *big.Int + gasLimit uint64 + gasPrice *big.Int + data []byte + checkNonce bool +} + +func NewMessage(from types.Address, to *types.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool) Message { + return Message{ + from: from, + to: to, + nonce: nonce, + amount: amount, + gasLimit: gasLimit, + gasPrice: gasPrice, + data: data, + checkNonce: checkNonce, + } +} + +func (m Message) From() types.Address { return m.from } +func (m Message) To() *types.Address { return m.to } +func (m Message) GasPrice() *big.Int { return m.gasPrice } +func (m Message) Value() *big.Int { return m.amount } +func (m Message) Gas() uint64 { return m.gasLimit } +func (m Message) Nonce() uint64 { return m.nonce } +func (m Message) Data() []byte { return m.data } +func (m Message) CheckNonce() bool { return m.checkNonce } diff --git a/eth-node/crypto/crypto.go b/eth-node/crypto/crypto.go index 18a3aa3a232..ef49262511e 100644 --- a/eth-node/crypto/crypto.go +++ b/eth-node/crypto/crypto.go @@ -1,6 +1,7 @@ package crypto import ( + "context" "crypto/aes" "crypto/cipher" "crypto/ecdsa" @@ -8,6 +9,8 @@ import ( "encoding/hex" "errors" "fmt" + types "github.com/status-im/status-go/eth-node/types" + "golang.org/x/crypto/sha3" gethcrypto "github.com/ethereum/go-ethereum/crypto" ) @@ -192,3 +195,56 @@ func generateSecureRandomData(length int) ([]byte, error) { return res, nil } + +// TextHash is a helper function that calculates a hash for the given message that can be +// safely used to calculate a signature from. +// +// The hash is calulcated as +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// This gives context to the signed message and prevents signing of transactions. +func TextHash(data []byte) []byte { + hash, _ := TextAndHash(data) + return hash +} + +// TextAndHash is a helper function that calculates a hash for the given message that can be +// safely used to calculate a signature from. +// +// The hash is calulcated as +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// This gives context to the signed message and prevents signing of transactions. +func TextAndHash(data []byte) ([]byte, string) { + msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), string(data)) + hasher := sha3.NewLegacyKeccak256() + hasher.Write([]byte(msg)) + return hasher.Sum(nil), msg +} + +func EcRecover(ctx context.Context, data types.HexBytes, sig types.HexBytes) (types.Address, error) { + // Returns the address for the Account that was used to create the signature. + // + // Note, this function is compatible with eth_sign and personal_sign. As such it recovers + // the address of: + // hash = keccak256("\x19${byteVersion}Ethereum Signed Message:\n${message length}${message}") + // addr = ecrecover(hash, signature) + // + // Note, the signature must conform to the secp256k1 curve R, S and V values, where + // the V value must be be 27 or 28 for legacy reasons. + // + // https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover + if len(sig) != 65 { + return types.Address{}, fmt.Errorf("signature must be 65 bytes long") + } + if sig[64] != 27 && sig[64] != 28 { + return types.Address{}, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)") + } + sig[64] -= 27 // Transform yellow paper V from 27/28 to 0/1 + hash := TextHash(data) + rpk, err := SigToPub(hash, sig) + if err != nil { + return types.Address{}, err + } + return PubkeyToAddress(*rpk), nil +} diff --git a/eth-node/go.sum b/eth-node/go.sum index f603ee8358d..4d664f67c7c 100644 --- a/eth-node/go.sum +++ b/eth-node/go.sum @@ -257,6 +257,7 @@ github.com/status-im/doubleratchet v3.0.0+incompatible h1:aJ1ejcSERpSzmWZBgtfYti github.com/status-im/doubleratchet v3.0.0+incompatible/go.mod h1:1sqR0+yhiM/bd+wrdX79AOt2csZuJOni0nUDzKNuqOU= github.com/status-im/go-ethereum v1.9.5-status.6 h1:ytuTO1yBIAuTVRtRQoc2mrdyngtP+XOQ9IHIibbz7/I= github.com/status-im/go-ethereum v1.9.5-status.6/go.mod h1:08JvQWE+IOnAFSe4UD4ACLNe2fDd9XmWMCq5Yzy9mk0= +github.com/status-im/go-ethereum v1.9.5-status.7 h1:DKH1GiF52LwaZaw6YDBliFEgm/JDsbIT+hn7ph6X94Q= github.com/status-im/go-ethereum v1.9.5-status.7/go.mod h1:YyH5DKB6+z+Vaya7eIm67pnuPZ1oiUMbbsZW41ktN0g= github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 h1:ju5UTwk5Odtm4trrY+4Ca4RMj5OyXbmVeDAVad2T0Jw= github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= diff --git a/go.mod b/go.mod index 92bae2ca97b..50033967c3d 100644 --- a/go.mod +++ b/go.mod @@ -23,20 +23,16 @@ replace github.com/status-im/status-go/waku => ./waku require ( github.com/beevik/ntp v0.2.0 github.com/ethereum/go-ethereum v1.9.5 - github.com/go-playground/universal-translator v0.17.0 // indirect github.com/golang/mock v1.3.1 - github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.2.0 - github.com/libp2p/go-libp2p v0.4.0 // indirect; indirect - github.com/libp2p/go-libp2p-core v0.2.3 + github.com/libp2p/go-libp2p v0.4.2 // indirect + github.com/libp2p/go-libp2p-core v0.2.4 github.com/multiformats/go-multiaddr v0.1.1 github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd github.com/pborman/uuid v1.2.0 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.2.1 - github.com/russolsen/ohyeah v0.0.0-20160324131710-f4938c005315 // indirect - github.com/russolsen/same v0.0.0-20160222130632-f089df61f51d // indirect github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a github.com/status-im/migrate/v4 v4.6.2-status.2 github.com/status-im/rendezvous v1.3.0 @@ -50,9 +46,6 @@ require ( github.com/syndtr/goleveldb v1.0.0 go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c - golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 // indirect - golang.org/x/tools v0.0.0-20191213032237-7093a17b0467 // indirect - gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.29.1 gopkg.in/natefinch/lumberjack.v2 v2.0.0 ) diff --git a/go.sum b/go.sum index 8742cc1d2f7..db992d3de8a 100644 --- a/go.sum +++ b/go.sum @@ -111,6 +111,7 @@ github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14y github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= +github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= github.com/dgrijalva/jwt-go v0.0.0-20170201225849-2268707a8f08/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= @@ -179,6 +180,8 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE= github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang-migrate/migrate/v4 v4.6.2 h1:LDDOHo/q1W5UDj6PbkxdCv7lv9yunyZHXvxuwDkGo3k= github.com/golang-migrate/migrate/v4 v4.6.2/go.mod h1:JYi6reN3+Z734VZ0akNuyOJNcrg45ZL7LDBMW3WGJL0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= @@ -251,11 +254,15 @@ github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUP github.com/ipfs/go-cid v0.0.3 h1:UIAh32wymBpStoe83YCzwVQQ5Oy/H0FdxvUS6DJDzms= github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= github.com/ipfs/go-ds-badger v0.0.5/go.mod h1:g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaHzfGTzuE3s= +github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9YlmAvpQBk= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= +github.com/ipfs/go-ds-leveldb v0.1.0/go.mod h1:hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50= github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= @@ -307,6 +314,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3 github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ= github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -334,25 +343,30 @@ github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atq github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= github.com/libp2p/go-libp2p v0.1.1 h1:52sB0TJuDk2nYMcMfHOKaPoaayDZjaYVCq6Vk1ejUTk= github.com/libp2p/go-libp2p v0.1.1/go.mod h1:I00BRo1UuUSdpuc8Q2mN7yDF/oTUTRAX6JWpTiK9Rp8= -github.com/libp2p/go-libp2p v0.4.0 h1:nV2q3fdhL80OWtPyBrsoWKcw32qC4TbbR+iGjEOMRaU= github.com/libp2p/go-libp2p v0.4.0/go.mod h1:9EsEIf9p2UDuwtPd0DwJsAl0qXVxgAnuDGRvHbfATfI= +github.com/libp2p/go-libp2p v0.4.2 h1:p0cthB0jDNHO4gH2HzS8/nAMMXbfUlFHs0jwZ4U+F2g= +github.com/libp2p/go-libp2p v0.4.2/go.mod h1:MNmgUxUw5pMsdOzMlT0EE7oKjRasl+WyVwM0IBlpKgQ= github.com/libp2p/go-libp2p-autonat v0.1.0 h1:aCWAu43Ri4nU0ZPO7NyLzUvvfqd0nE3dX0R/ZGYVgOU= github.com/libp2p/go-libp2p-autonat v0.1.0/go.mod h1:1tLf2yXxiE/oKGtDwPYWTSYG3PtvYlJmg7NeVtPRqH8= +github.com/libp2p/go-libp2p-autonat v0.1.1 h1:WLBZcIRsjZlWdAZj9CiBSvU2wQXoUOiS1Zk1tM7DTJI= +github.com/libp2p/go-libp2p-autonat v0.1.1/go.mod h1:OXqkeGOY2xJVWKAGV2inNF5aKN/djNA3fdpCWloIudE= github.com/libp2p/go-libp2p-blankhost v0.1.1 h1:X919sCh+KLqJcNRApj43xCSiQRYqOSI88Fdf55ngf78= github.com/libp2p/go-libp2p-blankhost v0.1.1/go.mod h1:pf2fvdLJPsC1FsVrNP3DUUvMzUts2dsLLBEpo1vW1ro= github.com/libp2p/go-libp2p-blankhost v0.1.4 h1:I96SWjR4rK9irDHcHq3XHN6hawCRTPUADzkJacgZLvk= github.com/libp2p/go-libp2p-blankhost v0.1.4/go.mod h1:oJF0saYsAXQCSfDq254GMNmLNz6ZTHTOvtF4ZydUvwU= github.com/libp2p/go-libp2p-circuit v0.1.0 h1:eniLL3Y9aq/sryfyV1IAHj5rlvuyj3b7iz8tSiZpdhY= github.com/libp2p/go-libp2p-circuit v0.1.0/go.mod h1:Ahq4cY3V9VJcHcn1SBXjr78AbFkZeIRmfunbA7pmFh8= -github.com/libp2p/go-libp2p-circuit v0.1.3 h1:WsMYYaA0PwdpgJSQu12EzPYf5ypkLSTgcOsWr7DYrgI= github.com/libp2p/go-libp2p-circuit v0.1.3/go.mod h1:Xqh2TjSy8DD5iV2cCOMzdynd6h8OTBGoV1AWbWor3qM= +github.com/libp2p/go-libp2p-circuit v0.1.4 h1:Phzbmrg3BkVzbqd4ZZ149JxCuUWu2wZcXf/Kr6hZJj8= +github.com/libp2p/go-libp2p-circuit v0.1.4/go.mod h1:CY67BrEjKNDhdTk8UgBX1Y/H5c3xkAcs3gnksxY7osU= github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco= github.com/libp2p/go-libp2p-core v0.0.3/go.mod h1:j+YQMNz9WNSkNezXOsahp9kwZBKBvxLpKD316QWSJXE= github.com/libp2p/go-libp2p-core v0.0.4/go.mod h1:jyuCQP356gzfCFtRKyvAbNkyeuxb7OlyhWZ3nls5d2I= github.com/libp2p/go-libp2p-core v0.2.0/go.mod h1:X0eyB0Gy93v0DZtSYbEM7RnMChm9Uv3j7yRXjO77xSI= github.com/libp2p/go-libp2p-core v0.2.2/go.mod h1:8fcwTbsG2B+lTgRJ1ICZtiM5GWCWZVoVrLaDRvIRng0= -github.com/libp2p/go-libp2p-core v0.2.3 h1:zXikZ5pLfebtTMeIYfcwVQ2Pae77O0FIwDquwM6AGNM= github.com/libp2p/go-libp2p-core v0.2.3/go.mod h1:GqhyQqyIAPsxFYXHMjfXgMv03lxsvM0mFzuYA9Ib42A= +github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= +github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ= github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI= github.com/libp2p/go-libp2p-discovery v0.1.0 h1:j+R6cokKcGbnZLf4kcNwpx6mDEUPF3N6SrqMymQhmvs= @@ -364,17 +378,21 @@ github.com/libp2p/go-libp2p-mplex v0.2.1 h1:E1xaJBQnbSiTHGI1gaBKmKhu1TUKkErKJnE8 github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= github.com/libp2p/go-libp2p-nat v0.0.4 h1:+KXK324yaY701On8a0aGjTnw8467kW3ExKcqW2wwmyw= github.com/libp2p/go-libp2p-nat v0.0.4/go.mod h1:N9Js/zVtAXqaeT99cXgTV9e75KpnWCvVOiGzlcHmBbY= +github.com/libp2p/go-libp2p-nat v0.0.5 h1:/mH8pXFVKleflDL1YwqMg27W9GD8kjEx7NY0P6eGc98= +github.com/libp2p/go-libp2p-nat v0.0.5/go.mod h1:1qubaE5bTZMJE+E/uu2URroMbzdubFz1ChgiN79yKPE= github.com/libp2p/go-libp2p-netutil v0.1.0/go.mod h1:3Qv/aDqtMLTUyQeundkKsA+YCThNdbQD54k3TqjpbFU= github.com/libp2p/go-libp2p-peer v0.2.0 h1:EQ8kMjaCUwt/Y5uLgjT8iY2qg0mGUT0N1zUjer50DsY= github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY= github.com/libp2p/go-libp2p-peerstore v0.1.0 h1:MKh7pRNPHSh1fLPj8u/M/s/napdmeNpoi9BRy9lPN0E= github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= -github.com/libp2p/go-libp2p-peerstore v0.1.3 h1:wMgajt1uM2tMiqf4M+4qWKVyyFc8SfA+84VV9glZq1M= github.com/libp2p/go-libp2p-peerstore v0.1.3/go.mod h1:BJ9sHlm59/80oSkpWgr1MyY1ciXAXV397W6h1GH/uKI= +github.com/libp2p/go-libp2p-peerstore v0.1.4 h1:d23fvq5oYMJ/lkkbO4oTwBp/JP+I/1m5gZJobNXCE/k= +github.com/libp2p/go-libp2p-peerstore v0.1.4/go.mod h1:+4BDbDiiKf4PzpANZDAT+knVdLxvqh7hXOujessqdzs= github.com/libp2p/go-libp2p-secio v0.1.0 h1:NNP5KLxuP97sE5Bu3iuwOWyT/dKEGMN5zSLMWdB7GTQ= github.com/libp2p/go-libp2p-secio v0.1.0/go.mod h1:tMJo2w7h3+wN4pgU2LSYeiKPrfqBgkOsdiKK77hE7c8= -github.com/libp2p/go-libp2p-secio v0.2.0 h1:ywzZBsWEEz2KNTn5RtzauEDq5RFEefPsttXYwAWqHng= github.com/libp2p/go-libp2p-secio v0.2.0/go.mod h1:2JdZepB8J5V9mBp79BmwsaPQhRPNN2NrnB2lKQcdy6g= +github.com/libp2p/go-libp2p-secio v0.2.1 h1:eNWbJTdyPA7NxhP7J3c5lT97DC5d+u+IldkgCYFTPVA= +github.com/libp2p/go-libp2p-secio v0.2.1/go.mod h1:cWtZpILJqkqrSkiYcDBh5lA3wbT2Q+hz3rJQq3iftD8= github.com/libp2p/go-libp2p-swarm v0.1.0 h1:HrFk2p0awrGEgch9JXK/qp/hfjqQfgNxpLWnCiWPg5s= github.com/libp2p/go-libp2p-swarm v0.1.0/go.mod h1:wQVsCdjsuZoc730CgOvh5ox6K8evllckjebkdiY5ta4= github.com/libp2p/go-libp2p-swarm v0.2.2 h1:T4hUpgEs2r371PweU3DuH7EOmBIdTBCwWs+FLcgx3bQ= @@ -402,8 +420,12 @@ github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-nat v0.0.3 h1:l6fKV+p0Xa354EqQOQP+d8CivdLM4kl5GxC1hSc/UeI= github.com/libp2p/go-nat v0.0.3/go.mod h1:88nUEt0k0JD45Bk93NIwDqjlhiOwOoV36GchpcVc1yI= +github.com/libp2p/go-nat v0.0.4 h1:KbizNnq8YIf7+Hn7+VFL/xE0eDrkPru2zIO9NMwL8UQ= +github.com/libp2p/go-nat v0.0.4/go.mod h1:Nmw50VAvKuk38jUBcmNh6p9lUJLoODbJRvYAa/+KSDo= github.com/libp2p/go-openssl v0.0.2 h1:9pP2d3Ubaxkv7ZisLjx9BFwgOGnQdQYnfcH29HNY3ls= github.com/libp2p/go-openssl v0.0.2/go.mod h1:v8Zw2ijCSWBQi8Pq5GAixw6DbFfa9u6VIYDXnvOXkc0= +github.com/libp2p/go-openssl v0.0.3 h1:wjlG7HvQkt4Fq4cfH33Ivpwp0omaElYEi9z26qaIkIk= +github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw= github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA= github.com/libp2p/go-reuseport-transport v0.0.2 h1:WglMwyXyBu61CMkjCCtnmqNqnjib0GIEjMiHTwR/KN4= @@ -482,16 +504,18 @@ github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= github.com/multiformats/go-multiaddr-dns v0.0.2 h1:/Bbsgsy3R6e3jf2qBahzNHzww6usYaZ0NhNH3sqdFS8= github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= -github.com/multiformats/go-multiaddr-dns v0.1.0 h1:gsPeMvo91XvcsNlQXgJgfjYjbsVV99bvveguUvDBpyQ= github.com/multiformats/go-multiaddr-dns v0.1.0/go.mod h1:01k2RAqtoXIuPa3DCavAE9/6jc6nM0H3EgZyfUhN2oY= +github.com/multiformats/go-multiaddr-dns v0.2.0 h1:YWJoIDwLePniH7OU5hBnDZV6SWuvJqJ0YtN6pLeH9zA= +github.com/multiformats/go-multiaddr-dns v0.2.0/go.mod h1:TJ5pr5bBO7Y1B18djPuRsVkduhQH2YqYSbxWJzYGdK0= github.com/multiformats/go-multiaddr-fmt v0.0.1 h1:5YjeOIzbX8OTKVaN72aOzGIYW7PnrZrnkDyOfAWRSMA= github.com/multiformats/go-multiaddr-fmt v0.0.1/go.mod h1:aBYjqL4T/7j4Qx+R73XSv/8JsgnRFlf0w2KGLCmXl3Q= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi/ek0E4eiDVbg9g= github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= -github.com/multiformats/go-multiaddr-net v0.1.0 h1:ZepO8Ezwovd+7b5XPPDhQhayk1yt0AJpzQBpq9fejx4= github.com/multiformats/go-multiaddr-net v0.1.0/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= +github.com/multiformats/go-multiaddr-net v0.1.1 h1:jFFKUuXTXv+3ARyHZi3XUqQO+YWMKgBdhEvuGRfnL6s= +github.com/multiformats/go-multiaddr-net v0.1.1/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= @@ -635,6 +659,7 @@ 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/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/status-go v0.38.5/go.mod h1:UKxySGdqFuVPvCyPSYD0+zKeV2OzDijZqICvR+tZ3uM= 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/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE= @@ -730,6 +755,7 @@ golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE= golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4= diff --git a/mailserver/migrations/bindata.go b/mailserver/migrations/bindata.go index a49d84606c2..684df9ce491 100644 --- a/mailserver/migrations/bindata.go +++ b/mailserver/migrations/bindata.go @@ -86,7 +86,7 @@ func _1557732988_initialize_dbDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "1557732988_initialize_db.down.sql", size: 72, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "1557732988_initialize_db.down.sql", size: 72, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x77, 0x40, 0x78, 0xb7, 0x71, 0x3c, 0x20, 0x3b, 0xc9, 0xb, 0x2f, 0x49, 0xe4, 0xff, 0x1c, 0x84, 0x54, 0xa1, 0x30, 0xe3, 0x90, 0xf8, 0x73, 0xda, 0xb0, 0x2a, 0xea, 0x8e, 0xf1, 0x82, 0xe7, 0xd2}} return a, nil } @@ -106,7 +106,7 @@ func _1557732988_initialize_dbUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "1557732988_initialize_db.up.sql", size: 234, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "1557732988_initialize_db.up.sql", size: 234, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8f, 0xa, 0x31, 0xf, 0x94, 0xe, 0xd7, 0xd6, 0xaa, 0x22, 0xd6, 0x6c, 0x7a, 0xbc, 0xad, 0x6a, 0xed, 0x2e, 0x7a, 0xf0, 0x24, 0x81, 0x87, 0x14, 0xe, 0x1c, 0x8a, 0xf1, 0x45, 0xaf, 0x9e, 0x85}} return a, nil } @@ -126,7 +126,7 @@ func staticGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "static.go", size: 178, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "static.go", size: 178, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xab, 0x8a, 0xf4, 0x27, 0x24, 0x9d, 0x2a, 0x1, 0x7b, 0x54, 0xea, 0xae, 0x4a, 0x35, 0x40, 0x92, 0xb5, 0xf9, 0xb3, 0x54, 0x3e, 0x3a, 0x1a, 0x2b, 0xae, 0xfb, 0x9e, 0x82, 0xeb, 0x4c, 0xf, 0x6}} return a, nil } diff --git a/multiaccounts/migrations/bindata.go b/multiaccounts/migrations/bindata.go index eaa9d20d258..2bbf13e53a4 100644 --- a/multiaccounts/migrations/bindata.go +++ b/multiaccounts/migrations/bindata.go @@ -86,7 +86,7 @@ func _0001_accountsDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_accounts.down.sql", size: 21, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "0001_accounts.down.sql", size: 21, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd2, 0x61, 0x4c, 0x18, 0xfc, 0xc, 0xdf, 0x5c, 0x1f, 0x5e, 0xd3, 0xbd, 0xfa, 0x12, 0x5e, 0x8d, 0x8d, 0x8b, 0xb9, 0x5f, 0x99, 0x46, 0x63, 0xa5, 0xe3, 0xa6, 0x8a, 0x4, 0xf1, 0x73, 0x8a, 0xe9}} return a, nil } @@ -106,7 +106,7 @@ func _0001_accountsUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_accounts.up.sql", size: 163, mode: os.FileMode(0644), modTime: time.Unix(1576607640, 0)} + info := bindataFileInfo{name: "0001_accounts.up.sql", size: 163, mode: os.FileMode(0644), modTime: time.Unix(1575903446, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xf2, 0xfa, 0x99, 0x8e, 0x96, 0xb3, 0x13, 0x6c, 0x1f, 0x6, 0x27, 0xc5, 0xd2, 0xd4, 0xe0, 0xa5, 0x26, 0x82, 0xa7, 0x26, 0xf2, 0x68, 0x9d, 0xed, 0x9c, 0x3d, 0xbb, 0xdc, 0x37, 0x28, 0xbc, 0x1}} return a, nil } @@ -126,7 +126,7 @@ func docGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x7c, 0x28, 0xcd, 0x47, 0xf2, 0xfa, 0x7c, 0x51, 0x2d, 0xd8, 0x38, 0xb, 0xb0, 0x34, 0x9d, 0x4c, 0x62, 0xa, 0x9e, 0x28, 0xc3, 0x31, 0x23, 0xd9, 0xbb, 0x89, 0x9f, 0xa0, 0x89, 0x1f, 0xe8}} return a, nil } diff --git a/params/config.go b/params/config.go index 29f736b428a..cc3285b9144 100644 --- a/params/config.go +++ b/params/config.go @@ -515,6 +515,11 @@ type ShhextConfig struct { // DatasyncEnabled indicates whether we should enable dataasync DataSyncEnabled bool + + // VerifyTransactionURL is the URL for verifying transactions. + // IMPORTANT: It should always be mainnet unless used for testing + VerifyTransactionURL string + VerifyTransactionChainID int64 } // Validate validates the ShhextConfig struct and returns an error if inconsistent values are found diff --git a/protocol/chat.go b/protocol/chat.go index 684e1cea884..74600b64d20 100644 --- a/protocol/chat.go +++ b/protocol/chat.go @@ -203,6 +203,13 @@ func oneToOneChatID(publicKey *ecdsa.PublicKey) string { return types.EncodeHex(crypto.FromECDSAPub(publicKey)) } +func OneToOneFromPublicKey(pk *ecdsa.PublicKey) *Chat { + chatID := types.EncodeHex(crypto.FromECDSAPub(pk)) + newChat := CreateOneToOneChat(chatID[:8], pk) + + return &newChat +} + func CreateOneToOneChat(name string, publicKey *ecdsa.PublicKey) Chat { return Chat{ ID: oneToOneChatID(publicKey), @@ -263,6 +270,33 @@ func stringSliceToPublicKeys(slice []string, prefixed bool) ([]*ecdsa.PublicKey, return result, nil } +// NextClockAndTimestamp returns the next clock value +// and the current timestamp +func (c *Chat) NextClockAndTimestamp() (uint64, uint64) { + clock := c.LastClockValue + timestamp := timestampInMs() + if clock == 0 || clock < timestamp { + clock = timestamp + } else { + clock = clock + 1 + } + return clock, timestamp +} + +func (c *Chat) UpdateFromMessage(message *Message) error { + c.Timestamp = int64(timestampInMs()) + if c.LastClockValue <= message.Clock { + jsonMessage, err := json.Marshal(message) + if err != nil { + return err + } + + c.LastClockValue = message.Clock + c.LastMessage = jsonMessage + } + return nil +} + func stringSliceContains(slice []string, item string) bool { for _, s := range slice { if s == item { diff --git a/protocol/contact.go b/protocol/contact.go index 949cc246ae8..cc6c2769f4f 100644 --- a/protocol/contact.go +++ b/protocol/contact.go @@ -48,7 +48,7 @@ type Contact struct { Photo string `json:"photoPath,omitempty"` // LastUpdated is the last time we received an update from the contact // updates should be discarded if last updated is less than the one stored - LastUpdated int64 `json:"lastUpdated"` + LastUpdated uint64 `json:"lastUpdated"` // SystemTags contains information about whether we blocked/added/have been // added. SystemTags []string `json:"systemTags"` diff --git a/protocol/go.mod b/protocol/go.mod index ca0400c3c41..973b203eeff 100644 --- a/protocol/go.mod +++ b/protocol/go.mod @@ -23,6 +23,7 @@ require ( github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a github.com/status-im/doubleratchet v3.0.0+incompatible github.com/status-im/migrate/v4 v4.6.2-status.2 + github.com/status-im/status-go v0.38.5 // indirect github.com/status-im/status-go/eth-node v1.0.0 github.com/status-im/status-go/whisper/v6 v6.0.1 github.com/stretchr/testify v1.4.0 diff --git a/protocol/go.sum b/protocol/go.sum index a146328d3b1..80b5dc96625 100644 --- a/protocol/go.sum +++ b/protocol/go.sum @@ -23,8 +23,10 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/allegro/bigcache v0.0.0-20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/allegro/bigcache v1.1.0/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= @@ -40,6 +42,7 @@ github.com/aristanetworks/goarista v0.0.0-20190219163901-728bce664cf5 h1:L0TwgZQ github.com/aristanetworks/goarista v0.0.0-20190219163901-728bce664cf5/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/aristanetworks/goarista v0.0.0-20190502180301-283422fc1708 h1:tS7jSmwRqSxTnonTRlDD1oHo6Q9YOK4xHS9/v4L56eg= github.com/aristanetworks/goarista v0.0.0-20190502180301-283422fc1708/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= +github.com/aristanetworks/goarista v0.0.0-20191106175434-873d404c7f40 h1:ZdRuixFqR3mfx4FHzclG3COrRgWrYq0VhNgIoYoObcM= github.com/aristanetworks/goarista v0.0.0-20191106175434-873d404c7f40/go.mod h1:Z4RTxGAuYhPzcq8+EdRM+R8M48Ssle2TsWtwRKa+vns= github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -136,6 +139,7 @@ github.com/elastic/gosigar v0.10.5/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTy github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/ethereum/go-ethereum v1.8.20/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= github.com/ethereum/go-ethereum v1.9.2/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= +github.com/ethereum/go-ethereum v1.9.9 h1:jnoBvjH8aMH++iH14XmiJdAsnRcmZUM+B5fsnEZBVE0= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a h1:1znxn4+q2MrEdTk1eCk6KIV3muTYVclBIB6CTVR/zBc= @@ -250,6 +254,7 @@ github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQ github.com/jackpal/go-nat-pmp v0.0.0-20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= @@ -434,11 +439,15 @@ github.com/olekukonko/tablewriter v0.0.0-20170128050532-febf2d34b54a/go.mod h1:v github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -503,6 +512,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= github.com/russolsen/ohyeah v0.0.0-20160324131710-f4938c005315 h1:H3hCXwP92pH/hSgNrCLtjxvsKJ50sq26nICbZuoR1tQ= @@ -517,6 +527,7 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t4 github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= @@ -537,6 +548,7 @@ github.com/status-im/go-ethereum v1.9.5-status.6 h1:ytuTO1yBIAuTVRtRQoc2mrdyngtP github.com/status-im/go-ethereum v1.9.5-status.6/go.mod h1:08JvQWE+IOnAFSe4UD4ACLNe2fDd9XmWMCq5Yzy9mk0= github.com/status-im/go-ethereum v1.9.5-status.7 h1:DKH1GiF52LwaZaw6YDBliFEgm/JDsbIT+hn7ph6X94Q= github.com/status-im/go-ethereum v1.9.5-status.7/go.mod h1:YyH5DKB6+z+Vaya7eIm67pnuPZ1oiUMbbsZW41ktN0g= +github.com/status-im/go-multiaddr-ethv4 v1.2.0/go.mod h1:2VQ3C+9zEurcceasz12gPAtmEzCeyLUGPeKLSXYQKHo= github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 h1:ju5UTwk5Odtm4trrY+4Ca4RMj5OyXbmVeDAVad2T0Jw= github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/keycard-go v0.0.0-20191119114148-6dd40a46baa0 h1:5UdlDkkBoPrJfh7zkfoR3X5utJhNs/MCQysK3x0ycgg= @@ -550,9 +562,14 @@ github.com/status-im/status-go v0.36.0 h1:91qDMJjHv+T3Li9FwxsWQ2JBVcYtvVDT0nGFSM github.com/status-im/status-go v0.36.1 h1:nb9eTq0UQJ57YyTZSl5U05emFT+R4AW8/Bga6ocgOks= github.com/status-im/status-go v0.37.3 h1:94/bOA8qrEIgWd23mSLN39SwUJwCu2TPQFV2HzSI2ZE= github.com/status-im/status-go v0.37.3/go.mod h1:9qHQ2+8NS6ivPJS5YbsI3gWkr0t6DWmJzKnr4M7vudw= +github.com/status-im/status-go v0.38.0 h1:3toC1ToY48wbRBVt7CMWSSG5FZAcPPMlnt0+G6iCbcE= +github.com/status-im/status-go v0.38.0/go.mod h1:u3tlXqVkxAW35dui3LjHajIkbOaF4d4CnriJ8zhntOw= +github.com/status-im/status-go v0.38.5 h1:vnbGgk5+X5ZUmn3/gJ88GlaNaAO9kGVgm8E5mR0umiQ= +github.com/status-im/status-go v0.38.5/go.mod h1:UKxySGdqFuVPvCyPSYD0+zKeV2OzDijZqICvR+tZ3uM= github.com/status-im/status-go/extkeys v1.0.0 h1:Qyirsoi5Ye5UFfisgPtCjPb/RkBxyK+UsSiEcr2PVlM= github.com/status-im/status-go/extkeys v1.0.0/go.mod h1:GdqJbrcpkNm5ZsSCpp+PdMxnXx+OcRBdm3PI0rs1FpU= github.com/status-im/status-go/protocol v1.0.1/go.mod h1:LpA7BsaNmj6EOdq7BwuqncewjPqIRHCletZOb2wlWrY= +github.com/status-im/status-go/waku v1.0.0 h1:XFcJ9Am1cK657dpUP/ysyCp+A99MWSvb1DVTtjo1fE8= github.com/status-im/status-go/waku v1.0.0/go.mod h1:1bjvQAL4cJYtxCsm6DnKdJbxcZwnvvZmxb6pmoUDtuY= 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= @@ -649,6 +666,7 @@ golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIo golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE= golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4= golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -714,6 +732,7 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056 h1:dHtDnRWQtSx0Hjq9kvKFpBh9uPPKfQN70NZZmvssGwk= golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -741,6 +760,7 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 h1:LCmXVkvpQCDj724eX6irUTPCJP5GelFHxqGSWL2D1R0= golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191213032237-7093a17b0467/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.3.2/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= @@ -758,6 +778,7 @@ google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a/go.mod h1:KF9sEfUPAXdG8Oev9e99iLGnl2uJMjc5B+4y3O7x610= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/protocol/message.go b/protocol/message.go index 5b805982dc8..2798336397b 100644 --- a/protocol/message.go +++ b/protocol/message.go @@ -19,13 +19,49 @@ type QuotedMessage struct { Text string `json:"text"` } +type CommandState int + +const ( + CommandStateRequestAddressForTransaction CommandState = iota + 1 + CommandStateRequestAddressForTransactionDeclined + CommandStateRequestAddressForTransactionAccepted + CommandStateRequestTransaction + CommandStateRequestTransactionDeclined + CommandStateTransactionPending + CommandStateTransactionSent +) + +type CommandParameters struct { + // ID is the ID of the initial message + ID string `json:"id"` + // From is the address we are sending the command from + From string `json:"from"` + // Address is the address sent with the command + Address string `json:"address"` + // Contract is the contract address for ERC20 tokens + Contract string `json:"contract"` + // Value is the value as a string sent + Value string `json:"value"` + // TransactionHash is the hash of the transaction + TransactionHash string `json:"transactionHash"` + // CommandState is the state of the command + CommandState CommandState `json:"commandState"` + // The Signature of the pk-bytes+transaction-hash from the wallet + // address originating + Signature []byte `json:"signature"` +} + +func (c *CommandParameters) IsTokenTransfer() bool { + return len(c.Contract) != 0 +} + const ( OutgoingStatusSending = "sending" OutgoingStatusSent = "sent" ) // Message represents a message record in the database, -// more specifically in user_messages_legacy table. +// more specifically in user_messages table. type Message struct { protobuf.ChatMessage @@ -42,70 +78,89 @@ type Message struct { // The chat id to be stored locally LocalChatID string `json:"localChatId"` - RetryCount int `json:"retryCount"` Seen bool `json:"seen"` OutgoingStatus string `json:"outgoingStatus,omitempty"` QuotedMessage *QuotedMessage `json:"quotedMessage"` + // CommandParameters is the parameters sent with the message + CommandParameters *CommandParameters `json:"commandParameters"` + // Computed fields RTL bool `json:"rtl"` ParsedText []byte `json:"parsedText"` LineCount int `json:"lineCount"` + // Replace indicates that this is a replacement of a message + // that has been updated + Replace string `json:"replace,omitEmpty"` SigPubKey *ecdsa.PublicKey `json:"-"` - // RawPayload is the marshaled payload, used for resending the message - RawPayload []byte `json:"-"` +} + +// RawMessage represent a sent or received message, kept for being able +// to re-send/propagate +type RawMessage struct { + ID string + LocalChatID string + LastSent uint64 + SendCount int + Sent bool + ResendAutomatically bool + MessageType protobuf.ApplicationMetadataMessage_Type + Payload []byte + Recipients []*ecdsa.PublicKey } func (m *Message) MarshalJSON() ([]byte, error) { type MessageAlias Message item := struct { - ID string `json:"id"` - WhisperTimestamp uint64 `json:"whisperTimestamp"` - From string `json:"from"` - Alias string `json:"alias"` - Identicon string `json:"identicon"` - RetryCount int `json:"retryCount"` - Seen bool `json:"seen"` - OutgoingStatus string `json:"outgoingStatus,omitempty"` - QuotedMessage *QuotedMessage `json:"quotedMessage"` - RTL bool `json:"rtl"` - ParsedText json.RawMessage `json:"parsedText"` - LineCount int `json:"lineCount"` - Text string `json:"text"` - ChatId string `json:"chatId"` - LocalChatID string `json:"localChatId"` - Clock uint64 `json:"clock"` - ResponseTo string `json:"responseTo"` - EnsName string `json:"ensName"` - Sticker *protobuf.StickerMessage `json:"sticker"` - Timestamp uint64 `json:"timestamp"` - ContentType protobuf.ChatMessage_ContentType `json:"contentType"` - MessageType protobuf.ChatMessage_MessageType `json:"messageType"` + ID string `json:"id"` + WhisperTimestamp uint64 `json:"whisperTimestamp"` + From string `json:"from"` + Alias string `json:"alias"` + Identicon string `json:"identicon"` + Seen bool `json:"seen"` + OutgoingStatus string `json:"outgoingStatus,omitempty"` + QuotedMessage *QuotedMessage `json:"quotedMessage"` + RTL bool `json:"rtl"` + ParsedText json.RawMessage `json:"parsedText"` + LineCount int `json:"lineCount"` + Text string `json:"text"` + ChatId string `json:"chatId"` + LocalChatID string `json:"localChatId"` + Clock uint64 `json:"clock"` + Replace string `json:"replace,omitEmpty"` + ResponseTo string `json:"responseTo"` + EnsName string `json:"ensName"` + Sticker *protobuf.StickerMessage `json:"sticker"` + CommandParameters *CommandParameters `json:"commandParameters"` + Timestamp uint64 `json:"timestamp"` + ContentType protobuf.ChatMessage_ContentType `json:"contentType"` + MessageType protobuf.ChatMessage_MessageType `json:"messageType"` }{ - ID: m.ID, - WhisperTimestamp: m.WhisperTimestamp, - From: m.From, - Alias: m.Alias, - Identicon: m.Identicon, - RetryCount: m.RetryCount, - Seen: m.Seen, - OutgoingStatus: m.OutgoingStatus, - QuotedMessage: m.QuotedMessage, - RTL: m.RTL, - ParsedText: m.ParsedText, - LineCount: m.LineCount, - Text: m.Text, - ChatId: m.ChatId, - LocalChatID: m.LocalChatID, - Clock: m.Clock, - ResponseTo: m.ResponseTo, - EnsName: m.EnsName, - Timestamp: m.Timestamp, - ContentType: m.ContentType, - MessageType: m.MessageType, - Sticker: m.GetSticker(), + ID: m.ID, + WhisperTimestamp: m.WhisperTimestamp, + From: m.From, + Alias: m.Alias, + Identicon: m.Identicon, + Seen: m.Seen, + OutgoingStatus: m.OutgoingStatus, + QuotedMessage: m.QuotedMessage, + RTL: m.RTL, + ParsedText: m.ParsedText, + LineCount: m.LineCount, + Text: m.Text, + Replace: m.Replace, + ChatId: m.ChatId, + LocalChatID: m.LocalChatID, + Clock: m.Clock, + ResponseTo: m.ResponseTo, + EnsName: m.EnsName, + Timestamp: m.Timestamp, + ContentType: m.ContentType, + MessageType: m.MessageType, + Sticker: m.GetSticker(), + CommandParameters: m.CommandParameters, } return json.Marshal(item) diff --git a/protocol/message_builder.go b/protocol/message_builder.go new file mode 100644 index 00000000000..2c4f48882c8 --- /dev/null +++ b/protocol/message_builder.go @@ -0,0 +1,39 @@ +package protocol + +import ( + "crypto/ecdsa" + + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/protocol/identity/alias" + "github.com/status-im/status-go/protocol/identity/identicon" +) + +func extendMessageFromChat(message *Message, chat *Chat, key *ecdsa.PublicKey) error { + clock, timestamp := chat.NextClockAndTimestamp() + + message.LocalChatID = chat.ID + message.Clock = clock + message.Timestamp = timestamp + message.From = types.EncodeHex(crypto.FromECDSAPub(key)) + message.SigPubKey = key + message.WhisperTimestamp = timestamp + message.Seen = true + message.OutgoingStatus = OutgoingStatusSending + + identicon, err := identicon.GenerateBase64(message.From) + if err != nil { + return err + } + + message.Identicon = identicon + + alias, err := alias.GenerateFromPublicKeyString(message.From) + if err != nil { + return err + } + + message.Alias = alias + return nil + +} diff --git a/protocol/message_handler.go b/protocol/message_handler.go index 171ad0b0c03..bbcfcd20222 100644 --- a/protocol/message_handler.go +++ b/protocol/message_handler.go @@ -1,46 +1,625 @@ package protocol import ( + "crypto/ecdsa" + "encoding/hex" "github.com/pkg/errors" + "go.uber.org/zap" + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/protocol/encryption/multidevice" "github.com/status-im/status-go/protocol/protobuf" v1protocol "github.com/status-im/status-go/protocol/v1" ) +type MessageHandler struct { + identity *ecdsa.PrivateKey + persistence *sqlitePersistence + logger *zap.Logger +} + +func newMessageHandler(identity *ecdsa.PrivateKey, logger *zap.Logger, persistence *sqlitePersistence) *MessageHandler { + return &MessageHandler{ + identity: identity, + persistence: persistence, + logger: logger} +} + // HandleMembershipUpdate updates a Chat instance according to the membership updates. // It retrieves chat, if exists, and merges membership updates from the message. // Finally, the Chat is updated with the new group events. -func HandleMembershipUpdate(chat *Chat, m *v1protocol.MembershipUpdateMessage, myIdentity string, translations map[protobuf.MembershipUpdateEvent_EventType]string) (*Chat, []*Message, error) { +func (m *MessageHandler) HandleMembershipUpdate(messageState *ReceivedMessageState, chat *Chat, rawMembershipUpdate protobuf.MembershipUpdateMessage, translations map[protobuf.MembershipUpdateEvent_EventType]string) error { + var group *v1protocol.Group + var err error + + message, err := v1protocol.MembershipUpdateMessageFromProtobuf(&rawMembershipUpdate) + if err != nil { + return err + + } + if chat == nil { - if len(m.Events) == 0 { - return nil, nil, errors.New("can't create new group chat without events") + if len(message.Events) == 0 { + return errors.New("can't create new group chat without events") } - group, err := v1protocol.NewGroupWithEvents(m.ChatID, m.Events) + group, err = v1protocol.NewGroupWithEvents(message.ChatID, message.Events) if err != nil { - return nil, nil, err + return err } // A new chat must contain us - if !group.IsMember(myIdentity) { - return nil, nil, errors.New("can't create a new group chat without us being a member") + if !group.IsMember(types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey))) { + return errors.New("can't create a new group chat without us being a member") } newChat := createGroupChat() - newChat.updateChatFromProtocolGroup(group) - return &newChat, buildSystemMessages(m.Events, translations), nil + chat = &newChat + + } else { + existingGroup, err := newProtocolGroupFromChat(chat) + if err != nil { + return errors.Wrap(err, "failed to create a Group from Chat") + } + updateGroup, err := v1protocol.NewGroupWithEvents(message.ChatID, message.Events) + if err != nil { + return errors.Wrap(err, "invalid membership update") + } + merged := v1protocol.MergeMembershipUpdateEvents(existingGroup.Events(), updateGroup.Events()) + group, err = v1protocol.NewGroup(chat.ID, merged) + if err != nil { + return errors.Wrap(err, "failed to create a group with new membership updates") + } + } + + chat.updateChatFromProtocolGroup(group) + systemMessages := buildSystemMessages(message.Events, translations) + + for _, message := range systemMessages { + messageID := message.ID + exists, err := m.messageExists(messageID, messageState.ExistingMessagesMap) + if err != nil { + m.logger.Warn("failed to check message exists", zap.Error(err)) + } + if exists { + continue + } + messageState.Response.Messages = append(messageState.Response.Messages, message) + } + + // Store in chats map as it might be a new one + messageState.AllChats[chat.ID] = chat + // Set in the map + messageState.ModifiedChats[chat.ID] = true + + if message.Message != nil { + messageState.CurrentMessageState.Message = *message.Message + return m.HandleChatMessage(messageState) } - existingGroup, err := newProtocolGroupFromChat(chat) + + return nil +} + +func (m *MessageHandler) handleCommandMessage(state *ReceivedMessageState, message *Message) error { + message.ID = state.CurrentMessageState.MessageID + message.From = state.CurrentMessageState.Contact.ID + message.Alias = state.CurrentMessageState.Contact.Alias + message.SigPubKey = state.CurrentMessageState.PublicKey + message.Identicon = state.CurrentMessageState.Contact.Identicon + message.WhisperTimestamp = state.CurrentMessageState.WhisperTimestamp + + message.PrepareContent() + chat, err := m.matchMessage(message, state.AllChats) if err != nil { - return nil, nil, errors.Wrap(err, "failed to create a Group from Chat") + return err } - updateGroup, err := v1protocol.NewGroupWithEvents(m.ChatID, m.Events) + + // If deleted-at is greater, ignore message + if chat.DeletedAtClockValue >= message.Clock { + return nil + } + + // Set the LocalChatID for the message + message.LocalChatID = chat.ID + + if c, ok := state.AllChats[chat.ID]; ok { + chat = c + } + + // Set the LocalChatID for the message + message.LocalChatID = chat.ID + + // Increase unviewed count + if !isPubKeyEqual(message.SigPubKey, &m.identity.PublicKey) { + chat.UnviewedMessagesCount++ + message.OutgoingStatus = "" + } else { + // Our own message, mark as sent + message.OutgoingStatus = OutgoingStatusSent + } + + err = chat.UpdateFromMessage(message) if err != nil { - return nil, nil, errors.Wrap(err, "invalid membership update") + return err } - merged := v1protocol.MergeMembershipUpdateEvents(existingGroup.Events(), updateGroup.Events()) - newGroup, err := v1protocol.NewGroup(chat.ID, merged) + + // Set chat active + chat.Active = true + // Set in the modified maps chat + state.ModifiedChats[chat.ID] = true + state.AllChats[chat.ID] = chat + + // Add to response + if message != nil { + state.Response.Messages = append(state.Response.Messages, message) + } + return nil +} + +func (m *MessageHandler) HandleSyncInstallationContact(state *ReceivedMessageState, message protobuf.SyncInstallationContact) error { + chat, ok := state.AllChats[state.CurrentMessageState.Contact.ID] + if !ok { + chat = OneToOneFromPublicKey(state.CurrentMessageState.PublicKey) + // We don't want to show the chat to the user + chat.Active = false + } + + contact, ok := state.AllContacts[message.Id] + if !ok { + publicKeyBytes, err := hex.DecodeString(message.Id[2:]) + if err != nil { + return err + } + publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes) + if err != nil { + return err + } + contact, err = buildContact(publicKey) + if err != nil { + return err + } + } + + if contact.LastUpdated < message.Clock { + if !contact.IsAdded() { + contact.SystemTags = append(contact.SystemTags, contactAdded) + } + if contact.Name != message.EnsName { + contact.Name = message.EnsName + contact.ENSVerified = false + } + contact.Photo = message.ProfileImage + contact.LastUpdated = message.Clock + state.ModifiedContacts[contact.ID] = true + state.AllContacts[contact.ID] = contact + } + + state.AllChats[chat.ID] = chat + + return nil +} + +func (m *MessageHandler) HandleContactUpdate(state *ReceivedMessageState, message protobuf.ContactUpdate) error { + logger := m.logger.With(zap.String("site", "HandleContactUpdate")) + contact := state.CurrentMessageState.Contact + chat, ok := state.AllChats[contact.ID] + if !ok { + chat = OneToOneFromPublicKey(state.CurrentMessageState.PublicKey) + // We don't want to show the chat to the user + chat.Active = false + } + + logger.Info("Handling contact update") + + if contact.LastUpdated < message.Clock { + logger.Info("Updating contact") + if !contact.HasBeenAdded() { + contact.SystemTags = append(contact.SystemTags, contactRequestReceived) + } + if contact.Name != message.EnsName { + contact.Name = message.EnsName + contact.ENSVerified = false + } + contact.Photo = message.ProfileImage + contact.LastUpdated = message.Clock + state.ModifiedContacts[contact.ID] = true + state.AllContacts[contact.ID] = contact + } + + if chat.LastClockValue < message.Clock { + chat.LastClockValue = message.Clock + } + + state.ModifiedChats[chat.ID] = true + state.AllChats[chat.ID] = chat + + return nil +} + +func (m *MessageHandler) HandlePairInstallation(state *ReceivedMessageState, message protobuf.PairInstallation) error { + logger := m.logger.With(zap.String("site", "HandlePairInstallation")) + if err := ValidateReceivedPairInstallation(&message); err != nil { + logger.Warn("failed to validate message", zap.Error(err)) + return err + } + + installation, ok := state.AllInstallations[message.InstallationId] + if !ok { + return errors.New("installation not found") + } + + metadata := &multidevice.InstallationMetadata{ + Name: message.Name, + DeviceType: message.DeviceType, + } + + installation.InstallationMetadata = metadata + state.AllInstallations[message.InstallationId] = installation + state.ModifiedInstallations[message.InstallationId] = true + + return nil +} + +func (m *MessageHandler) HandleChatMessage(state *ReceivedMessageState) error { + logger := m.logger.With(zap.String("site", "handleChatMessage")) + if err := ValidateReceivedChatMessage(&state.CurrentMessageState.Message); err != nil { + logger.Warn("failed to validate message", zap.Error(err)) + return err + } + receivedMessage := &Message{ + ID: state.CurrentMessageState.MessageID, + ChatMessage: state.CurrentMessageState.Message, + From: state.CurrentMessageState.Contact.ID, + Alias: state.CurrentMessageState.Contact.Alias, + SigPubKey: state.CurrentMessageState.PublicKey, + Identicon: state.CurrentMessageState.Contact.Identicon, + WhisperTimestamp: state.CurrentMessageState.WhisperTimestamp, + } + + receivedMessage.PrepareContent() + chat, err := m.matchMessage(receivedMessage, state.AllChats) + if err != nil { + return err + } + + // If deleted-at is greater, ignore message + if chat.DeletedAtClockValue >= receivedMessage.Clock { + return nil + } + + // Set the LocalChatID for the message + receivedMessage.LocalChatID = chat.ID + + if c, ok := state.AllChats[chat.ID]; ok { + chat = c + } + + // Set the LocalChatID for the message + receivedMessage.LocalChatID = chat.ID + + // Increase unviewed count + if !isPubKeyEqual(receivedMessage.SigPubKey, &m.identity.PublicKey) { + chat.UnviewedMessagesCount++ + } else { + // Our own message, mark as sent + receivedMessage.OutgoingStatus = OutgoingStatusSent + } + + err = chat.UpdateFromMessage(receivedMessage) if err != nil { - return nil, nil, errors.Wrap(err, "failed to create a group with new membership updates") + return err + } + + // Set chat active + chat.Active = true + // Set in the modified maps chat + state.ModifiedChats[chat.ID] = true + state.AllChats[chat.ID] = chat + + // Add to response + if receivedMessage != nil { + state.Response.Messages = append(state.Response.Messages, receivedMessage) + } + + return nil +} + +func (m *MessageHandler) HandleRequestAddressForTransaction(messageState *ReceivedMessageState, command protobuf.RequestAddressForTransaction) error { + err := ValidateReceivedRequestAddressForTransaction(&command) + if err != nil { + return err + } + message := &Message{ + ChatMessage: protobuf.ChatMessage{ + Clock: command.Clock, + Timestamp: messageState.CurrentMessageState.WhisperTimestamp, + Text: "Request address for transaction", + ChatId: types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)), + MessageType: protobuf.ChatMessage_ONE_TO_ONE, + ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND, + }, + CommandParameters: &CommandParameters{ + ID: messageState.CurrentMessageState.MessageID, + Value: command.Value, + Contract: command.Contract, + CommandState: CommandStateRequestAddressForTransaction, + }, + } + return m.handleCommandMessage(messageState, message) +} + +func (m *MessageHandler) HandleRequestTransaction(messageState *ReceivedMessageState, command protobuf.RequestTransaction) error { + err := ValidateReceivedRequestTransaction(&command) + if err != nil { + return err + } + message := &Message{ + ChatMessage: protobuf.ChatMessage{ + Clock: command.Clock, + Timestamp: messageState.CurrentMessageState.WhisperTimestamp, + Text: "Request transaction", + ChatId: types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)), + MessageType: protobuf.ChatMessage_ONE_TO_ONE, + ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND, + }, + CommandParameters: &CommandParameters{ + ID: messageState.CurrentMessageState.MessageID, + Value: command.Value, + Contract: command.Contract, + CommandState: CommandStateRequestTransaction, + Address: command.Address, + }, + } + return m.handleCommandMessage(messageState, message) +} + +func (m *MessageHandler) HandleAcceptRequestAddressForTransaction(messageState *ReceivedMessageState, command protobuf.AcceptRequestAddressForTransaction) error { + err := ValidateReceivedAcceptRequestAddressForTransaction(&command) + if err != nil { + return err + } + initialMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if initialMessage == nil { + return errors.New("message not found") + } + + if initialMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if initialMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if initialMessage.CommandParameters.CommandState != CommandStateRequestAddressForTransaction { + return errors.New("Wrong state for command") + } + + initialMessage.Clock = command.Clock + initialMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + initialMessage.Text = "Request address for transaction accepted" + initialMessage.CommandParameters.Address = command.Address + initialMessage.CommandParameters.CommandState = CommandStateRequestAddressForTransactionAccepted + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(command.Id) + if err != nil && err != errRecordNotFound { + return err + } + + if previousMessage != nil { + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return err + } + + initialMessage.Replace = previousMessage.ID + } + + return m.handleCommandMessage(messageState, initialMessage) +} + +func (m *MessageHandler) HandleSendTransaction(messageState *ReceivedMessageState, command protobuf.SendTransaction) error { + err := ValidateReceivedSendTransaction(&command) + if err != nil { + return err + } + transactionToValidate := &TransactionToValidate{ + MessageID: messageState.CurrentMessageState.MessageID, + CommandID: command.Id, + TransactionHash: command.TransactionHash, + FirstSeen: messageState.CurrentMessageState.WhisperTimestamp, + Signature: command.Signature, + Validate: true, + From: messageState.CurrentMessageState.PublicKey, + RetryCount: 0, + } + m.logger.Info("Saving transction to validate", zap.Any("transaction", transactionToValidate)) + + return m.persistence.SaveTransactionToValidate(transactionToValidate) +} + +func (m *MessageHandler) HandleDeclineRequestAddressForTransaction(messageState *ReceivedMessageState, command protobuf.DeclineRequestAddressForTransaction) error { + err := ValidateReceivedDeclineRequestAddressForTransaction(&command) + if err != nil { + return err + } + oldMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if oldMessage == nil { + return errors.New("message not found") + } + + if oldMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if oldMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if oldMessage.CommandParameters.CommandState != CommandStateRequestAddressForTransaction { + return errors.New("Wrong state for command") + } + + oldMessage.Clock = command.Clock + oldMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + oldMessage.Text = "Request address for transaction declined" + oldMessage.CommandParameters.CommandState = CommandStateRequestAddressForTransactionDeclined + + // Hide previous message + err = m.persistence.HideMessage(command.Id) + if err != nil { + return err + } + oldMessage.Replace = command.Id + + return m.handleCommandMessage(messageState, oldMessage) +} + +func (m *MessageHandler) HandleDeclineRequestTransaction(messageState *ReceivedMessageState, command protobuf.DeclineRequestTransaction) error { + err := ValidateReceivedDeclineRequestTransaction(&command) + if err != nil { + return err + } + oldMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if oldMessage == nil { + return errors.New("message not found") + } + + if oldMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if oldMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if oldMessage.CommandParameters.CommandState != CommandStateRequestTransaction { + return errors.New("Wrong state for command") + } + + oldMessage.Clock = command.Clock + oldMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + oldMessage.Text = "Transaction request declined" + oldMessage.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + // Hide previous message + err = m.persistence.HideMessage(command.Id) + if err != nil { + return err + } + oldMessage.Replace = command.Id + + return m.handleCommandMessage(messageState, oldMessage) +} + +func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat) (*Chat, error) { + if message.SigPubKey == nil { + m.logger.Error("public key can't be empty") + return nil, errors.New("received a message with empty public key") + } + + switch { + case message.MessageType == protobuf.ChatMessage_PUBLIC_GROUP: + // For public messages, all outgoing and incoming messages have the same chatID + // equal to a public chat name. + chatID := message.ChatId + chat := chats[chatID] + if chat == nil { + return nil, errors.New("received a public message from non-existing chat") + } + return chat, nil + case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE && isPubKeyEqual(message.SigPubKey, &m.identity.PublicKey): + // It's a private message coming from us so we rely on Message.ChatId + // If chat does not exist, it should be created to support multidevice synchronization. + chatID := message.ChatId + chat := chats[chatID] + if chat == nil { + if len(chatID) != PubKeyStringLength { + return nil, errors.New("invalid pubkey length") + } + bytePubKey, err := hex.DecodeString(chatID[2:]) + if err != nil { + return nil, errors.Wrap(err, "failed to decode hex chatID") + } + + pubKey, err := crypto.UnmarshalPubkey(bytePubKey) + if err != nil { + return nil, errors.Wrap(err, "failed to decode pubkey") + } + + newChat := CreateOneToOneChat(chatID[:8], pubKey) + chat = &newChat + } + return chat, nil + case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE: + // It's an incoming private message. ChatID is calculated from the signature. + // If a chat does not exist, a new one is created and saved. + chatID := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) + chat := chats[chatID] + if chat == nil { + // TODO: this should be a three-word name used in the mobile client + newChat := CreateOneToOneChat(chatID[:8], message.SigPubKey) + chat = &newChat + } + return chat, nil + case message.MessageType == protobuf.ChatMessage_PRIVATE_GROUP: + // In the case of a group message, ChatID is the same for all messages belonging to a group. + // It needs to be verified if the signature public key belongs to the chat. + chatID := message.ChatId + chat := chats[chatID] + if chat == nil { + return nil, errors.New("received group chat message for non-existing chat") + } + + theirKeyHex := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) + myKeyHex := types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)) + var theyJoined bool + var iJoined bool + for _, member := range chat.Members { + if member.ID == theirKeyHex && member.Joined { + theyJoined = true + } + } + for _, member := range chat.Members { + if member.ID == myKeyHex && member.Joined { + iJoined = true + } + } + + if theyJoined && iJoined { + return chat, nil + } + + return nil, errors.New("did not find a matching group chat") + default: + return nil, errors.New("can not match a chat because there is no valid case") + } +} + +func (m *MessageHandler) messageExists(messageID string, existingMessagesMap map[string]bool) (bool, error) { + if _, ok := existingMessagesMap[messageID]; ok { + return true, nil + } + + existingMessagesMap[messageID] = true + + // Check against the database, this is probably a bit slow for + // each message, but for now might do, we'll make it faster later + existingMessage, err := m.persistence.MessageByID(messageID) + if err != nil && err != errRecordNotFound { + return false, err + } + if existingMessage != nil { + return true, nil } - chat.updateChatFromProtocolGroup(newGroup) - return chat, buildSystemMessages(m.Events, translations), nil + return false, nil } diff --git a/protocol/message_processor.go b/protocol/message_processor.go index 16011cf6236..f72f10880b9 100644 --- a/protocol/message_processor.go +++ b/protocol/message_processor.go @@ -171,13 +171,40 @@ func (p *messageProcessor) sendPrivate( return messageID, nil } -func (p *messageProcessor) SendMembershipUpdate( +// sendPairInstallation sends data to the recipients, using DH +func (p *messageProcessor) SendPairInstallation( ctx context.Context, - recipients []*ecdsa.PublicKey, + recipient *ecdsa.PublicKey, + data []byte, + messageType protobuf.ApplicationMetadataMessage_Type, +) ([]byte, error) { + p.logger.Debug("sending private message", zap.Binary("recipient", crypto.FromECDSAPub(recipient))) + + wrappedMessage, err := p.wrapMessageV1(data, messageType) + if err != nil { + return nil, errors.Wrap(err, "failed to wrap message") + } + + messageSpec, err := p.protocol.BuildDHMessage(p.identity, recipient, wrappedMessage) + if err != nil { + return nil, errors.Wrap(err, "failed to encrypt message") + } + + hash, newMessage, err := p.sendMessageSpec(ctx, recipient, messageSpec) + if err != nil { + return nil, errors.Wrap(err, "failed to send a message spec") + } + + messageID := v1protocol.MessageID(&p.identity.PublicKey, wrappedMessage) + p.transport.Track([][]byte{messageID}, hash, newMessage) + + return messageID, nil +} + +func (p *messageProcessor) EncodeMembershipUpdate( group *v1protocol.Group, chatMessage *protobuf.ChatMessage, ) ([]byte, error) { - p.logger.Debug("sending a membership update", zap.Int("membersCount", len(recipients))) message := v1protocol.MembershipUpdateMessage{ ChatID: group.ChatID(), @@ -189,7 +216,7 @@ func (p *messageProcessor) SendMembershipUpdate( return nil, errors.Wrap(err, "failed to encode membership update message") } - return p.SendGroupRaw(ctx, recipients, encodedMessage, protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE) + return encodedMessage, nil } // SendPublicRaw takes encoded data, encrypts it and sends through the wire. diff --git a/protocol/message_validator.go b/protocol/message_validator.go index 43e51291987..682cc604709 100644 --- a/protocol/message_validator.go +++ b/protocol/message_validator.go @@ -2,46 +2,165 @@ package protocol import ( "errors" + "strconv" "strings" "github.com/status-im/status-go/protocol/protobuf" ) +func ValidateReceivedPairInstallation(message *protobuf.PairInstallation) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.Name)) == 0 { + return errors.New("name can't be empty") + } + + if len(strings.TrimSpace(message.DeviceType)) == 0 { + return errors.New("device type can't be empty") + } + + if len(strings.TrimSpace(message.InstallationId)) == 0 { + return errors.New("installationId can't be empty") + } + + return nil +} + +func ValidateReceivedSendTransaction(message *protobuf.SendTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.TransactionHash)) == 0 { + return errors.New("transaction hash can't be empty") + } + + if message.Signature == nil { + return errors.New("signature can't be nil") + } + + return nil +} + +func ValidateReceivedRequestAddressForTransaction(message *protobuf.RequestAddressForTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.Value)) == 0 { + return errors.New("value can't be empty") + } + + _, err := strconv.ParseFloat(message.Value, 64) + if err != nil { + return err + } + + return nil +} + +func ValidateReceivedRequestTransaction(message *protobuf.RequestTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.Value)) == 0 { + return errors.New("value can't be empty") + } + + if len(strings.TrimSpace(message.Address)) == 0 { + return errors.New("address can't be empty") + } + + _, err := strconv.ParseFloat(message.Value, 64) + if err != nil { + return err + } + + return nil +} + +func ValidateReceivedAcceptRequestAddressForTransaction(message *protobuf.AcceptRequestAddressForTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("messageID can't be empty") + } + + if len(strings.TrimSpace(message.Address)) == 0 { + return errors.New("address can't be empty") + } + + return nil +} + +func ValidateReceivedDeclineRequestAddressForTransaction(message *protobuf.DeclineRequestAddressForTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("messageID can't be empty") + } + + return nil +} + +func ValidateReceivedDeclineRequestTransaction(message *protobuf.DeclineRequestTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("messageID can't be empty") + } + + return nil +} + func ValidateReceivedChatMessage(message *protobuf.ChatMessage) error { if message.Clock == 0 { - return errors.New("Clock can't be 0") + return errors.New("clock can't be 0") } if message.Timestamp == 0 { - return errors.New("Timestamp can't be 0") + return errors.New("timestamp can't be 0") } if len(strings.TrimSpace(message.Text)) == 0 { - return errors.New("Text can't be empty") + return errors.New("text can't be empty") } if len(message.ChatId) == 0 { - return errors.New("ChatId can't be empty") + return errors.New("chatId can't be empty") } if message.ContentType == protobuf.ChatMessage_UNKNOWN_CONTENT_TYPE { - return errors.New("Unknown content type") + return errors.New("unknown content type") + } + + if message.ContentType == protobuf.ChatMessage_TRANSACTION_COMMAND { + return errors.New("can't receive request address for transaction from others") } if message.MessageType == protobuf.ChatMessage_UNKNOWN_MESSAGE_TYPE || message.MessageType == protobuf.ChatMessage_SYSTEM_MESSAGE_PRIVATE_GROUP { - return errors.New("Unknown message type") + return errors.New("unknown message type") } if message.ContentType == protobuf.ChatMessage_STICKER { if message.Payload == nil { - return errors.New("No sticker content") + return errors.New("no sticker content") } sticker := message.GetSticker() if sticker == nil { - return errors.New("No sticker content") + return errors.New("no sticker content") } if len(sticker.Hash) == 0 { - return errors.New("Sticker hash not set") + return errors.New("sticker hash not set") } } return nil diff --git a/protocol/message_validator_test.go b/protocol/message_validator_test.go index a9292a43fbc..e3688ee7edd 100644 --- a/protocol/message_validator_test.go +++ b/protocol/message_validator_test.go @@ -16,6 +16,60 @@ func TestMessageValidatorSuite(t *testing.T) { suite.Run(t, new(MessageValidatorSuite)) } +func (s *MessageValidatorSuite) TestValidateRequestAddressForTransaction() { + testCases := []struct { + Name string + Valid bool + Message protobuf.RequestAddressForTransaction + }{ + { + Name: "valid message", + Valid: true, + Message: protobuf.RequestAddressForTransaction{ + Clock: 30, + Value: "0.34", + Contract: "some contract", + }, + }, + { + Name: "missing clock value", + Valid: false, + Message: protobuf.RequestAddressForTransaction{ + Value: "0.34", + Contract: "some contract", + }, + }, + { + Name: "missing value", + Valid: false, + Message: protobuf.RequestAddressForTransaction{ + Clock: 30, + Contract: "some contract", + }, + }, + { + Name: "non number value", + Valid: false, + Message: protobuf.RequestAddressForTransaction{ + Clock: 30, + Value: "most definitely not a number", + Contract: "some contract", + }, + }, + } + for _, tc := range testCases { + s.Run(tc.Name, func() { + err := ValidateReceivedRequestAddressForTransaction(&tc.Message) + if tc.Valid { + s.Nil(err) + } else { + s.NotNil(err) + } + }) + } + +} + func (s *MessageValidatorSuite) TestValidatePlainTextMessage() { testCases := []struct { Name string @@ -144,6 +198,20 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() { ContentType: protobuf.ChatMessage_TEXT_PLAIN, }, }, + { + Name: "Request address for transaction message type", + Valid: false, + Message: protobuf.ChatMessage{ + ChatId: "a", + Text: "valid", + Clock: 2, + Timestamp: 3, + ResponseTo: "", + EnsName: "", + MessageType: protobuf.ChatMessage_ONE_TO_ONE, + ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND, + }, + }, { Name: "Valid emoji only emssage", Valid: true, @@ -194,25 +262,6 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() { ContentType: protobuf.ChatMessage_STICKER, }, }, - { - Name: "Invalid sticker message without Pack", - Valid: false, - Message: protobuf.ChatMessage{ - ChatId: "a", - Text: "valid", - Clock: 2, - Timestamp: 3, - ResponseTo: "", - EnsName: "", - Payload: &protobuf.ChatMessage_Sticker{ - Sticker: &protobuf.StickerMessage{ - Hash: "some-hash", - }, - }, - MessageType: protobuf.ChatMessage_ONE_TO_ONE, - ContentType: protobuf.ChatMessage_STICKER, - }, - }, { Name: "Invalid sticker message without Hash", Valid: false, diff --git a/protocol/messenger.go b/protocol/messenger.go index 6de0caa226b..95cbec00243 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -4,8 +4,6 @@ import ( "context" "crypto/ecdsa" "database/sql" - "encoding/hex" - "encoding/json" "math/rand" "sync" "time" @@ -52,14 +50,20 @@ type Messenger struct { transport *transport.WhisperServiceTransport encryptor *encryption.Protocol processor *messageProcessor + handler *MessageHandler logger *zap.Logger + verifyTransactionClient EthClient featureFlags featureFlags messagesPersistenceEnabled bool shutdownTasks []func() error systemMessagesTranslations map[protobuf.MembershipUpdateEvent_EventType]string allChats map[string]*Chat allContacts map[string]*Contact - mutex sync.Mutex + allInstallations map[string]*multidevice.Installation + modifiedInstallations map[string]bool + installationID string + + mutex sync.Mutex } type RawResponse struct { @@ -68,9 +72,10 @@ type RawResponse struct { } type MessengerResponse struct { - Chats []*Chat `json:"chats,omitEmpty"` - Messages []*Message `json:"messages,omitEmpty"` - Contacts []*Contact `json:"contacts,omitEmpty"` + Chats []*Chat `json:"chats,omitEmpty"` + Messages []*Message `json:"messages,omitEmpty"` + Contacts []*Contact `json:"contacts,omitEmpty"` + Installations []*multidevice.Installation `json:"installations,omitEmpty"` // Raw unprocessed messages RawMessages []*RawResponse `json:"rawMessages,omitEmpty"` } @@ -92,7 +97,6 @@ type dbConfig struct { } type config struct { - onNewInstallationsHandler func([]*multidevice.Installation) // This needs to be exposed until we move here mailserver logic // as otherwise the client is not notified of a new filter and // won't be pulling messages from mailservers until it reloads the chats/filters @@ -113,18 +117,13 @@ type config struct { dbConfig dbConfig db *sql.DB + verifyTransactionClient EthClient + logger *zap.Logger } type Option func(*config) error -func WithOnNewInstallationsHandler(h func([]*multidevice.Installation)) Option { - return func(c *config) error { - c.onNewInstallationsHandler = h - return nil - } -} - func WithSystemMessagesTranslations(t map[protobuf.MembershipUpdateEvent_EventType]string) Option { return func(c *config) error { c.systemMessagesTranslations = t @@ -160,6 +159,13 @@ func WithDatabaseConfig(dbPath, dbKey string) Option { } } +func WithVerifyTransactionClient(client EthClient) Option { + return func(c *config) error { + c.verifyTransactionClient = client + return nil + } +} + func WithDatabase(db *sql.DB) Option { return func(c *config) error { c.db = db @@ -210,18 +216,18 @@ func NewMessenger( } } - // Set default config fields. - if c.onNewInstallationsHandler == nil { - c.onNewInstallationsHandler = func(installations []*multidevice.Installation) { - sugar := logger.Sugar().With("site", "onNewInstallationsHandler") - for _, installation := range installations { - sugar.Infow( - "received a new installation", - "identity", installation.Identity, - "id", installation.ID) + onNewInstallationsHandler := func(installations []*multidevice.Installation) { + + for _, installation := range installations { + if installation.Identity == types.EncodeHex(crypto.FromECDSAPub(&messenger.identity.PublicKey)) { + if _, ok := messenger.allInstallations[installation.ID]; !ok { + messenger.allInstallations[installation.ID] = installation + messenger.modifiedInstallations[installation.ID] = true + } } } } + // Set default config fields. onNewSharedSecretHandler := func(secrets []*sharedsecret.Secret) { filters, err := messenger.handleSharedSecrets(secrets) if err != nil { @@ -295,7 +301,7 @@ func NewMessenger( encryptionProtocol := encryption.New( database, installationID, - c.onNewInstallationsHandler, + onNewInstallationsHandler, onNewSharedSecretHandler, c.onSendContactCodeHandler, logger, @@ -313,6 +319,8 @@ func NewMessenger( return nil, errors.Wrap(err, "failed to create messageProcessor") } + handler := newMessageHandler(identity, logger, &sqlitePersistence{db: database}) + messenger = &Messenger{ node: node, identity: identity, @@ -320,11 +328,16 @@ func NewMessenger( transport: t, encryptor: encryptionProtocol, processor: processor, + handler: handler, featureFlags: c.featureFlags, systemMessagesTranslations: c.systemMessagesTranslations, allChats: make(map[string]*Chat), allContacts: make(map[string]*Contact), + allInstallations: make(map[string]*multidevice.Installation), + installationID: installationID, + modifiedInstallations: make(map[string]bool), messagesPersistenceEnabled: c.messagesPersistenceEnabled, + verifyTransactionClient: c.verifyTransactionClient, shutdownTasks: []func() error{ database.Close, t.Reset, @@ -416,6 +429,15 @@ func (m *Messenger) Init() error { publicKeys = append(publicKeys, publicKey) } + installations, err := m.encryptor.GetOurInstallations(&m.identity.PublicKey) + if err != nil { + return err + } + + for _, installation := range installations { + m.allInstallations[installation.ID] = installation + } + _, err = m.transport.InitFilters(publicChatIDs, publicKeys) return err } @@ -456,21 +478,70 @@ func (m *Messenger) handleSharedSecrets(secrets []*sharedsecret.Secret) ([]*tran } func (m *Messenger) EnableInstallation(id string) error { - return m.encryptor.EnableInstallation(&m.identity.PublicKey, id) + m.mutex.Lock() + defer m.mutex.Unlock() + + installation, ok := m.allInstallations[id] + if !ok { + return errors.New("no installation found") + } + + err := m.encryptor.EnableInstallation(&m.identity.PublicKey, id) + if err != nil { + return err + } + installation.Enabled = true + m.allInstallations[id] = installation + return nil } func (m *Messenger) DisableInstallation(id string) error { - return m.encryptor.DisableInstallation(&m.identity.PublicKey, id) + m.mutex.Lock() + defer m.mutex.Unlock() + + installation, ok := m.allInstallations[id] + if !ok { + return errors.New("no installation found") + } + + err := m.encryptor.DisableInstallation(&m.identity.PublicKey, id) + if err != nil { + return err + } + installation.Enabled = false + m.allInstallations[id] = installation + return nil } -func (m *Messenger) Installations() ([]*multidevice.Installation, error) { - return m.encryptor.GetOurInstallations(&m.identity.PublicKey) +func (m *Messenger) Installations() []*multidevice.Installation { + m.mutex.Lock() + defer m.mutex.Unlock() + installations := make([]*multidevice.Installation, len(m.allInstallations)) + + var i = 0 + for _, installation := range m.allInstallations { + installations[i] = installation + i++ + } + return installations } -func (m *Messenger) SetInstallationMetadata(id string, data *multidevice.InstallationMetadata) error { +func (m *Messenger) setInstallationMetadata(id string, data *multidevice.InstallationMetadata) error { + installation, ok := m.allInstallations[id] + if !ok { + return errors.New("no installation found") + } + + installation.InstallationMetadata = data return m.encryptor.SetInstallationMetadata(&m.identity.PublicKey, id, data) } +func (m *Messenger) SetInstallationMetadata(id string, data *multidevice.InstallationMetadata) error { + m.mutex.Lock() + defer m.mutex.Unlock() + return m.setInstallationMetadata(id, data) +} + // NOT IMPLEMENTED func (m *Messenger) SelectMailserver(id string) error { return ErrNotImplemented @@ -567,9 +638,24 @@ func (m *Messenger) CreateGroupChatWithMembers(ctx context.Context, name string, return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + m.allChats[chat.ID] = &chat + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{&chat} @@ -613,9 +699,22 @@ func (m *Messenger) RemoveMemberFromGroupChat(ctx context.Context, chatID string if err != nil { return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, oldRecipients, nil); err != nil { + + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: oldRecipients, + ResendAutomatically: true, + }) + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} response.Messages = buildSystemMessages(chat.MembershipUpdates, m.systemMessagesTranslations) @@ -657,9 +756,22 @@ func (m *Messenger) AddMembersToGroupChat(ctx context.Context, chatID string, me return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} @@ -704,9 +816,22 @@ func (m *Messenger) AddAdminsToGroupChat(ctx context.Context, chatID string, mem return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} @@ -754,9 +879,21 @@ func (m *Messenger) ConfirmJoiningGroup(ctx context.Context, chatID string) (*Me return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} @@ -805,9 +942,21 @@ func (m *Messenger) LeaveGroupChat(ctx context.Context, chatID string) (*Messeng return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) chat.Active = false @@ -816,32 +965,6 @@ func (m *Messenger) LeaveGroupChat(ctx context.Context, chatID string) (*Messeng return &response, m.saveChat(chat) } -func (m *Messenger) propagateMembershipUpdates(ctx context.Context, group *v1protocol.Group, recipients []*ecdsa.PublicKey, chatMessage *protobuf.ChatMessage) ([]byte, error) { - hasPairedDevices, err := m.hasPairedDevices() - if err != nil { - return nil, err - } - - if !hasPairedDevices { - // Filter out my key from the recipients - n := 0 - for _, recipient := range recipients { - if !isPubKeyEqual(recipient, &m.identity.PublicKey) { - recipients[n] = recipient - n++ - } - } - recipients = recipients[:n] - } - // Finally send membership updates to all recipients. - return m.processor.SendMembershipUpdate( - ctx, - recipients, - group, - chatMessage, - ) -} - func (m *Messenger) saveChat(chat *Chat) error { err := m.persistence.SaveChat(*chat) if err != nil { @@ -902,10 +1025,12 @@ func (m *Messenger) DeleteChat(chatID string) error { return nil } -func (m *Messenger) SaveContact(contact *Contact) error { - m.mutex.Lock() - defer m.mutex.Unlock() +func (m *Messenger) isNewContact(contact *Contact) bool { + previousContact, ok := m.allContacts[contact.ID] + return contact.IsAdded() && (!ok || !previousContact.IsAdded()) +} +func (m *Messenger) saveContact(contact *Contact) error { identicon, err := identicon.GenerateBase64(contact.ID) if err != nil { return err @@ -920,6 +1045,13 @@ func (m *Messenger) SaveContact(contact *Contact) error { contact.Alias = name + if m.isNewContact(contact) { + err := m.syncContact(context.Background(), contact) + if err != nil { + return err + } + } + err = m.persistence.SaveContact(contact, nil) if err != nil { return err @@ -927,6 +1059,12 @@ func (m *Messenger) SaveContact(contact *Contact) error { m.allContacts[contact.ID] = contact return nil + +} +func (m *Messenger) SaveContact(contact *Contact) error { + m.mutex.Lock() + defer m.mutex.Unlock() + return m.saveContact(contact) } func (m *Messenger) BlockContact(contact *Contact) ([]*Chat, error) { @@ -960,26 +1098,78 @@ func timestampInMs() uint64 { } // ReSendChatMessage pulls a message from the database and sends it again -func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) (*MessengerResponse, error) { +func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) error { m.mutex.Lock() defer m.mutex.Unlock() - logger := m.logger.With(zap.String("site", "ReSendChatMessage")) - var response MessengerResponse - message, err := m.persistence.MessageByID(messageID) + message, err := m.persistence.RawMessageByID(messageID) if err != nil { - return nil, err + return err } - if message == nil { - return nil, errors.New("message not found") + + chat, ok := m.allChats[message.LocalChatID] + if !ok { + return errors.New("chat not found") + } + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: message.Payload, + MessageType: message.MessageType, + Recipients: message.Recipients, + }) + return err +} + +func (m *Messenger) hasPairedDevices() bool { + var count int + for _, i := range m.allInstallations { + if i.Enabled { + count += 1 + } } - if message.RawPayload == nil { - return nil, errors.New("message payload not found, can't resend message") + return count > 1 +} + +// sendToPairedDevices will check if we have any paired devices and send to them if necessary +func (m *Messenger) sendToPairedDevices(ctx context.Context, payload []byte, messageType protobuf.ApplicationMetadataMessage_Type) error { + hasPairedDevices := m.hasPairedDevices() + // We send a message to any paired device + if hasPairedDevices { + _, err := m.processor.SendPrivateRaw(ctx, &m.identity.PublicKey, payload, messageType) + if err != nil { + return err + } } + return nil +} - chat, ok := m.allChats[message.LocalChatID] +func (m *Messenger) dispatchPairInstallationMessage(ctx context.Context, spec *RawMessage) ([]byte, error) { + var err error + var id []byte + + id, err = m.processor.SendPairInstallation(ctx, &m.identity.PublicKey, spec.Payload, spec.MessageType) + + if err != nil { + return nil, err + } + spec.ID = types.EncodeHex(id) + spec.SendCount += 1 + err = m.persistence.SaveRawMessage(spec) + if err != nil { + return nil, err + } + + return id, nil +} + +func (m *Messenger) dispatchMessage(ctx context.Context, spec *RawMessage) ([]byte, error) { + var err error + var id []byte + logger := m.logger.With(zap.String("site", "dispatchMessage"), zap.String("chatID", spec.LocalChatID)) + chat, ok := m.allChats[spec.LocalChatID] if !ok { - return nil, errors.New("chat not found") + return nil, errors.New("no chat found") } switch chat.ChatType { @@ -988,50 +1178,51 @@ func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) (*M if err != nil { return nil, err } - logger.Debug("re-sending private message") - id, err := m.processor.SendPrivateRaw(ctx, publicKey, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - if err != nil { - return nil, err - } - message.ID = "0x" + hex.EncodeToString(id) - err = m.sendToPairedDevices(ctx, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) + if !isPubKeyEqual(publicKey, &m.identity.PublicKey) { + id, err = m.processor.SendPrivateRaw(ctx, publicKey, spec.Payload, spec.MessageType) - if err != nil { - return nil, err + if err != nil { + return nil, err + } } - case ChatTypePublic: - logger.Debug("re-sending public message", zap.String("chatName", chat.Name)) - id, err := m.processor.SendPublicRaw(ctx, chat.ID, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) + err = m.sendToPairedDevices(ctx, spec.Payload, spec.MessageType) if err != nil { return nil, err } - message.ID = "0x" + hex.EncodeToString(id) - case ChatTypePrivateGroupChat: - logger.Debug("re-sending group message", zap.String("chatName", chat.Name)) - recipients, err := chat.MembersAsPublicKeys() + + case ChatTypePublic: + logger.Debug("sending public message", zap.String("chatName", chat.Name)) + id, err = m.processor.SendPublicRaw(ctx, chat.ID, spec.Payload, spec.MessageType) if err != nil { return nil, err } - n := 0 - for _, item := range recipients { - if !isPubKeyEqual(item, &m.identity.PublicKey) { - recipients[n] = item - n++ + case ChatTypePrivateGroupChat: + logger.Debug("sending group message", zap.String("chatName", chat.Name)) + if spec.Recipients == nil { + spec.Recipients, err = chat.MembersAsPublicKeys() + if err != nil { + return nil, err } } - id, err := m.processor.SendGroupRaw(ctx, recipients[:n], message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - - if err != nil { - return nil, err + hasPairedDevices := m.hasPairedDevices() + + if !hasPairedDevices { + // Filter out my key from the recipients + n := 0 + for _, recipient := range spec.Recipients { + if !isPubKeyEqual(recipient, &m.identity.PublicKey) { + spec.Recipients[n] = recipient + n++ + } + } + spec.Recipients = spec.Recipients[:n] } - message.ID = "0x" + hex.EncodeToString(id) - - err = m.sendToPairedDevices(ctx, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - + // We always wrap in group information + id, err = m.processor.SendGroupRaw(ctx, spec.Recipients, spec.Payload, protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE) if err != nil { return nil, err } @@ -1039,34 +1230,14 @@ func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) (*M default: return nil, errors.New("chat type not supported") } - - response.Messages = []*Message{message} - response.Chats = []*Chat{chat} - return &response, nil -} - -func (m *Messenger) hasPairedDevices() (bool, error) { - activeInstallations, err := m.encryptor.GetOurActiveInstallations(&m.identity.PublicKey) + spec.ID = types.EncodeHex(id) + spec.SendCount += 1 + err = m.persistence.SaveRawMessage(spec) if err != nil { - return false, err + return nil, err } - return len(activeInstallations) > 1, nil -} -// sendToPairedDevices will check if we have any paired devices and send to them if necessary -func (m *Messenger) sendToPairedDevices(ctx context.Context, payload []byte, messageType protobuf.ApplicationMetadataMessage_Type) error { - hasPairedDevices, err := m.hasPairedDevices() - if err != nil { - return err - } - // We send a message to any paired device - if hasPairedDevices { - _, err := m.processor.SendPrivateRaw(ctx, &m.identity.PublicKey, payload, messageType) - if err != nil { - return err - } - } - return nil + return id, nil } // SendChatMessage takes a minimal message and sends it based on the corresponding chat @@ -1083,117 +1254,64 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes return nil, errors.New("Chat not found") } - clock := chat.LastClockValue - timestamp := timestampInMs() - if clock == 0 || clock < timestamp { - clock = timestamp - } else { - clock = clock + 1 - } - - message.LocalChatID = chat.ID - message.Clock = clock - message.Timestamp = timestamp - message.From = "0x" + hex.EncodeToString(crypto.FromECDSAPub(&m.identity.PublicKey)) - message.SigPubKey = &m.identity.PublicKey - message.WhisperTimestamp = timestamp - message.Seen = true - message.OutgoingStatus = OutgoingStatusSending - - identicon, err := identicon.GenerateBase64(message.From) - if err != nil { - return nil, err - } - - message.Identicon = identicon - - alias, err := alias.GenerateFromPublicKeyString(message.From) + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) if err != nil { return nil, err } - message.Alias = alias - + var encodedMessage []byte switch chat.ChatType { case ChatTypeOneToOne: - publicKey, err := chat.PublicKey() - if err != nil { - return nil, err - } logger.Debug("sending private message") message.MessageType = protobuf.ChatMessage_ONE_TO_ONE - encodedMessage, err := proto.Marshal(message) - if err != nil { - return nil, err - } - message.RawPayload = encodedMessage - - id, err := m.processor.SendPrivateRaw(ctx, publicKey, encodedMessage, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - - if err != nil { - return nil, err - } - message.ID = "0x" + hex.EncodeToString(id) - - err = m.sendToPairedDevices(ctx, encodedMessage, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - + encodedMessage, err = proto.Marshal(message) if err != nil { return nil, err } - case ChatTypePublic: logger.Debug("sending public message", zap.String("chatName", chat.Name)) message.MessageType = protobuf.ChatMessage_PUBLIC_GROUP - encodedMessage, err := proto.Marshal(message) - if err != nil { - return nil, err - } - message.RawPayload = encodedMessage - - id, err := m.processor.SendPublicRaw(ctx, chat.ID, encodedMessage, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - + encodedMessage, err = proto.Marshal(message) if err != nil { return nil, err } - message.ID = "0x" + hex.EncodeToString(id) case ChatTypePrivateGroupChat: - logger.Debug("sending public message", zap.String("chatName", chat.Name)) message.MessageType = protobuf.ChatMessage_PRIVATE_GROUP logger.Debug("sending group message", zap.String("chatName", chat.Name)) - recipients, err := chat.MembersAsPublicKeys() - if err != nil { - return nil, err - } group, err := newProtocolGroupFromChat(chat) if err != nil { return nil, err } - encodedMessage, err := m.propagateMembershipUpdates(ctx, group, recipients, &message.ChatMessage) + encodedMessage, err = m.processor.EncodeMembershipUpdate(group, &message.ChatMessage) if err != nil { return nil, err } - id := v1protocol.MessageID(&m.identity.PublicKey, encodedMessage) - message.ID = "0x" + hex.EncodeToString(id) default: return nil, errors.New("chat type not supported") } - err = message.PrepareContent() + id, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_CHAT_MESSAGE, + }) if err != nil { return nil, err } - jsonMessage, err := json.Marshal(message) + message.ID = types.EncodeHex(id) + err = message.PrepareContent() if err != nil { return nil, err } - chat.LastClockValue = clock - chat.LastMessage = jsonMessage - chat.Timestamp = int64(timestamp) + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } err = m.persistence.SaveMessagesLegacy([]*Message{message}) if err != nil { @@ -1205,149 +1323,277 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes return &response, m.saveChat(chat) } -// SendRaw takes encoded data, encrypts it and sends through the wire. -// DEPRECATED -func (m *Messenger) SendRaw(ctx context.Context, chat Chat, data []byte) ([]byte, error) { - publicKey, err := chat.PublicKey() - if err != nil { - return nil, err - } - if publicKey != nil { - return m.processor.SendPrivateRaw(ctx, publicKey, data, protobuf.ApplicationMetadataMessage_UNKNOWN) - } else if chat.Name != "" { - return m.processor.SendPublicRaw(ctx, chat.Name, data, protobuf.ApplicationMetadataMessage_UNKNOWN) - } - return nil, errors.New("chat is neither public nor private") -} +// Send contact updates to all contacts added by us +func (m *Messenger) SendContactUpdates(ctx context.Context, ensName, profileImage string) error { + m.mutex.Lock() + defer m.mutex.Unlock() -// RetrieveAll retrieves messages from all filters, processes them and returns a -// MessengerResponse to the client -func (m *Messenger) RetrieveAll() (*MessengerResponse, error) { - chatWithMessages, err := m.transport.RetrieveRawAll() - if err != nil { - return nil, err + for _, contact := range m.allContacts { + if contact.IsAdded() { + if _, err := m.sendContactUpdate(ctx, contact.ID, ensName, profileImage); err != nil { + return err + } + } } + return nil - return m.handleRetrievedMessages(chatWithMessages) } -type ReceivedMessageState struct { - // Message is the protobuf message received - Message protobuf.ChatMessage - // MessageID is the ID of the message - MessageID string - // WhisperTimestamp is the whisper timestamp of the message - WhisperTimestamp uint64 - // Contact is the contact associated with the author of the message - Contact *Contact - // PublicKey is the public key of the author of the message - PublicKey *ecdsa.PublicKey - // List of chats modified - ModifiedChats map[string]bool - PostProcessor *postProcessor +// SendContactUpdate sends a contact update to a user and adds the user to contacts +func (m *Messenger) SendContactUpdate(ctx context.Context, chatID, ensName, profileImage string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + return m.sendContactUpdate(ctx, chatID, ensName, profileImage) } -func (m *Messenger) handleChatMessage(state *ReceivedMessageState) (*Message, error) { - logger := m.logger.With(zap.String("site", "handleChatMessage")) - if err := ValidateReceivedChatMessage(&state.Message); err != nil { - logger.Warn("failed to validate message", zap.Error(err)) - return nil, err +func (m *Messenger) sendContactUpdate(ctx context.Context, chatID, ensName, profileImage string) (*MessengerResponse, error) { + var response MessengerResponse + + contact, ok := m.allContacts[chatID] + if !ok { + pubkeyBytes, err := types.DecodeHex(chatID) + if err != nil { + return nil, err + } + + publicKey, err := crypto.UnmarshalPubkey(pubkeyBytes) + if err != nil { + return nil, err + } + + contact, err = buildContact(publicKey) + if err != nil { + return nil, err + } + } + + chat, ok := m.allChats[chatID] + if !ok { + publicKey, err := contact.PublicKey() + if err != nil { + return nil, err + } + chat = OneToOneFromPublicKey(publicKey) + // We don't want to show the chat to the user + chat.Active = false } - receivedMessage := &Message{ - ID: state.MessageID, - ChatMessage: state.Message, - From: state.Contact.ID, - Alias: state.Contact.Alias, - SigPubKey: state.PublicKey, - Identicon: state.Contact.Identicon, - WhisperTimestamp: state.WhisperTimestamp, + + m.allChats[chat.ID] = chat + clock, _ := chat.NextClockAndTimestamp() + + contactUpdate := &protobuf.ContactUpdate{ + Clock: clock, + EnsName: ensName, + ProfileImage: profileImage} + encodedMessage, err := proto.Marshal(contactUpdate) + if err != nil { + return nil, err } - receivedMessage.PrepareContent() - chat, err := state.PostProcessor.matchMessage(receivedMessage, m.allChats) + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chatID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_CONTACT_UPDATE, + ResendAutomatically: true, + }) if err != nil { return nil, err } - // If deleted-at is greater, ignore message - if chat.DeletedAtClockValue >= receivedMessage.Clock { - return nil, nil + if !contact.IsAdded() { + contact.SystemTags = append(contact.SystemTags, contactAdded) } - // Set the LocalChatID for the message - receivedMessage.LocalChatID = chat.ID + response.Contacts = []*Contact{contact} + response.Chats = []*Chat{chat} - if c, ok := m.allChats[chat.ID]; ok { - chat = c + chat.LastClockValue = clock + err = m.saveChat(chat) + if err != nil { + return nil, err } + return &response, m.saveContact(contact) +} + +// SendPairInstallation sends a pair installation message +func (m *Messenger) SendPairInstallation(ctx context.Context) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() - // Set the LocalChatID for the message - receivedMessage.LocalChatID = chat.ID + var err error + var response MessengerResponse - // Increase unviewed count - if !isPubKeyEqual(receivedMessage.SigPubKey, &m.identity.PublicKey) { - chat.UnviewedMessagesCount++ - } else { - // Our own message, mark as sent - receivedMessage.OutgoingStatus = OutgoingStatusSent + installation, ok := m.allInstallations[m.installationID] + if !ok { + return nil, errors.New("no installation found") } - // Update chat timestamp - chat.Timestamp = int64(timestampInMs()) - // Update last clock value - if chat.LastClockValue <= receivedMessage.Clock { - chat.LastClockValue = receivedMessage.Clock - encodedLastMessage, err := json.Marshal(receivedMessage) - if err != nil { - return nil, err - } - chat.LastMessage = encodedLastMessage + if installation.InstallationMetadata == nil { + return nil, errors.New("no installation metadata") + } + + chatID := types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)) + + chat, ok := m.allChats[chatID] + if !ok { + chat = OneToOneFromPublicKey(&m.identity.PublicKey) + // We don't want to show the chat to the user + chat.Active = false } - // Set chat active - chat.Active = true - // Set in the modified maps chat - state.ModifiedChats[chat.ID] = true m.allChats[chat.ID] = chat + clock, _ := chat.NextClockAndTimestamp() + + pairMessage := &protobuf.PairInstallation{ + Clock: clock, + Name: installation.InstallationMetadata.Name, + InstallationId: installation.ID, + DeviceType: installation.InstallationMetadata.DeviceType} + encodedMessage, err := proto.Marshal(pairMessage) + if err != nil { + return nil, err + } + + _, err = m.dispatchPairInstallationMessage(ctx, &RawMessage{ + LocalChatID: chatID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_PAIR_INSTALLATION, + ResendAutomatically: true, + }) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} - return receivedMessage, nil + chat.LastClockValue = clock + err = m.saveChat(chat) + if err != nil { + return nil, err + } + return &response, nil } -func (m *Messenger) messageExists(messageID string, existingMessagesMap map[string]bool) (bool, error) { - if _, ok := existingMessagesMap[messageID]; ok { - return true, nil +// syncContact sync as contact with paired devices +func (m *Messenger) syncContact(ctx context.Context, contact *Contact) error { + var err error + if !m.hasPairedDevices() { + return nil } + chatID := types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)) - existingMessagesMap[messageID] = true + chat, ok := m.allChats[chatID] + if !ok { + chat = OneToOneFromPublicKey(&m.identity.PublicKey) + // We don't want to show the chat to the user + chat.Active = false + } - // Check against the database, this is probably a bit slow for - // each message, but for now might do, we'll make it faster later - existingMessage, err := m.persistence.MessageByID(messageID) - if err != nil && err != errRecordNotFound { - return false, err + m.allChats[chat.ID] = chat + clock, _ := chat.NextClockAndTimestamp() + + syncMessage := &protobuf.SyncInstallationContact{ + Clock: clock, + Id: contact.ID, + EnsName: contact.Name, + ProfileImage: contact.Photo, + } + encodedMessage, err := proto.Marshal(syncMessage) + if err != nil { + return err + } + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chatID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT, + ResendAutomatically: true, + }) + if err != nil { + return err + } + + chat.LastClockValue = clock + return m.saveChat(chat) +} + +// SendRaw takes encoded data, encrypts it and sends through the wire. +// DEPRECATED +func (m *Messenger) SendRaw(ctx context.Context, chat Chat, data []byte) ([]byte, error) { + publicKey, err := chat.PublicKey() + if err != nil { + return nil, err + } + if publicKey != nil { + return m.processor.SendPrivateRaw(ctx, publicKey, data, protobuf.ApplicationMetadataMessage_UNKNOWN) + } else if chat.Name != "" { + return m.processor.SendPublicRaw(ctx, chat.Name, data, protobuf.ApplicationMetadataMessage_UNKNOWN) } - if existingMessage != nil { - return true, nil + return nil, errors.New("chat is neither public nor private") +} + +// RetrieveAll retrieves messages from all filters, processes them and returns a +// MessengerResponse to the client +func (m *Messenger) RetrieveAll() (*MessengerResponse, error) { + chatWithMessages, err := m.transport.RetrieveRawAll() + if err != nil { + return nil, err } - return false, nil + + return m.handleRetrievedMessages(chatWithMessages) +} + +type CurrentMessageState struct { + // Message is the protobuf message received + Message protobuf.ChatMessage + // MessageID is the ID of the message + MessageID string + // WhisperTimestamp is the whisper timestamp of the message + WhisperTimestamp uint64 + // Contact is the contact associated with the author of the message + Contact *Contact + // PublicKey is the public key of the author of the message + PublicKey *ecdsa.PublicKey +} + +type ReceivedMessageState struct { + // State on the message being processed + CurrentMessageState *CurrentMessageState + // AllChats in memory + AllChats map[string]*Chat + // List of chats modified + ModifiedChats map[string]bool + // All contacts in memory + AllContacts map[string]*Contact + // List of contacs modified + ModifiedContacts map[string]bool + // All installations in memory + AllInstallations map[string]*multidevice.Installation + // List of installations modified + ModifiedInstallations map[string]bool + // Map of existing messages + ExistingMessagesMap map[string]bool + // Response to the client + Response *MessengerResponse } func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filter][]*types.Message) (*MessengerResponse, error) { m.mutex.Lock() defer m.mutex.Unlock() - response := &MessengerResponse{ - Chats: []*Chat{}, - Messages: []*Message{}, + messageState := &ReceivedMessageState{ + AllChats: m.allChats, + ModifiedChats: make(map[string]bool), + AllContacts: m.allContacts, + ModifiedContacts: make(map[string]bool), + AllInstallations: m.allInstallations, + ModifiedInstallations: m.modifiedInstallations, + ExistingMessagesMap: make(map[string]bool), + Response: &MessengerResponse{}, } - postProcessor := newPostProcessor(m, postProcessorConfig{MatchChat: true}) - logger := m.logger.With(zap.String("site", "RetrieveAll")) rawMessages := make(map[transport.Filter][]*v1protocol.StatusMessage) - modifiedChats := make(map[string]bool) - modifiedContacts := make(map[string]bool) - existingMessagesMap := make(map[string]bool) - for chat, messages := range chatWithMessages { for _, shhMessage := range messages { // TODO: fix this to use an exported method. @@ -1362,12 +1608,12 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte // Check for messages from blocked users senderID := types.EncodeHex(crypto.FromECDSAPub(publicKey)) - if _, ok := m.allContacts[senderID]; ok && m.allContacts[senderID].IsBlocked() { + if _, ok := messageState.AllContacts[senderID]; ok && messageState.AllContacts[senderID].IsBlocked() { continue } // Don't process duplicates messageID := types.EncodeHex(msg.ID) - exists, err := m.messageExists(messageID, existingMessagesMap) + exists, err := m.handler.messageExists(messageID, messageState.ExistingMessagesMap) if err != nil { logger.Warn("failed to check message exists", zap.Error(err)) } @@ -1376,7 +1622,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte } var contact *Contact - if c, ok := m.allContacts[senderID]; ok { + if c, ok := messageState.AllContacts[senderID]; ok { contact = c } else { c, err := buildContact(publicKey) @@ -1385,123 +1631,187 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte continue } contact = c - m.allContacts[senderID] = c - modifiedContacts[contact.ID] = true + messageState.AllContacts[senderID] = c + messageState.ModifiedContacts[contact.ID] = true } - messageState := &ReceivedMessageState{ + messageState.CurrentMessageState = &CurrentMessageState{ MessageID: messageID, WhisperTimestamp: uint64(msg.TransportMessage.Timestamp) * 1000, Contact: contact, PublicKey: publicKey, - ModifiedChats: modifiedChats, - PostProcessor: postProcessor, } if msg.ParsedMessage != nil { + logger.Debug("Handling parsed message") switch msg.ParsedMessage.(type) { case protobuf.MembershipUpdateMessage: + logger.Debug("Handling MembershipUpdateMessage") rawMembershipUpdate := msg.ParsedMessage.(protobuf.MembershipUpdateMessage) - membershipUpdate, err := v1protocol.MembershipUpdateMessageFromProtobuf(&rawMembershipUpdate) + + err = m.handler.HandleMembershipUpdate(messageState, messageState.AllChats[rawMembershipUpdate.ChatId], rawMembershipUpdate, m.systemMessagesTranslations) if err != nil { - logger.Warn("failed to process membership update", zap.Error(err)) + logger.Warn("failed to handle MembershipUpdate", zap.Error(err)) continue - } - chat, systemMessages, err := HandleMembershipUpdate(m.allChats[membershipUpdate.ChatID], membershipUpdate, types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)), m.systemMessagesTranslations) + case protobuf.ChatMessage: + logger.Debug("Handling ChatMessage") + messageState.CurrentMessageState.Message = msg.ParsedMessage.(protobuf.ChatMessage) + err = m.handler.HandleChatMessage(messageState) + if err != nil { + logger.Warn("failed to handle ChatMessage", zap.Error(err)) + continue + } + case protobuf.PairInstallation: + if !isPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) { + logger.Warn("not coming from us, ignoring") + continue + } + p := msg.ParsedMessage.(protobuf.PairInstallation) + logger.Debug("Handling PairInstallation", zap.Any("message", p)) + err = m.handler.HandlePairInstallation(messageState, p) if err != nil { - logger.Warn("failed to process membership update", zap.Error(err)) + logger.Warn("failed to handle PairInstallation", zap.Error(err)) continue } - for _, message := range systemMessages { - messageID := message.ID - exists, err := m.messageExists(messageID, existingMessagesMap) - if err != nil { - logger.Warn("failed to check message exists", zap.Error(err)) - } - if exists { - continue - } - response.Messages = append(response.Messages, message) + case protobuf.SyncInstallationContact: + if !isPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) { + logger.Warn("not coming from us, ignoring") + continue } - // Store in chats map as it might be a new one - m.allChats[chat.ID] = chat - // Set in the map - modifiedChats[chat.ID] = true - - if rawMembershipUpdate.Message != nil { - messageState.Message = *rawMembershipUpdate.Message - receivedMessage, err := m.handleChatMessage(messageState) - if err != nil { - logger.Warn("failed to process message", zap.Error(err)) - continue - } - // Add to response - if receivedMessage != nil { - response.Messages = append(response.Messages, receivedMessage) - } + p := msg.ParsedMessage.(protobuf.SyncInstallationContact) + logger.Debug("Handling SyncInstallationContact", zap.Any("message", p)) + err = m.handler.HandleSyncInstallationContact(messageState, p) + if err != nil { + logger.Warn("failed to handle SyncInstallationContact", zap.Error(err)) + continue + } + case protobuf.RequestAddressForTransaction: + command := msg.ParsedMessage.(protobuf.RequestAddressForTransaction) + logger.Debug("Handling RequestAddressForTransaction", zap.Any("message", command)) + err = m.handler.HandleRequestAddressForTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle RequestAddressForTransaction", zap.Error(err)) + continue + } + case protobuf.SendTransaction: + command := msg.ParsedMessage.(protobuf.SendTransaction) + logger.Debug("Handling SendTransaction", zap.Any("message", command)) + err = m.handler.HandleSendTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle SendTransaction", zap.Error(err)) + continue + } + case protobuf.AcceptRequestAddressForTransaction: + command := msg.ParsedMessage.(protobuf.AcceptRequestAddressForTransaction) + logger.Debug("Handling AcceptRequestAddressForTransaction") + err = m.handler.HandleAcceptRequestAddressForTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle AcceptRequestAddressForTransaction", zap.Error(err)) + continue + } + case protobuf.DeclineRequestAddressForTransaction: + command := msg.ParsedMessage.(protobuf.DeclineRequestAddressForTransaction) + logger.Debug("Handling DeclineRequestAddressForTransaction") + err = m.handler.HandleDeclineRequestAddressForTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle DeclineRequestAddressForTransaction", zap.Error(err)) + continue } - case protobuf.ChatMessage: - messageState.Message = msg.ParsedMessage.(protobuf.ChatMessage) - receivedMessage, err := m.handleChatMessage(messageState) + case protobuf.DeclineRequestTransaction: + command := msg.ParsedMessage.(protobuf.DeclineRequestTransaction) + logger.Debug("Handling DeclineRequestTransaction") + err = m.handler.HandleDeclineRequestTransaction(messageState, command) if err != nil { - logger.Warn("failed to process message", zap.Error(err)) + logger.Warn("failed to handle DeclineRequestTransaction", zap.Error(err)) continue } - // Add to response - if receivedMessage != nil { - response.Messages = append(response.Messages, receivedMessage) + + case protobuf.RequestTransaction: + command := msg.ParsedMessage.(protobuf.RequestTransaction) + logger.Debug("Handling RequestTransaction") + err = m.handler.HandleRequestTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle RequestTransaction", zap.Error(err)) + continue + } + case protobuf.ContactUpdate: + logger.Debug("Handling ContactUpdate") + + contactUpdate := msg.ParsedMessage.(protobuf.ContactUpdate) + + err = m.handler.HandleContactUpdate(messageState, contactUpdate) + if err != nil { + logger.Warn("failed to handle ContactUpdate", zap.Error(err)) + continue } + default: // RawMessage, not processed here, pass straight to the client rawMessages[chat] = append(rawMessages[chat], msg) } } else { + logger.Debug("Adding raw message", zap.Any("msg", msg)) rawMessages[chat] = append(rawMessages[chat], msg) } } } } - for id := range modifiedChats { - response.Chats = append(response.Chats, m.allChats[id]) + for id := range messageState.ModifiedChats { + messageState.Response.Chats = append(messageState.Response.Chats, messageState.AllChats[id]) + } + + for id := range messageState.ModifiedContacts { + messageState.Response.Contacts = append(messageState.Response.Contacts, messageState.AllContacts[id]) } - for id := range modifiedContacts { - response.Contacts = append(response.Contacts, m.allContacts[id]) + for id, _ := range messageState.ModifiedInstallations { + installation := messageState.AllInstallations[id] + messageState.Response.Installations = append(messageState.Response.Installations, installation) + if installation.InstallationMetadata != nil { + err := m.setInstallationMetadata(id, installation.InstallationMetadata) + if err != nil { + return nil, err + } + } } var err error - if len(response.Chats) > 0 { - err = m.saveChats(response.Chats) + if len(messageState.Response.Chats) > 0 { + err = m.saveChats(messageState.Response.Chats) if err != nil { return nil, err } } - if len(response.Messages) > 0 { - err = m.SaveMessages(response.Messages) + if len(messageState.Response.Messages) > 0 { + err = m.SaveMessages(messageState.Response.Messages) if err != nil { return nil, err } } - if len(response.Contacts) > 0 { - err = m.persistence.SaveContacts(response.Contacts) + if len(messageState.Response.Contacts) > 0 { + err = m.persistence.SaveContacts(messageState.Response.Contacts) if err != nil { return nil, err } } for filter, messages := range rawMessages { - response.RawMessages = append(response.RawMessages, &RawResponse{Filter: &filter, Messages: messages}) + messageState.Response.RawMessages = append(messageState.Response.RawMessages, &RawResponse{Filter: &filter, Messages: messages}) } - return response, nil + + // Reset installations + m.modifiedInstallations = make(map[string]bool) + + return messageState.Response, nil } func (m *Messenger) RequestHistoricMessages( @@ -1585,116 +1895,6 @@ func (m *Messenger) UpdateMessageOutgoingStatus(id, newOutgoingStatus string) er return m.persistence.UpdateMessageOutgoingStatus(id, newOutgoingStatus) } -// postProcessor performs a set of actions on newly retrieved messages. -// If persist is true, it saves the messages into the database. -// If matchChat is true, it matches each messages against a Chat instance. -type postProcessor struct { - myPublicKey *ecdsa.PublicKey - persistence *sqlitePersistence - logger *zap.Logger - - config postProcessorConfig -} - -type postProcessorConfig struct { - MatchChat bool // match each messages to a chat; may result in a new chat creation - Persist bool // if true, all sent and received user messages will be persisted - Parse bool // if true, it will parse the content -} - -func newPostProcessor(m *Messenger, config postProcessorConfig) *postProcessor { - return &postProcessor{ - myPublicKey: &m.identity.PublicKey, - persistence: m.persistence, - logger: m.logger, - config: config, - } -} - -func (p *postProcessor) matchMessage(message *Message, chats map[string]*Chat) (*Chat, error) { - if message.SigPubKey == nil { - p.logger.Error("public key can't be empty") - return nil, errors.New("received a message with empty public key") - } - - switch { - case message.MessageType == protobuf.ChatMessage_PUBLIC_GROUP: - // For public messages, all outgoing and incoming messages have the same chatID - // equal to a public chat name. - chatID := message.ChatId - chat := chats[chatID] - if chat == nil { - return nil, errors.New("received a public message from non-existing chat") - } - return chat, nil - case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE && isPubKeyEqual(message.SigPubKey, p.myPublicKey): - // It's a private message coming from us so we rely on Message.ChatId - // If chat does not exist, it should be created to support multidevice synchronization. - chatID := message.ChatId - chat := chats[chatID] - if chat == nil { - if len(chatID) != PubKeyStringLength { - return nil, errors.New("invalid pubkey length") - } - bytePubKey, err := hex.DecodeString(chatID[2:]) - if err != nil { - return nil, errors.Wrap(err, "failed to decode hex chatID") - } - - pubKey, err := crypto.UnmarshalPubkey(bytePubKey) - if err != nil { - return nil, errors.Wrap(err, "failed to decode pubkey") - } - - newChat := CreateOneToOneChat(chatID[:8], pubKey) - chat = &newChat - } - return chat, nil - case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE: - // It's an incoming private message. ChatID is calculated from the signature. - // If a chat does not exist, a new one is created and saved. - chatID := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) - chat := chats[chatID] - if chat == nil { - // TODO: this should be a three-word name used in the mobile client - newChat := CreateOneToOneChat(chatID[:8], message.SigPubKey) - chat = &newChat - } - return chat, nil - case message.MessageType == protobuf.ChatMessage_PRIVATE_GROUP: - // In the case of a group message, ChatID is the same for all messages belonging to a group. - // It needs to be verified if the signature public key belongs to the chat. - chatID := message.ChatId - chat := chats[chatID] - if chat == nil { - return nil, errors.New("received group chat message for non-existing chat") - } - - theirKeyHex := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) - myKeyHex := types.EncodeHex(crypto.FromECDSAPub(p.myPublicKey)) - var theyJoined bool - var iJoined bool - for _, member := range chat.Members { - if member.ID == theirKeyHex && member.Joined { - theyJoined = true - } - } - for _, member := range chat.Members { - if member.ID == myKeyHex && member.Joined { - iJoined = true - } - } - - if theyJoined && iJoined { - return chat, nil - } - - return nil, errors.New("did not find a matching group chat") - default: - return nil, errors.New("can not match a chat because there is no valid case") - } -} - // Identicon returns an identicon based on the input string func Identicon(id string) (string, error) { return identicon.GenerateBase64(id) @@ -1750,3 +1950,700 @@ func (m *Messenger) VerifyENSNames(rpcEndpoint, contractAddress string, ensDetai func GenerateAlias(id string) (string, error) { return alias.GenerateFromPublicKeyString(id) } + +func (m *Messenger) RequestTransaction(ctx context.Context, chatID, value, contract, address string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + message := &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.Text = "Request transaction" + + request := &protobuf.RequestTransaction{ + Clock: message.Clock, + Address: address, + Value: value, + Contract: contract, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + id, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_REQUEST_TRANSACTION, + ResendAutomatically: true, + }) + + message.CommandParameters = &CommandParameters{ + ID: types.EncodeHex(id), + Value: value, + Address: address, + Contract: contract, + CommandState: CommandStateRequestTransaction, + } + + if err != nil { + return nil, err + } + messageID := types.EncodeHex(id) + + message.ID = messageID + message.CommandParameters.ID = messageID + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) RequestAddressForTransaction(ctx context.Context, chatID, from, value, contract string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + message := &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.Text = "Request address for transaction" + + request := &protobuf.RequestAddressForTransaction{ + Clock: message.Clock, + Value: value, + Contract: contract, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + id, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION, + ResendAutomatically: true, + }) + + message.CommandParameters = &CommandParameters{ + ID: types.EncodeHex(id), + From: from, + Value: value, + Contract: contract, + CommandState: CommandStateRequestAddressForTransaction, + } + + if err != nil { + return nil, err + } + messageID := types.EncodeHex(id) + + message.ID = messageID + message.CommandParameters.ID = messageID + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) AcceptRequestAddressForTransaction(ctx context.Context, messageID, address string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Request address for transaction accepted" + message.OutgoingStatus = OutgoingStatusSending + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(messageID) + if err != nil { + return nil, err + } + + if previousMessage == nil { + return nil, errors.New("No previous message found") + } + + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return nil, err + } + + message.Replace = previousMessage.ID + + request := &protobuf.AcceptRequestAddressForTransaction{ + Clock: message.Clock, + Id: messageID, + Address: address, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.Address = address + message.CommandParameters.CommandState = CommandStateRequestAddressForTransactionAccepted + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) DeclineRequestTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Transaction request declined" + message.OutgoingStatus = OutgoingStatusSending + message.Replace = messageID + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.DeclineRequestTransaction{ + Clock: message.Clock, + Id: messageID, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Request address for transaction declined" + message.OutgoingStatus = OutgoingStatusSending + message.Replace = messageID + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.DeclineRequestAddressForTransaction{ + Clock: message.Clock, + Id: messageID, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.CommandState = CommandStateRequestAddressForTransactionDeclined + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) AcceptRequestTransaction(ctx context.Context, transactionHash, messageID string, signature []byte) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Transaction sent" + message.OutgoingStatus = OutgoingStatusSending + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(messageID) + if err != nil && err != errRecordNotFound { + return nil, err + } + + if previousMessage != nil { + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return nil, err + } + message.Replace = previousMessage.ID + } + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.SendTransaction{ + Clock: message.Clock, + Id: messageID, + TransactionHash: transactionHash, + Signature: signature, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_SEND_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.TransactionHash = transactionHash + message.CommandParameters.Signature = signature + message.CommandParameters.CommandState = CommandStateTransactionSent + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) SendTransaction(ctx context.Context, chatID, transactionHash string, signature []byte) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + message := &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.LocalChatID = chatID + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Transaction sent" + + request := &protobuf.SendTransaction{ + Clock: message.Clock, + TransactionHash: transactionHash, + Signature: signature, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_SEND_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters = &CommandParameters{ + TransactionHash: transactionHash, + Signature: signature, + CommandState: CommandStateTransactionSent, + } + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) ValidateTransactions(ctx context.Context, addresses []types.Address) (*MessengerResponse, error) { + if m.verifyTransactionClient == nil { + return nil, nil + } + m.mutex.Lock() + defer m.mutex.Unlock() + + modifiedChats := make(map[string]bool) + + logger := m.logger.With(zap.String("site", "ValidateTransactions")) + logger.Debug("Validating transactions") + txs, err := m.persistence.TransactionsToValidate() + if err != nil { + logger.Error("Error pulling", zap.Error(err)) + return nil, err + } + logger.Debug("Txs", zap.Int("count", len(txs)), zap.Any("txs", txs)) + var response MessengerResponse + validator := NewTransactionValidator(addresses, m.persistence, m.verifyTransactionClient, m.logger) + responses, err := validator.ValidateTransactions(ctx) + if err != nil { + logger.Error("Error validating", zap.Error(err)) + return nil, err + } + for _, validationResult := range responses { + var message *Message + chatID := types.EncodeHex(crypto.FromECDSAPub(validationResult.Transaction.From)) + chat, ok := m.allChats[chatID] + if !ok { + chat = OneToOneFromPublicKey(validationResult.Transaction.From) + } + if validationResult.Message != nil { + message = validationResult.Message + } else { + message = &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.LocalChatID = chatID + message.OutgoingStatus = "" + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.Timestamp = timestamp + message.WhisperTimestamp = timestamp + message.Text = "Transaction received" + + message.ID = validationResult.Transaction.MessageID + if message.CommandParameters == nil { + message.CommandParameters = &CommandParameters{} + } else { + message.CommandParameters = validationResult.Message.CommandParameters + } + + message.CommandParameters.Value = validationResult.Value + message.CommandParameters.Contract = validationResult.Contract + message.CommandParameters.Address = validationResult.Address + message.CommandParameters.CommandState = CommandStateTransactionSent + message.CommandParameters.TransactionHash = validationResult.Transaction.TransactionHash + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(message.CommandParameters.ID) + if err != nil && err != errRecordNotFound { + return nil, err + } + + if previousMessage != nil { + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return nil, err + } + message.Replace = previousMessage.ID + } + + response.Messages = append(response.Messages, message) + m.allChats[chat.ID] = chat + modifiedChats[chat.ID] = true + + } + for id, _ := range modifiedChats { + response.Chats = append(response.Chats, m.allChats[id]) + } + + if len(response.Messages) > 0 { + err = m.SaveMessages(response.Messages) + if err != nil { + return nil, err + } + } + return &response, nil +} diff --git a/protocol/messenger_contact_update_test.go b/protocol/messenger_contact_update_test.go new file mode 100644 index 00000000000..f4c069529a0 --- /dev/null +++ b/protocol/messenger_contact_update_test.go @@ -0,0 +1,143 @@ +package protocol + +import ( + "context" + "crypto/ecdsa" + "errors" + "io/ioutil" + "os" + "testing" + + "github.com/google/uuid" + gethbridge "github.com/status-im/status-go/eth-node/bridge/geth" + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/protocol/tt" + "github.com/status-im/status-go/whisper/v6" + "github.com/stretchr/testify/suite" + "go.uber.org/zap" +) + +func TestMessengerContactUpdateSuite(t *testing.T) { + suite.Run(t, new(MessengerContactUpdateSuite)) +} + +type MessengerContactUpdateSuite struct { + suite.Suite + m *Messenger // main instance of Messenger + privateKey *ecdsa.PrivateKey // private key for the main instance of Messenger + // If one wants to send messages between different instances of Messenger, + // a single Whisper service should be shared. + shh types.Whisper + tmpFiles []*os.File // files to clean up + logger *zap.Logger +} + +func (s *MessengerContactUpdateSuite) SetupTest() { + s.logger = tt.MustCreateTestLogger() + + config := whisper.DefaultConfig + config.MinimumAcceptedPOW = 0 + shh := whisper.New(&config) + s.shh = gethbridge.NewGethWhisperWrapper(shh) + s.Require().NoError(shh.Start(nil)) + + s.m = s.newMessenger(s.shh) + s.privateKey = s.m.identity +} + +func (s *MessengerContactUpdateSuite) newMessengerWithKey(shh types.Whisper, privateKey *ecdsa.PrivateKey) *Messenger { + tmpFile, err := ioutil.TempFile("", "") + s.Require().NoError(err) + + options := []Option{ + WithCustomLogger(s.logger), + WithMessagesPersistenceEnabled(), + WithDatabaseConfig(tmpFile.Name(), "some-key"), + WithDatasync(), + } + m, err := NewMessenger( + privateKey, + &testNode{shh: shh}, + uuid.New().String(), + options..., + ) + s.Require().NoError(err) + + err = m.Init() + s.Require().NoError(err) + + s.tmpFiles = append(s.tmpFiles, tmpFile) + + return m +} + +func (s *MessengerContactUpdateSuite) newMessenger(shh types.Whisper) *Messenger { + privateKey, err := crypto.GenerateKey() + s.Require().NoError(err) + + return s.newMessengerWithKey(s.shh, privateKey) +} + +func (s *MessengerContactUpdateSuite) TestReceiveContactUpdate() { + theirName := "ens-name.stateofus.eth" + theirPicture := "their-picture" + contactID := types.EncodeHex(crypto.FromECDSAPub(&s.m.identity.PublicKey)) + + theirMessenger := s.newMessenger(s.shh) + theirContactID := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + response, err := theirMessenger.SendContactUpdate(context.Background(), contactID, theirName, theirPicture) + s.Require().NoError(err) + s.Require().NotNil(response) + + s.Require().Len(response.Contacts, 1) + contact := response.Contacts[0] + s.Require().True(contact.IsAdded()) + + s.Require().Len(response.Chats, 1) + chat := response.Chats[0] + s.Require().False(chat.Active, "It does not create an active chat") + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = s.m.RetrieveAll() + if err == nil && len(response.Contacts) == 0 { + err = errors.New("contact request not received") + } + return err + }) + s.Require().NoError(err) + + receivedContact := response.Contacts[0] + s.Require().Equal(theirName, receivedContact.Name) + s.Require().Equal(theirPicture, receivedContact.Photo) + s.Require().False(receivedContact.ENSVerified) + s.Require().True(receivedContact.HasBeenAdded()) + s.Require().NotEmpty(receivedContact.LastUpdated) + + newName := "new-name" + newPicture := "new-picture" + err = theirMessenger.SendContactUpdates(context.Background(), newName, newPicture) + s.Require().NoError(err) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = s.m.RetrieveAll() + if err == nil && len(response.Contacts) == 0 || (len(response.Contacts) == 1 && response.Contacts[0].ID != theirContactID) { + err = errors.New("contact request not received") + } + return err + }) + s.Require().NoError(err) + + receivedContact = response.Contacts[0] + s.Require().Equal(theirContactID, receivedContact.ID) + s.Require().Equal(newName, receivedContact.Name) + s.Require().Equal(newPicture, receivedContact.Photo) + s.Require().False(receivedContact.ENSVerified) + s.Require().True(receivedContact.HasBeenAdded()) + s.Require().NotEmpty(receivedContact.LastUpdated) +} diff --git a/protocol/messenger_installations_test.go b/protocol/messenger_installations_test.go new file mode 100644 index 00000000000..46e61b3d3ba --- /dev/null +++ b/protocol/messenger_installations_test.go @@ -0,0 +1,147 @@ +package protocol + +import ( + "context" + "crypto/ecdsa" + "errors" + "io/ioutil" + "os" + "testing" + + "github.com/google/uuid" + gethbridge "github.com/status-im/status-go/eth-node/bridge/geth" + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/protocol/encryption/multidevice" + "github.com/status-im/status-go/protocol/tt" + "github.com/status-im/status-go/whisper/v6" + "github.com/stretchr/testify/suite" + "go.uber.org/zap" +) + +func TestMessengerInstallationSuite(t *testing.T) { + suite.Run(t, new(MessengerInstallationSuite)) +} + +type MessengerInstallationSuite struct { + suite.Suite + m *Messenger // main instance of Messenger + privateKey *ecdsa.PrivateKey // private key for the main instance of Messenger + // If one wants to send messages between different instances of Messenger, + // a single Whisper service should be shared. + shh types.Whisper + tmpFiles []*os.File // files to clean up + logger *zap.Logger + installationID string +} + +func (s *MessengerInstallationSuite) SetupTest() { + s.logger = tt.MustCreateTestLogger() + + config := whisper.DefaultConfig + config.MinimumAcceptedPOW = 0 + shh := whisper.New(&config) + s.shh = gethbridge.NewGethWhisperWrapper(shh) + s.Require().NoError(shh.Start(nil)) + + s.m = s.newMessenger(s.shh) + s.privateKey = s.m.identity +} + +func (s *MessengerInstallationSuite) newMessengerWithKey(shh types.Whisper, privateKey *ecdsa.PrivateKey) *Messenger { + tmpFile, err := ioutil.TempFile("", "") + s.Require().NoError(err) + + options := []Option{ + WithCustomLogger(s.logger), + WithMessagesPersistenceEnabled(), + WithDatabaseConfig(tmpFile.Name(), "some-key"), + WithDatasync(), + } + installationID := uuid.New().String() + m, err := NewMessenger( + privateKey, + &testNode{shh: shh}, + installationID, + options..., + ) + s.Require().NoError(err) + + err = m.Init() + s.Require().NoError(err) + + s.tmpFiles = append(s.tmpFiles, tmpFile) + + return m +} + +func (s *MessengerInstallationSuite) newMessenger(shh types.Whisper) *Messenger { + privateKey, err := crypto.GenerateKey() + s.Require().NoError(err) + + return s.newMessengerWithKey(s.shh, privateKey) +} + +func (s *MessengerInstallationSuite) TestReceiveInstallation() { + theirMessenger := s.newMessengerWithKey(s.shh, s.privateKey) + + err := theirMessenger.SetInstallationMetadata(theirMessenger.installationID, &multidevice.InstallationMetadata{ + Name: "their-name", + DeviceType: "their-device-type", + }) + s.Require().NoError(err) + response, err := theirMessenger.SendPairInstallation(context.Background()) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().False(response.Chats[0].Active) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = s.m.RetrieveAll() + if err == nil && len(response.Installations) == 0 { + err = errors.New("installation not received") + } + return err + }) + s.Require().NoError(err) + actualInstallation := response.Installations[0] + s.Require().Equal(theirMessenger.installationID, actualInstallation.ID) + s.Require().NotNil(actualInstallation.InstallationMetadata) + s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name) + s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType) + + err = s.m.EnableInstallation(theirMessenger.installationID) + s.Require().NoError(err) + + contactKey, err := crypto.GenerateKey() + s.Require().NoError(err) + + contact, err := buildContact(&contactKey.PublicKey) + s.Require().NoError(err) + contact.SystemTags = append(contact.SystemTags, contactAdded) + err = s.m.SaveContact(contact) + s.Require().NoError(err) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = theirMessenger.RetrieveAll() + if err == nil && len(response.Contacts) == 0 { + err = errors.New("contact not received") + } + if len(response.Contacts) != 0 && response.Contacts[0].ID != contact.ID { + err = errors.New("contact not received") + } + return err + }) + s.Require().NoError(err) + + actualContact := response.Contacts[0] + s.Require().Equal(contact.ID, actualContact.ID) + s.Require().True(actualContact.IsAdded()) +} + +func (s *MessengerInstallationSuite) TestReceiveSyncInstallation() { +} diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index 4bba5c8afe5..df72fdca40c 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -7,8 +7,10 @@ import ( "encoding/json" "errors" "io/ioutil" + "math/big" "os" "strconv" + "strings" "testing" "time" @@ -18,11 +20,11 @@ import ( "go.uber.org/zap" gethbridge "github.com/status-im/status-go/eth-node/bridge/geth" + coretypes "github.com/status-im/status-go/eth-node/core/types" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" enstypes "github.com/status-im/status-go/eth-node/types/ens" "github.com/status-im/status-go/protocol/protobuf" - "github.com/status-im/status-go/protocol/sqlite" "github.com/status-im/status-go/protocol/tt" v1protocol "github.com/status-im/status-go/protocol/v1" "github.com/status-im/status-go/whisper/v6" @@ -36,8 +38,8 @@ func TestMessengerWithDataSyncEnabledSuite(t *testing.T) { suite.Run(t, &MessengerSuite{enableDataSync: true}) } -func TestPostProcessorSuite(t *testing.T) { - suite.Run(t, new(PostProcessorSuite)) +func TestMessageHandlerSuite(t *testing.T) { + suite.Run(t, new(MessageHandlerSuite)) } type MessengerSuite struct { @@ -62,6 +64,14 @@ func (n *testNode) NewENSVerifier(_ *zap.Logger) enstypes.ENSVerifier { panic("not implemented") } +func (n *testNode) AddPeer(_ string) error { + panic("not implemented") +} + +func (n *testNode) RemovePeer(_ string) error { + panic("not implemented") +} + func (n *testNode) GetWhisper(_ interface{}) (types.Whisper, error) { return n.shh, nil } @@ -582,11 +592,9 @@ func (s *MessengerSuite) TestResendPublicMessage() { sentMessage := sendResponse1.Messages[0] - sendResponse2, err := theirMessenger.ReSendChatMessage(context.Background(), sentMessage.ID) + err = theirMessenger.ReSendChatMessage(context.Background(), sentMessage.ID) s.Require().NoError(err) - s.Require().Equal(sendResponse1.Messages[0].ID, sendResponse2.Messages[0].ID) - // Wait for the message to reach its destination var response *MessengerResponse err = tt.RetryWithBackOff(func() error { @@ -610,7 +618,7 @@ func (s *MessengerSuite) TestResendPublicMessage() { s.Require().NotNil(actualChat.LastMessage) // We send the messag again - _, err = theirMessenger.ReSendChatMessage(context.Background(), sentMessage.ID) + err = theirMessenger.ReSendChatMessage(context.Background(), sentMessage.ID) s.Require().NoError(err) // It should not be retrieved anymore @@ -703,90 +711,6 @@ func (s *MessengerSuite) TestRetrieveTheirPrivateChatNonExisting() { s.Require().True(actualChat.Active) } -// Test retrieve paired message -func (s *MessengerSuite) TestRetrieveOurPairedMessage() { - pairedMessenger := s.newMessengerWithKey(s.shh, s.privateKey) - chat := CreateOneToOneChat("XXX", &s.privateKey.PublicKey) - err := pairedMessenger.SaveChat(&chat) - s.NoError(err) - - inputMessage := buildTestMessage(chat) - - // Send a message so we now of the installation - sendResponse, err := pairedMessenger.SendChatMessage(context.Background(), inputMessage) - s.NoError(err) - s.Require().Len(sendResponse.Messages, 1) - - sentMessage := sendResponse.Messages[0] - - // Wait for the message to reach its destination - - var response *MessengerResponse - err = tt.RetryWithBackOff(func() error { - var err error - response, err = s.m.RetrieveAll() - if err == nil && len(response.Messages) == 0 { - err = errors.New("no messages") - } - return err - }) - s.Require().NoError(err) - // Check message is received - s.Require().Len(response.Messages, 1) - - actualChat := response.Chats[0] - // It does not update the unviewed message count - s.Require().Equal(uint(0), actualChat.UnviewedMessagesCount) - // It updates the last message clock value - s.Require().Equal(sentMessage.Clock, actualChat.LastClockValue) - // It sets the last message - s.Require().NotNil(actualChat.LastMessage) - - // Get installations - installations, err := s.m.Installations() - s.Require().NoError(err) - s.Require().Len(installations, 2) - - // Enable installations - err = s.m.EnableInstallation(installations[0].ID) - s.Require().NoError(err) - err = s.m.EnableInstallation(installations[1].ID) - s.Require().NoError(err) - - // We create new one to one chat - key, err := crypto.GenerateKey() - s.Require().NoError(err) - chat = CreateOneToOneChat("new-chat", &key.PublicKey) - err = s.m.SaveChat(&chat) - s.NoError(err) - - inputMessage = buildTestMessage(chat) - _, err = s.m.SendChatMessage(context.Background(), inputMessage) - s.NoError(err) - - // Wait for the message to reach its destination - err = tt.RetryWithBackOff(func() error { - var err error - response, err = pairedMessenger.RetrieveAll() - if err == nil && len(response.Messages) == 0 { - err = errors.New("no messages") - } - return err - }) - s.Require().NoError(err) - - // Check message is received - s.Require().Len(response.Messages, 1) - - message := response.Messages[0] - - // The chatID is the same chatID as the received one - s.Require().Equal(message.LocalChatID, chat.ID) - - // Sets the outgoing status - s.Equal(message.OutgoingStatus, OutgoingStatusSent) -} - // Test receiving a message on an non-existing public chat func (s *MessengerSuite) TestRetrieveTheirPublicChatNonExisting() { theirMessenger := s.newMessenger(s.shh) @@ -1535,11 +1459,651 @@ func (s *MessengerSuite) TestAddMembersToChat() { s.EqualValues([]string{publicKeyHex, keyHex}, []string{chat.Members[0].ID, chat.Members[1].ID}) } +func (s *MessengerSuite) TestDeclineRequestAddressForTransaction() { + value := "0.01" + contract := "some-contract" + theirMessenger := s.newMessenger(s.shh) + theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) + err := s.m.SaveChat(&chat) + s.Require().NoError(err) + + myAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + + response, err := s.m.RequestAddressForTransaction(context.Background(), theirPkString, myAddress.Hex(), value, contract) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + initialCommandID := senderMessage.ID + + s.Require().Equal("Request address for transaction", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestAddressForTransaction, senderMessage.CommandParameters.CommandState) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = theirMessenger.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + s.Require().Equal("Request address for transaction", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestAddressForTransaction, receiverMessage.CommandParameters.CommandState) + + // We decline the request + response, err = theirMessenger.DeclineRequestAddressForTransaction(context.Background(), receiverMessage.ID) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + s.Require().Equal("Request address for transaction declined", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(CommandStateRequestAddressForTransactionDeclined, senderMessage.CommandParameters.CommandState) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(receiverMessage.ID, senderMessage.Replace) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = s.m.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + s.Require().Equal("Request address for transaction declined", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(CommandStateRequestAddressForTransactionDeclined, receiverMessage.CommandParameters.CommandState) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(initialCommandID, receiverMessage.Replace) +} + +func (s *MessengerSuite) TestSendEthTransaction() { + value := "2000" + + theirMessenger := s.newMessenger(s.shh) + theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + receiverAddress := crypto.PubkeyToAddress(theirMessenger.identity.PublicKey) + receiverAddressString := strings.ToLower(receiverAddress.Hex()) + + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) + err := s.m.SaveChat(&chat) + s.Require().NoError(err) + + transactionHash := "0x412a851ac2ae51cad34a56c8a9cfee55d577ac5e1ac71cf488a2f2093a373799" + signature, err := buildSignature(s.m.identity, &s.m.identity.PublicKey, transactionHash) + s.Require().NoError(err) + + response, err := s.m.SendTransaction(context.Background(), theirPkString, transactionHash, signature) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + s.Require().Equal("Transaction sent", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(transactionHash, senderMessage.CommandParameters.TransactionHash) + s.Require().Equal(signature, senderMessage.CommandParameters.Signature) + s.Require().Equal(CommandStateTransactionSent, senderMessage.CommandParameters.CommandState) + s.Require().NotEmpty(senderMessage.ID) + s.Require().Equal("", senderMessage.Replace) + + var transactions []*TransactionToValidate + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + + _, err = theirMessenger.RetrieveAll() + if err != nil { + return err + } + transactions, err = theirMessenger.persistence.TransactionsToValidate() + if err == nil && len(transactions) == 0 { + err = errors.New("no transactions") + } + return err + }) + s.Require().NoError(err) + + actualTransaction := transactions[0] + + s.Require().Equal(&s.m.identity.PublicKey, actualTransaction.From) + s.Require().Equal(transactionHash, actualTransaction.TransactionHash) + s.Require().True(actualTransaction.Validate) + + senderAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + + client := MockEthClient{} + valueBig, ok := big.NewInt(0).SetString(value, 10) + s.Require().True(ok) + client.messages = make(map[string]MockTransaction) + client.messages[transactionHash] = MockTransaction{ + Message: coretypes.NewMessage( + senderAddress, + &receiverAddress, + 1, + valueBig, + 0, + nil, + nil, + false, + ), + } + theirMessenger.verifyTransactionClient = client + response, err = theirMessenger.ValidateTransactions(context.Background(), []types.Address{receiverAddress}) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + + s.Require().Equal("Transaction received", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(strings.ToLower(receiverAddress.Hex()), receiverMessage.CommandParameters.Address) + s.Require().Equal(transactionHash, receiverMessage.CommandParameters.TransactionHash) + s.Require().Equal(receiverAddressString, receiverMessage.CommandParameters.Address) + s.Require().Equal("", receiverMessage.CommandParameters.ID) + s.Require().Equal(CommandStateTransactionSent, receiverMessage.CommandParameters.CommandState) + s.Require().Equal(senderMessage.ID, receiverMessage.ID) + s.Require().Equal("", receiverMessage.Replace) +} + +func (s *MessengerSuite) TestSendTokenTransaction() { + value := "2000" + contract := "0x314159265dd8dbb310642f98f50c066173c1259b" + + theirMessenger := s.newMessenger(s.shh) + theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + receiverAddress := crypto.PubkeyToAddress(theirMessenger.identity.PublicKey) + receiverAddressString := strings.ToLower(receiverAddress.Hex()) + + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) + err := s.m.SaveChat(&chat) + s.Require().NoError(err) + + transactionHash := "0x412a851ac2ae51cad34a56c8a9cfee55d577ac5e1ac71cf488a2f2093a373799" + signature, err := buildSignature(s.m.identity, &s.m.identity.PublicKey, transactionHash) + s.Require().NoError(err) + + response, err := s.m.SendTransaction(context.Background(), theirPkString, transactionHash, signature) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + s.Require().Equal("Transaction sent", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(transactionHash, senderMessage.CommandParameters.TransactionHash) + s.Require().Equal(signature, senderMessage.CommandParameters.Signature) + s.Require().Equal(CommandStateTransactionSent, senderMessage.CommandParameters.CommandState) + s.Require().NotEmpty(senderMessage.ID) + + var transactions []*TransactionToValidate + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + + _, err = theirMessenger.RetrieveAll() + if err != nil { + return err + } + transactions, err = theirMessenger.persistence.TransactionsToValidate() + if err == nil && len(transactions) == 0 { + err = errors.New("no transactions") + } + return err + }) + s.Require().NoError(err) + + actualTransaction := transactions[0] + + s.Require().Equal(&s.m.identity.PublicKey, actualTransaction.From) + s.Require().Equal(transactionHash, actualTransaction.TransactionHash) + s.Require().True(actualTransaction.Validate) + + senderAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + + contractAddress := types.HexToAddress(contract) + client := MockEthClient{} + valueBig, ok := big.NewInt(0).SetString(value, 10) + s.Require().True(ok) + client.messages = make(map[string]MockTransaction) + client.messages[transactionHash] = MockTransaction{ + Message: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + nil, + 0, + nil, + buildData(transferFunction, receiverAddress, valueBig), + false, + ), + } + theirMessenger.verifyTransactionClient = client + response, err = theirMessenger.ValidateTransactions(context.Background(), []types.Address{receiverAddress}) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + + s.Require().Equal("Transaction received", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(transactionHash, receiverMessage.CommandParameters.TransactionHash) + s.Require().Equal(receiverAddressString, receiverMessage.CommandParameters.Address) + s.Require().Equal("", receiverMessage.CommandParameters.ID) + s.Require().Equal(CommandStateTransactionSent, receiverMessage.CommandParameters.CommandState) + s.Require().Equal(senderMessage.ID, receiverMessage.ID) + s.Require().Equal(senderMessage.Replace, senderMessage.Replace) +} + +func (s *MessengerSuite) TestAcceptRequestAddressForTransaction() { + value := "0.01" + contract := "some-contract" + theirMessenger := s.newMessenger(s.shh) + theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + myAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) + err := s.m.SaveChat(&chat) + s.Require().NoError(err) + + response, err := s.m.RequestAddressForTransaction(context.Background(), theirPkString, myAddress.Hex(), value, contract) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + initialCommandID := senderMessage.ID + + s.Require().Equal("Request address for transaction", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestAddressForTransaction, senderMessage.CommandParameters.CommandState) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = theirMessenger.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + s.Require().Equal("Request address for transaction", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestAddressForTransaction, receiverMessage.CommandParameters.CommandState) + + // We accept the request + response, err = theirMessenger.AcceptRequestAddressForTransaction(context.Background(), receiverMessage.ID, "some-address") + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + s.Require().Equal("Request address for transaction accepted", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(CommandStateRequestAddressForTransactionAccepted, senderMessage.CommandParameters.CommandState) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal("some-address", senderMessage.CommandParameters.Address) + s.Require().Equal(receiverMessage.ID, senderMessage.Replace) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = s.m.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + s.Require().Equal("Request address for transaction accepted", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(CommandStateRequestAddressForTransactionAccepted, receiverMessage.CommandParameters.CommandState) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal("some-address", receiverMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, receiverMessage.Replace) +} + +func (s *MessengerSuite) TestDeclineRequestTransaction() { + value := "2000" + contract := "0x314159265dd8dbb310642f98f50c066173c1259b" + receiverAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + receiverAddressString := strings.ToLower(receiverAddress.Hex()) + theirMessenger := s.newMessenger(s.shh) + theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) + err := s.m.SaveChat(&chat) + s.Require().NoError(err) + + response, err := s.m.RequestTransaction(context.Background(), theirPkString, value, contract, receiverAddressString) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + initialCommandID := senderMessage.ID + + s.Require().Equal("Request transaction", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(receiverAddressString, senderMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestTransaction, senderMessage.CommandParameters.CommandState) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = theirMessenger.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + s.Require().Equal("Request transaction", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(receiverAddressString, receiverMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestTransaction, receiverMessage.CommandParameters.CommandState) + + response, err = theirMessenger.DeclineRequestTransaction(context.Background(), initialCommandID) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + + s.Require().Equal("Transaction request declined", senderMessage.Text) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(receiverMessage.ID, senderMessage.Replace) + s.Require().Equal(CommandStateRequestTransactionDeclined, senderMessage.CommandParameters.CommandState) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = s.m.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + + s.Require().Equal("Transaction request declined", receiverMessage.Text) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(initialCommandID, receiverMessage.Replace) + s.Require().Equal(CommandStateRequestTransactionDeclined, receiverMessage.CommandParameters.CommandState) +} + +func (s *MessengerSuite) TestRequestTransaction() { + value := "2000" + contract := "0x314159265dd8dbb310642f98f50c066173c1259b" + receiverAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + receiverAddressString := strings.ToLower(receiverAddress.Hex()) + theirMessenger := s.newMessenger(s.shh) + theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) + err := s.m.SaveChat(&chat) + s.Require().NoError(err) + + response, err := s.m.RequestTransaction(context.Background(), theirPkString, value, contract, receiverAddressString) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + initialCommandID := senderMessage.ID + + s.Require().Equal("Request transaction", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(receiverAddressString, senderMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestTransaction, senderMessage.CommandParameters.CommandState) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = theirMessenger.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + s.Require().Equal("Request transaction", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(receiverAddressString, receiverMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestTransaction, receiverMessage.CommandParameters.CommandState) + + transactionHash := "0x412a851ac2ae51cad34a56c8a9cfee55d577ac5e1ac71cf488a2f2093a373799" + signature, err := buildSignature(theirMessenger.identity, &theirMessenger.identity.PublicKey, transactionHash) + s.Require().NoError(err) + response, err = theirMessenger.AcceptRequestTransaction(context.Background(), transactionHash, initialCommandID, signature) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + + s.Require().Equal("Transaction sent", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(transactionHash, senderMessage.CommandParameters.TransactionHash) + s.Require().Equal(receiverAddressString, senderMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(signature, senderMessage.CommandParameters.Signature) + s.Require().NotEmpty(senderMessage.ID) + s.Require().Equal(receiverMessage.ID, senderMessage.Replace) + s.Require().Equal(CommandStateTransactionSent, senderMessage.CommandParameters.CommandState) + + var transactions []*TransactionToValidate + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + + _, err = s.m.RetrieveAll() + if err != nil { + return err + } + transactions, err = s.m.persistence.TransactionsToValidate() + if err == nil && len(transactions) == 0 { + err = errors.New("no transactions") + } + return err + }) + s.Require().NoError(err) + + actualTransaction := transactions[0] + + s.Require().Equal(&theirMessenger.identity.PublicKey, actualTransaction.From) + s.Require().Equal(transactionHash, actualTransaction.TransactionHash) + s.Require().True(actualTransaction.Validate) + s.Require().Equal(initialCommandID, actualTransaction.CommandID) + + senderAddress := crypto.PubkeyToAddress(theirMessenger.identity.PublicKey) + + contractAddress := types.HexToAddress(contract) + client := MockEthClient{} + valueBig, ok := big.NewInt(0).SetString(value, 10) + s.Require().True(ok) + client.messages = make(map[string]MockTransaction) + client.messages[transactionHash] = MockTransaction{ + Message: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + nil, + 0, + nil, + buildData(transferFunction, receiverAddress, valueBig), + false, + ), + } + s.m.verifyTransactionClient = client + response, err = s.m.ValidateTransactions(context.Background(), []types.Address{receiverAddress}) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + + s.Require().Equal("Transaction received", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(transactionHash, receiverMessage.CommandParameters.TransactionHash) + s.Require().Equal(receiverAddressString, receiverMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(signature, receiverMessage.CommandParameters.Signature) + s.Require().Equal(CommandStateTransactionSent, receiverMessage.CommandParameters.CommandState) + s.Require().Equal(senderMessage.ID, receiverMessage.ID) + s.Require().Equal(senderMessage.Replace, senderMessage.Replace) +} + +type MockTransaction struct { + Pending bool + Message coretypes.Message +} + +type MockEthClient struct { + messages map[string]MockTransaction +} + type mockSendMessagesRequest struct { types.Whisper req types.MessagesRequest } +func (m MockEthClient) TransactionByHash(ctx context.Context, hash types.Hash) (coretypes.Message, bool, error) { + mockTransaction, ok := m.messages[hash.Hex()] + if !ok { + return coretypes.Message{}, false, nil + } else { + return mockTransaction.Message, mockTransaction.Pending, nil + } +} + func (m *mockSendMessagesRequest) SendMessagesRequest(peerID []byte, request types.MessagesRequest) error { m.req = request return nil @@ -1559,7 +2123,7 @@ func (s *MessengerSuite) TestMessageJSON() { From: "from-field", } - expectedJSON := `{"id":"test-1","whisperTimestamp":0,"from":"from-field","alias":"alias","identicon":"","retryCount":0,"seen":false,"quotedMessage":null,"rtl":false,"parsedText":null,"lineCount":0,"text":"test-1","chatId":"remote-chat-id","localChatId":"local-chat-id","clock":1,"responseTo":"","ensName":"","sticker":null,"timestamp":0,"contentType":0,"messageType":0}` + expectedJSON := `{"id":"test-1","whisperTimestamp":0,"from":"from-field","alias":"alias","identicon":"","seen":false,"quotedMessage":null,"rtl":false,"parsedText":null,"lineCount":0,"text":"test-1","chatId":"remote-chat-id","localChatId":"local-chat-id","clock":1,"replace":"","responseTo":"","ensName":"","sticker":null,"commandParameters":null,"timestamp":0,"contentType":0,"messageType":0}` messageJSON, err := json.Marshal(message) s.Require().NoError(err) @@ -1591,39 +2155,30 @@ func (s *MessengerSuite) testRequestHistoricMessagesRequest() { s.NotEmpty(shh.req.Bloom) } -type PostProcessorSuite struct { +type MessageHandlerSuite struct { suite.Suite - postProcessor *postProcessor - logger *zap.Logger + messageHandler *MessageHandler + logger *zap.Logger } -func (s *PostProcessorSuite) SetupTest() { +func (s *MessageHandlerSuite) SetupTest() { s.logger = tt.MustCreateTestLogger() privateKey, err := crypto.GenerateKey() s.Require().NoError(err) - db, err := sqlite.OpenInMemory() - s.Require().NoError(err) - - s.postProcessor = &postProcessor{ - myPublicKey: &privateKey.PublicKey, - persistence: &sqlitePersistence{db: db}, - logger: s.logger, - config: postProcessorConfig{ - MatchChat: true, - Persist: true, - Parse: true, - }, + s.messageHandler = &MessageHandler{ + identity: privateKey, + logger: s.logger, } } -func (s *PostProcessorSuite) TearDownTest() { +func (s *MessageHandlerSuite) TearDownTest() { _ = s.logger.Sync() } -func (s *PostProcessorSuite) TestRun() { +func (s *MessageHandlerSuite) TestRun() { key1, err := crypto.GenerateKey() s.Require().NoError(err) key2, err := crypto.GenerateKey() @@ -1721,12 +2276,6 @@ func (s *PostProcessorSuite) TestRun() { chatsMap := make(map[string]*Chat) if tc.Chat.ID != "" { chatsMap[tc.Chat.ID] = &tc.Chat - err := s.postProcessor.persistence.SaveChat(tc.Chat) - s.Require().NoError(err) - defer func() { - err := s.postProcessor.persistence.DeleteChat(tc.Chat.ID) - s.Require().NoError(err) - }() } message := tc.Message @@ -1735,7 +2284,7 @@ func (s *PostProcessorSuite) TestRun() { s.Empty(message.LocalChatID) message.ID = strconv.Itoa(idx) // manually set the ID because messages does not go through messageProcessor - chat, err := s.postProcessor.matchMessage(&message, chatsMap) + chat, err := s.messageHandler.matchMessage(&message, chatsMap) if tc.Error { s.Require().Error(err) } else { diff --git a/protocol/migrations/migrations.go b/protocol/migrations/migrations.go index 4ff613eac70..597b517f4bc 100644 --- a/protocol/migrations/migrations.go +++ b/protocol/migrations/migrations.go @@ -1,15 +1,7 @@ // Code generated by go-bindata. DO NOT EDIT. // sources: -// 000001_init.down.db.sql (82B) -// 000001_init.up.db.sql (832B) -// 000002_add_chats.down.db.sql (74B) -// 000002_add_chats.up.db.sql (495B) -// 000003_add_contacts.down.db.sql (21B) -// 000003_add_contacts.up.db.sql (381B) -// 000004_user_messages_compatibility.down.sql (33B) -// 000004_user_messages_compatibility.up.sql (980B) -// 1567112142_user_messages.down.sql (26B) -// 1567112142_user_messages.up.sql (543B) +// 000001_init.down.db.sql (65B) +// 000001_init.up.db.sql (2.693kB) // doc.go (377B) package migrations @@ -79,7 +71,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var __000001_initDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\xb6\xe6\x42\x92\xc9\x4d\xcd\x4d\x4a\x2d\x2a\xce\xc8\x2c\x88\x2f\x2d\x48\x49\x2c\x41\x93\x4e\xce\x48\x2c\x89\x87\xaa\xb1\xe6\x02\x04\x00\x00\xff\xff\x69\x98\x5e\xa1\x52\x00\x00\x00") +var __000001_initDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x48\xce\x48\x2c\x29\xb6\xe6\x42\x12\x29\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x45\x95\x49\xce\xcf\x2b\x49\x4c\x06\x29\x07\x04\x00\x00\xff\xff\x61\x86\xbd\x5f\x41\x00\x00\x00") func _000001_initDownDbSqlBytes() ([]byte, error) { return bindataRead( @@ -94,12 +86,12 @@ func _000001_initDownDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.down.db.sql", size: 82, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe8, 0x5f, 0xe0, 0x6, 0xfc, 0xed, 0xb7, 0xff, 0xb5, 0xf3, 0x33, 0x45, 0x1, 0x5b, 0x84, 0x80, 0x74, 0x60, 0x81, 0xa6, 0x8b, 0xb4, 0xd4, 0xad, 0x10, 0xa8, 0xb3, 0x61, 0x6f, 0xc5, 0x2f, 0xaa}} + info := bindataFileInfo{name: "000001_init.down.db.sql", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1577718673, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5e, 0xbb, 0x3f, 0x1, 0x75, 0x19, 0x70, 0x86, 0xa7, 0x34, 0x40, 0x17, 0x34, 0x3e, 0x18, 0x51, 0x79, 0xd4, 0x22, 0xad, 0x8f, 0x80, 0xcc, 0xa6, 0xcc, 0x6, 0x2b, 0x62, 0x2, 0x47, 0xba, 0xf9}} return a, nil } -var __000001_initUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x92\xcd\x6e\xea\x30\x10\x85\xf7\x79\x8a\x59\x12\x89\xc5\xdd\xdf\x95\x03\x13\xb0\x9a\xda\xad\xe3\x14\x58\x45\x26\x71\xc1\x85\x84\x08\x1b\xa9\xbc\x7d\x45\x7e\x68\x48\xab\x0a\x96\x9e\x39\x3e\x9e\xef\x8c\x27\x02\x89\x44\x90\x24\x88\x10\x68\x08\x8c\x4b\xc0\x25\x8d\x65\x0c\x27\xab\x8f\x69\xa1\xad\x55\x1b\x6d\x61\xe4\x01\x00\x98\x1c\x82\x88\x07\x90\x30\xfa\x9a\x60\xad\x66\x49\x14\x8d\xeb\x66\xb6\x55\x2e\x35\x39\xbc\x11\x31\x99\x13\x31\xec\x1e\x4a\xa7\x4b\x97\xba\x73\xa5\x81\x32\xd9\x54\x5b\xff\x41\xd5\xe9\x4f\x07\x12\x97\xed\x31\xdb\x1f\xb2\x1d\x04\x74\xf6\x2d\x30\x85\xb6\x4e\x15\xd5\x4d\xb5\x7b\xa2\x1b\xa4\xe7\xd0\x3d\x7e\x6b\x5c\x9d\xd6\x7b\x93\xa5\x3b\x7d\xae\xb1\x9a\xe2\xfb\x5e\x6d\xec\x65\x96\x2b\x00\x4c\x31\x24\x49\x24\xe1\x9f\xe7\xff\xf7\xbc\x36\x33\xca\xa6\xb8\xec\xa0\x2d\x70\x76\x9b\xd8\xa8\xed\xf4\x6e\xfc\x96\x72\xa1\x8b\xb5\x3e\xda\xad\xa9\xd2\x53\x95\x2b\xd7\x8f\xba\x0b\xf2\x45\xd0\x67\x22\x56\xf0\x84\xab\x41\xa8\xb9\x72\xaa\xd9\xc8\x23\xab\x08\xb9\x40\x3a\x63\xb5\xdf\x75\x4c\x10\x18\xa2\x40\x36\xc1\xb8\xbe\x6e\x47\x26\xf7\x3d\x1f\x16\x54\xce\x79\x22\x41\xf0\x05\x9d\xfe\xcd\x52\x5b\xb5\x40\x2d\xc5\x20\xe1\x87\xc6\x54\x79\x61\x4a\x08\x38\x8f\x90\xb0\x9f\xcb\x08\x49\x14\x63\xa3\xfc\x38\x98\x52\xe7\x77\x49\xef\x67\x6f\xf4\xcd\x4f\xef\x94\xe3\x1e\x90\x7f\xf9\x0c\x5f\x01\x00\x00\xff\xff\x22\x17\x48\xa6\x40\x03\x00\x00") +var __000001_initUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x56\x51\x6f\xe3\x36\x0c\x7e\xf7\xaf\x20\xb0\x87\xb6\x80\x3b\xdc\x80\xdb\x6d\x40\x9f\xd2\x9e\xbb\x05\xcb\x92\x43\xea\x0e\xbd\x27\x81\x91\xd8\x58\x88\x2d\x19\x12\x9d\x5c\x80\xfb\xf1\x83\x9c\x38\xb1\x12\xa7\xbd\x61\x7d\x28\x5a\x52\x24\xc5\x8f\xfc\x3e\xf9\x61\x9e\x8d\xf2\x0c\xf2\xd1\xfd\x24\x83\xf1\x23\x4c\x67\x39\x64\x2f\xe3\xa7\xfc\x09\x64\x81\xec\xe1\x3a\xd1\x0a\xfe\x19\xcd\x1f\xfe\x1c\xcd\xe1\xcb\x7c\xfc\xf7\x68\xfe\x15\xfe\xca\xbe\xc2\x6c\x0a\x0f\xb3\xe9\xe3\x64\xfc\x90\xc3\x3c\xfb\x32\x19\x3d\x64\x69\x62\xb0\xa2\xc3\xe9\x90\x6b\xfa\x3c\x99\xa4\x89\xb4\xa5\x75\x67\x76\xf8\x9c\x3d\x8e\x9e\x27\x39\x5c\xfd\x84\xbf\xfc\xfe\x9b\xfa\xf5\x2a\x4d\x78\x5b\x13\x8c\xa7\x79\x2f\x18\x25\xeb\x35\xc1\xfd\x6c\x36\xc9\x46\xd3\xf3\xe8\x7c\xfe\x9c\xa5\x09\xeb\x8a\x3c\x63\x55\x9f\x44\x2b\x2a\x89\x49\x09\x64\x21\x4b\x2b\x57\x62\x8d\x65\x13\x97\x38\x64\xfa\x90\x26\x75\xb3\x28\xb5\x14\x2b\xda\xc2\xfd\x64\x76\x9f\x26\x8d\x59\x6b\xda\x90\x12\x15\x79\x8f\x4b\x12\xd2\x36\x86\x2f\xc6\x97\xe8\x7f\xac\x50\x7b\x70\x9f\x73\x5f\xaa\xa2\x6a\x41\xce\xc7\xff\x15\xba\x16\x4d\xad\x90\x69\xe7\x48\x6e\xee\x92\x24\x9a\x9a\xb4\x86\x51\xb6\xa3\x02\xd0\x0a\xf2\xec\x25\x7f\x7f\x52\x00\xa8\x94\x23\xef\x77\xe7\x8f\x80\x01\xb4\x43\x3c\xb3\x92\xf1\x62\x4d\x4e\xbf\x6a\x52\x87\x61\x74\x0d\x3d\x8e\x26\x4f\xd9\xe9\x29\x81\x97\x71\x02\xc0\x52\xe3\x40\x71\xad\xc8\xb0\x96\xd6\x9c\xbb\xea\xc2\xb2\x3d\x37\xb7\x48\xee\x20\x52\x6f\xd4\xf3\x5b\xcf\x54\x09\xc6\x65\x87\x30\x80\xa2\xb5\x96\x24\xb4\x79\xb5\x07\x1b\x3b\xbd\x68\x98\x04\x5b\xc1\x58\xae\xe2\x7a\x2d\xfa\xb7\xb7\x30\xe6\x2b\x0f\xba\xaa\xad\x63\x34\x0c\x5c\x60\xf8\xa5\x3d\x30\x2e\x4a\x82\x02\x3d\x38\xbb\xd1\x0a\xd0\xc3\x86\xc0\x51\xb9\x05\x6b\x40\x73\x08\xde\x14\x64\x42\x70\x49\x55\xe8\xd5\x2c\x41\x9b\x57\x6d\x34\xd3\xad\x97\xce\x96\xe5\xcf\xc9\x1b\xb4\x6c\x3c\xb9\x6e\x71\x76\x33\x6f\xa7\xfe\xc3\x14\x0d\xe7\x37\x85\xf6\x35\x39\x11\x91\x26\xfb\x23\x9b\x47\xc0\x02\x78\xdb\x38\x39\xb0\x0b\x01\x39\xcf\xda\x20\x6b\x6b\x0e\xc8\x01\x30\x7d\xe3\x01\xfa\x07\x57\xd8\x52\x32\x2c\x06\x08\x1e\xdc\xa1\xab\xbe\x78\xec\xf3\x5d\x20\x75\x9b\xb0\x40\x16\xbd\xc6\x63\x6f\x69\x25\x96\xe2\xed\x33\x85\x56\x74\x79\x93\x01\x1c\xf9\xda\x1a\x1f\x56\x21\xbe\x56\x27\x05\x5d\x2f\xfb\x0b\x5d\x60\xfd\x1e\x4a\x22\x73\x59\xc3\x7a\x55\x6d\xc3\x4b\xab\xcd\x52\x78\x46\x6e\x7c\x5c\xb9\x46\xe7\x49\x89\x16\xe7\x23\xec\x0e\x37\xa2\xc6\x6d\x69\x51\xf5\xac\x9e\xb5\x5c\x91\x13\x35\xca\xd5\xf1\x96\x9d\xb5\x40\x5f\xc4\xb9\xa5\xad\x2a\x34\xaa\x87\x57\x6c\xdf\x75\x36\xe8\xea\xa4\x64\xd0\xf9\xea\x6c\x35\xec\x09\x3b\xe1\x50\xf2\xb0\x97\x1d\x1a\x1f\xc4\xdf\x9a\x37\x6e\xeb\xf5\xd2\x20\x37\x8e\x7a\x9d\x1f\x7c\x8c\xdc\xce\xa2\x2f\x9a\xe3\xe9\xe7\xec\x05\xb4\xfa\x26\xf6\xdb\x3d\x9b\xc6\x9c\xba\xde\xd9\x6f\xee\x06\x22\x08\x9d\x2c\xc4\x62\x7b\xd8\xac\xd9\x14\x4e\xa2\x77\x28\x37\x0b\xcf\xee\xfa\xea\xc3\xff\xfc\xb9\x82\xef\xdf\xfb\x8b\x95\xc2\xed\xa7\x8f\x29\x7c\xfa\x78\x13\x1c\x5a\xa5\x1d\x0d\xd2\x76\x9b\xcf\x1f\x87\x58\x3b\xc2\xa2\x44\xd2\xf1\xdf\x84\xe3\x7d\x52\xb5\x5a\xec\xe9\xe4\x81\x6c\xe5\x97\xda\x81\x9f\xbe\x9d\x7b\x17\x5f\xe6\xa1\xa3\x36\x14\x1b\xb6\x15\xb2\x96\x58\x96\xdb\xcb\xa7\x87\xa8\xe9\x48\xea\x5a\x93\xe1\xa3\xf0\xf7\xd9\xf2\x0e\x66\x21\x23\x99\x65\x50\xcb\xe3\x42\xfa\xf0\x3c\xac\xb1\xd4\xe1\xd5\x69\x91\xec\x0a\xc7\xec\x39\xe7\x54\xd4\xf9\xa5\x15\xef\x0f\x63\xd7\x01\xbb\xed\x11\xbd\x60\x7a\xd5\xae\x85\x9a\x4c\x67\x89\x99\x10\xd7\xe9\x5d\xf6\x14\xba\xdd\xe7\x13\xc0\xc9\x97\xcf\x20\x63\x06\xb1\x88\xa0\x08\x7c\x78\x1f\xb1\xeb\xde\xdf\x37\x77\xc9\xbf\x01\x00\x00\xff\xff\xc7\x20\x3e\x09\x85\x0a\x00\x00") func _000001_initUpDbSqlBytes() ([]byte, error) { return bindataRead( @@ -114,168 +106,8 @@ func _000001_initUpDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.up.db.sql", size: 832, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x1c, 0xa4, 0xac, 0x0, 0xd3, 0x19, 0x53, 0x35, 0x91, 0x1c, 0x94, 0xea, 0xde, 0xa7, 0x75, 0xb6, 0x73, 0x1d, 0x42, 0x14, 0xca, 0x84, 0x5b, 0xdb, 0x10, 0x94, 0x28, 0xc0, 0x33, 0x95, 0x7f, 0xf}} - return a, nil -} - -var __000002_add_chatsDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\xc8\x4d\xcd\x4d\x4a\x2d\x2a\xce\xc8\x2c\x88\x2f\x2d\x48\x49\x2c\x49\x2d\xb6\xe6\x42\x92\x4e\xce\x48\x2c\x89\x87\xaa\xc1\x90\x28\xb6\xe6\x02\x04\x00\x00\xff\xff\xde\x59\xf6\x29\x4a\x00\x00\x00") - -func _000002_add_chatsDownDbSqlBytes() ([]byte, error) { - return bindataRead( - __000002_add_chatsDownDbSql, - "000002_add_chats.down.db.sql", - ) -} - -func _000002_add_chatsDownDbSql() (*asset, error) { - bytes, err := _000002_add_chatsDownDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000002_add_chats.down.db.sql", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd3, 0xa7, 0xf0, 0x94, 0x7a, 0x9, 0xdc, 0x6c, 0x7b, 0xdc, 0x12, 0x30, 0x55, 0x31, 0x17, 0xf2, 0xcc, 0x6e, 0xfd, 0xbb, 0x70, 0xb9, 0xd8, 0x9f, 0x81, 0x83, 0xdc, 0x1d, 0x1c, 0x3a, 0x8d, 0xce}} - return a, nil -} - -var __000002_add_chatsUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x91\xc1\x6a\x32\x31\x14\x85\xf7\xf7\x29\x2e\xfc\x0b\xff\xc2\x2c\xda\x45\x69\xc1\x55\x66\x8c\x74\x68\x3a\x91\x18\x4b\x5d\x85\x98\xb9\xd4\xc1\xc4\x19\x4c\xc6\xe2\xdb\x17\xdb\x41\xb4\x52\xe8\x32\xb9\xdf\x77\xce\xe2\x14\x8a\x33\xcd\x51\xb3\x5c\x70\x2c\xa7\x58\x49\x8d\xfc\xad\x9c\xeb\x39\xba\xb5\x4d\x11\xff\x43\x53\xe3\x2b\x53\xc5\x13\x53\x38\x53\xe5\x0b\x53\x4b\x7c\xe6\x4b\x94\x15\x16\xb2\x9a\x8a\xb2\xd0\xa8\xf8\x4c\xb0\x82\x67\xb0\xb5\x81\x4e\xf4\x31\xab\x5a\x08\x91\x81\x6b\x7d\xbb\xbb\xfa\xc7\x09\x9f\xb2\x85\xd0\x38\xfa\x67\xef\x1e\x1f\xea\xfb\x51\x06\xe9\xd0\x11\x96\x95\x3e\x93\xad\x4b\xcd\x9e\x30\x97\x52\x70\x56\x5d\xdb\x5a\x2d\x78\x06\xa9\x09\x14\x93\x0d\xdd\x0f\xbb\x26\x4f\x89\x6a\x63\x93\x71\xbe\x75\x1b\xb3\xb7\xbe\xbf\xac\x38\x25\xdd\x66\xd0\xf5\x2b\xdf\x38\xb3\xa1\x03\xe6\x42\xe6\x19\xf4\xdb\x7d\x43\x1f\x54\x9b\x40\x31\xda\x77\x32\xae\xed\xb7\xe9\x57\xdf\xdb\xf8\xb7\xa2\x2f\x70\xc8\x1c\xaa\x02\x85\x15\xed\xe2\xe5\x6b\xdd\x74\xa6\xef\x6a\x9b\xe8\xfb\x00\x37\x63\x00\x98\x28\x39\x1b\x46\xbb\xe6\xc6\xe7\xe7\xe3\x8a\x66\x60\xc6\xf0\x19\x00\x00\xff\xff\x99\xae\x9f\xf2\xef\x01\x00\x00") - -func _000002_add_chatsUpDbSqlBytes() ([]byte, error) { - return bindataRead( - __000002_add_chatsUpDbSql, - "000002_add_chats.up.db.sql", - ) -} - -func _000002_add_chatsUpDbSql() (*asset, error) { - bytes, err := _000002_add_chatsUpDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000002_add_chats.up.db.sql", size: 495, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6e, 0xca, 0x2b, 0xf7, 0xca, 0x21, 0xda, 0x17, 0x1f, 0x97, 0xa8, 0x12, 0xb5, 0x6c, 0xad, 0x92, 0xe7, 0x2, 0xaf, 0x1, 0xcb, 0x5e, 0xe9, 0x71, 0xc4, 0x81, 0xa7, 0x3, 0x93, 0x5b, 0x73, 0x73}} - return a, nil -} - -var __000003_add_contactsDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x48\xce\xcf\x2b\x49\x4c\x2e\x29\xb6\xe6\x02\x04\x00\x00\xff\xff\x66\x64\xd9\xdd\x15\x00\x00\x00") - -func _000003_add_contactsDownDbSqlBytes() ([]byte, error) { - return bindataRead( - __000003_add_contactsDownDbSql, - "000003_add_contacts.down.db.sql", - ) -} - -func _000003_add_contactsDownDbSql() (*asset, error) { - bytes, err := _000003_add_contactsDownDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000003_add_contacts.down.db.sql", size: 21, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfc, 0x7e, 0xb, 0xec, 0x72, 0xcd, 0x21, 0x3e, 0xa2, 0x38, 0xe0, 0x95, 0x7e, 0xce, 0x4a, 0x17, 0xc8, 0xd0, 0x1c, 0xfa, 0xa3, 0x23, 0x5, 0xab, 0x89, 0xf9, 0xfc, 0x63, 0x7, 0x28, 0xe9, 0x93}} - return a, nil -} - -var __000003_add_contactsUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x8d\x41\x4b\x33\x31\x14\x45\xf7\xf3\x2b\xee\xf2\xfb\xc0\x85\x7b\x57\x99\xf1\x15\x06\x63\x52\xc6\x14\xec\x2a\xc4\xc9\xab\x06\xa7\x49\x99\xbc\x16\xfc\xf7\x52\x85\x8a\x8e\xb8\x3d\xf7\x70\x4f\x37\x90\x72\x04\xa7\x5a\x4d\x18\x4b\x96\x30\x4a\xc5\xbf\x06\x48\x11\x8e\x1e\x1d\xd6\x43\x7f\xaf\x86\x2d\xee\x68\x0b\x6b\xd0\x59\xb3\xd2\x7d\xe7\x30\xd0\x5a\xab\x8e\xae\x1a\x20\xc4\x38\x73\xad\x9f\xbe\xb1\x0e\x66\xa3\xf5\x79\xc8\x61\xcf\x4b\xca\xb9\xfa\x13\xcf\x69\x97\x38\xa2\xb5\x56\x93\x32\xb8\xa5\x95\xda\x68\x87\x95\xd2\x0f\xf4\xd3\xf2\x41\xd0\x9b\xaf\x97\x8b\x7d\xfd\x91\x9f\x52\xf8\x25\x9e\x22\x67\x49\x63\xc9\xcb\xe9\xf0\x52\xa4\x2c\xf1\x14\xaa\xf8\xe3\x21\x06\xe1\xf8\x47\xaf\xbe\x55\xe1\xbd\x97\xf0\x5c\xd1\x6a\xdb\x9e\x59\xe4\x53\x1a\xd9\xa7\xbc\x2b\x17\x26\x73\x7a\x3a\x0a\x7b\x29\x5e\xc2\xf4\xfa\xbd\xd7\xfc\xbf\x69\xde\x03\x00\x00\xff\xff\xc5\xff\x5b\xb1\x7d\x01\x00\x00") - -func _000003_add_contactsUpDbSqlBytes() ([]byte, error) { - return bindataRead( - __000003_add_contactsUpDbSql, - "000003_add_contacts.up.db.sql", - ) -} - -func _000003_add_contactsUpDbSql() (*asset, error) { - bytes, err := _000003_add_contactsUpDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000003_add_contacts.up.db.sql", size: 381, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x45, 0xfe, 0x1e, 0xf2, 0x75, 0x33, 0x37, 0x8e, 0x7f, 0x93, 0x6f, 0x16, 0xbb, 0xf8, 0xa4, 0x70, 0x6b, 0xe0, 0xc1, 0x4f, 0x99, 0x8d, 0xc8, 0x2d, 0x40, 0xf1, 0xed, 0x65, 0x90, 0xc3, 0xad, 0xc7}} - return a, nil -} - -var __000004_user_messages_compatibilityDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\x8e\xcf\x49\x4d\x4f\x4c\xae\xb4\xe6\x02\x04\x00\x00\xff\xff\x25\xef\xa4\x66\x21\x00\x00\x00") - -func _000004_user_messages_compatibilityDownSqlBytes() ([]byte, error) { - return bindataRead( - __000004_user_messages_compatibilityDownSql, - "000004_user_messages_compatibility.down.sql", - ) -} - -func _000004_user_messages_compatibilityDownSql() (*asset, error) { - bytes, err := _000004_user_messages_compatibilityDownSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000004_user_messages_compatibility.down.sql", size: 33, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb9, 0xaf, 0x48, 0x80, 0x3d, 0x54, 0x5e, 0x53, 0xee, 0x98, 0x26, 0xbb, 0x99, 0x6a, 0xd8, 0x37, 0x94, 0xf2, 0xf, 0x82, 0xfa, 0xb7, 0x6a, 0x68, 0xcd, 0x8b, 0xe2, 0xc4, 0x6, 0x25, 0xdc, 0x6}} - return a, nil -} - -var __000004_user_messages_compatibilityUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x52\xc1\x6e\xda\x40\x10\xbd\xf3\x15\x73\x0b\x48\xb8\xca\x21\xca\x25\x27\x43\x96\xd6\xaa\x6b\x47\xc6\xa9\xc8\x69\xb5\xd8\x53\xbc\x62\xbd\x6b\xed\x8c\x4b\x2c\xe5\xe3\x2b\x03\x26\x40\x51\x2f\xf5\xc1\x87\x79\x33\x6f\xde\xdb\x79\x41\x00\x11\xdf\x11\xe8\xba\x71\x9e\x95\x65\xe0\x4a\xf5\x3f\x4d\xc0\x6a\x6d\x10\x2a\x45\xe0\xdd\x4e\x97\xa0\x08\x76\x08\x1e\x4d\x07\xce\x82\xe6\x51\x10\xc0\xae\x42\xdb\x0f\x1b\xac\xd1\xb2\xb6\x1b\xd0\xf6\x97\xb6\x9a\x31\xa0\xc2\x3b\x63\xbe\x8c\xe6\x99\x08\x73\x01\x79\x38\x8b\x05\x44\x0b\x48\xd2\x1c\xc4\x2a\x5a\xe6\x4b\x68\x09\xbd\xac\x91\x48\x6d\x90\xa4\xc1\x8d\x2a\x3a\x18\x8f\x00\x00\x74\x09\x3f\xc3\x6c\xfe\x2d\xcc\xe0\x25\x8b\x7e\x84\xd9\x1b\x7c\x17\x6f\x90\x26\x30\x4f\x93\x45\x1c\xcd\x73\xc8\xc4\x4b\x1c\xce\xc5\x74\xdf\xbf\xab\x34\x35\xe8\x25\xeb\x1a\x89\x55\xdd\x40\x94\xe4\xe2\xab\xc8\xf6\xfb\x92\xd7\x38\x3e\xf4\x91\x6b\x7d\x81\x90\x8b\x55\x7e\x85\x94\x48\xac\xad\x62\xed\x2c\xcc\xe2\x74\x76\xa8\x32\xbe\xf3\x49\xc9\xe5\x40\xe1\x2c\xa3\x65\xc9\x5d\x83\xfd\xb6\x2b\xb8\x37\x67\x55\x8d\xc3\xf4\x91\xef\x5c\xdf\x35\x61\xa5\x58\x9e\x19\xbf\x44\x8d\x2b\x94\x91\xff\xee\xf1\xc8\xbe\x93\x85\x6b\x2d\x5f\xf0\xc3\xb3\x58\x84\xaf\x71\x0e\xf7\x43\x1f\x35\xce\x12\x4a\x76\x97\xf2\x8e\xc7\x38\x79\x3a\x0a\x33\xae\xd8\xca\xdf\xca\xb4\xb7\x8c\x12\xa2\x85\x59\x9a\xc6\x22\x4c\xfe\xde\xb8\x08\xe3\xe5\xf1\x46\xae\xe5\x8d\xd3\x76\x23\x89\x15\xb7\x74\xb9\xb9\x51\x9e\xb0\x94\xfb\xf7\xfe\x7c\x7e\xaf\x76\xb2\x51\x9d\x71\xaa\x3c\xab\x12\xeb\x62\x8b\x5e\x36\xaa\xd8\x7e\xaa\x1c\xaa\x95\xa2\x6a\xe0\x1e\x4d\x9e\x46\x43\x02\xa3\xe4\x59\xac\x40\x97\xef\xf2\x18\x82\x34\xb9\x99\xc0\xf1\x01\x9e\x3c\xdd\x18\x44\xe5\x8b\x4a\xae\xbb\xd3\x1d\xd2\x04\x6e\x93\x1c\x24\xb5\x6b\x62\x3f\xbe\xbb\xff\xcf\xef\x0e\x3e\x3e\xce\xaf\x30\x85\xe0\xf1\x61\x0a\x8f\x0f\x93\x1e\xd0\xe5\x74\xc8\x4e\xef\xf7\x4f\x00\x00\x00\xff\xff\x91\x46\x82\xd5\xd4\x03\x00\x00") - -func _000004_user_messages_compatibilityUpSqlBytes() ([]byte, error) { - return bindataRead( - __000004_user_messages_compatibilityUpSql, - "000004_user_messages_compatibility.up.sql", - ) -} - -func _000004_user_messages_compatibilityUpSql() (*asset, error) { - bytes, err := _000004_user_messages_compatibilityUpSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000004_user_messages_compatibility.up.sql", size: 980, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc, 0x7a, 0xba, 0xae, 0x6d, 0xef, 0x69, 0x12, 0x6b, 0x48, 0xe3, 0xa7, 0xad, 0x21, 0x4a, 0xcf, 0x4f, 0xbc, 0x14, 0xc1, 0x19, 0x69, 0x1c, 0xc, 0xa2, 0x3d, 0xbc, 0x12, 0x32, 0x71, 0x76, 0x15}} - return a, nil -} - -var __1567112142_user_messagesDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\xb6\xe6\x02\x04\x00\x00\xff\xff\xa9\xe2\x72\x97\x1a\x00\x00\x00") - -func _1567112142_user_messagesDownSqlBytes() ([]byte, error) { - return bindataRead( - __1567112142_user_messagesDownSql, - "1567112142_user_messages.down.sql", - ) -} - -func _1567112142_user_messagesDownSql() (*asset, error) { - bytes, err := _1567112142_user_messagesDownSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "1567112142_user_messages.down.sql", size: 26, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x79, 0x8e, 0xbe, 0x63, 0x64, 0x52, 0xa3, 0x13, 0x83, 0xc7, 0x47, 0xff, 0x56, 0xa9, 0xc, 0x72, 0xb4, 0x97, 0x6, 0xc7, 0xa5, 0x68, 0xb6, 0x55, 0x6a, 0xd5, 0xb0, 0x12, 0xfb, 0x4c, 0xa5, 0x27}} - return a, nil -} - -var __1567112142_user_messagesUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\x4f\x4d\x73\x9b\x30\x14\xbc\xf3\x2b\xf6\x96\x64\xa6\xce\xf4\x9e\x13\x06\xb9\x65\x86\xc1\x2d\x96\xdb\xdc\x3c\x42\x7a\x09\x1a\x0b\x89\x41\x8f\x3a\xfc\xfb\x0e\x04\x37\x75\x8e\x6f\x77\xdf\x7e\x6c\x36\xc8\x87\xd0\x43\xf9\x09\xfd\x40\x7f\x6c\x18\xa3\x9b\xa0\x07\x52\x4c\x06\x63\xa4\xe1\xd4\x51\x8c\xea\x95\x22\x58\x35\x8e\x1e\x93\xcd\x06\xbf\x09\x26\xf8\x3b\x86\x27\x32\xe0\x80\xc8\x6a\x42\xa3\xf4\xf9\xa2\x06\x03\x1d\xba\x5e\xb1\x6d\x1c\xe1\x62\xb9\x85\xe5\xf9\xa9\x21\xad\xc6\x48\xb0\x7c\x17\xe1\x03\xcf\xee\x66\x4e\xbe\xb4\x34\x10\xe8\x4d\x53\xcf\x78\x09\x03\xb8\x25\xe8\xe0\x63\x70\x04\xed\x2c\x79\x7e\x4c\xf2\x7a\xff\x03\x32\xdd\x96\xe2\xb6\xd5\x53\x92\x64\xb5\x48\xa5\x58\xc9\x62\x87\x6a\x2f\x21\x9e\x8b\x83\x3c\x7c\x1a\x70\x9f\x00\x80\x35\xd8\x96\xfb\x2d\x8e\x55\xf1\xf3\x28\x16\x75\x75\x2c\xcb\x2f\x0b\xa9\x5b\xc5\x27\x6b\xf0\x2b\xad\xb3\xef\x69\xfd\x8f\x45\x2d\x76\xa2\x16\x55\x26\x0e\x8b\x26\xde\x5b\xf3\x80\x7d\x85\x5c\x94\x42\x0a\x64\xe9\x21\x4b\x73\xb1\x9a\x04\xcf\xe4\xf9\xc4\x53\x4f\x28\x2a\xf9\x8e\xae\x35\x3e\xa1\x4c\x6f\x0c\x29\x9e\xd7\x53\xbb\xa0\xcf\xd8\x16\xdf\x3e\x04\xb6\xa3\xc8\xaa\xeb\x6f\xd0\x6b\xc4\xb5\xef\x7f\x0e\xd7\xf0\x5b\xe3\x7e\x6c\x9c\xd5\xa7\x33\x4d\xcb\xfa\x77\xf0\xc5\xa9\xd7\x38\x77\xf9\xd8\x99\x8b\x5d\x7a\x2c\x25\xbe\x26\x0f\x4f\xc9\xdf\x00\x00\x00\xff\xff\x6e\x1c\xcd\x6f\x1f\x02\x00\x00") - -func _1567112142_user_messagesUpSqlBytes() ([]byte, error) { - return bindataRead( - __1567112142_user_messagesUpSql, - "1567112142_user_messages.up.sql", - ) -} - -func _1567112142_user_messagesUpSql() (*asset, error) { - bytes, err := _1567112142_user_messagesUpSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "1567112142_user_messages.up.sql", size: 543, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xff, 0xc0, 0x47, 0x32, 0xa9, 0xa4, 0x6, 0x63, 0x6b, 0xe7, 0x79, 0x2b, 0x80, 0x52, 0x2b, 0x6f, 0xf9, 0x9d, 0x9a, 0xc2, 0xa9, 0x7a, 0xf7, 0x4d, 0x14, 0x12, 0x21, 0x10, 0xc4, 0x30, 0x42, 0xaa}} + info := bindataFileInfo{name: "000001_init.up.db.sql", size: 2693, mode: os.FileMode(0644), modTime: time.Unix(1577718868, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0x9f, 0x6, 0x64, 0xcf, 0x97, 0xbe, 0xa8, 0xa2, 0x2f, 0xda, 0xc5, 0x9d, 0x26, 0x3, 0x65, 0x98, 0x8a, 0x7a, 0x6a, 0xc3, 0xd, 0x3f, 0x25, 0xfe, 0x4c, 0x5, 0xdb, 0x98, 0xa9, 0xf9, 0xf}} return a, nil } @@ -394,22 +226,6 @@ var _bindata = map[string]func() (*asset, error){ "000001_init.up.db.sql": _000001_initUpDbSql, - "000002_add_chats.down.db.sql": _000002_add_chatsDownDbSql, - - "000002_add_chats.up.db.sql": _000002_add_chatsUpDbSql, - - "000003_add_contacts.down.db.sql": _000003_add_contactsDownDbSql, - - "000003_add_contacts.up.db.sql": _000003_add_contactsUpDbSql, - - "000004_user_messages_compatibility.down.sql": _000004_user_messages_compatibilityDownSql, - - "000004_user_messages_compatibility.up.sql": _000004_user_messages_compatibilityUpSql, - - "1567112142_user_messages.down.sql": _1567112142_user_messagesDownSql, - - "1567112142_user_messages.up.sql": _1567112142_user_messagesUpSql, - "doc.go": docGo, } @@ -454,17 +270,9 @@ type bintree struct { } var _bintree = &bintree{nil, map[string]*bintree{ - "000001_init.down.db.sql": &bintree{_000001_initDownDbSql, map[string]*bintree{}}, - "000001_init.up.db.sql": &bintree{_000001_initUpDbSql, map[string]*bintree{}}, - "000002_add_chats.down.db.sql": &bintree{_000002_add_chatsDownDbSql, map[string]*bintree{}}, - "000002_add_chats.up.db.sql": &bintree{_000002_add_chatsUpDbSql, map[string]*bintree{}}, - "000003_add_contacts.down.db.sql": &bintree{_000003_add_contactsDownDbSql, map[string]*bintree{}}, - "000003_add_contacts.up.db.sql": &bintree{_000003_add_contactsUpDbSql, map[string]*bintree{}}, - "000004_user_messages_compatibility.down.sql": &bintree{_000004_user_messages_compatibilityDownSql, map[string]*bintree{}}, - "000004_user_messages_compatibility.up.sql": &bintree{_000004_user_messages_compatibilityUpSql, map[string]*bintree{}}, - "1567112142_user_messages.down.sql": &bintree{_1567112142_user_messagesDownSql, map[string]*bintree{}}, - "1567112142_user_messages.up.sql": &bintree{_1567112142_user_messagesUpSql, map[string]*bintree{}}, - "doc.go": &bintree{docGo, map[string]*bintree{}}, + "000001_init.down.db.sql": &bintree{_000001_initDownDbSql, map[string]*bintree{}}, + "000001_init.up.db.sql": &bintree{_000001_initUpDbSql, map[string]*bintree{}}, + "doc.go": &bintree{docGo, map[string]*bintree{}}, }} // RestoreAsset restores an asset under the given directory. diff --git a/protocol/migrations/sqlite/000001_init.down.db.sql b/protocol/migrations/sqlite/000001_init.down.db.sql index 85e187108aa..8c030eddccc 100644 --- a/protocol/migrations/sqlite/000001_init.down.db.sql +++ b/protocol/migrations/sqlite/000001_init.down.db.sql @@ -1,3 +1,3 @@ +DROP TABLE chats; DROP TABLE user_messages; -DROP TABLE membership_updates; -DROP TABLE chat_members; +DROP TABLE contacts; diff --git a/protocol/migrations/sqlite/000001_init.up.db.sql b/protocol/migrations/sqlite/000001_init.up.db.sql index 3e4c251474c..ef945e402c4 100644 --- a/protocol/migrations/sqlite/000001_init.up.db.sql +++ b/protocol/migrations/sqlite/000001_init.up.db.sql @@ -1,31 +1,91 @@ +CREATE TABLE IF NOT EXISTS chats ( + id VARCHAR PRIMARY KEY ON CONFLICT REPLACE, + name VARCHAR NOT NULL, + color VARCHAR NOT NULL DEFAULT '#a187d5', + type INT NOT NULL, + active BOOLEAN NOT NULL DEFAULT TRUE, + timestamp INT NOT NULL, + deleted_at_clock_value INT NOT NULL DEFAULT 0, + public_key BLOB, + unviewed_message_count INT NOT NULL DEFAULT 0, + last_clock_value INT NOT NULL DEFAULT 0, + last_message BLOB, + members BLOB, + membership_updates BLOB +); + +CREATE TABLE contacts ( + id TEXT PRIMARY KEY ON CONFLICT REPLACE, + address TEXT NOT NULL, + name TEXT NOT NULL, + ens_verified BOOLEAN DEFAULT FALSE, + ens_verified_at INT NOT NULL DEFAULT 0, + alias TEXT NOT NULL, + identicon TEXT NOT NULL, + photo TEXT NOT NULL, + last_updated INT NOT NULL DEFAULT 0, + system_tags BLOB, + device_info BLOB, + tribute_to_talk TEXT NOT NULL +); + +-- It's important that this table has rowid as we rely on it +-- when implementing infinite-scroll. CREATE TABLE IF NOT EXISTS user_messages ( - id BLOB UNIQUE NOT NULL, + id VARCHAR PRIMARY KEY ON CONFLICT REPLACE, + whisper_timestamp INTEGER NOT NULL, + source TEXT NOT NULL, + destination BLOB, + text VARCHAR NOT NULL, + content_type INT NOT NULL, + username VARCHAR, + timestamp INT NOT NULL, chat_id VARCHAR NOT NULL, - content_type INT, + local_chat_id VARCHAR NOT NULL, + hide BOOLEAN DEFAULT FALSE, + response_to VARCHAR, message_type INT, - text TEXT, - clock BIGINT, - timestamp BIGINT, - content_chat_id TEXT, - content_text TEXT, - public_key BLOB, - flags INT NOT NULL DEFAULT 0 + clock_value INT NOT NULL, + seen BOOLEAN NOT NULL DEFAULT FALSE, + outgoing_status VARCHAR, + parsed_text BLOB, + raw_payload BLOB, + sticker_pack INT, + sticker_hash VARCHAR, + command_id VARCHAR, + command_value VARCHAR, + command_address VARCHAR, + command_from VARCHAR, + command_contract VARCHAR, + command_transaction_hash VARCHAR, + command_signature BLOB, + command_state INT ); -CREATE INDEX chat_ids ON user_messages(chat_id); +CREATE INDEX idx_source ON user_messages(source); +CREATE INDEX idx_search_by_chat_id ON user_messages( + substr('0000000000000000000000000000000000000000000000000000000000000000' || clock_value, -64, 64) || id, chat_id, hide +); -CREATE TABLE IF NOT EXISTS membership_updates ( - id VARCHAR PRIMARY KEY NOT NULL, - data BLOB NOT NULL, - chat_id VARCHAR NOT NULL, - FOREIGN KEY (chat_id) REFERENCES chats(id) -) WITHOUT ROWID; +CREATE TABLE IF NOT EXISTS raw_messages ( + id VARCHAR PRIMARY KEY ON CONFLICT REPLACE, + local_chat_id VARCHAR NOT NULL, + last_sent INT NOT NULL, + send_count INT NOT NULL, + sent BOOLEAN DEFAULT FALSE, + resend_automatically BOOLEAN DEFAULT FALSE, + message_type INT, + recipients BLOB, + payload BLOB); -CREATE TABLE IF NOT EXISTS chat_members ( - public_key BLOB NOT NULL, - chat_id VARCHAR NOT NULL, - admin BOOLEAN NOT NULL DEFAULT FALSE, - joined BOOLEAN NOT NULL DEFAULT FALSE, - FOREIGN KEY (chat_id) REFERENCES chats(id), - UNIQUE(chat_id, public_key) -); +CREATE TABLE IF NOT EXISTS messenger_transactions_to_validate ( + message_id VARCHAR, + command_id VARCHAR NOT NULL, + transaction_hash VARCHAR PRIMARY KEY, + retry_count INT, + first_seen INT, + signature BLOB NOT NULL, + to_validate BOOLEAN DEFAULT TRUE, + public_key BLOB); + +CREATE INDEX idx_messenger_transaction_to_validate ON messenger_transactions_to_validate(to_validate); diff --git a/protocol/migrations/sqlite/000002_add_chats.down.db.sql b/protocol/migrations/sqlite/000002_add_chats.down.db.sql deleted file mode 100644 index 1f63a6211a9..00000000000 --- a/protocol/migrations/sqlite/000002_add_chats.down.db.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE membership_updates; -DROP TABLE chat_members; -DROP TABLE chats; diff --git a/protocol/migrations/sqlite/000002_add_chats.up.db.sql b/protocol/migrations/sqlite/000002_add_chats.up.db.sql deleted file mode 100644 index aac630befb6..00000000000 --- a/protocol/migrations/sqlite/000002_add_chats.up.db.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE TABLE IF NOT EXISTS chats ( -id VARCHAR PRIMARY KEY ON CONFLICT REPLACE, -name VARCHAR NOT NULL, -color VARCHAR NOT NULL DEFAULT '#a187d5', -type INT NOT NULL, -active BOOLEAN NOT NULL DEFAULT TRUE, -timestamp INT NOT NULL, -deleted_at_clock_value INT NOT NULL DEFAULT 0, -public_key BLOB, -unviewed_message_count INT NOT NULL DEFAULT 0, -last_clock_value INT NOT NULL DEFAULT 0, -last_message BLOB, -members BLOB, -membership_updates BLOB -); - - -DROP TABLE membership_updates; -DROP TABLE chat_members; diff --git a/protocol/migrations/sqlite/000003_add_contacts.down.db.sql b/protocol/migrations/sqlite/000003_add_contacts.down.db.sql deleted file mode 100644 index 0417128946f..00000000000 --- a/protocol/migrations/sqlite/000003_add_contacts.down.db.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE contacts; diff --git a/protocol/migrations/sqlite/000003_add_contacts.up.db.sql b/protocol/migrations/sqlite/000003_add_contacts.up.db.sql deleted file mode 100644 index e373aaa992c..00000000000 --- a/protocol/migrations/sqlite/000003_add_contacts.up.db.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE contacts ( - id TEXT PRIMARY KEY ON CONFLICT REPLACE, - address TEXT NOT NULL, - name TEXT NOT NULL, - ens_verified BOOLEAN DEFAULT FALSE, - ens_verified_at INT NOT NULL DEFAULT 0, - alias TEXT NOT NULL, - identicon TEXT NOT NULL, - photo TEXT NOT NULL, - last_updated INT NOT NULL DEFAULT 0, - system_tags BLOB, - device_info BLOB, - tribute_to_talk TEXT NOT NULL -); diff --git a/protocol/migrations/sqlite/000004_user_messages_compatibility.down.sql b/protocol/migrations/sqlite/000004_user_messages_compatibility.down.sql deleted file mode 100644 index 37894b51846..00000000000 --- a/protocol/migrations/sqlite/000004_user_messages_compatibility.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE user_messages_legacy; diff --git a/protocol/migrations/sqlite/000004_user_messages_compatibility.up.sql b/protocol/migrations/sqlite/000004_user_messages_compatibility.up.sql deleted file mode 100644 index f1c3359ecbc..00000000000 --- a/protocol/migrations/sqlite/000004_user_messages_compatibility.up.sql +++ /dev/null @@ -1,29 +0,0 @@ --- It's important that this table has rowid as we rely on it --- when implementing infinite-scroll. -CREATE TABLE IF NOT EXISTS user_messages_legacy ( - id VARCHAR PRIMARY KEY ON CONFLICT REPLACE, - whisper_timestamp INTEGER NOT NULL, - source TEXT NOT NULL, - destination BLOB, - text VARCHAR NOT NULL, - content_type INT NOT NULL, - username VARCHAR, - timestamp INT NOT NULL, - chat_id VARCHAR NOT NULL, - local_chat_id VARCHAR NOT NULL, - retry_count INT NOT NULL DEFAULT 0, - response_to VARCHAR, - message_type INT, - clock_value INT NOT NULL, - seen BOOLEAN NOT NULL DEFAULT FALSE, - outgoing_status VARCHAR, - parsed_text BLOB, - raw_payload BLOB, - sticker_pack INT, - sticker_hash VARCHAR -); - -CREATE INDEX idx_source ON user_messages_legacy(source); -CREATE INDEX idx_search_by_chat_id ON user_messages_legacy( - substr('0000000000000000000000000000000000000000000000000000000000000000' || clock_value, -64, 64) || id, chat_id -); diff --git a/protocol/migrations/sqlite/1567112142_user_messages.down.sql b/protocol/migrations/sqlite/1567112142_user_messages.down.sql deleted file mode 100644 index 53829377ed3..00000000000 --- a/protocol/migrations/sqlite/1567112142_user_messages.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE user_messages; diff --git a/protocol/migrations/sqlite/1567112142_user_messages.up.sql b/protocol/migrations/sqlite/1567112142_user_messages.up.sql deleted file mode 100644 index 6e978aa018b..00000000000 --- a/protocol/migrations/sqlite/1567112142_user_messages.up.sql +++ /dev/null @@ -1,18 +0,0 @@ --- Drop any previously created user_messages table. --- We don't need to stay backward compatible with it --- because it's not used anywhere except for the console client. -DROP TABLE user_messages; - -CREATE TABLE IF NOT EXISTS user_messages ( - id BLOB UNIQUE NOT NULL, - chat_id VARCHAR NOT NULL REFERENCES chats(id) ON DELETE CASCADE, - content_type INT, - message_type INT, - text TEXT, - clock BIGINT, - timestamp BIGINT, - content_chat_id TEXT, - content_text TEXT, - public_key BLOB, - flags INT NOT NULL DEFAULT 0 -); diff --git a/protocol/persistence.go b/protocol/persistence.go index 3100b3bb119..265b7f1c26e 100644 --- a/protocol/persistence.go +++ b/protocol/persistence.go @@ -7,6 +7,7 @@ import ( "encoding/gob" "github.com/pkg/errors" + "github.com/status-im/status-go/eth-node/crypto" ) var ( @@ -347,6 +348,99 @@ func (db sqlitePersistence) Contacts() ([]*Contact, error) { return response, nil } +func (db sqlitePersistence) SaveRawMessage(message *RawMessage) error { + var pubKeys [][]byte + for _, pk := range message.Recipients { + pubKeys = append(pubKeys, crypto.CompressPubkey(pk)) + } + // Encode recipients + var encodedRecipients bytes.Buffer + encoder := gob.NewEncoder(&encodedRecipients) + + if err := encoder.Encode(pubKeys); err != nil { + return err + } + + _, err := db.db.Exec(` + INSERT INTO + raw_messages + ( + id, + local_chat_id, + last_sent, + send_count, + sent, + message_type, + resend_automatically, + recipients, + payload + ) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, + message.ID, + message.LocalChatID, + message.LastSent, + message.SendCount, + message.Sent, + message.MessageType, + message.ResendAutomatically, + encodedRecipients.Bytes(), + message.Payload) + return err +} + +func (db sqlitePersistence) RawMessageByID(id string) (*RawMessage, error) { + var rawPubKeys [][]byte + var encodedRecipients []byte + message := &RawMessage{} + + err := db.db.QueryRow(` + SELECT + id, + local_chat_id, + last_sent, + send_count, + sent, + message_type, + resend_automatically, + recipients, + payload + FROM + raw_messages + WHERE + id = ?`, + id, + ).Scan( + &message.ID, + &message.LocalChatID, + &message.LastSent, + &message.SendCount, + &message.Sent, + &message.MessageType, + &message.ResendAutomatically, + &encodedRecipients, + &message.Payload, + ) + if err != nil { + return nil, err + } + + // Restore recipients + decoder := gob.NewDecoder(bytes.NewBuffer(encodedRecipients)) + err = decoder.Decode(&rawPubKeys) + if err != nil { + return nil, err + } + for _, pkBytes := range rawPubKeys { + pubkey, err := crypto.UnmarshalPubkey(pkBytes) + if err != nil { + return nil, err + } + message.Recipients = append(message.Recipients, pubkey) + } + + return message, nil +} + func (db sqlitePersistence) SaveContact(contact *Contact, tx *sql.Tx) (err error) { if tx == nil { tx, err = db.db.BeginTx(context.Background(), &sql.TxOptions{}) @@ -417,3 +511,89 @@ func (db sqlitePersistence) SaveContact(contact *Contact, tx *sql.Tx) (err error ) return } + +func (db sqlitePersistence) SaveTransactionToValidate(transaction *TransactionToValidate) error { + compressedKey := crypto.CompressPubkey(transaction.From) + + _, err := db.db.Exec(`INSERT INTO messenger_transactions_to_validate( + command_id, + message_id, + transaction_hash, + retry_count, + first_seen, + public_key, + signature, + to_validate) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, + transaction.CommandID, + transaction.MessageID, + transaction.TransactionHash, + transaction.RetryCount, + transaction.FirstSeen, + compressedKey, + transaction.Signature, + transaction.Validate, + ) + + return err +} + +func (db sqlitePersistence) UpdateTransactionToValidate(transaction *TransactionToValidate) error { + _, err := db.db.Exec(`UPDATE messenger_transactions_to_validate + SET retry_count = ?, to_validate = ? + WHERE transaction_hash = ?`, + transaction.RetryCount, + transaction.Validate, + transaction.TransactionHash, + ) + return err +} + +func (db sqlitePersistence) TransactionsToValidate() ([]*TransactionToValidate, error) { + var transactions []*TransactionToValidate + rows, err := db.db.Query(` + SELECT + command_id, + message_id, + transaction_hash, + retry_count, + first_seen, + public_key, + signature, + to_validate + FROM messenger_transactions_to_validate + WHERE to_validate = 1; + `) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var t TransactionToValidate + var pkBytes []byte + err = rows.Scan( + &t.CommandID, + &t.MessageID, + &t.TransactionHash, + &t.RetryCount, + &t.FirstSeen, + &pkBytes, + &t.Signature, + &t.Validate, + ) + if err != nil { + return nil, err + } + + publicKey, err := crypto.DecompressPubkey(pkBytes) + if err != nil { + return nil, err + } + t.From = publicKey + + transactions = append(transactions, &t) + } + + return transactions, nil +} diff --git a/protocol/persistence_legacy.go b/protocol/persistence_legacy.go index 55975a6ce77..ed4364c4a5c 100644 --- a/protocol/persistence_legacy.go +++ b/protocol/persistence_legacy.go @@ -26,15 +26,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllFields() string { timestamp, chat_id, local_chat_id, - retry_count, message_type, clock_value, seen, outgoing_status, parsed_text, - raw_payload, sticker_pack, sticker_hash, + command_id, + command_value, + command_from, + command_address, + command_contract, + command_transaction_hash, + command_state, + command_signature, response_to` } @@ -48,15 +54,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllFieldsJoin() string { m1.timestamp, m1.chat_id, m1.local_chat_id, - m1.retry_count, m1.message_type, m1.clock_value, m1.seen, m1.outgoing_status, m1.parsed_text, - m1.raw_payload, m1.sticker_pack, m1.sticker_hash, + m1.command_id, + m1.command_value, + m1.command_from, + m1.command_address, + m1.command_contract, + m1.command_transaction_hash, + m1.command_state, + m1.command_signature, m1.response_to, m2.source, m2.text, @@ -79,6 +91,7 @@ func (db sqlitePersistence) tableUserMessagesLegacyScanAllFields(row scanner, me var identicon sql.NullString sticker := &protobuf.StickerMessage{} + command := &CommandParameters{} args := []interface{}{ &message.ID, @@ -90,15 +103,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyScanAllFields(row scanner, me &message.Timestamp, &message.ChatId, &message.LocalChatID, - &message.RetryCount, &message.MessageType, &message.Clock, &message.Seen, &message.OutgoingStatus, &message.ParsedText, - &message.RawPayload, &sticker.Pack, &sticker.Hash, + &command.ID, + &command.Value, + &command.From, + &command.Address, + &command.Contract, + &command.TransactionHash, + &command.CommandState, + &command.Signature, &message.ResponseTo, "edFrom, "edText, @@ -122,6 +141,10 @@ func (db sqlitePersistence) tableUserMessagesLegacyScanAllFields(row scanner, me message.Payload = &protobuf.ChatMessage_Sticker{Sticker: sticker} } + if message.ContentType == protobuf.ChatMessage_TRANSACTION_COMMAND { + message.CommandParameters = command + } + return nil } @@ -130,6 +153,10 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllValues(message *Message) ( if sticker == nil { sticker = &protobuf.StickerMessage{} } + command := message.CommandParameters + if command == nil { + command = &CommandParameters{} + } return []interface{}{ message.ID, message.WhisperTimestamp, @@ -140,15 +167,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllValues(message *Message) ( message.Timestamp, message.ChatId, message.LocalChatID, - message.RetryCount, message.MessageType, message.Clock, message.Seen, message.OutgoingStatus, message.ParsedText, - message.RawPayload, sticker.Pack, sticker.Hash, + command.ID, + command.Value, + command.From, + command.Address, + command.Contract, + command.TransactionHash, + command.CommandState, + command.Signature, message.ResponseTo, }, nil } @@ -178,9 +211,9 @@ func (db sqlitePersistence) messageByID(tx *sql.Tx, id string) (*Message, error) SELECT %s FROM - user_messages_legacy m1 + user_messages m1 LEFT JOIN - user_messages_legacy m2 + user_messages m2 ON m1.response_to = m2.id @@ -204,6 +237,44 @@ func (db sqlitePersistence) messageByID(tx *sql.Tx, id string) (*Message, error) } } +func (db sqlitePersistence) MessageByCommandID(id string) (*Message, error) { + + var message Message + + allFields := db.tableUserMessagesLegacyAllFieldsJoin() + row := db.db.QueryRow( + fmt.Sprintf(` + SELECT + %s + FROM + user_messages m1 + LEFT JOIN + user_messages m2 + ON + m1.response_to = m2.id + + LEFT JOIN + contacts c + ON + m1.source = c.id + WHERE + m1.command_id = ? + ORDER BY m1.clock_value DESC + LIMIT 1 + `, allFields), + id, + ) + err := db.tableUserMessagesLegacyScanAllFields(row, &message) + switch err { + case sql.ErrNoRows: + return nil, errRecordNotFound + case nil: + return &message, nil + default: + return nil, err + } +} + func (db sqlitePersistence) MessageByID(id string) (*Message, error) { return db.messageByID(nil, id) } @@ -220,7 +291,7 @@ func (db sqlitePersistence) MessagesExist(ids []string) (map[string]bool, error) } inVector := strings.Repeat("?, ", len(ids)-1) + "?" - query := fmt.Sprintf(`SELECT id FROM user_messages_legacy WHERE id IN (%s)`, inVector) + query := fmt.Sprintf(`SELECT id FROM user_messages WHERE id IN (%s)`, inVector) rows, err := db.db.Query(query, idsArgs...) if err != nil { return nil, err @@ -261,9 +332,9 @@ func (db sqlitePersistence) MessageByChatID(chatID string, currCursor string, li %s, substr('0000000000000000000000000000000000000000000000000000000000000000' || m1.clock_value, -64, 64) || m1.id as cursor FROM - user_messages_legacy m1 + user_messages m1 LEFT JOIN - user_messages_legacy m2 + user_messages m2 ON m1.response_to = m2.id @@ -273,7 +344,7 @@ func (db sqlitePersistence) MessageByChatID(chatID string, currCursor string, li m1.source = c.id WHERE - m1.local_chat_id = ? %s + m1.hide != 1 AND m1.local_chat_id = ? %s ORDER BY cursor DESC LIMIT ? `, allFields, cursorWhere), @@ -324,7 +395,7 @@ func (db sqlitePersistence) SaveMessagesLegacy(messages []*Message) (err error) allFields := db.tableUserMessagesLegacyAllFields() valuesVector := strings.Repeat("?, ", db.tableUserMessagesLegacyAllFieldsCount()-1) + "?" - query := fmt.Sprintf(`INSERT INTO user_messages_legacy(%s) VALUES (%s)`, allFields, valuesVector) + query := fmt.Sprintf(`INSERT INTO user_messages(%s) VALUES (%s)`, allFields, valuesVector) stmt, err := tx.Prepare(query) if err != nil { return @@ -346,12 +417,17 @@ func (db sqlitePersistence) SaveMessagesLegacy(messages []*Message) (err error) } func (db sqlitePersistence) DeleteMessage(id string) error { - _, err := db.db.Exec(`DELETE FROM user_messages_legacy WHERE id = ?`, id) + _, err := db.db.Exec(`DELETE FROM user_messages WHERE id = ?`, id) + return err +} + +func (db sqlitePersistence) HideMessage(id string) error { + _, err := db.db.Exec(`UPDATE user_messages SET hide = 1 WHERE id = ?`, id) return err } func (db sqlitePersistence) DeleteMessagesByChatID(id string) error { - _, err := db.db.Exec(`DELETE FROM user_messages_legacy WHERE local_chat_id = ?`, id) + _, err := db.db.Exec(`DELETE FROM user_messages WHERE local_chat_id = ?`, id) return err } @@ -377,7 +453,7 @@ func (db sqlitePersistence) MarkMessagesSeen(chatID string, ids []string) error inVector := strings.Repeat("?, ", len(ids)-1) + "?" _, err = tx.Exec( fmt.Sprintf(` - UPDATE user_messages_legacy + UPDATE user_messages SET seen = 1 WHERE id IN (%s) `, inVector), @@ -391,7 +467,7 @@ func (db sqlitePersistence) MarkMessagesSeen(chatID string, ids []string) error `UPDATE chats SET unviewed_message_count = (SELECT COUNT(1) - FROM user_messages_legacy + FROM user_messages WHERE local_chat_id = ? AND seen = 0) WHERE id = ?`, chatID, chatID) return err @@ -399,7 +475,7 @@ func (db sqlitePersistence) MarkMessagesSeen(chatID string, ids []string) error func (db sqlitePersistence) UpdateMessageOutgoingStatus(id string, newOutgoingStatus string) error { _, err := db.db.Exec(` - UPDATE user_messages_legacy + UPDATE user_messages SET outgoing_status = ? WHERE id = ? `, newOutgoingStatus, id) @@ -425,7 +501,7 @@ func (db sqlitePersistence) BlockContact(contact *Contact) ([]*Chat, error) { // Delete messages _, err = tx.Exec( `DELETE - FROM user_messages_legacy + FROM user_messages WHERE source = ?`, contact.ID, ) @@ -449,7 +525,7 @@ func (db sqlitePersistence) BlockContact(contact *Contact) ([]*Chat, error) { _, err = tx.Exec(` UPDATE chats SET - unviewed_message_count = (SELECT COUNT(1) FROM user_messages_legacy WHERE seen = 0 AND local_chat_id = chats.id)`) + unviewed_message_count = (SELECT COUNT(1) FROM user_messages WHERE seen = 0 AND local_chat_id = chats.id)`) if err != nil { return nil, err } @@ -461,7 +537,7 @@ func (db sqlitePersistence) BlockContact(contact *Contact) ([]*Chat, error) { } for _, c := range chats { var lastMessageID string - row := tx.QueryRow(`SELECT id FROM user_messages_legacy WHERE local_chat_id = ? ORDER BY clock_value DESC LIMIT 1`, c.ID) + row := tx.QueryRow(`SELECT id FROM user_messages WHERE local_chat_id = ? ORDER BY clock_value DESC LIMIT 1`, c.ID) switch err := row.Scan(&lastMessageID); err { case nil: diff --git a/protocol/protobuf/application_metadata_message.pb.go b/protocol/protobuf/application_metadata_message.pb.go index 7b439229ffd..bd650fdd6b5 100644 --- a/protocol/protobuf/application_metadata_message.pb.go +++ b/protocol/protobuf/application_metadata_message.pb.go @@ -24,30 +24,57 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type ApplicationMetadataMessage_Type int32 const ( - ApplicationMetadataMessage_UNKNOWN ApplicationMetadataMessage_Type = 0 - ApplicationMetadataMessage_CHAT_MESSAGE ApplicationMetadataMessage_Type = 1 - ApplicationMetadataMessage_CONTACT_REQUEST ApplicationMetadataMessage_Type = 2 - ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE ApplicationMetadataMessage_Type = 3 - ApplicationMetadataMessage_PAIR_INSTALLATION ApplicationMetadataMessage_Type = 4 - ApplicationMetadataMessage_SYNC_INSTALLATION ApplicationMetadataMessage_Type = 5 + ApplicationMetadataMessage_UNKNOWN ApplicationMetadataMessage_Type = 0 + ApplicationMetadataMessage_CHAT_MESSAGE ApplicationMetadataMessage_Type = 1 + ApplicationMetadataMessage_CONTACT_UPDATE ApplicationMetadataMessage_Type = 2 + ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE ApplicationMetadataMessage_Type = 3 + ApplicationMetadataMessage_PAIR_INSTALLATION ApplicationMetadataMessage_Type = 4 + ApplicationMetadataMessage_SYNC_INSTALLATION ApplicationMetadataMessage_Type = 5 + ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 6 + ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 7 + ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 8 + ApplicationMetadataMessage_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 9 + ApplicationMetadataMessage_SEND_TRANSACTION ApplicationMetadataMessage_Type = 10 + ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 11 + ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT ApplicationMetadataMessage_Type = 12 + ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT ApplicationMetadataMessage_Type = 13 + ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT ApplicationMetadataMessage_Type = 14 ) var ApplicationMetadataMessage_Type_name = map[int32]string{ - 0: "UNKNOWN", - 1: "CHAT_MESSAGE", - 2: "CONTACT_REQUEST", - 3: "MEMBERSHIP_UPDATE_MESSAGE", - 4: "PAIR_INSTALLATION", - 5: "SYNC_INSTALLATION", + 0: "UNKNOWN", + 1: "CHAT_MESSAGE", + 2: "CONTACT_UPDATE", + 3: "MEMBERSHIP_UPDATE_MESSAGE", + 4: "PAIR_INSTALLATION", + 5: "SYNC_INSTALLATION", + 6: "REQUEST_ADDRESS_FOR_TRANSACTION", + 7: "ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION", + 8: "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION", + 9: "REQUEST_TRANSACTION", + 10: "SEND_TRANSACTION", + 11: "DECLINE_REQUEST_TRANSACTION", + 12: "SYNC_INSTALLATION_CONTACT", + 13: "SYNC_INSTALLATION_ACCOUNT", + 14: "SYNC_INSTALLATION_PUBLIC_CHAT", } var ApplicationMetadataMessage_Type_value = map[string]int32{ - "UNKNOWN": 0, - "CHAT_MESSAGE": 1, - "CONTACT_REQUEST": 2, - "MEMBERSHIP_UPDATE_MESSAGE": 3, - "PAIR_INSTALLATION": 4, - "SYNC_INSTALLATION": 5, + "UNKNOWN": 0, + "CHAT_MESSAGE": 1, + "CONTACT_UPDATE": 2, + "MEMBERSHIP_UPDATE_MESSAGE": 3, + "PAIR_INSTALLATION": 4, + "SYNC_INSTALLATION": 5, + "REQUEST_ADDRESS_FOR_TRANSACTION": 6, + "ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION": 7, + "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION": 8, + "REQUEST_TRANSACTION": 9, + "SEND_TRANSACTION": 10, + "DECLINE_REQUEST_TRANSACTION": 11, + "SYNC_INSTALLATION_CONTACT": 12, + "SYNC_INSTALLATION_ACCOUNT": 13, + "SYNC_INSTALLATION_PUBLIC_CHAT": 14, } func (x ApplicationMetadataMessage_Type) String() string { @@ -124,22 +151,29 @@ func init() { func init() { proto.RegisterFile("application_metadata_message.proto", fileDescriptor_ad09a6406fcf24c7) } var fileDescriptor_ad09a6406fcf24c7 = []byte{ - // 269 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x8e, 0x41, 0x4b, 0xc3, 0x30, - 0x18, 0x86, 0x6d, 0x57, 0x9d, 0x7e, 0x0e, 0xad, 0x11, 0xa1, 0x8a, 0xc2, 0xe8, 0x69, 0x5e, 0x7a, - 0xd0, 0xb3, 0x87, 0x58, 0x83, 0x2b, 0xae, 0x69, 0x4d, 0x52, 0xc4, 0x53, 0xc8, 0x5c, 0x1c, 0x85, - 0x6d, 0x0d, 0x6b, 0x76, 0xe8, 0x2f, 0xf0, 0x57, 0xf8, 0x5f, 0x65, 0xd5, 0x39, 0x3c, 0x78, 0x0a, - 0xef, 0x93, 0xf7, 0xe1, 0xfd, 0x20, 0x54, 0xc6, 0xcc, 0xca, 0x37, 0x65, 0xcb, 0x6a, 0x21, 0xe7, - 0xda, 0xaa, 0x89, 0xb2, 0x4a, 0xce, 0x75, 0x5d, 0xab, 0xa9, 0x8e, 0xcc, 0xb2, 0xb2, 0x15, 0xda, - 0x6f, 0x9f, 0xf1, 0xea, 0x3d, 0xfc, 0x74, 0xe1, 0x02, 0x6f, 0x85, 0xf4, 0xa7, 0x9f, 0x7e, 0xd7, - 0xd1, 0x25, 0x1c, 0xd4, 0xe5, 0x74, 0xa1, 0xec, 0x6a, 0xa9, 0x03, 0xa7, 0xef, 0x0c, 0x7a, 0x6c, - 0x0b, 0x50, 0x00, 0x5d, 0xa3, 0x9a, 0x59, 0xa5, 0x26, 0x81, 0xdb, 0xfe, 0x6d, 0x22, 0xba, 0x03, - 0xcf, 0x36, 0x46, 0x07, 0x9d, 0xbe, 0x33, 0x38, 0xba, 0xb9, 0x8e, 0x36, 0x7b, 0xd1, 0xff, 0x5b, - 0x91, 0x68, 0x8c, 0x66, 0xad, 0x16, 0x7e, 0x38, 0xe0, 0xad, 0x23, 0x3a, 0x84, 0x6e, 0x41, 0x9f, - 0x68, 0xf6, 0x42, 0xfd, 0x1d, 0xe4, 0x43, 0x2f, 0x1e, 0x62, 0x21, 0x53, 0xc2, 0x39, 0x7e, 0x24, - 0xbe, 0x83, 0x4e, 0xe1, 0x38, 0xce, 0xa8, 0xc0, 0xb1, 0x90, 0x8c, 0x3c, 0x17, 0x84, 0x0b, 0xdf, - 0x45, 0x57, 0x70, 0x9e, 0x92, 0xf4, 0x9e, 0x30, 0x3e, 0x4c, 0x72, 0x59, 0xe4, 0x0f, 0x58, 0x90, - 0x5f, 0xa7, 0x83, 0xce, 0xe0, 0x24, 0xc7, 0x09, 0x93, 0x09, 0xe5, 0x02, 0x8f, 0x46, 0x58, 0x24, - 0x19, 0xf5, 0xbd, 0x35, 0xe6, 0xaf, 0x34, 0xfe, 0x8b, 0x77, 0xc7, 0x7b, 0xed, 0xe5, 0xb7, 0x5f, - 0x01, 0x00, 0x00, 0xff, 0xff, 0xb9, 0xdb, 0x0d, 0x56, 0x56, 0x01, 0x00, 0x00, + // 377 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xcf, 0x8e, 0xd3, 0x30, + 0x10, 0xc6, 0xc9, 0x36, 0x6c, 0x77, 0x67, 0x4b, 0x65, 0x06, 0x10, 0xe1, 0xcf, 0x6a, 0x97, 0x22, + 0xc1, 0x02, 0x52, 0x0e, 0x70, 0xe6, 0xe0, 0x75, 0x0c, 0x1b, 0x91, 0x38, 0xc1, 0x76, 0x84, 0x38, + 0x59, 0x2e, 0x0d, 0x55, 0xa5, 0xb6, 0x89, 0xda, 0xf4, 0xd0, 0x07, 0xe3, 0x29, 0x78, 0x29, 0x94, + 0xd0, 0xd2, 0x96, 0x82, 0x7a, 0xb2, 0xe6, 0xfb, 0x7e, 0x9f, 0x47, 0x33, 0x03, 0x3d, 0x5b, 0x96, + 0xe3, 0xd1, 0x37, 0x5b, 0x8d, 0x8a, 0xa9, 0x99, 0xe4, 0x95, 0x1d, 0xd8, 0xca, 0x9a, 0x49, 0x3e, + 0x9f, 0xdb, 0x61, 0xee, 0x97, 0xb3, 0xa2, 0x2a, 0xf0, 0xa4, 0x79, 0xfa, 0x8b, 0xef, 0xbd, 0x9f, + 0x2e, 0x3c, 0xa6, 0x9b, 0x40, 0xbc, 0xe2, 0xe3, 0xdf, 0x38, 0x3e, 0x85, 0xd3, 0xf9, 0x68, 0x38, + 0xb5, 0xd5, 0x62, 0x96, 0x7b, 0xce, 0xa5, 0x73, 0xd5, 0x91, 0x1b, 0x01, 0x3d, 0x68, 0x97, 0x76, + 0x39, 0x2e, 0xec, 0xc0, 0x3b, 0x6a, 0xbc, 0x75, 0x89, 0xef, 0xc1, 0xad, 0x96, 0x65, 0xee, 0xb5, + 0x2e, 0x9d, 0xab, 0xee, 0xdb, 0x57, 0xfe, 0xba, 0x9f, 0xff, 0xff, 0x5e, 0xbe, 0x5e, 0x96, 0xb9, + 0x6c, 0x62, 0xbd, 0x1f, 0x2d, 0x70, 0xeb, 0x12, 0xcf, 0xa0, 0x9d, 0x89, 0x4f, 0x22, 0xf9, 0x22, + 0xc8, 0x2d, 0x24, 0xd0, 0x61, 0x37, 0x54, 0x9b, 0x98, 0x2b, 0x45, 0x3f, 0x72, 0xe2, 0x20, 0x42, + 0x97, 0x25, 0x42, 0x53, 0xa6, 0x4d, 0x96, 0x06, 0x54, 0x73, 0x72, 0x84, 0xe7, 0xf0, 0x28, 0xe6, + 0xf1, 0x35, 0x97, 0xea, 0x26, 0x4c, 0x57, 0xf2, 0x9f, 0x48, 0x0b, 0x1f, 0xc0, 0xdd, 0x94, 0x86, + 0xd2, 0x84, 0x42, 0x69, 0x1a, 0x45, 0x54, 0x87, 0x89, 0x20, 0x6e, 0x2d, 0xab, 0xaf, 0x82, 0xed, + 0xca, 0xb7, 0xf1, 0x39, 0x5c, 0x48, 0xfe, 0x39, 0xe3, 0x4a, 0x1b, 0x1a, 0x04, 0x92, 0x2b, 0x65, + 0x3e, 0x24, 0xd2, 0x68, 0x49, 0x85, 0xa2, 0xac, 0x81, 0x8e, 0xf1, 0x35, 0xbc, 0xa0, 0x8c, 0xf1, + 0x54, 0x9b, 0x43, 0x6c, 0x1b, 0xdf, 0xc0, 0xcb, 0x80, 0xb3, 0x28, 0x14, 0xfc, 0x20, 0x7c, 0x82, + 0x0f, 0xe1, 0xde, 0x1a, 0xda, 0x36, 0x4e, 0xf1, 0x3e, 0x10, 0xc5, 0x45, 0xb0, 0xa3, 0x02, 0x5e, + 0xc0, 0x93, 0xbf, 0xff, 0xde, 0x06, 0xce, 0xea, 0xd5, 0xec, 0x0d, 0x69, 0x56, 0x0b, 0x24, 0x9d, + 0x7f, 0xdb, 0x94, 0xb1, 0x24, 0x13, 0x9a, 0xdc, 0xc1, 0x67, 0x70, 0xbe, 0x6f, 0xa7, 0xd9, 0x75, + 0x14, 0x32, 0x53, 0xdf, 0x85, 0x74, 0xfb, 0xc7, 0xcd, 0x9d, 0xdf, 0xfd, 0x0a, 0x00, 0x00, 0xff, + 0xff, 0xb7, 0x6c, 0xd6, 0xba, 0x84, 0x02, 0x00, 0x00, } diff --git a/protocol/protobuf/application_metadata_message.proto b/protocol/protobuf/application_metadata_message.proto index 9d99259ca96..dae1d78be47 100644 --- a/protocol/protobuf/application_metadata_message.proto +++ b/protocol/protobuf/application_metadata_message.proto @@ -14,9 +14,18 @@ message ApplicationMetadataMessage { enum Type { UNKNOWN = 0; CHAT_MESSAGE = 1; - CONTACT_REQUEST = 2; + CONTACT_UPDATE = 2; MEMBERSHIP_UPDATE_MESSAGE = 3; PAIR_INSTALLATION = 4; SYNC_INSTALLATION = 5; + REQUEST_ADDRESS_FOR_TRANSACTION = 6; + ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION = 7; + DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION = 8; + REQUEST_TRANSACTION = 9; + SEND_TRANSACTION = 10; + DECLINE_REQUEST_TRANSACTION = 11; + SYNC_INSTALLATION_CONTACT = 12; + SYNC_INSTALLATION_ACCOUNT = 13; + SYNC_INSTALLATION_PUBLIC_CHAT = 14; } } diff --git a/protocol/protobuf/chat_message.pb.go b/protocol/protobuf/chat_message.pb.go index 9963ed524c3..61db6ead545 100644 --- a/protocol/protobuf/chat_message.pb.go +++ b/protocol/protobuf/chat_message.pb.go @@ -64,8 +64,7 @@ const ( ChatMessage_STICKER ChatMessage_ContentType = 2 ChatMessage_STATUS ChatMessage_ContentType = 3 ChatMessage_EMOJI ChatMessage_ContentType = 4 - ChatMessage_COMMAND ChatMessage_ContentType = 5 - ChatMessage_COMMAND_REQUEST ChatMessage_ContentType = 6 + ChatMessage_TRANSACTION_COMMAND ChatMessage_ContentType = 5 ) var ChatMessage_ContentType_name = map[int32]string{ @@ -74,8 +73,7 @@ var ChatMessage_ContentType_name = map[int32]string{ 2: "STICKER", 3: "STATUS", 4: "EMOJI", - 5: "COMMAND", - 6: "COMMAND_REQUEST", + 5: "TRANSACTION_COMMAND", } var ChatMessage_ContentType_value = map[string]int32{ @@ -84,8 +82,7 @@ var ChatMessage_ContentType_value = map[string]int32{ "STICKER": 2, "STATUS": 3, "EMOJI": 4, - "COMMAND": 5, - "COMMAND_REQUEST": 6, + "TRANSACTION_COMMAND": 5, } func (x ChatMessage_ContentType) String() string { @@ -294,34 +291,34 @@ func init() { func init() { proto.RegisterFile("chat_message.proto", fileDescriptor_263952f55fd35689) } var fileDescriptor_263952f55fd35689 = []byte{ - // 462 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0xcf, 0x6f, 0xd3, 0x30, - 0x14, 0x5e, 0xda, 0xb4, 0x69, 0x5f, 0x46, 0x31, 0x66, 0x12, 0x46, 0x9a, 0x44, 0xe9, 0xa9, 0xa7, - 0x1e, 0x06, 0x07, 0xae, 0x5d, 0x66, 0x8d, 0xb0, 0xc5, 0x29, 0x8e, 0x0b, 0xec, 0x64, 0x79, 0xa9, - 0xa1, 0x55, 0x97, 0x1f, 0x6a, 0x8c, 0x44, 0x0f, 0xf0, 0x67, 0x73, 0x46, 0x71, 0x5a, 0xda, 0x5d, - 0x76, 0xf2, 0xfb, 0xbe, 0xf7, 0xbd, 0xef, 0xe5, 0x7d, 0x01, 0x9c, 0x2e, 0x95, 0x91, 0x99, 0xae, - 0x2a, 0xf5, 0x43, 0x4f, 0xca, 0x4d, 0x61, 0x0a, 0xdc, 0xb3, 0xcf, 0xfd, 0xcf, 0xef, 0xa3, 0x0f, - 0x30, 0x48, 0xcc, 0x2a, 0x5d, 0xeb, 0x4d, 0xd4, 0x28, 0x30, 0x06, 0x77, 0xa9, 0xaa, 0x25, 0x71, - 0x86, 0xce, 0xb8, 0xcf, 0x6d, 0x5d, 0x73, 0xa5, 0x4a, 0xd7, 0xa4, 0x35, 0x74, 0xc6, 0x1d, 0x6e, - 0xeb, 0xd1, 0x5f, 0x17, 0xfc, 0x60, 0xa9, 0xcc, 0x7e, 0xee, 0x0c, 0x3a, 0xe9, 0x43, 0x91, 0xae, - 0xed, 0xa0, 0xcb, 0x1b, 0x80, 0xcf, 0xa1, 0x6f, 0x56, 0x99, 0xae, 0x8c, 0xca, 0x4a, 0x3b, 0xee, - 0xf2, 0x03, 0x51, 0xfb, 0x1a, 0xfd, 0xcb, 0x90, 0x76, 0xb3, 0xab, 0xae, 0xf1, 0x1b, 0xf0, 0x37, - 0xba, 0x2a, 0x8b, 0xbc, 0xd2, 0xd2, 0x14, 0xc4, 0xb5, 0x2d, 0xd8, 0x53, 0xa2, 0xc0, 0xaf, 0xa1, - 0xa7, 0xf3, 0x4a, 0xe6, 0x2a, 0xd3, 0xa4, 0x63, 0xbb, 0x9e, 0xce, 0x2b, 0xa6, 0x32, 0x8d, 0x5f, - 0x81, 0x67, 0xaf, 0x5d, 0x2d, 0x48, 0xd7, 0x76, 0xba, 0x35, 0x0c, 0x17, 0xf8, 0x0a, 0x4e, 0x77, - 0x09, 0x48, 0xb3, 0x2d, 0x35, 0xf1, 0x86, 0xce, 0x78, 0x70, 0xf1, 0x76, 0xb2, 0xcf, 0x61, 0x72, - 0x74, 0xc9, 0x64, 0xf7, 0x8a, 0x6d, 0xa9, 0xb9, 0x9f, 0x1d, 0x40, 0xed, 0x92, 0x16, 0xb9, 0xd1, - 0xb9, 0x69, 0x5c, 0x7a, 0x4f, 0xb9, 0x04, 0x8d, 0xb2, 0x71, 0x49, 0x0f, 0x00, 0xbf, 0x07, 0xaf, - 0x6a, 0x22, 0x27, 0xfd, 0xa1, 0x33, 0xf6, 0x2f, 0xc8, 0xc1, 0xe0, 0xf1, 0xbf, 0xf8, 0x78, 0xc2, - 0xf7, 0xd2, 0xd1, 0x1f, 0xf0, 0x8f, 0xbe, 0x0b, 0x13, 0x38, 0x9b, 0xb3, 0x1b, 0x16, 0x7f, 0x65, - 0x32, 0xa2, 0x49, 0x32, 0xbd, 0xa6, 0x52, 0xdc, 0xcd, 0x28, 0x3a, 0xc1, 0x03, 0x80, 0x98, 0x51, - 0x29, 0x62, 0x19, 0x33, 0x8a, 0x1c, 0x8c, 0xe0, 0x74, 0x36, 0xbf, 0xbc, 0x0d, 0x03, 0x79, 0xcd, - 0xe3, 0xf9, 0x0c, 0xb5, 0xf0, 0x0b, 0x78, 0x36, 0xe3, 0xe1, 0x97, 0xa9, 0xa0, 0x3b, 0xaa, 0x8d, - 0x87, 0x70, 0x9e, 0xdc, 0x25, 0x82, 0x46, 0xff, 0xdd, 0x1e, 0x2b, 0xdc, 0xd1, 0x6f, 0xf0, 0x8f, - 0x2e, 0x3a, 0xde, 0x1f, 0xc4, 0x4c, 0x50, 0x26, 0x8e, 0xf6, 0x0b, 0xfa, 0x4d, 0xc8, 0xd9, 0xed, - 0x34, 0x64, 0xc8, 0xc1, 0x3e, 0x78, 0x89, 0x08, 0x83, 0x1b, 0xca, 0x51, 0x0b, 0x03, 0x74, 0x13, - 0x31, 0x15, 0xf3, 0x04, 0xb5, 0x71, 0x1f, 0x3a, 0x34, 0x8a, 0x3f, 0x85, 0xc8, 0xad, 0x35, 0x41, - 0x1c, 0x45, 0x53, 0x76, 0x85, 0x3a, 0xf8, 0x25, 0x3c, 0xdf, 0x01, 0xc9, 0xe9, 0xe7, 0x39, 0x4d, - 0x04, 0xea, 0x5e, 0xf6, 0xc1, 0x2b, 0xd5, 0xf6, 0xa1, 0x50, 0x8b, 0xfb, 0xae, 0x4d, 0xeb, 0xdd, - 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3a, 0x19, 0x70, 0x9c, 0xd9, 0x02, 0x00, 0x00, + // 460 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0x4d, 0x6f, 0xd3, 0x4c, + 0x10, 0xc7, 0xeb, 0xc4, 0x89, 0x93, 0x71, 0x9f, 0xc8, 0xcf, 0x52, 0xa9, 0x8b, 0x54, 0x89, 0x90, + 0x53, 0x4e, 0x39, 0x14, 0x0e, 0x5c, 0x5d, 0x77, 0x55, 0x4c, 0xeb, 0xb5, 0xb5, 0xde, 0x00, 0x3d, + 0xad, 0xb6, 0xce, 0x42, 0xa2, 0xd4, 0x2f, 0x8a, 0x17, 0x89, 0x5c, 0xf8, 0xc6, 0x7c, 0x07, 0xe4, + 0x75, 0x42, 0xdc, 0x0b, 0xa7, 0x9d, 0x97, 0xff, 0xfc, 0xc6, 0xf3, 0x37, 0xa0, 0x6c, 0x2d, 0xb5, + 0xc8, 0x55, 0x5d, 0xcb, 0xef, 0x6a, 0x51, 0xed, 0x4a, 0x5d, 0xa2, 0x91, 0x79, 0x9e, 0x7e, 0x7c, + 0x9b, 0x7d, 0x80, 0x49, 0xaa, 0x37, 0xd9, 0x56, 0xed, 0xa2, 0x56, 0x81, 0x10, 0xd8, 0x6b, 0x59, + 0xaf, 0xb1, 0x35, 0xb5, 0xe6, 0x63, 0x66, 0xe2, 0xa6, 0x56, 0xc9, 0x6c, 0x8b, 0x7b, 0x53, 0x6b, + 0x3e, 0x60, 0x26, 0x9e, 0xfd, 0xb6, 0xc1, 0x0d, 0xd6, 0x52, 0x1f, 0xe7, 0x2e, 0x60, 0x90, 0x3d, + 0x97, 0xd9, 0xd6, 0x0c, 0xda, 0xac, 0x4d, 0xd0, 0x15, 0x8c, 0xf5, 0x26, 0x57, 0xb5, 0x96, 0x79, + 0x65, 0xc6, 0x6d, 0x76, 0x2a, 0x34, 0x5c, 0xad, 0x7e, 0x6a, 0xdc, 0x6f, 0x77, 0x35, 0x31, 0x7a, + 0x03, 0xee, 0x4e, 0xd5, 0x55, 0x59, 0xd4, 0x4a, 0xe8, 0x12, 0xdb, 0xa6, 0x05, 0xc7, 0x12, 0x2f, + 0xd1, 0x6b, 0x18, 0xa9, 0xa2, 0x16, 0x85, 0xcc, 0x15, 0x1e, 0x98, 0xae, 0xa3, 0x8a, 0x9a, 0xca, + 0x5c, 0xa1, 0x4b, 0x70, 0xcc, 0xb5, 0x9b, 0x15, 0x1e, 0x9a, 0xce, 0xb0, 0x49, 0xc3, 0x15, 0xba, + 0x85, 0xf3, 0x83, 0x03, 0x42, 0xef, 0x2b, 0x85, 0x9d, 0xa9, 0x35, 0x9f, 0x5c, 0xbf, 0x5d, 0x1c, + 0x7d, 0x58, 0x74, 0x2e, 0x59, 0x1c, 0x5e, 0xbe, 0xaf, 0x14, 0x73, 0xf3, 0x53, 0xd2, 0x50, 0xb2, + 0xb2, 0xd0, 0xaa, 0xd0, 0x2d, 0x65, 0xf4, 0x2f, 0x4a, 0xd0, 0x2a, 0x5b, 0x4a, 0x76, 0x4a, 0xd0, + 0x7b, 0x70, 0xea, 0xd6, 0x72, 0x3c, 0x9e, 0x5a, 0x73, 0xf7, 0x1a, 0x9f, 0x00, 0x2f, 0xff, 0xc5, + 0xc7, 0x33, 0x76, 0x94, 0xce, 0x7e, 0x81, 0xdb, 0xf9, 0x2e, 0x84, 0xe1, 0x62, 0x49, 0xef, 0x69, + 0xfc, 0x85, 0x8a, 0x88, 0xa4, 0xa9, 0x7f, 0x47, 0x04, 0x7f, 0x4c, 0x88, 0x77, 0x86, 0x26, 0x00, + 0x31, 0x25, 0x82, 0xc7, 0x22, 0xa6, 0xc4, 0xb3, 0x90, 0x07, 0xe7, 0xc9, 0xf2, 0xe6, 0x21, 0x0c, + 0xc4, 0x1d, 0x8b, 0x97, 0x89, 0xd7, 0x43, 0xff, 0xc3, 0x7f, 0x09, 0x0b, 0x3f, 0xfb, 0x9c, 0x1c, + 0x4a, 0x7d, 0x34, 0x85, 0xab, 0xf4, 0x31, 0xe5, 0x24, 0xfa, 0x4b, 0x7b, 0xa9, 0xb0, 0x67, 0x1a, + 0xdc, 0xce, 0x45, 0xdd, 0xfd, 0x41, 0x4c, 0x39, 0xa1, 0xbc, 0xb3, 0x9f, 0x93, 0xaf, 0x5c, 0x24, + 0x0f, 0x7e, 0x48, 0x3d, 0x0b, 0xb9, 0xe0, 0xa4, 0x3c, 0x0c, 0xee, 0x09, 0xf3, 0x7a, 0x08, 0x60, + 0x98, 0x72, 0x9f, 0x2f, 0x53, 0xaf, 0x8f, 0xc6, 0x30, 0x20, 0x51, 0xfc, 0x29, 0xf4, 0x6c, 0x74, + 0x09, 0xaf, 0x38, 0xf3, 0x69, 0xea, 0x07, 0x3c, 0x8c, 0x1b, 0x62, 0x14, 0xf9, 0xf4, 0xd6, 0x1b, + 0xdc, 0x8c, 0xc1, 0xa9, 0xe4, 0xfe, 0xb9, 0x94, 0xab, 0xa7, 0xa1, 0x31, 0xe9, 0xdd, 0x9f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x54, 0x6d, 0xd5, 0x10, 0xd0, 0x02, 0x00, 0x00, } diff --git a/protocol/protobuf/chat_message.proto b/protocol/protobuf/chat_message.proto index e7d2309da67..8dbb5f6e1e9 100644 --- a/protocol/protobuf/chat_message.proto +++ b/protocol/protobuf/chat_message.proto @@ -48,7 +48,6 @@ message ChatMessage { STICKER = 2; STATUS = 3; EMOJI = 4; - COMMAND = 5; - COMMAND_REQUEST = 6; + TRANSACTION_COMMAND = 5; } } diff --git a/protocol/protobuf/command.pb.go b/protocol/protobuf/command.pb.go new file mode 100644 index 00000000000..c2a95993847 --- /dev/null +++ b/protocol/protobuf/command.pb.go @@ -0,0 +1,383 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: command.proto + +package protobuf + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type RequestAddressForTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RequestAddressForTransaction) Reset() { *m = RequestAddressForTransaction{} } +func (m *RequestAddressForTransaction) String() string { return proto.CompactTextString(m) } +func (*RequestAddressForTransaction) ProtoMessage() {} +func (*RequestAddressForTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{0} +} + +func (m *RequestAddressForTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RequestAddressForTransaction.Unmarshal(m, b) +} +func (m *RequestAddressForTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RequestAddressForTransaction.Marshal(b, m, deterministic) +} +func (m *RequestAddressForTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_RequestAddressForTransaction.Merge(m, src) +} +func (m *RequestAddressForTransaction) XXX_Size() int { + return xxx_messageInfo_RequestAddressForTransaction.Size(m) +} +func (m *RequestAddressForTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_RequestAddressForTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_RequestAddressForTransaction proto.InternalMessageInfo + +func (m *RequestAddressForTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *RequestAddressForTransaction) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +func (m *RequestAddressForTransaction) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + +type AcceptRequestAddressForTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *AcceptRequestAddressForTransaction) Reset() { *m = AcceptRequestAddressForTransaction{} } +func (m *AcceptRequestAddressForTransaction) String() string { return proto.CompactTextString(m) } +func (*AcceptRequestAddressForTransaction) ProtoMessage() {} +func (*AcceptRequestAddressForTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{1} +} + +func (m *AcceptRequestAddressForTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_AcceptRequestAddressForTransaction.Unmarshal(m, b) +} +func (m *AcceptRequestAddressForTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_AcceptRequestAddressForTransaction.Marshal(b, m, deterministic) +} +func (m *AcceptRequestAddressForTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_AcceptRequestAddressForTransaction.Merge(m, src) +} +func (m *AcceptRequestAddressForTransaction) XXX_Size() int { + return xxx_messageInfo_AcceptRequestAddressForTransaction.Size(m) +} +func (m *AcceptRequestAddressForTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_AcceptRequestAddressForTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_AcceptRequestAddressForTransaction proto.InternalMessageInfo + +func (m *AcceptRequestAddressForTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *AcceptRequestAddressForTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *AcceptRequestAddressForTransaction) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +type DeclineRequestAddressForTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeclineRequestAddressForTransaction) Reset() { *m = DeclineRequestAddressForTransaction{} } +func (m *DeclineRequestAddressForTransaction) String() string { return proto.CompactTextString(m) } +func (*DeclineRequestAddressForTransaction) ProtoMessage() {} +func (*DeclineRequestAddressForTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{2} +} + +func (m *DeclineRequestAddressForTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeclineRequestAddressForTransaction.Unmarshal(m, b) +} +func (m *DeclineRequestAddressForTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeclineRequestAddressForTransaction.Marshal(b, m, deterministic) +} +func (m *DeclineRequestAddressForTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeclineRequestAddressForTransaction.Merge(m, src) +} +func (m *DeclineRequestAddressForTransaction) XXX_Size() int { + return xxx_messageInfo_DeclineRequestAddressForTransaction.Size(m) +} +func (m *DeclineRequestAddressForTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_DeclineRequestAddressForTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_DeclineRequestAddressForTransaction proto.InternalMessageInfo + +func (m *DeclineRequestAddressForTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *DeclineRequestAddressForTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type DeclineRequestTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeclineRequestTransaction) Reset() { *m = DeclineRequestTransaction{} } +func (m *DeclineRequestTransaction) String() string { return proto.CompactTextString(m) } +func (*DeclineRequestTransaction) ProtoMessage() {} +func (*DeclineRequestTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{3} +} + +func (m *DeclineRequestTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeclineRequestTransaction.Unmarshal(m, b) +} +func (m *DeclineRequestTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeclineRequestTransaction.Marshal(b, m, deterministic) +} +func (m *DeclineRequestTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeclineRequestTransaction.Merge(m, src) +} +func (m *DeclineRequestTransaction) XXX_Size() int { + return xxx_messageInfo_DeclineRequestTransaction.Size(m) +} +func (m *DeclineRequestTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_DeclineRequestTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_DeclineRequestTransaction proto.InternalMessageInfo + +func (m *DeclineRequestTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *DeclineRequestTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type RequestTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` + Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RequestTransaction) Reset() { *m = RequestTransaction{} } +func (m *RequestTransaction) String() string { return proto.CompactTextString(m) } +func (*RequestTransaction) ProtoMessage() {} +func (*RequestTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{4} +} + +func (m *RequestTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RequestTransaction.Unmarshal(m, b) +} +func (m *RequestTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RequestTransaction.Marshal(b, m, deterministic) +} +func (m *RequestTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_RequestTransaction.Merge(m, src) +} +func (m *RequestTransaction) XXX_Size() int { + return xxx_messageInfo_RequestTransaction.Size(m) +} +func (m *RequestTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_RequestTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_RequestTransaction proto.InternalMessageInfo + +func (m *RequestTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *RequestTransaction) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *RequestTransaction) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +func (m *RequestTransaction) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + +type SendTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + TransactionHash string `protobuf:"bytes,3,opt,name=transaction_hash,json=transactionHash,proto3" json:"transaction_hash,omitempty"` + Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SendTransaction) Reset() { *m = SendTransaction{} } +func (m *SendTransaction) String() string { return proto.CompactTextString(m) } +func (*SendTransaction) ProtoMessage() {} +func (*SendTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{5} +} + +func (m *SendTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SendTransaction.Unmarshal(m, b) +} +func (m *SendTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SendTransaction.Marshal(b, m, deterministic) +} +func (m *SendTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_SendTransaction.Merge(m, src) +} +func (m *SendTransaction) XXX_Size() int { + return xxx_messageInfo_SendTransaction.Size(m) +} +func (m *SendTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_SendTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_SendTransaction proto.InternalMessageInfo + +func (m *SendTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SendTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *SendTransaction) GetTransactionHash() string { + if m != nil { + return m.TransactionHash + } + return "" +} + +func (m *SendTransaction) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +func init() { + proto.RegisterType((*RequestAddressForTransaction)(nil), "protobuf.RequestAddressForTransaction") + proto.RegisterType((*AcceptRequestAddressForTransaction)(nil), "protobuf.AcceptRequestAddressForTransaction") + proto.RegisterType((*DeclineRequestAddressForTransaction)(nil), "protobuf.DeclineRequestAddressForTransaction") + proto.RegisterType((*DeclineRequestTransaction)(nil), "protobuf.DeclineRequestTransaction") + proto.RegisterType((*RequestTransaction)(nil), "protobuf.RequestTransaction") + proto.RegisterType((*SendTransaction)(nil), "protobuf.SendTransaction") +} + +func init() { proto.RegisterFile("command.proto", fileDescriptor_213c0bb044472049) } + +var fileDescriptor_213c0bb044472049 = []byte{ + // 257 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x41, 0x4b, 0x03, 0x31, + 0x10, 0x85, 0xd9, 0x6d, 0xd5, 0x76, 0x50, 0x2b, 0xc1, 0xc3, 0x2a, 0x3d, 0x94, 0x78, 0xa9, 0x17, + 0x2f, 0xfe, 0x82, 0x05, 0x11, 0xc1, 0xdb, 0xea, 0x5d, 0xa6, 0x93, 0xa9, 0x1b, 0xdc, 0x26, 0x35, + 0xc9, 0xf6, 0xec, 0x4f, 0x17, 0xb3, 0xab, 0xdb, 0x0a, 0x82, 0xab, 0xa7, 0xf0, 0x5e, 0x78, 0xf3, + 0x65, 0x1e, 0x81, 0x23, 0xb2, 0xab, 0x15, 0x1a, 0x75, 0xb5, 0x76, 0x36, 0x58, 0x31, 0x8a, 0xc7, + 0xa2, 0x5e, 0xca, 0x25, 0x4c, 0x0b, 0x7e, 0xad, 0xd9, 0x87, 0x5c, 0x29, 0xc7, 0xde, 0xdf, 0x5a, + 0xf7, 0xe8, 0xd0, 0x78, 0xa4, 0xa0, 0xad, 0x11, 0xa7, 0xb0, 0x47, 0x95, 0xa5, 0x97, 0x2c, 0x99, + 0x25, 0xf3, 0x61, 0xd1, 0x88, 0x0f, 0x77, 0x83, 0x55, 0xcd, 0x59, 0x3a, 0x4b, 0xe6, 0xe3, 0xa2, + 0x11, 0xe2, 0x1c, 0x46, 0x64, 0x4d, 0x70, 0x48, 0x21, 0x1b, 0xc4, 0x8b, 0x2f, 0x2d, 0x15, 0xc8, + 0x9c, 0x88, 0xd7, 0xe1, 0x0f, 0xb4, 0x63, 0x48, 0xb5, 0x6a, 0x51, 0xa9, 0x56, 0x22, 0x83, 0x03, + 0x6c, 0xe2, 0x2d, 0xe6, 0x53, 0xca, 0x7b, 0xb8, 0xb8, 0x61, 0xaa, 0xb4, 0xe1, 0xff, 0x63, 0x64, + 0x0e, 0x67, 0xbb, 0xc3, 0xfa, 0x8f, 0xd8, 0x80, 0xf8, 0x75, 0x76, 0x6b, 0xab, 0x74, 0x67, 0xab, + 0xae, 0xed, 0xc1, 0x4f, 0x6d, 0x0f, 0xbf, 0xb5, 0xfd, 0x96, 0xc0, 0xe4, 0x81, 0x8d, 0xea, 0xdf, + 0xed, 0x25, 0x9c, 0x84, 0x2e, 0xf4, 0x54, 0xa2, 0x2f, 0x5b, 0xec, 0x64, 0xcb, 0xbf, 0x43, 0x5f, + 0x8a, 0x29, 0x8c, 0xbd, 0x7e, 0x36, 0x18, 0x6a, 0xc7, 0xf1, 0x05, 0x87, 0x45, 0x67, 0x2c, 0xf6, + 0xe3, 0x17, 0xbb, 0x7e, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x13, 0xdb, 0x87, 0x02, 0x7a, 0x02, 0x00, + 0x00, +} diff --git a/protocol/protobuf/command.proto b/protocol/protobuf/command.proto new file mode 100644 index 00000000000..195e9035d93 --- /dev/null +++ b/protocol/protobuf/command.proto @@ -0,0 +1,39 @@ +syntax = "proto3"; + +package protobuf; + +message RequestAddressForTransaction { + uint64 clock = 1; + string value = 2; + string contract = 3; +} + +message AcceptRequestAddressForTransaction { + uint64 clock = 1; + string id = 2; + string address = 3; +} + +message DeclineRequestAddressForTransaction { + uint64 clock = 1; + string id = 2; +} + +message DeclineRequestTransaction { + uint64 clock = 1; + string id = 2; +} + +message RequestTransaction { + uint64 clock = 1; + string address = 2; + string value = 3; + string contract = 4; +} + +message SendTransaction { + uint64 clock = 1; + string id = 2; + string transaction_hash = 3; + bytes signature = 4; +} diff --git a/protocol/protobuf/contact.pb.go b/protocol/protobuf/contact.pb.go new file mode 100644 index 00000000000..0bc4ce7b8ff --- /dev/null +++ b/protocol/protobuf/contact.pb.go @@ -0,0 +1,95 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: contact.proto + +package protobuf + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ContactUpdate struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + EnsName string `protobuf:"bytes,2,opt,name=ens_name,json=ensName,proto3" json:"ens_name,omitempty"` + ProfileImage string `protobuf:"bytes,3,opt,name=profile_image,json=profileImage,proto3" json:"profile_image,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContactUpdate) Reset() { *m = ContactUpdate{} } +func (m *ContactUpdate) String() string { return proto.CompactTextString(m) } +func (*ContactUpdate) ProtoMessage() {} +func (*ContactUpdate) Descriptor() ([]byte, []int) { + return fileDescriptor_a5036fff2565fb15, []int{0} +} + +func (m *ContactUpdate) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ContactUpdate.Unmarshal(m, b) +} +func (m *ContactUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ContactUpdate.Marshal(b, m, deterministic) +} +func (m *ContactUpdate) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContactUpdate.Merge(m, src) +} +func (m *ContactUpdate) XXX_Size() int { + return xxx_messageInfo_ContactUpdate.Size(m) +} +func (m *ContactUpdate) XXX_DiscardUnknown() { + xxx_messageInfo_ContactUpdate.DiscardUnknown(m) +} + +var xxx_messageInfo_ContactUpdate proto.InternalMessageInfo + +func (m *ContactUpdate) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *ContactUpdate) GetEnsName() string { + if m != nil { + return m.EnsName + } + return "" +} + +func (m *ContactUpdate) GetProfileImage() string { + if m != nil { + return m.ProfileImage + } + return "" +} + +func init() { + proto.RegisterType((*ContactUpdate)(nil), "protobuf.ContactUpdate") +} + +func init() { proto.RegisterFile("contact.proto", fileDescriptor_a5036fff2565fb15) } + +var fileDescriptor_a5036fff2565fb15 = []byte{ + // 135 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0xce, 0xcf, 0x2b, + 0x49, 0x4c, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x00, 0x53, 0x49, 0xa5, 0x69, + 0x4a, 0xa9, 0x5c, 0xbc, 0xce, 0x10, 0xa9, 0xd0, 0x82, 0x94, 0xc4, 0x92, 0x54, 0x21, 0x11, 0x2e, + 0xd6, 0xe4, 0x9c, 0xfc, 0xe4, 0x6c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x96, 0x20, 0x08, 0x47, 0x48, + 0x92, 0x8b, 0x23, 0x35, 0xaf, 0x38, 0x3e, 0x2f, 0x31, 0x37, 0x55, 0x82, 0x49, 0x81, 0x51, 0x83, + 0x33, 0x88, 0x3d, 0x35, 0xaf, 0xd8, 0x2f, 0x31, 0x37, 0x55, 0x48, 0x99, 0x8b, 0xb7, 0xa0, 0x28, + 0x3f, 0x2d, 0x33, 0x27, 0x35, 0x3e, 0x33, 0x37, 0x31, 0x3d, 0x55, 0x82, 0x19, 0x2c, 0xcf, 0x03, + 0x15, 0xf4, 0x04, 0x89, 0x25, 0xb1, 0x81, 0x2d, 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x74, + 0xf9, 0x5c, 0xff, 0x88, 0x00, 0x00, 0x00, +} diff --git a/protocol/protobuf/contact.proto b/protocol/protobuf/contact.proto new file mode 100644 index 00000000000..06bb8b24a9d --- /dev/null +++ b/protocol/protobuf/contact.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package protobuf; + +message ContactUpdate { + uint64 clock = 1; + string ens_name = 2; + string profile_image = 3; +} diff --git a/protocol/protobuf/pairing.pb.go b/protocol/protobuf/pairing.pb.go new file mode 100644 index 00000000000..e1c3e2fa763 --- /dev/null +++ b/protocol/protobuf/pairing.pb.go @@ -0,0 +1,358 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: pairing.proto + +package protobuf + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type PairInstallation struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + InstallationId string `protobuf:"bytes,2,opt,name=installation_id,json=installationId,proto3" json:"installation_id,omitempty"` + DeviceType string `protobuf:"bytes,3,opt,name=device_type,json=deviceType,proto3" json:"device_type,omitempty"` + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *PairInstallation) Reset() { *m = PairInstallation{} } +func (m *PairInstallation) String() string { return proto.CompactTextString(m) } +func (*PairInstallation) ProtoMessage() {} +func (*PairInstallation) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{0} +} + +func (m *PairInstallation) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_PairInstallation.Unmarshal(m, b) +} +func (m *PairInstallation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_PairInstallation.Marshal(b, m, deterministic) +} +func (m *PairInstallation) XXX_Merge(src proto.Message) { + xxx_messageInfo_PairInstallation.Merge(m, src) +} +func (m *PairInstallation) XXX_Size() int { + return xxx_messageInfo_PairInstallation.Size(m) +} +func (m *PairInstallation) XXX_DiscardUnknown() { + xxx_messageInfo_PairInstallation.DiscardUnknown(m) +} + +var xxx_messageInfo_PairInstallation proto.InternalMessageInfo + +func (m *PairInstallation) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *PairInstallation) GetInstallationId() string { + if m != nil { + return m.InstallationId + } + return "" +} + +func (m *PairInstallation) GetDeviceType() string { + if m != nil { + return m.DeviceType + } + return "" +} + +func (m *PairInstallation) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +type SyncInstallationContact struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + ProfileImage string `protobuf:"bytes,3,opt,name=profile_image,json=profileImage,proto3" json:"profile_image,omitempty"` + EnsName string `protobuf:"bytes,4,opt,name=ens_name,json=ensName,proto3" json:"ens_name,omitempty"` + LastUpdated uint64 `protobuf:"varint,5,opt,name=last_updated,json=lastUpdated,proto3" json:"last_updated,omitempty"` + SystemTags []string `protobuf:"bytes,6,rep,name=system_tags,json=systemTags,proto3" json:"system_tags,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallationContact) Reset() { *m = SyncInstallationContact{} } +func (m *SyncInstallationContact) String() string { return proto.CompactTextString(m) } +func (*SyncInstallationContact) ProtoMessage() {} +func (*SyncInstallationContact) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{1} +} + +func (m *SyncInstallationContact) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallationContact.Unmarshal(m, b) +} +func (m *SyncInstallationContact) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallationContact.Marshal(b, m, deterministic) +} +func (m *SyncInstallationContact) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallationContact.Merge(m, src) +} +func (m *SyncInstallationContact) XXX_Size() int { + return xxx_messageInfo_SyncInstallationContact.Size(m) +} +func (m *SyncInstallationContact) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallationContact.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallationContact proto.InternalMessageInfo + +func (m *SyncInstallationContact) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SyncInstallationContact) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *SyncInstallationContact) GetProfileImage() string { + if m != nil { + return m.ProfileImage + } + return "" +} + +func (m *SyncInstallationContact) GetEnsName() string { + if m != nil { + return m.EnsName + } + return "" +} + +func (m *SyncInstallationContact) GetLastUpdated() uint64 { + if m != nil { + return m.LastUpdated + } + return 0 +} + +func (m *SyncInstallationContact) GetSystemTags() []string { + if m != nil { + return m.SystemTags + } + return nil +} + +type SyncInstallationAccount struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + ProfileImage string `protobuf:"bytes,2,opt,name=profile_image,json=profileImage,proto3" json:"profile_image,omitempty"` + LastUpdated uint64 `protobuf:"varint,3,opt,name=last_updated,json=lastUpdated,proto3" json:"last_updated,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallationAccount) Reset() { *m = SyncInstallationAccount{} } +func (m *SyncInstallationAccount) String() string { return proto.CompactTextString(m) } +func (*SyncInstallationAccount) ProtoMessage() {} +func (*SyncInstallationAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{2} +} + +func (m *SyncInstallationAccount) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallationAccount.Unmarshal(m, b) +} +func (m *SyncInstallationAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallationAccount.Marshal(b, m, deterministic) +} +func (m *SyncInstallationAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallationAccount.Merge(m, src) +} +func (m *SyncInstallationAccount) XXX_Size() int { + return xxx_messageInfo_SyncInstallationAccount.Size(m) +} +func (m *SyncInstallationAccount) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallationAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallationAccount proto.InternalMessageInfo + +func (m *SyncInstallationAccount) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SyncInstallationAccount) GetProfileImage() string { + if m != nil { + return m.ProfileImage + } + return "" +} + +func (m *SyncInstallationAccount) GetLastUpdated() uint64 { + if m != nil { + return m.LastUpdated + } + return 0 +} + +type SyncInstallationPublicChat struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallationPublicChat) Reset() { *m = SyncInstallationPublicChat{} } +func (m *SyncInstallationPublicChat) String() string { return proto.CompactTextString(m) } +func (*SyncInstallationPublicChat) ProtoMessage() {} +func (*SyncInstallationPublicChat) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{3} +} + +func (m *SyncInstallationPublicChat) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallationPublicChat.Unmarshal(m, b) +} +func (m *SyncInstallationPublicChat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallationPublicChat.Marshal(b, m, deterministic) +} +func (m *SyncInstallationPublicChat) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallationPublicChat.Merge(m, src) +} +func (m *SyncInstallationPublicChat) XXX_Size() int { + return xxx_messageInfo_SyncInstallationPublicChat.Size(m) +} +func (m *SyncInstallationPublicChat) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallationPublicChat.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallationPublicChat proto.InternalMessageInfo + +func (m *SyncInstallationPublicChat) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SyncInstallationPublicChat) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type SyncInstallation struct { + Contacts []*SyncInstallationContact `protobuf:"bytes,1,rep,name=contacts,proto3" json:"contacts,omitempty"` + PublicChats []*SyncInstallationPublicChat `protobuf:"bytes,2,rep,name=public_chats,json=publicChats,proto3" json:"public_chats,omitempty"` + Account *SyncInstallationAccount `protobuf:"bytes,3,opt,name=account,proto3" json:"account,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallation) Reset() { *m = SyncInstallation{} } +func (m *SyncInstallation) String() string { return proto.CompactTextString(m) } +func (*SyncInstallation) ProtoMessage() {} +func (*SyncInstallation) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{4} +} + +func (m *SyncInstallation) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallation.Unmarshal(m, b) +} +func (m *SyncInstallation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallation.Marshal(b, m, deterministic) +} +func (m *SyncInstallation) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallation.Merge(m, src) +} +func (m *SyncInstallation) XXX_Size() int { + return xxx_messageInfo_SyncInstallation.Size(m) +} +func (m *SyncInstallation) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallation.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallation proto.InternalMessageInfo + +func (m *SyncInstallation) GetContacts() []*SyncInstallationContact { + if m != nil { + return m.Contacts + } + return nil +} + +func (m *SyncInstallation) GetPublicChats() []*SyncInstallationPublicChat { + if m != nil { + return m.PublicChats + } + return nil +} + +func (m *SyncInstallation) GetAccount() *SyncInstallationAccount { + if m != nil { + return m.Account + } + return nil +} + +func init() { + proto.RegisterType((*PairInstallation)(nil), "protobuf.PairInstallation") + proto.RegisterType((*SyncInstallationContact)(nil), "protobuf.SyncInstallationContact") + proto.RegisterType((*SyncInstallationAccount)(nil), "protobuf.SyncInstallationAccount") + proto.RegisterType((*SyncInstallationPublicChat)(nil), "protobuf.SyncInstallationPublicChat") + proto.RegisterType((*SyncInstallation)(nil), "protobuf.SyncInstallation") +} + +func init() { proto.RegisterFile("pairing.proto", fileDescriptor_d61ab7221f0b5518) } + +var fileDescriptor_d61ab7221f0b5518 = []byte{ + // 378 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6e, 0x9b, 0x40, + 0x10, 0xc6, 0x05, 0xf8, 0x5f, 0x07, 0xdb, 0xb5, 0x56, 0x95, 0xba, 0xed, 0xa5, 0x98, 0x56, 0xaa, + 0x4f, 0x3e, 0xb4, 0xc7, 0xaa, 0x87, 0xc4, 0x87, 0xc8, 0x97, 0xc8, 0x22, 0xce, 0x19, 0xad, 0x97, + 0x35, 0x5e, 0x05, 0x96, 0x15, 0xbb, 0x24, 0xe2, 0x05, 0xf2, 0x62, 0x79, 0x88, 0xbc, 0x4e, 0xc4, + 0x62, 0x3b, 0xc8, 0x0e, 0x51, 0x4e, 0x2c, 0x1f, 0xb3, 0xf3, 0xfd, 0xbe, 0x19, 0x60, 0x24, 0x09, + 0xcf, 0xb9, 0x88, 0xe7, 0x32, 0xcf, 0x74, 0x86, 0x06, 0xe6, 0xb1, 0x29, 0xb6, 0xfe, 0xa3, 0x05, + 0x93, 0x15, 0xe1, 0xf9, 0x52, 0x28, 0x4d, 0x92, 0x84, 0x68, 0x9e, 0x09, 0xf4, 0x05, 0xba, 0x34, + 0xc9, 0xe8, 0x1d, 0xb6, 0x3c, 0x6b, 0xd6, 0x09, 0xea, 0x17, 0xf4, 0x1b, 0x3e, 0xf3, 0x46, 0x55, + 0xc8, 0x23, 0x6c, 0x7b, 0xd6, 0xec, 0x53, 0x30, 0x6e, 0xca, 0xcb, 0x08, 0xfd, 0x00, 0x37, 0x62, + 0xf7, 0x9c, 0xb2, 0x50, 0x97, 0x92, 0x61, 0xc7, 0x14, 0x41, 0x2d, 0xad, 0x4b, 0xc9, 0x10, 0x82, + 0x8e, 0x20, 0x29, 0xc3, 0x1d, 0xf3, 0xc5, 0x9c, 0xfd, 0x27, 0x0b, 0xbe, 0xde, 0x94, 0x82, 0x36, + 0x41, 0x16, 0x99, 0xd0, 0x84, 0xea, 0x16, 0x9e, 0x31, 0xd8, 0x47, 0x04, 0x9b, 0x47, 0xe8, 0x27, + 0x8c, 0x64, 0x9e, 0x6d, 0x79, 0xc2, 0x42, 0x9e, 0x92, 0xf8, 0x60, 0x3c, 0xdc, 0x8b, 0xcb, 0x4a, + 0x43, 0xdf, 0x60, 0xc0, 0x84, 0x0a, 0x1b, 0xf6, 0x7d, 0x26, 0xd4, 0x35, 0x49, 0x19, 0x9a, 0xc2, + 0x30, 0x21, 0x4a, 0x87, 0x85, 0x8c, 0x88, 0x66, 0x11, 0xee, 0x1a, 0x33, 0xb7, 0xd2, 0x6e, 0x6b, + 0xa9, 0x4a, 0xa6, 0x4a, 0xa5, 0x59, 0x1a, 0x6a, 0x12, 0x2b, 0xdc, 0xf3, 0x9c, 0x2a, 0x59, 0x2d, + 0xad, 0x49, 0xac, 0xfc, 0x87, 0xf3, 0x10, 0x17, 0x94, 0x66, 0x85, 0x68, 0x0b, 0x71, 0x06, 0x6d, + 0xbf, 0x01, 0x7d, 0x4a, 0xe6, 0x9c, 0x91, 0xf9, 0x97, 0xf0, 0xfd, 0xd4, 0x78, 0x55, 0x6c, 0x12, + 0x4e, 0x17, 0x3b, 0xf2, 0xc1, 0x01, 0xfa, 0xcf, 0x16, 0x4c, 0x4e, 0x9b, 0xa0, 0xff, 0x30, 0xa0, + 0xf5, 0x1a, 0x14, 0xb6, 0x3c, 0x67, 0xe6, 0xfe, 0x99, 0xce, 0x0f, 0x7f, 0xcf, 0xbc, 0x65, 0x61, + 0xc1, 0xf1, 0x0a, 0xba, 0x82, 0xa1, 0x34, 0x1c, 0x21, 0xdd, 0x11, 0xad, 0xb0, 0x6d, 0x5a, 0xfc, + 0x6a, 0x6f, 0xf1, 0x4a, 0x1d, 0xb8, 0xf2, 0x78, 0x56, 0xe8, 0x1f, 0xf4, 0x49, 0x3d, 0x49, 0x13, + 0xff, 0x5d, 0x8c, 0xfd, 0xc8, 0x83, 0xc3, 0x8d, 0x4d, 0xcf, 0x94, 0xfe, 0x7d, 0x09, 0x00, 0x00, + 0xff, 0xff, 0xd7, 0x5f, 0x3a, 0x87, 0x07, 0x03, 0x00, 0x00, +} diff --git a/protocol/protobuf/pairing.proto b/protocol/protobuf/pairing.proto new file mode 100644 index 00000000000..9b6bce63e05 --- /dev/null +++ b/protocol/protobuf/pairing.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +package protobuf; + +message PairInstallation { + uint64 clock = 1; + string installation_id = 2; + string device_type = 3; + string name = 4; +} + +message SyncInstallationContact { + uint64 clock = 1; + string id = 2; + string profile_image = 3; + string ens_name = 4; + uint64 last_updated = 5; + repeated string system_tags = 6; +} + +message SyncInstallationAccount { + uint64 clock = 1; + string profile_image = 2; + uint64 last_updated = 3; +} + +message SyncInstallationPublicChat { + uint64 clock = 1; + string id = 2; +} + +message SyncInstallation { + repeated SyncInstallationContact contacts = 1; + repeated SyncInstallationPublicChat public_chats = 2; + SyncInstallationAccount account = 3; +} diff --git a/protocol/protobuf/service.go b/protocol/protobuf/service.go index 56d5d54c272..f6652e485fe 100644 --- a/protocol/protobuf/service.go +++ b/protocol/protobuf/service.go @@ -4,7 +4,7 @@ import ( "github.com/golang/protobuf/proto" ) -//go:generate protoc --go_out=. ./chat_message.proto ./application_metadata_message.proto ./membership_update_message.proto +//go:generate protoc --go_out=. ./chat_message.proto ./application_metadata_message.proto ./membership_update_message.proto ./command.proto ./contact.proto ./pairing.proto func Unmarshal(payload []byte) (*ApplicationMetadataMessage, error) { var message ApplicationMetadataMessage diff --git a/protocol/transaction_validator.go b/protocol/transaction_validator.go new file mode 100644 index 00000000000..fc5cd3550eb --- /dev/null +++ b/protocol/transaction_validator.go @@ -0,0 +1,324 @@ +package protocol + +import ( + "context" + "crypto/ecdsa" + "encoding/hex" + "fmt" + "time" + + "github.com/pkg/errors" + coretypes "github.com/status-im/status-go/eth-node/core/types" + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "go.uber.org/zap" + "math/big" + "strings" +) + +const ( + transferFunction = "a9059cbb" + tokenTransferDataLength = 68 + transactionHashLength = 66 +) + +type TransactionValidator struct { + persistence *sqlitePersistence + addresses map[string]bool + client EthClient + logger *zap.Logger +} + +var invalidResponse = &VerifyTransactionResponse{Valid: false} + +type TransactionToValidate struct { + TransactionHash string + CommandID string + MessageID string + RetryCount int + // First seen indicates the whisper timestamp of the first time we seen this + FirstSeen uint64 + // Validate indicates whether we should be validating this transaction + Validate bool + Signature []byte + From *ecdsa.PublicKey +} + +func NewTransactionValidator(addresses []types.Address, persistence *sqlitePersistence, client EthClient, logger *zap.Logger) *TransactionValidator { + addressesMap := make(map[string]bool) + for _, a := range addresses { + addressesMap[strings.ToLower(a.Hex())] = true + } + logger.Debug("Checking addresses", zap.Any("addrse", addressesMap)) + + return &TransactionValidator{ + persistence: persistence, + addresses: addressesMap, + logger: logger, + client: client, + } +} + +type EthClient interface { + TransactionByHash(context.Context, types.Hash) (coretypes.Message, bool, error) +} + +func (t *TransactionValidator) verifyTransactionSignature(ctx context.Context, from *ecdsa.PublicKey, address types.Address, transactionHash string, signature []byte) error { + publicKeyBytes := crypto.FromECDSAPub(from) + + if len(transactionHash) != transactionHashLength { + return errors.New("wrong transaction hash lenght") + } + + hashBytes, err := hex.DecodeString(transactionHash[2:]) + if err != nil { + return err + } + signatureMaterial := append(publicKeyBytes, hashBytes...) + + // We take a copy as EcRecover modifies the byte slice + signatureCopy := make([]byte, len(signature)) + copy(signatureCopy, signature) + extractedAddress, err := crypto.EcRecover(ctx, signatureMaterial, signatureCopy) + if err != nil { + return err + } + + if extractedAddress != address { + return errors.New("failed to verify signature") + } + return nil +} + +func (t *TransactionValidator) validateTokenTransfer(parameters *CommandParameters, transaction coretypes.Message) (*VerifyTransactionResponse, error) { + + data := transaction.Data() + if len(data) != tokenTransferDataLength { + return nil, errors.New(fmt.Sprintf("wrong data length: %d", len(data))) + } + + functionCalled := hex.EncodeToString(data[:4]) + + if functionCalled != transferFunction { + return invalidResponse, nil + } + + actualContractAddress := strings.ToLower(transaction.To().Hex()) + + if parameters.Contract != "" && actualContractAddress != parameters.Contract { + return invalidResponse, nil + } + + to := types.EncodeHex(data[16:36]) + + if !t.validateToAddress(parameters.Address, to) { + return invalidResponse, nil + } + + value := data[36:] + amount := new(big.Int).SetBytes(value) + + if parameters.Value != "" { + advertisedAmount, ok := new(big.Int).SetString(parameters.Value, 10) + if !ok { + return nil, errors.New("can't parse amount") + } + + return &VerifyTransactionResponse{ + Value: parameters.Value, + Contract: actualContractAddress, + Address: to, + AccordingToSpec: amount.Cmp(advertisedAmount) == 0, + Valid: true, + }, nil + } + + return &VerifyTransactionResponse{ + Value: amount.String(), + Address: to, + Contract: actualContractAddress, + AccordingToSpec: false, + Valid: true, + }, nil + +} + +func (t *TransactionValidator) validateToAddress(specifiedTo, actualTo string) bool { + if len(specifiedTo) != 0 && (strings.ToLower(specifiedTo) != strings.ToLower(actualTo) || !t.addresses[strings.ToLower(actualTo)]) { + return false + } + + return t.addresses[actualTo] +} + +func (t *TransactionValidator) validateEthereumTransfer(parameters *CommandParameters, transaction coretypes.Message) (*VerifyTransactionResponse, error) { + toAddress := strings.ToLower(transaction.To().Hex()) + + if !t.validateToAddress(parameters.Address, toAddress) { + return invalidResponse, nil + } + amount := transaction.Value() + if parameters.Value != "" { + advertisedAmount, ok := new(big.Int).SetString(parameters.Value, 10) + if !ok { + return nil, errors.New("can't parse amount") + } + return &VerifyTransactionResponse{ + AccordingToSpec: amount.Cmp(advertisedAmount) == 0, + Valid: true, + Value: amount.String(), + Address: toAddress, + }, nil + + } else { + return &VerifyTransactionResponse{ + AccordingToSpec: false, + Valid: true, + Value: amount.String(), + Address: toAddress, + }, nil + + } + +} + +type VerifyTransactionResponse struct { + Pending bool + // AccordingToSpec means that the transaction is valid, + // the user should be notified, but is not the same as + // what was requested, for example because the value is different + AccordingToSpec bool + // Valid means that the transaction is valid + Valid bool + // The actual value received + Value string + // The contract used in case of tokens + Contract string + // The address the transaction was actually sent + Address string + + Message *Message + Transaction *TransactionToValidate +} + +// validateTransaction validates a transaction and returns a response. +// If a negative response is returned, i.e `Valid` is false, it should +// not be retried. +// If an error is returned, validation can be retried. +func (t *TransactionValidator) validateTransaction(ctx context.Context, message coretypes.Message, parameters *CommandParameters, from *ecdsa.PublicKey) (*VerifyTransactionResponse, error) { + + fromAddress := types.BytesToAddress(message.From().Bytes()) + + err := t.verifyTransactionSignature(ctx, from, fromAddress, parameters.TransactionHash, parameters.Signature) + if err != nil { + t.logger.Error("failed validating signature", zap.Error(err)) + return invalidResponse, nil + } + + if len(message.Data()) != 0 { + t.logger.Debug("Validating token") + return t.validateTokenTransfer(parameters, message) + } else { + t.logger.Debug("Validating eth") + return t.validateEthereumTransfer(parameters, message) + } +} + +func (t *TransactionValidator) ValidateTransactions(ctx context.Context) ([]*VerifyTransactionResponse, error) { + if t.client == nil { + return nil, nil + } + var response []*VerifyTransactionResponse + t.logger.Debug("Started validating transactions") + transactions, err := t.persistence.TransactionsToValidate() + if err != nil { + return nil, err + } + + t.logger.Debug("Transactions to validated", zap.Any("transactions", transactions)) + + for _, transaction := range transactions { + var validationResult *VerifyTransactionResponse + t.logger.Debug("Validating transaction", zap.Any("transaction", transaction)) + if transaction.CommandID != "" { + message, err := t.persistence.MessageByCommandID(transaction.CommandID) + if err != nil { + + t.logger.Error("error pulling message", zap.Error(err)) + return nil, err + } + if message == nil { + t.logger.Info("No message found, ignoring transaction") + // This is not a valid case, ignore transaction + transaction.Validate = false + transaction.RetryCount += 1 + err = t.persistence.UpdateTransactionToValidate(transaction) + if err != nil { + return nil, err + } + continue + + } + commandParameters := message.CommandParameters + commandParameters.TransactionHash = transaction.TransactionHash + commandParameters.Signature = transaction.Signature + validationResult, err = t.ValidateTransaction(ctx, message.CommandParameters, transaction.From) + if err != nil { + t.logger.Error("Error validating transaction", zap.Error(err)) + continue + } + validationResult.Message = message + } else { + commandParameters := &CommandParameters{} + commandParameters.TransactionHash = transaction.TransactionHash + commandParameters.Signature = transaction.Signature + + validationResult, err = t.ValidateTransaction(ctx, commandParameters, transaction.From) + if err != nil { + t.logger.Error("Error validating transaction", zap.Error(err)) + continue + } + } + + if validationResult.Pending { + t.logger.Debug("Pending transaction skipping") + // Check if we should stop updating + continue + } + + // Mark transaction as valid + transaction.Validate = false + transaction.RetryCount += 1 + err = t.persistence.UpdateTransactionToValidate(transaction) + if err != nil { + return nil, err + } + + if !validationResult.Valid { + t.logger.Debug("Transaction not valid") + continue + } + t.logger.Debug("Transaction valid") + validationResult.Transaction = transaction + response = append(response, validationResult) + } + return response, nil +} + +func (t *TransactionValidator) ValidateTransaction(ctx context.Context, parameters *CommandParameters, from *ecdsa.PublicKey) (*VerifyTransactionResponse, error) { + t.logger.Debug("validating transaction", zap.Any("transaction", parameters), zap.Any("from", from)) + hash := parameters.TransactionHash + c, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() + + message, pending, err := t.client.TransactionByHash(c, types.HexToHash(hash)) + if err != nil { + return nil, err + } + if pending { + t.logger.Debug("Transaction pending") + return &VerifyTransactionResponse{Pending: true}, nil + } + + return t.validateTransaction(ctx, message, parameters, from) +} diff --git a/protocol/transaction_validator_test.go b/protocol/transaction_validator_test.go new file mode 100644 index 00000000000..2369246b64e --- /dev/null +++ b/protocol/transaction_validator_test.go @@ -0,0 +1,439 @@ +package protocol + +import ( + "context" + "crypto/ecdsa" + "encoding/hex" + "strings" + "testing" + + coretypes "github.com/status-im/status-go/eth-node/core/types" + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/protocol/tt" + "github.com/stretchr/testify/suite" + "math/big" +) + +func padArray(bb []byte, size int) []byte { + l := len(bb) + if l == size { + return bb + } + if l > size { + return bb[l-size:] + } + tmp := make([]byte, size) + copy(tmp[size-l:], bb) + return tmp +} + +type TransactionValidatorSuite struct { + suite.Suite +} + +func TestTransactionValidatorSuite(t *testing.T) { + suite.Run(t, new(TransactionValidatorSuite)) +} + +func buildSignature(walletKey *ecdsa.PrivateKey, chatKey *ecdsa.PublicKey, hash string) ([]byte, error) { + hashBytes, err := hex.DecodeString(hash[2:]) + if err != nil { + return nil, err + } + chatKeyBytes := crypto.FromECDSAPub(chatKey) + signatureMaterial := append(chatKeyBytes, hashBytes...) + signatureMaterial = crypto.TextHash(signatureMaterial) + signature, err := crypto.Sign(signatureMaterial, walletKey) + if err != nil { + return nil, err + } + signature[64] += 27 + return signature, nil +} + +func buildData(fn string, to types.Address, value *big.Int) []byte { + var data []byte + addressBytes := make([]byte, 32) + + fnBytes, _ := hex.DecodeString(fn) + copy(addressBytes[12:], to.Bytes()) + valueBytes := padArray(value.Bytes(), 32) + + data = append(data, fnBytes...) + data = append(data, addressBytes...) + data = append(data, valueBytes...) + return data +} + +func (s *TransactionValidatorSuite) TestValidateTransactions() { + notTransferFunction := "a9059cbd" + + senderKey, err := crypto.GenerateKey() + s.Require().NoError(err) + + senderWalletKey, err := crypto.GenerateKey() + s.Require().NoError(err) + + myWalletKey1, err := crypto.GenerateKey() + s.Require().NoError(err) + myWalletKey2, err := crypto.GenerateKey() + s.Require().NoError(err) + + senderAddress := crypto.PubkeyToAddress(senderWalletKey.PublicKey) + myAddress1 := crypto.PubkeyToAddress(myWalletKey1.PublicKey) + myAddress2 := crypto.PubkeyToAddress(myWalletKey2.PublicKey) + + db, err := openTestDB() + s.Require().NoError(err) + p := &sqlitePersistence{db: db} + + logger := tt.MustCreateTestLogger() + validator := NewTransactionValidator([]types.Address{myAddress1, myAddress2}, p, nil, logger) + + contractString := "0x744d70fdbe2ba4cf95131626614a1763df805b9e" + contractAddress := types.HexToAddress(contractString) + + defaultTransactionHash := "0x53edbe74408c2eeed4e5493b3aac0c006d8a14b140975f4306dd35f5e1d245bc" + testCases := []struct { + Name string + Valid bool + AccordingToSpec bool + Error bool + Transaction coretypes.Message + OverrideSignatureChatKey *ecdsa.PublicKey + OverrideTransactionHash string + Parameters *CommandParameters + WalletKey *ecdsa.PrivateKey + From *ecdsa.PublicKey + }{ + { + Name: "valid eth transfer to any address", + Valid: true, + AccordingToSpec: true, + Transaction: coretypes.NewMessage( + senderAddress, + &myAddress1, + 1, + big.NewInt(int64(23)), + 0, + nil, + nil, + false, + ), + Parameters: &CommandParameters{ + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "valid eth transfer to specific address", + Valid: true, + AccordingToSpec: true, + Transaction: coretypes.NewMessage( + senderAddress, + &myAddress1, + 1, + big.NewInt(int64(23)), + 0, + nil, + nil, + false, + ), + Parameters: &CommandParameters{ + Value: "23", + Address: strings.ToLower(myAddress1.Hex()), + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "invalid eth transfer, not includes pk of the chat in signature", + Transaction: coretypes.NewMessage( + senderAddress, + &myAddress1, + 1, + big.NewInt(int64(23)), + 0, + nil, + nil, + false, + ), + Parameters: &CommandParameters{ + Value: "23", + Address: strings.ToLower(myAddress1.Hex()), + }, + WalletKey: senderWalletKey, + OverrideSignatureChatKey: &senderWalletKey.PublicKey, + From: &senderKey.PublicKey, + }, + { + Name: "invalid eth transfer, not signed with the wallet key", + Transaction: coretypes.NewMessage( + senderAddress, + &myAddress1, + 1, + big.NewInt(int64(23)), + 0, + nil, + nil, + false, + ), + Parameters: &CommandParameters{ + Value: "23", + Address: strings.ToLower(myAddress1.Hex()), + }, + WalletKey: senderKey, + From: &senderKey.PublicKey, + }, + { + Name: "invalid eth transfer, wrong signature transaction hash", + Transaction: coretypes.NewMessage( + senderAddress, + &myAddress1, + 1, + big.NewInt(int64(23)), + 0, + nil, + nil, + false, + ), + OverrideTransactionHash: "0xdd9202df5e2f3611b5b6b716aef2a3543cc0bdd7506f50926e0869b83c8383b9", + Parameters: &CommandParameters{ + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + + { + Name: "invalid eth transfer, we own the wallet but not as specified", + Transaction: coretypes.NewMessage( + senderAddress, + &myAddress1, + 1, + big.NewInt(int64(23)), + 0, + nil, + nil, + false, + ), + Parameters: &CommandParameters{ + Value: "23", + Address: strings.ToLower(myAddress2.Hex()), + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "invalid eth transfer, not our wallet", + Transaction: coretypes.NewMessage( + senderAddress, + &senderAddress, + 1, + big.NewInt(int64(23)), + 0, + nil, + nil, + false, + ), + Parameters: &CommandParameters{ + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "valid eth transfer, but not according to spec, wrong amount", + Valid: true, + Transaction: coretypes.NewMessage( + senderAddress, + &myAddress1, + 1, + big.NewInt(int64(20)), + 0, + nil, + nil, + false, + ), + Parameters: &CommandParameters{ + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "valid token transfer to any address", + Valid: true, + AccordingToSpec: true, + Transaction: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + big.NewInt(int64(0)), + 0, + nil, + buildData(transferFunction, myAddress1, big.NewInt(int64(23))), + false, + ), + Parameters: &CommandParameters{ + Contract: contractString, + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "valid token transfer to a specific address", + Valid: true, + AccordingToSpec: true, + Transaction: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + big.NewInt(int64(0)), + 0, + nil, + buildData(transferFunction, myAddress1, big.NewInt(int64(23))), + false, + ), + Parameters: &CommandParameters{ + Contract: contractString, + Address: strings.ToLower(myAddress1.Hex()), + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "valid token transfer, not according to spec because of amount", + Valid: true, + AccordingToSpec: false, + Transaction: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + big.NewInt(int64(0)), + 0, + nil, + buildData(transferFunction, myAddress1, big.NewInt(int64(13))), + false, + ), + Parameters: &CommandParameters{ + Contract: contractString, + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "invalid token transfer, wrong contract", + Transaction: coretypes.NewMessage( + senderAddress, + &senderAddress, + 1, + big.NewInt(int64(0)), + 0, + nil, + buildData(transferFunction, myAddress1, big.NewInt(int64(23))), + false, + ), + Parameters: &CommandParameters{ + Contract: contractString, + Address: strings.ToLower(myAddress1.Hex()), + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + + { + Name: "invalid token transfer, not an address I own", + Transaction: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + big.NewInt(int64(0)), + 0, + nil, + buildData(transferFunction, myAddress1, big.NewInt(int64(23))), + false, + ), + Parameters: &CommandParameters{ + Contract: contractString, + Address: strings.ToLower(senderAddress.Hex()), + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + + { + Name: "invalid token transfer, not the specified address", + Transaction: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + big.NewInt(int64(0)), + 0, + nil, + buildData(transferFunction, myAddress2, big.NewInt(int64(23))), + false, + ), + Parameters: &CommandParameters{ + Contract: contractString, + Address: strings.ToLower(myAddress1.Hex()), + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + { + Name: "invalid token transfer, wrong fn", + Transaction: coretypes.NewMessage( + senderAddress, + &contractAddress, + 1, + big.NewInt(int64(0)), + 0, + nil, + buildData(notTransferFunction, myAddress1, big.NewInt(int64(23))), + false, + ), + Parameters: &CommandParameters{ + Contract: contractString, + Value: "23", + }, + WalletKey: senderWalletKey, + From: &senderKey.PublicKey, + }, + } + + for _, tc := range testCases { + s.Run(tc.Name, func() { + tc.Parameters.TransactionHash = defaultTransactionHash + signatureTransactionHash := defaultTransactionHash + signatureChatKey := tc.From + if tc.OverrideTransactionHash != "" { + signatureTransactionHash = tc.OverrideTransactionHash + } + if tc.OverrideSignatureChatKey != nil { + signatureChatKey = tc.OverrideSignatureChatKey + } + signature, err := buildSignature(tc.WalletKey, signatureChatKey, signatureTransactionHash) + s.Require().NoError(err) + tc.Parameters.Signature = signature + + response, err := validator.validateTransaction(context.Background(), tc.Transaction, tc.Parameters, tc.From) + if tc.Error { + s.Error(err) + return + } + s.Require().NoError(err) + s.Equal(tc.AccordingToSpec, response.AccordingToSpec) + s.Equal(tc.Valid, response.Valid) + }) + } + +} diff --git a/protocol/v1/status_message.go b/protocol/v1/status_message.go index aa9a9cc771e..e1653e2356d 100644 --- a/protocol/v1/status_message.go +++ b/protocol/v1/status_message.go @@ -182,7 +182,143 @@ func (m *StatusMessage) HandleApplication() error { return nil } - } + case protobuf.ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION: + var message protobuf.AcceptRequestAddressForTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode AcceptRequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SEND_TRANSACTION: + var message protobuf.SendTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SendTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + + case protobuf.ApplicationMetadataMessage_REQUEST_TRANSACTION: + var message protobuf.RequestTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode RequestTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION: + var message protobuf.DeclineRequestAddressForTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode DeclineRequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION: + var message protobuf.DeclineRequestTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode DeclineRequestTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + + case protobuf.ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION: + var message protobuf.RequestAddressForTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode RequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + + case protobuf.ApplicationMetadataMessage_CONTACT_UPDATE: + var message protobuf.ContactUpdate + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode ContactUpdate: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION: + var message protobuf.SyncInstallation + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallation: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT: + var message protobuf.SyncInstallationContact + log.Printf("Sync installation contact") + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallationContact: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT: + var message protobuf.SyncInstallationPublicChat + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallationPublicChat: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT: + var message protobuf.SyncInstallationAccount + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallationAccount: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_PAIR_INSTALLATION: + var message protobuf.PairInstallation + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode PairInstallation: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + } return nil } diff --git a/services/shhext/api.go b/services/shhext/api.go index e8371baf3e3..91b5cabaa21 100644 --- a/services/shhext/api.go +++ b/services/shhext/api.go @@ -646,7 +646,7 @@ func (api *PublicAPI) DisableInstallation(installationID string) error { } // GetOurInstallations returns all the installations available given an identity -func (api *PublicAPI) GetOurInstallations() ([]*multidevice.Installation, error) { +func (api *PublicAPI) GetOurInstallations() []*multidevice.Installation { return api.service.messenger.Installations() } @@ -697,10 +697,46 @@ func (api *PublicAPI) SendChatMessage(ctx context.Context, message *protocol.Mes return api.service.messenger.SendChatMessage(ctx, message) } -func (api *PublicAPI) ReSendChatMessage(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) { +func (api *PublicAPI) ReSendChatMessage(ctx context.Context, messageID string) error { return api.service.messenger.ReSendChatMessage(ctx, messageID) } +func (api *PublicAPI) RequestTransaction(ctx context.Context, chatID, value, contract, address string) (*protocol.MessengerResponse, error) { + return api.service.messenger.RequestTransaction(ctx, chatID, value, contract, address) +} + +func (api *PublicAPI) RequestAddressForTransaction(ctx context.Context, chatID, from, value, contract string) (*protocol.MessengerResponse, error) { + return api.service.messenger.RequestAddressForTransaction(ctx, chatID, from, value, contract) +} + +func (api *PublicAPI) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) { + return api.service.messenger.DeclineRequestAddressForTransaction(ctx, messageID) +} + +func (api *PublicAPI) DeclineRequestTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) { + return api.service.messenger.DeclineRequestTransaction(ctx, messageID) +} + +func (api *PublicAPI) AcceptRequestAddressForTransaction(ctx context.Context, messageID, address string) (*protocol.MessengerResponse, error) { + return api.service.messenger.AcceptRequestAddressForTransaction(ctx, messageID, address) +} + +func (api *PublicAPI) SendTransaction(ctx context.Context, chatID, transactionHash string, signature types.HexBytes) (*protocol.MessengerResponse, error) { + return api.service.messenger.SendTransaction(ctx, chatID, transactionHash, signature) +} + +func (api *PublicAPI) AcceptRequestTransaction(ctx context.Context, transactionHash, messageID string, signature types.HexBytes) (*protocol.MessengerResponse, error) { + return api.service.messenger.AcceptRequestTransaction(ctx, transactionHash, messageID, signature) +} + +func (api *PublicAPI) SendContactUpdates(ctx context.Context, name, picture string) error { + return api.service.messenger.SendContactUpdates(ctx, name, picture) +} + +func (api *PublicAPI) SendContactUpdate(ctx context.Context, contactID, name, picture string) (*protocol.MessengerResponse, error) { + return api.service.messenger.SendContactUpdate(ctx, contactID, name, picture) +} + // ----- // HELPER // ----- diff --git a/services/shhext/service.go b/services/shhext/service.go index 02edc51956c..5fb1b31137a 100644 --- a/services/shhext/service.go +++ b/services/shhext/service.go @@ -5,12 +5,16 @@ import ( "crypto/ecdsa" "database/sql" "fmt" + "math/big" "os" "path/filepath" "time" "github.com/status-im/status-go/logutils" + commongethtypes "github.com/ethereum/go-ethereum/common" + gethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" @@ -18,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/status-im/status-go/db" + "github.com/status-im/status-go/multiaccounts/accounts" "github.com/status-im/status-go/params" "github.com/status-im/status-go/services/shhext/mailservers" "github.com/status-im/status-go/signal" @@ -25,6 +30,7 @@ import ( "github.com/syndtr/goleveldb/leveldb" "go.uber.org/zap" + coretypes "github.com/status-im/status-go/eth-node/core/types" "github.com/status-im/status-go/eth-node/types" protocol "github.com/status-im/status-go/protocol" protocolwhisper "github.com/status-im/status-go/protocol/transport/whisper" @@ -64,6 +70,7 @@ type Service struct { cache *mailservers.Cache connManager *mailservers.ConnectionManager lastUsedMonitor *mailservers.LastUsedConnectionMonitor + accountsDB *accounts.Database } // Make sure that Service implements node.Service interface. @@ -150,10 +157,12 @@ func (s *Service) InitProtocol(identity *ecdsa.PrivateKey, db *sql.DB) error { / if err != nil { return err } + s.accountsDB = accounts.NewDB(db) s.messenger = messenger // Start a loop that retrieves all messages and propagates them to status-react. s.cancelMessenger = make(chan struct{}) go s.retrieveMessagesLoop(time.Second, s.cancelMessenger) + go s.verifyTransactionLoop(30*time.Second, s.cancelMessenger) return s.messenger.Init() } @@ -179,6 +188,82 @@ func (s *Service) retrieveMessagesLoop(tick time.Duration, cancel <-chan struct{ } } +type verifyTransactionClient struct { + chainID *big.Int + url string +} + +func (c *verifyTransactionClient) TransactionByHash(ctx context.Context, hash types.Hash) (coretypes.Message, bool, error) { + signer := gethtypes.NewEIP155Signer(c.chainID) + client, err := ethclient.Dial(c.url) + if err != nil { + return coretypes.Message{}, false, err + } + + transaction, pending, err := client.TransactionByHash(ctx, commongethtypes.BytesToHash(hash.Bytes())) + if err != nil { + return coretypes.Message{}, false, err + } + + message, err := transaction.AsMessage(signer) + if err != nil { + return coretypes.Message{}, false, err + } + from := types.BytesToAddress(message.From().Bytes()) + to := types.BytesToAddress(message.To().Bytes()) + + return coretypes.NewMessage( + from, + &to, + message.Nonce(), + message.Value(), + message.Gas(), + message.GasPrice(), + message.Data(), + message.CheckNonce(), + ), pending, nil +} + +func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct{}) { + if s.config.VerifyTransactionURL == "" { + log.Warn("not starting transaction loop") + return + } + + ticker := time.NewTicker(tick) + defer ticker.Stop() + + ctx, cancelVerifyTransaction := context.WithCancel(context.Background()) + + for { + select { + case <-ticker.C: + accounts, err := s.accountsDB.GetAccounts() + if err != nil { + log.Error("failed to retrieve accounts", "err", err) + } + var wallets []types.Address + for _, account := range accounts { + if account.Wallet { + wallets = append(wallets, types.BytesToAddress(account.Address.Bytes())) + } + } + + response, err := s.messenger.ValidateTransactions(ctx, wallets) + if err != nil { + log.Error("failed to validate transactions", "err", err) + continue + } + if !response.IsEmpty() { + PublisherSignalHandler{}.NewMessages(response) + } + case <-cancel: + cancelVerifyTransaction() + return + } + } +} + func (s *Service) ConfirmMessagesProcessed(messageIDs [][]byte) error { return s.messenger.ConfirmMessagesProcessed(messageIDs) } @@ -358,5 +443,13 @@ func buildMessengerOptions(config params.ShhextConfig, db *sql.DB, envelopesMoni options = append(options, protocol.WithDatasync()) } + if config.VerifyTransactionURL != "" { + client := &verifyTransactionClient{ + url: config.VerifyTransactionURL, + chainID: big.NewInt(config.VerifyTransactionChainID), + } + options = append(options, protocol.WithVerifyTransactionClient(client)) + } + return options } diff --git a/static/bindata.go b/static/bindata.go index fe190dd6dff..a1d3b36cbd5 100644 --- a/static/bindata.go +++ b/static/bindata.go @@ -97,7 +97,7 @@ func ConfigReadmeMd() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/README.md", size: 3330, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "../config/README.md", size: 3330, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x65, 0xb9, 0xf5, 0x6, 0xbe, 0x7d, 0x85, 0x3b, 0x8, 0xbc, 0x5c, 0x71, 0x85, 0x19, 0xd1, 0xde, 0x38, 0xb5, 0xe9, 0x90, 0x5c, 0x45, 0xb2, 0xa5, 0x8a, 0x91, 0xee, 0xeb, 0x1e, 0xb4, 0xa9, 0x8f}} return a, nil } @@ -117,7 +117,7 @@ func ConfigCliFleetEthBetaJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3261, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3261, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x2b, 0xae, 0x42, 0x4b, 0xa4, 0xd9, 0x2, 0x69, 0x99, 0x29, 0x7e, 0x1, 0x4e, 0xd9, 0x58, 0x84, 0x28, 0x3a, 0x81, 0xc4, 0xde, 0x1d, 0xea, 0x51, 0xc8, 0x21, 0xff, 0x7b, 0xff, 0x23, 0x1c, 0x16}} return a, nil } @@ -137,7 +137,7 @@ func ConfigCliFleetEthStagingJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1862, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1862, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xae, 0x85, 0xa1, 0x10, 0x16, 0x87, 0x10, 0x1c, 0xc3, 0xf4, 0xc7, 0xc, 0x2e, 0x51, 0xb7, 0x3, 0x61, 0x16, 0x99, 0x84, 0x3d, 0x5d, 0x82, 0x62, 0xfb, 0xf4, 0x5e, 0x19, 0xda, 0xb9, 0xaa, 0xc4}} return a, nil } @@ -157,7 +157,7 @@ func ConfigCliFleetEthTestJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1543, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1543, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x68, 0xef, 0x71, 0xa1, 0x38, 0x37, 0xf0, 0x0, 0xbb, 0x95, 0x26, 0x2a, 0x2a, 0x65, 0x98, 0xfe, 0xe5, 0x3f, 0xbf, 0xb, 0x68, 0xa6, 0xb5, 0xa4, 0x10, 0xc1, 0x4b, 0x67, 0xb4, 0x4e, 0x32, 0xc0}} return a, nil } @@ -177,7 +177,7 @@ func ConfigCliLesEnabledJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x7e, 0xee, 0x27, 0xa7, 0x74, 0xa0, 0x46, 0xa1, 0x41, 0xed, 0x4d, 0x16, 0x5b, 0xf3, 0xf0, 0x7c, 0xc8, 0x2f, 0x6f, 0x47, 0xa4, 0xbb, 0x5f, 0x43, 0x33, 0xd, 0x9, 0x9d, 0xea, 0x9e, 0x15, 0xee}} return a, nil } @@ -197,7 +197,7 @@ func ConfigCliMailserverEnabledJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/mailserver-enabled.json", size: 176, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "../config/cli/mailserver-enabled.json", size: 176, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0xec, 0x81, 0x8b, 0x99, 0xb6, 0xdb, 0xc0, 0x8b, 0x46, 0x97, 0x96, 0xc7, 0x58, 0x30, 0x33, 0xef, 0x54, 0x25, 0x87, 0x7b, 0xb9, 0x94, 0x6b, 0x18, 0xa4, 0x5b, 0x58, 0x67, 0x7c, 0x44, 0xa6}} return a, nil } @@ -217,7 +217,7 @@ func ConfigStatusChainGenesisJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} + info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb, 0xf0, 0xc, 0x1, 0x95, 0x65, 0x6, 0x55, 0x48, 0x8f, 0x83, 0xa0, 0xb4, 0x81, 0xda, 0xad, 0x30, 0x6d, 0xb2, 0x78, 0x1b, 0x26, 0x4, 0x13, 0x12, 0x9, 0x6, 0xae, 0x3a, 0x2c, 0x1, 0x71}} return a, nil } @@ -237,7 +237,7 @@ func keysBootnodeKey() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/bootnode.key", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "keys/bootnode.key", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x31, 0xcf, 0x27, 0xd4, 0x96, 0x2e, 0x32, 0xcd, 0x58, 0x96, 0x2a, 0xe5, 0x8c, 0xa0, 0xf1, 0x73, 0x1f, 0xd6, 0xd6, 0x8b, 0xb, 0x73, 0xd3, 0x2c, 0x84, 0x1a, 0x56, 0xa4, 0x74, 0xb6, 0x95, 0x20}} return a, nil } @@ -257,7 +257,7 @@ func keysFirebaseauthkey() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(0644), modTime: time.Unix(1560062905, 0)} + info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(0644), modTime: time.Unix(1536843582, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe, 0x69, 0x23, 0x64, 0x7d, 0xf9, 0x14, 0x37, 0x6f, 0x2b, 0x1, 0xf0, 0xb0, 0xa4, 0xb2, 0xd0, 0x18, 0xcd, 0xf9, 0xeb, 0x57, 0xa3, 0xfd, 0x79, 0x25, 0xa7, 0x9c, 0x3, 0xce, 0x26, 0xec, 0xe1}} return a, nil } @@ -277,7 +277,7 @@ func keysTestAccount1StatusChainPk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account1-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "keys/test-account1-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8f, 0xba, 0x35, 0x1, 0x2b, 0x9d, 0xad, 0xf0, 0x2d, 0x3c, 0x4d, 0x6, 0xb5, 0x22, 0x2, 0x47, 0xd4, 0x1c, 0xf4, 0x31, 0x2f, 0xb, 0x5b, 0x27, 0x5d, 0x43, 0x97, 0x58, 0x2d, 0xf0, 0xe1, 0xbe}} return a, nil } @@ -297,7 +297,7 @@ func keysTestAccount1Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account1.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "keys/test-account1.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9, 0x43, 0xc2, 0xf4, 0x8c, 0xc6, 0x64, 0x25, 0x8c, 0x7, 0x8c, 0xa8, 0x89, 0x2b, 0x7b, 0x9b, 0x4f, 0x81, 0xcb, 0xce, 0x3d, 0xef, 0x82, 0x9c, 0x27, 0x27, 0xa9, 0xc5, 0x46, 0x70, 0x30, 0x38}} return a, nil } @@ -317,7 +317,7 @@ func keysTestAccount2StatusChainPk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account2-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "keys/test-account2-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9, 0xf8, 0x5c, 0xe9, 0x92, 0x96, 0x2d, 0x88, 0x2b, 0x8e, 0x42, 0x3f, 0xa4, 0x93, 0x6c, 0xad, 0xe9, 0xc0, 0x1b, 0x8a, 0x8, 0x8c, 0x5e, 0x7a, 0x84, 0xa2, 0xf, 0x9f, 0x77, 0x58, 0x2c, 0x2c}} return a, nil } @@ -337,7 +337,7 @@ func keysTestAccount2Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account2.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "keys/test-account2.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9f, 0x72, 0xd5, 0x95, 0x5c, 0x5a, 0x99, 0x9d, 0x2f, 0x21, 0x83, 0xd7, 0x10, 0x17, 0x4a, 0x3d, 0x65, 0xc9, 0x26, 0x1a, 0x2c, 0x9d, 0x65, 0x63, 0xd2, 0xa0, 0xfc, 0x7c, 0x0, 0x87, 0x38, 0x9f}} return a, nil } @@ -357,7 +357,7 @@ func keysTestAccount3BeforeEip55Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account3-before-eip55.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "keys/test-account3-before-eip55.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x81, 0x40, 0x56, 0xc1, 0x5e, 0x10, 0x6e, 0x28, 0x15, 0x3, 0x4e, 0xc4, 0xc4, 0x71, 0x4d, 0x16, 0x99, 0xcc, 0x1b, 0x63, 0xee, 0x10, 0x20, 0xe4, 0x59, 0x52, 0x3f, 0xc0, 0xad, 0x15, 0x13, 0x72}} return a, nil } diff --git a/t/bindata.go b/t/bindata.go index 661464e97c7..6b84c07728b 100644 --- a/t/bindata.go +++ b/t/bindata.go @@ -86,7 +86,7 @@ func configPublicChainAccountsJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/public-chain-accounts.json", size: 307, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "config/public-chain-accounts.json", size: 307, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x76, 0x5d, 0xc0, 0xfe, 0x57, 0x50, 0x18, 0xec, 0x2d, 0x61, 0x1b, 0xa9, 0x81, 0x11, 0x5f, 0x77, 0xf7, 0xb6, 0x67, 0x82, 0x1, 0x40, 0x68, 0x9d, 0xc5, 0x41, 0xaf, 0xce, 0x43, 0x81, 0x92, 0x96}} return a, nil } @@ -106,7 +106,7 @@ func configStatusChainAccountsJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/status-chain-accounts.json", size: 543, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "config/status-chain-accounts.json", size: 543, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8e, 0xb3, 0x61, 0x51, 0x70, 0x3c, 0x12, 0x3e, 0xf1, 0x1c, 0x81, 0xfb, 0x9a, 0x7c, 0xe3, 0x63, 0xd0, 0x8f, 0x12, 0xc5, 0x2d, 0xf4, 0xea, 0x27, 0x33, 0xef, 0xca, 0xf9, 0x3f, 0x72, 0x44, 0xbf}} return a, nil } @@ -126,7 +126,7 @@ func configTestDataJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/test-data.json", size: 84, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} + info := bindataFileInfo{name: "config/test-data.json", size: 84, mode: os.FileMode(0644), modTime: time.Unix(1573806410, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xce, 0x9d, 0x80, 0xf5, 0x87, 0xfa, 0x57, 0x1d, 0xa1, 0xd5, 0x7a, 0x10, 0x3, 0xac, 0xd7, 0xf4, 0x64, 0x32, 0x96, 0x2b, 0xb7, 0x21, 0xb7, 0xa6, 0x80, 0x40, 0xe9, 0x65, 0xe3, 0xd6, 0xbd, 0x40}} return a, nil } diff --git a/vendor/github.com/gogo/protobuf/proto/encode.go b/vendor/github.com/gogo/protobuf/proto/encode.go index 3abfed2cff0..9581ccd3042 100644 --- a/vendor/github.com/gogo/protobuf/proto/encode.go +++ b/vendor/github.com/gogo/protobuf/proto/encode.go @@ -189,6 +189,8 @@ type Marshaler interface { // prefixed by a varint-encoded length. func (p *Buffer) EncodeMessage(pb Message) error { siz := Size(pb) + sizVar := SizeVarint(uint64(siz)) + p.grow(siz + sizVar) p.EncodeVarint(uint64(siz)) return p.Marshal(pb) } diff --git a/vendor/github.com/gogo/protobuf/proto/properties.go b/vendor/github.com/gogo/protobuf/proto/properties.go index 62c55624a8a..28da1475fb3 100644 --- a/vendor/github.com/gogo/protobuf/proto/properties.go +++ b/vendor/github.com/gogo/protobuf/proto/properties.go @@ -43,7 +43,6 @@ package proto import ( "fmt" "log" - "os" "reflect" "sort" "strconv" @@ -205,7 +204,7 @@ func (p *Properties) Parse(s string) { // "bytes,49,opt,name=foo,def=hello!" fields := strings.Split(s, ",") // breaks def=, but handled below. if len(fields) < 2 { - fmt.Fprintf(os.Stderr, "proto: tag has too few fields: %q\n", s) + log.Printf("proto: tag has too few fields: %q", s) return } @@ -225,7 +224,7 @@ func (p *Properties) Parse(s string) { p.WireType = WireBytes // no numeric converter for non-numeric types default: - fmt.Fprintf(os.Stderr, "proto: tag has unknown wire type: %q\n", s) + log.Printf("proto: tag has unknown wire type: %q", s) return } diff --git a/vendor/github.com/gogo/protobuf/proto/table_marshal.go b/vendor/github.com/gogo/protobuf/proto/table_marshal.go index db9927a0c75..f8babdefab9 100644 --- a/vendor/github.com/gogo/protobuf/proto/table_marshal.go +++ b/vendor/github.com/gogo/protobuf/proto/table_marshal.go @@ -2969,7 +2969,9 @@ func (p *Buffer) Marshal(pb Message) error { if m, ok := pb.(newMarshaler); ok { siz := m.XXX_Size() p.grow(siz) // make sure buf has enough capacity - p.buf, err = m.XXX_Marshal(p.buf, p.deterministic) + pp := p.buf[len(p.buf) : len(p.buf) : len(p.buf)+siz] + pp, err = m.XXX_Marshal(pp, p.deterministic) + p.buf = append(p.buf, pp...) return err } if m, ok := pb.(Marshaler); ok { diff --git a/vendor/github.com/gogo/protobuf/proto/text.go b/vendor/github.com/gogo/protobuf/proto/text.go index 0407ba85d01..87416afe955 100644 --- a/vendor/github.com/gogo/protobuf/proto/text.go +++ b/vendor/github.com/gogo/protobuf/proto/text.go @@ -476,6 +476,8 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error { return nil } +var textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem() + // writeAny writes an arbitrary field. func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error { v = reflect.Indirect(v) @@ -589,8 +591,8 @@ func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Propert // mutating this value. v = v.Addr() } - if etm, ok := v.Interface().(encoding.TextMarshaler); ok { - text, err := etm.MarshalText() + if v.Type().Implements(textMarshalerType) { + text, err := v.Interface().(encoding.TextMarshaler).MarshalText() if err != nil { return err } diff --git a/vendor/github.com/jbenet/goprocess/ratelimit/README.md b/vendor/github.com/jbenet/goprocess/ratelimit/README.md deleted file mode 100644 index 3c91185e4eb..00000000000 --- a/vendor/github.com/jbenet/goprocess/ratelimit/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# goprocess/ratelimit - ratelimit children creation - -- goprocess: https://github.com/jbenet/goprocess -- Godoc: https://godoc.org/github.com/jbenet/goprocess/ratelimit diff --git a/vendor/github.com/jbenet/goprocess/ratelimit/ratelimit.go b/vendor/github.com/jbenet/goprocess/ratelimit/ratelimit.go deleted file mode 100644 index 1838d053745..00000000000 --- a/vendor/github.com/jbenet/goprocess/ratelimit/ratelimit.go +++ /dev/null @@ -1,68 +0,0 @@ -// Package ratelimit is part of github.com/jbenet/goprocess. -// It provides a simple process that ratelimits child creation. -// This is done internally with a channel/semaphore. -// So the call `RateLimiter.LimitedGo` may block until another -// child is Closed(). -package ratelimit - -import ( - process "github.com/jbenet/goprocess" -) - -// RateLimiter limits the spawning of children. It does so -// with an internal semaphore. Note that Go will continue -// to be the unlimited process.Process.Go, and ONLY the -// added function `RateLimiter.LimitedGo` will honor the -// limit. This is to improve readability and avoid confusion -// for the reader, particularly if code changes over time. -type RateLimiter struct { - process.Process - - limiter chan struct{} -} - -func NewRateLimiter(parent process.Process, limit int) *RateLimiter { - proc := process.WithParent(parent) - return &RateLimiter{Process: proc, limiter: LimitChan(limit)} -} - -// LimitedGo creates a new process, adds it as a child, and spawns the -// ProcessFunc f in its own goroutine, but may block according to the -// internal rate limit. It is equivalent to: -// -// func(f process.ProcessFunc) { -// <-limitch -// p.Go(func (child process.Process) { -// f(child) -// f.Close() // make sure its children close too! -// limitch<- struct{}{} -// }) -/// } -// -// It is useful to construct simple asynchronous workers, children of p, -// and rate limit their creation, to avoid spinning up too many, too fast. -// This is great for providing backpressure to producers. -func (rl *RateLimiter) LimitedGo(f process.ProcessFunc) { - - <-rl.limiter - p := rl.Go(f) - - // this <-closed() is here because the child may have spawned - // children of its own, and our rate limiter should capture that. - go func() { - <-p.Closed() - rl.limiter <- struct{}{} - }() -} - -// LimitChan returns a rate-limiting channel. it is the usual, simple, -// golang-idiomatic rate-limiting semaphore. This function merely -// initializes it with certain buffer size, and sends that many values, -// so it is ready to be used. -func LimitChan(limit int) chan struct{} { - limitch := make(chan struct{}, limit) - for i := 0; i < limit; i++ { - limitch <- struct{}{} - } - return limitch -} diff --git a/vendor/github.com/koron/go-ssdp/interface.go b/vendor/github.com/koron/go-ssdp/interface.go index 5a887131cb9..6907e378885 100644 --- a/vendor/github.com/koron/go-ssdp/interface.go +++ b/vendor/github.com/koron/go-ssdp/interface.go @@ -1,23 +1,40 @@ package ssdp -import "net" +import ( + "net" + "sync" +) // Interfaces specify target interfaces to multicast. If no interfaces are // specified, all interfaces will be used. var Interfaces []net.Interface -func interfaces() []net.Interface { - if Interfaces == nil { - Interfaces = interfacesIPv4() +var ifLock sync.Mutex +var ifList []net.Interface + +// interfaces gets list of net.Interface to multicast UDP packet. +func interfaces() ([]net.Interface, error) { + ifLock.Lock() + defer ifLock.Unlock() + if len(Interfaces) > 0 { + return Interfaces, nil + } + if len(ifList) > 0 { + return ifList, nil + } + l, err := interfacesIPv4() + if err != nil { + return nil, err } - return Interfaces + ifList = l + return ifList, nil } -func interfacesIPv4() []net.Interface { +// interfacesIPv4 lists net.Interface on IPv4. +func interfacesIPv4() ([]net.Interface, error) { iflist, err := net.Interfaces() if err != nil { - logf("failed to list interfaces: %s", err) - return make([]net.Interface, 0) + return nil, err } list := make([]net.Interface, 0, len(iflist)) for _, ifi := range iflist { @@ -26,7 +43,7 @@ func interfacesIPv4() []net.Interface { } list = append(list, ifi) } - return list + return list, nil } // hasLinkUp checks an I/F have link-up or not. diff --git a/vendor/github.com/koron/go-ssdp/multicast.go b/vendor/github.com/koron/go-ssdp/multicast.go index ac4b3020f47..7fe7f432a29 100644 --- a/vendor/github.com/koron/go-ssdp/multicast.go +++ b/vendor/github.com/koron/go-ssdp/multicast.go @@ -27,7 +27,11 @@ func multicastListen(localAddr string) (*multicastConn, error) { return nil, err } // configure socket to use with multicast. - iflist := interfaces() + iflist, err := interfaces() + if err != nil { + conn.Close() + return nil, err + } pconn, err := joinGroupIPv4(conn, iflist, ssdpAddrIPv4) if err != nil { conn.Close() diff --git a/vendor/github.com/libp2p/go-libp2p-autonat/go.mod b/vendor/github.com/libp2p/go-libp2p-autonat/go.mod index 531d4b2e0ef..9c1dfcac274 100644 --- a/vendor/github.com/libp2p/go-libp2p-autonat/go.mod +++ b/vendor/github.com/libp2p/go-libp2p-autonat/go.mod @@ -1,10 +1,12 @@ module github.com/libp2p/go-libp2p-autonat require ( - github.com/gogo/protobuf v1.2.1 + github.com/gogo/protobuf v1.3.1 github.com/ipfs/go-log v0.0.1 - github.com/libp2p/go-libp2p-blankhost v0.1.1 - github.com/libp2p/go-libp2p-core v0.0.1 - github.com/libp2p/go-libp2p-swarm v0.1.0 - github.com/multiformats/go-multiaddr v0.0.4 + github.com/libp2p/go-libp2p-blankhost v0.1.4 + github.com/libp2p/go-libp2p-core v0.2.4 + github.com/libp2p/go-libp2p-swarm v0.2.2 + github.com/multiformats/go-multiaddr v0.1.1 ) + +go 1.12 diff --git a/vendor/github.com/libp2p/go-libp2p-autonat/go.sum b/vendor/github.com/libp2p/go-libp2p-autonat/go.sum index e2d20f17f83..9f1d36cf58c 100644 --- a/vendor/github.com/libp2p/go-libp2p-autonat/go.sum +++ b/vendor/github.com/libp2p/go-libp2p-autonat/go.sum @@ -1,44 +1,73 @@ -github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= -github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= +github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= -github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE= +github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= -github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= +github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= -github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= +github.com/ipfs/go-ds-badger v0.0.5/go.mod h1:g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaHzfGTzuE3s= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= @@ -51,10 +80,14 @@ github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsj github.com/jbenet/goprocess v0.1.3 h1:YKyIEECS/XvcfHtBzxtjBBbWK+MbvA6dG8ASiqwvr10= github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -67,41 +100,52 @@ github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOS github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/libp2p/go-conn-security-multistream v0.1.0 h1:aqGmto+ttL/uJgX0JtQI0tD21CIEy5eYd1Hlp0juHY0= github.com/libp2p/go-conn-security-multistream v0.1.0/go.mod h1:aw6eD7LOsHEX7+2hJkDxw1MteijaVcI+/eP2/x3J1xc= +github.com/libp2p/go-eventbus v0.1.0 h1:mlawomSAjjkk97QnYiEmHsLu7E136+2oCWSHRUvMfzQ= +github.com/libp2p/go-eventbus v0.1.0/go.mod h1:vROgu5cs5T7cv7POWlWxBaVLxfSegC5UGQf8A2eEmx4= github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s= github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= -github.com/libp2p/go-libp2p-blankhost v0.1.1 h1:X919sCh+KLqJcNRApj43xCSiQRYqOSI88Fdf55ngf78= -github.com/libp2p/go-libp2p-blankhost v0.1.1/go.mod h1:pf2fvdLJPsC1FsVrNP3DUUvMzUts2dsLLBEpo1vW1ro= +github.com/libp2p/go-libp2p-blankhost v0.1.4 h1:I96SWjR4rK9irDHcHq3XHN6hawCRTPUADzkJacgZLvk= +github.com/libp2p/go-libp2p-blankhost v0.1.4/go.mod h1:oJF0saYsAXQCSfDq254GMNmLNz6ZTHTOvtF4ZydUvwU= github.com/libp2p/go-libp2p-core v0.0.1 h1:HSTZtFIq/W5Ue43Zw+uWZyy2Vl5WtF0zDjKN8/DT/1I= github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco= -github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ= -github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI= +github.com/libp2p/go-libp2p-core v0.0.4/go.mod h1:jyuCQP356gzfCFtRKyvAbNkyeuxb7OlyhWZ3nls5d2I= +github.com/libp2p/go-libp2p-core v0.2.0/go.mod h1:X0eyB0Gy93v0DZtSYbEM7RnMChm9Uv3j7yRXjO77xSI= +github.com/libp2p/go-libp2p-core v0.2.2/go.mod h1:8fcwTbsG2B+lTgRJ1ICZtiM5GWCWZVoVrLaDRvIRng0= +github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= +github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8= github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90= github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo= github.com/libp2p/go-libp2p-mplex v0.2.1 h1:E1xaJBQnbSiTHGI1gaBKmKhu1TUKkErKJnE8iGvirYI= github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= -github.com/libp2p/go-libp2p-peer v0.2.0 h1:EQ8kMjaCUwt/Y5uLgjT8iY2qg0mGUT0N1zUjer50DsY= -github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY= -github.com/libp2p/go-libp2p-peerstore v0.1.0 h1:MKh7pRNPHSh1fLPj8u/M/s/napdmeNpoi9BRy9lPN0E= -github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= -github.com/libp2p/go-libp2p-secio v0.1.0 h1:NNP5KLxuP97sE5Bu3iuwOWyT/dKEGMN5zSLMWdB7GTQ= -github.com/libp2p/go-libp2p-secio v0.1.0/go.mod h1:tMJo2w7h3+wN4pgU2LSYeiKPrfqBgkOsdiKK77hE7c8= -github.com/libp2p/go-libp2p-swarm v0.1.0 h1:HrFk2p0awrGEgch9JXK/qp/hfjqQfgNxpLWnCiWPg5s= -github.com/libp2p/go-libp2p-swarm v0.1.0/go.mod h1:wQVsCdjsuZoc730CgOvh5ox6K8evllckjebkdiY5ta4= +github.com/libp2p/go-libp2p-peerstore v0.1.3 h1:wMgajt1uM2tMiqf4M+4qWKVyyFc8SfA+84VV9glZq1M= +github.com/libp2p/go-libp2p-peerstore v0.1.3/go.mod h1:BJ9sHlm59/80oSkpWgr1MyY1ciXAXV397W6h1GH/uKI= +github.com/libp2p/go-libp2p-secio v0.2.0 h1:ywzZBsWEEz2KNTn5RtzauEDq5RFEefPsttXYwAWqHng= +github.com/libp2p/go-libp2p-secio v0.2.0/go.mod h1:2JdZepB8J5V9mBp79BmwsaPQhRPNN2NrnB2lKQcdy6g= +github.com/libp2p/go-libp2p-swarm v0.2.2 h1:T4hUpgEs2r371PweU3DuH7EOmBIdTBCwWs+FLcgx3bQ= +github.com/libp2p/go-libp2p-swarm v0.2.2/go.mod h1:fvmtQ0T1nErXym1/aa1uJEyN7JzaTNyBcHImCxRpPKU= github.com/libp2p/go-libp2p-testing v0.0.2/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= github.com/libp2p/go-libp2p-testing v0.0.3 h1:bdij4bKaaND7tCsaXVjRfYkMpvoOeKj9AVQGJllA6jM= github.com/libp2p/go-libp2p-testing v0.0.3/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-testing v0.0.4/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-testing v0.1.0 h1:WaFRj/t3HdMZGNZqnU2pS7pDRBmMeoDx7/HDNpeyT9U= +github.com/libp2p/go-libp2p-testing v0.1.0/go.mod h1:xaZWMJrPUM5GlDBxCeGUi7kI4eqnjVyavGroI2nxEM0= github.com/libp2p/go-libp2p-transport-upgrader v0.1.1 h1:PZMS9lhjK9VytzMCW3tWHAXtKXmlURSc3ZdvwEcKCzw= github.com/libp2p/go-libp2p-transport-upgrader v0.1.1/go.mod h1:IEtA6or8JUbsV07qPW4r01GnTenLW4oi3lOPbUMGJJA= github.com/libp2p/go-libp2p-yamux v0.2.0 h1:TSPZ5cMMz/wdoYsye/wU1TE4G3LDGMoeEN0xgnCKU/I= github.com/libp2p/go-libp2p-yamux v0.2.0/go.mod h1:Db2gU+XfLpm6E4rG5uGCFX6uXA8MEXOxFcRoXUODaK8= github.com/libp2p/go-maddr-filter v0.0.4 h1:hx8HIuuwk34KePddrp2mM5ivgPkZ09JH4AvsALRbFUs= github.com/libp2p/go-maddr-filter v0.0.4/go.mod h1:6eT12kSQMA9x2pvFQa+xesMKUBlj9VImZbj3B9FBH/Q= +github.com/libp2p/go-maddr-filter v0.0.5 h1:CW3AgbMO6vUvT4kf87y4N+0P8KUl2aqLYhrGyDUbLSg= +github.com/libp2p/go-maddr-filter v0.0.5/go.mod h1:Jk+36PMfIqCJhAnaASRH83bdAvfDRp/w6ENFaC9bG+M= github.com/libp2p/go-mplex v0.0.3/go.mod h1:pK5yMLmOoBR1pNCqDlA2GQrdAVTMkqFalaTWe7l4Yd0= github.com/libp2p/go-mplex v0.1.0 h1:/nBTy5+1yRyY82YaO6HXQRnO5IAGsXTjEJaR3LdTPc0= github.com/libp2p/go-mplex v0.1.0/go.mod h1:SXgmdki2kwCUlCCbfGLEgHjC4pFqhTp0ZoV6aiKgxDU= -github.com/libp2p/go-msgio v0.0.2 h1:ivPvEKHxmVkTClHzg6RXTYHqaJQ0V9cDbq+6lKb3UV0= -github.com/libp2p/go-msgio v0.0.2/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA= +github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-openssl v0.0.2/go.mod h1:v8Zw2ijCSWBQi8Pq5GAixw6DbFfa9u6VIYDXnvOXkc0= +github.com/libp2p/go-openssl v0.0.3 h1:wjlG7HvQkt4Fq4cfH33Ivpwp0omaElYEi9z26qaIkIk= +github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw= github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA= github.com/libp2p/go-reuseport-transport v0.0.2 h1:WglMwyXyBu61CMkjCCtnmqNqnjib0GIEjMiHTwR/KN4= @@ -109,14 +153,20 @@ github.com/libp2p/go-reuseport-transport v0.0.2/go.mod h1:YkbSDrvjUVDL6b8XqriyA2 github.com/libp2p/go-stream-muxer v0.0.1/go.mod h1:bAo8x7YkSpadMTbtTaxGVHWUQsR/l5MEaHbKaliuT14= github.com/libp2p/go-stream-muxer-multistream v0.2.0 h1:714bRJ4Zy9mdhyTLJ+ZKiROmAFwUHpeRidG+q7LTQOg= github.com/libp2p/go-stream-muxer-multistream v0.2.0/go.mod h1:j9eyPol/LLRqT+GPLSxvimPhNph4sfYfMoDPd7HkzIc= -github.com/libp2p/go-tcp-transport v0.1.0 h1:IGhowvEqyMFknOar4FWCKSWE0zL36UFKQtiRQD60/8o= -github.com/libp2p/go-tcp-transport v0.1.0/go.mod h1:oJ8I5VXryj493DEJ7OsBieu8fcg2nHGctwtInJVpipc= +github.com/libp2p/go-tcp-transport v0.1.1 h1:yGlqURmqgNA2fvzjSgZNlHcsd/IulAnKM8Ncu+vlqnw= +github.com/libp2p/go-tcp-transport v0.1.1/go.mod h1:3HzGvLbx6etZjnFlERyakbaYPdfjg2pWP97dFZworkY= github.com/libp2p/go-yamux v1.2.2 h1:s6J6o7+ajoQMjHe7BEnq+EynOj5D2EoG8CuQgL3F2vg= github.com/libp2p/go-yamux v1.2.2/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ= @@ -124,6 +174,11 @@ github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+ github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8KM= github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= +github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.1 h1:OJIdWOWYe2l5PQNgimGtuwHY8nDskvJ5vvs//YnzRLs= github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= @@ -134,18 +189,23 @@ github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lg github.com/multiformats/go-multiaddr v0.0.2/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= github.com/multiformats/go-multiaddr v0.0.4 h1:WgMSI84/eRLdbptXMkMWDXPjPq7SPLIgGUVm2eroyU4= github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multiaddr v0.1.0/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multiaddr v0.1.1 h1:rVAztJYMhCQ7vEFr8FvxW3mS+HF2eY/oPbOMeS0ZDnE= +github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= -github.com/multiformats/go-multiaddr-dns v0.0.2 h1:/Bbsgsy3R6e3jf2qBahzNHzww6usYaZ0NhNH3sqdFS8= -github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= -github.com/multiformats/go-multiaddr-fmt v0.0.1 h1:5YjeOIzbX8OTKVaN72aOzGIYW7PnrZrnkDyOfAWRSMA= -github.com/multiformats/go-multiaddr-fmt v0.0.1/go.mod h1:aBYjqL4T/7j4Qx+R73XSv/8JsgnRFlf0w2KGLCmXl3Q= +github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= +github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi/ek0E4eiDVbg9g= github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= +github.com/multiformats/go-multiaddr-net v0.1.0 h1:ZepO8Ezwovd+7b5XPPDhQhayk1yt0AJpzQBpq9fejx4= +github.com/multiformats/go-multiaddr-net v0.1.0/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po= +github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= +github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multistream v0.1.0 h1:UpO6jrsjqs46mqAK3n6wKRYFhugss9ArzbyUzU+4wkQ= github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -157,20 +217,35 @@ github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smola/gocompat v0.2.0 h1:6b1oIMlUXIpz//VKEDzPVBK8KG7beVwmHIUEBIs/Pns= +github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= @@ -178,22 +253,47 @@ github.com/whyrusleeping/mafmt v1.2.8 h1:TCghSl5kkwEE0j+sU/gudyhVMRlpBin8fMBBHg5 github.com/whyrusleeping/mafmt v1.2.8/go.mod h1:faQJFPbLSxzD9xpA02ttW/tS9vZykNvXwGvqIpk20FA= github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 h1:E9S12nwJwEOXe2d6gT6qxdvqMnNq+VnSsKPgm2ZZNds= github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7/go.mod h1:X2c0RVCI1eSUFI8eLcY3c0423ykwiUdxLJtkDvruhjI= +github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.1 h1:8dP3SGL7MPB94crU3bEPplMPe83FI4EouesJUeFHv50= +go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b h1:+/WWzjwW6gidDJnMKWLKLX1gxn7irUTF1fLpQovfQ5M= golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= -golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190227160552-c95aed5357e7 h1:C2F/nMkR/9sfUTpvR3QrjBuTdvMUC/cFajkphs1YLQo= golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= @@ -201,16 +301,39 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/src-d/go-cli.v0 v0.0.0-20181105080154-d492247bbc0d/go.mod h1:z+K8VcOYVYcSwSjGebuDL6176A1XskgbtNl64NSg+n8= +gopkg.in/src-d/go-log.v1 v1.0.1/go.mod h1:GN34hKP0g305ysm2/hctJ0Y8nWP3zxXXJ8GFabTyABE= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.pb.go b/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.pb.go index 3617b4615ac..b176cb99e05 100644 --- a/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.pb.go +++ b/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.pb.go @@ -8,6 +8,7 @@ import ( proto "github.com/gogo/protobuf/proto" io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -19,7 +20,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Message_MessageType int32 @@ -133,7 +134,7 @@ func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Message.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -195,7 +196,7 @@ func (m *Message_PeerInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return xxx_messageInfo_Message_PeerInfo.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -249,7 +250,7 @@ func (m *Message_Dial) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return xxx_messageInfo_Message_Dial.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -298,7 +299,7 @@ func (m *Message_DialResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte return xxx_messageInfo_Message_DialResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -380,7 +381,7 @@ var fileDescriptor_a04e278ef61ac07a = []byte{ func (m *Message) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -388,45 +389,55 @@ func (m *Message) Marshal() (dAtA []byte, err error) { } func (m *Message) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Type != nil { - dAtA[i] = 0x8 - i++ - i = encodeVarintAutonat(dAtA, i, uint64(*m.Type)) - } - if m.Dial != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintAutonat(dAtA, i, uint64(m.Dial.Size())) - n1, err := m.Dial.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) } if m.DialResponse != nil { + { + size, err := m.DialResponse.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAutonat(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0x1a - i++ - i = encodeVarintAutonat(dAtA, i, uint64(m.DialResponse.Size())) - n2, err := m.DialResponse.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + } + if m.Dial != nil { + { + size, err := m.Dial.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAutonat(dAtA, i, uint64(size)) } - i += n2 + i-- + dAtA[i] = 0x12 } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if m.Type != nil { + i = encodeVarintAutonat(dAtA, i, uint64(*m.Type)) + i-- + dAtA[i] = 0x8 } - return i, nil + return len(dAtA) - i, nil } func (m *Message_PeerInfo) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -434,34 +445,42 @@ func (m *Message_PeerInfo) Marshal() (dAtA []byte, err error) { } func (m *Message_PeerInfo) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_PeerInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Id != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintAutonat(dAtA, i, uint64(len(m.Id))) - i += copy(dAtA[i:], m.Id) + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) } if len(m.Addrs) > 0 { - for _, b := range m.Addrs { + for iNdEx := len(m.Addrs) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addrs[iNdEx]) + copy(dAtA[i:], m.Addrs[iNdEx]) + i = encodeVarintAutonat(dAtA, i, uint64(len(m.Addrs[iNdEx]))) + i-- dAtA[i] = 0x12 - i++ - i = encodeVarintAutonat(dAtA, i, uint64(len(b))) - i += copy(dAtA[i:], b) } } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if m.Id != nil { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintAutonat(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func (m *Message_Dial) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -469,30 +488,38 @@ func (m *Message_Dial) Marshal() (dAtA []byte, err error) { } func (m *Message_Dial) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_Dial) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } if m.Peer != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintAutonat(dAtA, i, uint64(m.Peer.Size())) - n3, err := m.Peer.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + { + size, err := m.Peer.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAutonat(dAtA, i, uint64(size)) } - i += n3 - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func (m *Message_DialResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -500,41 +527,51 @@ func (m *Message_DialResponse) Marshal() (dAtA []byte, err error) { } func (m *Message_DialResponse) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_DialResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Status != nil { - dAtA[i] = 0x8 - i++ - i = encodeVarintAutonat(dAtA, i, uint64(*m.Status)) - } - if m.StatusText != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintAutonat(dAtA, i, uint64(len(*m.StatusText))) - i += copy(dAtA[i:], *m.StatusText) + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) } if m.Addr != nil { - dAtA[i] = 0x1a - i++ + i -= len(m.Addr) + copy(dAtA[i:], m.Addr) i = encodeVarintAutonat(dAtA, i, uint64(len(m.Addr))) - i += copy(dAtA[i:], m.Addr) + i-- + dAtA[i] = 0x1a } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if m.StatusText != nil { + i -= len(*m.StatusText) + copy(dAtA[i:], *m.StatusText) + i = encodeVarintAutonat(dAtA, i, uint64(len(*m.StatusText))) + i-- + dAtA[i] = 0x12 } - return i, nil + if m.Status != nil { + i = encodeVarintAutonat(dAtA, i, uint64(*m.Status)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func encodeVarintAutonat(dAtA []byte, offset int, v uint64) int { + offset -= sovAutonat(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *Message) Size() (n int) { if m == nil { @@ -621,14 +658,7 @@ func (m *Message_DialResponse) Size() (n int) { } func sovAutonat(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozAutonat(x uint64) (n int) { return sovAutonat(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -1133,6 +1163,7 @@ func (m *Message_DialResponse) Unmarshal(dAtA []byte) error { func skipAutonat(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -1164,10 +1195,8 @@ func skipAutonat(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -1191,52 +1220,27 @@ func skipAutonat(dAtA []byte) (n int, err error) { if iNdEx < 0 { return 0, ErrInvalidLengthAutonat } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowAutonat - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipAutonat(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthAutonat - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAutonat + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthAutonat = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowAutonat = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthAutonat = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAutonat = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAutonat = fmt.Errorf("proto: unexpected end of group") ) diff --git a/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.proto b/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.proto index 7107e1c07f4..777270a1397 100644 --- a/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.proto +++ b/vendor/github.com/libp2p/go-libp2p-autonat/pb/autonat.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package autonat.pb; message Message { diff --git a/vendor/github.com/libp2p/go-libp2p-circuit/go.mod b/vendor/github.com/libp2p/go-libp2p-circuit/go.mod index 8fbc25d6740..d13cd8ce643 100644 --- a/vendor/github.com/libp2p/go-libp2p-circuit/go.mod +++ b/vendor/github.com/libp2p/go-libp2p-circuit/go.mod @@ -1,15 +1,15 @@ module github.com/libp2p/go-libp2p-circuit require ( - github.com/gogo/protobuf v1.2.1 + github.com/gogo/protobuf v1.3.1 github.com/ipfs/go-log v0.0.1 github.com/libp2p/go-buffer-pool v0.0.2 github.com/libp2p/go-libp2p-blankhost v0.1.4 - github.com/libp2p/go-libp2p-core v0.2.2 + github.com/libp2p/go-libp2p-core v0.2.4 github.com/libp2p/go-libp2p-swarm v0.2.2 github.com/libp2p/go-libp2p-transport-upgrader v0.1.1 github.com/multiformats/go-multiaddr v0.1.1 - github.com/multiformats/go-multiaddr-net v0.1.0 + github.com/multiformats/go-multiaddr-net v0.1.1 ) go 1.12 diff --git a/vendor/github.com/libp2p/go-libp2p-circuit/go.sum b/vendor/github.com/libp2p/go-libp2p-circuit/go.sum index fa7c30496dc..9b0c219eb31 100644 --- a/vendor/github.com/libp2p/go-libp2p-circuit/go.sum +++ b/vendor/github.com/libp2p/go-libp2p-circuit/go.sum @@ -7,6 +7,8 @@ github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS3 github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c h1:aEbSeNALREWXk0G7UdNhR3ayBV7tZ4M2PNmnrCAph6Q= github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= @@ -35,7 +37,12 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= @@ -43,6 +50,8 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= @@ -56,6 +65,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= github.com/ipfs/go-ds-badger v0.0.5/go.mod h1:g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaHzfGTzuE3s= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= @@ -73,6 +83,7 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -100,6 +111,8 @@ github.com/libp2p/go-libp2p-core v0.0.4/go.mod h1:jyuCQP356gzfCFtRKyvAbNkyeuxb7O github.com/libp2p/go-libp2p-core v0.2.0/go.mod h1:X0eyB0Gy93v0DZtSYbEM7RnMChm9Uv3j7yRXjO77xSI= github.com/libp2p/go-libp2p-core v0.2.2 h1:Sv1ggdoMx9c7v7FOFkR7agraHCnAgqYsXrU1ARSRUMs= github.com/libp2p/go-libp2p-core v0.2.2/go.mod h1:8fcwTbsG2B+lTgRJ1ICZtiM5GWCWZVoVrLaDRvIRng0= +github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= +github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8= github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90= github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo= @@ -132,6 +145,8 @@ github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-openssl v0.0.2 h1:9pP2d3Ubaxkv7ZisLjx9BFwgOGnQdQYnfcH29HNY3ls= github.com/libp2p/go-openssl v0.0.2/go.mod h1:v8Zw2ijCSWBQi8Pq5GAixw6DbFfa9u6VIYDXnvOXkc0= +github.com/libp2p/go-openssl v0.0.3 h1:wjlG7HvQkt4Fq4cfH33Ivpwp0omaElYEi9z26qaIkIk= +github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw= github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA= github.com/libp2p/go-reuseport-transport v0.0.2 h1:WglMwyXyBu61CMkjCCtnmqNqnjib0GIEjMiHTwR/KN4= @@ -144,6 +159,7 @@ github.com/libp2p/go-tcp-transport v0.1.1/go.mod h1:3HzGvLbx6etZjnFlERyakbaYPdfj github.com/libp2p/go-yamux v1.2.2 h1:s6J6o7+ajoQMjHe7BEnq+EynOj5D2EoG8CuQgL3F2vg= github.com/libp2p/go-yamux v1.2.2/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= @@ -160,6 +176,8 @@ github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8 github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= +github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= @@ -182,6 +200,8 @@ github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= github.com/multiformats/go-multiaddr-net v0.1.0 h1:ZepO8Ezwovd+7b5XPPDhQhayk1yt0AJpzQBpq9fejx4= github.com/multiformats/go-multiaddr-net v0.1.0/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= +github.com/multiformats/go-multiaddr-net v0.1.1 h1:jFFKUuXTXv+3ARyHZi3XUqQO+YWMKgBdhEvuGRfnL6s= +github.com/multiformats/go-multiaddr-net v0.1.1/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= @@ -206,6 +226,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smola/gocompat v0.2.0 h1:6b1oIMlUXIpz//VKEDzPVBK8KG7beVwmHIUEBIs/Pns= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= @@ -238,6 +259,8 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7V github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.1 h1:8dP3SGL7MPB94crU3bEPplMPe83FI4EouesJUeFHv50= +go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -248,9 +271,12 @@ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 h1:IcSOAf4PyMp3U3XbIEj1/xJ2BjNN2jWv7JoyOsMxXUU= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -277,19 +303,28 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/vendor/github.com/libp2p/go-libp2p-circuit/pb/relay.pb.go b/vendor/github.com/libp2p/go-libp2p-circuit/pb/relay.pb.go index ca165ee60d8..66703f15aa3 100644 --- a/vendor/github.com/libp2p/go-libp2p-circuit/pb/relay.pb.go +++ b/vendor/github.com/libp2p/go-libp2p-circuit/pb/relay.pb.go @@ -9,6 +9,7 @@ import ( proto "github.com/gogo/protobuf/proto" io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -20,7 +21,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type CircuitRelay_Status int32 @@ -174,7 +175,7 @@ func (m *CircuitRelay) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return xxx_messageInfo_CircuitRelay.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -243,7 +244,7 @@ func (m *CircuitRelay_Peer) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return xxx_messageInfo_CircuitRelay_Peer.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -322,7 +323,7 @@ var fileDescriptor_9f69a7d5a802d584 = []byte{ func (m *CircuitRelay) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -330,50 +331,60 @@ func (m *CircuitRelay) Marshal() (dAtA []byte, err error) { } func (m *CircuitRelay) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CircuitRelay) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Type != nil { - dAtA[i] = 0x8 - i++ - i = encodeVarintRelay(dAtA, i, uint64(*m.Type)) + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) } - if m.SrcPeer != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintRelay(dAtA, i, uint64(m.SrcPeer.Size())) - n1, err := m.SrcPeer.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 + if m.Code != nil { + i = encodeVarintRelay(dAtA, i, uint64(*m.Code)) + i-- + dAtA[i] = 0x20 } if m.DstPeer != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintRelay(dAtA, i, uint64(m.DstPeer.Size())) - n2, err := m.DstPeer.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + { + size, err := m.DstPeer.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRelay(dAtA, i, uint64(size)) } - i += n2 + i-- + dAtA[i] = 0x1a } - if m.Code != nil { - dAtA[i] = 0x20 - i++ - i = encodeVarintRelay(dAtA, i, uint64(*m.Code)) + if m.SrcPeer != nil { + { + size, err := m.SrcPeer.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRelay(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if m.Type != nil { + i = encodeVarintRelay(dAtA, i, uint64(*m.Type)) + i-- + dAtA[i] = 0x8 } - return i, nil + return len(dAtA) - i, nil } func (m *CircuitRelay_Peer) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -381,40 +392,50 @@ func (m *CircuitRelay_Peer) Marshal() (dAtA []byte, err error) { } func (m *CircuitRelay_Peer) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CircuitRelay_Peer) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Id == nil { - return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("id") - } else { - dAtA[i] = 0xa - i++ - i = encodeVarintRelay(dAtA, i, uint64(len(m.Id))) - i += copy(dAtA[i:], m.Id) + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) } if len(m.Addrs) > 0 { - for _, b := range m.Addrs { + for iNdEx := len(m.Addrs) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addrs[iNdEx]) + copy(dAtA[i:], m.Addrs[iNdEx]) + i = encodeVarintRelay(dAtA, i, uint64(len(m.Addrs[iNdEx]))) + i-- dAtA[i] = 0x12 - i++ - i = encodeVarintRelay(dAtA, i, uint64(len(b))) - i += copy(dAtA[i:], b) } } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if m.Id == nil { + return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("id") + } else { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintRelay(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func encodeVarintRelay(dAtA []byte, offset int, v uint64) int { + offset -= sovRelay(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *CircuitRelay) Size() (n int) { if m == nil { @@ -465,14 +486,7 @@ func (m *CircuitRelay_Peer) Size() (n int) { } func sovRelay(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozRelay(x uint64) (n int) { return sovRelay(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -771,6 +785,7 @@ func (m *CircuitRelay_Peer) Unmarshal(dAtA []byte) error { func skipRelay(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -802,10 +817,8 @@ func skipRelay(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -829,52 +842,27 @@ func skipRelay(dAtA []byte) (n int, err error) { if iNdEx < 0 { return 0, ErrInvalidLengthRelay } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRelay - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRelay(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthRelay - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupRelay + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthRelay = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRelay = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthRelay = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowRelay = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupRelay = fmt.Errorf("proto: unexpected end of group") ) diff --git a/vendor/github.com/libp2p/go-libp2p-core/crypto/ed25519.go b/vendor/github.com/libp2p/go-libp2p-core/crypto/ed25519.go index 231dadb0358..ceb3483798b 100644 --- a/vendor/github.com/libp2p/go-libp2p-core/crypto/ed25519.go +++ b/vendor/github.com/libp2p/go-libp2p-core/crypto/ed25519.go @@ -68,7 +68,7 @@ func (k *Ed25519PrivateKey) pubKeyBytes() []byte { func (k *Ed25519PrivateKey) Equals(o Key) bool { edk, ok := o.(*Ed25519PrivateKey) if !ok { - return false + return basicEquals(k, o) } return subtle.ConstantTimeCompare(k.k, edk.k) == 1 @@ -103,7 +103,7 @@ func (k *Ed25519PublicKey) Raw() ([]byte, error) { func (k *Ed25519PublicKey) Equals(o Key) bool { edk, ok := o.(*Ed25519PublicKey) if !ok { - return false + return basicEquals(k, o) } return bytes.Equal(k.k, edk.k) diff --git a/vendor/github.com/libp2p/go-libp2p-core/crypto/key.go b/vendor/github.com/libp2p/go-libp2p-core/crypto/key.go index 6cd9dc0beb9..bdb6f089b56 100644 --- a/vendor/github.com/libp2p/go-libp2p-core/crypto/key.go +++ b/vendor/github.com/libp2p/go-libp2p-core/crypto/key.go @@ -181,6 +181,8 @@ type StretchedKeys struct { CipherKey []byte } +// PENDING DEPRECATION: KeyStretcher() will be deprecated with secio; for new +// code, please use PBKDF2 (golang.org/x/crypto/pbkdf2) instead. // KeyStretcher returns a set of keys for each party by stretching the shared key. // (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey). // This function accepts the following cipher types: diff --git a/vendor/github.com/libp2p/go-libp2p-core/crypto/key_not_openssl.go b/vendor/github.com/libp2p/go-libp2p-core/crypto/key_not_openssl.go new file mode 100644 index 00000000000..ae8b01f00b8 --- /dev/null +++ b/vendor/github.com/libp2p/go-libp2p-core/crypto/key_not_openssl.go @@ -0,0 +1,40 @@ +// +build !openssl + +package crypto + +import ( + "crypto" + "crypto/ecdsa" + "crypto/rsa" + + btcec "github.com/btcsuite/btcd/btcec" + "golang.org/x/crypto/ed25519" +) + +// KeyPairFromStdKey wraps standard library (and secp256k1) private keys in libp2p/go-libp2p-core/crypto keys +func KeyPairFromStdKey(priv crypto.PrivateKey) (PrivKey, PubKey, error) { + if priv == nil { + return nil, nil, ErrNilPrivateKey + } + + switch p := priv.(type) { + case *rsa.PrivateKey: + return &RsaPrivateKey{*p}, &RsaPublicKey{p.PublicKey}, nil + + case *ecdsa.PrivateKey: + return &ECDSAPrivateKey{p}, &ECDSAPublicKey{&p.PublicKey}, nil + + case *ed25519.PrivateKey: + pubIfc := p.Public() + pub, _ := pubIfc.(ed25519.PublicKey) + return &Ed25519PrivateKey{*p}, &Ed25519PublicKey{pub}, nil + + case *btcec.PrivateKey: + sPriv := Secp256k1PrivateKey(*p) + sPub := Secp256k1PublicKey(*p.PubKey()) + return &sPriv, &sPub, nil + + default: + return nil, nil, ErrBadKeyType + } +} diff --git a/vendor/github.com/libp2p/go-libp2p-core/crypto/key_openssl.go b/vendor/github.com/libp2p/go-libp2p-core/crypto/key_openssl.go new file mode 100644 index 00000000000..4545492cf36 --- /dev/null +++ b/vendor/github.com/libp2p/go-libp2p-core/crypto/key_openssl.go @@ -0,0 +1,47 @@ +// +build openssl + +package crypto + +import ( + "crypto" + "crypto/ecdsa" + "crypto/rsa" + "crypto/x509" + + btcec "github.com/btcsuite/btcd/btcec" + openssl "github.com/libp2p/go-openssl" + "golang.org/x/crypto/ed25519" +) + +// KeyPairFromStdKey wraps standard library (and secp256k1) private keys in libp2p/go-libp2p-core/crypto keys +func KeyPairFromStdKey(priv crypto.PrivateKey) (PrivKey, PubKey, error) { + if priv == nil { + return nil, nil, ErrNilPrivateKey + } + + switch p := priv.(type) { + case *rsa.PrivateKey: + pk, err := openssl.LoadPrivateKeyFromDER(x509.MarshalPKCS1PrivateKey(p)) + if err != nil { + return nil, nil, err + } + + return &opensslPrivateKey{pk}, &opensslPublicKey{pk}, nil + + case *ecdsa.PrivateKey: + return &ECDSAPrivateKey{p}, &ECDSAPublicKey{&p.PublicKey}, nil + + case *ed25519.PrivateKey: + pubIfc := p.Public() + pub, _ := pubIfc.(ed25519.PublicKey) + return &Ed25519PrivateKey{*p}, &Ed25519PublicKey{pub}, nil + + case *btcec.PrivateKey: + sPriv := Secp256k1PrivateKey(*p) + sPub := Secp256k1PublicKey(*p.PubKey()) + return &sPriv, &sPub, nil + + default: + return nil, nil, ErrBadKeyType + } +} diff --git a/vendor/github.com/libp2p/go-libp2p-core/crypto/rsa_openssl.go b/vendor/github.com/libp2p/go-libp2p-core/crypto/rsa_openssl.go index fd9d4510439..9b7a3423457 100644 --- a/vendor/github.com/libp2p/go-libp2p-core/crypto/rsa_openssl.go +++ b/vendor/github.com/libp2p/go-libp2p-core/crypto/rsa_openssl.go @@ -43,6 +43,9 @@ func UnmarshalRsaPrivateKey(b []byte) (PrivKey, error) { if err != nil { return nil, err } + if 8*key.key.Size() < MinRsaKeyBits { + return nil, ErrRsaKeyTooSmall + } if key.Type() != RSA { return nil, errors.New("not actually an rsa public key") } @@ -55,6 +58,9 @@ func UnmarshalRsaPublicKey(b []byte) (PubKey, error) { if err != nil { return nil, err } + if 8*key.key.Size() < MinRsaKeyBits { + return nil, ErrRsaKeyTooSmall + } if key.Type() != RSA { return nil, errors.New("not actually an rsa public key") } diff --git a/vendor/github.com/libp2p/go-libp2p-nat/go.mod b/vendor/github.com/libp2p/go-libp2p-nat/go.mod index e43298be05f..0b433995c0f 100644 --- a/vendor/github.com/libp2p/go-libp2p-nat/go.mod +++ b/vendor/github.com/libp2p/go-libp2p-nat/go.mod @@ -4,6 +4,7 @@ require ( github.com/ipfs/go-log v0.0.1 github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec // indirect github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 - github.com/libp2p/go-nat v0.0.3 - github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f + github.com/libp2p/go-nat v0.0.4 ) + +go 1.13 diff --git a/vendor/github.com/libp2p/go-libp2p-nat/go.sum b/vendor/github.com/libp2p/go-libp2p-nat/go.sum index 39da03d4a55..22a35c947f1 100644 --- a/vendor/github.com/libp2p/go-libp2p-nat/go.sum +++ b/vendor/github.com/libp2p/go-libp2p-nat/go.sum @@ -17,10 +17,10 @@ github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5f github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= -github.com/libp2p/go-nat v0.0.3 h1:l6fKV+p0Xa354EqQOQP+d8CivdLM4kl5GxC1hSc/UeI= -github.com/libp2p/go-nat v0.0.3/go.mod h1:88nUEt0k0JD45Bk93NIwDqjlhiOwOoV36GchpcVc1yI= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/libp2p/go-nat v0.0.4 h1:KbizNnq8YIf7+Hn7+VFL/xE0eDrkPru2zIO9NMwL8UQ= +github.com/libp2p/go-nat v0.0.4/go.mod h1:Nmw50VAvKuk38jUBcmNh6p9lUJLoODbJRvYAa/+KSDo= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= @@ -34,8 +34,6 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= -github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f h1:M/lL30eFZTKnomXY6huvM6G0+gVquFNf6mxghaWlFUg= -github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f/go.mod h1:cZNvX9cFybI01GriPRMXDtczuvUhgbcYr9iCGaNlRv8= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190227160552-c95aed5357e7 h1:C2F/nMkR/9sfUTpvR3QrjBuTdvMUC/cFajkphs1YLQo= golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/vendor/github.com/libp2p/go-libp2p-nat/nat.go b/vendor/github.com/libp2p/go-libp2p-nat/nat.go index 178f7d01401..cdddaeaec50 100644 --- a/vendor/github.com/libp2p/go-libp2p-nat/nat.go +++ b/vendor/github.com/libp2p/go-libp2p-nat/nat.go @@ -74,8 +74,6 @@ type NAT struct { mappingmu sync.RWMutex // guards mappings mappings map[*mapping]struct{} - - Notifier } func newNAT(realNAT nat.NAT) *NAT { @@ -186,25 +184,14 @@ func (nat *NAT) establishMapping(m *mapping) { m.setExternalPort(0) // clear mapping // TODO: log.Event log.Warningf("failed to establish port mapping: %s", err) - nat.Notifier.notifyAll(func(n Notifiee) { - n.MappingFailed(nat, m, oldport, err) - }) - // we do not close if the mapping failed, // because it may work again next time. return } m.setExternalPort(newport) - log.Debugf("NAT Mapping: %s --> %s (%s)", m.ExternalPort(), m.InternalPort(), m.Protocol()) + log.Debugf("NAT Mapping: %d --> %d (%s)", m.ExternalPort(), m.InternalPort(), m.Protocol()) if oldport != 0 && newport != oldport { log.Debugf("failed to renew same port mapping: ch %d -> %d", oldport, newport) - nat.Notifier.notifyAll(func(n Notifiee) { - n.MappingChanged(nat, m, oldport, newport) - }) } - - nat.Notifier.notifyAll(func(n Notifiee) { - n.MappingSuccess(nat, m) - }) } diff --git a/vendor/github.com/libp2p/go-libp2p-nat/notifier.go b/vendor/github.com/libp2p/go-libp2p-nat/notifier.go deleted file mode 100644 index 10fb6ac6bf4..00000000000 --- a/vendor/github.com/libp2p/go-libp2p-nat/notifier.go +++ /dev/null @@ -1,47 +0,0 @@ -package nat - -import ( - notifier "github.com/whyrusleeping/go-notifier" -) - -// Notifier is an object that assists NAT in notifying listeners. -// It is implemented using thirdparty/notifier -type Notifier struct { - n notifier.Notifier -} - -func (n *Notifier) notifyAll(notify func(n Notifiee)) { - n.n.NotifyAll(func(n notifier.Notifiee) { - notify(n.(Notifiee)) - }) -} - -// Notify signs up notifiee to listen to NAT events. -func (n *Notifier) Notify(notifiee Notifiee) { - n.n.Notify(n) -} - -// StopNotify stops signaling events to notifiee. -func (n *Notifier) StopNotify(notifiee Notifiee) { - n.n.StopNotify(notifiee) -} - -// Notifiee is an interface objects must implement to listen to NAT events. -type Notifiee interface { - - // Called every time a successful mapping happens - // Warning: the port mapping may have changed. If that is the - // case, both MappingSuccess and MappingChanged are called. - MappingSuccess(nat *NAT, m Mapping) - - // Called when mapping a port succeeds, but the mapping is - // with a different port than an earlier success. - MappingChanged(nat *NAT, m Mapping, oldport, newport int) - - // Called when a port mapping fails. NAT will continue attempting after - // the next period. To stop trying, use: mapping.Close(). After this failure, - // mapping.ExternalPort() will be zero, and nat.ExternalAddrs() will not - // return the address for this mapping. With luck, the next attempt will - // succeed, without the client needing to do anything. - MappingFailed(nat *NAT, m Mapping, oldport int, err error) -} diff --git a/vendor/github.com/libp2p/go-libp2p-peerstore/addr/sorting.go b/vendor/github.com/libp2p/go-libp2p-peerstore/addr/sorting.go index f8a89150a2a..5c7c6c3a3d7 100644 --- a/vendor/github.com/libp2p/go-libp2p-peerstore/addr/sorting.go +++ b/vendor/github.com/libp2p/go-libp2p-peerstore/addr/sorting.go @@ -4,8 +4,8 @@ import ( "bytes" ma "github.com/multiformats/go-multiaddr" + mafmt "github.com/multiformats/go-multiaddr-fmt" manet "github.com/multiformats/go-multiaddr-net" - mafmt "github.com/whyrusleeping/mafmt" ) func isFDCostlyTransport(a ma.Multiaddr) bool { diff --git a/vendor/github.com/libp2p/go-libp2p-peerstore/go.mod b/vendor/github.com/libp2p/go-libp2p-peerstore/go.mod index 65e64f44373..6979c9f1bd0 100644 --- a/vendor/github.com/libp2p/go-libp2p-peerstore/go.mod +++ b/vendor/github.com/libp2p/go-libp2p-peerstore/go.mod @@ -1,19 +1,21 @@ module github.com/libp2p/go-libp2p-peerstore require ( - github.com/gogo/protobuf v1.2.1 + github.com/gogo/protobuf v1.3.1 github.com/hashicorp/golang-lru v0.5.1 - github.com/ipfs/go-datastore v0.0.1 - github.com/ipfs/go-ds-badger v0.0.5 - github.com/ipfs/go-ds-leveldb v0.0.1 + github.com/ipfs/go-datastore v0.1.1 + github.com/ipfs/go-ds-badger v0.0.7 + github.com/ipfs/go-ds-leveldb v0.1.0 github.com/ipfs/go-log v0.0.1 - github.com/libp2p/go-buffer-pool v0.0.1 - github.com/libp2p/go-libp2p-core v0.0.4 + github.com/libp2p/go-buffer-pool v0.0.2 + github.com/libp2p/go-libp2p-core v0.2.4 github.com/multiformats/go-base32 v0.0.3 - github.com/multiformats/go-multiaddr v0.0.4 - github.com/multiformats/go-multiaddr-net v0.0.1 - github.com/multiformats/go-multihash v0.0.5 + github.com/multiformats/go-multiaddr v0.1.1 + github.com/multiformats/go-multiaddr-fmt v0.1.0 + github.com/multiformats/go-multiaddr-net v0.1.1 + github.com/multiformats/go-multihash v0.0.8 github.com/pkg/errors v0.8.1 github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 - github.com/whyrusleeping/mafmt v1.2.8 ) + +go 1.13 diff --git a/vendor/github.com/libp2p/go-libp2p-peerstore/go.sum b/vendor/github.com/libp2p/go-libp2p-peerstore/go.sum index d2caeb049f1..57c3c5ad26e 100644 --- a/vendor/github.com/libp2p/go-libp2p-peerstore/go.sum +++ b/vendor/github.com/libp2p/go-libp2p-peerstore/go.sum @@ -1,10 +1,11 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 h1:HD8gA2tkByhMAwYaFAX9w2l7vxvBQ5NMoxDrkhqhtn4= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c h1:aEbSeNALREWXk0G7UdNhR3ayBV7tZ4M2PNmnrCAph6Q= -github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= @@ -12,6 +13,7 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -22,8 +24,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgraph-io/badger v1.6.0-rc1 h1:JphPpoBZJ3WHha133BGYlQqltSGIhV+VsEID0++nN9A= -github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= +github.com/dgraph-io/badger v1.6.0 h1:DshxFxZWXUcO0xX476VJC07Xsr6ZCBVRHKZ93Oh7Evo= +github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -34,11 +36,18 @@ github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJY github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU= @@ -51,13 +60,14 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= -github.com/ipfs/go-datastore v0.0.1 h1:AW/KZCScnBWlSb5JbnEnLKFWXL224LBEh/9KXXOrUms= -github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= -github.com/ipfs/go-ds-badger v0.0.5 h1:dxKuqw5T1Jm8OuV+lchA76H9QZFyPKZeLuT6bN42hJQ= -github.com/ipfs/go-ds-badger v0.0.5/go.mod h1:g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaHzfGTzuE3s= -github.com/ipfs/go-ds-leveldb v0.0.1 h1:Z0lsTFciec9qYsyngAw1f/czhRU35qBLR2vhavPFgqA= -github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= +github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-datastore v0.1.1 h1:F4k0TkTAZGLFzBOrVKDAvch6JZtuN4NHkfdcEZL50aI= +github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= +github.com/ipfs/go-ds-badger v0.0.7 h1:NMyh88Q50HG6/S2YD58DLkq0c0/ZQPMbSojONH+PRf4= +github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9YlmAvpQBk= +github.com/ipfs/go-ds-leveldb v0.1.0 h1:OsCuIIh1LMTk4WIQ1UJH7e3j01qlOP+KWVhNS6lBDZY= +github.com/ipfs/go-ds-leveldb v0.1.0/go.mod h1:hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= @@ -67,10 +77,14 @@ github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsj github.com/jbenet/goprocess v0.1.3 h1:YKyIEECS/XvcfHtBzxtjBBbWK+MbvA6dG8ASiqwvr10= github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -78,21 +92,31 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/libp2p/go-buffer-pool v0.0.1 h1:9Rrn/H46cXjaA2HQ5Y8lyhOS1NhTkZ4yuEs2r3Eechg= github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= +github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs= +github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= -github.com/libp2p/go-libp2p-core v0.0.4 h1:wNg7b2tKrZlSNibP+j7A1v8eatjf4+9+YRw0L3DUeFE= -github.com/libp2p/go-libp2p-core v0.0.4/go.mod h1:jyuCQP356gzfCFtRKyvAbNkyeuxb7OlyhWZ3nls5d2I= +github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= +github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= +github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-openssl v0.0.3 h1:wjlG7HvQkt4Fq4cfH33Ivpwp0omaElYEi9z26qaIkIk= +github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= -github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= -github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8KM= -github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= +github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= @@ -100,18 +124,18 @@ github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= -github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= -github.com/multiformats/go-multiaddr v0.0.4 h1:WgMSI84/eRLdbptXMkMWDXPjPq7SPLIgGUVm2eroyU4= -github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= -github.com/multiformats/go-multiaddr-dns v0.0.1 h1:jQt9c6tDSdQLIlBo4tXYx7QUHCPjxsB1zXcag/2S7zc= -github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= -github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi/ek0E4eiDVbg9g= -github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= +github.com/multiformats/go-multiaddr v0.1.0/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multiaddr v0.1.1 h1:rVAztJYMhCQ7vEFr8FvxW3mS+HF2eY/oPbOMeS0ZDnE= +github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= +github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= +github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= +github.com/multiformats/go-multiaddr-net v0.1.1 h1:jFFKUuXTXv+3ARyHZi3XUqQO+YWMKgBdhEvuGRfnL6s= +github.com/multiformats/go-multiaddr-net v0.1.1/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= -github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= -github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po= +github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= +github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -125,8 +149,9 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= -github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smola/gocompat v0.2.0 h1:6b1oIMlUXIpz//VKEDzPVBK8KG7beVwmHIUEBIs/Pns= +github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= @@ -137,7 +162,9 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -148,25 +175,39 @@ github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdz github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= -github.com/whyrusleeping/mafmt v1.2.8 h1:TCghSl5kkwEE0j+sU/gudyhVMRlpBin8fMBBHg59EbA= -github.com/whyrusleeping/mafmt v1.2.8/go.mod h1:faQJFPbLSxzD9xpA02ttW/tS9vZykNvXwGvqIpk20FA= +github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 h1:IcSOAf4PyMp3U3XbIEj1/xJ2BjNN2jWv7JoyOsMxXUU= -golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190227160552-c95aed5357e7 h1:C2F/nMkR/9sfUTpvR3QrjBuTdvMUC/cFajkphs1YLQo= golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -175,19 +216,39 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpbl golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/src-d/go-cli.v0 v0.0.0-20181105080154-d492247bbc0d/go.mod h1:z+K8VcOYVYcSwSjGebuDL6176A1XskgbtNl64NSg+n8= +gopkg.in/src-d/go-log.v1 v1.0.1/go.mod h1:GN34hKP0g305ysm2/hctJ0Y8nWP3zxXXJ8GFabTyABE= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/github.com/libp2p/go-libp2p-secio/go.mod b/vendor/github.com/libp2p/go-libp2p-secio/go.mod index babe1ec660e..493170cb4ad 100644 --- a/vendor/github.com/libp2p/go-libp2p-secio/go.mod +++ b/vendor/github.com/libp2p/go-libp2p-secio/go.mod @@ -3,12 +3,12 @@ module github.com/libp2p/go-libp2p-secio go 1.12 require ( - github.com/gogo/protobuf v1.2.1 + github.com/gogo/protobuf v1.3.1 github.com/ipfs/go-log v0.0.1 github.com/libp2p/go-buffer-pool v0.0.2 - github.com/libp2p/go-libp2p-core v0.2.0 + github.com/libp2p/go-libp2p-core v0.2.4 github.com/libp2p/go-libp2p-testing v0.0.2 github.com/libp2p/go-msgio v0.0.4 - github.com/minio/sha256-simd v0.1.0 - github.com/multiformats/go-multihash v0.0.5 + github.com/minio/sha256-simd v0.1.1 + github.com/multiformats/go-multihash v0.0.8 ) diff --git a/vendor/github.com/libp2p/go-libp2p-secio/go.sum b/vendor/github.com/libp2p/go-libp2p-secio/go.sum index 25d596b9884..b1ca45da6b1 100644 --- a/vendor/github.com/libp2p/go-libp2p-secio/go.sum +++ b/vendor/github.com/libp2p/go-libp2p-secio/go.sum @@ -3,8 +3,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= -github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c h1:aEbSeNALREWXk0G7UdNhR3ayBV7tZ4M2PNmnrCAph6Q= -github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= @@ -23,18 +23,23 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE= +github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= -github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= @@ -47,6 +52,7 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -60,12 +66,15 @@ github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoR github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= github.com/libp2p/go-libp2p-core v0.0.1 h1:HSTZtFIq/W5Ue43Zw+uWZyy2Vl5WtF0zDjKN8/DT/1I= github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco= -github.com/libp2p/go-libp2p-core v0.2.0 h1:ycFtuNwtZBAJSxzaHbyv6NjG3Yj5Nmra1csHaQ3zwaw= -github.com/libp2p/go-libp2p-core v0.2.0/go.mod h1:X0eyB0Gy93v0DZtSYbEM7RnMChm9Uv3j7yRXjO77xSI= +github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= +github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= github.com/libp2p/go-libp2p-testing v0.0.2 h1:p9ySW7MFvGGs83hAAe0MPGnjy/tPjl5KyxpMkojdZ+g= github.com/libp2p/go-libp2p-testing v0.0.2/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-openssl v0.0.3 h1:wjlG7HvQkt4Fq4cfH33Ivpwp0omaElYEi9z26qaIkIk= +github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= @@ -78,9 +87,9 @@ github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0 github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= -github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= -github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8KM= -github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= +github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.1 h1:OJIdWOWYe2l5PQNgimGtuwHY8nDskvJ5vvs//YnzRLs= @@ -90,13 +99,13 @@ github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjW github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-multiaddr v0.0.2 h1:RBysRCv5rv3FWlhKWKoXv8tnsCUpEpIZpCmqAGZos2s= github.com/multiformats/go-multiaddr v0.0.2/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= -github.com/multiformats/go-multiaddr v0.0.4 h1:WgMSI84/eRLdbptXMkMWDXPjPq7SPLIgGUVm2eroyU4= -github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multiaddr v0.1.1 h1:rVAztJYMhCQ7vEFr8FvxW3mS+HF2eY/oPbOMeS0ZDnE= +github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= -github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= -github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po= +github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= +github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -105,6 +114,7 @@ github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smola/gocompat v0.2.0 h1:6b1oIMlUXIpz//VKEDzPVBK8KG7beVwmHIUEBIs/Pns= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= @@ -121,18 +131,19 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 h1:IcSOAf4PyMp3U3XbIEj1/xJ2BjNN2jWv7JoyOsMxXUU= -golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -142,6 +153,8 @@ golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -155,16 +168,25 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpbl golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/vendor/github.com/libp2p/go-libp2p-secio/pb/spipe.pb.go b/vendor/github.com/libp2p/go-libp2p-secio/pb/spipe.pb.go index 0f3236e2c8c..8e66ebe9eb3 100644 --- a/vendor/github.com/libp2p/go-libp2p-secio/pb/spipe.pb.go +++ b/vendor/github.com/libp2p/go-libp2p-secio/pb/spipe.pb.go @@ -8,6 +8,7 @@ import ( proto "github.com/gogo/protobuf/proto" io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -19,7 +20,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Propose struct { Rand []byte `protobuf:"bytes,1,opt,name=rand" json:"rand"` @@ -43,7 +44,7 @@ func (m *Propose) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Propose.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -116,7 +117,7 @@ func (m *Exchange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Exchange.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -176,7 +177,7 @@ var fileDescriptor_c474ec75f0379e64 = []byte{ func (m *Propose) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -184,41 +185,51 @@ func (m *Propose) Marshal() (dAtA []byte, err error) { } func (m *Propose) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Propose) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Rand != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintSpipe(dAtA, i, uint64(len(m.Rand))) - i += copy(dAtA[i:], m.Rand) - } + i -= len(m.Hashes) + copy(dAtA[i:], m.Hashes) + i = encodeVarintSpipe(dAtA, i, uint64(len(m.Hashes))) + i-- + dAtA[i] = 0x2a + i -= len(m.Ciphers) + copy(dAtA[i:], m.Ciphers) + i = encodeVarintSpipe(dAtA, i, uint64(len(m.Ciphers))) + i-- + dAtA[i] = 0x22 + i -= len(m.Exchanges) + copy(dAtA[i:], m.Exchanges) + i = encodeVarintSpipe(dAtA, i, uint64(len(m.Exchanges))) + i-- + dAtA[i] = 0x1a if m.Pubkey != nil { - dAtA[i] = 0x12 - i++ + i -= len(m.Pubkey) + copy(dAtA[i:], m.Pubkey) i = encodeVarintSpipe(dAtA, i, uint64(len(m.Pubkey))) - i += copy(dAtA[i:], m.Pubkey) + i-- + dAtA[i] = 0x12 } - dAtA[i] = 0x1a - i++ - i = encodeVarintSpipe(dAtA, i, uint64(len(m.Exchanges))) - i += copy(dAtA[i:], m.Exchanges) - dAtA[i] = 0x22 - i++ - i = encodeVarintSpipe(dAtA, i, uint64(len(m.Ciphers))) - i += copy(dAtA[i:], m.Ciphers) - dAtA[i] = 0x2a - i++ - i = encodeVarintSpipe(dAtA, i, uint64(len(m.Hashes))) - i += copy(dAtA[i:], m.Hashes) - return i, nil + if m.Rand != nil { + i -= len(m.Rand) + copy(dAtA[i:], m.Rand) + i = encodeVarintSpipe(dAtA, i, uint64(len(m.Rand))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } func (m *Exchange) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -226,33 +237,42 @@ func (m *Exchange) Marshal() (dAtA []byte, err error) { } func (m *Exchange) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Exchange) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Epubkey != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintSpipe(dAtA, i, uint64(len(m.Epubkey))) - i += copy(dAtA[i:], m.Epubkey) - } if m.Signature != nil { - dAtA[i] = 0x12 - i++ + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) i = encodeVarintSpipe(dAtA, i, uint64(len(m.Signature))) - i += copy(dAtA[i:], m.Signature) + i-- + dAtA[i] = 0x12 + } + if m.Epubkey != nil { + i -= len(m.Epubkey) + copy(dAtA[i:], m.Epubkey) + i = encodeVarintSpipe(dAtA, i, uint64(len(m.Epubkey))) + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func encodeVarintSpipe(dAtA []byte, offset int, v uint64) int { + offset -= sovSpipe(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *Propose) Size() (n int) { if m == nil { @@ -295,14 +315,7 @@ func (m *Exchange) Size() (n int) { } func sovSpipe(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozSpipe(x uint64) (n int) { return sovSpipe(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -648,6 +661,7 @@ func (m *Exchange) Unmarshal(dAtA []byte) error { func skipSpipe(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -679,10 +693,8 @@ func skipSpipe(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -703,55 +715,30 @@ func skipSpipe(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthSpipe } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthSpipe - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSpipe - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipSpipe(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthSpipe - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSpipe + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthSpipe + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthSpipe = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSpipe = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthSpipe = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSpipe = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSpipe = fmt.Errorf("proto: unexpected end of group") ) diff --git a/vendor/github.com/libp2p/go-libp2p/README.md b/vendor/github.com/libp2p/go-libp2p/README.md index a066cd5794f..318b75230e8 100644 --- a/vendor/github.com/libp2p/go-libp2p/README.md +++ b/vendor/github.com/libp2p/go-libp2p/README.md @@ -40,7 +40,7 @@ [libp2p](https://github.com/libp2p/specs) is a networking stack and library modularized out of [The IPFS Project](https://github.com/ipfs/ipfs), and bundled separately for other tools to use. > -libp2p is the product of a long, and arduous quest of understanding -- a deep dive into the internet's network stack, and plentiful peer-to-peer protocols from the past. Building large scale peer-to-peer systems has been complex and difficult in the last 15 years, and libp2p is a way to fix that. It is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects. +libp2p is the product of a long, and arduous quest of understanding -- a deep dive into the internet's network stack, and plentiful peer-to-peer protocols from the past. Building large-scale peer-to-peer systems has been complex and difficult in the last 15 years, and libp2p is a way to fix that. It is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects. > > We will be writing a set of docs, posts, tutorials, and talks to explain what p2p is, why it is tremendously useful, and how it can help your existing and new projects. But in the meantime, check out > @@ -63,7 +63,13 @@ You can start using go-libp2p in your Go application simply by adding imports fr import "github.com/libp2p/go-libp2p" ``` -The next time you run `go get` or `go build`, the Go build tools will look for [available releases](https://github.com/libp2p/go-libp2p/releases), and will pick the highest available one. +Run `go get` or `go build`, excluding the libp2p repos from Go modules proxy usage. You only need to do this the first time you import go-libp2p to make sure you latch onto the correct version lineage (see [golang/go#34189](https://github.com/golang/go/issues/34189) for context): + +```sh +$ GOPRIVATE='github.com/libp2p/*' go get ./... +``` + +The Go build tools will look for [available releases](https://github.com/libp2p/go-libp2p/releases), and will pick the highest available one. As new releases of go-libp2p are made available, you can upgrade your application by manually editing your `go.mod` file, or using the [Go tools](https://golang.org/cmd/go/#hdr-Maintaining_module_requirements) to maintain module requirements. @@ -81,7 +87,7 @@ Examples can be found in the [examples repo](https://github.com/libp2p/go-libp2p While developing, you may need to make changes to several modules at once, or you may want changes made locally in one module to be available for import by another. -The [go libp2p workspace](https://github.com/libp2p/workspace-go-libp2p) provides a developer-oriented view of the modules that comprise go-libp2p. +The [go-libp2p workspace](https://github.com/libp2p/workspace-go-libp2p) provides a developer-oriented view of the modules that comprise go-libp2p. Using the tooling in the workspace repository, you can checkout all of go-libp2p's module repos and enter "local mode", which adds [replace directives](https://github.com/golang/go/wiki/Modules#gomod) to the go.mod files in each local working copy. When you build locally, the libp2p depdendencies will be resolved from your local working copies. @@ -197,17 +203,17 @@ List of packages currently in existence for libp2p: # Contribute -go-libp2p is part of [The IPFS Project](https://github.com/ipfs/ipfs), and is MIT licensed open source software. We welcome contributions big and small! Take a look at the [community contributing notes](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md). Please make sure to check the [issues](https://github.com/ipfs/go-libp2p/issues). Search the closed ones before reporting things, and help us with the open ones. +go-libp2p is part of [The IPFS Project](https://github.com/ipfs/ipfs), and is MIT-licensed open source software. We welcome contributions big and small! Take a look at the [community contributing notes](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md). Please make sure to check the [issues](https://github.com/ipfs/go-libp2p/issues). Search the closed ones before reporting things, and help us with the open ones. Guidelines: - read the [libp2p spec](https://github.com/libp2p/specs) - please make branches + pull-request, even if working on the main repository -- ask questions or talk about things in [Issues](https://github.com/libp2p/go-libp2p/issues), our [discussion forums](https://discuss.libp2p.io), or #libp2p or #ipfs on freenode. -- ensure you are able to contribute (no legal issues please-- we use the DCO) +- ask questions or talk about things in [issues](https://github.com/libp2p/go-libp2p/issues), our [discussion forums](https://discuss.libp2p.io), or #libp2p or #ipfs on freenode. +- ensure you are able to contribute (no legal issues please -- we use the DCO) - run `go fmt` before pushing any code - run `golint` and `go vet` too -- some things (like protobuf files) are expected to fail. -- get in touch with @jbenet and @diasdavid about how best to contribute +- get in touch with @raulk and @mgoelzer about how best to contribute - have fun! There's a few things you can do right now to help out: diff --git a/vendor/github.com/libp2p/go-libp2p/go.mod b/vendor/github.com/libp2p/go-libp2p/go.mod index 5f909db5445..159a13fdcd1 100644 --- a/vendor/github.com/libp2p/go-libp2p/go.mod +++ b/vendor/github.com/libp2p/go-libp2p/go.mod @@ -1,7 +1,7 @@ module github.com/libp2p/go-libp2p require ( - github.com/gogo/protobuf v1.3.0 + github.com/gogo/protobuf v1.3.1 github.com/ipfs/go-cid v0.0.3 github.com/ipfs/go-detect-race v0.0.1 github.com/ipfs/go-ipfs-util v0.0.1 @@ -10,17 +10,17 @@ require ( github.com/jbenet/goprocess v0.1.3 github.com/libp2p/go-conn-security-multistream v0.1.0 github.com/libp2p/go-eventbus v0.1.0 - github.com/libp2p/go-libp2p-autonat v0.1.0 + github.com/libp2p/go-libp2p-autonat v0.1.1 github.com/libp2p/go-libp2p-blankhost v0.1.4 - github.com/libp2p/go-libp2p-circuit v0.1.3 - github.com/libp2p/go-libp2p-core v0.2.3 + github.com/libp2p/go-libp2p-circuit v0.1.4 + github.com/libp2p/go-libp2p-core v0.2.4 github.com/libp2p/go-libp2p-discovery v0.1.0 github.com/libp2p/go-libp2p-loggables v0.1.0 github.com/libp2p/go-libp2p-mplex v0.2.1 - github.com/libp2p/go-libp2p-nat v0.0.4 + github.com/libp2p/go-libp2p-nat v0.0.5 github.com/libp2p/go-libp2p-netutil v0.1.0 - github.com/libp2p/go-libp2p-peerstore v0.1.3 - github.com/libp2p/go-libp2p-secio v0.2.0 + github.com/libp2p/go-libp2p-peerstore v0.1.4 + github.com/libp2p/go-libp2p-secio v0.2.1 github.com/libp2p/go-libp2p-swarm v0.2.2 github.com/libp2p/go-libp2p-testing v0.1.0 github.com/libp2p/go-libp2p-transport-upgrader v0.1.1 @@ -31,10 +31,11 @@ require ( github.com/libp2p/go-ws-transport v0.1.2 github.com/miekg/dns v1.1.12 // indirect github.com/multiformats/go-multiaddr v0.1.1 - github.com/multiformats/go-multiaddr-dns v0.1.0 - github.com/multiformats/go-multiaddr-net v0.1.0 + github.com/multiformats/go-multiaddr-dns v0.2.0 + github.com/multiformats/go-multiaddr-net v0.1.1 github.com/multiformats/go-multistream v0.1.0 github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9 + golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 // indirect ) go 1.12 diff --git a/vendor/github.com/libp2p/go-libp2p/go.sum b/vendor/github.com/libp2p/go-libp2p/go.sum index 90200587e2f..bbb95c31bb3 100644 --- a/vendor/github.com/libp2p/go-libp2p/go.sum +++ b/vendor/github.com/libp2p/go-libp2p/go.sum @@ -31,6 +31,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= +github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -41,6 +42,8 @@ github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE= github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -76,11 +79,15 @@ github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUP github.com/ipfs/go-cid v0.0.3 h1:UIAh32wymBpStoe83YCzwVQQ5Oy/H0FdxvUS6DJDzms= github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= github.com/ipfs/go-ds-badger v0.0.5/go.mod h1:g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaHzfGTzuE3s= +github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9YlmAvpQBk= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= +github.com/ipfs/go-ds-leveldb v0.1.0/go.mod h1:hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50= github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= @@ -107,8 +114,8 @@ github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQL github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -125,21 +132,21 @@ github.com/libp2p/go-eventbus v0.1.0 h1:mlawomSAjjkk97QnYiEmHsLu7E136+2oCWSHRUvM github.com/libp2p/go-eventbus v0.1.0/go.mod h1:vROgu5cs5T7cv7POWlWxBaVLxfSegC5UGQf8A2eEmx4= github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s= github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= -github.com/libp2p/go-libp2p-autonat v0.1.0 h1:aCWAu43Ri4nU0ZPO7NyLzUvvfqd0nE3dX0R/ZGYVgOU= -github.com/libp2p/go-libp2p-autonat v0.1.0/go.mod h1:1tLf2yXxiE/oKGtDwPYWTSYG3PtvYlJmg7NeVtPRqH8= +github.com/libp2p/go-libp2p-autonat v0.1.1 h1:WLBZcIRsjZlWdAZj9CiBSvU2wQXoUOiS1Zk1tM7DTJI= +github.com/libp2p/go-libp2p-autonat v0.1.1/go.mod h1:OXqkeGOY2xJVWKAGV2inNF5aKN/djNA3fdpCWloIudE= github.com/libp2p/go-libp2p-blankhost v0.1.1/go.mod h1:pf2fvdLJPsC1FsVrNP3DUUvMzUts2dsLLBEpo1vW1ro= github.com/libp2p/go-libp2p-blankhost v0.1.4 h1:I96SWjR4rK9irDHcHq3XHN6hawCRTPUADzkJacgZLvk= github.com/libp2p/go-libp2p-blankhost v0.1.4/go.mod h1:oJF0saYsAXQCSfDq254GMNmLNz6ZTHTOvtF4ZydUvwU= -github.com/libp2p/go-libp2p-circuit v0.1.3 h1:WsMYYaA0PwdpgJSQu12EzPYf5ypkLSTgcOsWr7DYrgI= -github.com/libp2p/go-libp2p-circuit v0.1.3/go.mod h1:Xqh2TjSy8DD5iV2cCOMzdynd6h8OTBGoV1AWbWor3qM= +github.com/libp2p/go-libp2p-circuit v0.1.4 h1:Phzbmrg3BkVzbqd4ZZ149JxCuUWu2wZcXf/Kr6hZJj8= +github.com/libp2p/go-libp2p-circuit v0.1.4/go.mod h1:CY67BrEjKNDhdTk8UgBX1Y/H5c3xkAcs3gnksxY7osU= github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco= github.com/libp2p/go-libp2p-core v0.0.4/go.mod h1:jyuCQP356gzfCFtRKyvAbNkyeuxb7OlyhWZ3nls5d2I= github.com/libp2p/go-libp2p-core v0.2.0 h1:ycFtuNwtZBAJSxzaHbyv6NjG3Yj5Nmra1csHaQ3zwaw= github.com/libp2p/go-libp2p-core v0.2.0/go.mod h1:X0eyB0Gy93v0DZtSYbEM7RnMChm9Uv3j7yRXjO77xSI= github.com/libp2p/go-libp2p-core v0.2.2 h1:Sv1ggdoMx9c7v7FOFkR7agraHCnAgqYsXrU1ARSRUMs= github.com/libp2p/go-libp2p-core v0.2.2/go.mod h1:8fcwTbsG2B+lTgRJ1ICZtiM5GWCWZVoVrLaDRvIRng0= -github.com/libp2p/go-libp2p-core v0.2.3 h1:zXikZ5pLfebtTMeIYfcwVQ2Pae77O0FIwDquwM6AGNM= -github.com/libp2p/go-libp2p-core v0.2.3/go.mod h1:GqhyQqyIAPsxFYXHMjfXgMv03lxsvM0mFzuYA9Ib42A= +github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= +github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI= github.com/libp2p/go-libp2p-discovery v0.1.0 h1:j+R6cokKcGbnZLf4kcNwpx6mDEUPF3N6SrqMymQhmvs= github.com/libp2p/go-libp2p-discovery v0.1.0/go.mod h1:4F/x+aldVHjHDHuX85x1zWoFTGElt8HnoDzwkFZm29g= @@ -148,18 +155,22 @@ github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3x github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo= github.com/libp2p/go-libp2p-mplex v0.2.1 h1:E1xaJBQnbSiTHGI1gaBKmKhu1TUKkErKJnE8iGvirYI= github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= -github.com/libp2p/go-libp2p-nat v0.0.4 h1:+KXK324yaY701On8a0aGjTnw8467kW3ExKcqW2wwmyw= -github.com/libp2p/go-libp2p-nat v0.0.4/go.mod h1:N9Js/zVtAXqaeT99cXgTV9e75KpnWCvVOiGzlcHmBbY= +github.com/libp2p/go-libp2p-nat v0.0.5 h1:/mH8pXFVKleflDL1YwqMg27W9GD8kjEx7NY0P6eGc98= +github.com/libp2p/go-libp2p-nat v0.0.5/go.mod h1:1qubaE5bTZMJE+E/uu2URroMbzdubFz1ChgiN79yKPE= github.com/libp2p/go-libp2p-netutil v0.1.0 h1:zscYDNVEcGxyUpMd0JReUZTrpMfia8PmLKcKF72EAMQ= github.com/libp2p/go-libp2p-netutil v0.1.0/go.mod h1:3Qv/aDqtMLTUyQeundkKsA+YCThNdbQD54k3TqjpbFU= github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY= github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= github.com/libp2p/go-libp2p-peerstore v0.1.3 h1:wMgajt1uM2tMiqf4M+4qWKVyyFc8SfA+84VV9glZq1M= github.com/libp2p/go-libp2p-peerstore v0.1.3/go.mod h1:BJ9sHlm59/80oSkpWgr1MyY1ciXAXV397W6h1GH/uKI= +github.com/libp2p/go-libp2p-peerstore v0.1.4 h1:d23fvq5oYMJ/lkkbO4oTwBp/JP+I/1m5gZJobNXCE/k= +github.com/libp2p/go-libp2p-peerstore v0.1.4/go.mod h1:+4BDbDiiKf4PzpANZDAT+knVdLxvqh7hXOujessqdzs= github.com/libp2p/go-libp2p-secio v0.1.0 h1:NNP5KLxuP97sE5Bu3iuwOWyT/dKEGMN5zSLMWdB7GTQ= github.com/libp2p/go-libp2p-secio v0.1.0/go.mod h1:tMJo2w7h3+wN4pgU2LSYeiKPrfqBgkOsdiKK77hE7c8= github.com/libp2p/go-libp2p-secio v0.2.0 h1:ywzZBsWEEz2KNTn5RtzauEDq5RFEefPsttXYwAWqHng= github.com/libp2p/go-libp2p-secio v0.2.0/go.mod h1:2JdZepB8J5V9mBp79BmwsaPQhRPNN2NrnB2lKQcdy6g= +github.com/libp2p/go-libp2p-secio v0.2.1 h1:eNWbJTdyPA7NxhP7J3c5lT97DC5d+u+IldkgCYFTPVA= +github.com/libp2p/go-libp2p-secio v0.2.1/go.mod h1:cWtZpILJqkqrSkiYcDBh5lA3wbT2Q+hz3rJQq3iftD8= github.com/libp2p/go-libp2p-swarm v0.1.0/go.mod h1:wQVsCdjsuZoc730CgOvh5ox6K8evllckjebkdiY5ta4= github.com/libp2p/go-libp2p-swarm v0.2.2 h1:T4hUpgEs2r371PweU3DuH7EOmBIdTBCwWs+FLcgx3bQ= github.com/libp2p/go-libp2p-swarm v0.2.2/go.mod h1:fvmtQ0T1nErXym1/aa1uJEyN7JzaTNyBcHImCxRpPKU= @@ -184,10 +195,12 @@ github.com/libp2p/go-msgio v0.0.2 h1:ivPvEKHxmVkTClHzg6RXTYHqaJQ0V9cDbq+6lKb3UV0 github.com/libp2p/go-msgio v0.0.2/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= -github.com/libp2p/go-nat v0.0.3 h1:l6fKV+p0Xa354EqQOQP+d8CivdLM4kl5GxC1hSc/UeI= -github.com/libp2p/go-nat v0.0.3/go.mod h1:88nUEt0k0JD45Bk93NIwDqjlhiOwOoV36GchpcVc1yI= +github.com/libp2p/go-nat v0.0.4 h1:KbizNnq8YIf7+Hn7+VFL/xE0eDrkPru2zIO9NMwL8UQ= +github.com/libp2p/go-nat v0.0.4/go.mod h1:Nmw50VAvKuk38jUBcmNh6p9lUJLoODbJRvYAa/+KSDo= github.com/libp2p/go-openssl v0.0.2 h1:9pP2d3Ubaxkv7ZisLjx9BFwgOGnQdQYnfcH29HNY3ls= github.com/libp2p/go-openssl v0.0.2/go.mod h1:v8Zw2ijCSWBQi8Pq5GAixw6DbFfa9u6VIYDXnvOXkc0= +github.com/libp2p/go-openssl v0.0.3 h1:wjlG7HvQkt4Fq4cfH33Ivpwp0omaElYEi9z26qaIkIk= +github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw= github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA= github.com/libp2p/go-reuseport-transport v0.0.2 h1:WglMwyXyBu61CMkjCCtnmqNqnjib0GIEjMiHTwR/KN4= @@ -244,8 +257,8 @@ github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= github.com/multiformats/go-multiaddr-dns v0.0.2 h1:/Bbsgsy3R6e3jf2qBahzNHzww6usYaZ0NhNH3sqdFS8= github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= -github.com/multiformats/go-multiaddr-dns v0.1.0 h1:gsPeMvo91XvcsNlQXgJgfjYjbsVV99bvveguUvDBpyQ= -github.com/multiformats/go-multiaddr-dns v0.1.0/go.mod h1:01k2RAqtoXIuPa3DCavAE9/6jc6nM0H3EgZyfUhN2oY= +github.com/multiformats/go-multiaddr-dns v0.2.0 h1:YWJoIDwLePniH7OU5hBnDZV6SWuvJqJ0YtN6pLeH9zA= +github.com/multiformats/go-multiaddr-dns v0.2.0/go.mod h1:TJ5pr5bBO7Y1B18djPuRsVkduhQH2YqYSbxWJzYGdK0= github.com/multiformats/go-multiaddr-fmt v0.0.1 h1:5YjeOIzbX8OTKVaN72aOzGIYW7PnrZrnkDyOfAWRSMA= github.com/multiformats/go-multiaddr-fmt v0.0.1/go.mod h1:aBYjqL4T/7j4Qx+R73XSv/8JsgnRFlf0w2KGLCmXl3Q= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= @@ -254,6 +267,8 @@ github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= github.com/multiformats/go-multiaddr-net v0.1.0 h1:ZepO8Ezwovd+7b5XPPDhQhayk1yt0AJpzQBpq9fejx4= github.com/multiformats/go-multiaddr-net v0.1.0/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= +github.com/multiformats/go-multiaddr-net v0.1.1 h1:jFFKUuXTXv+3ARyHZi3XUqQO+YWMKgBdhEvuGRfnL6s= +github.com/multiformats/go-multiaddr-net v0.1.1/go.mod h1:5JNbcfBOP4dnhoZOv10JJVkJO0pCCEf8mTnipAo2UZQ= github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= @@ -304,8 +319,6 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= -github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f h1:M/lL30eFZTKnomXY6huvM6G0+gVquFNf6mxghaWlFUg= -github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f/go.mod h1:cZNvX9cFybI01GriPRMXDtczuvUhgbcYr9iCGaNlRv8= github.com/whyrusleeping/mafmt v1.2.8 h1:TCghSl5kkwEE0j+sU/gudyhVMRlpBin8fMBBHg59EbA= github.com/whyrusleeping/mafmt v1.2.8/go.mod h1:faQJFPbLSxzD9xpA02ttW/tS9vZykNvXwGvqIpk20FA= github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9 h1:Y1/FEOpaCpD21WxrmfeIYCFPuVPRCY2XZTWzTNHGw30= @@ -329,8 +342,8 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 h1:IcSOAf4PyMp3U3XbIEj1/xJ2BjNN2jWv7JoyOsMxXUU= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -377,6 +390,7 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c h1:vamGzbGri8IKo20MQncCulj golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= diff --git a/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/obsaddr.go b/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/obsaddr.go index 12e22860dcb..d9e3318dd74 100644 --- a/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/obsaddr.go +++ b/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/obsaddr.go @@ -11,10 +11,23 @@ import ( ma "github.com/multiformats/go-multiaddr" ) -const ActivationThresh = 4 - +// ActivationThresh sets how many times an address must be seen as "activated" +// and therefore advertised to other peers as an address that the local peer +// can be contacted on. The "seen" events expire by default after 40 minutes +// (OwnObservedAddressTTL * ActivationThreshold). The are cleaned up during +// the GC rounds set by GCInterval. +var ActivationThresh = 4 + +// GCInterval specicies how often to make a round cleaning seen events and +// observed addresses. An address will be cleaned if it has not been seen in +// OwnObservedAddressTTL (10 minutes). A "seen" event will be cleaned up if +// it is older than OwnObservedAddressTTL * ActivationThresh (40 minutes). var GCInterval = 10 * time.Minute +// observedAddrSetWorkerChannelSize defines how many addresses can be enqueued +// for adding to an ObservedAddrSet. +var observedAddrSetWorkerChannelSize = 16 + type observation struct { seenTime time.Time connDirection network.Direction @@ -22,8 +35,8 @@ type observation struct { // ObservedAddr is an entry for an address reported by our peers. // We only use addresses that: -// - have been observed at least 4 times in last 1h. (counter symmetric nats) -// - have been observed at least once recently (1h), because our position in the +// - have been observed at least 4 times in last 40 minutes. (counter symmetric nats) +// - have been observed at least once recently (10 minutes), because our position in the // network, or network port mapppings, may have changed. type ObservedAddr struct { Addr ma.Multiaddr @@ -32,8 +45,9 @@ type ObservedAddr struct { } func (oa *ObservedAddr) activated(ttl time.Duration) bool { - // We only activate if in the TTL other peers observed the same address - // of ours at least 4 times. + // We only activate if other peers observed the same address + // of ours at least 4 times. SeenBy peers are removed by GC if + // they say the address more than ttl*ActivationThresh return len(oa.SeenBy) >= ActivationThresh } @@ -55,11 +69,13 @@ type ObservedAddrSet struct { wch chan newObservation } +// NewObservedAddrSet returns a new set using peerstore.OwnObservedAddressTTL +// as the TTL. func NewObservedAddrSet(ctx context.Context) *ObservedAddrSet { oas := &ObservedAddrSet{ addrs: make(map[string][]*ObservedAddr), ttl: peerstore.OwnObservedAddrTTL, - wch: make(chan newObservation, 16), + wch: make(chan newObservation, observedAddrSetWorkerChannelSize), } go oas.worker(ctx) return oas @@ -111,6 +127,7 @@ func (oas *ObservedAddrSet) Addrs() (addrs []ma.Multiaddr) { return addrs } +// Add attemps to queue a new observed address to be added to the set. func (oas *ObservedAddrSet) Add(observed, local, observer ma.Multiaddr, direction network.Direction) { select { @@ -150,7 +167,7 @@ func (oas *ObservedAddrSet) gc() { for _, a := range observedAddrs { // clean up SeenBy set for k, ob := range a.SeenBy { - if now.Sub(ob.seenTime) > oas.ttl*ActivationThresh { + if now.Sub(ob.seenTime) > oas.ttl*time.Duration(ActivationThresh) { delete(a.SeenBy, k) } } @@ -217,12 +234,14 @@ func observerGroup(m ma.Multiaddr) string { return string(first.Bytes()) } +// SetTTL sets the TTL of an observed address-set. func (oas *ObservedAddrSet) SetTTL(ttl time.Duration) { oas.Lock() defer oas.Unlock() oas.ttl = ttl } +// TTL gets the TTL of an observed address-set. func (oas *ObservedAddrSet) TTL() time.Duration { oas.RLock() defer oas.RUnlock() diff --git a/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/pb/identify.pb.go b/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/pb/identify.pb.go index 8480e5ba544..51754252928 100644 --- a/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/pb/identify.pb.go +++ b/vendor/github.com/libp2p/go-libp2p/p2p/protocol/identify/pb/identify.pb.go @@ -8,6 +8,7 @@ import ( proto "github.com/gogo/protobuf/proto" io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -19,7 +20,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Delta struct { // new protocols now serviced by the peer. @@ -45,7 +46,7 @@ func (m *Delta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Delta.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -117,7 +118,7 @@ func (m *Identify) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Identify.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -215,7 +216,7 @@ var fileDescriptor_83f1e7e6b485409f = []byte{ func (m *Delta) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -223,50 +224,44 @@ func (m *Delta) Marshal() (dAtA []byte, err error) { } func (m *Delta) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Delta) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if len(m.AddedProtocols) > 0 { - for _, s := range m.AddedProtocols { - dAtA[i] = 0xa - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) } if len(m.RmProtocols) > 0 { - for _, s := range m.RmProtocols { + for iNdEx := len(m.RmProtocols) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.RmProtocols[iNdEx]) + copy(dAtA[i:], m.RmProtocols[iNdEx]) + i = encodeVarintIdentify(dAtA, i, uint64(len(m.RmProtocols[iNdEx]))) + i-- dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) } } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if len(m.AddedProtocols) > 0 { + for iNdEx := len(m.AddedProtocols) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AddedProtocols[iNdEx]) + copy(dAtA[i:], m.AddedProtocols[iNdEx]) + i = encodeVarintIdentify(dAtA, i, uint64(len(m.AddedProtocols[iNdEx]))) + i-- + dAtA[i] = 0xa + } } - return i, nil + return len(dAtA) - i, nil } func (m *Identify) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -274,81 +269,90 @@ func (m *Identify) Marshal() (dAtA []byte, err error) { } func (m *Identify) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Identify) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.PublicKey != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintIdentify(dAtA, i, uint64(len(m.PublicKey))) - i += copy(dAtA[i:], m.PublicKey) - } - if len(m.ListenAddrs) > 0 { - for _, b := range m.ListenAddrs { - dAtA[i] = 0x12 - i++ - i = encodeVarintIdentify(dAtA, i, uint64(len(b))) - i += copy(dAtA[i:], b) - } + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) } - if len(m.Protocols) > 0 { - for _, s := range m.Protocols { - dAtA[i] = 0x1a - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) + if m.Delta != nil { + { + size, err := m.Delta.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintIdentify(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x3a } - if m.ObservedAddr != nil { - dAtA[i] = 0x22 - i++ - i = encodeVarintIdentify(dAtA, i, uint64(len(m.ObservedAddr))) - i += copy(dAtA[i:], m.ObservedAddr) + if m.AgentVersion != nil { + i -= len(*m.AgentVersion) + copy(dAtA[i:], *m.AgentVersion) + i = encodeVarintIdentify(dAtA, i, uint64(len(*m.AgentVersion))) + i-- + dAtA[i] = 0x32 } if m.ProtocolVersion != nil { - dAtA[i] = 0x2a - i++ + i -= len(*m.ProtocolVersion) + copy(dAtA[i:], *m.ProtocolVersion) i = encodeVarintIdentify(dAtA, i, uint64(len(*m.ProtocolVersion))) - i += copy(dAtA[i:], *m.ProtocolVersion) + i-- + dAtA[i] = 0x2a } - if m.AgentVersion != nil { - dAtA[i] = 0x32 - i++ - i = encodeVarintIdentify(dAtA, i, uint64(len(*m.AgentVersion))) - i += copy(dAtA[i:], *m.AgentVersion) + if m.ObservedAddr != nil { + i -= len(m.ObservedAddr) + copy(dAtA[i:], m.ObservedAddr) + i = encodeVarintIdentify(dAtA, i, uint64(len(m.ObservedAddr))) + i-- + dAtA[i] = 0x22 } - if m.Delta != nil { - dAtA[i] = 0x3a - i++ - i = encodeVarintIdentify(dAtA, i, uint64(m.Delta.Size())) - n1, err := m.Delta.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + if len(m.Protocols) > 0 { + for iNdEx := len(m.Protocols) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Protocols[iNdEx]) + copy(dAtA[i:], m.Protocols[iNdEx]) + i = encodeVarintIdentify(dAtA, i, uint64(len(m.Protocols[iNdEx]))) + i-- + dAtA[i] = 0x1a } - i += n1 } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if len(m.ListenAddrs) > 0 { + for iNdEx := len(m.ListenAddrs) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ListenAddrs[iNdEx]) + copy(dAtA[i:], m.ListenAddrs[iNdEx]) + i = encodeVarintIdentify(dAtA, i, uint64(len(m.ListenAddrs[iNdEx]))) + i-- + dAtA[i] = 0x12 + } } - return i, nil + if m.PublicKey != nil { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintIdentify(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } func encodeVarintIdentify(dAtA []byte, offset int, v uint64) int { + offset -= sovIdentify(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *Delta) Size() (n int) { if m == nil { @@ -419,14 +423,7 @@ func (m *Identify) Size() (n int) { } func sovIdentify(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozIdentify(x uint64) (n int) { return sovIdentify(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -840,6 +837,7 @@ func (m *Identify) Unmarshal(dAtA []byte) error { func skipIdentify(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -871,10 +869,8 @@ func skipIdentify(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -898,52 +894,27 @@ func skipIdentify(dAtA []byte) (n int, err error) { if iNdEx < 0 { return 0, ErrInvalidLengthIdentify } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowIdentify - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipIdentify(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthIdentify - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupIdentify + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthIdentify = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowIdentify = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthIdentify = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowIdentify = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupIdentify = fmt.Errorf("proto: unexpected end of group") ) diff --git a/vendor/github.com/libp2p/go-nat/go.mod b/vendor/github.com/libp2p/go-nat/go.mod index 718fdbdff77..a6dd7e1e419 100644 --- a/vendor/github.com/libp2p/go-nat/go.mod +++ b/vendor/github.com/libp2p/go-nat/go.mod @@ -4,5 +4,7 @@ require ( github.com/huin/goupnp v1.0.0 github.com/jackpal/gateway v1.0.5 github.com/jackpal/go-nat-pmp v1.0.1 - github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b + github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d ) + +go 1.12 diff --git a/vendor/github.com/libp2p/go-nat/go.sum b/vendor/github.com/libp2p/go-nat/go.sum index 1a3a280ed3c..399175cc00a 100644 --- a/vendor/github.com/libp2p/go-nat/go.sum +++ b/vendor/github.com/libp2p/go-nat/go.sum @@ -5,8 +5,8 @@ github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= diff --git a/vendor/github.com/libp2p/go-nat/nat.go b/vendor/github.com/libp2p/go-nat/nat.go index 371fdb03543..c38030075c9 100644 --- a/vendor/github.com/libp2p/go-nat/nat.go +++ b/vendor/github.com/libp2p/go-nat/nat.go @@ -44,9 +44,6 @@ func DiscoverNATs(ctx context.Context) <-chan NAT { go func() { defer close(nats) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - upnpIg1 := discoverUPNP_IG1(ctx) upnpIg2 := discoverUPNP_IG2(ctx) natpmp := discoverNATPMP(ctx) diff --git a/vendor/github.com/libp2p/go-openssl/README.md b/vendor/github.com/libp2p/go-openssl/README.md index b3f1ac2ef41..62ac7dcd6da 100644 --- a/vendor/github.com/libp2p/go-openssl/README.md +++ b/vendor/github.com/libp2p/go-openssl/README.md @@ -1,7 +1,17 @@ # OpenSSL bindings for Go +Forked from https://github.com/spacemonkeygo/openssl (unmaintained) to add: + +1. FreeBSD support. +2. Key equality checking. +3. A function to get the size of signatures produced by a key. + +--- + Please see http://godoc.org/github.com/libp2p/go-openssl for more info +--- + ### License Copyright (C) 2017. See AUTHORS. diff --git a/vendor/github.com/libp2p/go-openssl/go.mod b/vendor/github.com/libp2p/go-openssl/go.mod index 13d7bed42a9..51068e7f572 100644 --- a/vendor/github.com/libp2p/go-openssl/go.mod +++ b/vendor/github.com/libp2p/go-openssl/go.mod @@ -4,3 +4,5 @@ require ( github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect ) + +go 1.12 diff --git a/vendor/github.com/libp2p/go-openssl/key.go b/vendor/github.com/libp2p/go-openssl/key.go index 3b36fa04234..268ff013736 100644 --- a/vendor/github.com/libp2p/go-openssl/key.go +++ b/vendor/github.com/libp2p/go-openssl/key.go @@ -88,6 +88,9 @@ type PublicKey interface { // Equal compares the key with the passed in key. Equal(key PublicKey) bool + // Size returns the size (in bytes) of signatures created with this key. + Size() int + evpPKey() *C.EVP_PKEY } @@ -120,6 +123,10 @@ func (key *pKey) KeyType() NID { return NID(C.EVP_PKEY_id(key.key)) } +func (key *pKey) Size() int { + return int(C.EVP_PKEY_size(key.key)) +} + func (key *pKey) BaseType() NID { return NID(C.EVP_PKEY_base_id(key.key)) } diff --git a/vendor/github.com/multiformats/go-multiaddr-dns/dns.go b/vendor/github.com/multiformats/go-multiaddr-dns/dns.go index 6b8ccd04ed5..4a5a93460ca 100644 --- a/vendor/github.com/multiformats/go-multiaddr-dns/dns.go +++ b/vendor/github.com/multiformats/go-multiaddr-dns/dns.go @@ -6,6 +6,8 @@ import ( // Extracted from source of truth for multicodec codes: https://github.com/multiformats/multicodec const ( + // Deprecated: use ma.P_DNS + P_DNS = ma.P_DNS // Deprecated: use ma.P_DNS4 P_DNS4 = ma.P_DNS4 // Deprecated: use ma.P_DNS6 @@ -14,6 +16,9 @@ const ( P_DNSADDR = ma.P_DNSADDR ) +// Deprecated: use ma.ProtocolWithCode(P_DNS) +var DnsProtocol = ma.ProtocolWithCode(P_DNS) + // Deprecated: use ma.ProtocolWithCode(P_DNS4) var Dns4Protocol = ma.ProtocolWithCode(P_DNS4) diff --git a/vendor/github.com/multiformats/go-multiaddr-dns/go.mod b/vendor/github.com/multiformats/go-multiaddr-dns/go.mod index c1d394ac458..0824647482c 100644 --- a/vendor/github.com/multiformats/go-multiaddr-dns/go.mod +++ b/vendor/github.com/multiformats/go-multiaddr-dns/go.mod @@ -1,5 +1,5 @@ module github.com/multiformats/go-multiaddr-dns -require github.com/multiformats/go-multiaddr v0.1.0 +require github.com/multiformats/go-multiaddr v0.1.1 go 1.12 diff --git a/vendor/github.com/multiformats/go-multiaddr-dns/go.sum b/vendor/github.com/multiformats/go-multiaddr-dns/go.sum index 87f7a0940a3..0061b94a7d0 100644 --- a/vendor/github.com/multiformats/go-multiaddr-dns/go.sum +++ b/vendor/github.com/multiformats/go-multiaddr-dns/go.sum @@ -1,18 +1,20 @@ -github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU= -github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= -github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc= -github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= -github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ= -github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= -github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ= -github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= -github.com/multiformats/go-multiaddr v0.1.0 h1:fkISCUNDb3xIpCcI6BGlPsQE+ywcxzimOsUnHWnrE74= -github.com/multiformats/go-multiaddr v0.1.0/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= -github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ= -github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= -golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE= -golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0= -golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= +github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-multiaddr v0.1.1 h1:rVAztJYMhCQ7vEFr8FvxW3mS+HF2eY/oPbOMeS0ZDnE= +github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= +github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= +github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/vendor/github.com/multiformats/go-multiaddr-dns/resolve.go b/vendor/github.com/multiformats/go-multiaddr-dns/resolve.go index 6808ca134f4..64d8f707db0 100644 --- a/vendor/github.com/multiformats/go-multiaddr-dns/resolve.go +++ b/vendor/github.com/multiformats/go-multiaddr-dns/resolve.go @@ -2,16 +2,17 @@ package madns import ( "context" - "fmt" "net" "strings" ma "github.com/multiformats/go-multiaddr" ) -var ResolvableProtocols = []ma.Protocol{DnsaddrProtocol, Dns4Protocol, Dns6Protocol} +var ResolvableProtocols = []ma.Protocol{DnsaddrProtocol, Dns4Protocol, Dns6Protocol, DnsProtocol} var DefaultResolver = &Resolver{Backend: net.DefaultResolver} +const dnsaddrTXTPrefix = "dnsaddr=" + type backend interface { LookupIPAddr(context.Context, string) ([]net.IPAddr, error) LookupTXT(context.Context, string) ([]string, error) @@ -44,19 +45,15 @@ func (r *MockBackend) LookupTXT(ctx context.Context, name string) ([]string, err } } -func Matches(maddr ma.Multiaddr) bool { - protos := maddr.Protocols() - if len(protos) == 0 { - return false - } - - for _, p := range ResolvableProtocols { - if protos[0].Code == p.Code { - return true +func Matches(maddr ma.Multiaddr) (matches bool) { + ma.ForEach(maddr, func(c ma.Component) bool { + switch c.Protocol().Code { + case DnsProtocol.Code, Dns4Protocol.Code, Dns6Protocol.Code, DnsaddrProtocol.Code: + matches = true } - } - - return false + return !matches + }) + return matches } func Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { @@ -64,121 +61,209 @@ func Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { } func (r *Resolver) Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { - if !Matches(maddr) { - return []ma.Multiaddr{maddr}, nil - } + var results []ma.Multiaddr + for i := 0; maddr != nil; i++ { + var keep ma.Multiaddr - protos := maddr.Protocols() - if protos[0].Code == Dns4Protocol.Code { - return r.resolveDns4(ctx, maddr) - } - if protos[0].Code == Dns6Protocol.Code { - return r.resolveDns6(ctx, maddr) - } - if protos[0].Code == DnsaddrProtocol.Code { - return r.resolveDnsaddr(ctx, maddr) - } + // Find the next dns component. + keep, maddr = ma.SplitFunc(maddr, func(c ma.Component) bool { + switch c.Protocol().Code { + case DnsProtocol.Code, Dns4Protocol.Code, Dns6Protocol.Code, DnsaddrProtocol.Code: + return true + default: + return false + } + }) - panic("unreachable") -} + // Keep everything before the dns component. + if keep != nil { + if len(results) == 0 { + results = []ma.Multiaddr{keep} + } else { + for i, r := range results { + results[i] = r.Encapsulate(keep) + } + } + } -func (r *Resolver) resolveDns4(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { - value, err := maddr.ValueForProtocol(Dns4Protocol.Code) - if err != nil { - return nil, fmt.Errorf("error resolving %s: %s", maddr.String(), err) - } + // If the rest is empty, we've hit the end (there _was_ no dns component). + if maddr == nil { + break + } - encap := ma.Split(maddr)[1:] + // split off the dns component. + var resolve *ma.Component + resolve, maddr = ma.SplitFirst(maddr) - result := []ma.Multiaddr{} - records, err := r.Backend.LookupIPAddr(ctx, value) - if err != nil { - return result, err - } + proto := resolve.Protocol() + value := resolve.Value() - for _, r := range records { - ip4 := r.IP.To4() - if ip4 == nil { - continue - } - ip4maddr, err := ma.NewMultiaddr("/ip4/" + ip4.String()) - if err != nil { - return result, err - } - parts := append([]ma.Multiaddr{ip4maddr}, encap...) - result = append(result, ma.Join(parts...)) - } - return result, nil -} + // resolve the dns component + var resolved []ma.Multiaddr + switch proto.Code { + case Dns4Protocol.Code, Dns6Protocol.Code, DnsProtocol.Code: + // The dns, dns4, and dns6 resolver simply resolves each + // dns* component into an ipv4/ipv6 address. -func (r *Resolver) resolveDns6(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { - value, err := maddr.ValueForProtocol(Dns6Protocol.Code) - if err != nil { - return nil, fmt.Errorf("error resolving %s: %s", maddr.String(), err) - } + v4only := proto.Code == Dns4Protocol.Code + v6only := proto.Code == Dns6Protocol.Code - encap := ma.Split(maddr)[1:] + // XXX: Unfortunately, go does a pretty terrible job of + // differentiating between IPv6 and IPv4. A v4-in-v6 + // AAAA record will _look_ like an A record to us and + // there's nothing we can do about that. + records, err := r.Backend.LookupIPAddr(ctx, value) + if err != nil { + return nil, err + } - result := []ma.Multiaddr{} - records, err := r.Backend.LookupIPAddr(ctx, value) - if err != nil { - return result, err - } + // Convert each DNS record into a multiaddr. If the + // protocol is dns4, throw away any IPv6 addresses. If + // the protocol is dns6, throw away any IPv4 addresses. - for _, r := range records { - if r.IP.To4() != nil { - continue - } - ip6maddr, err := ma.NewMultiaddr("/ip6/" + r.IP.To16().String()) - if err != nil { - return result, err - } - parts := append([]ma.Multiaddr{ip6maddr}, encap...) - result = append(result, ma.Join(parts...)) - } - return result, nil -} + for _, r := range records { + var ( + rmaddr ma.Multiaddr + err error + ) + ip4 := r.IP.To4() + if ip4 == nil { + if v4only { + continue + } + rmaddr, err = ma.NewMultiaddr("/ip6/" + r.IP.String()) + } else { + if v6only { + continue + } + rmaddr, err = ma.NewMultiaddr("/ip4/" + ip4.String()) + } + if err != nil { + return nil, err + } + resolved = append(resolved, rmaddr) + } + case DnsaddrProtocol.Code: + // The dnsaddr resolver is a bit more complicated. We: + // + // 1. Lookup the dnsaddr txt record on _dnsaddr.DOMAIN.TLD + // 2. Take everything _after_ the `/dnsaddr/DOMAIN.TLD` + // part of the multiaddr. + // 3. Find the dnsaddr records (if any) with suffixes + // matching the result of step 2. -func (r *Resolver) resolveDnsaddr(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { - value, err := maddr.ValueForProtocol(DnsaddrProtocol.Code) - if err != nil { - return nil, fmt.Errorf("error resolving %s: %s", maddr.String(), err) - } + // First, lookup the TXT record + records, err := r.Backend.LookupTXT(ctx, "_dnsaddr."+value) + if err != nil { + return nil, err + } - trailer := ma.Split(maddr)[1:] + // Then, calculate the length of the suffix we're + // looking for. + length := 0 + if maddr != nil { + length = addrLen(maddr) + } - result := []ma.Multiaddr{} - records, err := r.Backend.LookupTXT(ctx, "_dnsaddr."+value) - if err != nil { - return result, err - } + for _, r := range records { + // Ignore non dnsaddr TXT records. + if !strings.HasPrefix(r, dnsaddrTXTPrefix) { + continue + } - for _, r := range records { - rv := strings.Split(r, "dnsaddr=") - if len(rv) != 2 { - continue - } + // Extract and decode the multiaddr. + rmaddr, err := ma.NewMultiaddr(r[len(dnsaddrTXTPrefix):]) + if err != nil { + // discard multiaddrs we don't understand. + // XXX: Is this right? It's the best we + // can do for now, really. + continue + } + + // If we have a suffix to match on. + if maddr != nil { + // Make sure the new address is at least + // as long as the suffix we're looking + // for. + rmlen := addrLen(rmaddr) + if rmlen < length { + // not long enough. + continue + } + + // Matches everything after the /dnsaddr/... with the end of the + // dnsaddr record: + // + // v----------rmlen-----------------v + // /ip4/1.2.3.4/tcp/1234/p2p/QmFoobar + // /p2p/QmFoobar + // ^--(rmlen - length)--^---length--^ + if !maddr.Equal(offset(rmaddr, rmlen-length)) { + continue + } + } - rmaddr, err := ma.NewMultiaddr(rv[1]) - if err != nil { - return result, err + resolved = append(resolved, rmaddr) + } + + // consumes the rest of the multiaddr as part of the "match" process. + maddr = nil + default: + panic("unreachable") } - if matchDnsaddr(rmaddr, trailer) { - result = append(result, rmaddr) + if len(resolved) == 0 { + return nil, nil + } else if len(results) == 0 { + results = resolved + } else { + // We take the cross product here as we don't have any + // better way to represent "ORs" in multiaddrs. For + // example, `/dns/foo.com/p2p-circuit/dns/bar.com` could + // resolve to: + // + // * /ip4/1.1.1.1/p2p-circuit/ip4/2.1.1.1 + // * /ip4/1.1.1.1/p2p-circuit/ip4/2.1.1.2 + // * /ip4/1.1.1.2/p2p-circuit/ip4/2.1.1.1 + // * /ip4/1.1.1.2/p2p-circuit/ip4/2.1.1.2 + results = cross(results, resolved) } } - return result, nil + + return results, nil } -// XXX probably insecure -func matchDnsaddr(maddr ma.Multiaddr, trailer []ma.Multiaddr) bool { - parts := ma.Split(maddr) - if len(trailer) > len(parts) { - return false - } - if ma.Join(parts[len(parts)-len(trailer):]...).Equal(ma.Join(trailer...)) { +// counts the number of components in the multiaddr +func addrLen(maddr ma.Multiaddr) int { + length := 0 + ma.ForEach(maddr, func(_ ma.Component) bool { + length++ return true + }) + return length +} + +// trims `offset` components from the beginning of the multiaddr. +func offset(maddr ma.Multiaddr, offset int) ma.Multiaddr { + _, after := ma.SplitFunc(maddr, func(c ma.Component) bool { + if offset == 0 { + return true + } + offset-- + return false + }) + return after +} + +// takes the cross product of two sets of multiaddrs +// +// assumes `a` is non-empty. +func cross(a, b []ma.Multiaddr) []ma.Multiaddr { + res := make([]ma.Multiaddr, 0, len(a)*len(b)) + for _, x := range a { + for _, y := range b { + res = append(res, x.Encapsulate(y)) + } } - return false + return res } diff --git a/vendor/github.com/multiformats/go-multiaddr-net/convert.go b/vendor/github.com/multiformats/go-multiaddr-net/convert.go index b1e544668d3..11ee7d5ad25 100644 --- a/vendor/github.com/multiformats/go-multiaddr-net/convert.go +++ b/vendor/github.com/multiformats/go-multiaddr-net/convert.go @@ -4,6 +4,8 @@ import ( "fmt" "net" "path/filepath" + "runtime" + "strings" ma "github.com/multiformats/go-multiaddr" ) @@ -192,6 +194,10 @@ func DialArgs(m ma.Multiaddr) (string, string, error) { } return network, "[" + ip + "]" + ":" + port, nil case "unix": + if runtime.GOOS == "windows" { + // convert /c:/... to c:\... + ip = filepath.FromSlash(strings.TrimLeft(ip, "/")) + } return network, ip, nil default: return "", "", fmt.Errorf("%s is not a 'thin waist' address", m) @@ -263,6 +269,16 @@ func parseUnixNetAddr(a net.Addr) (ma.Multiaddr, error) { if !ok { return nil, errIncorrectNetAddr } - cleaned := filepath.Clean(ac.Name) - return ma.NewComponent("unix", cleaned) + + path := ac.Name + if runtime.GOOS == "windows" { + // Convert c:\foobar\... to c:/foobar/... + path = filepath.ToSlash(path) + } + if len(path) == 0 || path[0] != '/' { + // convert "" and "c:/..." to "/..." + path = "/" + path + } + + return ma.NewComponent("unix", path) } diff --git a/vendor/github.com/status-im/status-go/eth-node/core/types/transaction.go b/vendor/github.com/status-im/status-go/eth-node/core/types/transaction.go new file mode 100644 index 00000000000..bc41ec86061 --- /dev/null +++ b/vendor/github.com/status-im/status-go/eth-node/core/types/transaction.go @@ -0,0 +1,39 @@ +package types + +import ( + "github.com/status-im/status-go/eth-node/types" + "math/big" +) + +type Message struct { + to *types.Address + from types.Address + nonce uint64 + amount *big.Int + gasLimit uint64 + gasPrice *big.Int + data []byte + checkNonce bool +} + +func NewMessage(from types.Address, to *types.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool) Message { + return Message{ + from: from, + to: to, + nonce: nonce, + amount: amount, + gasLimit: gasLimit, + gasPrice: gasPrice, + data: data, + checkNonce: checkNonce, + } +} + +func (m Message) From() types.Address { return m.from } +func (m Message) To() *types.Address { return m.to } +func (m Message) GasPrice() *big.Int { return m.gasPrice } +func (m Message) Value() *big.Int { return m.amount } +func (m Message) Gas() uint64 { return m.gasLimit } +func (m Message) Nonce() uint64 { return m.nonce } +func (m Message) Data() []byte { return m.data } +func (m Message) CheckNonce() bool { return m.checkNonce } diff --git a/vendor/github.com/status-im/status-go/eth-node/crypto/crypto.go b/vendor/github.com/status-im/status-go/eth-node/crypto/crypto.go index 18a3aa3a232..ef49262511e 100644 --- a/vendor/github.com/status-im/status-go/eth-node/crypto/crypto.go +++ b/vendor/github.com/status-im/status-go/eth-node/crypto/crypto.go @@ -1,6 +1,7 @@ package crypto import ( + "context" "crypto/aes" "crypto/cipher" "crypto/ecdsa" @@ -8,6 +9,8 @@ import ( "encoding/hex" "errors" "fmt" + types "github.com/status-im/status-go/eth-node/types" + "golang.org/x/crypto/sha3" gethcrypto "github.com/ethereum/go-ethereum/crypto" ) @@ -192,3 +195,56 @@ func generateSecureRandomData(length int) ([]byte, error) { return res, nil } + +// TextHash is a helper function that calculates a hash for the given message that can be +// safely used to calculate a signature from. +// +// The hash is calulcated as +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// This gives context to the signed message and prevents signing of transactions. +func TextHash(data []byte) []byte { + hash, _ := TextAndHash(data) + return hash +} + +// TextAndHash is a helper function that calculates a hash for the given message that can be +// safely used to calculate a signature from. +// +// The hash is calulcated as +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// This gives context to the signed message and prevents signing of transactions. +func TextAndHash(data []byte) ([]byte, string) { + msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), string(data)) + hasher := sha3.NewLegacyKeccak256() + hasher.Write([]byte(msg)) + return hasher.Sum(nil), msg +} + +func EcRecover(ctx context.Context, data types.HexBytes, sig types.HexBytes) (types.Address, error) { + // Returns the address for the Account that was used to create the signature. + // + // Note, this function is compatible with eth_sign and personal_sign. As such it recovers + // the address of: + // hash = keccak256("\x19${byteVersion}Ethereum Signed Message:\n${message length}${message}") + // addr = ecrecover(hash, signature) + // + // Note, the signature must conform to the secp256k1 curve R, S and V values, where + // the V value must be be 27 or 28 for legacy reasons. + // + // https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover + if len(sig) != 65 { + return types.Address{}, fmt.Errorf("signature must be 65 bytes long") + } + if sig[64] != 27 && sig[64] != 28 { + return types.Address{}, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)") + } + sig[64] -= 27 // Transform yellow paper V from 27/28 to 0/1 + hash := TextHash(data) + rpk, err := SigToPub(hash, sig) + if err != nil { + return types.Address{}, err + } + return PubkeyToAddress(*rpk), nil +} diff --git a/vendor/github.com/status-im/status-go/protocol/chat.go b/vendor/github.com/status-im/status-go/protocol/chat.go index 684e1cea884..74600b64d20 100644 --- a/vendor/github.com/status-im/status-go/protocol/chat.go +++ b/vendor/github.com/status-im/status-go/protocol/chat.go @@ -203,6 +203,13 @@ func oneToOneChatID(publicKey *ecdsa.PublicKey) string { return types.EncodeHex(crypto.FromECDSAPub(publicKey)) } +func OneToOneFromPublicKey(pk *ecdsa.PublicKey) *Chat { + chatID := types.EncodeHex(crypto.FromECDSAPub(pk)) + newChat := CreateOneToOneChat(chatID[:8], pk) + + return &newChat +} + func CreateOneToOneChat(name string, publicKey *ecdsa.PublicKey) Chat { return Chat{ ID: oneToOneChatID(publicKey), @@ -263,6 +270,33 @@ func stringSliceToPublicKeys(slice []string, prefixed bool) ([]*ecdsa.PublicKey, return result, nil } +// NextClockAndTimestamp returns the next clock value +// and the current timestamp +func (c *Chat) NextClockAndTimestamp() (uint64, uint64) { + clock := c.LastClockValue + timestamp := timestampInMs() + if clock == 0 || clock < timestamp { + clock = timestamp + } else { + clock = clock + 1 + } + return clock, timestamp +} + +func (c *Chat) UpdateFromMessage(message *Message) error { + c.Timestamp = int64(timestampInMs()) + if c.LastClockValue <= message.Clock { + jsonMessage, err := json.Marshal(message) + if err != nil { + return err + } + + c.LastClockValue = message.Clock + c.LastMessage = jsonMessage + } + return nil +} + func stringSliceContains(slice []string, item string) bool { for _, s := range slice { if s == item { diff --git a/vendor/github.com/status-im/status-go/protocol/contact.go b/vendor/github.com/status-im/status-go/protocol/contact.go index 949cc246ae8..cc6c2769f4f 100644 --- a/vendor/github.com/status-im/status-go/protocol/contact.go +++ b/vendor/github.com/status-im/status-go/protocol/contact.go @@ -48,7 +48,7 @@ type Contact struct { Photo string `json:"photoPath,omitempty"` // LastUpdated is the last time we received an update from the contact // updates should be discarded if last updated is less than the one stored - LastUpdated int64 `json:"lastUpdated"` + LastUpdated uint64 `json:"lastUpdated"` // SystemTags contains information about whether we blocked/added/have been // added. SystemTags []string `json:"systemTags"` diff --git a/vendor/github.com/status-im/status-go/protocol/go.mod b/vendor/github.com/status-im/status-go/protocol/go.mod index ca0400c3c41..973b203eeff 100644 --- a/vendor/github.com/status-im/status-go/protocol/go.mod +++ b/vendor/github.com/status-im/status-go/protocol/go.mod @@ -23,6 +23,7 @@ require ( github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a github.com/status-im/doubleratchet v3.0.0+incompatible github.com/status-im/migrate/v4 v4.6.2-status.2 + github.com/status-im/status-go v0.38.5 // indirect github.com/status-im/status-go/eth-node v1.0.0 github.com/status-im/status-go/whisper/v6 v6.0.1 github.com/stretchr/testify v1.4.0 diff --git a/vendor/github.com/status-im/status-go/protocol/go.sum b/vendor/github.com/status-im/status-go/protocol/go.sum index a146328d3b1..80b5dc96625 100644 --- a/vendor/github.com/status-im/status-go/protocol/go.sum +++ b/vendor/github.com/status-im/status-go/protocol/go.sum @@ -23,8 +23,10 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/allegro/bigcache v0.0.0-20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/allegro/bigcache v1.1.0/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= @@ -40,6 +42,7 @@ github.com/aristanetworks/goarista v0.0.0-20190219163901-728bce664cf5 h1:L0TwgZQ github.com/aristanetworks/goarista v0.0.0-20190219163901-728bce664cf5/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/aristanetworks/goarista v0.0.0-20190502180301-283422fc1708 h1:tS7jSmwRqSxTnonTRlDD1oHo6Q9YOK4xHS9/v4L56eg= github.com/aristanetworks/goarista v0.0.0-20190502180301-283422fc1708/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= +github.com/aristanetworks/goarista v0.0.0-20191106175434-873d404c7f40 h1:ZdRuixFqR3mfx4FHzclG3COrRgWrYq0VhNgIoYoObcM= github.com/aristanetworks/goarista v0.0.0-20191106175434-873d404c7f40/go.mod h1:Z4RTxGAuYhPzcq8+EdRM+R8M48Ssle2TsWtwRKa+vns= github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -136,6 +139,7 @@ github.com/elastic/gosigar v0.10.5/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTy github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/ethereum/go-ethereum v1.8.20/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= github.com/ethereum/go-ethereum v1.9.2/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= +github.com/ethereum/go-ethereum v1.9.9 h1:jnoBvjH8aMH++iH14XmiJdAsnRcmZUM+B5fsnEZBVE0= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a h1:1znxn4+q2MrEdTk1eCk6KIV3muTYVclBIB6CTVR/zBc= @@ -250,6 +254,7 @@ github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQ github.com/jackpal/go-nat-pmp v0.0.0-20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= @@ -434,11 +439,15 @@ github.com/olekukonko/tablewriter v0.0.0-20170128050532-febf2d34b54a/go.mod h1:v github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -503,6 +512,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= github.com/russolsen/ohyeah v0.0.0-20160324131710-f4938c005315 h1:H3hCXwP92pH/hSgNrCLtjxvsKJ50sq26nICbZuoR1tQ= @@ -517,6 +527,7 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t4 github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= @@ -537,6 +548,7 @@ github.com/status-im/go-ethereum v1.9.5-status.6 h1:ytuTO1yBIAuTVRtRQoc2mrdyngtP github.com/status-im/go-ethereum v1.9.5-status.6/go.mod h1:08JvQWE+IOnAFSe4UD4ACLNe2fDd9XmWMCq5Yzy9mk0= github.com/status-im/go-ethereum v1.9.5-status.7 h1:DKH1GiF52LwaZaw6YDBliFEgm/JDsbIT+hn7ph6X94Q= github.com/status-im/go-ethereum v1.9.5-status.7/go.mod h1:YyH5DKB6+z+Vaya7eIm67pnuPZ1oiUMbbsZW41ktN0g= +github.com/status-im/go-multiaddr-ethv4 v1.2.0/go.mod h1:2VQ3C+9zEurcceasz12gPAtmEzCeyLUGPeKLSXYQKHo= github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 h1:ju5UTwk5Odtm4trrY+4Ca4RMj5OyXbmVeDAVad2T0Jw= github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/keycard-go v0.0.0-20191119114148-6dd40a46baa0 h1:5UdlDkkBoPrJfh7zkfoR3X5utJhNs/MCQysK3x0ycgg= @@ -550,9 +562,14 @@ github.com/status-im/status-go v0.36.0 h1:91qDMJjHv+T3Li9FwxsWQ2JBVcYtvVDT0nGFSM github.com/status-im/status-go v0.36.1 h1:nb9eTq0UQJ57YyTZSl5U05emFT+R4AW8/Bga6ocgOks= github.com/status-im/status-go v0.37.3 h1:94/bOA8qrEIgWd23mSLN39SwUJwCu2TPQFV2HzSI2ZE= github.com/status-im/status-go v0.37.3/go.mod h1:9qHQ2+8NS6ivPJS5YbsI3gWkr0t6DWmJzKnr4M7vudw= +github.com/status-im/status-go v0.38.0 h1:3toC1ToY48wbRBVt7CMWSSG5FZAcPPMlnt0+G6iCbcE= +github.com/status-im/status-go v0.38.0/go.mod h1:u3tlXqVkxAW35dui3LjHajIkbOaF4d4CnriJ8zhntOw= +github.com/status-im/status-go v0.38.5 h1:vnbGgk5+X5ZUmn3/gJ88GlaNaAO9kGVgm8E5mR0umiQ= +github.com/status-im/status-go v0.38.5/go.mod h1:UKxySGdqFuVPvCyPSYD0+zKeV2OzDijZqICvR+tZ3uM= github.com/status-im/status-go/extkeys v1.0.0 h1:Qyirsoi5Ye5UFfisgPtCjPb/RkBxyK+UsSiEcr2PVlM= github.com/status-im/status-go/extkeys v1.0.0/go.mod h1:GdqJbrcpkNm5ZsSCpp+PdMxnXx+OcRBdm3PI0rs1FpU= github.com/status-im/status-go/protocol v1.0.1/go.mod h1:LpA7BsaNmj6EOdq7BwuqncewjPqIRHCletZOb2wlWrY= +github.com/status-im/status-go/waku v1.0.0 h1:XFcJ9Am1cK657dpUP/ysyCp+A99MWSvb1DVTtjo1fE8= github.com/status-im/status-go/waku v1.0.0/go.mod h1:1bjvQAL4cJYtxCsm6DnKdJbxcZwnvvZmxb6pmoUDtuY= 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= @@ -649,6 +666,7 @@ golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIo golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE= golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4= golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -714,6 +732,7 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056 h1:dHtDnRWQtSx0Hjq9kvKFpBh9uPPKfQN70NZZmvssGwk= golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -741,6 +760,7 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 h1:LCmXVkvpQCDj724eX6irUTPCJP5GelFHxqGSWL2D1R0= golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191213032237-7093a17b0467/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.3.2/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= @@ -758,6 +778,7 @@ google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a/go.mod h1:KF9sEfUPAXdG8Oev9e99iLGnl2uJMjc5B+4y3O7x610= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/vendor/github.com/status-im/status-go/protocol/message.go b/vendor/github.com/status-im/status-go/protocol/message.go index 5b805982dc8..2798336397b 100644 --- a/vendor/github.com/status-im/status-go/protocol/message.go +++ b/vendor/github.com/status-im/status-go/protocol/message.go @@ -19,13 +19,49 @@ type QuotedMessage struct { Text string `json:"text"` } +type CommandState int + +const ( + CommandStateRequestAddressForTransaction CommandState = iota + 1 + CommandStateRequestAddressForTransactionDeclined + CommandStateRequestAddressForTransactionAccepted + CommandStateRequestTransaction + CommandStateRequestTransactionDeclined + CommandStateTransactionPending + CommandStateTransactionSent +) + +type CommandParameters struct { + // ID is the ID of the initial message + ID string `json:"id"` + // From is the address we are sending the command from + From string `json:"from"` + // Address is the address sent with the command + Address string `json:"address"` + // Contract is the contract address for ERC20 tokens + Contract string `json:"contract"` + // Value is the value as a string sent + Value string `json:"value"` + // TransactionHash is the hash of the transaction + TransactionHash string `json:"transactionHash"` + // CommandState is the state of the command + CommandState CommandState `json:"commandState"` + // The Signature of the pk-bytes+transaction-hash from the wallet + // address originating + Signature []byte `json:"signature"` +} + +func (c *CommandParameters) IsTokenTransfer() bool { + return len(c.Contract) != 0 +} + const ( OutgoingStatusSending = "sending" OutgoingStatusSent = "sent" ) // Message represents a message record in the database, -// more specifically in user_messages_legacy table. +// more specifically in user_messages table. type Message struct { protobuf.ChatMessage @@ -42,70 +78,89 @@ type Message struct { // The chat id to be stored locally LocalChatID string `json:"localChatId"` - RetryCount int `json:"retryCount"` Seen bool `json:"seen"` OutgoingStatus string `json:"outgoingStatus,omitempty"` QuotedMessage *QuotedMessage `json:"quotedMessage"` + // CommandParameters is the parameters sent with the message + CommandParameters *CommandParameters `json:"commandParameters"` + // Computed fields RTL bool `json:"rtl"` ParsedText []byte `json:"parsedText"` LineCount int `json:"lineCount"` + // Replace indicates that this is a replacement of a message + // that has been updated + Replace string `json:"replace,omitEmpty"` SigPubKey *ecdsa.PublicKey `json:"-"` - // RawPayload is the marshaled payload, used for resending the message - RawPayload []byte `json:"-"` +} + +// RawMessage represent a sent or received message, kept for being able +// to re-send/propagate +type RawMessage struct { + ID string + LocalChatID string + LastSent uint64 + SendCount int + Sent bool + ResendAutomatically bool + MessageType protobuf.ApplicationMetadataMessage_Type + Payload []byte + Recipients []*ecdsa.PublicKey } func (m *Message) MarshalJSON() ([]byte, error) { type MessageAlias Message item := struct { - ID string `json:"id"` - WhisperTimestamp uint64 `json:"whisperTimestamp"` - From string `json:"from"` - Alias string `json:"alias"` - Identicon string `json:"identicon"` - RetryCount int `json:"retryCount"` - Seen bool `json:"seen"` - OutgoingStatus string `json:"outgoingStatus,omitempty"` - QuotedMessage *QuotedMessage `json:"quotedMessage"` - RTL bool `json:"rtl"` - ParsedText json.RawMessage `json:"parsedText"` - LineCount int `json:"lineCount"` - Text string `json:"text"` - ChatId string `json:"chatId"` - LocalChatID string `json:"localChatId"` - Clock uint64 `json:"clock"` - ResponseTo string `json:"responseTo"` - EnsName string `json:"ensName"` - Sticker *protobuf.StickerMessage `json:"sticker"` - Timestamp uint64 `json:"timestamp"` - ContentType protobuf.ChatMessage_ContentType `json:"contentType"` - MessageType protobuf.ChatMessage_MessageType `json:"messageType"` + ID string `json:"id"` + WhisperTimestamp uint64 `json:"whisperTimestamp"` + From string `json:"from"` + Alias string `json:"alias"` + Identicon string `json:"identicon"` + Seen bool `json:"seen"` + OutgoingStatus string `json:"outgoingStatus,omitempty"` + QuotedMessage *QuotedMessage `json:"quotedMessage"` + RTL bool `json:"rtl"` + ParsedText json.RawMessage `json:"parsedText"` + LineCount int `json:"lineCount"` + Text string `json:"text"` + ChatId string `json:"chatId"` + LocalChatID string `json:"localChatId"` + Clock uint64 `json:"clock"` + Replace string `json:"replace,omitEmpty"` + ResponseTo string `json:"responseTo"` + EnsName string `json:"ensName"` + Sticker *protobuf.StickerMessage `json:"sticker"` + CommandParameters *CommandParameters `json:"commandParameters"` + Timestamp uint64 `json:"timestamp"` + ContentType protobuf.ChatMessage_ContentType `json:"contentType"` + MessageType protobuf.ChatMessage_MessageType `json:"messageType"` }{ - ID: m.ID, - WhisperTimestamp: m.WhisperTimestamp, - From: m.From, - Alias: m.Alias, - Identicon: m.Identicon, - RetryCount: m.RetryCount, - Seen: m.Seen, - OutgoingStatus: m.OutgoingStatus, - QuotedMessage: m.QuotedMessage, - RTL: m.RTL, - ParsedText: m.ParsedText, - LineCount: m.LineCount, - Text: m.Text, - ChatId: m.ChatId, - LocalChatID: m.LocalChatID, - Clock: m.Clock, - ResponseTo: m.ResponseTo, - EnsName: m.EnsName, - Timestamp: m.Timestamp, - ContentType: m.ContentType, - MessageType: m.MessageType, - Sticker: m.GetSticker(), + ID: m.ID, + WhisperTimestamp: m.WhisperTimestamp, + From: m.From, + Alias: m.Alias, + Identicon: m.Identicon, + Seen: m.Seen, + OutgoingStatus: m.OutgoingStatus, + QuotedMessage: m.QuotedMessage, + RTL: m.RTL, + ParsedText: m.ParsedText, + LineCount: m.LineCount, + Text: m.Text, + Replace: m.Replace, + ChatId: m.ChatId, + LocalChatID: m.LocalChatID, + Clock: m.Clock, + ResponseTo: m.ResponseTo, + EnsName: m.EnsName, + Timestamp: m.Timestamp, + ContentType: m.ContentType, + MessageType: m.MessageType, + Sticker: m.GetSticker(), + CommandParameters: m.CommandParameters, } return json.Marshal(item) diff --git a/vendor/github.com/status-im/status-go/protocol/message_builder.go b/vendor/github.com/status-im/status-go/protocol/message_builder.go new file mode 100644 index 00000000000..2c4f48882c8 --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/message_builder.go @@ -0,0 +1,39 @@ +package protocol + +import ( + "crypto/ecdsa" + + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/protocol/identity/alias" + "github.com/status-im/status-go/protocol/identity/identicon" +) + +func extendMessageFromChat(message *Message, chat *Chat, key *ecdsa.PublicKey) error { + clock, timestamp := chat.NextClockAndTimestamp() + + message.LocalChatID = chat.ID + message.Clock = clock + message.Timestamp = timestamp + message.From = types.EncodeHex(crypto.FromECDSAPub(key)) + message.SigPubKey = key + message.WhisperTimestamp = timestamp + message.Seen = true + message.OutgoingStatus = OutgoingStatusSending + + identicon, err := identicon.GenerateBase64(message.From) + if err != nil { + return err + } + + message.Identicon = identicon + + alias, err := alias.GenerateFromPublicKeyString(message.From) + if err != nil { + return err + } + + message.Alias = alias + return nil + +} diff --git a/vendor/github.com/status-im/status-go/protocol/message_handler.go b/vendor/github.com/status-im/status-go/protocol/message_handler.go index 171ad0b0c03..bbcfcd20222 100644 --- a/vendor/github.com/status-im/status-go/protocol/message_handler.go +++ b/vendor/github.com/status-im/status-go/protocol/message_handler.go @@ -1,46 +1,625 @@ package protocol import ( + "crypto/ecdsa" + "encoding/hex" "github.com/pkg/errors" + "go.uber.org/zap" + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/protocol/encryption/multidevice" "github.com/status-im/status-go/protocol/protobuf" v1protocol "github.com/status-im/status-go/protocol/v1" ) +type MessageHandler struct { + identity *ecdsa.PrivateKey + persistence *sqlitePersistence + logger *zap.Logger +} + +func newMessageHandler(identity *ecdsa.PrivateKey, logger *zap.Logger, persistence *sqlitePersistence) *MessageHandler { + return &MessageHandler{ + identity: identity, + persistence: persistence, + logger: logger} +} + // HandleMembershipUpdate updates a Chat instance according to the membership updates. // It retrieves chat, if exists, and merges membership updates from the message. // Finally, the Chat is updated with the new group events. -func HandleMembershipUpdate(chat *Chat, m *v1protocol.MembershipUpdateMessage, myIdentity string, translations map[protobuf.MembershipUpdateEvent_EventType]string) (*Chat, []*Message, error) { +func (m *MessageHandler) HandleMembershipUpdate(messageState *ReceivedMessageState, chat *Chat, rawMembershipUpdate protobuf.MembershipUpdateMessage, translations map[protobuf.MembershipUpdateEvent_EventType]string) error { + var group *v1protocol.Group + var err error + + message, err := v1protocol.MembershipUpdateMessageFromProtobuf(&rawMembershipUpdate) + if err != nil { + return err + + } + if chat == nil { - if len(m.Events) == 0 { - return nil, nil, errors.New("can't create new group chat without events") + if len(message.Events) == 0 { + return errors.New("can't create new group chat without events") } - group, err := v1protocol.NewGroupWithEvents(m.ChatID, m.Events) + group, err = v1protocol.NewGroupWithEvents(message.ChatID, message.Events) if err != nil { - return nil, nil, err + return err } // A new chat must contain us - if !group.IsMember(myIdentity) { - return nil, nil, errors.New("can't create a new group chat without us being a member") + if !group.IsMember(types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey))) { + return errors.New("can't create a new group chat without us being a member") } newChat := createGroupChat() - newChat.updateChatFromProtocolGroup(group) - return &newChat, buildSystemMessages(m.Events, translations), nil + chat = &newChat + + } else { + existingGroup, err := newProtocolGroupFromChat(chat) + if err != nil { + return errors.Wrap(err, "failed to create a Group from Chat") + } + updateGroup, err := v1protocol.NewGroupWithEvents(message.ChatID, message.Events) + if err != nil { + return errors.Wrap(err, "invalid membership update") + } + merged := v1protocol.MergeMembershipUpdateEvents(existingGroup.Events(), updateGroup.Events()) + group, err = v1protocol.NewGroup(chat.ID, merged) + if err != nil { + return errors.Wrap(err, "failed to create a group with new membership updates") + } + } + + chat.updateChatFromProtocolGroup(group) + systemMessages := buildSystemMessages(message.Events, translations) + + for _, message := range systemMessages { + messageID := message.ID + exists, err := m.messageExists(messageID, messageState.ExistingMessagesMap) + if err != nil { + m.logger.Warn("failed to check message exists", zap.Error(err)) + } + if exists { + continue + } + messageState.Response.Messages = append(messageState.Response.Messages, message) + } + + // Store in chats map as it might be a new one + messageState.AllChats[chat.ID] = chat + // Set in the map + messageState.ModifiedChats[chat.ID] = true + + if message.Message != nil { + messageState.CurrentMessageState.Message = *message.Message + return m.HandleChatMessage(messageState) } - existingGroup, err := newProtocolGroupFromChat(chat) + + return nil +} + +func (m *MessageHandler) handleCommandMessage(state *ReceivedMessageState, message *Message) error { + message.ID = state.CurrentMessageState.MessageID + message.From = state.CurrentMessageState.Contact.ID + message.Alias = state.CurrentMessageState.Contact.Alias + message.SigPubKey = state.CurrentMessageState.PublicKey + message.Identicon = state.CurrentMessageState.Contact.Identicon + message.WhisperTimestamp = state.CurrentMessageState.WhisperTimestamp + + message.PrepareContent() + chat, err := m.matchMessage(message, state.AllChats) if err != nil { - return nil, nil, errors.Wrap(err, "failed to create a Group from Chat") + return err } - updateGroup, err := v1protocol.NewGroupWithEvents(m.ChatID, m.Events) + + // If deleted-at is greater, ignore message + if chat.DeletedAtClockValue >= message.Clock { + return nil + } + + // Set the LocalChatID for the message + message.LocalChatID = chat.ID + + if c, ok := state.AllChats[chat.ID]; ok { + chat = c + } + + // Set the LocalChatID for the message + message.LocalChatID = chat.ID + + // Increase unviewed count + if !isPubKeyEqual(message.SigPubKey, &m.identity.PublicKey) { + chat.UnviewedMessagesCount++ + message.OutgoingStatus = "" + } else { + // Our own message, mark as sent + message.OutgoingStatus = OutgoingStatusSent + } + + err = chat.UpdateFromMessage(message) if err != nil { - return nil, nil, errors.Wrap(err, "invalid membership update") + return err } - merged := v1protocol.MergeMembershipUpdateEvents(existingGroup.Events(), updateGroup.Events()) - newGroup, err := v1protocol.NewGroup(chat.ID, merged) + + // Set chat active + chat.Active = true + // Set in the modified maps chat + state.ModifiedChats[chat.ID] = true + state.AllChats[chat.ID] = chat + + // Add to response + if message != nil { + state.Response.Messages = append(state.Response.Messages, message) + } + return nil +} + +func (m *MessageHandler) HandleSyncInstallationContact(state *ReceivedMessageState, message protobuf.SyncInstallationContact) error { + chat, ok := state.AllChats[state.CurrentMessageState.Contact.ID] + if !ok { + chat = OneToOneFromPublicKey(state.CurrentMessageState.PublicKey) + // We don't want to show the chat to the user + chat.Active = false + } + + contact, ok := state.AllContacts[message.Id] + if !ok { + publicKeyBytes, err := hex.DecodeString(message.Id[2:]) + if err != nil { + return err + } + publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes) + if err != nil { + return err + } + contact, err = buildContact(publicKey) + if err != nil { + return err + } + } + + if contact.LastUpdated < message.Clock { + if !contact.IsAdded() { + contact.SystemTags = append(contact.SystemTags, contactAdded) + } + if contact.Name != message.EnsName { + contact.Name = message.EnsName + contact.ENSVerified = false + } + contact.Photo = message.ProfileImage + contact.LastUpdated = message.Clock + state.ModifiedContacts[contact.ID] = true + state.AllContacts[contact.ID] = contact + } + + state.AllChats[chat.ID] = chat + + return nil +} + +func (m *MessageHandler) HandleContactUpdate(state *ReceivedMessageState, message protobuf.ContactUpdate) error { + logger := m.logger.With(zap.String("site", "HandleContactUpdate")) + contact := state.CurrentMessageState.Contact + chat, ok := state.AllChats[contact.ID] + if !ok { + chat = OneToOneFromPublicKey(state.CurrentMessageState.PublicKey) + // We don't want to show the chat to the user + chat.Active = false + } + + logger.Info("Handling contact update") + + if contact.LastUpdated < message.Clock { + logger.Info("Updating contact") + if !contact.HasBeenAdded() { + contact.SystemTags = append(contact.SystemTags, contactRequestReceived) + } + if contact.Name != message.EnsName { + contact.Name = message.EnsName + contact.ENSVerified = false + } + contact.Photo = message.ProfileImage + contact.LastUpdated = message.Clock + state.ModifiedContacts[contact.ID] = true + state.AllContacts[contact.ID] = contact + } + + if chat.LastClockValue < message.Clock { + chat.LastClockValue = message.Clock + } + + state.ModifiedChats[chat.ID] = true + state.AllChats[chat.ID] = chat + + return nil +} + +func (m *MessageHandler) HandlePairInstallation(state *ReceivedMessageState, message protobuf.PairInstallation) error { + logger := m.logger.With(zap.String("site", "HandlePairInstallation")) + if err := ValidateReceivedPairInstallation(&message); err != nil { + logger.Warn("failed to validate message", zap.Error(err)) + return err + } + + installation, ok := state.AllInstallations[message.InstallationId] + if !ok { + return errors.New("installation not found") + } + + metadata := &multidevice.InstallationMetadata{ + Name: message.Name, + DeviceType: message.DeviceType, + } + + installation.InstallationMetadata = metadata + state.AllInstallations[message.InstallationId] = installation + state.ModifiedInstallations[message.InstallationId] = true + + return nil +} + +func (m *MessageHandler) HandleChatMessage(state *ReceivedMessageState) error { + logger := m.logger.With(zap.String("site", "handleChatMessage")) + if err := ValidateReceivedChatMessage(&state.CurrentMessageState.Message); err != nil { + logger.Warn("failed to validate message", zap.Error(err)) + return err + } + receivedMessage := &Message{ + ID: state.CurrentMessageState.MessageID, + ChatMessage: state.CurrentMessageState.Message, + From: state.CurrentMessageState.Contact.ID, + Alias: state.CurrentMessageState.Contact.Alias, + SigPubKey: state.CurrentMessageState.PublicKey, + Identicon: state.CurrentMessageState.Contact.Identicon, + WhisperTimestamp: state.CurrentMessageState.WhisperTimestamp, + } + + receivedMessage.PrepareContent() + chat, err := m.matchMessage(receivedMessage, state.AllChats) + if err != nil { + return err + } + + // If deleted-at is greater, ignore message + if chat.DeletedAtClockValue >= receivedMessage.Clock { + return nil + } + + // Set the LocalChatID for the message + receivedMessage.LocalChatID = chat.ID + + if c, ok := state.AllChats[chat.ID]; ok { + chat = c + } + + // Set the LocalChatID for the message + receivedMessage.LocalChatID = chat.ID + + // Increase unviewed count + if !isPubKeyEqual(receivedMessage.SigPubKey, &m.identity.PublicKey) { + chat.UnviewedMessagesCount++ + } else { + // Our own message, mark as sent + receivedMessage.OutgoingStatus = OutgoingStatusSent + } + + err = chat.UpdateFromMessage(receivedMessage) if err != nil { - return nil, nil, errors.Wrap(err, "failed to create a group with new membership updates") + return err + } + + // Set chat active + chat.Active = true + // Set in the modified maps chat + state.ModifiedChats[chat.ID] = true + state.AllChats[chat.ID] = chat + + // Add to response + if receivedMessage != nil { + state.Response.Messages = append(state.Response.Messages, receivedMessage) + } + + return nil +} + +func (m *MessageHandler) HandleRequestAddressForTransaction(messageState *ReceivedMessageState, command protobuf.RequestAddressForTransaction) error { + err := ValidateReceivedRequestAddressForTransaction(&command) + if err != nil { + return err + } + message := &Message{ + ChatMessage: protobuf.ChatMessage{ + Clock: command.Clock, + Timestamp: messageState.CurrentMessageState.WhisperTimestamp, + Text: "Request address for transaction", + ChatId: types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)), + MessageType: protobuf.ChatMessage_ONE_TO_ONE, + ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND, + }, + CommandParameters: &CommandParameters{ + ID: messageState.CurrentMessageState.MessageID, + Value: command.Value, + Contract: command.Contract, + CommandState: CommandStateRequestAddressForTransaction, + }, + } + return m.handleCommandMessage(messageState, message) +} + +func (m *MessageHandler) HandleRequestTransaction(messageState *ReceivedMessageState, command protobuf.RequestTransaction) error { + err := ValidateReceivedRequestTransaction(&command) + if err != nil { + return err + } + message := &Message{ + ChatMessage: protobuf.ChatMessage{ + Clock: command.Clock, + Timestamp: messageState.CurrentMessageState.WhisperTimestamp, + Text: "Request transaction", + ChatId: types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)), + MessageType: protobuf.ChatMessage_ONE_TO_ONE, + ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND, + }, + CommandParameters: &CommandParameters{ + ID: messageState.CurrentMessageState.MessageID, + Value: command.Value, + Contract: command.Contract, + CommandState: CommandStateRequestTransaction, + Address: command.Address, + }, + } + return m.handleCommandMessage(messageState, message) +} + +func (m *MessageHandler) HandleAcceptRequestAddressForTransaction(messageState *ReceivedMessageState, command protobuf.AcceptRequestAddressForTransaction) error { + err := ValidateReceivedAcceptRequestAddressForTransaction(&command) + if err != nil { + return err + } + initialMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if initialMessage == nil { + return errors.New("message not found") + } + + if initialMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if initialMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if initialMessage.CommandParameters.CommandState != CommandStateRequestAddressForTransaction { + return errors.New("Wrong state for command") + } + + initialMessage.Clock = command.Clock + initialMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + initialMessage.Text = "Request address for transaction accepted" + initialMessage.CommandParameters.Address = command.Address + initialMessage.CommandParameters.CommandState = CommandStateRequestAddressForTransactionAccepted + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(command.Id) + if err != nil && err != errRecordNotFound { + return err + } + + if previousMessage != nil { + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return err + } + + initialMessage.Replace = previousMessage.ID + } + + return m.handleCommandMessage(messageState, initialMessage) +} + +func (m *MessageHandler) HandleSendTransaction(messageState *ReceivedMessageState, command protobuf.SendTransaction) error { + err := ValidateReceivedSendTransaction(&command) + if err != nil { + return err + } + transactionToValidate := &TransactionToValidate{ + MessageID: messageState.CurrentMessageState.MessageID, + CommandID: command.Id, + TransactionHash: command.TransactionHash, + FirstSeen: messageState.CurrentMessageState.WhisperTimestamp, + Signature: command.Signature, + Validate: true, + From: messageState.CurrentMessageState.PublicKey, + RetryCount: 0, + } + m.logger.Info("Saving transction to validate", zap.Any("transaction", transactionToValidate)) + + return m.persistence.SaveTransactionToValidate(transactionToValidate) +} + +func (m *MessageHandler) HandleDeclineRequestAddressForTransaction(messageState *ReceivedMessageState, command protobuf.DeclineRequestAddressForTransaction) error { + err := ValidateReceivedDeclineRequestAddressForTransaction(&command) + if err != nil { + return err + } + oldMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if oldMessage == nil { + return errors.New("message not found") + } + + if oldMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if oldMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if oldMessage.CommandParameters.CommandState != CommandStateRequestAddressForTransaction { + return errors.New("Wrong state for command") + } + + oldMessage.Clock = command.Clock + oldMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + oldMessage.Text = "Request address for transaction declined" + oldMessage.CommandParameters.CommandState = CommandStateRequestAddressForTransactionDeclined + + // Hide previous message + err = m.persistence.HideMessage(command.Id) + if err != nil { + return err + } + oldMessage.Replace = command.Id + + return m.handleCommandMessage(messageState, oldMessage) +} + +func (m *MessageHandler) HandleDeclineRequestTransaction(messageState *ReceivedMessageState, command protobuf.DeclineRequestTransaction) error { + err := ValidateReceivedDeclineRequestTransaction(&command) + if err != nil { + return err + } + oldMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if oldMessage == nil { + return errors.New("message not found") + } + + if oldMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if oldMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if oldMessage.CommandParameters.CommandState != CommandStateRequestTransaction { + return errors.New("Wrong state for command") + } + + oldMessage.Clock = command.Clock + oldMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + oldMessage.Text = "Transaction request declined" + oldMessage.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + // Hide previous message + err = m.persistence.HideMessage(command.Id) + if err != nil { + return err + } + oldMessage.Replace = command.Id + + return m.handleCommandMessage(messageState, oldMessage) +} + +func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat) (*Chat, error) { + if message.SigPubKey == nil { + m.logger.Error("public key can't be empty") + return nil, errors.New("received a message with empty public key") + } + + switch { + case message.MessageType == protobuf.ChatMessage_PUBLIC_GROUP: + // For public messages, all outgoing and incoming messages have the same chatID + // equal to a public chat name. + chatID := message.ChatId + chat := chats[chatID] + if chat == nil { + return nil, errors.New("received a public message from non-existing chat") + } + return chat, nil + case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE && isPubKeyEqual(message.SigPubKey, &m.identity.PublicKey): + // It's a private message coming from us so we rely on Message.ChatId + // If chat does not exist, it should be created to support multidevice synchronization. + chatID := message.ChatId + chat := chats[chatID] + if chat == nil { + if len(chatID) != PubKeyStringLength { + return nil, errors.New("invalid pubkey length") + } + bytePubKey, err := hex.DecodeString(chatID[2:]) + if err != nil { + return nil, errors.Wrap(err, "failed to decode hex chatID") + } + + pubKey, err := crypto.UnmarshalPubkey(bytePubKey) + if err != nil { + return nil, errors.Wrap(err, "failed to decode pubkey") + } + + newChat := CreateOneToOneChat(chatID[:8], pubKey) + chat = &newChat + } + return chat, nil + case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE: + // It's an incoming private message. ChatID is calculated from the signature. + // If a chat does not exist, a new one is created and saved. + chatID := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) + chat := chats[chatID] + if chat == nil { + // TODO: this should be a three-word name used in the mobile client + newChat := CreateOneToOneChat(chatID[:8], message.SigPubKey) + chat = &newChat + } + return chat, nil + case message.MessageType == protobuf.ChatMessage_PRIVATE_GROUP: + // In the case of a group message, ChatID is the same for all messages belonging to a group. + // It needs to be verified if the signature public key belongs to the chat. + chatID := message.ChatId + chat := chats[chatID] + if chat == nil { + return nil, errors.New("received group chat message for non-existing chat") + } + + theirKeyHex := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) + myKeyHex := types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)) + var theyJoined bool + var iJoined bool + for _, member := range chat.Members { + if member.ID == theirKeyHex && member.Joined { + theyJoined = true + } + } + for _, member := range chat.Members { + if member.ID == myKeyHex && member.Joined { + iJoined = true + } + } + + if theyJoined && iJoined { + return chat, nil + } + + return nil, errors.New("did not find a matching group chat") + default: + return nil, errors.New("can not match a chat because there is no valid case") + } +} + +func (m *MessageHandler) messageExists(messageID string, existingMessagesMap map[string]bool) (bool, error) { + if _, ok := existingMessagesMap[messageID]; ok { + return true, nil + } + + existingMessagesMap[messageID] = true + + // Check against the database, this is probably a bit slow for + // each message, but for now might do, we'll make it faster later + existingMessage, err := m.persistence.MessageByID(messageID) + if err != nil && err != errRecordNotFound { + return false, err + } + if existingMessage != nil { + return true, nil } - chat.updateChatFromProtocolGroup(newGroup) - return chat, buildSystemMessages(m.Events, translations), nil + return false, nil } diff --git a/vendor/github.com/status-im/status-go/protocol/message_processor.go b/vendor/github.com/status-im/status-go/protocol/message_processor.go index 16011cf6236..f72f10880b9 100644 --- a/vendor/github.com/status-im/status-go/protocol/message_processor.go +++ b/vendor/github.com/status-im/status-go/protocol/message_processor.go @@ -171,13 +171,40 @@ func (p *messageProcessor) sendPrivate( return messageID, nil } -func (p *messageProcessor) SendMembershipUpdate( +// sendPairInstallation sends data to the recipients, using DH +func (p *messageProcessor) SendPairInstallation( ctx context.Context, - recipients []*ecdsa.PublicKey, + recipient *ecdsa.PublicKey, + data []byte, + messageType protobuf.ApplicationMetadataMessage_Type, +) ([]byte, error) { + p.logger.Debug("sending private message", zap.Binary("recipient", crypto.FromECDSAPub(recipient))) + + wrappedMessage, err := p.wrapMessageV1(data, messageType) + if err != nil { + return nil, errors.Wrap(err, "failed to wrap message") + } + + messageSpec, err := p.protocol.BuildDHMessage(p.identity, recipient, wrappedMessage) + if err != nil { + return nil, errors.Wrap(err, "failed to encrypt message") + } + + hash, newMessage, err := p.sendMessageSpec(ctx, recipient, messageSpec) + if err != nil { + return nil, errors.Wrap(err, "failed to send a message spec") + } + + messageID := v1protocol.MessageID(&p.identity.PublicKey, wrappedMessage) + p.transport.Track([][]byte{messageID}, hash, newMessage) + + return messageID, nil +} + +func (p *messageProcessor) EncodeMembershipUpdate( group *v1protocol.Group, chatMessage *protobuf.ChatMessage, ) ([]byte, error) { - p.logger.Debug("sending a membership update", zap.Int("membersCount", len(recipients))) message := v1protocol.MembershipUpdateMessage{ ChatID: group.ChatID(), @@ -189,7 +216,7 @@ func (p *messageProcessor) SendMembershipUpdate( return nil, errors.Wrap(err, "failed to encode membership update message") } - return p.SendGroupRaw(ctx, recipients, encodedMessage, protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE) + return encodedMessage, nil } // SendPublicRaw takes encoded data, encrypts it and sends through the wire. diff --git a/vendor/github.com/status-im/status-go/protocol/message_validator.go b/vendor/github.com/status-im/status-go/protocol/message_validator.go index 43e51291987..682cc604709 100644 --- a/vendor/github.com/status-im/status-go/protocol/message_validator.go +++ b/vendor/github.com/status-im/status-go/protocol/message_validator.go @@ -2,46 +2,165 @@ package protocol import ( "errors" + "strconv" "strings" "github.com/status-im/status-go/protocol/protobuf" ) +func ValidateReceivedPairInstallation(message *protobuf.PairInstallation) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.Name)) == 0 { + return errors.New("name can't be empty") + } + + if len(strings.TrimSpace(message.DeviceType)) == 0 { + return errors.New("device type can't be empty") + } + + if len(strings.TrimSpace(message.InstallationId)) == 0 { + return errors.New("installationId can't be empty") + } + + return nil +} + +func ValidateReceivedSendTransaction(message *protobuf.SendTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.TransactionHash)) == 0 { + return errors.New("transaction hash can't be empty") + } + + if message.Signature == nil { + return errors.New("signature can't be nil") + } + + return nil +} + +func ValidateReceivedRequestAddressForTransaction(message *protobuf.RequestAddressForTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.Value)) == 0 { + return errors.New("value can't be empty") + } + + _, err := strconv.ParseFloat(message.Value, 64) + if err != nil { + return err + } + + return nil +} + +func ValidateReceivedRequestTransaction(message *protobuf.RequestTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(strings.TrimSpace(message.Value)) == 0 { + return errors.New("value can't be empty") + } + + if len(strings.TrimSpace(message.Address)) == 0 { + return errors.New("address can't be empty") + } + + _, err := strconv.ParseFloat(message.Value, 64) + if err != nil { + return err + } + + return nil +} + +func ValidateReceivedAcceptRequestAddressForTransaction(message *protobuf.AcceptRequestAddressForTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("messageID can't be empty") + } + + if len(strings.TrimSpace(message.Address)) == 0 { + return errors.New("address can't be empty") + } + + return nil +} + +func ValidateReceivedDeclineRequestAddressForTransaction(message *protobuf.DeclineRequestAddressForTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("messageID can't be empty") + } + + return nil +} + +func ValidateReceivedDeclineRequestTransaction(message *protobuf.DeclineRequestTransaction) error { + if message.Clock == 0 { + return errors.New("clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("messageID can't be empty") + } + + return nil +} + func ValidateReceivedChatMessage(message *protobuf.ChatMessage) error { if message.Clock == 0 { - return errors.New("Clock can't be 0") + return errors.New("clock can't be 0") } if message.Timestamp == 0 { - return errors.New("Timestamp can't be 0") + return errors.New("timestamp can't be 0") } if len(strings.TrimSpace(message.Text)) == 0 { - return errors.New("Text can't be empty") + return errors.New("text can't be empty") } if len(message.ChatId) == 0 { - return errors.New("ChatId can't be empty") + return errors.New("chatId can't be empty") } if message.ContentType == protobuf.ChatMessage_UNKNOWN_CONTENT_TYPE { - return errors.New("Unknown content type") + return errors.New("unknown content type") + } + + if message.ContentType == protobuf.ChatMessage_TRANSACTION_COMMAND { + return errors.New("can't receive request address for transaction from others") } if message.MessageType == protobuf.ChatMessage_UNKNOWN_MESSAGE_TYPE || message.MessageType == protobuf.ChatMessage_SYSTEM_MESSAGE_PRIVATE_GROUP { - return errors.New("Unknown message type") + return errors.New("unknown message type") } if message.ContentType == protobuf.ChatMessage_STICKER { if message.Payload == nil { - return errors.New("No sticker content") + return errors.New("no sticker content") } sticker := message.GetSticker() if sticker == nil { - return errors.New("No sticker content") + return errors.New("no sticker content") } if len(sticker.Hash) == 0 { - return errors.New("Sticker hash not set") + return errors.New("sticker hash not set") } } return nil diff --git a/vendor/github.com/status-im/status-go/protocol/messenger.go b/vendor/github.com/status-im/status-go/protocol/messenger.go index 6de0caa226b..95cbec00243 100644 --- a/vendor/github.com/status-im/status-go/protocol/messenger.go +++ b/vendor/github.com/status-im/status-go/protocol/messenger.go @@ -4,8 +4,6 @@ import ( "context" "crypto/ecdsa" "database/sql" - "encoding/hex" - "encoding/json" "math/rand" "sync" "time" @@ -52,14 +50,20 @@ type Messenger struct { transport *transport.WhisperServiceTransport encryptor *encryption.Protocol processor *messageProcessor + handler *MessageHandler logger *zap.Logger + verifyTransactionClient EthClient featureFlags featureFlags messagesPersistenceEnabled bool shutdownTasks []func() error systemMessagesTranslations map[protobuf.MembershipUpdateEvent_EventType]string allChats map[string]*Chat allContacts map[string]*Contact - mutex sync.Mutex + allInstallations map[string]*multidevice.Installation + modifiedInstallations map[string]bool + installationID string + + mutex sync.Mutex } type RawResponse struct { @@ -68,9 +72,10 @@ type RawResponse struct { } type MessengerResponse struct { - Chats []*Chat `json:"chats,omitEmpty"` - Messages []*Message `json:"messages,omitEmpty"` - Contacts []*Contact `json:"contacts,omitEmpty"` + Chats []*Chat `json:"chats,omitEmpty"` + Messages []*Message `json:"messages,omitEmpty"` + Contacts []*Contact `json:"contacts,omitEmpty"` + Installations []*multidevice.Installation `json:"installations,omitEmpty"` // Raw unprocessed messages RawMessages []*RawResponse `json:"rawMessages,omitEmpty"` } @@ -92,7 +97,6 @@ type dbConfig struct { } type config struct { - onNewInstallationsHandler func([]*multidevice.Installation) // This needs to be exposed until we move here mailserver logic // as otherwise the client is not notified of a new filter and // won't be pulling messages from mailservers until it reloads the chats/filters @@ -113,18 +117,13 @@ type config struct { dbConfig dbConfig db *sql.DB + verifyTransactionClient EthClient + logger *zap.Logger } type Option func(*config) error -func WithOnNewInstallationsHandler(h func([]*multidevice.Installation)) Option { - return func(c *config) error { - c.onNewInstallationsHandler = h - return nil - } -} - func WithSystemMessagesTranslations(t map[protobuf.MembershipUpdateEvent_EventType]string) Option { return func(c *config) error { c.systemMessagesTranslations = t @@ -160,6 +159,13 @@ func WithDatabaseConfig(dbPath, dbKey string) Option { } } +func WithVerifyTransactionClient(client EthClient) Option { + return func(c *config) error { + c.verifyTransactionClient = client + return nil + } +} + func WithDatabase(db *sql.DB) Option { return func(c *config) error { c.db = db @@ -210,18 +216,18 @@ func NewMessenger( } } - // Set default config fields. - if c.onNewInstallationsHandler == nil { - c.onNewInstallationsHandler = func(installations []*multidevice.Installation) { - sugar := logger.Sugar().With("site", "onNewInstallationsHandler") - for _, installation := range installations { - sugar.Infow( - "received a new installation", - "identity", installation.Identity, - "id", installation.ID) + onNewInstallationsHandler := func(installations []*multidevice.Installation) { + + for _, installation := range installations { + if installation.Identity == types.EncodeHex(crypto.FromECDSAPub(&messenger.identity.PublicKey)) { + if _, ok := messenger.allInstallations[installation.ID]; !ok { + messenger.allInstallations[installation.ID] = installation + messenger.modifiedInstallations[installation.ID] = true + } } } } + // Set default config fields. onNewSharedSecretHandler := func(secrets []*sharedsecret.Secret) { filters, err := messenger.handleSharedSecrets(secrets) if err != nil { @@ -295,7 +301,7 @@ func NewMessenger( encryptionProtocol := encryption.New( database, installationID, - c.onNewInstallationsHandler, + onNewInstallationsHandler, onNewSharedSecretHandler, c.onSendContactCodeHandler, logger, @@ -313,6 +319,8 @@ func NewMessenger( return nil, errors.Wrap(err, "failed to create messageProcessor") } + handler := newMessageHandler(identity, logger, &sqlitePersistence{db: database}) + messenger = &Messenger{ node: node, identity: identity, @@ -320,11 +328,16 @@ func NewMessenger( transport: t, encryptor: encryptionProtocol, processor: processor, + handler: handler, featureFlags: c.featureFlags, systemMessagesTranslations: c.systemMessagesTranslations, allChats: make(map[string]*Chat), allContacts: make(map[string]*Contact), + allInstallations: make(map[string]*multidevice.Installation), + installationID: installationID, + modifiedInstallations: make(map[string]bool), messagesPersistenceEnabled: c.messagesPersistenceEnabled, + verifyTransactionClient: c.verifyTransactionClient, shutdownTasks: []func() error{ database.Close, t.Reset, @@ -416,6 +429,15 @@ func (m *Messenger) Init() error { publicKeys = append(publicKeys, publicKey) } + installations, err := m.encryptor.GetOurInstallations(&m.identity.PublicKey) + if err != nil { + return err + } + + for _, installation := range installations { + m.allInstallations[installation.ID] = installation + } + _, err = m.transport.InitFilters(publicChatIDs, publicKeys) return err } @@ -456,21 +478,70 @@ func (m *Messenger) handleSharedSecrets(secrets []*sharedsecret.Secret) ([]*tran } func (m *Messenger) EnableInstallation(id string) error { - return m.encryptor.EnableInstallation(&m.identity.PublicKey, id) + m.mutex.Lock() + defer m.mutex.Unlock() + + installation, ok := m.allInstallations[id] + if !ok { + return errors.New("no installation found") + } + + err := m.encryptor.EnableInstallation(&m.identity.PublicKey, id) + if err != nil { + return err + } + installation.Enabled = true + m.allInstallations[id] = installation + return nil } func (m *Messenger) DisableInstallation(id string) error { - return m.encryptor.DisableInstallation(&m.identity.PublicKey, id) + m.mutex.Lock() + defer m.mutex.Unlock() + + installation, ok := m.allInstallations[id] + if !ok { + return errors.New("no installation found") + } + + err := m.encryptor.DisableInstallation(&m.identity.PublicKey, id) + if err != nil { + return err + } + installation.Enabled = false + m.allInstallations[id] = installation + return nil } -func (m *Messenger) Installations() ([]*multidevice.Installation, error) { - return m.encryptor.GetOurInstallations(&m.identity.PublicKey) +func (m *Messenger) Installations() []*multidevice.Installation { + m.mutex.Lock() + defer m.mutex.Unlock() + installations := make([]*multidevice.Installation, len(m.allInstallations)) + + var i = 0 + for _, installation := range m.allInstallations { + installations[i] = installation + i++ + } + return installations } -func (m *Messenger) SetInstallationMetadata(id string, data *multidevice.InstallationMetadata) error { +func (m *Messenger) setInstallationMetadata(id string, data *multidevice.InstallationMetadata) error { + installation, ok := m.allInstallations[id] + if !ok { + return errors.New("no installation found") + } + + installation.InstallationMetadata = data return m.encryptor.SetInstallationMetadata(&m.identity.PublicKey, id, data) } +func (m *Messenger) SetInstallationMetadata(id string, data *multidevice.InstallationMetadata) error { + m.mutex.Lock() + defer m.mutex.Unlock() + return m.setInstallationMetadata(id, data) +} + // NOT IMPLEMENTED func (m *Messenger) SelectMailserver(id string) error { return ErrNotImplemented @@ -567,9 +638,24 @@ func (m *Messenger) CreateGroupChatWithMembers(ctx context.Context, name string, return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + m.allChats[chat.ID] = &chat + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{&chat} @@ -613,9 +699,22 @@ func (m *Messenger) RemoveMemberFromGroupChat(ctx context.Context, chatID string if err != nil { return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, oldRecipients, nil); err != nil { + + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: oldRecipients, + ResendAutomatically: true, + }) + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} response.Messages = buildSystemMessages(chat.MembershipUpdates, m.systemMessagesTranslations) @@ -657,9 +756,22 @@ func (m *Messenger) AddMembersToGroupChat(ctx context.Context, chatID string, me return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} @@ -704,9 +816,22 @@ func (m *Messenger) AddAdminsToGroupChat(ctx context.Context, chatID string, mem return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} @@ -754,9 +879,21 @@ func (m *Messenger) ConfirmJoiningGroup(ctx context.Context, chatID string) (*Me return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) response.Chats = []*Chat{chat} @@ -805,9 +942,21 @@ func (m *Messenger) LeaveGroupChat(ctx context.Context, chatID string) (*Messeng return nil, err } - if _, err := m.propagateMembershipUpdates(ctx, group, recipients, nil); err != nil { + encodedMessage, err := m.processor.EncodeMembershipUpdate(group, nil) + if err != nil { + return nil, err + } + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE, + Recipients: recipients, + ResendAutomatically: true, + }) + if err != nil { return nil, err } + chat.updateChatFromProtocolGroup(group) chat.Active = false @@ -816,32 +965,6 @@ func (m *Messenger) LeaveGroupChat(ctx context.Context, chatID string) (*Messeng return &response, m.saveChat(chat) } -func (m *Messenger) propagateMembershipUpdates(ctx context.Context, group *v1protocol.Group, recipients []*ecdsa.PublicKey, chatMessage *protobuf.ChatMessage) ([]byte, error) { - hasPairedDevices, err := m.hasPairedDevices() - if err != nil { - return nil, err - } - - if !hasPairedDevices { - // Filter out my key from the recipients - n := 0 - for _, recipient := range recipients { - if !isPubKeyEqual(recipient, &m.identity.PublicKey) { - recipients[n] = recipient - n++ - } - } - recipients = recipients[:n] - } - // Finally send membership updates to all recipients. - return m.processor.SendMembershipUpdate( - ctx, - recipients, - group, - chatMessage, - ) -} - func (m *Messenger) saveChat(chat *Chat) error { err := m.persistence.SaveChat(*chat) if err != nil { @@ -902,10 +1025,12 @@ func (m *Messenger) DeleteChat(chatID string) error { return nil } -func (m *Messenger) SaveContact(contact *Contact) error { - m.mutex.Lock() - defer m.mutex.Unlock() +func (m *Messenger) isNewContact(contact *Contact) bool { + previousContact, ok := m.allContacts[contact.ID] + return contact.IsAdded() && (!ok || !previousContact.IsAdded()) +} +func (m *Messenger) saveContact(contact *Contact) error { identicon, err := identicon.GenerateBase64(contact.ID) if err != nil { return err @@ -920,6 +1045,13 @@ func (m *Messenger) SaveContact(contact *Contact) error { contact.Alias = name + if m.isNewContact(contact) { + err := m.syncContact(context.Background(), contact) + if err != nil { + return err + } + } + err = m.persistence.SaveContact(contact, nil) if err != nil { return err @@ -927,6 +1059,12 @@ func (m *Messenger) SaveContact(contact *Contact) error { m.allContacts[contact.ID] = contact return nil + +} +func (m *Messenger) SaveContact(contact *Contact) error { + m.mutex.Lock() + defer m.mutex.Unlock() + return m.saveContact(contact) } func (m *Messenger) BlockContact(contact *Contact) ([]*Chat, error) { @@ -960,26 +1098,78 @@ func timestampInMs() uint64 { } // ReSendChatMessage pulls a message from the database and sends it again -func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) (*MessengerResponse, error) { +func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) error { m.mutex.Lock() defer m.mutex.Unlock() - logger := m.logger.With(zap.String("site", "ReSendChatMessage")) - var response MessengerResponse - message, err := m.persistence.MessageByID(messageID) + message, err := m.persistence.RawMessageByID(messageID) if err != nil { - return nil, err + return err } - if message == nil { - return nil, errors.New("message not found") + + chat, ok := m.allChats[message.LocalChatID] + if !ok { + return errors.New("chat not found") + } + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: message.Payload, + MessageType: message.MessageType, + Recipients: message.Recipients, + }) + return err +} + +func (m *Messenger) hasPairedDevices() bool { + var count int + for _, i := range m.allInstallations { + if i.Enabled { + count += 1 + } } - if message.RawPayload == nil { - return nil, errors.New("message payload not found, can't resend message") + return count > 1 +} + +// sendToPairedDevices will check if we have any paired devices and send to them if necessary +func (m *Messenger) sendToPairedDevices(ctx context.Context, payload []byte, messageType protobuf.ApplicationMetadataMessage_Type) error { + hasPairedDevices := m.hasPairedDevices() + // We send a message to any paired device + if hasPairedDevices { + _, err := m.processor.SendPrivateRaw(ctx, &m.identity.PublicKey, payload, messageType) + if err != nil { + return err + } } + return nil +} - chat, ok := m.allChats[message.LocalChatID] +func (m *Messenger) dispatchPairInstallationMessage(ctx context.Context, spec *RawMessage) ([]byte, error) { + var err error + var id []byte + + id, err = m.processor.SendPairInstallation(ctx, &m.identity.PublicKey, spec.Payload, spec.MessageType) + + if err != nil { + return nil, err + } + spec.ID = types.EncodeHex(id) + spec.SendCount += 1 + err = m.persistence.SaveRawMessage(spec) + if err != nil { + return nil, err + } + + return id, nil +} + +func (m *Messenger) dispatchMessage(ctx context.Context, spec *RawMessage) ([]byte, error) { + var err error + var id []byte + logger := m.logger.With(zap.String("site", "dispatchMessage"), zap.String("chatID", spec.LocalChatID)) + chat, ok := m.allChats[spec.LocalChatID] if !ok { - return nil, errors.New("chat not found") + return nil, errors.New("no chat found") } switch chat.ChatType { @@ -988,50 +1178,51 @@ func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) (*M if err != nil { return nil, err } - logger.Debug("re-sending private message") - id, err := m.processor.SendPrivateRaw(ctx, publicKey, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - if err != nil { - return nil, err - } - message.ID = "0x" + hex.EncodeToString(id) - err = m.sendToPairedDevices(ctx, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) + if !isPubKeyEqual(publicKey, &m.identity.PublicKey) { + id, err = m.processor.SendPrivateRaw(ctx, publicKey, spec.Payload, spec.MessageType) - if err != nil { - return nil, err + if err != nil { + return nil, err + } } - case ChatTypePublic: - logger.Debug("re-sending public message", zap.String("chatName", chat.Name)) - id, err := m.processor.SendPublicRaw(ctx, chat.ID, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) + err = m.sendToPairedDevices(ctx, spec.Payload, spec.MessageType) if err != nil { return nil, err } - message.ID = "0x" + hex.EncodeToString(id) - case ChatTypePrivateGroupChat: - logger.Debug("re-sending group message", zap.String("chatName", chat.Name)) - recipients, err := chat.MembersAsPublicKeys() + + case ChatTypePublic: + logger.Debug("sending public message", zap.String("chatName", chat.Name)) + id, err = m.processor.SendPublicRaw(ctx, chat.ID, spec.Payload, spec.MessageType) if err != nil { return nil, err } - n := 0 - for _, item := range recipients { - if !isPubKeyEqual(item, &m.identity.PublicKey) { - recipients[n] = item - n++ + case ChatTypePrivateGroupChat: + logger.Debug("sending group message", zap.String("chatName", chat.Name)) + if spec.Recipients == nil { + spec.Recipients, err = chat.MembersAsPublicKeys() + if err != nil { + return nil, err } } - id, err := m.processor.SendGroupRaw(ctx, recipients[:n], message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - - if err != nil { - return nil, err + hasPairedDevices := m.hasPairedDevices() + + if !hasPairedDevices { + // Filter out my key from the recipients + n := 0 + for _, recipient := range spec.Recipients { + if !isPubKeyEqual(recipient, &m.identity.PublicKey) { + spec.Recipients[n] = recipient + n++ + } + } + spec.Recipients = spec.Recipients[:n] } - message.ID = "0x" + hex.EncodeToString(id) - - err = m.sendToPairedDevices(ctx, message.RawPayload, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - + // We always wrap in group information + id, err = m.processor.SendGroupRaw(ctx, spec.Recipients, spec.Payload, protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE) if err != nil { return nil, err } @@ -1039,34 +1230,14 @@ func (m *Messenger) ReSendChatMessage(ctx context.Context, messageID string) (*M default: return nil, errors.New("chat type not supported") } - - response.Messages = []*Message{message} - response.Chats = []*Chat{chat} - return &response, nil -} - -func (m *Messenger) hasPairedDevices() (bool, error) { - activeInstallations, err := m.encryptor.GetOurActiveInstallations(&m.identity.PublicKey) + spec.ID = types.EncodeHex(id) + spec.SendCount += 1 + err = m.persistence.SaveRawMessage(spec) if err != nil { - return false, err + return nil, err } - return len(activeInstallations) > 1, nil -} -// sendToPairedDevices will check if we have any paired devices and send to them if necessary -func (m *Messenger) sendToPairedDevices(ctx context.Context, payload []byte, messageType protobuf.ApplicationMetadataMessage_Type) error { - hasPairedDevices, err := m.hasPairedDevices() - if err != nil { - return err - } - // We send a message to any paired device - if hasPairedDevices { - _, err := m.processor.SendPrivateRaw(ctx, &m.identity.PublicKey, payload, messageType) - if err != nil { - return err - } - } - return nil + return id, nil } // SendChatMessage takes a minimal message and sends it based on the corresponding chat @@ -1083,117 +1254,64 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes return nil, errors.New("Chat not found") } - clock := chat.LastClockValue - timestamp := timestampInMs() - if clock == 0 || clock < timestamp { - clock = timestamp - } else { - clock = clock + 1 - } - - message.LocalChatID = chat.ID - message.Clock = clock - message.Timestamp = timestamp - message.From = "0x" + hex.EncodeToString(crypto.FromECDSAPub(&m.identity.PublicKey)) - message.SigPubKey = &m.identity.PublicKey - message.WhisperTimestamp = timestamp - message.Seen = true - message.OutgoingStatus = OutgoingStatusSending - - identicon, err := identicon.GenerateBase64(message.From) - if err != nil { - return nil, err - } - - message.Identicon = identicon - - alias, err := alias.GenerateFromPublicKeyString(message.From) + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) if err != nil { return nil, err } - message.Alias = alias - + var encodedMessage []byte switch chat.ChatType { case ChatTypeOneToOne: - publicKey, err := chat.PublicKey() - if err != nil { - return nil, err - } logger.Debug("sending private message") message.MessageType = protobuf.ChatMessage_ONE_TO_ONE - encodedMessage, err := proto.Marshal(message) - if err != nil { - return nil, err - } - message.RawPayload = encodedMessage - - id, err := m.processor.SendPrivateRaw(ctx, publicKey, encodedMessage, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - - if err != nil { - return nil, err - } - message.ID = "0x" + hex.EncodeToString(id) - - err = m.sendToPairedDevices(ctx, encodedMessage, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - + encodedMessage, err = proto.Marshal(message) if err != nil { return nil, err } - case ChatTypePublic: logger.Debug("sending public message", zap.String("chatName", chat.Name)) message.MessageType = protobuf.ChatMessage_PUBLIC_GROUP - encodedMessage, err := proto.Marshal(message) - if err != nil { - return nil, err - } - message.RawPayload = encodedMessage - - id, err := m.processor.SendPublicRaw(ctx, chat.ID, encodedMessage, protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) - + encodedMessage, err = proto.Marshal(message) if err != nil { return nil, err } - message.ID = "0x" + hex.EncodeToString(id) case ChatTypePrivateGroupChat: - logger.Debug("sending public message", zap.String("chatName", chat.Name)) message.MessageType = protobuf.ChatMessage_PRIVATE_GROUP logger.Debug("sending group message", zap.String("chatName", chat.Name)) - recipients, err := chat.MembersAsPublicKeys() - if err != nil { - return nil, err - } group, err := newProtocolGroupFromChat(chat) if err != nil { return nil, err } - encodedMessage, err := m.propagateMembershipUpdates(ctx, group, recipients, &message.ChatMessage) + encodedMessage, err = m.processor.EncodeMembershipUpdate(group, &message.ChatMessage) if err != nil { return nil, err } - id := v1protocol.MessageID(&m.identity.PublicKey, encodedMessage) - message.ID = "0x" + hex.EncodeToString(id) default: return nil, errors.New("chat type not supported") } - err = message.PrepareContent() + id, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_CHAT_MESSAGE, + }) if err != nil { return nil, err } - jsonMessage, err := json.Marshal(message) + message.ID = types.EncodeHex(id) + err = message.PrepareContent() if err != nil { return nil, err } - chat.LastClockValue = clock - chat.LastMessage = jsonMessage - chat.Timestamp = int64(timestamp) + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } err = m.persistence.SaveMessagesLegacy([]*Message{message}) if err != nil { @@ -1205,149 +1323,277 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes return &response, m.saveChat(chat) } -// SendRaw takes encoded data, encrypts it and sends through the wire. -// DEPRECATED -func (m *Messenger) SendRaw(ctx context.Context, chat Chat, data []byte) ([]byte, error) { - publicKey, err := chat.PublicKey() - if err != nil { - return nil, err - } - if publicKey != nil { - return m.processor.SendPrivateRaw(ctx, publicKey, data, protobuf.ApplicationMetadataMessage_UNKNOWN) - } else if chat.Name != "" { - return m.processor.SendPublicRaw(ctx, chat.Name, data, protobuf.ApplicationMetadataMessage_UNKNOWN) - } - return nil, errors.New("chat is neither public nor private") -} +// Send contact updates to all contacts added by us +func (m *Messenger) SendContactUpdates(ctx context.Context, ensName, profileImage string) error { + m.mutex.Lock() + defer m.mutex.Unlock() -// RetrieveAll retrieves messages from all filters, processes them and returns a -// MessengerResponse to the client -func (m *Messenger) RetrieveAll() (*MessengerResponse, error) { - chatWithMessages, err := m.transport.RetrieveRawAll() - if err != nil { - return nil, err + for _, contact := range m.allContacts { + if contact.IsAdded() { + if _, err := m.sendContactUpdate(ctx, contact.ID, ensName, profileImage); err != nil { + return err + } + } } + return nil - return m.handleRetrievedMessages(chatWithMessages) } -type ReceivedMessageState struct { - // Message is the protobuf message received - Message protobuf.ChatMessage - // MessageID is the ID of the message - MessageID string - // WhisperTimestamp is the whisper timestamp of the message - WhisperTimestamp uint64 - // Contact is the contact associated with the author of the message - Contact *Contact - // PublicKey is the public key of the author of the message - PublicKey *ecdsa.PublicKey - // List of chats modified - ModifiedChats map[string]bool - PostProcessor *postProcessor +// SendContactUpdate sends a contact update to a user and adds the user to contacts +func (m *Messenger) SendContactUpdate(ctx context.Context, chatID, ensName, profileImage string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + return m.sendContactUpdate(ctx, chatID, ensName, profileImage) } -func (m *Messenger) handleChatMessage(state *ReceivedMessageState) (*Message, error) { - logger := m.logger.With(zap.String("site", "handleChatMessage")) - if err := ValidateReceivedChatMessage(&state.Message); err != nil { - logger.Warn("failed to validate message", zap.Error(err)) - return nil, err +func (m *Messenger) sendContactUpdate(ctx context.Context, chatID, ensName, profileImage string) (*MessengerResponse, error) { + var response MessengerResponse + + contact, ok := m.allContacts[chatID] + if !ok { + pubkeyBytes, err := types.DecodeHex(chatID) + if err != nil { + return nil, err + } + + publicKey, err := crypto.UnmarshalPubkey(pubkeyBytes) + if err != nil { + return nil, err + } + + contact, err = buildContact(publicKey) + if err != nil { + return nil, err + } + } + + chat, ok := m.allChats[chatID] + if !ok { + publicKey, err := contact.PublicKey() + if err != nil { + return nil, err + } + chat = OneToOneFromPublicKey(publicKey) + // We don't want to show the chat to the user + chat.Active = false } - receivedMessage := &Message{ - ID: state.MessageID, - ChatMessage: state.Message, - From: state.Contact.ID, - Alias: state.Contact.Alias, - SigPubKey: state.PublicKey, - Identicon: state.Contact.Identicon, - WhisperTimestamp: state.WhisperTimestamp, + + m.allChats[chat.ID] = chat + clock, _ := chat.NextClockAndTimestamp() + + contactUpdate := &protobuf.ContactUpdate{ + Clock: clock, + EnsName: ensName, + ProfileImage: profileImage} + encodedMessage, err := proto.Marshal(contactUpdate) + if err != nil { + return nil, err } - receivedMessage.PrepareContent() - chat, err := state.PostProcessor.matchMessage(receivedMessage, m.allChats) + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chatID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_CONTACT_UPDATE, + ResendAutomatically: true, + }) if err != nil { return nil, err } - // If deleted-at is greater, ignore message - if chat.DeletedAtClockValue >= receivedMessage.Clock { - return nil, nil + if !contact.IsAdded() { + contact.SystemTags = append(contact.SystemTags, contactAdded) } - // Set the LocalChatID for the message - receivedMessage.LocalChatID = chat.ID + response.Contacts = []*Contact{contact} + response.Chats = []*Chat{chat} - if c, ok := m.allChats[chat.ID]; ok { - chat = c + chat.LastClockValue = clock + err = m.saveChat(chat) + if err != nil { + return nil, err } + return &response, m.saveContact(contact) +} + +// SendPairInstallation sends a pair installation message +func (m *Messenger) SendPairInstallation(ctx context.Context) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() - // Set the LocalChatID for the message - receivedMessage.LocalChatID = chat.ID + var err error + var response MessengerResponse - // Increase unviewed count - if !isPubKeyEqual(receivedMessage.SigPubKey, &m.identity.PublicKey) { - chat.UnviewedMessagesCount++ - } else { - // Our own message, mark as sent - receivedMessage.OutgoingStatus = OutgoingStatusSent + installation, ok := m.allInstallations[m.installationID] + if !ok { + return nil, errors.New("no installation found") } - // Update chat timestamp - chat.Timestamp = int64(timestampInMs()) - // Update last clock value - if chat.LastClockValue <= receivedMessage.Clock { - chat.LastClockValue = receivedMessage.Clock - encodedLastMessage, err := json.Marshal(receivedMessage) - if err != nil { - return nil, err - } - chat.LastMessage = encodedLastMessage + if installation.InstallationMetadata == nil { + return nil, errors.New("no installation metadata") + } + + chatID := types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)) + + chat, ok := m.allChats[chatID] + if !ok { + chat = OneToOneFromPublicKey(&m.identity.PublicKey) + // We don't want to show the chat to the user + chat.Active = false } - // Set chat active - chat.Active = true - // Set in the modified maps chat - state.ModifiedChats[chat.ID] = true m.allChats[chat.ID] = chat + clock, _ := chat.NextClockAndTimestamp() + + pairMessage := &protobuf.PairInstallation{ + Clock: clock, + Name: installation.InstallationMetadata.Name, + InstallationId: installation.ID, + DeviceType: installation.InstallationMetadata.DeviceType} + encodedMessage, err := proto.Marshal(pairMessage) + if err != nil { + return nil, err + } + + _, err = m.dispatchPairInstallationMessage(ctx, &RawMessage{ + LocalChatID: chatID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_PAIR_INSTALLATION, + ResendAutomatically: true, + }) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} - return receivedMessage, nil + chat.LastClockValue = clock + err = m.saveChat(chat) + if err != nil { + return nil, err + } + return &response, nil } -func (m *Messenger) messageExists(messageID string, existingMessagesMap map[string]bool) (bool, error) { - if _, ok := existingMessagesMap[messageID]; ok { - return true, nil +// syncContact sync as contact with paired devices +func (m *Messenger) syncContact(ctx context.Context, contact *Contact) error { + var err error + if !m.hasPairedDevices() { + return nil } + chatID := types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)) - existingMessagesMap[messageID] = true + chat, ok := m.allChats[chatID] + if !ok { + chat = OneToOneFromPublicKey(&m.identity.PublicKey) + // We don't want to show the chat to the user + chat.Active = false + } - // Check against the database, this is probably a bit slow for - // each message, but for now might do, we'll make it faster later - existingMessage, err := m.persistence.MessageByID(messageID) - if err != nil && err != errRecordNotFound { - return false, err + m.allChats[chat.ID] = chat + clock, _ := chat.NextClockAndTimestamp() + + syncMessage := &protobuf.SyncInstallationContact{ + Clock: clock, + Id: contact.ID, + EnsName: contact.Name, + ProfileImage: contact.Photo, + } + encodedMessage, err := proto.Marshal(syncMessage) + if err != nil { + return err + } + + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chatID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT, + ResendAutomatically: true, + }) + if err != nil { + return err + } + + chat.LastClockValue = clock + return m.saveChat(chat) +} + +// SendRaw takes encoded data, encrypts it and sends through the wire. +// DEPRECATED +func (m *Messenger) SendRaw(ctx context.Context, chat Chat, data []byte) ([]byte, error) { + publicKey, err := chat.PublicKey() + if err != nil { + return nil, err + } + if publicKey != nil { + return m.processor.SendPrivateRaw(ctx, publicKey, data, protobuf.ApplicationMetadataMessage_UNKNOWN) + } else if chat.Name != "" { + return m.processor.SendPublicRaw(ctx, chat.Name, data, protobuf.ApplicationMetadataMessage_UNKNOWN) } - if existingMessage != nil { - return true, nil + return nil, errors.New("chat is neither public nor private") +} + +// RetrieveAll retrieves messages from all filters, processes them and returns a +// MessengerResponse to the client +func (m *Messenger) RetrieveAll() (*MessengerResponse, error) { + chatWithMessages, err := m.transport.RetrieveRawAll() + if err != nil { + return nil, err } - return false, nil + + return m.handleRetrievedMessages(chatWithMessages) +} + +type CurrentMessageState struct { + // Message is the protobuf message received + Message protobuf.ChatMessage + // MessageID is the ID of the message + MessageID string + // WhisperTimestamp is the whisper timestamp of the message + WhisperTimestamp uint64 + // Contact is the contact associated with the author of the message + Contact *Contact + // PublicKey is the public key of the author of the message + PublicKey *ecdsa.PublicKey +} + +type ReceivedMessageState struct { + // State on the message being processed + CurrentMessageState *CurrentMessageState + // AllChats in memory + AllChats map[string]*Chat + // List of chats modified + ModifiedChats map[string]bool + // All contacts in memory + AllContacts map[string]*Contact + // List of contacs modified + ModifiedContacts map[string]bool + // All installations in memory + AllInstallations map[string]*multidevice.Installation + // List of installations modified + ModifiedInstallations map[string]bool + // Map of existing messages + ExistingMessagesMap map[string]bool + // Response to the client + Response *MessengerResponse } func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filter][]*types.Message) (*MessengerResponse, error) { m.mutex.Lock() defer m.mutex.Unlock() - response := &MessengerResponse{ - Chats: []*Chat{}, - Messages: []*Message{}, + messageState := &ReceivedMessageState{ + AllChats: m.allChats, + ModifiedChats: make(map[string]bool), + AllContacts: m.allContacts, + ModifiedContacts: make(map[string]bool), + AllInstallations: m.allInstallations, + ModifiedInstallations: m.modifiedInstallations, + ExistingMessagesMap: make(map[string]bool), + Response: &MessengerResponse{}, } - postProcessor := newPostProcessor(m, postProcessorConfig{MatchChat: true}) - logger := m.logger.With(zap.String("site", "RetrieveAll")) rawMessages := make(map[transport.Filter][]*v1protocol.StatusMessage) - modifiedChats := make(map[string]bool) - modifiedContacts := make(map[string]bool) - existingMessagesMap := make(map[string]bool) - for chat, messages := range chatWithMessages { for _, shhMessage := range messages { // TODO: fix this to use an exported method. @@ -1362,12 +1608,12 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte // Check for messages from blocked users senderID := types.EncodeHex(crypto.FromECDSAPub(publicKey)) - if _, ok := m.allContacts[senderID]; ok && m.allContacts[senderID].IsBlocked() { + if _, ok := messageState.AllContacts[senderID]; ok && messageState.AllContacts[senderID].IsBlocked() { continue } // Don't process duplicates messageID := types.EncodeHex(msg.ID) - exists, err := m.messageExists(messageID, existingMessagesMap) + exists, err := m.handler.messageExists(messageID, messageState.ExistingMessagesMap) if err != nil { logger.Warn("failed to check message exists", zap.Error(err)) } @@ -1376,7 +1622,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte } var contact *Contact - if c, ok := m.allContacts[senderID]; ok { + if c, ok := messageState.AllContacts[senderID]; ok { contact = c } else { c, err := buildContact(publicKey) @@ -1385,123 +1631,187 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte continue } contact = c - m.allContacts[senderID] = c - modifiedContacts[contact.ID] = true + messageState.AllContacts[senderID] = c + messageState.ModifiedContacts[contact.ID] = true } - messageState := &ReceivedMessageState{ + messageState.CurrentMessageState = &CurrentMessageState{ MessageID: messageID, WhisperTimestamp: uint64(msg.TransportMessage.Timestamp) * 1000, Contact: contact, PublicKey: publicKey, - ModifiedChats: modifiedChats, - PostProcessor: postProcessor, } if msg.ParsedMessage != nil { + logger.Debug("Handling parsed message") switch msg.ParsedMessage.(type) { case protobuf.MembershipUpdateMessage: + logger.Debug("Handling MembershipUpdateMessage") rawMembershipUpdate := msg.ParsedMessage.(protobuf.MembershipUpdateMessage) - membershipUpdate, err := v1protocol.MembershipUpdateMessageFromProtobuf(&rawMembershipUpdate) + + err = m.handler.HandleMembershipUpdate(messageState, messageState.AllChats[rawMembershipUpdate.ChatId], rawMembershipUpdate, m.systemMessagesTranslations) if err != nil { - logger.Warn("failed to process membership update", zap.Error(err)) + logger.Warn("failed to handle MembershipUpdate", zap.Error(err)) continue - } - chat, systemMessages, err := HandleMembershipUpdate(m.allChats[membershipUpdate.ChatID], membershipUpdate, types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)), m.systemMessagesTranslations) + case protobuf.ChatMessage: + logger.Debug("Handling ChatMessage") + messageState.CurrentMessageState.Message = msg.ParsedMessage.(protobuf.ChatMessage) + err = m.handler.HandleChatMessage(messageState) + if err != nil { + logger.Warn("failed to handle ChatMessage", zap.Error(err)) + continue + } + case protobuf.PairInstallation: + if !isPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) { + logger.Warn("not coming from us, ignoring") + continue + } + p := msg.ParsedMessage.(protobuf.PairInstallation) + logger.Debug("Handling PairInstallation", zap.Any("message", p)) + err = m.handler.HandlePairInstallation(messageState, p) if err != nil { - logger.Warn("failed to process membership update", zap.Error(err)) + logger.Warn("failed to handle PairInstallation", zap.Error(err)) continue } - for _, message := range systemMessages { - messageID := message.ID - exists, err := m.messageExists(messageID, existingMessagesMap) - if err != nil { - logger.Warn("failed to check message exists", zap.Error(err)) - } - if exists { - continue - } - response.Messages = append(response.Messages, message) + case protobuf.SyncInstallationContact: + if !isPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) { + logger.Warn("not coming from us, ignoring") + continue } - // Store in chats map as it might be a new one - m.allChats[chat.ID] = chat - // Set in the map - modifiedChats[chat.ID] = true - - if rawMembershipUpdate.Message != nil { - messageState.Message = *rawMembershipUpdate.Message - receivedMessage, err := m.handleChatMessage(messageState) - if err != nil { - logger.Warn("failed to process message", zap.Error(err)) - continue - } - // Add to response - if receivedMessage != nil { - response.Messages = append(response.Messages, receivedMessage) - } + p := msg.ParsedMessage.(protobuf.SyncInstallationContact) + logger.Debug("Handling SyncInstallationContact", zap.Any("message", p)) + err = m.handler.HandleSyncInstallationContact(messageState, p) + if err != nil { + logger.Warn("failed to handle SyncInstallationContact", zap.Error(err)) + continue + } + case protobuf.RequestAddressForTransaction: + command := msg.ParsedMessage.(protobuf.RequestAddressForTransaction) + logger.Debug("Handling RequestAddressForTransaction", zap.Any("message", command)) + err = m.handler.HandleRequestAddressForTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle RequestAddressForTransaction", zap.Error(err)) + continue + } + case protobuf.SendTransaction: + command := msg.ParsedMessage.(protobuf.SendTransaction) + logger.Debug("Handling SendTransaction", zap.Any("message", command)) + err = m.handler.HandleSendTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle SendTransaction", zap.Error(err)) + continue + } + case protobuf.AcceptRequestAddressForTransaction: + command := msg.ParsedMessage.(protobuf.AcceptRequestAddressForTransaction) + logger.Debug("Handling AcceptRequestAddressForTransaction") + err = m.handler.HandleAcceptRequestAddressForTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle AcceptRequestAddressForTransaction", zap.Error(err)) + continue + } + case protobuf.DeclineRequestAddressForTransaction: + command := msg.ParsedMessage.(protobuf.DeclineRequestAddressForTransaction) + logger.Debug("Handling DeclineRequestAddressForTransaction") + err = m.handler.HandleDeclineRequestAddressForTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle DeclineRequestAddressForTransaction", zap.Error(err)) + continue } - case protobuf.ChatMessage: - messageState.Message = msg.ParsedMessage.(protobuf.ChatMessage) - receivedMessage, err := m.handleChatMessage(messageState) + case protobuf.DeclineRequestTransaction: + command := msg.ParsedMessage.(protobuf.DeclineRequestTransaction) + logger.Debug("Handling DeclineRequestTransaction") + err = m.handler.HandleDeclineRequestTransaction(messageState, command) if err != nil { - logger.Warn("failed to process message", zap.Error(err)) + logger.Warn("failed to handle DeclineRequestTransaction", zap.Error(err)) continue } - // Add to response - if receivedMessage != nil { - response.Messages = append(response.Messages, receivedMessage) + + case protobuf.RequestTransaction: + command := msg.ParsedMessage.(protobuf.RequestTransaction) + logger.Debug("Handling RequestTransaction") + err = m.handler.HandleRequestTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle RequestTransaction", zap.Error(err)) + continue + } + case protobuf.ContactUpdate: + logger.Debug("Handling ContactUpdate") + + contactUpdate := msg.ParsedMessage.(protobuf.ContactUpdate) + + err = m.handler.HandleContactUpdate(messageState, contactUpdate) + if err != nil { + logger.Warn("failed to handle ContactUpdate", zap.Error(err)) + continue } + default: // RawMessage, not processed here, pass straight to the client rawMessages[chat] = append(rawMessages[chat], msg) } } else { + logger.Debug("Adding raw message", zap.Any("msg", msg)) rawMessages[chat] = append(rawMessages[chat], msg) } } } } - for id := range modifiedChats { - response.Chats = append(response.Chats, m.allChats[id]) + for id := range messageState.ModifiedChats { + messageState.Response.Chats = append(messageState.Response.Chats, messageState.AllChats[id]) + } + + for id := range messageState.ModifiedContacts { + messageState.Response.Contacts = append(messageState.Response.Contacts, messageState.AllContacts[id]) } - for id := range modifiedContacts { - response.Contacts = append(response.Contacts, m.allContacts[id]) + for id, _ := range messageState.ModifiedInstallations { + installation := messageState.AllInstallations[id] + messageState.Response.Installations = append(messageState.Response.Installations, installation) + if installation.InstallationMetadata != nil { + err := m.setInstallationMetadata(id, installation.InstallationMetadata) + if err != nil { + return nil, err + } + } } var err error - if len(response.Chats) > 0 { - err = m.saveChats(response.Chats) + if len(messageState.Response.Chats) > 0 { + err = m.saveChats(messageState.Response.Chats) if err != nil { return nil, err } } - if len(response.Messages) > 0 { - err = m.SaveMessages(response.Messages) + if len(messageState.Response.Messages) > 0 { + err = m.SaveMessages(messageState.Response.Messages) if err != nil { return nil, err } } - if len(response.Contacts) > 0 { - err = m.persistence.SaveContacts(response.Contacts) + if len(messageState.Response.Contacts) > 0 { + err = m.persistence.SaveContacts(messageState.Response.Contacts) if err != nil { return nil, err } } for filter, messages := range rawMessages { - response.RawMessages = append(response.RawMessages, &RawResponse{Filter: &filter, Messages: messages}) + messageState.Response.RawMessages = append(messageState.Response.RawMessages, &RawResponse{Filter: &filter, Messages: messages}) } - return response, nil + + // Reset installations + m.modifiedInstallations = make(map[string]bool) + + return messageState.Response, nil } func (m *Messenger) RequestHistoricMessages( @@ -1585,116 +1895,6 @@ func (m *Messenger) UpdateMessageOutgoingStatus(id, newOutgoingStatus string) er return m.persistence.UpdateMessageOutgoingStatus(id, newOutgoingStatus) } -// postProcessor performs a set of actions on newly retrieved messages. -// If persist is true, it saves the messages into the database. -// If matchChat is true, it matches each messages against a Chat instance. -type postProcessor struct { - myPublicKey *ecdsa.PublicKey - persistence *sqlitePersistence - logger *zap.Logger - - config postProcessorConfig -} - -type postProcessorConfig struct { - MatchChat bool // match each messages to a chat; may result in a new chat creation - Persist bool // if true, all sent and received user messages will be persisted - Parse bool // if true, it will parse the content -} - -func newPostProcessor(m *Messenger, config postProcessorConfig) *postProcessor { - return &postProcessor{ - myPublicKey: &m.identity.PublicKey, - persistence: m.persistence, - logger: m.logger, - config: config, - } -} - -func (p *postProcessor) matchMessage(message *Message, chats map[string]*Chat) (*Chat, error) { - if message.SigPubKey == nil { - p.logger.Error("public key can't be empty") - return nil, errors.New("received a message with empty public key") - } - - switch { - case message.MessageType == protobuf.ChatMessage_PUBLIC_GROUP: - // For public messages, all outgoing and incoming messages have the same chatID - // equal to a public chat name. - chatID := message.ChatId - chat := chats[chatID] - if chat == nil { - return nil, errors.New("received a public message from non-existing chat") - } - return chat, nil - case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE && isPubKeyEqual(message.SigPubKey, p.myPublicKey): - // It's a private message coming from us so we rely on Message.ChatId - // If chat does not exist, it should be created to support multidevice synchronization. - chatID := message.ChatId - chat := chats[chatID] - if chat == nil { - if len(chatID) != PubKeyStringLength { - return nil, errors.New("invalid pubkey length") - } - bytePubKey, err := hex.DecodeString(chatID[2:]) - if err != nil { - return nil, errors.Wrap(err, "failed to decode hex chatID") - } - - pubKey, err := crypto.UnmarshalPubkey(bytePubKey) - if err != nil { - return nil, errors.Wrap(err, "failed to decode pubkey") - } - - newChat := CreateOneToOneChat(chatID[:8], pubKey) - chat = &newChat - } - return chat, nil - case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE: - // It's an incoming private message. ChatID is calculated from the signature. - // If a chat does not exist, a new one is created and saved. - chatID := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) - chat := chats[chatID] - if chat == nil { - // TODO: this should be a three-word name used in the mobile client - newChat := CreateOneToOneChat(chatID[:8], message.SigPubKey) - chat = &newChat - } - return chat, nil - case message.MessageType == protobuf.ChatMessage_PRIVATE_GROUP: - // In the case of a group message, ChatID is the same for all messages belonging to a group. - // It needs to be verified if the signature public key belongs to the chat. - chatID := message.ChatId - chat := chats[chatID] - if chat == nil { - return nil, errors.New("received group chat message for non-existing chat") - } - - theirKeyHex := types.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) - myKeyHex := types.EncodeHex(crypto.FromECDSAPub(p.myPublicKey)) - var theyJoined bool - var iJoined bool - for _, member := range chat.Members { - if member.ID == theirKeyHex && member.Joined { - theyJoined = true - } - } - for _, member := range chat.Members { - if member.ID == myKeyHex && member.Joined { - iJoined = true - } - } - - if theyJoined && iJoined { - return chat, nil - } - - return nil, errors.New("did not find a matching group chat") - default: - return nil, errors.New("can not match a chat because there is no valid case") - } -} - // Identicon returns an identicon based on the input string func Identicon(id string) (string, error) { return identicon.GenerateBase64(id) @@ -1750,3 +1950,700 @@ func (m *Messenger) VerifyENSNames(rpcEndpoint, contractAddress string, ensDetai func GenerateAlias(id string) (string, error) { return alias.GenerateFromPublicKeyString(id) } + +func (m *Messenger) RequestTransaction(ctx context.Context, chatID, value, contract, address string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + message := &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.Text = "Request transaction" + + request := &protobuf.RequestTransaction{ + Clock: message.Clock, + Address: address, + Value: value, + Contract: contract, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + id, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_REQUEST_TRANSACTION, + ResendAutomatically: true, + }) + + message.CommandParameters = &CommandParameters{ + ID: types.EncodeHex(id), + Value: value, + Address: address, + Contract: contract, + CommandState: CommandStateRequestTransaction, + } + + if err != nil { + return nil, err + } + messageID := types.EncodeHex(id) + + message.ID = messageID + message.CommandParameters.ID = messageID + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) RequestAddressForTransaction(ctx context.Context, chatID, from, value, contract string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + message := &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.Text = "Request address for transaction" + + request := &protobuf.RequestAddressForTransaction{ + Clock: message.Clock, + Value: value, + Contract: contract, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + id, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION, + ResendAutomatically: true, + }) + + message.CommandParameters = &CommandParameters{ + ID: types.EncodeHex(id), + From: from, + Value: value, + Contract: contract, + CommandState: CommandStateRequestAddressForTransaction, + } + + if err != nil { + return nil, err + } + messageID := types.EncodeHex(id) + + message.ID = messageID + message.CommandParameters.ID = messageID + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) AcceptRequestAddressForTransaction(ctx context.Context, messageID, address string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Request address for transaction accepted" + message.OutgoingStatus = OutgoingStatusSending + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(messageID) + if err != nil { + return nil, err + } + + if previousMessage == nil { + return nil, errors.New("No previous message found") + } + + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return nil, err + } + + message.Replace = previousMessage.ID + + request := &protobuf.AcceptRequestAddressForTransaction{ + Clock: message.Clock, + Id: messageID, + Address: address, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.Address = address + message.CommandParameters.CommandState = CommandStateRequestAddressForTransactionAccepted + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) DeclineRequestTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Transaction request declined" + message.OutgoingStatus = OutgoingStatusSending + message.Replace = messageID + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.DeclineRequestTransaction{ + Clock: message.Clock, + Id: messageID, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Request address for transaction declined" + message.OutgoingStatus = OutgoingStatusSending + message.Replace = messageID + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.DeclineRequestAddressForTransaction{ + Clock: message.Clock, + Id: messageID, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.CommandState = CommandStateRequestAddressForTransactionDeclined + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) AcceptRequestTransaction(ctx context.Context, transactionHash, messageID string, signature []byte) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Transaction sent" + message.OutgoingStatus = OutgoingStatusSending + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(messageID) + if err != nil && err != errRecordNotFound { + return nil, err + } + + if previousMessage != nil { + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return nil, err + } + message.Replace = previousMessage.ID + } + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.SendTransaction{ + Clock: message.Clock, + Id: messageID, + TransactionHash: transactionHash, + Signature: signature, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_SEND_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.TransactionHash = transactionHash + message.CommandParameters.Signature = signature + message.CommandParameters.CommandState = CommandStateTransactionSent + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) SendTransaction(ctx context.Context, chatID, transactionHash string, signature []byte) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + message := &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.LocalChatID = chatID + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.WhisperTimestamp = timestamp + message.Timestamp = timestamp + message.Text = "Transaction sent" + + request := &protobuf.SendTransaction{ + Clock: message.Clock, + TransactionHash: transactionHash, + Signature: signature, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_SEND_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters = &CommandParameters{ + TransactionHash: transactionHash, + Signature: signature, + CommandState: CommandStateTransactionSent, + } + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + +func (m *Messenger) ValidateTransactions(ctx context.Context, addresses []types.Address) (*MessengerResponse, error) { + if m.verifyTransactionClient == nil { + return nil, nil + } + m.mutex.Lock() + defer m.mutex.Unlock() + + modifiedChats := make(map[string]bool) + + logger := m.logger.With(zap.String("site", "ValidateTransactions")) + logger.Debug("Validating transactions") + txs, err := m.persistence.TransactionsToValidate() + if err != nil { + logger.Error("Error pulling", zap.Error(err)) + return nil, err + } + logger.Debug("Txs", zap.Int("count", len(txs)), zap.Any("txs", txs)) + var response MessengerResponse + validator := NewTransactionValidator(addresses, m.persistence, m.verifyTransactionClient, m.logger) + responses, err := validator.ValidateTransactions(ctx) + if err != nil { + logger.Error("Error validating", zap.Error(err)) + return nil, err + } + for _, validationResult := range responses { + var message *Message + chatID := types.EncodeHex(crypto.FromECDSAPub(validationResult.Transaction.From)) + chat, ok := m.allChats[chatID] + if !ok { + chat = OneToOneFromPublicKey(validationResult.Transaction.From) + } + if validationResult.Message != nil { + message = validationResult.Message + } else { + message = &Message{} + err := extendMessageFromChat(message, chat, &m.identity.PublicKey) + if err != nil { + return nil, err + } + } + + message.MessageType = protobuf.ChatMessage_ONE_TO_ONE + message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND + message.LocalChatID = chatID + message.OutgoingStatus = "" + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.Timestamp = timestamp + message.WhisperTimestamp = timestamp + message.Text = "Transaction received" + + message.ID = validationResult.Transaction.MessageID + if message.CommandParameters == nil { + message.CommandParameters = &CommandParameters{} + } else { + message.CommandParameters = validationResult.Message.CommandParameters + } + + message.CommandParameters.Value = validationResult.Value + message.CommandParameters.Contract = validationResult.Contract + message.CommandParameters.Address = validationResult.Address + message.CommandParameters.CommandState = CommandStateTransactionSent + message.CommandParameters.TransactionHash = validationResult.Transaction.TransactionHash + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + // Hide previous message + previousMessage, err := m.persistence.MessageByCommandID(message.CommandParameters.ID) + if err != nil && err != errRecordNotFound { + return nil, err + } + + if previousMessage != nil { + err = m.persistence.HideMessage(previousMessage.ID) + if err != nil { + return nil, err + } + message.Replace = previousMessage.ID + } + + response.Messages = append(response.Messages, message) + m.allChats[chat.ID] = chat + modifiedChats[chat.ID] = true + + } + for id, _ := range modifiedChats { + response.Chats = append(response.Chats, m.allChats[id]) + } + + if len(response.Messages) > 0 { + err = m.SaveMessages(response.Messages) + if err != nil { + return nil, err + } + } + return &response, nil +} diff --git a/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go b/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go index 4ff613eac70..597b517f4bc 100644 --- a/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go +++ b/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go @@ -1,15 +1,7 @@ // Code generated by go-bindata. DO NOT EDIT. // sources: -// 000001_init.down.db.sql (82B) -// 000001_init.up.db.sql (832B) -// 000002_add_chats.down.db.sql (74B) -// 000002_add_chats.up.db.sql (495B) -// 000003_add_contacts.down.db.sql (21B) -// 000003_add_contacts.up.db.sql (381B) -// 000004_user_messages_compatibility.down.sql (33B) -// 000004_user_messages_compatibility.up.sql (980B) -// 1567112142_user_messages.down.sql (26B) -// 1567112142_user_messages.up.sql (543B) +// 000001_init.down.db.sql (65B) +// 000001_init.up.db.sql (2.693kB) // doc.go (377B) package migrations @@ -79,7 +71,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var __000001_initDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\xb6\xe6\x42\x92\xc9\x4d\xcd\x4d\x4a\x2d\x2a\xce\xc8\x2c\x88\x2f\x2d\x48\x49\x2c\x41\x93\x4e\xce\x48\x2c\x89\x87\xaa\xb1\xe6\x02\x04\x00\x00\xff\xff\x69\x98\x5e\xa1\x52\x00\x00\x00") +var __000001_initDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x48\xce\x48\x2c\x29\xb6\xe6\x42\x12\x29\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x45\x95\x49\xce\xcf\x2b\x49\x4c\x06\x29\x07\x04\x00\x00\xff\xff\x61\x86\xbd\x5f\x41\x00\x00\x00") func _000001_initDownDbSqlBytes() ([]byte, error) { return bindataRead( @@ -94,12 +86,12 @@ func _000001_initDownDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.down.db.sql", size: 82, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe8, 0x5f, 0xe0, 0x6, 0xfc, 0xed, 0xb7, 0xff, 0xb5, 0xf3, 0x33, 0x45, 0x1, 0x5b, 0x84, 0x80, 0x74, 0x60, 0x81, 0xa6, 0x8b, 0xb4, 0xd4, 0xad, 0x10, 0xa8, 0xb3, 0x61, 0x6f, 0xc5, 0x2f, 0xaa}} + info := bindataFileInfo{name: "000001_init.down.db.sql", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1577718673, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5e, 0xbb, 0x3f, 0x1, 0x75, 0x19, 0x70, 0x86, 0xa7, 0x34, 0x40, 0x17, 0x34, 0x3e, 0x18, 0x51, 0x79, 0xd4, 0x22, 0xad, 0x8f, 0x80, 0xcc, 0xa6, 0xcc, 0x6, 0x2b, 0x62, 0x2, 0x47, 0xba, 0xf9}} return a, nil } -var __000001_initUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x92\xcd\x6e\xea\x30\x10\x85\xf7\x79\x8a\x59\x12\x89\xc5\xdd\xdf\x95\x03\x13\xb0\x9a\xda\xad\xe3\x14\x58\x45\x26\x71\xc1\x85\x84\x08\x1b\xa9\xbc\x7d\x45\x7e\x68\x48\xab\x0a\x96\x9e\x39\x3e\x9e\xef\x8c\x27\x02\x89\x44\x90\x24\x88\x10\x68\x08\x8c\x4b\xc0\x25\x8d\x65\x0c\x27\xab\x8f\x69\xa1\xad\x55\x1b\x6d\x61\xe4\x01\x00\x98\x1c\x82\x88\x07\x90\x30\xfa\x9a\x60\xad\x66\x49\x14\x8d\xeb\x66\xb6\x55\x2e\x35\x39\xbc\x11\x31\x99\x13\x31\xec\x1e\x4a\xa7\x4b\x97\xba\x73\xa5\x81\x32\xd9\x54\x5b\xff\x41\xd5\xe9\x4f\x07\x12\x97\xed\x31\xdb\x1f\xb2\x1d\x04\x74\xf6\x2d\x30\x85\xb6\x4e\x15\xd5\x4d\xb5\x7b\xa2\x1b\xa4\xe7\xd0\x3d\x7e\x6b\x5c\x9d\xd6\x7b\x93\xa5\x3b\x7d\xae\xb1\x9a\xe2\xfb\x5e\x6d\xec\x65\x96\x2b\x00\x4c\x31\x24\x49\x24\xe1\x9f\xe7\xff\xf7\xbc\x36\x33\xca\xa6\xb8\xec\xa0\x2d\x70\x76\x9b\xd8\xa8\xed\xf4\x6e\xfc\x96\x72\xa1\x8b\xb5\x3e\xda\xad\xa9\xd2\x53\x95\x2b\xd7\x8f\xba\x0b\xf2\x45\xd0\x67\x22\x56\xf0\x84\xab\x41\xa8\xb9\x72\xaa\xd9\xc8\x23\xab\x08\xb9\x40\x3a\x63\xb5\xdf\x75\x4c\x10\x18\xa2\x40\x36\xc1\xb8\xbe\x6e\x47\x26\xf7\x3d\x1f\x16\x54\xce\x79\x22\x41\xf0\x05\x9d\xfe\xcd\x52\x5b\xb5\x40\x2d\xc5\x20\xe1\x87\xc6\x54\x79\x61\x4a\x08\x38\x8f\x90\xb0\x9f\xcb\x08\x49\x14\x63\xa3\xfc\x38\x98\x52\xe7\x77\x49\xef\x67\x6f\xf4\xcd\x4f\xef\x94\xe3\x1e\x90\x7f\xf9\x0c\x5f\x01\x00\x00\xff\xff\x22\x17\x48\xa6\x40\x03\x00\x00") +var __000001_initUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x56\x51\x6f\xe3\x36\x0c\x7e\xf7\xaf\x20\xb0\x87\xb6\x80\x3b\xdc\x80\xdb\x6d\x40\x9f\xd2\x9e\xbb\x05\xcb\x92\x43\xea\x0e\xbd\x27\x81\x91\xd8\x58\x88\x2d\x19\x12\x9d\x5c\x80\xfb\xf1\x83\x9c\x38\xb1\x12\xa7\xbd\x61\x7d\x28\x5a\x52\x24\xc5\x8f\xfc\x3e\xf9\x61\x9e\x8d\xf2\x0c\xf2\xd1\xfd\x24\x83\xf1\x23\x4c\x67\x39\x64\x2f\xe3\xa7\xfc\x09\x64\x81\xec\xe1\x3a\xd1\x0a\xfe\x19\xcd\x1f\xfe\x1c\xcd\xe1\xcb\x7c\xfc\xf7\x68\xfe\x15\xfe\xca\xbe\xc2\x6c\x0a\x0f\xb3\xe9\xe3\x64\xfc\x90\xc3\x3c\xfb\x32\x19\x3d\x64\x69\x62\xb0\xa2\xc3\xe9\x90\x6b\xfa\x3c\x99\xa4\x89\xb4\xa5\x75\x67\x76\xf8\x9c\x3d\x8e\x9e\x27\x39\x5c\xfd\x84\xbf\xfc\xfe\x9b\xfa\xf5\x2a\x4d\x78\x5b\x13\x8c\xa7\x79\x2f\x18\x25\xeb\x35\xc1\xfd\x6c\x36\xc9\x46\xd3\xf3\xe8\x7c\xfe\x9c\xa5\x09\xeb\x8a\x3c\x63\x55\x9f\x44\x2b\x2a\x89\x49\x09\x64\x21\x4b\x2b\x57\x62\x8d\x65\x13\x97\x38\x64\xfa\x90\x26\x75\xb3\x28\xb5\x14\x2b\xda\xc2\xfd\x64\x76\x9f\x26\x8d\x59\x6b\xda\x90\x12\x15\x79\x8f\x4b\x12\xd2\x36\x86\x2f\xc6\x97\xe8\x7f\xac\x50\x7b\x70\x9f\x73\x5f\xaa\xa2\x6a\x41\xce\xc7\xff\x15\xba\x16\x4d\xad\x90\x69\xe7\x48\x6e\xee\x92\x24\x9a\x9a\xb4\x86\x51\xb6\xa3\x02\xd0\x0a\xf2\xec\x25\x7f\x7f\x52\x00\xa8\x94\x23\xef\x77\xe7\x8f\x80\x01\xb4\x43\x3c\xb3\x92\xf1\x62\x4d\x4e\xbf\x6a\x52\x87\x61\x74\x0d\x3d\x8e\x26\x4f\xd9\xe9\x29\x81\x97\x71\x02\xc0\x52\xe3\x40\x71\xad\xc8\xb0\x96\xd6\x9c\xbb\xea\xc2\xb2\x3d\x37\xb7\x48\xee\x20\x52\x6f\xd4\xf3\x5b\xcf\x54\x09\xc6\x65\x87\x30\x80\xa2\xb5\x96\x24\xb4\x79\xb5\x07\x1b\x3b\xbd\x68\x98\x04\x5b\xc1\x58\xae\xe2\x7a\x2d\xfa\xb7\xb7\x30\xe6\x2b\x0f\xba\xaa\xad\x63\x34\x0c\x5c\x60\xf8\xa5\x3d\x30\x2e\x4a\x82\x02\x3d\x38\xbb\xd1\x0a\xd0\xc3\x86\xc0\x51\xb9\x05\x6b\x40\x73\x08\xde\x14\x64\x42\x70\x49\x55\xe8\xd5\x2c\x41\x9b\x57\x6d\x34\xd3\xad\x97\xce\x96\xe5\xcf\xc9\x1b\xb4\x6c\x3c\xb9\x6e\x71\x76\x33\x6f\xa7\xfe\xc3\x14\x0d\xe7\x37\x85\xf6\x35\x39\x11\x91\x26\xfb\x23\x9b\x47\xc0\x02\x78\xdb\x38\x39\xb0\x0b\x01\x39\xcf\xda\x20\x6b\x6b\x0e\xc8\x01\x30\x7d\xe3\x01\xfa\x07\x57\xd8\x52\x32\x2c\x06\x08\x1e\xdc\xa1\xab\xbe\x78\xec\xf3\x5d\x20\x75\x9b\xb0\x40\x16\xbd\xc6\x63\x6f\x69\x25\x96\xe2\xed\x33\x85\x56\x74\x79\x93\x01\x1c\xf9\xda\x1a\x1f\x56\x21\xbe\x56\x27\x05\x5d\x2f\xfb\x0b\x5d\x60\xfd\x1e\x4a\x22\x73\x59\xc3\x7a\x55\x6d\xc3\x4b\xab\xcd\x52\x78\x46\x6e\x7c\x5c\xb9\x46\xe7\x49\x89\x16\xe7\x23\xec\x0e\x37\xa2\xc6\x6d\x69\x51\xf5\xac\x9e\xb5\x5c\x91\x13\x35\xca\xd5\xf1\x96\x9d\xb5\x40\x5f\xc4\xb9\xa5\xad\x2a\x34\xaa\x87\x57\x6c\xdf\x75\x36\xe8\xea\xa4\x64\xd0\xf9\xea\x6c\x35\xec\x09\x3b\xe1\x50\xf2\xb0\x97\x1d\x1a\x1f\xc4\xdf\x9a\x37\x6e\xeb\xf5\xd2\x20\x37\x8e\x7a\x9d\x1f\x7c\x8c\xdc\xce\xa2\x2f\x9a\xe3\xe9\xe7\xec\x05\xb4\xfa\x26\xf6\xdb\x3d\x9b\xc6\x9c\xba\xde\xd9\x6f\xee\x06\x22\x08\x9d\x2c\xc4\x62\x7b\xd8\xac\xd9\x14\x4e\xa2\x77\x28\x37\x0b\xcf\xee\xfa\xea\xc3\xff\xfc\xb9\x82\xef\xdf\xfb\x8b\x95\xc2\xed\xa7\x8f\x29\x7c\xfa\x78\x13\x1c\x5a\xa5\x1d\x0d\xd2\x76\x9b\xcf\x1f\x87\x58\x3b\xc2\xa2\x44\xd2\xf1\xdf\x84\xe3\x7d\x52\xb5\x5a\xec\xe9\xe4\x81\x6c\xe5\x97\xda\x81\x9f\xbe\x9d\x7b\x17\x5f\xe6\xa1\xa3\x36\x14\x1b\xb6\x15\xb2\x96\x58\x96\xdb\xcb\xa7\x87\xa8\xe9\x48\xea\x5a\x93\xe1\xa3\xf0\xf7\xd9\xf2\x0e\x66\x21\x23\x99\x65\x50\xcb\xe3\x42\xfa\xf0\x3c\xac\xb1\xd4\xe1\xd5\x69\x91\xec\x0a\xc7\xec\x39\xe7\x54\xd4\xf9\xa5\x15\xef\x0f\x63\xd7\x01\xbb\xed\x11\xbd\x60\x7a\xd5\xae\x85\x9a\x4c\x67\x89\x99\x10\xd7\xe9\x5d\xf6\x14\xba\xdd\xe7\x13\xc0\xc9\x97\xcf\x20\x63\x06\xb1\x88\xa0\x08\x7c\x78\x1f\xb1\xeb\xde\xdf\x37\x77\xc9\xbf\x01\x00\x00\xff\xff\xc7\x20\x3e\x09\x85\x0a\x00\x00") func _000001_initUpDbSqlBytes() ([]byte, error) { return bindataRead( @@ -114,168 +106,8 @@ func _000001_initUpDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.up.db.sql", size: 832, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x1c, 0xa4, 0xac, 0x0, 0xd3, 0x19, 0x53, 0x35, 0x91, 0x1c, 0x94, 0xea, 0xde, 0xa7, 0x75, 0xb6, 0x73, 0x1d, 0x42, 0x14, 0xca, 0x84, 0x5b, 0xdb, 0x10, 0x94, 0x28, 0xc0, 0x33, 0x95, 0x7f, 0xf}} - return a, nil -} - -var __000002_add_chatsDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\xc8\x4d\xcd\x4d\x4a\x2d\x2a\xce\xc8\x2c\x88\x2f\x2d\x48\x49\x2c\x49\x2d\xb6\xe6\x42\x92\x4e\xce\x48\x2c\x89\x87\xaa\xc1\x90\x28\xb6\xe6\x02\x04\x00\x00\xff\xff\xde\x59\xf6\x29\x4a\x00\x00\x00") - -func _000002_add_chatsDownDbSqlBytes() ([]byte, error) { - return bindataRead( - __000002_add_chatsDownDbSql, - "000002_add_chats.down.db.sql", - ) -} - -func _000002_add_chatsDownDbSql() (*asset, error) { - bytes, err := _000002_add_chatsDownDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000002_add_chats.down.db.sql", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd3, 0xa7, 0xf0, 0x94, 0x7a, 0x9, 0xdc, 0x6c, 0x7b, 0xdc, 0x12, 0x30, 0x55, 0x31, 0x17, 0xf2, 0xcc, 0x6e, 0xfd, 0xbb, 0x70, 0xb9, 0xd8, 0x9f, 0x81, 0x83, 0xdc, 0x1d, 0x1c, 0x3a, 0x8d, 0xce}} - return a, nil -} - -var __000002_add_chatsUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x91\xc1\x6a\x32\x31\x14\x85\xf7\xf7\x29\x2e\xfc\x0b\xff\xc2\x2c\xda\x45\x69\xc1\x55\x66\x8c\x74\x68\x3a\x91\x18\x4b\x5d\x85\x98\xb9\xd4\xc1\xc4\x19\x4c\xc6\xe2\xdb\x17\xdb\x41\xb4\x52\xe8\x32\xb9\xdf\x77\xce\xe2\x14\x8a\x33\xcd\x51\xb3\x5c\x70\x2c\xa7\x58\x49\x8d\xfc\xad\x9c\xeb\x39\xba\xb5\x4d\x11\xff\x43\x53\xe3\x2b\x53\xc5\x13\x53\x38\x53\xe5\x0b\x53\x4b\x7c\xe6\x4b\x94\x15\x16\xb2\x9a\x8a\xb2\xd0\xa8\xf8\x4c\xb0\x82\x67\xb0\xb5\x81\x4e\xf4\x31\xab\x5a\x08\x91\x81\x6b\x7d\xbb\xbb\xfa\xc7\x09\x9f\xb2\x85\xd0\x38\xfa\x67\xef\x1e\x1f\xea\xfb\x51\x06\xe9\xd0\x11\x96\x95\x3e\x93\xad\x4b\xcd\x9e\x30\x97\x52\x70\x56\x5d\xdb\x5a\x2d\x78\x06\xa9\x09\x14\x93\x0d\xdd\x0f\xbb\x26\x4f\x89\x6a\x63\x93\x71\xbe\x75\x1b\xb3\xb7\xbe\xbf\xac\x38\x25\xdd\x66\xd0\xf5\x2b\xdf\x38\xb3\xa1\x03\xe6\x42\xe6\x19\xf4\xdb\x7d\x43\x1f\x54\x9b\x40\x31\xda\x77\x32\xae\xed\xb7\xe9\x57\xdf\xdb\xf8\xb7\xa2\x2f\x70\xc8\x1c\xaa\x02\x85\x15\xed\xe2\xe5\x6b\xdd\x74\xa6\xef\x6a\x9b\xe8\xfb\x00\x37\x63\x00\x98\x28\x39\x1b\x46\xbb\xe6\xc6\xe7\xe7\xe3\x8a\x66\x60\xc6\xf0\x19\x00\x00\xff\xff\x99\xae\x9f\xf2\xef\x01\x00\x00") - -func _000002_add_chatsUpDbSqlBytes() ([]byte, error) { - return bindataRead( - __000002_add_chatsUpDbSql, - "000002_add_chats.up.db.sql", - ) -} - -func _000002_add_chatsUpDbSql() (*asset, error) { - bytes, err := _000002_add_chatsUpDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000002_add_chats.up.db.sql", size: 495, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6e, 0xca, 0x2b, 0xf7, 0xca, 0x21, 0xda, 0x17, 0x1f, 0x97, 0xa8, 0x12, 0xb5, 0x6c, 0xad, 0x92, 0xe7, 0x2, 0xaf, 0x1, 0xcb, 0x5e, 0xe9, 0x71, 0xc4, 0x81, 0xa7, 0x3, 0x93, 0x5b, 0x73, 0x73}} - return a, nil -} - -var __000003_add_contactsDownDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x48\xce\xcf\x2b\x49\x4c\x2e\x29\xb6\xe6\x02\x04\x00\x00\xff\xff\x66\x64\xd9\xdd\x15\x00\x00\x00") - -func _000003_add_contactsDownDbSqlBytes() ([]byte, error) { - return bindataRead( - __000003_add_contactsDownDbSql, - "000003_add_contacts.down.db.sql", - ) -} - -func _000003_add_contactsDownDbSql() (*asset, error) { - bytes, err := _000003_add_contactsDownDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000003_add_contacts.down.db.sql", size: 21, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfc, 0x7e, 0xb, 0xec, 0x72, 0xcd, 0x21, 0x3e, 0xa2, 0x38, 0xe0, 0x95, 0x7e, 0xce, 0x4a, 0x17, 0xc8, 0xd0, 0x1c, 0xfa, 0xa3, 0x23, 0x5, 0xab, 0x89, 0xf9, 0xfc, 0x63, 0x7, 0x28, 0xe9, 0x93}} - return a, nil -} - -var __000003_add_contactsUpDbSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x8d\x41\x4b\x33\x31\x14\x45\xf7\xf3\x2b\xee\xf2\xfb\xc0\x85\x7b\x57\x99\xf1\x15\x06\x63\x52\xc6\x14\xec\x2a\xc4\xc9\xab\x06\xa7\x49\x99\xbc\x16\xfc\xf7\x52\x85\x8a\x8e\xb8\x3d\xf7\x70\x4f\x37\x90\x72\x04\xa7\x5a\x4d\x18\x4b\x96\x30\x4a\xc5\xbf\x06\x48\x11\x8e\x1e\x1d\xd6\x43\x7f\xaf\x86\x2d\xee\x68\x0b\x6b\xd0\x59\xb3\xd2\x7d\xe7\x30\xd0\x5a\xab\x8e\xae\x1a\x20\xc4\x38\x73\xad\x9f\xbe\xb1\x0e\x66\xa3\xf5\x79\xc8\x61\xcf\x4b\xca\xb9\xfa\x13\xcf\x69\x97\x38\xa2\xb5\x56\x93\x32\xb8\xa5\x95\xda\x68\x87\x95\xd2\x0f\xf4\xd3\xf2\x41\xd0\x9b\xaf\x97\x8b\x7d\xfd\x91\x9f\x52\xf8\x25\x9e\x22\x67\x49\x63\xc9\xcb\xe9\xf0\x52\xa4\x2c\xf1\x14\xaa\xf8\xe3\x21\x06\xe1\xf8\x47\xaf\xbe\x55\xe1\xbd\x97\xf0\x5c\xd1\x6a\xdb\x9e\x59\xe4\x53\x1a\xd9\xa7\xbc\x2b\x17\x26\x73\x7a\x3a\x0a\x7b\x29\x5e\xc2\xf4\xfa\xbd\xd7\xfc\xbf\x69\xde\x03\x00\x00\xff\xff\xc5\xff\x5b\xb1\x7d\x01\x00\x00") - -func _000003_add_contactsUpDbSqlBytes() ([]byte, error) { - return bindataRead( - __000003_add_contactsUpDbSql, - "000003_add_contacts.up.db.sql", - ) -} - -func _000003_add_contactsUpDbSql() (*asset, error) { - bytes, err := _000003_add_contactsUpDbSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000003_add_contacts.up.db.sql", size: 381, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x45, 0xfe, 0x1e, 0xf2, 0x75, 0x33, 0x37, 0x8e, 0x7f, 0x93, 0x6f, 0x16, 0xbb, 0xf8, 0xa4, 0x70, 0x6b, 0xe0, 0xc1, 0x4f, 0x99, 0x8d, 0xc8, 0x2d, 0x40, 0xf1, 0xed, 0x65, 0x90, 0xc3, 0xad, 0xc7}} - return a, nil -} - -var __000004_user_messages_compatibilityDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\x8e\xcf\x49\x4d\x4f\x4c\xae\xb4\xe6\x02\x04\x00\x00\xff\xff\x25\xef\xa4\x66\x21\x00\x00\x00") - -func _000004_user_messages_compatibilityDownSqlBytes() ([]byte, error) { - return bindataRead( - __000004_user_messages_compatibilityDownSql, - "000004_user_messages_compatibility.down.sql", - ) -} - -func _000004_user_messages_compatibilityDownSql() (*asset, error) { - bytes, err := _000004_user_messages_compatibilityDownSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000004_user_messages_compatibility.down.sql", size: 33, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb9, 0xaf, 0x48, 0x80, 0x3d, 0x54, 0x5e, 0x53, 0xee, 0x98, 0x26, 0xbb, 0x99, 0x6a, 0xd8, 0x37, 0x94, 0xf2, 0xf, 0x82, 0xfa, 0xb7, 0x6a, 0x68, 0xcd, 0x8b, 0xe2, 0xc4, 0x6, 0x25, 0xdc, 0x6}} - return a, nil -} - -var __000004_user_messages_compatibilityUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x52\xc1\x6e\xda\x40\x10\xbd\xf3\x15\x73\x0b\x48\xb8\xca\x21\xca\x25\x27\x43\x96\xd6\xaa\x6b\x47\xc6\xa9\xc8\x69\xb5\xd8\x53\xbc\x62\xbd\x6b\xed\x8c\x4b\x2c\xe5\xe3\x2b\x03\x26\x40\x51\x2f\xf5\xc1\x87\x79\x33\x6f\xde\xdb\x79\x41\x00\x11\xdf\x11\xe8\xba\x71\x9e\x95\x65\xe0\x4a\xf5\x3f\x4d\xc0\x6a\x6d\x10\x2a\x45\xe0\xdd\x4e\x97\xa0\x08\x76\x08\x1e\x4d\x07\xce\x82\xe6\x51\x10\xc0\xae\x42\xdb\x0f\x1b\xac\xd1\xb2\xb6\x1b\xd0\xf6\x97\xb6\x9a\x31\xa0\xc2\x3b\x63\xbe\x8c\xe6\x99\x08\x73\x01\x79\x38\x8b\x05\x44\x0b\x48\xd2\x1c\xc4\x2a\x5a\xe6\x4b\x68\x09\xbd\xac\x91\x48\x6d\x90\xa4\xc1\x8d\x2a\x3a\x18\x8f\x00\x00\x74\x09\x3f\xc3\x6c\xfe\x2d\xcc\xe0\x25\x8b\x7e\x84\xd9\x1b\x7c\x17\x6f\x90\x26\x30\x4f\x93\x45\x1c\xcd\x73\xc8\xc4\x4b\x1c\xce\xc5\x74\xdf\xbf\xab\x34\x35\xe8\x25\xeb\x1a\x89\x55\xdd\x40\x94\xe4\xe2\xab\xc8\xf6\xfb\x92\xd7\x38\x3e\xf4\x91\x6b\x7d\x81\x90\x8b\x55\x7e\x85\x94\x48\xac\xad\x62\xed\x2c\xcc\xe2\x74\x76\xa8\x32\xbe\xf3\x49\xc9\xe5\x40\xe1\x2c\xa3\x65\xc9\x5d\x83\xfd\xb6\x2b\xb8\x37\x67\x55\x8d\xc3\xf4\x91\xef\x5c\xdf\x35\x61\xa5\x58\x9e\x19\xbf\x44\x8d\x2b\x94\x91\xff\xee\xf1\xc8\xbe\x93\x85\x6b\x2d\x5f\xf0\xc3\xb3\x58\x84\xaf\x71\x0e\xf7\x43\x1f\x35\xce\x12\x4a\x76\x97\xf2\x8e\xc7\x38\x79\x3a\x0a\x33\xae\xd8\xca\xdf\xca\xb4\xb7\x8c\x12\xa2\x85\x59\x9a\xc6\x22\x4c\xfe\xde\xb8\x08\xe3\xe5\xf1\x46\xae\xe5\x8d\xd3\x76\x23\x89\x15\xb7\x74\xb9\xb9\x51\x9e\xb0\x94\xfb\xf7\xfe\x7c\x7e\xaf\x76\xb2\x51\x9d\x71\xaa\x3c\xab\x12\xeb\x62\x8b\x5e\x36\xaa\xd8\x7e\xaa\x1c\xaa\x95\xa2\x6a\xe0\x1e\x4d\x9e\x46\x43\x02\xa3\xe4\x59\xac\x40\x97\xef\xf2\x18\x82\x34\xb9\x99\xc0\xf1\x01\x9e\x3c\xdd\x18\x44\xe5\x8b\x4a\xae\xbb\xd3\x1d\xd2\x04\x6e\x93\x1c\x24\xb5\x6b\x62\x3f\xbe\xbb\xff\xcf\xef\x0e\x3e\x3e\xce\xaf\x30\x85\xe0\xf1\x61\x0a\x8f\x0f\x93\x1e\xd0\xe5\x74\xc8\x4e\xef\xf7\x4f\x00\x00\x00\xff\xff\x91\x46\x82\xd5\xd4\x03\x00\x00") - -func _000004_user_messages_compatibilityUpSqlBytes() ([]byte, error) { - return bindataRead( - __000004_user_messages_compatibilityUpSql, - "000004_user_messages_compatibility.up.sql", - ) -} - -func _000004_user_messages_compatibilityUpSql() (*asset, error) { - bytes, err := _000004_user_messages_compatibilityUpSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "000004_user_messages_compatibility.up.sql", size: 980, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc, 0x7a, 0xba, 0xae, 0x6d, 0xef, 0x69, 0x12, 0x6b, 0x48, 0xe3, 0xa7, 0xad, 0x21, 0x4a, 0xcf, 0x4f, 0xbc, 0x14, 0xc1, 0x19, 0x69, 0x1c, 0xc, 0xa2, 0x3d, 0xbc, 0x12, 0x32, 0x71, 0x76, 0x15}} - return a, nil -} - -var __1567112142_user_messagesDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\xb6\xe6\x02\x04\x00\x00\xff\xff\xa9\xe2\x72\x97\x1a\x00\x00\x00") - -func _1567112142_user_messagesDownSqlBytes() ([]byte, error) { - return bindataRead( - __1567112142_user_messagesDownSql, - "1567112142_user_messages.down.sql", - ) -} - -func _1567112142_user_messagesDownSql() (*asset, error) { - bytes, err := _1567112142_user_messagesDownSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "1567112142_user_messages.down.sql", size: 26, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x79, 0x8e, 0xbe, 0x63, 0x64, 0x52, 0xa3, 0x13, 0x83, 0xc7, 0x47, 0xff, 0x56, 0xa9, 0xc, 0x72, 0xb4, 0x97, 0x6, 0xc7, 0xa5, 0x68, 0xb6, 0x55, 0x6a, 0xd5, 0xb0, 0x12, 0xfb, 0x4c, 0xa5, 0x27}} - return a, nil -} - -var __1567112142_user_messagesUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\x4f\x4d\x73\x9b\x30\x14\xbc\xf3\x2b\xf6\x96\x64\xa6\xce\xf4\x9e\x13\x06\xb9\x65\x86\xc1\x2d\x96\xdb\xdc\x3c\x42\x7a\x09\x1a\x0b\x89\x41\x8f\x3a\xfc\xfb\x0e\x04\x37\x75\x8e\x6f\x77\xdf\x7e\x6c\x36\xc8\x87\xd0\x43\xf9\x09\xfd\x40\x7f\x6c\x18\xa3\x9b\xa0\x07\x52\x4c\x06\x63\xa4\xe1\xd4\x51\x8c\xea\x95\x22\x58\x35\x8e\x1e\x93\xcd\x06\xbf\x09\x26\xf8\x3b\x86\x27\x32\xe0\x80\xc8\x6a\x42\xa3\xf4\xf9\xa2\x06\x03\x1d\xba\x5e\xb1\x6d\x1c\xe1\x62\xb9\x85\xe5\xf9\xa9\x21\xad\xc6\x48\xb0\x7c\x17\xe1\x03\xcf\xee\x66\x4e\xbe\xb4\x34\x10\xe8\x4d\x53\xcf\x78\x09\x03\xb8\x25\xe8\xe0\x63\x70\x04\xed\x2c\x79\x7e\x4c\xf2\x7a\xff\x03\x32\xdd\x96\xe2\xb6\xd5\x53\x92\x64\xb5\x48\xa5\x58\xc9\x62\x87\x6a\x2f\x21\x9e\x8b\x83\x3c\x7c\x1a\x70\x9f\x00\x80\x35\xd8\x96\xfb\x2d\x8e\x55\xf1\xf3\x28\x16\x75\x75\x2c\xcb\x2f\x0b\xa9\x5b\xc5\x27\x6b\xf0\x2b\xad\xb3\xef\x69\xfd\x8f\x45\x2d\x76\xa2\x16\x55\x26\x0e\x8b\x26\xde\x5b\xf3\x80\x7d\x85\x5c\x94\x42\x0a\x64\xe9\x21\x4b\x73\xb1\x9a\x04\xcf\xe4\xf9\xc4\x53\x4f\x28\x2a\xf9\x8e\xae\x35\x3e\xa1\x4c\x6f\x0c\x29\x9e\xd7\x53\xbb\xa0\xcf\xd8\x16\xdf\x3e\x04\xb6\xa3\xc8\xaa\xeb\x6f\xd0\x6b\xc4\xb5\xef\x7f\x0e\xd7\xf0\x5b\xe3\x7e\x6c\x9c\xd5\xa7\x33\x4d\xcb\xfa\x77\xf0\xc5\xa9\xd7\x38\x77\xf9\xd8\x99\x8b\x5d\x7a\x2c\x25\xbe\x26\x0f\x4f\xc9\xdf\x00\x00\x00\xff\xff\x6e\x1c\xcd\x6f\x1f\x02\x00\x00") - -func _1567112142_user_messagesUpSqlBytes() ([]byte, error) { - return bindataRead( - __1567112142_user_messagesUpSql, - "1567112142_user_messages.up.sql", - ) -} - -func _1567112142_user_messagesUpSql() (*asset, error) { - bytes, err := _1567112142_user_messagesUpSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "1567112142_user_messages.up.sql", size: 543, mode: os.FileMode(0644), modTime: time.Unix(1575563165, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xff, 0xc0, 0x47, 0x32, 0xa9, 0xa4, 0x6, 0x63, 0x6b, 0xe7, 0x79, 0x2b, 0x80, 0x52, 0x2b, 0x6f, 0xf9, 0x9d, 0x9a, 0xc2, 0xa9, 0x7a, 0xf7, 0x4d, 0x14, 0x12, 0x21, 0x10, 0xc4, 0x30, 0x42, 0xaa}} + info := bindataFileInfo{name: "000001_init.up.db.sql", size: 2693, mode: os.FileMode(0644), modTime: time.Unix(1577718868, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0x9f, 0x6, 0x64, 0xcf, 0x97, 0xbe, 0xa8, 0xa2, 0x2f, 0xda, 0xc5, 0x9d, 0x26, 0x3, 0x65, 0x98, 0x8a, 0x7a, 0x6a, 0xc3, 0xd, 0x3f, 0x25, 0xfe, 0x4c, 0x5, 0xdb, 0x98, 0xa9, 0xf9, 0xf}} return a, nil } @@ -394,22 +226,6 @@ var _bindata = map[string]func() (*asset, error){ "000001_init.up.db.sql": _000001_initUpDbSql, - "000002_add_chats.down.db.sql": _000002_add_chatsDownDbSql, - - "000002_add_chats.up.db.sql": _000002_add_chatsUpDbSql, - - "000003_add_contacts.down.db.sql": _000003_add_contactsDownDbSql, - - "000003_add_contacts.up.db.sql": _000003_add_contactsUpDbSql, - - "000004_user_messages_compatibility.down.sql": _000004_user_messages_compatibilityDownSql, - - "000004_user_messages_compatibility.up.sql": _000004_user_messages_compatibilityUpSql, - - "1567112142_user_messages.down.sql": _1567112142_user_messagesDownSql, - - "1567112142_user_messages.up.sql": _1567112142_user_messagesUpSql, - "doc.go": docGo, } @@ -454,17 +270,9 @@ type bintree struct { } var _bintree = &bintree{nil, map[string]*bintree{ - "000001_init.down.db.sql": &bintree{_000001_initDownDbSql, map[string]*bintree{}}, - "000001_init.up.db.sql": &bintree{_000001_initUpDbSql, map[string]*bintree{}}, - "000002_add_chats.down.db.sql": &bintree{_000002_add_chatsDownDbSql, map[string]*bintree{}}, - "000002_add_chats.up.db.sql": &bintree{_000002_add_chatsUpDbSql, map[string]*bintree{}}, - "000003_add_contacts.down.db.sql": &bintree{_000003_add_contactsDownDbSql, map[string]*bintree{}}, - "000003_add_contacts.up.db.sql": &bintree{_000003_add_contactsUpDbSql, map[string]*bintree{}}, - "000004_user_messages_compatibility.down.sql": &bintree{_000004_user_messages_compatibilityDownSql, map[string]*bintree{}}, - "000004_user_messages_compatibility.up.sql": &bintree{_000004_user_messages_compatibilityUpSql, map[string]*bintree{}}, - "1567112142_user_messages.down.sql": &bintree{_1567112142_user_messagesDownSql, map[string]*bintree{}}, - "1567112142_user_messages.up.sql": &bintree{_1567112142_user_messagesUpSql, map[string]*bintree{}}, - "doc.go": &bintree{docGo, map[string]*bintree{}}, + "000001_init.down.db.sql": &bintree{_000001_initDownDbSql, map[string]*bintree{}}, + "000001_init.up.db.sql": &bintree{_000001_initUpDbSql, map[string]*bintree{}}, + "doc.go": &bintree{docGo, map[string]*bintree{}}, }} // RestoreAsset restores an asset under the given directory. diff --git a/vendor/github.com/status-im/status-go/protocol/persistence.go b/vendor/github.com/status-im/status-go/protocol/persistence.go index 3100b3bb119..265b7f1c26e 100644 --- a/vendor/github.com/status-im/status-go/protocol/persistence.go +++ b/vendor/github.com/status-im/status-go/protocol/persistence.go @@ -7,6 +7,7 @@ import ( "encoding/gob" "github.com/pkg/errors" + "github.com/status-im/status-go/eth-node/crypto" ) var ( @@ -347,6 +348,99 @@ func (db sqlitePersistence) Contacts() ([]*Contact, error) { return response, nil } +func (db sqlitePersistence) SaveRawMessage(message *RawMessage) error { + var pubKeys [][]byte + for _, pk := range message.Recipients { + pubKeys = append(pubKeys, crypto.CompressPubkey(pk)) + } + // Encode recipients + var encodedRecipients bytes.Buffer + encoder := gob.NewEncoder(&encodedRecipients) + + if err := encoder.Encode(pubKeys); err != nil { + return err + } + + _, err := db.db.Exec(` + INSERT INTO + raw_messages + ( + id, + local_chat_id, + last_sent, + send_count, + sent, + message_type, + resend_automatically, + recipients, + payload + ) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, + message.ID, + message.LocalChatID, + message.LastSent, + message.SendCount, + message.Sent, + message.MessageType, + message.ResendAutomatically, + encodedRecipients.Bytes(), + message.Payload) + return err +} + +func (db sqlitePersistence) RawMessageByID(id string) (*RawMessage, error) { + var rawPubKeys [][]byte + var encodedRecipients []byte + message := &RawMessage{} + + err := db.db.QueryRow(` + SELECT + id, + local_chat_id, + last_sent, + send_count, + sent, + message_type, + resend_automatically, + recipients, + payload + FROM + raw_messages + WHERE + id = ?`, + id, + ).Scan( + &message.ID, + &message.LocalChatID, + &message.LastSent, + &message.SendCount, + &message.Sent, + &message.MessageType, + &message.ResendAutomatically, + &encodedRecipients, + &message.Payload, + ) + if err != nil { + return nil, err + } + + // Restore recipients + decoder := gob.NewDecoder(bytes.NewBuffer(encodedRecipients)) + err = decoder.Decode(&rawPubKeys) + if err != nil { + return nil, err + } + for _, pkBytes := range rawPubKeys { + pubkey, err := crypto.UnmarshalPubkey(pkBytes) + if err != nil { + return nil, err + } + message.Recipients = append(message.Recipients, pubkey) + } + + return message, nil +} + func (db sqlitePersistence) SaveContact(contact *Contact, tx *sql.Tx) (err error) { if tx == nil { tx, err = db.db.BeginTx(context.Background(), &sql.TxOptions{}) @@ -417,3 +511,89 @@ func (db sqlitePersistence) SaveContact(contact *Contact, tx *sql.Tx) (err error ) return } + +func (db sqlitePersistence) SaveTransactionToValidate(transaction *TransactionToValidate) error { + compressedKey := crypto.CompressPubkey(transaction.From) + + _, err := db.db.Exec(`INSERT INTO messenger_transactions_to_validate( + command_id, + message_id, + transaction_hash, + retry_count, + first_seen, + public_key, + signature, + to_validate) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, + transaction.CommandID, + transaction.MessageID, + transaction.TransactionHash, + transaction.RetryCount, + transaction.FirstSeen, + compressedKey, + transaction.Signature, + transaction.Validate, + ) + + return err +} + +func (db sqlitePersistence) UpdateTransactionToValidate(transaction *TransactionToValidate) error { + _, err := db.db.Exec(`UPDATE messenger_transactions_to_validate + SET retry_count = ?, to_validate = ? + WHERE transaction_hash = ?`, + transaction.RetryCount, + transaction.Validate, + transaction.TransactionHash, + ) + return err +} + +func (db sqlitePersistence) TransactionsToValidate() ([]*TransactionToValidate, error) { + var transactions []*TransactionToValidate + rows, err := db.db.Query(` + SELECT + command_id, + message_id, + transaction_hash, + retry_count, + first_seen, + public_key, + signature, + to_validate + FROM messenger_transactions_to_validate + WHERE to_validate = 1; + `) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var t TransactionToValidate + var pkBytes []byte + err = rows.Scan( + &t.CommandID, + &t.MessageID, + &t.TransactionHash, + &t.RetryCount, + &t.FirstSeen, + &pkBytes, + &t.Signature, + &t.Validate, + ) + if err != nil { + return nil, err + } + + publicKey, err := crypto.DecompressPubkey(pkBytes) + if err != nil { + return nil, err + } + t.From = publicKey + + transactions = append(transactions, &t) + } + + return transactions, nil +} diff --git a/vendor/github.com/status-im/status-go/protocol/persistence_legacy.go b/vendor/github.com/status-im/status-go/protocol/persistence_legacy.go index 55975a6ce77..ed4364c4a5c 100644 --- a/vendor/github.com/status-im/status-go/protocol/persistence_legacy.go +++ b/vendor/github.com/status-im/status-go/protocol/persistence_legacy.go @@ -26,15 +26,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllFields() string { timestamp, chat_id, local_chat_id, - retry_count, message_type, clock_value, seen, outgoing_status, parsed_text, - raw_payload, sticker_pack, sticker_hash, + command_id, + command_value, + command_from, + command_address, + command_contract, + command_transaction_hash, + command_state, + command_signature, response_to` } @@ -48,15 +54,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllFieldsJoin() string { m1.timestamp, m1.chat_id, m1.local_chat_id, - m1.retry_count, m1.message_type, m1.clock_value, m1.seen, m1.outgoing_status, m1.parsed_text, - m1.raw_payload, m1.sticker_pack, m1.sticker_hash, + m1.command_id, + m1.command_value, + m1.command_from, + m1.command_address, + m1.command_contract, + m1.command_transaction_hash, + m1.command_state, + m1.command_signature, m1.response_to, m2.source, m2.text, @@ -79,6 +91,7 @@ func (db sqlitePersistence) tableUserMessagesLegacyScanAllFields(row scanner, me var identicon sql.NullString sticker := &protobuf.StickerMessage{} + command := &CommandParameters{} args := []interface{}{ &message.ID, @@ -90,15 +103,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyScanAllFields(row scanner, me &message.Timestamp, &message.ChatId, &message.LocalChatID, - &message.RetryCount, &message.MessageType, &message.Clock, &message.Seen, &message.OutgoingStatus, &message.ParsedText, - &message.RawPayload, &sticker.Pack, &sticker.Hash, + &command.ID, + &command.Value, + &command.From, + &command.Address, + &command.Contract, + &command.TransactionHash, + &command.CommandState, + &command.Signature, &message.ResponseTo, "edFrom, "edText, @@ -122,6 +141,10 @@ func (db sqlitePersistence) tableUserMessagesLegacyScanAllFields(row scanner, me message.Payload = &protobuf.ChatMessage_Sticker{Sticker: sticker} } + if message.ContentType == protobuf.ChatMessage_TRANSACTION_COMMAND { + message.CommandParameters = command + } + return nil } @@ -130,6 +153,10 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllValues(message *Message) ( if sticker == nil { sticker = &protobuf.StickerMessage{} } + command := message.CommandParameters + if command == nil { + command = &CommandParameters{} + } return []interface{}{ message.ID, message.WhisperTimestamp, @@ -140,15 +167,21 @@ func (db sqlitePersistence) tableUserMessagesLegacyAllValues(message *Message) ( message.Timestamp, message.ChatId, message.LocalChatID, - message.RetryCount, message.MessageType, message.Clock, message.Seen, message.OutgoingStatus, message.ParsedText, - message.RawPayload, sticker.Pack, sticker.Hash, + command.ID, + command.Value, + command.From, + command.Address, + command.Contract, + command.TransactionHash, + command.CommandState, + command.Signature, message.ResponseTo, }, nil } @@ -178,9 +211,9 @@ func (db sqlitePersistence) messageByID(tx *sql.Tx, id string) (*Message, error) SELECT %s FROM - user_messages_legacy m1 + user_messages m1 LEFT JOIN - user_messages_legacy m2 + user_messages m2 ON m1.response_to = m2.id @@ -204,6 +237,44 @@ func (db sqlitePersistence) messageByID(tx *sql.Tx, id string) (*Message, error) } } +func (db sqlitePersistence) MessageByCommandID(id string) (*Message, error) { + + var message Message + + allFields := db.tableUserMessagesLegacyAllFieldsJoin() + row := db.db.QueryRow( + fmt.Sprintf(` + SELECT + %s + FROM + user_messages m1 + LEFT JOIN + user_messages m2 + ON + m1.response_to = m2.id + + LEFT JOIN + contacts c + ON + m1.source = c.id + WHERE + m1.command_id = ? + ORDER BY m1.clock_value DESC + LIMIT 1 + `, allFields), + id, + ) + err := db.tableUserMessagesLegacyScanAllFields(row, &message) + switch err { + case sql.ErrNoRows: + return nil, errRecordNotFound + case nil: + return &message, nil + default: + return nil, err + } +} + func (db sqlitePersistence) MessageByID(id string) (*Message, error) { return db.messageByID(nil, id) } @@ -220,7 +291,7 @@ func (db sqlitePersistence) MessagesExist(ids []string) (map[string]bool, error) } inVector := strings.Repeat("?, ", len(ids)-1) + "?" - query := fmt.Sprintf(`SELECT id FROM user_messages_legacy WHERE id IN (%s)`, inVector) + query := fmt.Sprintf(`SELECT id FROM user_messages WHERE id IN (%s)`, inVector) rows, err := db.db.Query(query, idsArgs...) if err != nil { return nil, err @@ -261,9 +332,9 @@ func (db sqlitePersistence) MessageByChatID(chatID string, currCursor string, li %s, substr('0000000000000000000000000000000000000000000000000000000000000000' || m1.clock_value, -64, 64) || m1.id as cursor FROM - user_messages_legacy m1 + user_messages m1 LEFT JOIN - user_messages_legacy m2 + user_messages m2 ON m1.response_to = m2.id @@ -273,7 +344,7 @@ func (db sqlitePersistence) MessageByChatID(chatID string, currCursor string, li m1.source = c.id WHERE - m1.local_chat_id = ? %s + m1.hide != 1 AND m1.local_chat_id = ? %s ORDER BY cursor DESC LIMIT ? `, allFields, cursorWhere), @@ -324,7 +395,7 @@ func (db sqlitePersistence) SaveMessagesLegacy(messages []*Message) (err error) allFields := db.tableUserMessagesLegacyAllFields() valuesVector := strings.Repeat("?, ", db.tableUserMessagesLegacyAllFieldsCount()-1) + "?" - query := fmt.Sprintf(`INSERT INTO user_messages_legacy(%s) VALUES (%s)`, allFields, valuesVector) + query := fmt.Sprintf(`INSERT INTO user_messages(%s) VALUES (%s)`, allFields, valuesVector) stmt, err := tx.Prepare(query) if err != nil { return @@ -346,12 +417,17 @@ func (db sqlitePersistence) SaveMessagesLegacy(messages []*Message) (err error) } func (db sqlitePersistence) DeleteMessage(id string) error { - _, err := db.db.Exec(`DELETE FROM user_messages_legacy WHERE id = ?`, id) + _, err := db.db.Exec(`DELETE FROM user_messages WHERE id = ?`, id) + return err +} + +func (db sqlitePersistence) HideMessage(id string) error { + _, err := db.db.Exec(`UPDATE user_messages SET hide = 1 WHERE id = ?`, id) return err } func (db sqlitePersistence) DeleteMessagesByChatID(id string) error { - _, err := db.db.Exec(`DELETE FROM user_messages_legacy WHERE local_chat_id = ?`, id) + _, err := db.db.Exec(`DELETE FROM user_messages WHERE local_chat_id = ?`, id) return err } @@ -377,7 +453,7 @@ func (db sqlitePersistence) MarkMessagesSeen(chatID string, ids []string) error inVector := strings.Repeat("?, ", len(ids)-1) + "?" _, err = tx.Exec( fmt.Sprintf(` - UPDATE user_messages_legacy + UPDATE user_messages SET seen = 1 WHERE id IN (%s) `, inVector), @@ -391,7 +467,7 @@ func (db sqlitePersistence) MarkMessagesSeen(chatID string, ids []string) error `UPDATE chats SET unviewed_message_count = (SELECT COUNT(1) - FROM user_messages_legacy + FROM user_messages WHERE local_chat_id = ? AND seen = 0) WHERE id = ?`, chatID, chatID) return err @@ -399,7 +475,7 @@ func (db sqlitePersistence) MarkMessagesSeen(chatID string, ids []string) error func (db sqlitePersistence) UpdateMessageOutgoingStatus(id string, newOutgoingStatus string) error { _, err := db.db.Exec(` - UPDATE user_messages_legacy + UPDATE user_messages SET outgoing_status = ? WHERE id = ? `, newOutgoingStatus, id) @@ -425,7 +501,7 @@ func (db sqlitePersistence) BlockContact(contact *Contact) ([]*Chat, error) { // Delete messages _, err = tx.Exec( `DELETE - FROM user_messages_legacy + FROM user_messages WHERE source = ?`, contact.ID, ) @@ -449,7 +525,7 @@ func (db sqlitePersistence) BlockContact(contact *Contact) ([]*Chat, error) { _, err = tx.Exec(` UPDATE chats SET - unviewed_message_count = (SELECT COUNT(1) FROM user_messages_legacy WHERE seen = 0 AND local_chat_id = chats.id)`) + unviewed_message_count = (SELECT COUNT(1) FROM user_messages WHERE seen = 0 AND local_chat_id = chats.id)`) if err != nil { return nil, err } @@ -461,7 +537,7 @@ func (db sqlitePersistence) BlockContact(contact *Contact) ([]*Chat, error) { } for _, c := range chats { var lastMessageID string - row := tx.QueryRow(`SELECT id FROM user_messages_legacy WHERE local_chat_id = ? ORDER BY clock_value DESC LIMIT 1`, c.ID) + row := tx.QueryRow(`SELECT id FROM user_messages WHERE local_chat_id = ? ORDER BY clock_value DESC LIMIT 1`, c.ID) switch err := row.Scan(&lastMessageID); err { case nil: diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go index 7b439229ffd..bd650fdd6b5 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go @@ -24,30 +24,57 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type ApplicationMetadataMessage_Type int32 const ( - ApplicationMetadataMessage_UNKNOWN ApplicationMetadataMessage_Type = 0 - ApplicationMetadataMessage_CHAT_MESSAGE ApplicationMetadataMessage_Type = 1 - ApplicationMetadataMessage_CONTACT_REQUEST ApplicationMetadataMessage_Type = 2 - ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE ApplicationMetadataMessage_Type = 3 - ApplicationMetadataMessage_PAIR_INSTALLATION ApplicationMetadataMessage_Type = 4 - ApplicationMetadataMessage_SYNC_INSTALLATION ApplicationMetadataMessage_Type = 5 + ApplicationMetadataMessage_UNKNOWN ApplicationMetadataMessage_Type = 0 + ApplicationMetadataMessage_CHAT_MESSAGE ApplicationMetadataMessage_Type = 1 + ApplicationMetadataMessage_CONTACT_UPDATE ApplicationMetadataMessage_Type = 2 + ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE ApplicationMetadataMessage_Type = 3 + ApplicationMetadataMessage_PAIR_INSTALLATION ApplicationMetadataMessage_Type = 4 + ApplicationMetadataMessage_SYNC_INSTALLATION ApplicationMetadataMessage_Type = 5 + ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 6 + ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 7 + ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 8 + ApplicationMetadataMessage_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 9 + ApplicationMetadataMessage_SEND_TRANSACTION ApplicationMetadataMessage_Type = 10 + ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 11 + ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT ApplicationMetadataMessage_Type = 12 + ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT ApplicationMetadataMessage_Type = 13 + ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT ApplicationMetadataMessage_Type = 14 ) var ApplicationMetadataMessage_Type_name = map[int32]string{ - 0: "UNKNOWN", - 1: "CHAT_MESSAGE", - 2: "CONTACT_REQUEST", - 3: "MEMBERSHIP_UPDATE_MESSAGE", - 4: "PAIR_INSTALLATION", - 5: "SYNC_INSTALLATION", + 0: "UNKNOWN", + 1: "CHAT_MESSAGE", + 2: "CONTACT_UPDATE", + 3: "MEMBERSHIP_UPDATE_MESSAGE", + 4: "PAIR_INSTALLATION", + 5: "SYNC_INSTALLATION", + 6: "REQUEST_ADDRESS_FOR_TRANSACTION", + 7: "ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION", + 8: "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION", + 9: "REQUEST_TRANSACTION", + 10: "SEND_TRANSACTION", + 11: "DECLINE_REQUEST_TRANSACTION", + 12: "SYNC_INSTALLATION_CONTACT", + 13: "SYNC_INSTALLATION_ACCOUNT", + 14: "SYNC_INSTALLATION_PUBLIC_CHAT", } var ApplicationMetadataMessage_Type_value = map[string]int32{ - "UNKNOWN": 0, - "CHAT_MESSAGE": 1, - "CONTACT_REQUEST": 2, - "MEMBERSHIP_UPDATE_MESSAGE": 3, - "PAIR_INSTALLATION": 4, - "SYNC_INSTALLATION": 5, + "UNKNOWN": 0, + "CHAT_MESSAGE": 1, + "CONTACT_UPDATE": 2, + "MEMBERSHIP_UPDATE_MESSAGE": 3, + "PAIR_INSTALLATION": 4, + "SYNC_INSTALLATION": 5, + "REQUEST_ADDRESS_FOR_TRANSACTION": 6, + "ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION": 7, + "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION": 8, + "REQUEST_TRANSACTION": 9, + "SEND_TRANSACTION": 10, + "DECLINE_REQUEST_TRANSACTION": 11, + "SYNC_INSTALLATION_CONTACT": 12, + "SYNC_INSTALLATION_ACCOUNT": 13, + "SYNC_INSTALLATION_PUBLIC_CHAT": 14, } func (x ApplicationMetadataMessage_Type) String() string { @@ -124,22 +151,29 @@ func init() { func init() { proto.RegisterFile("application_metadata_message.proto", fileDescriptor_ad09a6406fcf24c7) } var fileDescriptor_ad09a6406fcf24c7 = []byte{ - // 269 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x8e, 0x41, 0x4b, 0xc3, 0x30, - 0x18, 0x86, 0x6d, 0x57, 0x9d, 0x7e, 0x0e, 0xad, 0x11, 0xa1, 0x8a, 0xc2, 0xe8, 0x69, 0x5e, 0x7a, - 0xd0, 0xb3, 0x87, 0x58, 0x83, 0x2b, 0xae, 0x69, 0x4d, 0x52, 0xc4, 0x53, 0xc8, 0x5c, 0x1c, 0x85, - 0x6d, 0x0d, 0x6b, 0x76, 0xe8, 0x2f, 0xf0, 0x57, 0xf8, 0x5f, 0x65, 0xd5, 0x39, 0x3c, 0x78, 0x0a, - 0xef, 0x93, 0xf7, 0xe1, 0xfd, 0x20, 0x54, 0xc6, 0xcc, 0xca, 0x37, 0x65, 0xcb, 0x6a, 0x21, 0xe7, - 0xda, 0xaa, 0x89, 0xb2, 0x4a, 0xce, 0x75, 0x5d, 0xab, 0xa9, 0x8e, 0xcc, 0xb2, 0xb2, 0x15, 0xda, - 0x6f, 0x9f, 0xf1, 0xea, 0x3d, 0xfc, 0x74, 0xe1, 0x02, 0x6f, 0x85, 0xf4, 0xa7, 0x9f, 0x7e, 0xd7, - 0xd1, 0x25, 0x1c, 0xd4, 0xe5, 0x74, 0xa1, 0xec, 0x6a, 0xa9, 0x03, 0xa7, 0xef, 0x0c, 0x7a, 0x6c, - 0x0b, 0x50, 0x00, 0x5d, 0xa3, 0x9a, 0x59, 0xa5, 0x26, 0x81, 0xdb, 0xfe, 0x6d, 0x22, 0xba, 0x03, - 0xcf, 0x36, 0x46, 0x07, 0x9d, 0xbe, 0x33, 0x38, 0xba, 0xb9, 0x8e, 0x36, 0x7b, 0xd1, 0xff, 0x5b, - 0x91, 0x68, 0x8c, 0x66, 0xad, 0x16, 0x7e, 0x38, 0xe0, 0xad, 0x23, 0x3a, 0x84, 0x6e, 0x41, 0x9f, - 0x68, 0xf6, 0x42, 0xfd, 0x1d, 0xe4, 0x43, 0x2f, 0x1e, 0x62, 0x21, 0x53, 0xc2, 0x39, 0x7e, 0x24, - 0xbe, 0x83, 0x4e, 0xe1, 0x38, 0xce, 0xa8, 0xc0, 0xb1, 0x90, 0x8c, 0x3c, 0x17, 0x84, 0x0b, 0xdf, - 0x45, 0x57, 0x70, 0x9e, 0x92, 0xf4, 0x9e, 0x30, 0x3e, 0x4c, 0x72, 0x59, 0xe4, 0x0f, 0x58, 0x90, - 0x5f, 0xa7, 0x83, 0xce, 0xe0, 0x24, 0xc7, 0x09, 0x93, 0x09, 0xe5, 0x02, 0x8f, 0x46, 0x58, 0x24, - 0x19, 0xf5, 0xbd, 0x35, 0xe6, 0xaf, 0x34, 0xfe, 0x8b, 0x77, 0xc7, 0x7b, 0xed, 0xe5, 0xb7, 0x5f, - 0x01, 0x00, 0x00, 0xff, 0xff, 0xb9, 0xdb, 0x0d, 0x56, 0x56, 0x01, 0x00, 0x00, + // 377 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xcf, 0x8e, 0xd3, 0x30, + 0x10, 0xc6, 0xc9, 0x36, 0x6c, 0x77, 0x67, 0x4b, 0x65, 0x06, 0x10, 0xe1, 0xcf, 0x6a, 0x97, 0x22, + 0xc1, 0x02, 0x52, 0x0e, 0x70, 0xe6, 0xe0, 0x75, 0x0c, 0x1b, 0x91, 0x38, 0xc1, 0x76, 0x84, 0x38, + 0x59, 0x2e, 0x0d, 0x55, 0xa5, 0xb6, 0x89, 0xda, 0xf4, 0xd0, 0x07, 0xe3, 0x29, 0x78, 0x29, 0x94, + 0xd0, 0xd2, 0x96, 0x82, 0x7a, 0xb2, 0xe6, 0xfb, 0x7e, 0x9f, 0x47, 0x33, 0x03, 0x3d, 0x5b, 0x96, + 0xe3, 0xd1, 0x37, 0x5b, 0x8d, 0x8a, 0xa9, 0x99, 0xe4, 0x95, 0x1d, 0xd8, 0xca, 0x9a, 0x49, 0x3e, + 0x9f, 0xdb, 0x61, 0xee, 0x97, 0xb3, 0xa2, 0x2a, 0xf0, 0xa4, 0x79, 0xfa, 0x8b, 0xef, 0xbd, 0x9f, + 0x2e, 0x3c, 0xa6, 0x9b, 0x40, 0xbc, 0xe2, 0xe3, 0xdf, 0x38, 0x3e, 0x85, 0xd3, 0xf9, 0x68, 0x38, + 0xb5, 0xd5, 0x62, 0x96, 0x7b, 0xce, 0xa5, 0x73, 0xd5, 0x91, 0x1b, 0x01, 0x3d, 0x68, 0x97, 0x76, + 0x39, 0x2e, 0xec, 0xc0, 0x3b, 0x6a, 0xbc, 0x75, 0x89, 0xef, 0xc1, 0xad, 0x96, 0x65, 0xee, 0xb5, + 0x2e, 0x9d, 0xab, 0xee, 0xdb, 0x57, 0xfe, 0xba, 0x9f, 0xff, 0xff, 0x5e, 0xbe, 0x5e, 0x96, 0xb9, + 0x6c, 0x62, 0xbd, 0x1f, 0x2d, 0x70, 0xeb, 0x12, 0xcf, 0xa0, 0x9d, 0x89, 0x4f, 0x22, 0xf9, 0x22, + 0xc8, 0x2d, 0x24, 0xd0, 0x61, 0x37, 0x54, 0x9b, 0x98, 0x2b, 0x45, 0x3f, 0x72, 0xe2, 0x20, 0x42, + 0x97, 0x25, 0x42, 0x53, 0xa6, 0x4d, 0x96, 0x06, 0x54, 0x73, 0x72, 0x84, 0xe7, 0xf0, 0x28, 0xe6, + 0xf1, 0x35, 0x97, 0xea, 0x26, 0x4c, 0x57, 0xf2, 0x9f, 0x48, 0x0b, 0x1f, 0xc0, 0xdd, 0x94, 0x86, + 0xd2, 0x84, 0x42, 0x69, 0x1a, 0x45, 0x54, 0x87, 0x89, 0x20, 0x6e, 0x2d, 0xab, 0xaf, 0x82, 0xed, + 0xca, 0xb7, 0xf1, 0x39, 0x5c, 0x48, 0xfe, 0x39, 0xe3, 0x4a, 0x1b, 0x1a, 0x04, 0x92, 0x2b, 0x65, + 0x3e, 0x24, 0xd2, 0x68, 0x49, 0x85, 0xa2, 0xac, 0x81, 0x8e, 0xf1, 0x35, 0xbc, 0xa0, 0x8c, 0xf1, + 0x54, 0x9b, 0x43, 0x6c, 0x1b, 0xdf, 0xc0, 0xcb, 0x80, 0xb3, 0x28, 0x14, 0xfc, 0x20, 0x7c, 0x82, + 0x0f, 0xe1, 0xde, 0x1a, 0xda, 0x36, 0x4e, 0xf1, 0x3e, 0x10, 0xc5, 0x45, 0xb0, 0xa3, 0x02, 0x5e, + 0xc0, 0x93, 0xbf, 0xff, 0xde, 0x06, 0xce, 0xea, 0xd5, 0xec, 0x0d, 0x69, 0x56, 0x0b, 0x24, 0x9d, + 0x7f, 0xdb, 0x94, 0xb1, 0x24, 0x13, 0x9a, 0xdc, 0xc1, 0x67, 0x70, 0xbe, 0x6f, 0xa7, 0xd9, 0x75, + 0x14, 0x32, 0x53, 0xdf, 0x85, 0x74, 0xfb, 0xc7, 0xcd, 0x9d, 0xdf, 0xfd, 0x0a, 0x00, 0x00, 0xff, + 0xff, 0xb7, 0x6c, 0xd6, 0xba, 0x84, 0x02, 0x00, 0x00, } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto index 9d99259ca96..dae1d78be47 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto @@ -14,9 +14,18 @@ message ApplicationMetadataMessage { enum Type { UNKNOWN = 0; CHAT_MESSAGE = 1; - CONTACT_REQUEST = 2; + CONTACT_UPDATE = 2; MEMBERSHIP_UPDATE_MESSAGE = 3; PAIR_INSTALLATION = 4; SYNC_INSTALLATION = 5; + REQUEST_ADDRESS_FOR_TRANSACTION = 6; + ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION = 7; + DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION = 8; + REQUEST_TRANSACTION = 9; + SEND_TRANSACTION = 10; + DECLINE_REQUEST_TRANSACTION = 11; + SYNC_INSTALLATION_CONTACT = 12; + SYNC_INSTALLATION_ACCOUNT = 13; + SYNC_INSTALLATION_PUBLIC_CHAT = 14; } } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.pb.go b/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.pb.go index 9963ed524c3..61db6ead545 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.pb.go +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.pb.go @@ -64,8 +64,7 @@ const ( ChatMessage_STICKER ChatMessage_ContentType = 2 ChatMessage_STATUS ChatMessage_ContentType = 3 ChatMessage_EMOJI ChatMessage_ContentType = 4 - ChatMessage_COMMAND ChatMessage_ContentType = 5 - ChatMessage_COMMAND_REQUEST ChatMessage_ContentType = 6 + ChatMessage_TRANSACTION_COMMAND ChatMessage_ContentType = 5 ) var ChatMessage_ContentType_name = map[int32]string{ @@ -74,8 +73,7 @@ var ChatMessage_ContentType_name = map[int32]string{ 2: "STICKER", 3: "STATUS", 4: "EMOJI", - 5: "COMMAND", - 6: "COMMAND_REQUEST", + 5: "TRANSACTION_COMMAND", } var ChatMessage_ContentType_value = map[string]int32{ @@ -84,8 +82,7 @@ var ChatMessage_ContentType_value = map[string]int32{ "STICKER": 2, "STATUS": 3, "EMOJI": 4, - "COMMAND": 5, - "COMMAND_REQUEST": 6, + "TRANSACTION_COMMAND": 5, } func (x ChatMessage_ContentType) String() string { @@ -294,34 +291,34 @@ func init() { func init() { proto.RegisterFile("chat_message.proto", fileDescriptor_263952f55fd35689) } var fileDescriptor_263952f55fd35689 = []byte{ - // 462 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0xcf, 0x6f, 0xd3, 0x30, - 0x14, 0x5e, 0xda, 0xb4, 0x69, 0x5f, 0x46, 0x31, 0x66, 0x12, 0x46, 0x9a, 0x44, 0xe9, 0xa9, 0xa7, - 0x1e, 0x06, 0x07, 0xae, 0x5d, 0x66, 0x8d, 0xb0, 0xc5, 0x29, 0x8e, 0x0b, 0xec, 0x64, 0x79, 0xa9, - 0xa1, 0x55, 0x97, 0x1f, 0x6a, 0x8c, 0x44, 0x0f, 0xf0, 0x67, 0x73, 0x46, 0x71, 0x5a, 0xda, 0x5d, - 0x76, 0xf2, 0xfb, 0xbe, 0xf7, 0xbd, 0xef, 0xe5, 0x7d, 0x01, 0x9c, 0x2e, 0x95, 0x91, 0x99, 0xae, - 0x2a, 0xf5, 0x43, 0x4f, 0xca, 0x4d, 0x61, 0x0a, 0xdc, 0xb3, 0xcf, 0xfd, 0xcf, 0xef, 0xa3, 0x0f, - 0x30, 0x48, 0xcc, 0x2a, 0x5d, 0xeb, 0x4d, 0xd4, 0x28, 0x30, 0x06, 0x77, 0xa9, 0xaa, 0x25, 0x71, - 0x86, 0xce, 0xb8, 0xcf, 0x6d, 0x5d, 0x73, 0xa5, 0x4a, 0xd7, 0xa4, 0x35, 0x74, 0xc6, 0x1d, 0x6e, - 0xeb, 0xd1, 0x5f, 0x17, 0xfc, 0x60, 0xa9, 0xcc, 0x7e, 0xee, 0x0c, 0x3a, 0xe9, 0x43, 0x91, 0xae, - 0xed, 0xa0, 0xcb, 0x1b, 0x80, 0xcf, 0xa1, 0x6f, 0x56, 0x99, 0xae, 0x8c, 0xca, 0x4a, 0x3b, 0xee, - 0xf2, 0x03, 0x51, 0xfb, 0x1a, 0xfd, 0xcb, 0x90, 0x76, 0xb3, 0xab, 0xae, 0xf1, 0x1b, 0xf0, 0x37, - 0xba, 0x2a, 0x8b, 0xbc, 0xd2, 0xd2, 0x14, 0xc4, 0xb5, 0x2d, 0xd8, 0x53, 0xa2, 0xc0, 0xaf, 0xa1, - 0xa7, 0xf3, 0x4a, 0xe6, 0x2a, 0xd3, 0xa4, 0x63, 0xbb, 0x9e, 0xce, 0x2b, 0xa6, 0x32, 0x8d, 0x5f, - 0x81, 0x67, 0xaf, 0x5d, 0x2d, 0x48, 0xd7, 0x76, 0xba, 0x35, 0x0c, 0x17, 0xf8, 0x0a, 0x4e, 0x77, - 0x09, 0x48, 0xb3, 0x2d, 0x35, 0xf1, 0x86, 0xce, 0x78, 0x70, 0xf1, 0x76, 0xb2, 0xcf, 0x61, 0x72, - 0x74, 0xc9, 0x64, 0xf7, 0x8a, 0x6d, 0xa9, 0xb9, 0x9f, 0x1d, 0x40, 0xed, 0x92, 0x16, 0xb9, 0xd1, - 0xb9, 0x69, 0x5c, 0x7a, 0x4f, 0xb9, 0x04, 0x8d, 0xb2, 0x71, 0x49, 0x0f, 0x00, 0xbf, 0x07, 0xaf, - 0x6a, 0x22, 0x27, 0xfd, 0xa1, 0x33, 0xf6, 0x2f, 0xc8, 0xc1, 0xe0, 0xf1, 0xbf, 0xf8, 0x78, 0xc2, - 0xf7, 0xd2, 0xd1, 0x1f, 0xf0, 0x8f, 0xbe, 0x0b, 0x13, 0x38, 0x9b, 0xb3, 0x1b, 0x16, 0x7f, 0x65, - 0x32, 0xa2, 0x49, 0x32, 0xbd, 0xa6, 0x52, 0xdc, 0xcd, 0x28, 0x3a, 0xc1, 0x03, 0x80, 0x98, 0x51, - 0x29, 0x62, 0x19, 0x33, 0x8a, 0x1c, 0x8c, 0xe0, 0x74, 0x36, 0xbf, 0xbc, 0x0d, 0x03, 0x79, 0xcd, - 0xe3, 0xf9, 0x0c, 0xb5, 0xf0, 0x0b, 0x78, 0x36, 0xe3, 0xe1, 0x97, 0xa9, 0xa0, 0x3b, 0xaa, 0x8d, - 0x87, 0x70, 0x9e, 0xdc, 0x25, 0x82, 0x46, 0xff, 0xdd, 0x1e, 0x2b, 0xdc, 0xd1, 0x6f, 0xf0, 0x8f, - 0x2e, 0x3a, 0xde, 0x1f, 0xc4, 0x4c, 0x50, 0x26, 0x8e, 0xf6, 0x0b, 0xfa, 0x4d, 0xc8, 0xd9, 0xed, - 0x34, 0x64, 0xc8, 0xc1, 0x3e, 0x78, 0x89, 0x08, 0x83, 0x1b, 0xca, 0x51, 0x0b, 0x03, 0x74, 0x13, - 0x31, 0x15, 0xf3, 0x04, 0xb5, 0x71, 0x1f, 0x3a, 0x34, 0x8a, 0x3f, 0x85, 0xc8, 0xad, 0x35, 0x41, - 0x1c, 0x45, 0x53, 0x76, 0x85, 0x3a, 0xf8, 0x25, 0x3c, 0xdf, 0x01, 0xc9, 0xe9, 0xe7, 0x39, 0x4d, - 0x04, 0xea, 0x5e, 0xf6, 0xc1, 0x2b, 0xd5, 0xf6, 0xa1, 0x50, 0x8b, 0xfb, 0xae, 0x4d, 0xeb, 0xdd, - 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3a, 0x19, 0x70, 0x9c, 0xd9, 0x02, 0x00, 0x00, + // 460 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0x4d, 0x6f, 0xd3, 0x4c, + 0x10, 0xc7, 0xeb, 0xc4, 0x89, 0x93, 0x71, 0x9f, 0xc8, 0xcf, 0x52, 0xa9, 0x8b, 0x54, 0x89, 0x90, + 0x53, 0x4e, 0x39, 0x14, 0x0e, 0x5c, 0x5d, 0x77, 0x55, 0x4c, 0xeb, 0xb5, 0xb5, 0xde, 0x00, 0x3d, + 0xad, 0xb6, 0xce, 0x42, 0xa2, 0xd4, 0x2f, 0x8a, 0x17, 0x89, 0x5c, 0xf8, 0xc6, 0x7c, 0x07, 0xe4, + 0x75, 0x42, 0xdc, 0x0b, 0xa7, 0x9d, 0x97, 0xff, 0xfc, 0xc6, 0xf3, 0x37, 0xa0, 0x6c, 0x2d, 0xb5, + 0xc8, 0x55, 0x5d, 0xcb, 0xef, 0x6a, 0x51, 0xed, 0x4a, 0x5d, 0xa2, 0x91, 0x79, 0x9e, 0x7e, 0x7c, + 0x9b, 0x7d, 0x80, 0x49, 0xaa, 0x37, 0xd9, 0x56, 0xed, 0xa2, 0x56, 0x81, 0x10, 0xd8, 0x6b, 0x59, + 0xaf, 0xb1, 0x35, 0xb5, 0xe6, 0x63, 0x66, 0xe2, 0xa6, 0x56, 0xc9, 0x6c, 0x8b, 0x7b, 0x53, 0x6b, + 0x3e, 0x60, 0x26, 0x9e, 0xfd, 0xb6, 0xc1, 0x0d, 0xd6, 0x52, 0x1f, 0xe7, 0x2e, 0x60, 0x90, 0x3d, + 0x97, 0xd9, 0xd6, 0x0c, 0xda, 0xac, 0x4d, 0xd0, 0x15, 0x8c, 0xf5, 0x26, 0x57, 0xb5, 0x96, 0x79, + 0x65, 0xc6, 0x6d, 0x76, 0x2a, 0x34, 0x5c, 0xad, 0x7e, 0x6a, 0xdc, 0x6f, 0x77, 0x35, 0x31, 0x7a, + 0x03, 0xee, 0x4e, 0xd5, 0x55, 0x59, 0xd4, 0x4a, 0xe8, 0x12, 0xdb, 0xa6, 0x05, 0xc7, 0x12, 0x2f, + 0xd1, 0x6b, 0x18, 0xa9, 0xa2, 0x16, 0x85, 0xcc, 0x15, 0x1e, 0x98, 0xae, 0xa3, 0x8a, 0x9a, 0xca, + 0x5c, 0xa1, 0x4b, 0x70, 0xcc, 0xb5, 0x9b, 0x15, 0x1e, 0x9a, 0xce, 0xb0, 0x49, 0xc3, 0x15, 0xba, + 0x85, 0xf3, 0x83, 0x03, 0x42, 0xef, 0x2b, 0x85, 0x9d, 0xa9, 0x35, 0x9f, 0x5c, 0xbf, 0x5d, 0x1c, + 0x7d, 0x58, 0x74, 0x2e, 0x59, 0x1c, 0x5e, 0xbe, 0xaf, 0x14, 0x73, 0xf3, 0x53, 0xd2, 0x50, 0xb2, + 0xb2, 0xd0, 0xaa, 0xd0, 0x2d, 0x65, 0xf4, 0x2f, 0x4a, 0xd0, 0x2a, 0x5b, 0x4a, 0x76, 0x4a, 0xd0, + 0x7b, 0x70, 0xea, 0xd6, 0x72, 0x3c, 0x9e, 0x5a, 0x73, 0xf7, 0x1a, 0x9f, 0x00, 0x2f, 0xff, 0xc5, + 0xc7, 0x33, 0x76, 0x94, 0xce, 0x7e, 0x81, 0xdb, 0xf9, 0x2e, 0x84, 0xe1, 0x62, 0x49, 0xef, 0x69, + 0xfc, 0x85, 0x8a, 0x88, 0xa4, 0xa9, 0x7f, 0x47, 0x04, 0x7f, 0x4c, 0x88, 0x77, 0x86, 0x26, 0x00, + 0x31, 0x25, 0x82, 0xc7, 0x22, 0xa6, 0xc4, 0xb3, 0x90, 0x07, 0xe7, 0xc9, 0xf2, 0xe6, 0x21, 0x0c, + 0xc4, 0x1d, 0x8b, 0x97, 0x89, 0xd7, 0x43, 0xff, 0xc3, 0x7f, 0x09, 0x0b, 0x3f, 0xfb, 0x9c, 0x1c, + 0x4a, 0x7d, 0x34, 0x85, 0xab, 0xf4, 0x31, 0xe5, 0x24, 0xfa, 0x4b, 0x7b, 0xa9, 0xb0, 0x67, 0x1a, + 0xdc, 0xce, 0x45, 0xdd, 0xfd, 0x41, 0x4c, 0x39, 0xa1, 0xbc, 0xb3, 0x9f, 0x93, 0xaf, 0x5c, 0x24, + 0x0f, 0x7e, 0x48, 0x3d, 0x0b, 0xb9, 0xe0, 0xa4, 0x3c, 0x0c, 0xee, 0x09, 0xf3, 0x7a, 0x08, 0x60, + 0x98, 0x72, 0x9f, 0x2f, 0x53, 0xaf, 0x8f, 0xc6, 0x30, 0x20, 0x51, 0xfc, 0x29, 0xf4, 0x6c, 0x74, + 0x09, 0xaf, 0x38, 0xf3, 0x69, 0xea, 0x07, 0x3c, 0x8c, 0x1b, 0x62, 0x14, 0xf9, 0xf4, 0xd6, 0x1b, + 0xdc, 0x8c, 0xc1, 0xa9, 0xe4, 0xfe, 0xb9, 0x94, 0xab, 0xa7, 0xa1, 0x31, 0xe9, 0xdd, 0x9f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x54, 0x6d, 0xd5, 0x10, 0xd0, 0x02, 0x00, 0x00, } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.proto b/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.proto index e7d2309da67..8dbb5f6e1e9 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.proto +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/chat_message.proto @@ -48,7 +48,6 @@ message ChatMessage { STICKER = 2; STATUS = 3; EMOJI = 4; - COMMAND = 5; - COMMAND_REQUEST = 6; + TRANSACTION_COMMAND = 5; } } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/command.pb.go b/vendor/github.com/status-im/status-go/protocol/protobuf/command.pb.go new file mode 100644 index 00000000000..c2a95993847 --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/command.pb.go @@ -0,0 +1,383 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: command.proto + +package protobuf + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type RequestAddressForTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RequestAddressForTransaction) Reset() { *m = RequestAddressForTransaction{} } +func (m *RequestAddressForTransaction) String() string { return proto.CompactTextString(m) } +func (*RequestAddressForTransaction) ProtoMessage() {} +func (*RequestAddressForTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{0} +} + +func (m *RequestAddressForTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RequestAddressForTransaction.Unmarshal(m, b) +} +func (m *RequestAddressForTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RequestAddressForTransaction.Marshal(b, m, deterministic) +} +func (m *RequestAddressForTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_RequestAddressForTransaction.Merge(m, src) +} +func (m *RequestAddressForTransaction) XXX_Size() int { + return xxx_messageInfo_RequestAddressForTransaction.Size(m) +} +func (m *RequestAddressForTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_RequestAddressForTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_RequestAddressForTransaction proto.InternalMessageInfo + +func (m *RequestAddressForTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *RequestAddressForTransaction) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +func (m *RequestAddressForTransaction) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + +type AcceptRequestAddressForTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *AcceptRequestAddressForTransaction) Reset() { *m = AcceptRequestAddressForTransaction{} } +func (m *AcceptRequestAddressForTransaction) String() string { return proto.CompactTextString(m) } +func (*AcceptRequestAddressForTransaction) ProtoMessage() {} +func (*AcceptRequestAddressForTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{1} +} + +func (m *AcceptRequestAddressForTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_AcceptRequestAddressForTransaction.Unmarshal(m, b) +} +func (m *AcceptRequestAddressForTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_AcceptRequestAddressForTransaction.Marshal(b, m, deterministic) +} +func (m *AcceptRequestAddressForTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_AcceptRequestAddressForTransaction.Merge(m, src) +} +func (m *AcceptRequestAddressForTransaction) XXX_Size() int { + return xxx_messageInfo_AcceptRequestAddressForTransaction.Size(m) +} +func (m *AcceptRequestAddressForTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_AcceptRequestAddressForTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_AcceptRequestAddressForTransaction proto.InternalMessageInfo + +func (m *AcceptRequestAddressForTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *AcceptRequestAddressForTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *AcceptRequestAddressForTransaction) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +type DeclineRequestAddressForTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeclineRequestAddressForTransaction) Reset() { *m = DeclineRequestAddressForTransaction{} } +func (m *DeclineRequestAddressForTransaction) String() string { return proto.CompactTextString(m) } +func (*DeclineRequestAddressForTransaction) ProtoMessage() {} +func (*DeclineRequestAddressForTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{2} +} + +func (m *DeclineRequestAddressForTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeclineRequestAddressForTransaction.Unmarshal(m, b) +} +func (m *DeclineRequestAddressForTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeclineRequestAddressForTransaction.Marshal(b, m, deterministic) +} +func (m *DeclineRequestAddressForTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeclineRequestAddressForTransaction.Merge(m, src) +} +func (m *DeclineRequestAddressForTransaction) XXX_Size() int { + return xxx_messageInfo_DeclineRequestAddressForTransaction.Size(m) +} +func (m *DeclineRequestAddressForTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_DeclineRequestAddressForTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_DeclineRequestAddressForTransaction proto.InternalMessageInfo + +func (m *DeclineRequestAddressForTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *DeclineRequestAddressForTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type DeclineRequestTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeclineRequestTransaction) Reset() { *m = DeclineRequestTransaction{} } +func (m *DeclineRequestTransaction) String() string { return proto.CompactTextString(m) } +func (*DeclineRequestTransaction) ProtoMessage() {} +func (*DeclineRequestTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{3} +} + +func (m *DeclineRequestTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeclineRequestTransaction.Unmarshal(m, b) +} +func (m *DeclineRequestTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeclineRequestTransaction.Marshal(b, m, deterministic) +} +func (m *DeclineRequestTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeclineRequestTransaction.Merge(m, src) +} +func (m *DeclineRequestTransaction) XXX_Size() int { + return xxx_messageInfo_DeclineRequestTransaction.Size(m) +} +func (m *DeclineRequestTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_DeclineRequestTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_DeclineRequestTransaction proto.InternalMessageInfo + +func (m *DeclineRequestTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *DeclineRequestTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type RequestTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` + Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RequestTransaction) Reset() { *m = RequestTransaction{} } +func (m *RequestTransaction) String() string { return proto.CompactTextString(m) } +func (*RequestTransaction) ProtoMessage() {} +func (*RequestTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{4} +} + +func (m *RequestTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RequestTransaction.Unmarshal(m, b) +} +func (m *RequestTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RequestTransaction.Marshal(b, m, deterministic) +} +func (m *RequestTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_RequestTransaction.Merge(m, src) +} +func (m *RequestTransaction) XXX_Size() int { + return xxx_messageInfo_RequestTransaction.Size(m) +} +func (m *RequestTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_RequestTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_RequestTransaction proto.InternalMessageInfo + +func (m *RequestTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *RequestTransaction) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *RequestTransaction) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +func (m *RequestTransaction) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + +type SendTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + TransactionHash string `protobuf:"bytes,3,opt,name=transaction_hash,json=transactionHash,proto3" json:"transaction_hash,omitempty"` + Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SendTransaction) Reset() { *m = SendTransaction{} } +func (m *SendTransaction) String() string { return proto.CompactTextString(m) } +func (*SendTransaction) ProtoMessage() {} +func (*SendTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{5} +} + +func (m *SendTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SendTransaction.Unmarshal(m, b) +} +func (m *SendTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SendTransaction.Marshal(b, m, deterministic) +} +func (m *SendTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_SendTransaction.Merge(m, src) +} +func (m *SendTransaction) XXX_Size() int { + return xxx_messageInfo_SendTransaction.Size(m) +} +func (m *SendTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_SendTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_SendTransaction proto.InternalMessageInfo + +func (m *SendTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SendTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *SendTransaction) GetTransactionHash() string { + if m != nil { + return m.TransactionHash + } + return "" +} + +func (m *SendTransaction) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +func init() { + proto.RegisterType((*RequestAddressForTransaction)(nil), "protobuf.RequestAddressForTransaction") + proto.RegisterType((*AcceptRequestAddressForTransaction)(nil), "protobuf.AcceptRequestAddressForTransaction") + proto.RegisterType((*DeclineRequestAddressForTransaction)(nil), "protobuf.DeclineRequestAddressForTransaction") + proto.RegisterType((*DeclineRequestTransaction)(nil), "protobuf.DeclineRequestTransaction") + proto.RegisterType((*RequestTransaction)(nil), "protobuf.RequestTransaction") + proto.RegisterType((*SendTransaction)(nil), "protobuf.SendTransaction") +} + +func init() { proto.RegisterFile("command.proto", fileDescriptor_213c0bb044472049) } + +var fileDescriptor_213c0bb044472049 = []byte{ + // 257 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x41, 0x4b, 0x03, 0x31, + 0x10, 0x85, 0xd9, 0x6d, 0xd5, 0x76, 0x50, 0x2b, 0xc1, 0xc3, 0x2a, 0x3d, 0x94, 0x78, 0xa9, 0x17, + 0x2f, 0xfe, 0x82, 0x05, 0x11, 0xc1, 0xdb, 0xea, 0x5d, 0xa6, 0x93, 0xa9, 0x1b, 0xdc, 0x26, 0x35, + 0xc9, 0xf6, 0xec, 0x4f, 0x17, 0xb3, 0xab, 0xdb, 0x0a, 0x82, 0xab, 0xa7, 0xf0, 0x5e, 0x78, 0xf3, + 0x65, 0x1e, 0x81, 0x23, 0xb2, 0xab, 0x15, 0x1a, 0x75, 0xb5, 0x76, 0x36, 0x58, 0x31, 0x8a, 0xc7, + 0xa2, 0x5e, 0xca, 0x25, 0x4c, 0x0b, 0x7e, 0xad, 0xd9, 0x87, 0x5c, 0x29, 0xc7, 0xde, 0xdf, 0x5a, + 0xf7, 0xe8, 0xd0, 0x78, 0xa4, 0xa0, 0xad, 0x11, 0xa7, 0xb0, 0x47, 0x95, 0xa5, 0x97, 0x2c, 0x99, + 0x25, 0xf3, 0x61, 0xd1, 0x88, 0x0f, 0x77, 0x83, 0x55, 0xcd, 0x59, 0x3a, 0x4b, 0xe6, 0xe3, 0xa2, + 0x11, 0xe2, 0x1c, 0x46, 0x64, 0x4d, 0x70, 0x48, 0x21, 0x1b, 0xc4, 0x8b, 0x2f, 0x2d, 0x15, 0xc8, + 0x9c, 0x88, 0xd7, 0xe1, 0x0f, 0xb4, 0x63, 0x48, 0xb5, 0x6a, 0x51, 0xa9, 0x56, 0x22, 0x83, 0x03, + 0x6c, 0xe2, 0x2d, 0xe6, 0x53, 0xca, 0x7b, 0xb8, 0xb8, 0x61, 0xaa, 0xb4, 0xe1, 0xff, 0x63, 0x64, + 0x0e, 0x67, 0xbb, 0xc3, 0xfa, 0x8f, 0xd8, 0x80, 0xf8, 0x75, 0x76, 0x6b, 0xab, 0x74, 0x67, 0xab, + 0xae, 0xed, 0xc1, 0x4f, 0x6d, 0x0f, 0xbf, 0xb5, 0xfd, 0x96, 0xc0, 0xe4, 0x81, 0x8d, 0xea, 0xdf, + 0xed, 0x25, 0x9c, 0x84, 0x2e, 0xf4, 0x54, 0xa2, 0x2f, 0x5b, 0xec, 0x64, 0xcb, 0xbf, 0x43, 0x5f, + 0x8a, 0x29, 0x8c, 0xbd, 0x7e, 0x36, 0x18, 0x6a, 0xc7, 0xf1, 0x05, 0x87, 0x45, 0x67, 0x2c, 0xf6, + 0xe3, 0x17, 0xbb, 0x7e, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x13, 0xdb, 0x87, 0x02, 0x7a, 0x02, 0x00, + 0x00, +} diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/command.proto b/vendor/github.com/status-im/status-go/protocol/protobuf/command.proto new file mode 100644 index 00000000000..195e9035d93 --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/command.proto @@ -0,0 +1,39 @@ +syntax = "proto3"; + +package protobuf; + +message RequestAddressForTransaction { + uint64 clock = 1; + string value = 2; + string contract = 3; +} + +message AcceptRequestAddressForTransaction { + uint64 clock = 1; + string id = 2; + string address = 3; +} + +message DeclineRequestAddressForTransaction { + uint64 clock = 1; + string id = 2; +} + +message DeclineRequestTransaction { + uint64 clock = 1; + string id = 2; +} + +message RequestTransaction { + uint64 clock = 1; + string address = 2; + string value = 3; + string contract = 4; +} + +message SendTransaction { + uint64 clock = 1; + string id = 2; + string transaction_hash = 3; + bytes signature = 4; +} diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/contact.pb.go b/vendor/github.com/status-im/status-go/protocol/protobuf/contact.pb.go new file mode 100644 index 00000000000..0bc4ce7b8ff --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/contact.pb.go @@ -0,0 +1,95 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: contact.proto + +package protobuf + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ContactUpdate struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + EnsName string `protobuf:"bytes,2,opt,name=ens_name,json=ensName,proto3" json:"ens_name,omitempty"` + ProfileImage string `protobuf:"bytes,3,opt,name=profile_image,json=profileImage,proto3" json:"profile_image,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContactUpdate) Reset() { *m = ContactUpdate{} } +func (m *ContactUpdate) String() string { return proto.CompactTextString(m) } +func (*ContactUpdate) ProtoMessage() {} +func (*ContactUpdate) Descriptor() ([]byte, []int) { + return fileDescriptor_a5036fff2565fb15, []int{0} +} + +func (m *ContactUpdate) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ContactUpdate.Unmarshal(m, b) +} +func (m *ContactUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ContactUpdate.Marshal(b, m, deterministic) +} +func (m *ContactUpdate) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContactUpdate.Merge(m, src) +} +func (m *ContactUpdate) XXX_Size() int { + return xxx_messageInfo_ContactUpdate.Size(m) +} +func (m *ContactUpdate) XXX_DiscardUnknown() { + xxx_messageInfo_ContactUpdate.DiscardUnknown(m) +} + +var xxx_messageInfo_ContactUpdate proto.InternalMessageInfo + +func (m *ContactUpdate) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *ContactUpdate) GetEnsName() string { + if m != nil { + return m.EnsName + } + return "" +} + +func (m *ContactUpdate) GetProfileImage() string { + if m != nil { + return m.ProfileImage + } + return "" +} + +func init() { + proto.RegisterType((*ContactUpdate)(nil), "protobuf.ContactUpdate") +} + +func init() { proto.RegisterFile("contact.proto", fileDescriptor_a5036fff2565fb15) } + +var fileDescriptor_a5036fff2565fb15 = []byte{ + // 135 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0xce, 0xcf, 0x2b, + 0x49, 0x4c, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x00, 0x53, 0x49, 0xa5, 0x69, + 0x4a, 0xa9, 0x5c, 0xbc, 0xce, 0x10, 0xa9, 0xd0, 0x82, 0x94, 0xc4, 0x92, 0x54, 0x21, 0x11, 0x2e, + 0xd6, 0xe4, 0x9c, 0xfc, 0xe4, 0x6c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x96, 0x20, 0x08, 0x47, 0x48, + 0x92, 0x8b, 0x23, 0x35, 0xaf, 0x38, 0x3e, 0x2f, 0x31, 0x37, 0x55, 0x82, 0x49, 0x81, 0x51, 0x83, + 0x33, 0x88, 0x3d, 0x35, 0xaf, 0xd8, 0x2f, 0x31, 0x37, 0x55, 0x48, 0x99, 0x8b, 0xb7, 0xa0, 0x28, + 0x3f, 0x2d, 0x33, 0x27, 0x35, 0x3e, 0x33, 0x37, 0x31, 0x3d, 0x55, 0x82, 0x19, 0x2c, 0xcf, 0x03, + 0x15, 0xf4, 0x04, 0x89, 0x25, 0xb1, 0x81, 0x2d, 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x74, + 0xf9, 0x5c, 0xff, 0x88, 0x00, 0x00, 0x00, +} diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/contact.proto b/vendor/github.com/status-im/status-go/protocol/protobuf/contact.proto new file mode 100644 index 00000000000..06bb8b24a9d --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/contact.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package protobuf; + +message ContactUpdate { + uint64 clock = 1; + string ens_name = 2; + string profile_image = 3; +} diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/pairing.pb.go b/vendor/github.com/status-im/status-go/protocol/protobuf/pairing.pb.go new file mode 100644 index 00000000000..e1c3e2fa763 --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/pairing.pb.go @@ -0,0 +1,358 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: pairing.proto + +package protobuf + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type PairInstallation struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + InstallationId string `protobuf:"bytes,2,opt,name=installation_id,json=installationId,proto3" json:"installation_id,omitempty"` + DeviceType string `protobuf:"bytes,3,opt,name=device_type,json=deviceType,proto3" json:"device_type,omitempty"` + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *PairInstallation) Reset() { *m = PairInstallation{} } +func (m *PairInstallation) String() string { return proto.CompactTextString(m) } +func (*PairInstallation) ProtoMessage() {} +func (*PairInstallation) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{0} +} + +func (m *PairInstallation) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_PairInstallation.Unmarshal(m, b) +} +func (m *PairInstallation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_PairInstallation.Marshal(b, m, deterministic) +} +func (m *PairInstallation) XXX_Merge(src proto.Message) { + xxx_messageInfo_PairInstallation.Merge(m, src) +} +func (m *PairInstallation) XXX_Size() int { + return xxx_messageInfo_PairInstallation.Size(m) +} +func (m *PairInstallation) XXX_DiscardUnknown() { + xxx_messageInfo_PairInstallation.DiscardUnknown(m) +} + +var xxx_messageInfo_PairInstallation proto.InternalMessageInfo + +func (m *PairInstallation) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *PairInstallation) GetInstallationId() string { + if m != nil { + return m.InstallationId + } + return "" +} + +func (m *PairInstallation) GetDeviceType() string { + if m != nil { + return m.DeviceType + } + return "" +} + +func (m *PairInstallation) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +type SyncInstallationContact struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + ProfileImage string `protobuf:"bytes,3,opt,name=profile_image,json=profileImage,proto3" json:"profile_image,omitempty"` + EnsName string `protobuf:"bytes,4,opt,name=ens_name,json=ensName,proto3" json:"ens_name,omitempty"` + LastUpdated uint64 `protobuf:"varint,5,opt,name=last_updated,json=lastUpdated,proto3" json:"last_updated,omitempty"` + SystemTags []string `protobuf:"bytes,6,rep,name=system_tags,json=systemTags,proto3" json:"system_tags,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallationContact) Reset() { *m = SyncInstallationContact{} } +func (m *SyncInstallationContact) String() string { return proto.CompactTextString(m) } +func (*SyncInstallationContact) ProtoMessage() {} +func (*SyncInstallationContact) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{1} +} + +func (m *SyncInstallationContact) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallationContact.Unmarshal(m, b) +} +func (m *SyncInstallationContact) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallationContact.Marshal(b, m, deterministic) +} +func (m *SyncInstallationContact) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallationContact.Merge(m, src) +} +func (m *SyncInstallationContact) XXX_Size() int { + return xxx_messageInfo_SyncInstallationContact.Size(m) +} +func (m *SyncInstallationContact) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallationContact.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallationContact proto.InternalMessageInfo + +func (m *SyncInstallationContact) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SyncInstallationContact) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *SyncInstallationContact) GetProfileImage() string { + if m != nil { + return m.ProfileImage + } + return "" +} + +func (m *SyncInstallationContact) GetEnsName() string { + if m != nil { + return m.EnsName + } + return "" +} + +func (m *SyncInstallationContact) GetLastUpdated() uint64 { + if m != nil { + return m.LastUpdated + } + return 0 +} + +func (m *SyncInstallationContact) GetSystemTags() []string { + if m != nil { + return m.SystemTags + } + return nil +} + +type SyncInstallationAccount struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + ProfileImage string `protobuf:"bytes,2,opt,name=profile_image,json=profileImage,proto3" json:"profile_image,omitempty"` + LastUpdated uint64 `protobuf:"varint,3,opt,name=last_updated,json=lastUpdated,proto3" json:"last_updated,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallationAccount) Reset() { *m = SyncInstallationAccount{} } +func (m *SyncInstallationAccount) String() string { return proto.CompactTextString(m) } +func (*SyncInstallationAccount) ProtoMessage() {} +func (*SyncInstallationAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{2} +} + +func (m *SyncInstallationAccount) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallationAccount.Unmarshal(m, b) +} +func (m *SyncInstallationAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallationAccount.Marshal(b, m, deterministic) +} +func (m *SyncInstallationAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallationAccount.Merge(m, src) +} +func (m *SyncInstallationAccount) XXX_Size() int { + return xxx_messageInfo_SyncInstallationAccount.Size(m) +} +func (m *SyncInstallationAccount) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallationAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallationAccount proto.InternalMessageInfo + +func (m *SyncInstallationAccount) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SyncInstallationAccount) GetProfileImage() string { + if m != nil { + return m.ProfileImage + } + return "" +} + +func (m *SyncInstallationAccount) GetLastUpdated() uint64 { + if m != nil { + return m.LastUpdated + } + return 0 +} + +type SyncInstallationPublicChat struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallationPublicChat) Reset() { *m = SyncInstallationPublicChat{} } +func (m *SyncInstallationPublicChat) String() string { return proto.CompactTextString(m) } +func (*SyncInstallationPublicChat) ProtoMessage() {} +func (*SyncInstallationPublicChat) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{3} +} + +func (m *SyncInstallationPublicChat) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallationPublicChat.Unmarshal(m, b) +} +func (m *SyncInstallationPublicChat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallationPublicChat.Marshal(b, m, deterministic) +} +func (m *SyncInstallationPublicChat) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallationPublicChat.Merge(m, src) +} +func (m *SyncInstallationPublicChat) XXX_Size() int { + return xxx_messageInfo_SyncInstallationPublicChat.Size(m) +} +func (m *SyncInstallationPublicChat) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallationPublicChat.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallationPublicChat proto.InternalMessageInfo + +func (m *SyncInstallationPublicChat) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *SyncInstallationPublicChat) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type SyncInstallation struct { + Contacts []*SyncInstallationContact `protobuf:"bytes,1,rep,name=contacts,proto3" json:"contacts,omitempty"` + PublicChats []*SyncInstallationPublicChat `protobuf:"bytes,2,rep,name=public_chats,json=publicChats,proto3" json:"public_chats,omitempty"` + Account *SyncInstallationAccount `protobuf:"bytes,3,opt,name=account,proto3" json:"account,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SyncInstallation) Reset() { *m = SyncInstallation{} } +func (m *SyncInstallation) String() string { return proto.CompactTextString(m) } +func (*SyncInstallation) ProtoMessage() {} +func (*SyncInstallation) Descriptor() ([]byte, []int) { + return fileDescriptor_d61ab7221f0b5518, []int{4} +} + +func (m *SyncInstallation) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SyncInstallation.Unmarshal(m, b) +} +func (m *SyncInstallation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SyncInstallation.Marshal(b, m, deterministic) +} +func (m *SyncInstallation) XXX_Merge(src proto.Message) { + xxx_messageInfo_SyncInstallation.Merge(m, src) +} +func (m *SyncInstallation) XXX_Size() int { + return xxx_messageInfo_SyncInstallation.Size(m) +} +func (m *SyncInstallation) XXX_DiscardUnknown() { + xxx_messageInfo_SyncInstallation.DiscardUnknown(m) +} + +var xxx_messageInfo_SyncInstallation proto.InternalMessageInfo + +func (m *SyncInstallation) GetContacts() []*SyncInstallationContact { + if m != nil { + return m.Contacts + } + return nil +} + +func (m *SyncInstallation) GetPublicChats() []*SyncInstallationPublicChat { + if m != nil { + return m.PublicChats + } + return nil +} + +func (m *SyncInstallation) GetAccount() *SyncInstallationAccount { + if m != nil { + return m.Account + } + return nil +} + +func init() { + proto.RegisterType((*PairInstallation)(nil), "protobuf.PairInstallation") + proto.RegisterType((*SyncInstallationContact)(nil), "protobuf.SyncInstallationContact") + proto.RegisterType((*SyncInstallationAccount)(nil), "protobuf.SyncInstallationAccount") + proto.RegisterType((*SyncInstallationPublicChat)(nil), "protobuf.SyncInstallationPublicChat") + proto.RegisterType((*SyncInstallation)(nil), "protobuf.SyncInstallation") +} + +func init() { proto.RegisterFile("pairing.proto", fileDescriptor_d61ab7221f0b5518) } + +var fileDescriptor_d61ab7221f0b5518 = []byte{ + // 378 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6e, 0x9b, 0x40, + 0x10, 0xc6, 0x05, 0xf8, 0x5f, 0x07, 0xdb, 0xb5, 0x56, 0x95, 0xba, 0xed, 0xa5, 0x98, 0x56, 0xaa, + 0x4f, 0x3e, 0xb4, 0xc7, 0xaa, 0x87, 0xc4, 0x87, 0xc8, 0x97, 0xc8, 0x22, 0xce, 0x19, 0xad, 0x97, + 0x35, 0x5e, 0x05, 0x96, 0x15, 0xbb, 0x24, 0xe2, 0x05, 0xf2, 0x62, 0x79, 0x88, 0xbc, 0x4e, 0xc4, + 0x62, 0x3b, 0xc8, 0x0e, 0x51, 0x4e, 0x2c, 0x1f, 0xb3, 0xf3, 0xfd, 0xbe, 0x19, 0x60, 0x24, 0x09, + 0xcf, 0xb9, 0x88, 0xe7, 0x32, 0xcf, 0x74, 0x86, 0x06, 0xe6, 0xb1, 0x29, 0xb6, 0xfe, 0xa3, 0x05, + 0x93, 0x15, 0xe1, 0xf9, 0x52, 0x28, 0x4d, 0x92, 0x84, 0x68, 0x9e, 0x09, 0xf4, 0x05, 0xba, 0x34, + 0xc9, 0xe8, 0x1d, 0xb6, 0x3c, 0x6b, 0xd6, 0x09, 0xea, 0x17, 0xf4, 0x1b, 0x3e, 0xf3, 0x46, 0x55, + 0xc8, 0x23, 0x6c, 0x7b, 0xd6, 0xec, 0x53, 0x30, 0x6e, 0xca, 0xcb, 0x08, 0xfd, 0x00, 0x37, 0x62, + 0xf7, 0x9c, 0xb2, 0x50, 0x97, 0x92, 0x61, 0xc7, 0x14, 0x41, 0x2d, 0xad, 0x4b, 0xc9, 0x10, 0x82, + 0x8e, 0x20, 0x29, 0xc3, 0x1d, 0xf3, 0xc5, 0x9c, 0xfd, 0x27, 0x0b, 0xbe, 0xde, 0x94, 0x82, 0x36, + 0x41, 0x16, 0x99, 0xd0, 0x84, 0xea, 0x16, 0x9e, 0x31, 0xd8, 0x47, 0x04, 0x9b, 0x47, 0xe8, 0x27, + 0x8c, 0x64, 0x9e, 0x6d, 0x79, 0xc2, 0x42, 0x9e, 0x92, 0xf8, 0x60, 0x3c, 0xdc, 0x8b, 0xcb, 0x4a, + 0x43, 0xdf, 0x60, 0xc0, 0x84, 0x0a, 0x1b, 0xf6, 0x7d, 0x26, 0xd4, 0x35, 0x49, 0x19, 0x9a, 0xc2, + 0x30, 0x21, 0x4a, 0x87, 0x85, 0x8c, 0x88, 0x66, 0x11, 0xee, 0x1a, 0x33, 0xb7, 0xd2, 0x6e, 0x6b, + 0xa9, 0x4a, 0xa6, 0x4a, 0xa5, 0x59, 0x1a, 0x6a, 0x12, 0x2b, 0xdc, 0xf3, 0x9c, 0x2a, 0x59, 0x2d, + 0xad, 0x49, 0xac, 0xfc, 0x87, 0xf3, 0x10, 0x17, 0x94, 0x66, 0x85, 0x68, 0x0b, 0x71, 0x06, 0x6d, + 0xbf, 0x01, 0x7d, 0x4a, 0xe6, 0x9c, 0x91, 0xf9, 0x97, 0xf0, 0xfd, 0xd4, 0x78, 0x55, 0x6c, 0x12, + 0x4e, 0x17, 0x3b, 0xf2, 0xc1, 0x01, 0xfa, 0xcf, 0x16, 0x4c, 0x4e, 0x9b, 0xa0, 0xff, 0x30, 0xa0, + 0xf5, 0x1a, 0x14, 0xb6, 0x3c, 0x67, 0xe6, 0xfe, 0x99, 0xce, 0x0f, 0x7f, 0xcf, 0xbc, 0x65, 0x61, + 0xc1, 0xf1, 0x0a, 0xba, 0x82, 0xa1, 0x34, 0x1c, 0x21, 0xdd, 0x11, 0xad, 0xb0, 0x6d, 0x5a, 0xfc, + 0x6a, 0x6f, 0xf1, 0x4a, 0x1d, 0xb8, 0xf2, 0x78, 0x56, 0xe8, 0x1f, 0xf4, 0x49, 0x3d, 0x49, 0x13, + 0xff, 0x5d, 0x8c, 0xfd, 0xc8, 0x83, 0xc3, 0x8d, 0x4d, 0xcf, 0x94, 0xfe, 0x7d, 0x09, 0x00, 0x00, + 0xff, 0xff, 0xd7, 0x5f, 0x3a, 0x87, 0x07, 0x03, 0x00, 0x00, +} diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/pairing.proto b/vendor/github.com/status-im/status-go/protocol/protobuf/pairing.proto new file mode 100644 index 00000000000..9b6bce63e05 --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/pairing.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +package protobuf; + +message PairInstallation { + uint64 clock = 1; + string installation_id = 2; + string device_type = 3; + string name = 4; +} + +message SyncInstallationContact { + uint64 clock = 1; + string id = 2; + string profile_image = 3; + string ens_name = 4; + uint64 last_updated = 5; + repeated string system_tags = 6; +} + +message SyncInstallationAccount { + uint64 clock = 1; + string profile_image = 2; + uint64 last_updated = 3; +} + +message SyncInstallationPublicChat { + uint64 clock = 1; + string id = 2; +} + +message SyncInstallation { + repeated SyncInstallationContact contacts = 1; + repeated SyncInstallationPublicChat public_chats = 2; + SyncInstallationAccount account = 3; +} diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/service.go b/vendor/github.com/status-im/status-go/protocol/protobuf/service.go index 56d5d54c272..f6652e485fe 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/service.go +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/service.go @@ -4,7 +4,7 @@ import ( "github.com/golang/protobuf/proto" ) -//go:generate protoc --go_out=. ./chat_message.proto ./application_metadata_message.proto ./membership_update_message.proto +//go:generate protoc --go_out=. ./chat_message.proto ./application_metadata_message.proto ./membership_update_message.proto ./command.proto ./contact.proto ./pairing.proto func Unmarshal(payload []byte) (*ApplicationMetadataMessage, error) { var message ApplicationMetadataMessage diff --git a/vendor/github.com/status-im/status-go/protocol/transaction_validator.go b/vendor/github.com/status-im/status-go/protocol/transaction_validator.go new file mode 100644 index 00000000000..fc5cd3550eb --- /dev/null +++ b/vendor/github.com/status-im/status-go/protocol/transaction_validator.go @@ -0,0 +1,324 @@ +package protocol + +import ( + "context" + "crypto/ecdsa" + "encoding/hex" + "fmt" + "time" + + "github.com/pkg/errors" + coretypes "github.com/status-im/status-go/eth-node/core/types" + "github.com/status-im/status-go/eth-node/crypto" + "github.com/status-im/status-go/eth-node/types" + "go.uber.org/zap" + "math/big" + "strings" +) + +const ( + transferFunction = "a9059cbb" + tokenTransferDataLength = 68 + transactionHashLength = 66 +) + +type TransactionValidator struct { + persistence *sqlitePersistence + addresses map[string]bool + client EthClient + logger *zap.Logger +} + +var invalidResponse = &VerifyTransactionResponse{Valid: false} + +type TransactionToValidate struct { + TransactionHash string + CommandID string + MessageID string + RetryCount int + // First seen indicates the whisper timestamp of the first time we seen this + FirstSeen uint64 + // Validate indicates whether we should be validating this transaction + Validate bool + Signature []byte + From *ecdsa.PublicKey +} + +func NewTransactionValidator(addresses []types.Address, persistence *sqlitePersistence, client EthClient, logger *zap.Logger) *TransactionValidator { + addressesMap := make(map[string]bool) + for _, a := range addresses { + addressesMap[strings.ToLower(a.Hex())] = true + } + logger.Debug("Checking addresses", zap.Any("addrse", addressesMap)) + + return &TransactionValidator{ + persistence: persistence, + addresses: addressesMap, + logger: logger, + client: client, + } +} + +type EthClient interface { + TransactionByHash(context.Context, types.Hash) (coretypes.Message, bool, error) +} + +func (t *TransactionValidator) verifyTransactionSignature(ctx context.Context, from *ecdsa.PublicKey, address types.Address, transactionHash string, signature []byte) error { + publicKeyBytes := crypto.FromECDSAPub(from) + + if len(transactionHash) != transactionHashLength { + return errors.New("wrong transaction hash lenght") + } + + hashBytes, err := hex.DecodeString(transactionHash[2:]) + if err != nil { + return err + } + signatureMaterial := append(publicKeyBytes, hashBytes...) + + // We take a copy as EcRecover modifies the byte slice + signatureCopy := make([]byte, len(signature)) + copy(signatureCopy, signature) + extractedAddress, err := crypto.EcRecover(ctx, signatureMaterial, signatureCopy) + if err != nil { + return err + } + + if extractedAddress != address { + return errors.New("failed to verify signature") + } + return nil +} + +func (t *TransactionValidator) validateTokenTransfer(parameters *CommandParameters, transaction coretypes.Message) (*VerifyTransactionResponse, error) { + + data := transaction.Data() + if len(data) != tokenTransferDataLength { + return nil, errors.New(fmt.Sprintf("wrong data length: %d", len(data))) + } + + functionCalled := hex.EncodeToString(data[:4]) + + if functionCalled != transferFunction { + return invalidResponse, nil + } + + actualContractAddress := strings.ToLower(transaction.To().Hex()) + + if parameters.Contract != "" && actualContractAddress != parameters.Contract { + return invalidResponse, nil + } + + to := types.EncodeHex(data[16:36]) + + if !t.validateToAddress(parameters.Address, to) { + return invalidResponse, nil + } + + value := data[36:] + amount := new(big.Int).SetBytes(value) + + if parameters.Value != "" { + advertisedAmount, ok := new(big.Int).SetString(parameters.Value, 10) + if !ok { + return nil, errors.New("can't parse amount") + } + + return &VerifyTransactionResponse{ + Value: parameters.Value, + Contract: actualContractAddress, + Address: to, + AccordingToSpec: amount.Cmp(advertisedAmount) == 0, + Valid: true, + }, nil + } + + return &VerifyTransactionResponse{ + Value: amount.String(), + Address: to, + Contract: actualContractAddress, + AccordingToSpec: false, + Valid: true, + }, nil + +} + +func (t *TransactionValidator) validateToAddress(specifiedTo, actualTo string) bool { + if len(specifiedTo) != 0 && (strings.ToLower(specifiedTo) != strings.ToLower(actualTo) || !t.addresses[strings.ToLower(actualTo)]) { + return false + } + + return t.addresses[actualTo] +} + +func (t *TransactionValidator) validateEthereumTransfer(parameters *CommandParameters, transaction coretypes.Message) (*VerifyTransactionResponse, error) { + toAddress := strings.ToLower(transaction.To().Hex()) + + if !t.validateToAddress(parameters.Address, toAddress) { + return invalidResponse, nil + } + amount := transaction.Value() + if parameters.Value != "" { + advertisedAmount, ok := new(big.Int).SetString(parameters.Value, 10) + if !ok { + return nil, errors.New("can't parse amount") + } + return &VerifyTransactionResponse{ + AccordingToSpec: amount.Cmp(advertisedAmount) == 0, + Valid: true, + Value: amount.String(), + Address: toAddress, + }, nil + + } else { + return &VerifyTransactionResponse{ + AccordingToSpec: false, + Valid: true, + Value: amount.String(), + Address: toAddress, + }, nil + + } + +} + +type VerifyTransactionResponse struct { + Pending bool + // AccordingToSpec means that the transaction is valid, + // the user should be notified, but is not the same as + // what was requested, for example because the value is different + AccordingToSpec bool + // Valid means that the transaction is valid + Valid bool + // The actual value received + Value string + // The contract used in case of tokens + Contract string + // The address the transaction was actually sent + Address string + + Message *Message + Transaction *TransactionToValidate +} + +// validateTransaction validates a transaction and returns a response. +// If a negative response is returned, i.e `Valid` is false, it should +// not be retried. +// If an error is returned, validation can be retried. +func (t *TransactionValidator) validateTransaction(ctx context.Context, message coretypes.Message, parameters *CommandParameters, from *ecdsa.PublicKey) (*VerifyTransactionResponse, error) { + + fromAddress := types.BytesToAddress(message.From().Bytes()) + + err := t.verifyTransactionSignature(ctx, from, fromAddress, parameters.TransactionHash, parameters.Signature) + if err != nil { + t.logger.Error("failed validating signature", zap.Error(err)) + return invalidResponse, nil + } + + if len(message.Data()) != 0 { + t.logger.Debug("Validating token") + return t.validateTokenTransfer(parameters, message) + } else { + t.logger.Debug("Validating eth") + return t.validateEthereumTransfer(parameters, message) + } +} + +func (t *TransactionValidator) ValidateTransactions(ctx context.Context) ([]*VerifyTransactionResponse, error) { + if t.client == nil { + return nil, nil + } + var response []*VerifyTransactionResponse + t.logger.Debug("Started validating transactions") + transactions, err := t.persistence.TransactionsToValidate() + if err != nil { + return nil, err + } + + t.logger.Debug("Transactions to validated", zap.Any("transactions", transactions)) + + for _, transaction := range transactions { + var validationResult *VerifyTransactionResponse + t.logger.Debug("Validating transaction", zap.Any("transaction", transaction)) + if transaction.CommandID != "" { + message, err := t.persistence.MessageByCommandID(transaction.CommandID) + if err != nil { + + t.logger.Error("error pulling message", zap.Error(err)) + return nil, err + } + if message == nil { + t.logger.Info("No message found, ignoring transaction") + // This is not a valid case, ignore transaction + transaction.Validate = false + transaction.RetryCount += 1 + err = t.persistence.UpdateTransactionToValidate(transaction) + if err != nil { + return nil, err + } + continue + + } + commandParameters := message.CommandParameters + commandParameters.TransactionHash = transaction.TransactionHash + commandParameters.Signature = transaction.Signature + validationResult, err = t.ValidateTransaction(ctx, message.CommandParameters, transaction.From) + if err != nil { + t.logger.Error("Error validating transaction", zap.Error(err)) + continue + } + validationResult.Message = message + } else { + commandParameters := &CommandParameters{} + commandParameters.TransactionHash = transaction.TransactionHash + commandParameters.Signature = transaction.Signature + + validationResult, err = t.ValidateTransaction(ctx, commandParameters, transaction.From) + if err != nil { + t.logger.Error("Error validating transaction", zap.Error(err)) + continue + } + } + + if validationResult.Pending { + t.logger.Debug("Pending transaction skipping") + // Check if we should stop updating + continue + } + + // Mark transaction as valid + transaction.Validate = false + transaction.RetryCount += 1 + err = t.persistence.UpdateTransactionToValidate(transaction) + if err != nil { + return nil, err + } + + if !validationResult.Valid { + t.logger.Debug("Transaction not valid") + continue + } + t.logger.Debug("Transaction valid") + validationResult.Transaction = transaction + response = append(response, validationResult) + } + return response, nil +} + +func (t *TransactionValidator) ValidateTransaction(ctx context.Context, parameters *CommandParameters, from *ecdsa.PublicKey) (*VerifyTransactionResponse, error) { + t.logger.Debug("validating transaction", zap.Any("transaction", parameters), zap.Any("from", from)) + hash := parameters.TransactionHash + c, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() + + message, pending, err := t.client.TransactionByHash(c, types.HexToHash(hash)) + if err != nil { + return nil, err + } + if pending { + t.logger.Debug("Transaction pending") + return &VerifyTransactionResponse{Pending: true}, nil + } + + return t.validateTransaction(ctx, message, parameters, from) +} diff --git a/vendor/github.com/status-im/status-go/protocol/v1/status_message.go b/vendor/github.com/status-im/status-go/protocol/v1/status_message.go index aa9a9cc771e..e1653e2356d 100644 --- a/vendor/github.com/status-im/status-go/protocol/v1/status_message.go +++ b/vendor/github.com/status-im/status-go/protocol/v1/status_message.go @@ -182,7 +182,143 @@ func (m *StatusMessage) HandleApplication() error { return nil } - } + case protobuf.ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION: + var message protobuf.AcceptRequestAddressForTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode AcceptRequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SEND_TRANSACTION: + var message protobuf.SendTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SendTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + + case protobuf.ApplicationMetadataMessage_REQUEST_TRANSACTION: + var message protobuf.RequestTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode RequestTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION: + var message protobuf.DeclineRequestAddressForTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode DeclineRequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION: + var message protobuf.DeclineRequestTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode DeclineRequestTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + + case protobuf.ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION: + var message protobuf.RequestAddressForTransaction + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode RequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + + case protobuf.ApplicationMetadataMessage_CONTACT_UPDATE: + var message protobuf.ContactUpdate + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode ContactUpdate: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION: + var message protobuf.SyncInstallation + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallation: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT: + var message protobuf.SyncInstallationContact + log.Printf("Sync installation contact") + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallationContact: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT: + var message protobuf.SyncInstallationPublicChat + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallationPublicChat: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT: + var message protobuf.SyncInstallationAccount + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode SyncInstallationAccount: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + case protobuf.ApplicationMetadataMessage_PAIR_INSTALLATION: + var message protobuf.PairInstallation + err := proto.Unmarshal(m.DecryptedPayload, &message) + if err != nil { + m.ParsedMessage = nil + log.Printf("[message::DecodeMessage] could not decode PairInstallation: %#x, err: %v", m.Hash, err.Error()) + } else { + m.ParsedMessage = message + + return nil + } + } return nil } diff --git a/vendor/github.com/whyrusleeping/go-notifier/LICENSE b/vendor/github.com/whyrusleeping/go-notifier/LICENSE deleted file mode 100644 index 26100332ba2..00000000000 --- a/vendor/github.com/whyrusleeping/go-notifier/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Jeromy Johnson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/whyrusleeping/go-notifier/notifier.go b/vendor/github.com/whyrusleeping/go-notifier/notifier.go deleted file mode 100644 index 33302cfdecf..00000000000 --- a/vendor/github.com/whyrusleeping/go-notifier/notifier.go +++ /dev/null @@ -1,146 +0,0 @@ -// Package notifier provides a simple notification dispatcher -// meant to be embedded in larger structres who wish to allow -// clients to sign up for event notifications. -package notifier - -import ( - "sync" - - process "github.com/jbenet/goprocess" - ratelimit "github.com/jbenet/goprocess/ratelimit" -) - -// Notifiee is a generic interface. Clients implement -// their own Notifiee interfaces to ensure type-safety -// of notifications: -// -// type RocketNotifiee interface{ -// Countdown(r Rocket, countdown time.Duration) -// LiftedOff(Rocket) -// ReachedOrbit(Rocket) -// Detached(Rocket, Capsule) -// Landed(Rocket) -// } -// -type Notifiee interface{} - -// Notifier is a notification dispatcher. It's meant -// to be composed, and its zero-value is ready to be used. -// -// type Rocket struct { -// notifier notifier.Notifier -// } -// -type Notifier struct { - mu sync.RWMutex // guards notifiees - nots map[Notifiee]struct{} - lim *ratelimit.RateLimiter -} - -// RateLimited returns a rate limited Notifier. only limit goroutines -// will be spawned. If limit is zero, no rate limiting happens. This -// is the same as `Notifier{}`. -func RateLimited(limit int) Notifier { - n := Notifier{} - if limit > 0 { - n.lim = ratelimit.NewRateLimiter(process.Background(), limit) - } - return n -} - -// Notify signs up Notifiee e for notifications. This function -// is meant to be called behind your own type-safe function(s): -// -// // generic function for pattern-following -// func (r *Rocket) Notify(n Notifiee) { -// r.notifier.Notify(n) -// } -// -// // or as part of other functions -// func (r *Rocket) Onboard(a Astronaut) { -// r.astronauts = append(r.austronauts, a) -// r.notifier.Notify(a) -// } -// -func (n *Notifier) Notify(e Notifiee) { - n.mu.Lock() - if n.nots == nil { // so that zero-value is ready to be used. - n.nots = make(map[Notifiee]struct{}) - } - n.nots[e] = struct{}{} - n.mu.Unlock() -} - -// StopNotify stops notifying Notifiee e. This function -// is meant to be called behind your own type-safe function(s): -// -// // generic function for pattern-following -// func (r *Rocket) StopNotify(n Notifiee) { -// r.notifier.StopNotify(n) -// } -// -// // or as part of other functions -// func (r *Rocket) Detach(c Capsule) { -// r.notifier.StopNotify(c) -// r.capsule = nil -// } -// -func (n *Notifier) StopNotify(e Notifiee) { - n.mu.Lock() - if n.nots != nil { // so that zero-value is ready to be used. - delete(n.nots, e) - } - n.mu.Unlock() -} - -// NotifyAll messages the notifier's notifiees with a given notification. -// This is done by calling the given function with each notifiee. It is -// meant to be called with your own type-safe notification functions: -// -// func (r *Rocket) Launch() { -// r.notifyAll(func(n Notifiee) { -// n.Launched(r) -// }) -// } -// -// // make it private so only you can use it. This function is necessary -// // to make sure you only up-cast in one place. You control who you added -// // to be a notifiee. If Go adds generics, maybe we can get rid of this -// // method but for now it is like wrapping a type-less container with -// // a type safe interface. -// func (r *Rocket) notifyAll(notify func(Notifiee)) { -// r.notifier.NotifyAll(func(n notifier.Notifiee) { -// notify(n.(Notifiee)) -// }) -// } -// -// Note well: each notification is launched in its own goroutine, so they -// can be processed concurrently, and so that whatever the notification does -// it _never_ blocks out the client. This is so that consumers _cannot_ add -// hooks into your object that block you accidentally. -func (n *Notifier) NotifyAll(notify func(Notifiee)) { - n.mu.Lock() - defer n.mu.Unlock() - - if n.nots == nil { // so that zero-value is ready to be used. - return - } - - // no rate limiting. - if n.lim == nil { - for notifiee := range n.nots { - go notify(notifiee) - } - return - } - - // with rate limiting. - n.lim.Go(func(worker process.Process) { - for notifiee := range n.nots { - notifiee := notifiee // rebind for loop data races - n.lim.LimitedGo(func(worker process.Process) { - notify(notifiee) - }) - } - }) -} diff --git a/vendor/github.com/whyrusleeping/go-notifier/package.json b/vendor/github.com/whyrusleeping/go-notifier/package.json deleted file mode 100644 index 8eba8f55fac..00000000000 --- a/vendor/github.com/whyrusleeping/go-notifier/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "author": "whyrusleeping", - "bugs": { - "url": "https://github.com/whyrusleeping/go-notifier" - }, - "gx": { - "dvcsimport": "github.com/whyrusleeping/go-notifier" - }, - "gxDependencies": [ - { - "author": "whyrusleeping", - "hash": "QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP", - "name": "goprocess", - "version": "1.0.0" - } - ], - "gxVersion": "0.9.1", - "language": "go", - "license": "", - "name": "go-notifier", - "releaseCmd": "git commit -a -m \"gx publish $VERSION\"", - "version": "1.0.0" -} - diff --git a/vendor/modules.txt b/vendor/modules.txt index ee2f404ad96..4b0bec5acf2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -118,7 +118,7 @@ github.com/go-playground/locales/currency github.com/go-playground/universal-translator # github.com/go-stack/stack v1.8.0 github.com/go-stack/stack -# github.com/gogo/protobuf v1.3.0 +# github.com/gogo/protobuf v1.3.1 github.com/gogo/protobuf/io github.com/gogo/protobuf/proto # github.com/golang-migrate/migrate/v4 v4.6.2 @@ -175,12 +175,11 @@ github.com/jbenet/go-temp-err-catcher github.com/jbenet/goprocess github.com/jbenet/goprocess/context github.com/jbenet/goprocess/periodic -github.com/jbenet/goprocess/ratelimit # github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8 github.com/jinzhu/copier # github.com/karalabe/usb v0.0.0-20190819132248-550797b1cad8 github.com/karalabe/usb -# github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b +# github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d github.com/koron/go-ssdp # github.com/leodido/go-urn v1.2.0 github.com/leodido/go-urn @@ -198,7 +197,7 @@ github.com/libp2p/go-conn-security-multistream github.com/libp2p/go-eventbus # github.com/libp2p/go-flow-metrics v0.0.1 github.com/libp2p/go-flow-metrics -# github.com/libp2p/go-libp2p v0.4.0 +# github.com/libp2p/go-libp2p v0.4.2 github.com/libp2p/go-libp2p github.com/libp2p/go-libp2p/config github.com/libp2p/go-libp2p/p2p/host/basic @@ -207,13 +206,13 @@ github.com/libp2p/go-libp2p/p2p/host/routed github.com/libp2p/go-libp2p/p2p/protocol/identify github.com/libp2p/go-libp2p/p2p/protocol/identify/pb github.com/libp2p/go-libp2p/p2p/protocol/ping -# github.com/libp2p/go-libp2p-autonat v0.1.0 +# github.com/libp2p/go-libp2p-autonat v0.1.1 github.com/libp2p/go-libp2p-autonat github.com/libp2p/go-libp2p-autonat/pb -# github.com/libp2p/go-libp2p-circuit v0.1.3 +# github.com/libp2p/go-libp2p-circuit v0.1.4 github.com/libp2p/go-libp2p-circuit github.com/libp2p/go-libp2p-circuit/pb -# github.com/libp2p/go-libp2p-core v0.2.3 +# github.com/libp2p/go-libp2p-core v0.2.4 github.com/libp2p/go-libp2p-core/connmgr github.com/libp2p/go-libp2p-core/crypto github.com/libp2p/go-libp2p-core/crypto/pb @@ -239,13 +238,13 @@ github.com/libp2p/go-libp2p-discovery github.com/libp2p/go-libp2p-loggables # github.com/libp2p/go-libp2p-mplex v0.2.1 github.com/libp2p/go-libp2p-mplex -# github.com/libp2p/go-libp2p-nat v0.0.4 +# github.com/libp2p/go-libp2p-nat v0.0.5 github.com/libp2p/go-libp2p-nat -# github.com/libp2p/go-libp2p-peerstore v0.1.3 +# github.com/libp2p/go-libp2p-peerstore v0.1.4 github.com/libp2p/go-libp2p-peerstore github.com/libp2p/go-libp2p-peerstore/addr github.com/libp2p/go-libp2p-peerstore/pstoremem -# github.com/libp2p/go-libp2p-secio v0.2.0 +# github.com/libp2p/go-libp2p-secio v0.2.1 github.com/libp2p/go-libp2p-secio github.com/libp2p/go-libp2p-secio/pb # github.com/libp2p/go-libp2p-swarm v0.2.2 @@ -260,9 +259,9 @@ github.com/libp2p/go-maddr-filter github.com/libp2p/go-mplex # github.com/libp2p/go-msgio v0.0.4 github.com/libp2p/go-msgio -# github.com/libp2p/go-nat v0.0.3 +# github.com/libp2p/go-nat v0.0.4 github.com/libp2p/go-nat -# github.com/libp2p/go-openssl v0.0.2 +# github.com/libp2p/go-openssl v0.0.3 github.com/libp2p/go-openssl github.com/libp2p/go-openssl/utils # github.com/libp2p/go-reuseport v0.0.1 @@ -297,11 +296,11 @@ github.com/mr-tron/base58/base58 github.com/multiformats/go-base32 # github.com/multiformats/go-multiaddr v0.1.1 github.com/multiformats/go-multiaddr -# github.com/multiformats/go-multiaddr-dns v0.1.0 +# github.com/multiformats/go-multiaddr-dns v0.2.0 github.com/multiformats/go-multiaddr-dns # github.com/multiformats/go-multiaddr-fmt v0.1.0 github.com/multiformats/go-multiaddr-fmt -# github.com/multiformats/go-multiaddr-net v0.1.0 +# github.com/multiformats/go-multiaddr-net v0.1.1 github.com/multiformats/go-multiaddr-net # github.com/multiformats/go-multibase v0.0.1 github.com/multiformats/go-multibase @@ -372,6 +371,7 @@ github.com/status-im/rendezvous/server # github.com/status-im/status-go/eth-node v1.1.0 => ./eth-node github.com/status-im/status-go/eth-node/bridge/geth github.com/status-im/status-go/eth-node/bridge/geth/ens +github.com/status-im/status-go/eth-node/core/types github.com/status-im/status-go/eth-node/crypto github.com/status-im/status-go/eth-node/crypto/ecies github.com/status-im/status-go/eth-node/keystore @@ -459,8 +459,6 @@ github.com/wealdtech/go-ens/v3/util github.com/wealdtech/go-multicodec # github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc github.com/whyrusleeping/go-logging -# github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f -github.com/whyrusleeping/go-notifier # github.com/whyrusleeping/mafmt v1.2.8 github.com/whyrusleeping/mafmt # github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7