-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Peer-to-peer applications #1425
Comments
I'll probably make it a plugin. |
Your idea is solid but i think we should consider to be able to tie it to an ID if needed SuggestionTo add optional native implementation to sign verify, encrypt, decrypt messages from/to an id Possible UsageSay i want to play tictactoe against another online user say bob@id.bit on a site, it's also possible for something like IRC-hybrid that only save the messages to disk once every 1min(or site close) to preserve history, but broadcast all messages P2P, since it's better to collect all writes and flush it all at once Possible concernsConcerns of privacy where one IP or tor address can be tied to one id, this can be dismissed, IF the site is big enough, more than likely that ip is just forwarding/propagating a message they receive Minor Passive Protection SuggestionAdding more passive protections, i dont think a regex is enough, we should have:
if i am sure my application will never send out more then 1 packet per second i can put it there to limit and stop people spamming,
other peers will drop and flag/add points, if the message is over x byte(wrapper should reject sending if over this limit), this limit should be very high and is just there to to prevent users sending absurdly large packets and choking peers with less bandwidth
This flag force all messages sent to be signed with the valid signatures described(probably will be identical to the one in the |
As for passive protection, we should probably make it Etherium-like, i.e. allow crypto-functions, conditionals, etc. |
Renamed |
Done. |
Added size limit. Will update docs soon. |
Implemented signature. (not encryption or "disable no-signature") |
do you think encryption via preshare keys are a good idea? possible use caseI am playing a tic tac toe with bob@id, but i want to allow a few specific users to spectate, It also works for a non bidirectional use case, say an invite only chat, where if the member grows everyone now have to do send one more encrypted message(so everyone can get it) unless everyone used a preshare key Yes i used tictactoe in this example, but you can assume the same for more confidential things sidenote, might be useful for partial encrypted leaving some metadata out, so everyone dont have to try to decrypt everything sent in their way {
"gameid":"(immutable hash of something)",
"encrypted:"(encrypted json object)"
} |
Added |
It definitely is. |
@Thunder33345 It's still a question how encrypted messages should be decrypted when they are received - by P2P-messages plugin or by JavaScript? |
is an option in the root contents.json good idea? parthial encrypted will be deal by js i assume since there's no way over it |
Maybe just use aesEncrypt/aesDecrypt instead? |
Problem: If the port is closed, no one can send you a message. |
hm so you need an open port to work? |
@krixano and I just checked it with only @krixano having port open, and it works. So if a peer has a closed port, but is connected to someone, this will work. |
Also we have problem of how to know if someone has a plugin |
In fact, this is not a bug but a feature request. So I probably won't follow the recommended issue format.
Idea
ZeroNet completely depends on sites. The only thing possible to be built on ZeroNet is a site.
However, I see a way to support much more. With the idea I promote we will be able to bring a blockchain here. The idea itself is rather simple: let's give the developer the control over P2P messages. For example, you could spread information to all peers, without files!
Implementation
Now to the implementation. There will be a new ZeroFrame command called
peerBroadcast(message, peer_count=5, broadcast=True, immediate=False, timeout=60)
. This will:some_hash(str(rand()) + "," + json.dumps(message))
.peer_count
random peers having current site.peerBroadcast(message=message, hash=hash_from_p1, peer_count=peer_count, broadcast=broadcast, immediate=immediate)
action on those peers.P2P
When a peer receives
peerBroadcast
from another peer, it first verifies that current message wasn't yet received in current session (i.e. check it by hash in some dict or list). It's unlikely that the IDs will be duplicated (they may be, but it should be handled by the zite correctly). And it's unlikely that the message will be received twice after shutdown (i.e. get mesasge, shutdown, start again, connect to other peers, get message again). So we don't need to store the list in file system.If the current message hasn't been received yet, it is sent to all current site's WebSockets via
peerReceive(ip=from_ip, hash=message_hash, message=message)
message.from_ip
is IPv4, IPv6, or some other ID in case of Tor or I2P. So the site gets messages. The site may respond with anotherpeerBroadcast
message if it wants to.immediate
If no WebSocket connection exists, e.g. the browser is closed, and
immediate
flag is set, the message is saved to the queue in memory. When the site is opened, the WebSocket connection is opened as well, and the queue is flushed to the socket. I say "in memory" because in fact if you shut down ZeroNet, other messages may be broadcasted, so you'll have to fetch them (e.g. by anotherpeerBroadcast
command).broadcast
Finally, if the message hasn't been received yet (this prevents infinite loop), the message is broadcasted to some random
peer_count
peers. All the arguments are same as received.Results
If
broadcast
is set toFalse
, the count of peers will be rather small (peer_count
or less if just a few peers are available). So we may get results from other peers (let's call them neighbours).In this case, neighbours send the message to WebSockets, get the answer (via some another ZeroFrame command, e.g.
peerReply
), and return it to previous peer. The previous peer sets some timeout, i.e. in case that WebSocket isn't open or the remote side hangs. Finally, the gathered results are send in form of[{ip: ip1, reply: reply1}, ...]
.reply
is the exact reply from neighbour's WebSocket, andip
is either IPv4 or IPv6 or some other ID, e.g. in case of Tor/I2P.Reply
Another ZeroFrame command called
peerSend(ip, message)
will send a message to peer specified by IPip
. The remote side may then reply, which results in return fromactionPeerSend(self, to, ip, message)
, so the zite gets the reply.Cross-site broadcast
It makes sense to ask user for permission to use CORS (because some site may store private data) and Merger (because it allows writing). However, just sending a message is secure enough. It makes no sense to do something serious when just a message is received. So
as(..., "peer...", ...)
should always be allowed for all sites, which will send a message to another site.Spam spam spam spam
Sending messages to other peers may be unsafe. For example, peer A may send lots of messages to other peers. This leads to spamming their network traffic and wasting CPU power. So I'd like to add two levels of protection: passive and active.
Passive protection
A new entry called
message_filter
will be added tocontent.json
. When a message is received from peer A, it is checked againstmessage_filter
regex incontent.json
. If the message doesn't match (i.e. it's invalid), it shouldn't be sent to WebSocket, to other peers. In this case peer A gets 5 ban points. So spamming won't be possible (no more than 20 invalid messages).Active protection
The only kind of correct but spam messages is messages which are correct, but contain invalid data the remote side cannot handle. In case of Bitcoin this is invalid block hash. It's impossible to run any code in Python safely, so here comes active protection in browser. When a message is received from WebSocket, the zite may send
peerInvalid(hash)
, which will add 10 ban points to the peer from which that message was received. This is more than passive protection because it's more likely to ban.However, there is no way to reply to a broadcast message, so there is no way to check whether a message is correct without something like
sleep; if didn't receive peerInvalid, then this message is valid
. So instead we addpeerValid(hash)
command, which marks a message as valid, and will make broadcast a bit faster; however, if it isn't sent, it will be timeouted in say 5s, so messages will be transfered just a bit slower.Usage examples
IRC
More examples are welcome.
Looking forward to hear from you, @HelloZeroNet.
The text was updated successfully, but these errors were encountered: