summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--other/fun/bootstrap_node_info.py98
-rw-r--r--toxcore/TCP_client.c24
-rw-r--r--toxcore/TCP_client.h1
4 files changed, 121 insertions, 6 deletions
diff --git a/README.md b/README.md
index cbe53af5..ff3a6bba 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
3 3
4With the rise of governmental monitoring programs, Tox, a FOSS initiative, aims to be an easy to use, all-in-one communication platform that ensures their users full privacy and secure message delivery.<br /> <br /> 4With the rise of governmental monitoring programs, Tox, a FOSS initiative, aims to be an easy to use, all-in-one communication platform that ensures their users full privacy and secure message delivery.<br /> <br />
5 5
6[**Website**](https://tox.im) **|** [**Wiki**](https://wiki.tox.im/) **|** [**Blog**](https://blog.libtoxcore.so/) **|** [**FAQ**](http://wiki.tox.im/FAQ) **|** [**Binaries**](https://wiki.tox.im/Binaries) **|** [**Clients**](https://wiki.tox.im/Client) **|** [**Compiling**](https://wiki.tox.im/Installing) **|** [**API**](https://libtoxcore.so/) **|** **IRC:** #tox@freenode 6[**Website**](https://tox.im) **|** [**Download**](https://wiki.tox.im/Binaries) **|** [**Wiki**](https://wiki.tox.im/) **|** [**Blog**](https://blog.libtoxcore.so/) **|** [**FAQ**](http://wiki.tox.im/FAQ) **|** [**Binaries**](https://wiki.tox.im/Binaries) **|** [**Clients**](https://wiki.tox.im/Client) **|** [**Compiling**](https://wiki.tox.im/Installing) **|** [**API**](https://libtoxcore.so/) **|** **IRC:** #tox@freenode
7 7
8 8
9## The Complex Stuff: 9## The Complex Stuff:
@@ -33,7 +33,7 @@ The goal of this project is to create a configuration-free P2P Skype replacement
33 33
34## Documentation: 34## Documentation:
35 35
36- [Installation](/INSTALL.md) 36- [Compiling](/INSTALL.md)
37- [DHT Protocol](https://wiki.tox.im/index.php/DHT)<br /> 37- [DHT Protocol](https://wiki.tox.im/index.php/DHT)<br />
38- [Lossless UDP Protocol](https://wiki.tox.im/index.php/Lossless_UDP)<br /> 38- [Lossless UDP Protocol](https://wiki.tox.im/index.php/Lossless_UDP)<br />
39- [Crypto](https://wiki.tox.im/index.php/Crypto)<br /> 39- [Crypto](https://wiki.tox.im/index.php/Crypto)<br />
diff --git a/other/fun/bootstrap_node_info.py b/other/fun/bootstrap_node_info.py
new file mode 100644
index 00000000..17349334
--- /dev/null
+++ b/other/fun/bootstrap_node_info.py
@@ -0,0 +1,98 @@
1#!/usr/bin/env python
2"""
3Copyright (c) 2014 by nurupo <nurupo.contributions@gmail.com>
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21THE SOFTWARE.
22"""
23
24from socket import *
25import sys
26
27if sys.version_info[0] == 2:
28 print("This script requires Python 3+ in order to run.")
29 sys.exit(1)
30
31def printHelp():
32 print("Usage: " + sys.argv[0] + " <ipv4|ipv6> <ip/hostname> <port>")
33 print(" Example: " + sys.argv[0] + " ipv4 192.210.149.121 33445")
34 print(" Example: " + sys.argv[0] + " ipv4 23.226.230.47 33445")
35 print(" Example: " + sys.argv[0] + " ipv4 biribiri.org 33445")
36 print(" Example: " + sys.argv[0] + " ipv4 cerberus.zodiaclabs.org 33445")
37 print(" Example: " + sys.argv[0] + " ipv6 2604:180:1::3ded:b280 33445")
38 print("")
39 print("Return values:")
40 print(" 0 - received info reply from a node")
41 print(" 1 - incorrect command line arguments")
42 print(" 2 - didn't receive any reply from a node")
43 print(" 3 - received a malformed/unexpected reply")
44
45if len(sys.argv) != 4:
46 printHelp()
47 sys.exit(1)
48
49protocol = sys.argv[1]
50ip = sys.argv[2]
51port = int(sys.argv[3])
52
53INFO_PACKET_ID = b"\xF0" # https://github.com/irungentoo/toxcore/blob/4940c4c62b6014d1f0586aa6aca7bf6e4ecfcf29/toxcore/network.h#L128
54INFO_REQUEST_PACKET_LENGTH = 78 # https://github.com/irungentoo/toxcore/blob/881b2d900d1998981fb6b9938ec66012d049635f/other/bootstrap_node_packets.c#L28
55# first byte is INFO_REQUEST_ID, other bytes don't matter as long as reqest's length matches INFO_REQUEST_LENGTH
56INFO_REQUEST_PACKET = INFO_PACKET_ID + ( b"0" * (INFO_REQUEST_PACKET_LENGTH - len(INFO_PACKET_ID)) )
57
58PACKET_ID_LENGTH = len(INFO_PACKET_ID)
59VERSION_LENGTH = 4 # https://github.com/irungentoo/toxcore/blob/881b2d900d1998981fb6b9938ec66012d049635f/other/bootstrap_node_packets.c#L44
60MAX_MOTD_LENGTH = 256 # https://github.com/irungentoo/toxcore/blob/881b2d900d1998981fb6b9938ec66012d049635f/other/bootstrap_node_packets.c#L26
61
62MAX_INFO_RESPONSE_PACKET_LENGTH = PACKET_ID_LENGTH + VERSION_LENGTH + MAX_MOTD_LENGTH
63
64SOCK_TIMEOUT_SECONDS = 1.0
65
66sock = None
67
68if protocol == "ipv4":
69 sock = socket(AF_INET, SOCK_DGRAM)
70elif protocol == "ipv6":
71 sock = socket(AF_INET6, SOCK_DGRAM)
72else:
73 print("Invalid first argument")
74 printHelp()
75 sys.exit(1)
76
77sock.sendto(INFO_REQUEST_PACKET, (ip, port))
78
79sock.settimeout(SOCK_TIMEOUT_SECONDS)
80
81try:
82 data, addr = sock.recvfrom(MAX_INFO_RESPONSE_PACKET_LENGTH)
83except timeout:
84 print("The DHT bootstrap node didn't reply in " + str(SOCK_TIMEOUT_SECONDS) + " sec.")
85 print("The likely reason for that is that the DHT bootstrap node is either offline or has no info set.")
86 sys.exit(2)
87
88packetId = data[:PACKET_ID_LENGTH]
89if packetId != INFO_PACKET_ID:
90 print("Bad response, first byte should be", INFO_PACKET_ID, "but got", packetId, "(", data, ")")
91 print("Are you sure that you are pointing the script at a Tox DHT bootstrap node and that the script is up to date?")
92 sys.exit(3)
93
94version = int.from_bytes(data[PACKET_ID_LENGTH:PACKET_ID_LENGTH + VERSION_LENGTH], byteorder='big')
95motd = data[PACKET_ID_LENGTH + VERSION_LENGTH:].decode("utf-8")
96print("Version: " + str(version))
97print("MOTD: " + motd)
98sys.exit(0) \ No newline at end of file
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index 087188f7..82720ae8 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -197,6 +197,8 @@ void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(v
197 con->status_callback_object = object; 197 con->status_callback_object = object;
198} 198}
199 199
200static int send_ping_response(TCP_Client_Connection *con);
201
200/* return 1 on success. 202/* return 1 on success.
201 * return 0 if could not send packet. 203 * return 0 if could not send packet.
202 * return -1 on failure. 204 * return -1 on failure.
@@ -209,6 +211,9 @@ int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, u
209 if (con->connections[con_id].status != 2) 211 if (con->connections[con_id].status != 2)
210 return -1; 212 return -1;
211 213
214 if (send_ping_response(con) == 0)
215 return 0;
216
212 uint8_t packet[1 + length]; 217 uint8_t packet[1 + length];
213 packet[0] = con_id + NUM_RESERVED_PORTS; 218 packet[0] = con_id + NUM_RESERVED_PORTS;
214 memcpy(packet + 1, data, length); 219 memcpy(packet + 1, data, length);
@@ -293,12 +298,21 @@ static int send_ping_request(TCP_Client_Connection *con, uint64_t ping_id)
293 * return 0 if could not send packet. 298 * return 0 if could not send packet.
294 * return -1 on failure (connection must be killed). 299 * return -1 on failure (connection must be killed).
295 */ 300 */
296static int send_ping_response(TCP_Client_Connection *con, uint64_t ping_id) 301static int send_ping_response(TCP_Client_Connection *con)
297{ 302{
303 if (!con->ping_response_id)
304 return 1;
305
298 uint8_t packet[1 + sizeof(uint64_t)]; 306 uint8_t packet[1 + sizeof(uint64_t)];
299 packet[0] = TCP_PACKET_PONG; 307 packet[0] = TCP_PACKET_PONG;
300 memcpy(packet + 1, &ping_id, sizeof(uint64_t)); 308 memcpy(packet + 1, &con->ping_response_id, sizeof(uint64_t));
301 return write_packet_TCP_secure_connection(con, packet, sizeof(packet)); 309 int ret;
310
311 if ((ret = write_packet_TCP_secure_connection(con, packet, sizeof(packet))) == 1) {
312 con->ping_response_id = 0;
313 }
314
315 return ret;
302} 316}
303 317
304/* return 1 on success. 318/* return 1 on success.
@@ -468,7 +482,8 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u
468 482
469 uint64_t ping_id; 483 uint64_t ping_id;
470 memcpy(&ping_id, data + 1, sizeof(uint64_t)); 484 memcpy(&ping_id, data + 1, sizeof(uint64_t));
471 send_ping_response(conn, ping_id); 485 conn->ping_response_id = ping_id;
486 send_ping_response(conn);
472 return 0; 487 return 0;
473 } 488 }
474 489
@@ -523,6 +538,7 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u
523static int do_confirmed_TCP(TCP_Client_Connection *conn) 538static int do_confirmed_TCP(TCP_Client_Connection *conn)
524{ 539{
525 send_pending_data(conn); 540 send_pending_data(conn);
541 send_ping_response(conn);
526 uint8_t packet[MAX_PACKET_SIZE]; 542 uint8_t packet[MAX_PACKET_SIZE];
527 int len; 543 int len;
528 544
diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h
index 2622b4f7..e6d232ed 100644
--- a/toxcore/TCP_client.h
+++ b/toxcore/TCP_client.h
@@ -57,6 +57,7 @@ typedef struct {
57 uint64_t last_pinged; 57 uint64_t last_pinged;
58 uint64_t ping_id; 58 uint64_t ping_id;
59 59
60 uint64_t ping_response_id;
60 void *net_crypto_pointer; 61 void *net_crypto_pointer;
61 uint32_t net_crypto_location; 62 uint32_t net_crypto_location;
62 struct { 63 struct {