From aed16a9071d61fb87e42d31bab0c0dbfe622f284 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Mon, 26 Mar 2018 18:17:17 +0300 Subject: [PATCH 1/7] patch --- ...send-self-messages-without-subscribe.patch | 58 +++++++++++++++++++ _assets/patches/geth/README.md | 2 + 2 files changed, 60 insertions(+) create mode 100644 _assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch diff --git a/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch b/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch new file mode 100644 index 000000000..88a9d0b28 --- /dev/null +++ b/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch @@ -0,0 +1,58 @@ +diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go +index 16db034e..9d5ebf84 100644 +--- a/whisper/whisperv6/api.go ++++ b/whisper/whisperv6/api.go +@@ -264,6 +264,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er + WorkTime: req.PowTime, + PoW: req.PowTarget, + Topic: req.Topic, ++ self: true, + } + + // Set key that is used to sign the message +diff --git a/whisper/whisperv6/envelope.go b/whisper/whisperv6/envelope.go +index c7bea2bb..5218d755 100644 +--- a/whisper/whisperv6/envelope.go ++++ b/whisper/whisperv6/envelope.go +@@ -47,6 +47,7 @@ type Envelope struct { + // the following variables should not be accessed directly, use the corresponding function instead: Hash(), Bloom() + hash common.Hash // Cached hash of the envelope to avoid rehashing every time. + bloom []byte ++ self bool + } + + // size returns the size of envelope as it is sent (i.e. public fields only) +diff --git a/whisper/whisperv6/message.go b/whisper/whisperv6/message.go +index b8318cbe..a31dcbe1 100644 +--- a/whisper/whisperv6/message.go ++++ b/whisper/whisperv6/message.go +@@ -46,6 +46,8 @@ type MessageParams struct { + PoW float64 + Payload []byte + Padding []byte ++ ++ self bool + } + + // SentMessage represents an end-user data packet to transmit through the +@@ -258,6 +260,7 @@ func (msg *sentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er + if err = envelope.Seal(options); err != nil { + return nil, err + } ++ envelope.self = options.self + return envelope, nil + } + +diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go +index a9e12d4a..94b9a42f 100644 +--- a/whisper/whisperv6/whisper.go ++++ b/whisper/whisperv6/whisper.go +@@ -852,7 +852,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) { + } + } + +- if !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { ++ if !envelope.self && !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { + // maybe the value was recently changed, and the peers did not adjust yet. + // in this case the previous value is retrieved by BloomFilterTolerance() + // for a short period of peer synchronization. diff --git a/_assets/patches/geth/README.md b/_assets/patches/geth/README.md index 4e5dc7758..432edc1b6 100644 --- a/_assets/patches/geth/README.md +++ b/_assets/patches/geth/README.md @@ -36,6 +36,8 @@ Instructions for creating a patch from the command line: - [`0014-whisperv6-notifications.patch`](./0014-whisperv6-notifications.patch) — adds Whisper v6 notifications (need to be reviewed and documented) - [`0015-whisperv6-envelopes-tracing.patch`](./0015-whisperv6-envelopes-tracing.patch) — adds Whisper v6 envelope tracing (need to be reviewed and documented) - [`0018-geth-181-whisperv6-peer-race-cond-fix.patch`](./0018-geth-181-whisperv6-peer-race-cond-fix.patch) — Fixes race condition in Whisper v6. This has been merged upstream and this patch will need to be removed for 1.8.2. +- [`0019-whisperv6-send-self-messages-without-subscribe.patch`](./0019-whisperv6-send-self-messages-without-subscribe.patch) — Allows user to send own messages without the subscription to it's topic + # Updating From aaf2b41e2e7c28ff879f0cddb0746cdd1dc095b4 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Mon, 26 Mar 2018 19:01:26 +0300 Subject: [PATCH 2/7] test sending message without subscription --- t/e2e/whisper/whisper_mailbox_test.go | 49 +++++++++++++++++++++------ 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/t/e2e/whisper/whisper_mailbox_test.go b/t/e2e/whisper/whisper_mailbox_test.go index 545acef3b..1a215dce8 100644 --- a/t/e2e/whisper/whisper_mailbox_test.go +++ b/t/e2e/whisper/whisper_mailbox_test.go @@ -110,7 +110,7 @@ func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() { reqMessagesResp := baseRPCResponse{} err = json.Unmarshal([]byte(resp), &reqMessagesResp) s.Require().NoError(err) - s.Require().Nil(reqMessagesResp.Err) + s.Require().Nil(reqMessagesResp.Error) //wait to receive message time.Sleep(time.Second) @@ -276,6 +276,31 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() { s.Require().Equal(helloWorldMessage, messages[0]["payload"].(string)) } +func (s *WhisperMailboxSuite) TestSendMessageWithoutSubscription() { + aliceBackend, stop := s.startBackend("alice") + defer stop() + + // we need to wain >= whisper.DefaultSyncAllowance seconds to update + time.Sleep(12 * time.Second) + + //get whisper service + aliceWhisperService, err := aliceBackend.NodeManager().WhisperService() + s.Require().NoError(err) + //get rpc client + aliceRPCClient := aliceBackend.NodeManager().RPCClient() + + //generate group chat symkey and topic + groupChatKeyID, err := aliceWhisperService.GenerateSymKey() + s.Require().NoError(err) + //generate group chat topic + groupChatTopic := whisper.BytesToTopic([]byte("groupChatTopic")) + + //alice send message to group chat + helloWorldMessage := hexutil.Encode([]byte("Hello world!")) + s.postMessageToGroup(aliceRPCClient, groupChatKeyID, groupChatTopic.String(), helloWorldMessage) + time.Sleep(5 * time.Second) //it need to receive envelopes by bob and charlie nodes +} + func newGroupChatParams(symkey []byte, topic whisper.TopicType) groupChatParams { groupChatKeyStr := hexutil.Bytes(symkey).String() return groupChatParams{ @@ -314,6 +339,8 @@ func (s *WhisperMailboxSuite) startBackend(name string) (*api.StatusBackend, fun s.Require().NoError(err) s.Require().False(backend.IsNodeRunning()) + nodeConfig.WhisperConfig.LightClient = true + if addr, err := GetRemoteURL(); err == nil { nodeConfig.UpstreamConfig.Enabled = true nodeConfig.UpstreamConfig.URL = addr @@ -373,7 +400,7 @@ func (s *WhisperMailboxSuite) createPrivateChatMessageFilter(rpcCli *rpc.Client, err := json.Unmarshal([]byte(resp), &msgFilterResp) messageFilterID := msgFilterResp.Result s.Require().NoError(err) - s.Require().Nil(msgFilterResp.Err) + s.Require().Nil(msgFilterResp.Error) s.Require().NotEqual("", messageFilterID, resp) return messageFilterID } @@ -392,7 +419,7 @@ func (s *WhisperMailboxSuite) createGroupChatMessageFilter(rpcCli *rpc.Client, s err := json.Unmarshal([]byte(resp), &msgFilterResp) messageFilterID := msgFilterResp.Result s.Require().NoError(err) - s.Require().Nil(msgFilterResp.Err) + s.Require().Nil(msgFilterResp.Error) s.Require().NotEqual("", messageFilterID, resp) return messageFilterID } @@ -414,7 +441,7 @@ func (s *WhisperMailboxSuite) postMessageToPrivate(rpcCli *rpc.Client, bobPubkey postResp := baseRPCResponse{} err := json.Unmarshal([]byte(resp), &postResp) s.Require().NoError(err) - s.Require().Nil(postResp.Err) + s.Require().Nil(postResp.Error) } func (s *WhisperMailboxSuite) postMessageToGroup(rpcCli *rpc.Client, groupChatKeyID string, topic string, payload string) { @@ -434,7 +461,7 @@ func (s *WhisperMailboxSuite) postMessageToGroup(rpcCli *rpc.Client, groupChatKe postResp := baseRPCResponse{} err := json.Unmarshal([]byte(resp), &postResp) s.Require().NoError(err) - s.Require().Nil(postResp.Err) + s.Require().Nil(postResp.Error) } //getMessagesByMessageFilterID get received messages by messageFilterID @@ -447,7 +474,7 @@ func (s *WhisperMailboxSuite) getMessagesByMessageFilterID(rpcCli *rpc.Client, m messages := getFilterMessagesResponse{} err := json.Unmarshal([]byte(resp), &messages) s.Require().NoError(err) - s.Require().Nil(messages.Err) + s.Require().Nil(messages.Error) return messages.Result } @@ -459,7 +486,7 @@ func (s *WhisperMailboxSuite) addSymKey(rpcCli *rpc.Client, symkey string) strin symkeyAddResp := returnedIDResponse{} err := json.Unmarshal([]byte(resp), &symkeyAddResp) s.Require().NoError(err) - s.Require().Nil(symkeyAddResp.Err) + s.Require().Nil(symkeyAddResp.Error) symkeyID := symkeyAddResp.Result s.Require().NotEmpty(symkeyID) return symkeyID @@ -482,19 +509,19 @@ func (s *WhisperMailboxSuite) requestHistoricMessages(rpcCli *rpc.Client, mailbo reqMessagesResp := baseRPCResponse{} err := json.Unmarshal([]byte(resp), &reqMessagesResp) s.Require().NoError(err) - s.Require().Nil(reqMessagesResp.Err) + s.Require().Nil(reqMessagesResp.Error) } type getFilterMessagesResponse struct { Result []map[string]interface{} - Err interface{} + Error interface{} } type returnedIDResponse struct { Result string - Err interface{} + Error interface{} } type baseRPCResponse struct { Result interface{} - Err interface{} + Error interface{} } From de0c03ca4ec27d723e08246e3a937d43fbe035b6 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Mon, 26 Mar 2018 19:30:31 +0300 Subject: [PATCH 3/7] patch sending message without subscription applied --- .../github.com/ethereum/go-ethereum/whisper/whisperv6/api.go | 1 + .../ethereum/go-ethereum/whisper/whisperv6/envelope.go | 1 + .../ethereum/go-ethereum/whisper/whisperv6/message.go | 3 +++ .../ethereum/go-ethereum/whisper/whisperv6/whisper.go | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go index 16db034e1..9d5ebf84a 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go @@ -264,6 +264,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er WorkTime: req.PowTime, PoW: req.PowTarget, Topic: req.Topic, + self: true, } // Set key that is used to sign the message diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go index c7bea2bb9..5218d755c 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go @@ -47,6 +47,7 @@ type Envelope struct { // the following variables should not be accessed directly, use the corresponding function instead: Hash(), Bloom() hash common.Hash // Cached hash of the envelope to avoid rehashing every time. bloom []byte + self bool } // size returns the size of envelope as it is sent (i.e. public fields only) diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go index b8318cbe8..a31dcbe12 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go @@ -46,6 +46,8 @@ type MessageParams struct { PoW float64 Payload []byte Padding []byte + + self bool } // SentMessage represents an end-user data packet to transmit through the @@ -258,6 +260,7 @@ func (msg *sentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er if err = envelope.Seal(options); err != nil { return nil, err } + envelope.self = options.self return envelope, nil } diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go index a9e12d4a8..9743e0816 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go @@ -852,7 +852,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) { } } - if !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { + if !envelope.self && !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { // maybe the value was recently changed, and the peers did not adjust yet. // in this case the previous value is retrieved by BloomFilterTolerance() // for a short period of peer synchronization. From a90be3c0de830cfc2b504bdedb8ca44854d8411e Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Mon, 26 Mar 2018 19:53:55 +0300 Subject: [PATCH 4/7] fixes after code review --- t/e2e/whisper/whisper_mailbox_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/t/e2e/whisper/whisper_mailbox_test.go b/t/e2e/whisper/whisper_mailbox_test.go index 1a215dce8..42abfa5e5 100644 --- a/t/e2e/whisper/whisper_mailbox_test.go +++ b/t/e2e/whisper/whisper_mailbox_test.go @@ -280,8 +280,8 @@ func (s *WhisperMailboxSuite) TestSendMessageWithoutSubscription() { aliceBackend, stop := s.startBackend("alice") defer stop() - // we need to wain >= whisper.DefaultSyncAllowance seconds to update - time.Sleep(12 * time.Second) + // we need to wait >= whisper.DefaultSyncAllowance seconds to update Bloom filter tolerated + time.Sleep((whisper.DefaultSyncAllowance + 1) * time.Second) //get whisper service aliceWhisperService, err := aliceBackend.NodeManager().WhisperService() @@ -298,7 +298,6 @@ func (s *WhisperMailboxSuite) TestSendMessageWithoutSubscription() { //alice send message to group chat helloWorldMessage := hexutil.Encode([]byte("Hello world!")) s.postMessageToGroup(aliceRPCClient, groupChatKeyID, groupChatTopic.String(), helloWorldMessage) - time.Sleep(5 * time.Second) //it need to receive envelopes by bob and charlie nodes } func newGroupChatParams(symkey []byte, topic whisper.TopicType) groupChatParams { From b9598a1a31c7dcab8f9d966b618f57218c3a9ced Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Mon, 26 Mar 2018 20:05:24 +0300 Subject: [PATCH 5/7] led comments to the standard --- t/e2e/whisper/whisper_mailbox_test.go | 118 +++++++++++++------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/t/e2e/whisper/whisper_mailbox_test.go b/t/e2e/whisper/whisper_mailbox_test.go index 42abfa5e5..953f80ad5 100644 --- a/t/e2e/whisper/whisper_mailbox_test.go +++ b/t/e2e/whisper/whisper_mailbox_test.go @@ -28,7 +28,7 @@ func TestWhisperMailboxTestSuite(t *testing.T) { } func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() { - //Start mailbox and status node + // Start mailbox and status node. mailboxBackend, stop := s.startMailboxBackend() defer stop() mailboxNode, err := mailboxBackend.NodeManager().Node() @@ -44,13 +44,13 @@ func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() { err = sender.NodeManager().AddPeer(mailboxEnode) s.Require().NoError(err) - //wait async processes on adding peer + // Wait async processes on adding peer. time.Sleep(time.Second) senderWhisperService, err := sender.NodeManager().WhisperService() s.Require().NoError(err) - //Mark mailbox node trusted + // Mark mailbox node trusted. parsedNode, err := discover.ParseNode(mailboxNode.Server().NodeInfo().Enode) s.Require().NoError(err) mailboxPeer := parsedNode.ID[:] @@ -58,7 +58,7 @@ func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() { err = senderWhisperService.AllowP2PMessagesFromPeer(mailboxPeer) s.Require().NoError(err) - //Generate mailbox symkey + // Generate mailbox symkey. password := "status-offline-inbox" MailServerKeyID, err := senderWhisperService.AddSymKeyFromPassword(password) s.Require().NoError(err) @@ -66,34 +66,34 @@ func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() { rpcClient := sender.NodeManager().RPCClient() s.Require().NotNil(rpcClient) - //create topic + // Create topic. topic := whisper.BytesToTopic([]byte("topic name")) - //Add key pair to whisper + // Add key pair to whisper. keyID, err := senderWhisperService.NewKeyPair() s.Require().NoError(err) key, err := senderWhisperService.GetPrivateKey(keyID) s.Require().NoError(err) pubkey := hexutil.Bytes(crypto.FromECDSAPub(&key.PublicKey)) - //Create message filter + // Create message filter. messageFilterID := s.createPrivateChatMessageFilter(rpcClient, keyID, topic.String()) - //Threre are no messages at filter + // There are no messages at filter. messages := s.getMessagesByMessageFilterID(rpcClient, messageFilterID) s.Require().Equal(0, len(messages)) - //Post message matching with filter (key and token) + // Post message matching with filter (key and token). s.postMessageToPrivate(rpcClient, pubkey.String(), topic.String(), hexutil.Encode([]byte("Hello world!"))) - //Get message to make sure that it will come from the mailbox later + // Get message to make sure that it will come from the mailbox later. time.Sleep(1 * time.Second) messages = s.getMessagesByMessageFilterID(rpcClient, messageFilterID) s.Require().Equal(1, len(messages)) - //act + // Act. - //Request messages (including the previous one, expired) from mailbox + // Request messages (including the previous one, expired) from mailbox. reqMessagesBody := `{ "jsonrpc": "2.0", "id": 1, @@ -112,19 +112,19 @@ func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() { s.Require().NoError(err) s.Require().Nil(reqMessagesResp.Error) - //wait to receive message + // Wait to receive message. time.Sleep(time.Second) - //And we receive message, it comes from mailbox + // And we receive message, it comes from mailbox. messages = s.getMessagesByMessageFilterID(rpcClient, messageFilterID) s.Require().Equal(1, len(messages)) - //check that there are no messages + // Check that there are no messages. messages = s.getMessagesByMessageFilterID(rpcClient, messageFilterID) s.Require().Equal(0, len(messages)) } func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() { - //Start mailbox, alice, bob, charlie node + // Start mailbox, alice, bob, charlie node. mailboxBackend, stop := s.startMailboxBackend() defer stop() @@ -137,7 +137,7 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() { charlieBackend, stop := s.startBackend("charlie") defer stop() - //add mailbox to static peers + // Add mailbox to static peers. mailboxNode, err := mailboxBackend.NodeManager().Node() s.Require().NoError(err) mailboxEnode := mailboxNode.Server().NodeInfo().Enode @@ -148,40 +148,40 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() { s.Require().NoError(err) err = charlieBackend.NodeManager().AddPeer(mailboxEnode) s.Require().NoError(err) - //wait async processes on adding peer + // Wait async processes on adding peer. time.Sleep(time.Second) - //get whisper service + // Get whisper service. aliceWhisperService, err := aliceBackend.NodeManager().WhisperService() s.Require().NoError(err) bobWhisperService, err := bobBackend.NodeManager().WhisperService() s.Require().NoError(err) charlieWhisperService, err := charlieBackend.NodeManager().WhisperService() s.Require().NoError(err) - //get rpc client + // Get rpc client. aliceRPCClient := aliceBackend.NodeManager().RPCClient() bobRPCClient := bobBackend.NodeManager().RPCClient() charlieRPCClient := charlieBackend.NodeManager().RPCClient() - //bob and charlie add mailserver key + // Bob and charlie add the mailserver key. password := "status-offline-inbox" bobMailServerKeyID, err := bobWhisperService.AddSymKeyFromPassword(password) s.Require().NoError(err) charlieMailServerKeyID, err := charlieWhisperService.AddSymKeyFromPassword(password) s.Require().NoError(err) - //generate group chat symkey and topic + // Generate a group chat symkey and topic. groupChatKeyID, err := aliceWhisperService.GenerateSymKey() s.Require().NoError(err) groupChatKey, err := aliceWhisperService.GetSymKey(groupChatKeyID) s.Require().NoError(err) - //generate group chat topic + // Generate a group chat topic. groupChatTopic := whisper.BytesToTopic([]byte("groupChatTopic")) groupChatPayload := newGroupChatParams(groupChatKey, groupChatTopic) payloadStr, err := groupChatPayload.Encode() s.Require().NoError(err) - //Add bob and charlie create key pairs to receive symmetric key for group chat from alice + // Add Bob and Charlie's key pairs to receive the symmetric key for the group chat from Alice. bobKeyID, err := bobWhisperService.NewKeyPair() s.Require().NoError(err) bobKey, err := bobWhisperService.GetPrivateKey(bobKeyID) @@ -196,19 +196,19 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() { charliePubkey := hexutil.Bytes(crypto.FromECDSAPub(&charlieKey.PublicKey)) charlieAliceKeySendTopic := whisper.BytesToTopic([]byte("charlieAliceKeySendTopic ")) - //bob and charlie create message filter + // Bob and charlie create message filter. bobMessageFilterID := s.createPrivateChatMessageFilter(bobRPCClient, bobKeyID, bobAliceKeySendTopic.String()) charlieMessageFilterID := s.createPrivateChatMessageFilter(charlieRPCClient, charlieKeyID, charlieAliceKeySendTopic.String()) - //Alice send message with symkey and topic to bob and charlie + // Alice send message with symkey and topic to Bob and Charlie. s.postMessageToPrivate(aliceRPCClient, bobPubkey.String(), bobAliceKeySendTopic.String(), payloadStr) s.postMessageToPrivate(aliceRPCClient, charliePubkey.String(), charlieAliceKeySendTopic.String(), payloadStr) - //wait to receive + // Wait to receive. time.Sleep(5 * time.Second) - //bob receive group chat data and add it to his node - //1. bob get group chat details + // Bob receive group chat data and add it to his node. + // Bob get group chat details. messages := s.getMessagesByMessageFilterID(bobRPCClient, bobMessageFilterID) s.Require().Equal(1, len(messages)) bobGroupChatData := groupChatParams{} @@ -216,15 +216,15 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() { s.Require().NoError(err) s.EqualValues(groupChatPayload, bobGroupChatData) - //2. bob add symkey to his node + // Bob add symkey to his node. bobGroupChatSymkeyID := s.addSymKey(bobRPCClient, bobGroupChatData.Key) s.Require().NotEmpty(bobGroupChatSymkeyID) - //3. bob create message filter to node by group chat topic + // Bob create message filter to node by group chat topic. bobGroupChatMessageFilterID := s.createGroupChatMessageFilter(bobRPCClient, bobGroupChatSymkeyID, bobGroupChatData.Topic) - //charlie receive group chat data and add it to his node - //1. charlie get group chat details + // Charlie receive group chat data and add it to his node. + // Charlie get group chat details. messages = s.getMessagesByMessageFilterID(charlieRPCClient, charlieMessageFilterID) s.Require().Equal(1, len(messages)) charlieGroupChatData := groupChatParams{} @@ -232,45 +232,47 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() { s.Require().NoError(err) s.EqualValues(groupChatPayload, charlieGroupChatData) - //2. charlie add symkey to his node + // Charlie add symkey to his node. charlieGroupChatSymkeyID := s.addSymKey(charlieRPCClient, charlieGroupChatData.Key) s.Require().NotEmpty(charlieGroupChatSymkeyID) - //3. charlie create message filter to node by group chat topic + // Charlie create message filter to node by group chat topic. charlieGroupChatMessageFilterID := s.createGroupChatMessageFilter(charlieRPCClient, charlieGroupChatSymkeyID, charlieGroupChatData.Topic) - //alice send message to group chat + // Alice send message to group chat. helloWorldMessage := hexutil.Encode([]byte("Hello world!")) s.postMessageToGroup(aliceRPCClient, groupChatKeyID, groupChatTopic.String(), helloWorldMessage) - time.Sleep(5 * time.Second) //it need to receive envelopes by bob and charlie nodes + // It need to receive envelopes by bob and charlie nodes. + time.Sleep(5 * time.Second) - //bob receive group chat message + // Bob receive group chat message. messages = s.getMessagesByMessageFilterID(bobRPCClient, bobGroupChatMessageFilterID) s.Require().Equal(1, len(messages)) s.Require().Equal(helloWorldMessage, messages[0]["payload"].(string)) - //charlie receive group chat message + // Charlie receive group chat message. messages = s.getMessagesByMessageFilterID(charlieRPCClient, charlieGroupChatMessageFilterID) s.Require().Equal(1, len(messages)) s.Require().Equal(helloWorldMessage, messages[0]["payload"].(string)) - //check that we don't receive messages each one time + // Check that we don't receive messages each one time. messages = s.getMessagesByMessageFilterID(bobRPCClient, bobGroupChatMessageFilterID) s.Require().Equal(0, len(messages)) messages = s.getMessagesByMessageFilterID(charlieRPCClient, charlieGroupChatMessageFilterID) s.Require().Equal(0, len(messages)) - //Request each one messages from mailbox using enode + // Request each one messages from mailbox using enode. s.requestHistoricMessages(bobRPCClient, mailboxEnode, bobMailServerKeyID, groupChatTopic.String()) s.requestHistoricMessages(charlieRPCClient, mailboxEnode, charlieMailServerKeyID, groupChatTopic.String()) - time.Sleep(5 * time.Second) //wait to receive p2p messages + // Wait to receive p2p messages. + time.Sleep(5 * time.Second) - //bob receive p2p message from grop chat filter + // Bob receive p2p message from group chat filter. messages = s.getMessagesByMessageFilterID(bobRPCClient, bobGroupChatMessageFilterID) s.Require().Equal(1, len(messages)) s.Require().Equal(helloWorldMessage, messages[0]["payload"].(string)) - //charlie receive p2p message from grop chat filter + // Charlie receive p2p message from group chat filter. messages = s.getMessagesByMessageFilterID(charlieRPCClient, charlieGroupChatMessageFilterID) s.Require().Equal(1, len(messages)) s.Require().Equal(helloWorldMessage, messages[0]["payload"].(string)) @@ -280,22 +282,24 @@ func (s *WhisperMailboxSuite) TestSendMessageWithoutSubscription() { aliceBackend, stop := s.startBackend("alice") defer stop() - // we need to wait >= whisper.DefaultSyncAllowance seconds to update Bloom filter tolerated + // We need to wait >= whisper.DefaultSyncAllowance seconds to update Bloom filter tolerated. time.Sleep((whisper.DefaultSyncAllowance + 1) * time.Second) - //get whisper service + // Get whisper service. aliceWhisperService, err := aliceBackend.NodeManager().WhisperService() s.Require().NoError(err) - //get rpc client + + // Get rpc client. aliceRPCClient := aliceBackend.NodeManager().RPCClient() - //generate group chat symkey and topic + // Generate group chat symkey and topic. groupChatKeyID, err := aliceWhisperService.GenerateSymKey() s.Require().NoError(err) - //generate group chat topic + + // Generate group chat topic. groupChatTopic := whisper.BytesToTopic([]byte("groupChatTopic")) - //alice send message to group chat + // Alice send message to group chat. helloWorldMessage := hexutil.Encode([]byte("Hello world!")) s.postMessageToGroup(aliceRPCClient, groupChatKeyID, groupChatTopic.String(), helloWorldMessage) } @@ -329,7 +333,7 @@ func (d *groupChatParams) Encode() (string, error) { return hexutil.Bytes(payload).String(), nil } -//Start status node +// Start status node. func (s *WhisperMailboxSuite) startBackend(name string) (*api.StatusBackend, func()) { datadir := filepath.Join(RootDir, ".ethereumtest/mailbox", name) backend := api.NewStatusBackend() @@ -358,7 +362,7 @@ func (s *WhisperMailboxSuite) startBackend(name string) (*api.StatusBackend, fun } -//Start mailbox node +// Start mailbox node. func (s *WhisperMailboxSuite) startMailboxBackend() (*api.StatusBackend, func()) { mailboxBackend := api.NewStatusBackend() mailboxConfig, err := MakeTestNodeConfig(GetNetworkID()) @@ -385,7 +389,7 @@ func (s *WhisperMailboxSuite) startMailboxBackend() (*api.StatusBackend, func()) } } -//createPrivateChatMessageFilter create message filter with asymmetric encryption +// createPrivateChatMessageFilter create message filter with asymmetric encryption. func (s *WhisperMailboxSuite) createPrivateChatMessageFilter(rpcCli *rpc.Client, privateKeyID string, topic string) string { resp := rpcCli.CallRaw(`{ "jsonrpc": "2.0", @@ -404,7 +408,7 @@ func (s *WhisperMailboxSuite) createPrivateChatMessageFilter(rpcCli *rpc.Client, return messageFilterID } -//createGroupChatMessageFilter create message filter with symmetric encryption +// createGroupChatMessageFilter create message filter with symmetric encryption. func (s *WhisperMailboxSuite) createGroupChatMessageFilter(rpcCli *rpc.Client, symkeyID string, topic string) string { resp := rpcCli.CallRaw(`{ "jsonrpc": "2.0", @@ -463,7 +467,7 @@ func (s *WhisperMailboxSuite) postMessageToGroup(rpcCli *rpc.Client, groupChatKe s.Require().Nil(postResp.Error) } -//getMessagesByMessageFilterID get received messages by messageFilterID +// getMessagesByMessageFilterID gets received messages by messageFilterID. func (s *WhisperMailboxSuite) getMessagesByMessageFilterID(rpcCli *rpc.Client, messageFilterID string) []map[string]interface{} { resp := rpcCli.CallRaw(`{ "jsonrpc": "2.0", @@ -477,7 +481,7 @@ func (s *WhisperMailboxSuite) getMessagesByMessageFilterID(rpcCli *rpc.Client, m return messages.Result } -//addSymKey added symkey to node and return symkeyID +// addSymKey added symkey to node and return symkeyID. func (s *WhisperMailboxSuite) addSymKey(rpcCli *rpc.Client, symkey string) string { resp := rpcCli.CallRaw(`{"jsonrpc":"2.0","method":"shh_addSymKey", "params":["` + symkey + `"], @@ -491,7 +495,7 @@ func (s *WhisperMailboxSuite) addSymKey(rpcCli *rpc.Client, symkey string) strin return symkeyID } -//requestHistoricMessages ask mailnode to resend messagess +// requestHistoricMessages asks a mailnode to resend messages. func (s *WhisperMailboxSuite) requestHistoricMessages(rpcCli *rpc.Client, mailboxEnode, mailServerKeyID, topic string) { resp := rpcCli.CallRaw(`{ "jsonrpc": "2.0", From b4c1cd72124b1b0de7993f7bab47529397b4ef1d Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Tue, 27 Mar 2018 17:47:15 +0300 Subject: [PATCH 6/7] send in-house messages without subscription --- ...send-self-messages-without-subscribe.patch | 78 +++++++------------ .../go-ethereum/whisper/whisperv6/api.go | 1 - .../go-ethereum/whisper/whisperv6/envelope.go | 1 - .../go-ethereum/whisper/whisperv6/message.go | 3 - .../go-ethereum/whisper/whisperv6/whisper.go | 8 +- 5 files changed, 34 insertions(+), 57 deletions(-) diff --git a/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch b/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch index 88a9d0b28..7098560f9 100644 --- a/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch +++ b/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch @@ -1,58 +1,40 @@ -diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go -index 16db034e..9d5ebf84 100644 ---- a/whisper/whisperv6/api.go -+++ b/whisper/whisperv6/api.go -@@ -264,6 +264,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er - WorkTime: req.PowTime, - PoW: req.PowTarget, - Topic: req.Topic, -+ self: true, - } - - // Set key that is used to sign the message -diff --git a/whisper/whisperv6/envelope.go b/whisper/whisperv6/envelope.go -index c7bea2bb..5218d755 100644 ---- a/whisper/whisperv6/envelope.go -+++ b/whisper/whisperv6/envelope.go -@@ -47,6 +47,7 @@ type Envelope struct { - // the following variables should not be accessed directly, use the corresponding function instead: Hash(), Bloom() - hash common.Hash // Cached hash of the envelope to avoid rehashing every time. - bloom []byte -+ self bool - } - - // size returns the size of envelope as it is sent (i.e. public fields only) -diff --git a/whisper/whisperv6/message.go b/whisper/whisperv6/message.go -index b8318cbe..a31dcbe1 100644 ---- a/whisper/whisperv6/message.go -+++ b/whisper/whisperv6/message.go -@@ -46,6 +46,8 @@ type MessageParams struct { - PoW float64 - Payload []byte - Padding []byte -+ -+ self bool - } - - // SentMessage represents an end-user data packet to transmit through the -@@ -258,6 +260,7 @@ func (msg *sentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er - if err = envelope.Seal(options); err != nil { - return nil, err - } -+ envelope.self = options.self - return envelope, nil - } - diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go -index a9e12d4a..94b9a42f 100644 +index a9e12d4a..ee82ac6d 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go +@@ -658,7 +658,7 @@ func (whisper *Whisper) Unsubscribe(id string) error { + // Send injects a message into the whisper send queue, to be distributed in the + // network in the coming cycles. + func (whisper *Whisper) Send(envelope *Envelope) error { +- ok, err := whisper.add(envelope) ++ ok, err := whisper.add(envelope, false) + if err != nil { + return err + } +@@ -745,7 +745,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error { + trouble := false + for _, env := range envelopes { + whisper.traceEnvelope(env, !whisper.isEnvelopeCached(env.Hash()), peerSource, p) +- cached, err := whisper.add(env) ++ cached, err := whisper.add(env, true) + if err != nil { + trouble = true + log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) +@@ -819,7 +819,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error { + // add inserts a new envelope into the message pool to be distributed within the + // whisper network. It also inserts the envelope into the expiration pool at the + // appropriate time-stamp. In case of error, connection should be dropped. +-func (whisper *Whisper) add(envelope *Envelope) (bool, error) { ++func (whisper *Whisper) add(envelope *Envelope, isForwarded bool) (bool, error) { + now := uint32(time.Now().Unix()) + sent := envelope.Expiry - envelope.TTL + @@ -852,7 +852,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) { } } - + - if !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { -+ if !envelope.self && !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { ++ if isForwarded && !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { // maybe the value was recently changed, and the peers did not adjust yet. // in this case the previous value is retrieved by BloomFilterTolerance() // for a short period of peer synchronization. diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go index 9d5ebf84a..16db034e1 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/api.go @@ -264,7 +264,6 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er WorkTime: req.PowTime, PoW: req.PowTarget, Topic: req.Topic, - self: true, } // Set key that is used to sign the message diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go index 5218d755c..c7bea2bb9 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/envelope.go @@ -47,7 +47,6 @@ type Envelope struct { // the following variables should not be accessed directly, use the corresponding function instead: Hash(), Bloom() hash common.Hash // Cached hash of the envelope to avoid rehashing every time. bloom []byte - self bool } // size returns the size of envelope as it is sent (i.e. public fields only) diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go index a31dcbe12..b8318cbe8 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/message.go @@ -46,8 +46,6 @@ type MessageParams struct { PoW float64 Payload []byte Padding []byte - - self bool } // SentMessage represents an end-user data packet to transmit through the @@ -260,7 +258,6 @@ func (msg *sentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er if err = envelope.Seal(options); err != nil { return nil, err } - envelope.self = options.self return envelope, nil } diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go index 9743e0816..ee82ac6d5 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go @@ -658,7 +658,7 @@ func (whisper *Whisper) Unsubscribe(id string) error { // Send injects a message into the whisper send queue, to be distributed in the // network in the coming cycles. func (whisper *Whisper) Send(envelope *Envelope) error { - ok, err := whisper.add(envelope) + ok, err := whisper.add(envelope, false) if err != nil { return err } @@ -745,7 +745,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error { trouble := false for _, env := range envelopes { whisper.traceEnvelope(env, !whisper.isEnvelopeCached(env.Hash()), peerSource, p) - cached, err := whisper.add(env) + cached, err := whisper.add(env, true) if err != nil { trouble = true log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) @@ -819,7 +819,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error { // add inserts a new envelope into the message pool to be distributed within the // whisper network. It also inserts the envelope into the expiration pool at the // appropriate time-stamp. In case of error, connection should be dropped. -func (whisper *Whisper) add(envelope *Envelope) (bool, error) { +func (whisper *Whisper) add(envelope *Envelope, isForwarded bool) (bool, error) { now := uint32(time.Now().Unix()) sent := envelope.Expiry - envelope.TTL @@ -852,7 +852,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) { } } - if !envelope.self && !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { + if isForwarded && !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { // maybe the value was recently changed, and the peers did not adjust yet. // in this case the previous value is retrieved by BloomFilterTolerance() // for a short period of peer synchronization. From e2e2af73d716bf1815002342cd9f56f1cd40bba6 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Tue, 27 Mar 2018 18:22:29 +0300 Subject: [PATCH 7/7] isForwarded constants introduced --- ...send-self-messages-without-subscribe.patch | 24 +++++++++++++++---- .../go-ethereum/whisper/whisperv6/doc.go | 3 +++ .../go-ethereum/whisper/whisperv6/whisper.go | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch b/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch index 7098560f9..99a9dc114 100644 --- a/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch +++ b/_assets/patches/geth/0019-whisperv6-send-self-messages-without-subscribe.patch @@ -1,5 +1,19 @@ +diff --git a/whisper/whisperv6/doc.go b/whisper/whisperv6/doc.go +index a98760b9..06736e55 100644 +--- a/whisper/whisperv6/doc.go ++++ b/whisper/whisperv6/doc.go +@@ -104,6 +104,9 @@ const ( + peerSource envelopeSource = iota + // p2pSource indicates that envelop was received from a trusted peer. + p2pSource ++ ++ forwarded = true ++ inHouse = false + ) + + // EnvelopeMeta keeps metadata of received envelopes. diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go -index a9e12d4a..ee82ac6d 100644 +index a9e12d4a..8bd991a9 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -658,7 +658,7 @@ func (whisper *Whisper) Unsubscribe(id string) error { @@ -7,7 +21,7 @@ index a9e12d4a..ee82ac6d 100644 // network in the coming cycles. func (whisper *Whisper) Send(envelope *Envelope) error { - ok, err := whisper.add(envelope) -+ ok, err := whisper.add(envelope, false) ++ ok, err := whisper.add(envelope, inHouse) if err != nil { return err } @@ -16,7 +30,7 @@ index a9e12d4a..ee82ac6d 100644 for _, env := range envelopes { whisper.traceEnvelope(env, !whisper.isEnvelopeCached(env.Hash()), peerSource, p) - cached, err := whisper.add(env) -+ cached, err := whisper.add(env, true) ++ cached, err := whisper.add(env, forwarded) if err != nil { trouble = true log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) @@ -28,11 +42,11 @@ index a9e12d4a..ee82ac6d 100644 +func (whisper *Whisper) add(envelope *Envelope, isForwarded bool) (bool, error) { now := uint32(time.Now().Unix()) sent := envelope.Expiry - envelope.TTL - + @@ -852,7 +852,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) { } } - + - if !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { + if isForwarded && !bloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) { // maybe the value was recently changed, and the peers did not adjust yet. diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/doc.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/doc.go index a98760b98..06736e55e 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/doc.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/doc.go @@ -104,6 +104,9 @@ const ( peerSource envelopeSource = iota // p2pSource indicates that envelop was received from a trusted peer. p2pSource + + forwarded = true + inHouse = false ) // EnvelopeMeta keeps metadata of received envelopes. diff --git a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go index ee82ac6d5..8bd991a9b 100644 --- a/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go +++ b/vendor/github.com/ethereum/go-ethereum/whisper/whisperv6/whisper.go @@ -658,7 +658,7 @@ func (whisper *Whisper) Unsubscribe(id string) error { // Send injects a message into the whisper send queue, to be distributed in the // network in the coming cycles. func (whisper *Whisper) Send(envelope *Envelope) error { - ok, err := whisper.add(envelope, false) + ok, err := whisper.add(envelope, inHouse) if err != nil { return err } @@ -745,7 +745,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error { trouble := false for _, env := range envelopes { whisper.traceEnvelope(env, !whisper.isEnvelopeCached(env.Hash()), peerSource, p) - cached, err := whisper.add(env, true) + cached, err := whisper.add(env, forwarded) if err != nil { trouble = true log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err)