ffi-tox 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ProjectTox-Core/CMakeLists.txt +28 -0
- data/ProjectTox-Core/COPYING +674 -0
- data/ProjectTox-Core/INSTALL.md +91 -0
- data/ProjectTox-Core/README.md +54 -0
- data/ProjectTox-Core/core/CMakeLists.txt +17 -0
- data/ProjectTox-Core/core/DHT.c +1104 -0
- data/ProjectTox-Core/core/DHT.h +111 -0
- data/ProjectTox-Core/core/LAN_discovery.c +79 -0
- data/ProjectTox-Core/core/LAN_discovery.h +50 -0
- data/ProjectTox-Core/core/Lossless_UDP.c +749 -0
- data/ProjectTox-Core/core/Lossless_UDP.h +106 -0
- data/ProjectTox-Core/core/Messenger.c +581 -0
- data/ProjectTox-Core/core/Messenger.h +157 -0
- data/ProjectTox-Core/core/friend_requests.c +131 -0
- data/ProjectTox-Core/core/friend_requests.h +51 -0
- data/ProjectTox-Core/core/net_crypto.c +564 -0
- data/ProjectTox-Core/core/net_crypto.h +134 -0
- data/ProjectTox-Core/core/network.c +188 -0
- data/ProjectTox-Core/core/network.h +134 -0
- data/ProjectTox-Core/other/CMakeLists.txt +9 -0
- data/ProjectTox-Core/other/DHT_bootstrap.c +139 -0
- data/ProjectTox-Core/testing/CMakeLists.txt +18 -0
- data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +228 -0
- data/ProjectTox-Core/testing/DHT_sendfiletest.c +176 -0
- data/ProjectTox-Core/testing/DHT_test.c +182 -0
- data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +214 -0
- data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +201 -0
- data/ProjectTox-Core/testing/Messenger_test.c +145 -0
- data/ProjectTox-Core/testing/misc_tools.c +40 -0
- data/ProjectTox-Core/testing/misc_tools.h +29 -0
- data/ProjectTox-Core/testing/nTox.c +381 -0
- data/ProjectTox-Core/testing/nTox.h +50 -0
- data/ProjectTox-Core/testing/nTox_win32.c +323 -0
- data/ProjectTox-Core/testing/nTox_win32.h +31 -0
- data/ProjectTox-Core/testing/rect.py +45 -0
- data/ext/ffi-tox/extconf.rb +16 -0
- data/interfaces/libtox.i +18 -0
- data/lib/ffi-tox/libtox.rb +37 -0
- data/lib/ffi-tox.rb +1 -0
- metadata +116 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
/* DHT.h
|
2
|
+
*
|
3
|
+
* An implementation of the DHT as seen in docs/DHT.txt
|
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 DHT_H
|
25
|
+
#define DHT_H
|
26
|
+
|
27
|
+
#include "net_crypto.h"
|
28
|
+
|
29
|
+
#ifdef __cplusplus
|
30
|
+
extern "C" {
|
31
|
+
#endif
|
32
|
+
|
33
|
+
/* Current time, unix format */
|
34
|
+
#define unix_time() ((uint32_t)time(NULL))
|
35
|
+
|
36
|
+
/* size of the client_id in bytes */
|
37
|
+
#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES
|
38
|
+
|
39
|
+
/* Add a new friend to the friends list
|
40
|
+
client_id must be CLIENT_ID_SIZE bytes long.
|
41
|
+
returns 0 if success
|
42
|
+
returns 1 if failure (friends list is full) */
|
43
|
+
int DHT_addfriend(uint8_t *client_id);
|
44
|
+
|
45
|
+
/* Delete a friend from the friends list
|
46
|
+
client_id must be CLIENT_ID_SIZE bytes long.
|
47
|
+
returns 0 if success
|
48
|
+
returns 1 if failure (client_id not in friends list) */
|
49
|
+
int DHT_delfriend(uint8_t *client_id);
|
50
|
+
|
51
|
+
/* Get ip of friend
|
52
|
+
client_id must be CLIENT_ID_SIZE bytes long.
|
53
|
+
ip must be 4 bytes long.
|
54
|
+
port must be 2 bytes long.
|
55
|
+
returns ip if success
|
56
|
+
returns ip of 0 if failure (This means the friend is either offline or we have not found him yet.)
|
57
|
+
returns ip of 1 if friend is not in list. */
|
58
|
+
IP_Port DHT_getfriendip(uint8_t *client_id);
|
59
|
+
|
60
|
+
/* Run this function at least a couple times per second (It's the main loop) */
|
61
|
+
void doDHT();
|
62
|
+
|
63
|
+
/* if we receive a DHT packet we call this function so it can be handled.
|
64
|
+
return 0 if packet is handled correctly.
|
65
|
+
return 1 if it didn't handle the packet or if the packet was shit. */
|
66
|
+
int DHT_handlepacket(uint8_t *packet, uint32_t length, IP_Port source);
|
67
|
+
|
68
|
+
/* Use this function to bootstrap the client
|
69
|
+
Sends a get nodes request to the given node with ip port and public_key */
|
70
|
+
void DHT_bootstrap(IP_Port ip_port, uint8_t *public_key);
|
71
|
+
|
72
|
+
/* ROUTING FUNCTIONS */
|
73
|
+
|
74
|
+
/* send the given packet to node with client_id
|
75
|
+
returns -1 if failure */
|
76
|
+
int route_packet(uint8_t *client_id, uint8_t *packet, uint32_t length);
|
77
|
+
|
78
|
+
/* Send the following packet to everyone who tells us they are connected to friend_id
|
79
|
+
returns the number of nodes it sent the packet to */
|
80
|
+
int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length);
|
81
|
+
|
82
|
+
/* NAT PUNCHING FUNCTIONS */
|
83
|
+
|
84
|
+
/* Puts all the different ips returned by the nodes for a friend_id into array ip_portlist
|
85
|
+
ip_portlist must be at least MAX_FRIEND_CLIENTS big
|
86
|
+
returns the number of ips returned
|
87
|
+
returns -1 if no such friend*/
|
88
|
+
int friend_ips(IP_Port *ip_portlist, uint8_t *friend_id);
|
89
|
+
|
90
|
+
/* SAVE/LOAD functions */
|
91
|
+
|
92
|
+
/* get the size of the DHT (for saving) */
|
93
|
+
uint32_t DHT_size();
|
94
|
+
|
95
|
+
/* save the DHT in data where data is an array of size DHT_size() */
|
96
|
+
void DHT_save(uint8_t *data);
|
97
|
+
|
98
|
+
/* load the DHT from data of size size;
|
99
|
+
return -1 if failure
|
100
|
+
return 0 if success */
|
101
|
+
int DHT_load(uint8_t *data, uint32_t size);
|
102
|
+
|
103
|
+
/* returns 0 if we are not connected to the DHT
|
104
|
+
returns 1 if we are */
|
105
|
+
int DHT_isconnected();
|
106
|
+
|
107
|
+
#ifdef __cplusplus
|
108
|
+
}
|
109
|
+
#endif
|
110
|
+
|
111
|
+
#endif
|
@@ -0,0 +1,79 @@
|
|
1
|
+
/* LAN_discovery.c
|
2
|
+
*
|
3
|
+
* LAN discovery implementation.
|
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
|
+
#include "LAN_discovery.h"
|
25
|
+
|
26
|
+
|
27
|
+
/*Return the broadcast ip
|
28
|
+
TODO: make it return the real one, not the 255.255.255.255 one.*/
|
29
|
+
IP broadcast_ip()
|
30
|
+
{
|
31
|
+
IP ip;
|
32
|
+
ip.i = ~0;
|
33
|
+
return ip;
|
34
|
+
}
|
35
|
+
|
36
|
+
/*return 0 if ip is a LAN ip
|
37
|
+
return -1 if it is not */
|
38
|
+
int LAN_ip(IP ip)
|
39
|
+
{
|
40
|
+
if (ip.c[0] == 127)/* Loopback */
|
41
|
+
return 0;
|
42
|
+
if (ip.c[0] == 10)/* 10.0.0.0 to 10.255.255.255 range */
|
43
|
+
return 0;
|
44
|
+
if (ip.c[0] == 172 && ip.c[1] >= 16 && ip.c[1] <= 31)/* 172.16.0.0 to 172.31.255.255 range */
|
45
|
+
return 0;
|
46
|
+
if (ip.c[0] == 192 && ip.c[1] == 168) /* 192.168.0.0 to 192.168.255.255 range */
|
47
|
+
return 0;
|
48
|
+
if (ip.c[0] == 169 && ip.c[1] == 254 && ip.c[2] != 0 && ip.c[2] != 255)/* 169.254.1.0 to 169.254.254.255 range */
|
49
|
+
return 0;
|
50
|
+
return -1;
|
51
|
+
}
|
52
|
+
|
53
|
+
int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source)
|
54
|
+
{
|
55
|
+
if (LAN_ip(source.ip) == -1)
|
56
|
+
return 1;
|
57
|
+
if (length != crypto_box_PUBLICKEYBYTES + 1)
|
58
|
+
return 1;
|
59
|
+
DHT_bootstrap(source, packet + 1);
|
60
|
+
return 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
int send_LANdiscovery(uint16_t port)
|
65
|
+
{
|
66
|
+
uint8_t data[crypto_box_PUBLICKEYBYTES + 1];
|
67
|
+
data[0] = 32;
|
68
|
+
memcpy(data + 1, self_public_key, crypto_box_PUBLICKEYBYTES);
|
69
|
+
IP_Port ip_port = {broadcast_ip(), port};
|
70
|
+
return sendpacket(ip_port, data, 1 + crypto_box_PUBLICKEYBYTES);
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
int LANdiscovery_handlepacket(uint8_t *packet, uint32_t length, IP_Port source)
|
75
|
+
{
|
76
|
+
if (packet[0] == 32)
|
77
|
+
return handle_LANdiscovery(packet, length, source);
|
78
|
+
return 1;
|
79
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/* LAN_discovery.h
|
2
|
+
*
|
3
|
+
* LAN discovery implementation.
|
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
|
+
|
25
|
+
#ifndef LAN_DISCOVERY_H
|
26
|
+
#define LAN_DISCOVERY_H
|
27
|
+
|
28
|
+
|
29
|
+
#include "DHT.h"
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
extern "C" {
|
33
|
+
#endif
|
34
|
+
|
35
|
+
/*Send a LAN discovery pcaket to the broadcast address with port port*/
|
36
|
+
int send_LANdiscovery(uint16_t port);
|
37
|
+
|
38
|
+
|
39
|
+
/* if we receive a packet we call this function so it can be handled.
|
40
|
+
return 0 if packet is handled correctly.
|
41
|
+
return 1 if it didn't handle the packet or if the packet was shit. */
|
42
|
+
int LANdiscovery_handlepacket(uint8_t *packet, uint32_t length, IP_Port source);
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
#ifdef __cplusplus
|
47
|
+
}
|
48
|
+
#endif
|
49
|
+
|
50
|
+
#endif
|