Added Draft of proposed Lossless UDP protocol.

This commit is contained in:
irungentoo 2013-06-26 19:47:38 -04:00
parent 488df25e05
commit 24fd7c5a5b
3 changed files with 95 additions and 5 deletions

View File

@ -47,6 +47,6 @@ DHT protocol:
see: [docs/DHT.txt](https://github.com/irungentoo/InsertProjectNameHere/blob/master/docs/DHT.txt)
Lossless UDP protocol:
Either we find one with an already working implementation (Preferred solution)
It should not be very hard to come up with one ourselves though if need be.
see also: [docs/Lossless_UDP.txt](https://github.com/irungentoo/InsertProjectNameHere/blob/master/docs/Lossless_UDP.txt)
Either we find one with an already working implementation (Didn't find a good implementation, writing my own)
see: [docs/Lossless_UDP.txt](https://github.com/irungentoo/InsertProjectNameHere/blob/master/docs/Lossless_UDP.txt)

View File

@ -5,3 +5,92 @@ Lossless UDP:
-Packet loss.
-Packet mixup.
-No flow control.
Draft of Proposed protocol:
Alice wants to connect to Bob (Connection handshake):
Alice generates a random 4 byte number.
Alice puts it in the handshake packet (handshake_id1).
Alice starts sending handshake packets to Bob.
Bob receives the packet.
Bob takes the handshake packet he got from adds a random 4 byte number to it (handshake_id2)
Alice receives the packet, checks if handshake_id1 matches the one she sent.
If it does she starts sending SYNC packets with sent_packetnum = handshake_id2 .
Bob receives the packet,
if (handshake_id2) matches Bob adds Alice to his connections list and starts sending SYNC packets to alice.
Alice receives the SYNC packets and starts sending them too.
Connection is now established.
Alice wants to send packets to Bob:
Alice sends packets to bob.
If bob receives the packets, his next SYNC packets reflect it.
Alice receives the SYNC packets which confirms that bob received them
Alice clears the packets from her buffer.
If bob does not receive any packets, but receives a SYNC packet with a larger sent_packetnum than his recv_packetnum:
bobs SYNC packets become request packets.
The packet id of the missing packet(s) are added to the end of the SYNC packet.
Alice resends the packets whose numbers appear at the end of the request packet.
If bob receives some packets but some are missing
bobs SYNC packets become request packets.
The packet id of the missing packet(s) are added to the end of the SYNC packet.
Alice resends the packets whose numbers appear at the end of the request packet.
The client receives a SYNC packet:
He checks if the packet is valid(sent_packetnum and counter make sense)
If the packet is valid:
If the client was currently trying to establish a connection.
If the handshake was done:
Start sending SYNC packets.
Add +1 to the counter of the SYNC packets we send.
Check to see if any packets were dropped when sending them to us (compare sent_packetnum with the number of packets we recieved.)
If some were, The next SYNC packets we send will be request packets requesting the missing packets.
Check if the other client received what we sent him (compare recv_packetnum with the number of packets we sent) and clear them from the buffer.
If the packet is a request packet.
Send the packets he requested.
The client receives a Connection handshake packet(not initiating connection):
If handshake_id2 is zero:
add our random handshake_id2 to it and send it back
If handshake_id2 is non zero
check if it matches what we sent.
If it does add the client sending it to our connection list.
The client receives a Connection handshake packet(initiating connection):
check if handshake_id1 matches what we sent.
If it does start sending SYNC packets with sent_packetnum as handshake_id2
The client receives a data packet:
Put the packet in the proper place in the receive buffer using packet_num as the reference.
If all the previous packets have been received correctly set recv_packetnum equal to packet_num
Keep track of the percent of packets dropped, if it is too high, lower the send rate. If it is low, increase it.
Alice and bob disconnect suddenly:
Alice stops receiving SYNC packets from bob.
Bob stops receiving SYNC packets from Alice.
Connexion times out if no data is received for 5 seconds.
Protocol:
Connection handshake packets:
[byte with value: 16 (10 in hex)][4 byte (handshake_id1)][4 bytes (handshake_id2)]
SYNC packets:
[byte with value: 17 (11 in hex)][byte (00 for keep alive, 01 for request)][byte (counter)][4 byte (recv_packetnum)][4 byte (sent_packetnum)][sequence of requested packet ids[4 bytes each](not present in keep alive)]
data packets:
[byte with value: 18 (12 in hex)][4 byte (packet_num)][data (arbitrary size)]

View File

@ -23,13 +23,14 @@ Less important.
No UDP hole punching on them so we need to do something else
(only if both the clients which try to connect to themselves are behind one)
-Decentralized IRC like channels.
-Decentralized IRC like channels (chatrooms).
-Offline messaging protocol (text only)
Use your friends.(or maybe the people closest (mathematically by comparing client_id's) to you or the friend you want to send the message to).
The message will not be very big. Let's say we limit the maximum number of bytes for one to 1024, it means if every client stores 1024 offline messages it only takes 1 MB of ram.
The message will not be very big. Lets say we limit the maximum number of bytes for one to 1024, it means if every client stores 1024 offline messages it only takes 1 MB of ram.
-IPv6
Currently the core only supports ipv4