Skip to content

Commit

Permalink
#71
Browse files Browse the repository at this point in the history
  • Loading branch information
irungentoo committed Oct 20, 2015
1 parent b51a79d commit f0f6842
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src_text/friend_connection.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
friend_connection is the module that sits on top of the DHT, onion and net_crypto modules and takes care of linking the 3 together.

Friends in friend_connection are represented by their real public key. When a friend is added in friend_connection, an onion friend is created for that friend. This means that the onion module will start looking for this friend and send that friend their DHT public key, and the TCP relays it is connected to, in case a connection is only possible with TCP.
Friends in friend_connection are represented by their real public key. When a friend is added in friend_connection, an onion search entry is created for that friend. This means that the onion module will start looking for this friend and send that friend their DHT public key, and the TCP relays it is connected to, in case a connection is only possible with TCP.

Once the onion returns the DHT public key of the peer, the DHT public key is saved, added to the DHT friends list and a new net_crypto connection is created. Any TCP relays returned by the onion for this friend are passed to the net_crypto connection.

Expand All @@ -10,9 +10,9 @@ If net_crypto finds that the friend has a different DHT public key, which can ha

When the net_crypto connection for a friend goes online, friend_connection will tell the onion module that the friend is online so that it can stop spending resources looking for the friend. When the friend connection goes offline, friend_connection will tell the onion module so that it can start looking for the friend again.

There are 2 types of data packets sent to friends with the net_crypto connection handled at the level of friend_connection. Alive packets are packets with the packet id or first byte of data (only byte in this packet) being 16. They are used in order to check if the other friend is still online. net_crypto does not have any timeout when the connection is established so timeouts are caught using this packet. In toxcore, this packet is sent every 8 seconds. If none of these packets are received for 32 seconds, the connection is timed out and killed. These numbers seem to cause the least issues and 32 seconds is not too long so that, if a friend times out, toxcore won't falsely see them online for too long. Usually when a friend goes offline they have time to send a disconnect packet in the net_crypto connection which makes them appear offline almost instantly.
There are 2 types of data packets sent to friends with the net_crypto connection handled at the level of friend_connection, Alive packets and TCP relay packets. Alive packets are packets with the packet id or first byte of data (only byte in this packet) being 16. They are used in order to check if the other friend is still online. net_crypto does not have any timeout when the connection is established so timeouts are caught using this packet. In toxcore, this packet is sent every 8 seconds. If none of these packets are received for 32 seconds, the connection is timed out and killed. These numbers seem to cause the least issues and 32 seconds is not too long so that, if a friend times out, toxcore won't falsely see them online for too long. Usually when a friend goes offline they have time to send a disconnect packet in the net_crypto connection which makes them appear offline almost instantly.

The timeout for when to stop retrying to connect to a friend by creating new net_crypto connections when the old one times out in toxcore is the same as the timeout for DHT peers. However, it is calculated from the last time a DHT public key was received for the friend or time the friend's net_crypto connection went offline after being online. The highest time is used to calculate when the timeout is. net_crypto connections will be recreated (if the connection fails) until this timeout.
The timeout for when to stop retrying to connect to a friend by creating new net_crypto connections when the old one times out in toxcore is the same as the timeout for DHT peers (122 seconds). However, it is calculated from the last time a DHT public key was received for the friend or time the friend's net_crypto connection went offline after being online. The highest time is used to calculate when the timeout is. net_crypto connections will be recreated (if the connection fails) until this timeout.

friend_connection sends a list of 3 relays (the same number as the target number of TCP relay connections in TCP_connections) to each connected friend every 5 minutes in toxcore. Immediately before sending the relays, they are associated to the current net_crypto->TCP_connections connection. This facilitates connecting the two friends together using the relays as the friend who receives the packet will associate the sent relays to the net_crypto connection they received it from. When both sides do this they will be able to connect to each other using the relays. The packet id or first byte of the packet of share relay packets is 17. This is then followed by some TCP relays stored in packed node format.

Expand Down

0 comments on commit f0f6842

Please sign in to comment.