Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whisper: test_shh_filter does not work to send messages to another node. #1031

Closed
avatar-lavventura opened this issue Aug 29, 2018 · 8 comments

Comments

@avatar-lavventura
Copy link

avatar-lavventura commented Aug 29, 2018

  • geth version: 1.8.15-unstable
  • Python: 3.5
  • OS: osx/linux
  • Web3.py version: 4.4.1

What was wrong?

I have followed following ssh-mode code, which lets each node to send message to itself but different nodes are not able to catch/filter the already sent messages from other nodes.

Overall, I am able to send/receive from the same node, but not from two different ones.

On this approach I observe that each node can only sends 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.

How can it be fixed? Please see the example case:

Node_1 runs shh_filter.get_new_entries() to catch messages but len(received_messages) returns 0, where there is no message is received.

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 = '0x13370000'

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:

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 = '0x13370000'
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 able to make node-2 to filter node-1's messages? Is it possible?

Also asked at ethereum.stackexchange but I couldn't reach anyone.

@avatar-lavventura
Copy link
Author

avatar-lavventura commented Sep 22, 2018

I also verify that both nodes are connected to the network. net.peerCount returns 3 on both nodes.

@wolovim
Copy link
Member

wolovim commented Nov 12, 2020

Stale issue, but Whisper was officially dropped from Geth and Parity/OE, so support has been removed from Web3.py in #1791.

@wolovim wolovim closed this as completed Nov 12, 2020
@avatar-lavventura
Copy link
Author

@marcgarreau In the latest web3.py versions still can I use it since I was able to use it on its previous versions?

Do you know the reason why is it dorpped from Geth and Parity? and is there any alternative for it?

@wolovim
Copy link
Member

wolovim commented Nov 18, 2020

@avatar-lavventura my limited understanding is that Whisper is discontinued or abandoned; I don't know the reasons why. You should look into the Status team's effort, Waku.

@avatar-lavventura
Copy link
Author

@marcgarreau Whisper is abandoned over a year, but it was working fine for basic stuff to send messages based on a topic. The issues I open never responded. The main goal in peer-to-peer messaging should considered Does go-ethereum/whisper provides any kind of Public Key Server to obtain other nodes' public key, which is not inclueded in Waku.

Ah also Waku seems like only focus on the mobil-app solution, so it would be difficult to integrate it with Python :-(

@wolovim
Copy link
Member

wolovim commented Dec 2, 2020

Ah, sorry to hear that Waku isn't an option for you. I don't believe its reasonable for this team to commit to maintaining an interface to a discontinued Whisper, but we are working to make it easier to introduce custom methods in web3.py. I think this interface is still evolving, but @kclowes is there anything we can share about it yet?

@kclowes
Copy link
Collaborator

kclowes commented Dec 2, 2020

@avatar-lavventura this is the WIP PR for the documentation, but use with caution as it's not public quite yet and is subject to breaking changes. But you should be able to use that in a pinch

@avatar-lavventura
Copy link
Author

avatar-lavventura commented Dec 3, 2020

@kclowes Thanks, I manage to make Whisper work, basic example: ( https://ethereum.stackexchange.com/a/58299/4575 ), by many trial-error and using @pipermerriam 's example-file (but the link is gone right now)

I am just get lost, where not sure whisper (w3.geth.shh) be available on the upcoming new versions of web3.py or will there be alternative to Whisper.

If it will be available , I will keep up my work related to whisper on my project; if not I need to find out different solution for peer-to-peer messaging.

Anyway Whisper is/was nice but sender's public key is not included along with the message so I had to send it along with the original message for receiver to respond back; and also the Ethereum address of the sender (which would be actually the real benefit of using it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants