#StackBounty: #go-ethereum #whisper #message Whisper: How to send a message from one node to another?

Bounty: 100

  • 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:

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],
        '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?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.