6
  • geth version: 1.8.15-unstable
  • Python: 3.5
  • OS: osx/linux

I have followed this answer.

On the answer's approach, I observe that each node can only send message to itself and other nodes don't filter/see those messages. For example, when node-1 sends a message to the network; it won't show up on the node-2 such that node-2's web3.shh.info{memory} remains 0, where I assume that it never catches the message.


I have tried using Web3.js and Web3.py where sent message on Node_1 does not show up on Node_2.

=> This is as far as I came by using Web3.js:

The way I start geth:

geth --syncmode fast --cache=1024 --shh --datadir $DATADIR/private  --rpcaddr 127.0.0.1 --rpc --rpcport 8545 --rpccorsdomain="*" --networkid 12345 --rpcapi admin,eth,net,web3,debug,personal,shh

On node-1's geth-client:

generatedSymKey=shh.generateSymKeyFromPassword("hello");    
symKey=shh.getSymKey(generatedSymKey)    
symKeyID=shh.addSymKey(symKey) //ex: "d5212e736703afbb21246e8acd192e4345ea910398544d765ed6b49f0ec524b5"
filter = web3.shh.newMessageFilter(
        {symKeyID: symKeyID, topic: '0x07678231'}, 
        function(err, res) {console.log(web3.toUtf8(res.payload))});

On node-2's geth-client:

generatedSymKey=shh.generateSymKeyFromPassword("hello")    
symKey=shh.getSymKey(generatedSymKey)    
symKeyID=shh.addSymKey(symKey) //ex: "c4c4cecf6ad9499c2386b8ce6416f44684e042e491726b38315646c0b4afadc6"
filter = web3.shh.newMessageFilter(
        {symKeyID: symKeyID, topic: '0x07678231'}, 
        function(err, res) {console.log(web3.toUtf8(res.payload))});

Then, node-1 sends message to the network, where only node-1 receives it but node-2 does not.

Following code is run on node-1's geth-client:

node-1's symKeyID is given:

web3.shh.post({
  symKeyID: 'd5212e736703afbb21246e8acd192e4345ea910398544d765ed6b49f0ec524b5', //symKeyID of the node-1
  ttl: 10,
  topic: '0x07678231',
  powTarget: 2.01,
  powTime: 2,
  payload: web3.fromAscii("Hello there!")
  });

=> This is as far as I came by using Web3.py:

Node_1 runs shh_filter.get_new_entries() in order to catch messages but len(received_messages) returns 0, where there is no message is received and web3.shh.info{memory} remains 0.

On node-1:

from web3 import Web3, HTTPProvider
web3 = Web3(HTTPProvider('http://localhost:8545'))
from web3.shh import Shh
Shh.attach(web3, "shh")

import time, sys;

from hexbytes import (
    HexBytes,
)

receiver = web3.shh.newKeyPair()
receiver_pub = web3.shh.getPublicKey(receiver)
print('receiverPubK: ' + receiver_pub);

topic = '0x07678231'

shh_filter = web3.shh.newMessageFilter({
    'privateKeyID': receiver,
    'topics': [topic]
})

input("Press Enter to continue...");

received_messages = [];
received_messages = shh_filter.get_new_entries()
print(len(received_messages)) # Returns '0'
print(web3.shh.info.memory) # Returns '0'

Output:

receiverPubK: 0x04226d96bf9857ac0ba429c1e8b480a2811ce47cb526dbd3829d7586e5cae740198ba291f3eca0f279f82db8a136be90ea9ec629ed6cd1d45cc7f873159811757d
Press Enter to continue...

After Node_1's messages are sent; I have copied printed receiverPublicKey into receiver_pub variable on the following code. I run following code on Node 2. Node 2 sends a message to the network. Later I press enter on the Node_1 and any of those messages does not show up on theNode_1:

On node-2:

from web3 import Web3, HTTPProvider
web3 = Web3(HTTPProvider('http://localhost:8545'))
from web3.shh import Shh
Shh.attach(web3, "shh")

import time, sys;

from hexbytes import (
    HexBytes,
)

receiver_pub='0x04226d96bf9857ac0ba429c1e8b480a2811ce47cb526dbd3829d7586e5cae740198ba291f3eca0f279f82db8a136be90ea9ec629ed6cd1'; # obtained from node_1 and assigned here.

topic = '0x07678231'
payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")]

web3.shh.post({
        'powTarget': 2.5,
        'powTime': 2,
        'ttl': 60,
        'payload': payloads[0],
        'topic': topic,
        'pubKey': receiver_pub
})
time.sleep(1)

web3.shh.post({
        'powTarget': 2.5,
        'powTime': 2,
        'ttl': 60,
        'payload': payloads[1],
        'topic': topic,
        'pubKey': receiver_pub
})

[Q] How could I send a whisper message from one node to another? What do I do wrong on my approaches?


On the reciever shh.info.memory remains 0 when sender node posts a message.

Please note that, I have opened issue on Web3.py and go-ethereum but no one responded. I have also tried one node is one of those nodes was bootnode and the other one needs to have its enode address in --bootnodes, which also did not work.

20
  • I follow this repo github.com/achiko/whisper-v6-test and it working fine, but we have to gen sym key from the same password shh.generateSymKeyFromPassword("password") When I'm using difference pwd then node-2 cannot receive msg from node-1
    – Tony Dang
    Commented Sep 7, 2018 at 8:37
  • I am using same password as well, but not sure why it is not working on my code. Did you tried on different nodes? Could you also share the code you tried, I can try it as well.
    – alper
    Commented Sep 7, 2018 at 9:12
  • I run on two nodes with difference port on the same host github.com/hadv/whisper-v6-demo
    – Tony Dang
    Commented Sep 7, 2018 at 9:17
  • That's why it works because they are on the same host. On my case, I run on two different node on completely different host, which was not working. I will try your code and see will it work or not.
    – alper
    Commented Sep 7, 2018 at 9:19
  • 1
    your code didnot work even in the same host, but if I change to const web3 = new Web3(new Web3.providers.WebsocketProvider("ws://localhost:8546")); then it worked properly; so I think we must use websocket, not http
    – Tony Dang
    Commented Sep 7, 2018 at 14:12

1 Answer 1

1

There is no node in the network started as bootnode. But I have manually added static nodes using admin.addPeer().

There are three main nodes, their enode is shared publicly where any new coming peers connected to all those three using admin.addPeer("mX_enode"). mX stands for either m1 or m2 or m3. Also all those 3 nodes are connected to each other using admin.addPeer("mX_enode") as well. I have added few nodes which connects to all those 3 nodes, that makes network more stable.

All those three nodes in the network uses following geth line, and newly connected nodes uses same line without --nodiscover flag:

geth --syncmode fast --cache=1024 --shh --datadir $DATADIR/private --rpcaddr 127.0.0.1 --rpc --rpcport 8545 --rpccorsdomain="*" --networkid 12345 --rpcapi eth,net,web3,personal,shh --nodiscover

Please see the image where all nodes are connected to each other.

enter image description here

Later I pick a sender and receiver node, where both admin.peers returns other node's enode so I verify that selected sender and receiver node is connected to each other on the network.

=> Receiver and sender node runs following code on its geth console:

generatedSymKey=shh.generateSymKeyFromPassword("hello");    
symKey=shh.getSymKey(generatedSymKey)    
symKeyID=shh.addSymKey(symKey)
filter = web3.shh.newMessageFilter(
        {symKeyID: symKeyID, topic: '0x07678231'}, 
        function(err, res) {console.log(web3.toUtf8(res.payload))});

I have stored sender and receiver's symKeyID where I will use it to post message. Sender's returned symKeyID is 321f3531fad3de1dd8344da26cba1a074ee3689acb796ecb8e5bdf8507b1a0ef. Receiver's returned symKeyID is ed30b966e40cec9088fb6054c1823d3ff36941aaa002ebd2eea9d5a6efd1a9fe:

=> Than sender node copy paste its symKeyID into following code piece to post its message

web3.shh.post({
  symKeyID: '321f3531fad3de1dd8344da26cba1a074ee3689acb796ecb8e5bdf8507b1a0ef', //symKeyID of the sender
  ttl: 10,
  topic: '0x07678231',
  powTarget: 2.01,
  powTime: 2,
  payload: web3.fromAscii("Hello there!")
  });

=> Receiver also do the same. Receiver copy paste its symKeyID into same code piece to post its message.

web3.shh.post({
  symKeyID: 'ed30b966e40cec9088fb6054c1823d3ff36941aaa002ebd2eea9d5a6efd1a9fe', //symKeyID of the receiver
  ttl: 10,
  topic: '0x07678231',
  powTarget: 2.01,
  powTime: 2,
  payload: web3.fromAscii("Hello there!")
  });

And I can see the sent message on the sender and receiver node's geth console.


I observe that:

In order to user Whisper protocol, where are not required to use any bootnode. Later I have tried running receiver and sender node without --nodiscover and still they were able to send and receive messages between each other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.