Skip to content
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

TCP connections human doc. #229

Open
NamsooCho opened this issue Sep 18, 2018 · 0 comments
Open

TCP connections human doc. #229

NamsooCho opened this issue Sep 18, 2018 · 0 comments

Comments

@NamsooCho
Copy link
Member

NamsooCho commented Sep 18, 2018

TCP connections

TCP connectins resides between net_crypto and tcp_client.
It serves to net_crypto using tcp_client.
It provides reliable connection to net_crypto via multiple tcp relays to a friend.
When a Tox client connects to a friend via tcp relay, normally 3 redundant connections are established.
One connection is used for data send/recv, 2 others are backup.
In toxcore maximum number of redundant connections is 6.
TCP connection can get into sleep mode.
Getting into sleep mode can occur when UDP connecion is established, because Tox prefer UDP than TCP.
When established UDP connection is disabled, TCP connecions are awaken.

Defintion of names.

- Connections has
    -  set of ConnOfClient(HashMap)
    -  set of Connection(HashMap)
- ConnOfClient has
    - handle of TcpClient connection
    - IP, port, PK : to save for sleeping status
- Connection has
    - handles of 3 to 6 ConnToRelay connections for redundancy
- ConnToRelay has
    - id as a key to ConnOfClient hashmap
    - connection_id of Routing Response packet
  • do_tcp_nections : main function of tcp_connections module called by messenger periodically

    • iterate all ConnOfClient in ConnOfClients
      • if ConnOfClient is not SLEEPING
        • call do_tcp_connection in TcpClient module
        • check if TcpClient connection is DISCONNECTED
          • check if ConnOfClient to the friend is CONNECTED
            • reconnect to the relay
          • else
            • kill the relay
        • check if ConnOfClient is not CONFIRMED and TcpClient connection is CONFIRMED
          • send routing request
          • set connection status to CONNECTED
        • check if SLEEP conditions is true
          • get into sleep
      • else if wakeup conditions is true
        • wakeup ConnOfClient
    • loop end
    • delete unused connections
  • end

  • reconnect to relay

    • check if ConnOfClient is SLEEPING then
      • return
    • get IP, port, PK of connection
    • kill ConnOfClient
    • make new ConnOfClient for IP, port, PK
    • init variables and status
  • end

  • get into sleep of ConnOfClient

    • check if ConnOfClient is not CONNECTED
      • return
    • check if lock_count != sleep_count
      • return
    • get Ip, port and PK
    • kill ConnOfClient
    • reset variables and status
  • end

  • wakeup ConnOfClient

    • check if ConnOfClient is not SLEEPING
      • return
    • make new ConnOfClient using saved IP, port, PK
    • init variables and status
  • end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant