ethereum / wiki

The Ethereum Wiki
https://www.ethereum.org
14.75k stars 2.57k forks source link

Whisper: Posted messages won't filtered on the other nodes #624

Closed avatar-lavventura closed 6 years ago

avatar-lavventura commented 6 years ago

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.

jamesray1 commented 6 years ago

Please see https://github.com/ethereum/wiki/blob/master/ISSUE_TEMPLATE.md. Sorry, I don't have time to handle generic issue requests. Good that you opened the other issues.