HelloZeroNet / Plugin-PeerMessage

26 stars 12 forks source link

Receiving Hub Messages #9

Closed d14na closed 4 years ago

d14na commented 4 years ago

Pleased to have PeerMessage(s) sending and receiving. But now I'm trying to setup via a Hub (to limit the broadcast/spam), but can't seem to follow the Receiving guide.

I am able to SEND messages cmd('as', [HUB_ADDRESS, 'peerBroadcast', pkg]).

But specifically, how to listen if (cmd == "peerReceive") { and RECEIVE messages from a Hub?

Also, there appears to be a contradiction in the docs:

So, the simpliest solution is: just create empty p2p.json in merger site's root, like this:

{}

however, earlier its said:

So, we also need p2p.json in hub's directory.

how can one be FORMATTED and the other NOT? Are they stored in 2 separate locations within the Hub? Or, are the "merger site" and "Hub" 2 separate zites? btw: I'm not at all familiar with the workings of merger sites.

Thanks!

purplesyringa commented 4 years ago

"Merger site" is the main site, like ZeroMe or Git Center. "Merged site" or "hub" is something like ZeroMe hub or Git Center repository. So, you need an empty p2p.json for the main site (to tell PeerMessage to listen to messages) and a correct p2p.json in hubs.

As for receiving messages: if your main site has a file called p2p.json in site root, it will receive all messages from its hubs by issuing peerReceive command. See, peerReceive is handled almost the same way as setSiteInfo. So, in case you're using simple ZeroFrame, you can just update route function to check for if(cmd == "peerReceive").

purplesyringa commented 4 years ago

Please close this issue if I answered your question.

d14na commented 4 years ago

So, you need an empty p2p.json for the main site (to tell PeerMessage to listen to messages) and a correct p2p.json in hubs.

got it! wasn't clear on the terms

So, in case you're using simple ZeroFrame, you can just update route function to check for if(cmd == "peerReceive")

i had that working WITHOUT a hub, with the p2p.json change, it should all work now.

thanks!