diff options
author | irungentoo <irungentoo@gmail.com> | 2013-12-24 16:22:56 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-12-24 16:22:56 -0500 |
commit | ad2037e165fd4639376144ddf92d8ed48ee4a032 (patch) | |
tree | 5d9cad9e2aeeba212786e49387c3149472a7f421 | |
parent | 01949b6a679d4949735972283284309d8caef0bd (diff) |
Added the shell of onion.{c, h}
-rw-r--r-- | docs/Prevent_Tracking.txt | 2 | ||||
-rw-r--r-- | toxcore/network.h | 15 | ||||
-rw-r--r-- | toxcore/onion.c | 104 | ||||
-rw-r--r-- | toxcore/onion.h | 33 | ||||
-rw-r--r-- | toxcore/tox.h | 6 |
5 files changed, 156 insertions, 4 deletions
diff --git a/docs/Prevent_Tracking.txt b/docs/Prevent_Tracking.txt index eb8db794..08c3f673 100644 --- a/docs/Prevent_Tracking.txt +++ b/docs/Prevent_Tracking.txt | |||
@@ -138,4 +138,4 @@ encrypted with temp symmetric key of Node A: [IP_Port (of us)][data to send back | |||
138 | 138 | ||
139 | (sent from node A to us): | 139 | (sent from node A to us): |
140 | 140 | ||
141 | [uint8_t packet id (143)][data to send back] | 141 | [data to send back] |
diff --git a/toxcore/network.h b/toxcore/network.h index 02c43e57..dc7a9f7f 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -111,6 +111,21 @@ typedef int sock_t; | |||
111 | #define NET_PACKET_LAN_DISCOVERY 33 /* LAN discovery packet ID. */ | 111 | #define NET_PACKET_LAN_DISCOVERY 33 /* LAN discovery packet ID. */ |
112 | #define NET_PACKET_GROUP_CHATS 48 /* Group chats packet ID. */ | 112 | #define NET_PACKET_GROUP_CHATS 48 /* Group chats packet ID. */ |
113 | 113 | ||
114 | /* See: docs/Prevent_Tracking.txt and onion.{c, h} */ | ||
115 | #define NET_PACKET_ONION_SEND_INITIAL 128 | ||
116 | #define NET_PACKET_ONION_SEND_1 129 | ||
117 | #define NET_PACKET_ONION_SEND_2 130 | ||
118 | |||
119 | #define NET_PACKET_ANNOUNCE_REQUEST 131 | ||
120 | #define NET_PACKET_ANNOUNCE_RESPONSE 132 | ||
121 | #define NET_PACKET_ONION_DATA_REQUEST 133 | ||
122 | #define NET_PACKET_ONION_DATA_RESPONSE 134 | ||
123 | |||
124 | #define NET_PACKET_ONION_RECV_3 140 | ||
125 | #define NET_PACKET_ONION_RECV_2 141 | ||
126 | #define NET_PACKET_ONION_RECV_1 142 | ||
127 | |||
128 | |||
114 | #define TOX_PORTRANGE_FROM 33445 | 129 | #define TOX_PORTRANGE_FROM 33445 |
115 | #define TOX_PORTRANGE_TO 33545 | 130 | #define TOX_PORTRANGE_TO 33545 |
116 | #define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM | 131 | #define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM |
diff --git a/toxcore/onion.c b/toxcore/onion.c new file mode 100644 index 00000000..7cfc8ecc --- /dev/null +++ b/toxcore/onion.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * onion.c -- Implementation of the onion part of docs/Prevent_Tracking.txt | ||
3 | * | ||
4 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
5 | * | ||
6 | * This file is part of Tox. | ||
7 | * | ||
8 | * Tox is free software: you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation, either version 3 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * Tox is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include "onion.h" | ||
24 | |||
25 | static int handle_send_initial(void *object, IP_Port source, uint8_t *packet, uint32_t length) | ||
26 | { | ||
27 | Onion *onion = object; | ||
28 | |||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | static int handle_send_1(void *object, IP_Port source, uint8_t *packet, uint32_t length) | ||
33 | { | ||
34 | Onion *onion = object; | ||
35 | |||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | static int handle_send_2(void *object, IP_Port source, uint8_t *packet, uint32_t length) | ||
40 | { | ||
41 | Onion *onion = object; | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | |||
47 | static int handle_recv_3(void *object, IP_Port source, uint8_t *packet, uint32_t length) | ||
48 | { | ||
49 | Onion *onion = object; | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | static int handle_recv_2(void *object, IP_Port source, uint8_t *packet, uint32_t length) | ||
55 | { | ||
56 | Onion *onion = object; | ||
57 | |||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static int handle_recv_1(void *object, IP_Port source, uint8_t *packet, uint32_t length) | ||
62 | { | ||
63 | Onion *onion = object; | ||
64 | |||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | |||
69 | |||
70 | Onion *new_onion(DHT *dht) | ||
71 | { | ||
72 | if (dht == NULL) | ||
73 | return NULL; | ||
74 | |||
75 | Onion *onion = calloc(1, sizeof(Onion)); | ||
76 | |||
77 | if (onion == NULL) | ||
78 | return NULL; | ||
79 | |||
80 | new_symmetric_key(onion->secret_symmetric_key); | ||
81 | |||
82 | networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_INITIAL, &handle_send_initial, onion); | ||
83 | networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, &handle_send_1, onion); | ||
84 | networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, &handle_send_2, onion); | ||
85 | |||
86 | networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_3, &handle_recv_3, onion); | ||
87 | networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_2, &handle_recv_2, onion); | ||
88 | networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_1, &handle_recv_1, onion); | ||
89 | |||
90 | return onion; | ||
91 | } | ||
92 | |||
93 | void kill_onion(Onion *onion) | ||
94 | { | ||
95 | networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_INITIAL, NULL, NULL); | ||
96 | networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, NULL, NULL); | ||
97 | networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, NULL, NULL); | ||
98 | |||
99 | networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_3, NULL, NULL); | ||
100 | networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_2, NULL, NULL); | ||
101 | networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_1, NULL, NULL); | ||
102 | |||
103 | free(onion); | ||
104 | } | ||
diff --git a/toxcore/onion.h b/toxcore/onion.h new file mode 100644 index 00000000..fd14c417 --- /dev/null +++ b/toxcore/onion.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * onion.h -- Implementation of the onion part of docs/Prevent_Tracking.txt | ||
3 | * | ||
4 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
5 | * | ||
6 | * This file is part of Tox. | ||
7 | * | ||
8 | * Tox is free software: you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation, either version 3 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * Tox is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include "DHT.h" | ||
24 | |||
25 | typedef struct { | ||
26 | DHT *dht; | ||
27 | uint8_t secret_symmetric_key[crypto_secretbox_KEYBYTES]; | ||
28 | } Onion; | ||
29 | |||
30 | |||
31 | Onion *new_onion(DHT *dht); | ||
32 | |||
33 | void kill_onion(Onion *onion); | ||
diff --git a/toxcore/tox.h b/toxcore/tox.h index 0ffeba62..8d9aab78 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -672,11 +672,11 @@ uint32_t tox_size_encrypted(Tox *tox); | |||
672 | 672 | ||
673 | /* Save the messenger, encrypting the data with key of length key_length | 673 | /* Save the messenger, encrypting the data with key of length key_length |
674 | * | 674 | * |
675 | * This functions simply calls and then encrypt the output of tox_save(..) | 675 | * This functions simply calls and then encrypt the output of tox_save(..) |
676 | * with crypto_secretbox(...) from NaCl/libsodium with the key | 676 | * with crypto_secretbox(...) from NaCl/libsodium with the key |
677 | * given to crypto_secretbox(...) being the SHA256 sum of the key | 677 | * given to crypto_secretbox(...) being the SHA256 sum of the key |
678 | * passed to this function. | 678 | * passed to this function. |
679 | * | 679 | * |
680 | * return 0 on success. | 680 | * return 0 on success. |
681 | * return -1 on failure. | 681 | * return -1 on failure. |
682 | */ | 682 | */ |