Expand description
Top-level TCP Packets according to Tox spec
Modules§
- connection_
id - Connection ID definition.
Structs§
- Connect
Notification - Sent by server to client.
Tell the client that connection_id is now connected meaning the other
is online and data can be sent using this
connection_id
. - Data
- Sent by client to server.
The client sends data with
connection_id
and the server relays it to the given connection - Disconnect
Notification - Sent by client to server.
Sent when client wants the server to forget about the connection related
to the connection_id in the notification. Server must remove this connection
and must be able to reuse the
connection_id
for another connection. If the connection was connected the server must send a disconnect notification to the other client. The other client must think that this client has simply disconnected from the TCP server. - Encrypted
Packet - Packets are encrypted and sent in this form.
- Onion
Request - Sent by client to server.
The server will pack payload from this request to
OnionRequest1
packet and send it to UDP socket. The server can accept both TCP and UDP families as destination IP address but regardless of this it will always sendOnionRequest1
to UDP socket. Return address fromOnionRequest1
will contain TCP address so that when we getOnionResponse2
we will know that this response should be sent to TCP client connected to our server. - Onion
Response - Sent by server to client.
The server just sends payload from
OnionResponse1
packet that it got from a UDP node to the client. - OobReceive
- Sent by server to client. OOB recv are sent with the announced public key of the peer that sent the OOB send packet and the exact data.
- OobSend
- Sent by client to server.
If a peer with private key equal to the key they announced themselves with is
connected, the data in the OOB send packet will be sent to that peer as an
OOB recv packet. If no such peer is connected, the packet is discarded. The
toxcore
TCP_server
implementation has a hard maximum OOB data length of 1024. 1024 was picked because it is big enough for thenet_crypto
packets related to the handshake and is large enough that any changes to the protocol would not require breakingTCP server
. It is however not large enough for the biggesnet_crypto
packets sent with an establishednet_crypto
connection to prevent sending those via OOB packets. - Ping
Request - Sent by both client and server, both will respond.
Ping packets are used to know if the other side of the connection is still
live. TCP when established doesn’t have any sane timeouts (1 week isn’t sane)
so we are obliged to have our own way to check if the other side is still live.
Ping ids can be anything except 0, this is because of how toxcore sets the
variable storing the
ping_id
that was sent to 0 when it receives a pong response which means 0 is invalid. - Pong
Response - Sent by both client and server, both will respond.
The server should respond to ping packets with pong packets with the same
ping_id
as was in the ping packet. The server should check that each pong packet contains the sameping_id
as was in the ping, if not the pong packet must be ignored. - Route
Request - Sent by client to server.
Send a routing request to the server that we want to connect
to peer with public key where the public key is the public the peer
announced themselves as. The server must respond to this with a
RouteResponse
. - Route
Response - Sent by server to client.
The response to the routing request, tell the client if the
routing request succeeded (valid
connection_id
) and if it did, tell them the id of the connection (connection_id
). The public key sent in the routing request is also sent in the response so that the client can send many requests at the same time to the server without having code to track which response belongs to which public key.
Enums§
- Data
Payload - Data payload enum.
- Packet
- Top-level TCP packet.
Constants§
- MAX_
LINKS_ N - MAX_
TCP_ ENC_ PACKET_ PAYLOAD_ SIZE - A serialized EncryptedPacket payload should be not longer than 2048 bytes
- MAX_
TCP_ ENC_ PACKET_ SIZE - A serialized EncryptedPacket should be not longer than 2050 bytes
- MAX_
TCP_ PACKET_ SIZE - A serialized Packet should be not longer than 2032 bytes