Skip to content

TCP connections human doc. #229

Open
@NamsooCho

Description

@NamsooCho

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions