{"action":"created","comment":{"url":"https://api.github.com/repos/Tox-Docs/Text/pulls/comments/42310730","id":42310730,"diff_hunk":"@@ -1,22 +1,22 @@\n-TCP_connections is what takes care of handling multiple TCP client instances to establish a reliable connection via TCP relays to a friend. Only connecting to a friend with one relay would not be very reliable so this level of abstraction is needed to take care of this. For example it makes sure that if a relay goes down then the connection to the peer will not be impacted. This is done by connecting to the other peer with more than one relay.\n+TCP_connections takes care of handling multiple TCP client instances to establish a reliable connection via TCP relays to a friend. Connecting to a friend with only one relay would not be very reliable, so TCP_connections provides the level of abstraction needed to manage multiple relays. For example, it ensures that if a relay goes down, the connection to the peer will not be impacted. This is done by connecting to the other peer with more than one relay.\n \n TCP_connections is above TCP_client and below net_crypto. \n \n-A TCP connection in TCP_connections is defined as a connection to a peer though one or more TCP relays. To connect to another peer with TCP_connections, a connection in TCP_connections to the peer with DHT public key X will be created. Some TCP relays which we know the peer is connected to will then be associated to that peer. Those relays will be the relays the peer has sent to us via the onion module if the peer isn't connected directly yet. The peer will also send some relays he is connected to directly once a connection is established however this is done by another module.\n+A TCP connection in TCP_connections is defined as a connection to a peer though one or more TCP relays. To connect to another peer with TCP_connections, a connection in TCP_connections to the peer with DHT public key X will be created. Some TCP relays which we know the peer is connected to will then be associated to that peer. If the peer isn't connected directly yet, these relays will be the ones that the peer has sent to us via the onion module. The peer will also send some relays he is connected to directly once a connection is established however this is done by another module.\n \n-TCP_connections has a list of all relays it is connected to. It tries to keep the number of relays it is connected to as small as possible. This is done in order to minimize load on relays and lower bandwidth usage for the client. The desired number of TCP relay connections per peer is set to 3 in toxcore with the maximum number set to 6. The reason for these numbers is that 1 would mean no backup relays and 2 would mean only 1. To be sure that the connection is reliable 3 seems to be the good number. The maximum number of 6 is the maximum number of relays that can be tied to each peer. if 2 peers are connected each to the same 6+ relays and they both need to be connected to that amount of relays because of other friends this is where this maximum comes into play.\n+TCP_connections has a list of all relays it is connected to. It tries to keep the number of relays it is connected to as small as possible in order to minimize load on relays and lower bandwidth usage for the client. The desired number of TCP relay connections per peer is set to 3 in toxcore with the maximum number set to 6. The reason for these numbers is that 1 would mean no backup relays and 2 would mean only 1. To be sure that the connection is reliable 3 seems to be the good number. The maximum number of 6 is the maximum number of relays that can be tied to each peer. If 2 peers are connected each to the same 6+ relays and they both need to be connected to that amount of relays because of other friends this is where this maximum comes into play.\n \n-If necessary, TCP_connections will connect to some TCP relays in order to use them to send onion packets. This is only done when there is no UDP connection to the network. When there is a UDP connection, packets are sent with UDP only because sending them with TCP relays can be less reliable. It is also important that we are connected at all times to some relays as these relays will be used by TCP only peers to initiate a connection to us.\n+If necessary, TCP_connections will connect to TCP relays to use them to send onion packets. This is only done if there is no UDP connection to the network. When there is a UDP connection, packets are sent with UDP only because sending them with TCP relays can be less reliable. It is also important that we are connected at all times to some relays as these relays will be used by TCP only peers to initiate a connection to us.\n \n-In toxcore each client is connected to 3 relays even if there are no TCP peers and the onion is not needed. It may be better to only connect to those relays when toxcore is initializing as this is the only time when peers will connect to us via TCP relays we are connected to. Due to how the onion works, after the initialization phase where each peer is searched in the onion and then if they are found the info required to connect back (DHT pk, TCP relays) is sent to them, there should be no more peers connecting to us via TCP relays. This may be a way to further reduce load on TCP relays however more research is needed.\n+In toxcore, each client is connected to 3 relays even if there are no TCP peers and the onion is not needed. It might be optimal to only connect to these relays when toxcore is initializing as this is the only time when peers will connect to us via TCP relays we are connected to. Due to how the onion works, after the initialization phase, where each peer is searched in the onion and then if they are found the info required to connect back (DHT pk, TCP relays) is sent to them, there should be no more peers connecting to us via TCP relays. This may be a way to further reduce load on TCP relays, however, more research is needed before it is implemented.\n \n-TCP_connections picks one relay and uses it and only it to send data to the other peer. The reason for not picking a random connected relay for each packet is that it severely deteriorates the quality of the link between two peers and makes performance of lossy video and audio transmissions really bad. For this reason one peer is picked and used to send all data. If for any reason no more data can be sent to that relay, the next relay is used. Reasons for that include the TCP socket being full which means that the relay should not be dropped if this occurs. Relays are only dropped if they time out, if they become useless (if the relay is one too many or is no longer used to relay data to any peers).\n+TCP_connections picks one relay and uses it, and only it, to send data to the other peer. The reason for not picking a random connected relay for each packet is that it severely deteriorates the quality of the link between two peers and makes performance of lossy video and audio transmissions really poor. For this reason, one peer is picked and used to send all data. If for any reason no more data can be sent through that relay, the next relay is used. This may happen if the TCP socket is full and so the relay should not necessarily be dropped if this occurs. Relays are only dropped if they time out or if they become useless (if the relay is one too many or is no longer being used to relay data to any peers).","path":"src_text/TCP_connections.txt","position":19,"original_position":19,"commit_id":"3d9b87ef985b0c4fcdc39030f00b2483e2149f69","original_commit_id":"3d9b87ef985b0c4fcdc39030f00b2483e2149f69","user":{"login":"zetok","id":3148759,"avatar_url":"https://avatars.githubusercontent.com/u/3148759?v=3","gravatar_id":"","url":"https://api.github.com/users/zetok","html_url":"https://github.com/zetok","followers_url":"https://api.github.com/users/zetok/followers","following_url":"https://api.github.com/users/zetok/following{/other_user}","gists_url":"https://api.github.com/users/zetok/gists{/gist_id}","starred_url":"https://api.github.com/users/zetok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zetok/subscriptions","organizations_url":"https://api.github.com/users/zetok/orgs","repos_url":"https://api.github.com/users/zetok/repos","events_url":"https://api.github.com/users/zetok/events{/privacy}","received_events_url":"https://api.github.com/users/zetok/received_events","type":"User","site_admin":false},"body":">TCP_connections picks one relay and uses it, and only it, to send data (…)\r\n\r\nperhaps change to ``TCP_connections picks one relay and uses only it to send data (…)`` ?\r\n\r\n>This may happen if the TCP socket is full and so the relay should not necessarily (…)\r\n\r\nperhaps change to ``This may happen if the TCP socket is full and thus the relay should not necessarily`` ?","created_at":"2015-10-17T15:59:32Z","updated_at":"2015-10-17T15:59:32Z","html_url":"https://github.com/Tox-Docs/Text/pull/69#discussion_r42310730","pull_request_url":"https://api.github.com/repos/Tox-Docs/Text/pulls/69","_links":{"self":{"href":"https://api.github.com/repos/Tox-Docs/Text/pulls/comments/42310730"},"html":{"href":"https://github.com/Tox-Docs/Text/pull/69#discussion_r42310730"},"pull_request":{"href":"https://api.github.com/repos/Tox-Docs/Text/pulls/69"}}},"pull_request":{"url":"https://api.github.com/repos/Tox-Docs/Text/pulls/69","id":47987362,"html_url":"https://github.com/Tox-Docs/Text/pull/69","diff_url":"https://github.com/Tox-Docs/Text/pull/69.diff","patch_url":"https://github.com/Tox-Docs/Text/pull/69.patch","issue_url":"https://api.github.com/repos/Tox-Docs/Text/issues/69","number":69,"state":"open","locked":false,"title":"Minor grammar/style improvement in TCP_connections.txt","user":{"login":"Jumbt","id":13854927,"avatar_url":"https://avatars.githubusercontent.com/u/13854927?v=3","gravatar_id":"","url":"https://api.github.com/users/Jumbt","html_url":"https://github.com/Jumbt","followers_url":"https://api.github.com/users/Jumbt/followers","following_url":"https://api.github.com/users/Jumbt/following{/other_user}","gists_url":"https://api.github.com/users/Jumbt/gists{/gist_id}","starred_url":"https://api.github.com/users/Jumbt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jumbt/subscriptions","organizations_url":"https://api.github.com/users/Jumbt/orgs","repos_url":"https://api.github.com/users/Jumbt/repos","events_url":"https://api.github.com/users/Jumbt/events{/privacy}","received_events_url":"https://api.github.com/users/Jumbt/received_events","type":"User","site_admin":false},"body":"A few changes to make tcp_connections read clearer. ","created_at":"2015-10-17T14:24:46Z","updated_at":"2015-10-17T15:59:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"496ab58a4b64ed689d34680567428c96c27cca08","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Tox-Docs/Text/pulls/69/commits","review_comments_url":"https://api.github.com/repos/Tox-Docs/Text/pulls/69/comments","review_comment_url":"https://api.github.com/repos/Tox-Docs/Text/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Tox-Docs/Text/issues/69/comments","statuses_url":"https://api.github.com/repos/Tox-Docs/Text/statuses/3d9b87ef985b0c4fcdc39030f00b2483e2149f69","head":{"label":"Jumbt:master","ref":"master","sha":"3d9b87ef985b0c4fcdc39030f00b2483e2149f69","user":{"login":"Jumbt","id":13854927,"avatar_url":"https://avatars.githubusercontent.com/u/13854927?v=3","gravatar_id":"","url":"https://api.github.com/users/Jumbt","html_url":"https://github.com/Jumbt","followers_url":"https://api.github.com/users/Jumbt/followers","following_url":"https://api.github.com/users/Jumbt/following{/other_user}","gists_url":"https://api.github.com/users/Jumbt/gists{/gist_id}","starred_url":"https://api.github.com/users/Jumbt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jumbt/subscriptions","organizations_url":"https://api.github.com/users/Jumbt/orgs","repos_url":"https://api.github.com/users/Jumbt/repos","events_url":"https://api.github.com/users/Jumbt/events{/privacy}","received_events_url":"https://api.github.com/users/Jumbt/received_events","type":"User","site_admin":false},"repo":{"id":42788158,"name":"Text","full_name":"Jumbt/Text","owner":{"login":"Jumbt","id":13854927,"avatar_url":"https://avatars.githubusercontent.com/u/13854927?v=3","gravatar_id":"","url":"https://api.github.com/users/Jumbt","html_url":"https://github.com/Jumbt","followers_url":"https://api.github.com/users/Jumbt/followers","following_url":"https://api.github.com/users/Jumbt/following{/other_user}","gists_url":"https://api.github.com/users/Jumbt/gists{/gist_id}","starred_url":"https://api.github.com/users/Jumbt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jumbt/subscriptions","organizations_url":"https://api.github.com/users/Jumbt/orgs","repos_url":"https://api.github.com/users/Jumbt/repos","events_url":"https://api.github.com/users/Jumbt/events{/privacy}","received_events_url":"https://api.github.com/users/Jumbt/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Jumbt/Text","description":"","fork":true,"url":"https://api.github.com/repos/Jumbt/Text","forks_url":"https://api.github.com/repos/Jumbt/Text/forks","keys_url":"https://api.github.com/repos/Jumbt/Text/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Jumbt/Text/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Jumbt/Text/teams","hooks_url":"https://api.github.com/repos/Jumbt/Text/hooks","issue_events_url":"https://api.github.com/repos/Jumbt/Text/issues/events{/number}","events_url":"https://api.github.com/repos/Jumbt/Text/events","assignees_url":"https://api.github.com/repos/Jumbt/Text/assignees{/user}","branches_url":"https://api.github.com/repos/Jumbt/Text/branches{/branch}","tags_url":"https://api.github.com/repos/Jumbt/Text/tags","blobs_url":"https://api.github.com/repos/Jumbt/Text/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Jumbt/Text/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Jumbt/Text/git/refs{/sha}","trees_url":"https://api.github.com/repos/Jumbt/Text/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Jumbt/Text/statuses/{sha}","languages_url":"https://api.github.com/repos/Jumbt/Text/languages","stargazers_url":"https://api.github.com/repos/Jumbt/Text/stargazers","contributors_url":"https://api.github.com/repos/Jumbt/Text/contributors","subscribers_url":"https://api.github.com/repos/Jumbt/Text/subscribers","subscription_url":"https://api.github.com/repos/Jumbt/Text/subscription","commits_url":"https://api.github.com/repos/Jumbt/Text/commits{/sha}","git_commits_url":"https://api.github.com/repos/Jumbt/Text/git/commits{/sha}","comments_url":"https://api.github.com/repos/Jumbt/Text/comments{/number}","issue_comment_url":"https://api.github.com/repos/Jumbt/Text/issues/comments{/number}","contents_url":"https://api.github.com/repos/Jumbt/Text/contents/{+path}","compare_url":"https://api.github.com/repos/Jumbt/Text/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Jumbt/Text/merges","archive_url":"https://api.github.com/repos/Jumbt/Text/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Jumbt/Text/downloads","issues_url":"https://api.github.com/repos/Jumbt/Text/issues{/number}","pulls_url":"https://api.github.com/repos/Jumbt/Text/pulls{/number}","milestones_url":"https://api.github.com/repos/Jumbt/Text/milestones{/number}","notifications_url":"https://api.github.com/repos/Jumbt/Text/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Jumbt/Text/labels{/name}","releases_url":"https://api.github.com/repos/Jumbt/Text/releases{/id}","created_at":"2015-09-19T20:16:27Z","updated_at":"2015-09-19T20:16:28Z","pushed_at":"2015-10-17T14:17:26Z","git_url":"git://github.com/Jumbt/Text.git","ssh_url":"git@github.com:Jumbt/Text.git","clone_url":"https://github.com/Jumbt/Text.git","svn_url":"https://github.com/Jumbt/Text","homepage":null,"size":197,"stargazers_count":0,"watchers_count":0,"language":"TeX","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Tox-Docs:master","ref":"master","sha":"6d2f9863695d2bb0df53a11af9d1c8856c855152","user":{"login":"Tox-Docs","id":14188845,"avatar_url":"https://avatars.githubusercontent.com/u/14188845?v=3","gravatar_id":"","url":"https://api.github.com/users/Tox-Docs","html_url":"https://github.com/Tox-Docs","followers_url":"https://api.github.com/users/Tox-Docs/followers","following_url":"https://api.github.com/users/Tox-Docs/following{/other_user}","gists_url":"https://api.github.com/users/Tox-Docs/gists{/gist_id}","starred_url":"https://api.github.com/users/Tox-Docs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tox-Docs/subscriptions","organizations_url":"https://api.github.com/users/Tox-Docs/orgs","repos_url":"https://api.github.com/users/Tox-Docs/repos","events_url":"https://api.github.com/users/Tox-Docs/events{/privacy}","received_events_url":"https://api.github.com/users/Tox-Docs/received_events","type":"Organization","site_admin":false},"repo":{"id":42143213,"name":"Text","full_name":"Tox-Docs/Text","owner":{"login":"Tox-Docs","id":14188845,"avatar_url":"https://avatars.githubusercontent.com/u/14188845?v=3","gravatar_id":"","url":"https://api.github.com/users/Tox-Docs","html_url":"https://github.com/Tox-Docs","followers_url":"https://api.github.com/users/Tox-Docs/followers","following_url":"https://api.github.com/users/Tox-Docs/following{/other_user}","gists_url":"https://api.github.com/users/Tox-Docs/gists{/gist_id}","starred_url":"https://api.github.com/users/Tox-Docs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tox-Docs/subscriptions","organizations_url":"https://api.github.com/users/Tox-Docs/orgs","repos_url":"https://api.github.com/users/Tox-Docs/repos","events_url":"https://api.github.com/users/Tox-Docs/events{/privacy}","received_events_url":"https://api.github.com/users/Tox-Docs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Tox-Docs/Text","description":"","fork":false,"url":"https://api.github.com/repos/Tox-Docs/Text","forks_url":"https://api.github.com/repos/Tox-Docs/Text/forks","keys_url":"https://api.github.com/repos/Tox-Docs/Text/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tox-Docs/Text/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tox-Docs/Text/teams","hooks_url":"https://api.github.com/repos/Tox-Docs/Text/hooks","issue_events_url":"https://api.github.com/repos/Tox-Docs/Text/issues/events{/number}","events_url":"https://api.github.com/repos/Tox-Docs/Text/events","assignees_url":"https://api.github.com/repos/Tox-Docs/Text/assignees{/user}","branches_url":"https://api.github.com/repos/Tox-Docs/Text/branches{/branch}","tags_url":"https://api.github.com/repos/Tox-Docs/Text/tags","blobs_url":"https://api.github.com/repos/Tox-Docs/Text/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tox-Docs/Text/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tox-Docs/Text/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tox-Docs/Text/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tox-Docs/Text/statuses/{sha}","languages_url":"https://api.github.com/repos/Tox-Docs/Text/languages","stargazers_url":"https://api.github.com/repos/Tox-Docs/Text/stargazers","contributors_url":"https://api.github.com/repos/Tox-Docs/Text/contributors","subscribers_url":"https://api.github.com/repos/Tox-Docs/Text/subscribers","subscription_url":"https://api.github.com/repos/Tox-Docs/Text/subscription","commits_url":"https://api.github.com/repos/Tox-Docs/Text/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tox-Docs/Text/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tox-Docs/Text/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tox-Docs/Text/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tox-Docs/Text/contents/{+path}","compare_url":"https://api.github.com/repos/Tox-Docs/Text/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tox-Docs/Text/merges","archive_url":"https://api.github.com/repos/Tox-Docs/Text/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tox-Docs/Text/downloads","issues_url":"https://api.github.com/repos/Tox-Docs/Text/issues{/number}","pulls_url":"https://api.github.com/repos/Tox-Docs/Text/pulls{/number}","milestones_url":"https://api.github.com/repos/Tox-Docs/Text/milestones{/number}","notifications_url":"https://api.github.com/repos/Tox-Docs/Text/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tox-Docs/Text/labels{/name}","releases_url":"https://api.github.com/repos/Tox-Docs/Text/releases{/id}","created_at":"2015-09-08T22:51:19Z","updated_at":"2015-10-17T01:09:03Z","pushed_at":"2015-10-17T14:24:47Z","git_url":"git://github.com/Tox-Docs/Text.git","ssh_url":"git@github.com:Tox-Docs/Text.git","clone_url":"https://github.com/Tox-Docs/Text.git","svn_url":"https://github.com/Tox-Docs/Text","homepage":null,"size":229,"stargazers_count":24,"watchers_count":24,"language":"TeX","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":46,"forks":7,"open_issues":46,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Tox-Docs/Text/pulls/69"},"html":{"href":"https://github.com/Tox-Docs/Text/pull/69"},"issue":{"href":"https://api.github.com/repos/Tox-Docs/Text/issues/69"},"comments":{"href":"https://api.github.com/repos/Tox-Docs/Text/issues/69/comments"},"review_comments":{"href":"https://api.github.com/repos/Tox-Docs/Text/pulls/69/comments"},"review_comment":{"href":"https://api.github.com/repos/Tox-Docs/Text/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Tox-Docs/Text/pulls/69/commits"},"statuses":{"href":"https://api.github.com/repos/Tox-Docs/Text/statuses/3d9b87ef985b0c4fcdc39030f00b2483e2149f69"}}}}