summaryrefslogtreecommitdiff
path: root/toxcore/Lossless_UDP.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-05-02 10:36:48 -0400
committerirungentoo <irungentoo@gmail.com>2014-05-02 10:36:48 -0400
commit8e24771fc41597dd9e3e02a192eb0b5b43771ac1 (patch)
tree1082d855140bd1548d87a2db618945f68b66884a /toxcore/Lossless_UDP.h
parentdeb8bfc350748555b7de5d0f4911c382b3f2d65e (diff)
Remove Lossless UDP (This breaks Tox.)
Diffstat (limited to 'toxcore/Lossless_UDP.h')
-rw-r--r--toxcore/Lossless_UDP.h262
1 files changed, 0 insertions, 262 deletions
diff --git a/toxcore/Lossless_UDP.h b/toxcore/Lossless_UDP.h
deleted file mode 100644
index 587cd9ff..00000000
--- a/toxcore/Lossless_UDP.h
+++ /dev/null
@@ -1,262 +0,0 @@
1/* Lossless_UDP.h
2 *
3 * An implementation of the Lossless_UDP protocol as seen in http://wiki.tox.im/index.php/Lossless_UDP
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#ifndef LOSSLESS_UDP_H
25#define LOSSLESS_UDP_H
26
27#include "network.h"
28#include "crypto_core.h"
29#include "misc_tools.h"
30
31
32/* Maximum length of the data in the data packets. */
33#define MAX_DATA_SIZE 1024
34
35/* Maximum data packets in sent and receive queues. */
36#define MAX_QUEUE_NUM 1024
37#define DEFAULT_QUEUE_NUM 4
38
39/* Maximum number of data packets in the buffer. */
40#define MAX_REQUESTED_PACKETS 256
41
42/* Timeout per connection is randomly set between CONNECTION_TIMEOUT and 2*CONNECTION_TIMEOUT. */
43#define CONNECTION_TIMEOUT 5
44
45/* Initial amount of sync/handshake packets to send per second. */
46#define SYNC_RATE 2
47
48/* Initial send rate of data. */
49#define DATA_SYNC_RATE 30
50
51typedef struct {
52 uint8_t data[MAX_DATA_SIZE];
53 uint16_t size;
54} Data;
55
56#define LUDP_NO_CONNECTION 0
57#define LUDP_HANDSHAKE_SENDING 1
58#define LUDP_NOT_CONFIRMED 2
59#define LUDP_ESTABLISHED 3
60#define LUDP_TIMED_OUT 4
61
62typedef struct {
63 IP_Port ip_port;
64
65 /*
66 * return LUDP_NO_CONNECTION if connection is dead.
67 * return LUDP_HANDSHAKE_SENDING if attempting handshake.
68 * return LUDP_NOT_CONFIRMED if handshake is done (we start sending SYNC packets).
69 * return LUDP_ESTABLISHED if we are sending SYNC packets and can send data.
70 * return LUDP_TIMED_OUT if the connection has timed out.
71 */
72 uint8_t status;
73
74 /*
75 * return 0 if connection was not initiated by someone else.
76 * return 1 if incoming_connection() has returned.
77 * return 2 if it has not.
78 */
79 uint8_t inbound;
80
81 uint16_t SYNC_rate; /* Current SYNC packet send rate packets per second. */
82 uint32_t data_rate; /* Current data packet send rate packets per second. */
83
84 uint64_t last_SYNC; /* Time our last SYNC packet was sent. */
85 uint64_t last_sent; /* Time our last data or handshake packet was sent. */
86 uint64_t last_recvSYNC; /* Time we last received a SYNC packet from the other. */
87 uint64_t last_recvdata; /* Time we last received a DATA packet from the other. */
88 uint64_t killat; /* Time to kill the connection. */
89
90 Data *sendbuffer; /* packet send buffer. */
91 uint32_t sendbuffer_length;
92 Data *recvbuffer; /* packet receive buffer. */
93 uint32_t recvbuffer_length;
94 uint32_t handshake_id1;
95 uint32_t handshake_id2;
96
97 /* Number of data packets received (also used as handshake_id1). */
98 uint32_t recv_packetnum;
99
100 /* Number of packets received by the other peer. */
101 uint32_t orecv_packetnum;
102
103 /* Number of data packets sent. */
104 uint32_t sent_packetnum;
105
106 /* Number of packets sent by the other peer. */
107 uint32_t osent_packetnum;
108
109 /* Number of latest packet written onto the sendbuffer. */
110 uint32_t sendbuff_packetnum;
111
112 /* We know all packets before that number were successfully sent. */
113 uint32_t successful_sent;
114
115 /* Packet number of last packet read with the read_packet function. */
116 uint32_t successful_read;
117
118 /* List of currently requested packet numbers(by the other person). */
119 uint32_t req_packets[MAX_REQUESTED_PACKETS];
120
121 /* Total number of currently requested packets(by the other person). */
122 uint16_t num_req_paquets;
123
124 uint8_t recv_counter;
125 uint8_t send_counter;
126 uint8_t timeout; /* connection timeout in seconds. */
127
128 /* Is the connection confirmed or not? 1 if yes, 0 if no */
129 uint8_t confirmed;
130} Connection;
131
132typedef struct {
133 Networking_Core *net;
134
135 tox_array connections;
136
137 /* Table of random numbers used in handshake_id. */
138 /* IPv6 (16) + port (2)*/
139 uint32_t randtable[18][256];
140} Lossless_UDP;
141
142/*
143 * Initialize a new connection to ip_port.
144 *
145 * return an integer corresponding to the connection id.
146 * return -1 if it could not initialize the connection.
147 * return number if there already was an existing connection to that ip_port.
148 */
149int new_connection(Lossless_UDP *ludp, IP_Port ip_port);
150
151/*
152 * Get connection id from IP_Port.
153 *
154 * return -1 if there are no connections like we are looking for.
155 * return id if it found it .
156 */
157int getconnection_id(Lossless_UDP *ludp, IP_Port ip_port);
158
159/*
160 * return an integer corresponding to the next connection in our incoming connection list with at least numpackets in the recieve queue.
161 * return -1 if there are no new incoming connections in the list.
162 */
163int incoming_connection(Lossless_UDP *ludp, uint32_t numpackets);
164
165/* return -1 if it could not kill the connection.
166 * return 0 if killed successfully.
167 */
168int kill_connection(Lossless_UDP *ludp, int connection_id);
169
170/*
171 * timeout connection in seconds seconds.
172 *
173 * return -1 if it can not kill the connection.
174 * return 0 if it will kill it.
175 */
176int timeout_connection_in(Lossless_UDP *ludp, int connection_id, uint32_t seconds);
177
178
179/* Check if connection is confirmed.
180 *
181 * returns 1 if yes.
182 * returns 0 if no.
183 */
184int connection_confirmed(Lossless_UDP *ludp, int connection_id);
185
186/* Confirm an incoming connection.
187 * Also disables the auto kill timeout on incomming connections.
188 *
189 * return 0 on success
190 * return -1 on failure.
191 */
192int confirm_connection(Lossless_UDP *ludp, int connection_id);
193
194/* returns the ip_port of the corresponding connection.
195 * return 0 if there is no such connection.
196 */
197IP_Port connection_ip(Lossless_UDP *ludp, int connection_id);
198
199/* returns the id of the next packet in the queue.
200 * return -1 if no packet in queue.
201 */
202uint8_t id_packet(Lossless_UDP *ludp, int connection_id);
203
204/* return 0 if there is no received data in the buffer.
205 * return length of received packet if successful.
206 */
207int read_packet(Lossless_UDP *ludp, int connection_id, uint8_t *data);
208
209/* Like read_packet() but does leaves the queue as is.
210 * return 0 if there is no received data in the buffer.
211 * return length of received packet if successful.
212 */
213int read_packet_silent(Lossless_UDP *ludp, int connection_id, uint8_t *data);
214
215/* Discard the next packet to be read from the queue
216 * return 0 if success.
217 * return -1 if failure.
218 */
219int discard_packet(Lossless_UDP *ludp, int connection_id);
220
221/* returns the number of packet slots left in the sendbuffer.
222 * return 0 if failure.
223 */
224uint32_t num_free_sendqueue_slots(Lossless_UDP *ludp, int connection_id);
225
226/* return 0 if data could not be put in packet queue.
227 * return 1 if data was put into the queue.
228 */
229int write_packet(Lossless_UDP *ludp, int connection_id, uint8_t *data, uint32_t length);
230
231/* return number of packets in the queue waiting to be successfully sent. */
232uint32_t sendqueue(Lossless_UDP *ludp, int connection_id);
233
234/* return number of packets in all queues waiting to be successfully sent. */
235uint32_t sendqueue_total(Lossless_UDP *ludp);
236
237/*
238 * return number of packets in the queue waiting to be successfully
239 * read with read_packet(...).
240 */
241uint32_t recvqueue(Lossless_UDP *ludp, int connection_id);
242
243/* Check if connection is connected:
244 *
245 * return LUDP_NO_CONNECTION if not.
246 * return LUDP_HANDSHAKE_SENDING if attempting handshake.
247 * return LUDP_NOT_CONFIRMED if handshake is done.
248 * return LUDP_ESTABLISHED if fully connected.
249 * return LUDP_TIMED_OUT if timed out and wating to be killed.
250 */
251int is_connected(Lossless_UDP *ludp, int connection_id);
252
253/* Call this function a couple times per second. It is the main loop. */
254void do_lossless_udp(Lossless_UDP *ludp);
255
256/* This function sets up LosslessUDP packet handling. */
257Lossless_UDP *new_lossless_udp(Networking_Core *net);
258
259void kill_lossless_udp(Lossless_UDP *ludp);
260
261
262#endif