summaryrefslogtreecommitdiff
path: root/toxcore/onion_client.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-01-13 17:06:18 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-01-14 16:20:43 +0000
commitc28d362dd238aefdafe16711dc3645e73b113c21 (patch)
tree571fbf488e18df87c19baf319e752fde30a775b3 /toxcore/onion_client.c
parentd8fcac5b4f66efcec961cf30cb461ab9231c6a67 (diff)
Make Onion_Client a module-private type.
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r--toxcore/onion_client.c118
1 files changed, 117 insertions, 1 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 1490d78d..8a4dd40d 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -36,6 +36,123 @@
36#define ANNOUNCE_ARRAY_SIZE 256 36#define ANNOUNCE_ARRAY_SIZE 256
37#define ANNOUNCE_TIMEOUT 10 37#define ANNOUNCE_TIMEOUT 10
38 38
39typedef struct {
40 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
41 IP_Port ip_port;
42 uint8_t ping_id[ONION_PING_ID_SIZE];
43 uint8_t data_public_key[CRYPTO_PUBLIC_KEY_SIZE];
44 uint8_t is_stored;
45
46 uint64_t added_time;
47
48 uint64_t timestamp;
49
50 uint64_t last_pinged;
51
52 uint8_t unsuccessful_pings;
53
54 uint32_t path_used;
55} Onion_Node;
56
57typedef struct {
58 Onion_Path paths[NUMBER_ONION_PATHS];
59 uint64_t last_path_success[NUMBER_ONION_PATHS];
60 uint64_t last_path_used[NUMBER_ONION_PATHS];
61 uint64_t path_creation_time[NUMBER_ONION_PATHS];
62 /* number of times used without success. */
63 unsigned int last_path_used_times[NUMBER_ONION_PATHS];
64} Onion_Client_Paths;
65
66typedef struct {
67 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
68 uint64_t timestamp;
69} Last_Pinged;
70
71typedef struct {
72 uint8_t status; /* 0 if friend is not valid, 1 if friend is valid.*/
73 uint8_t is_online; /* Set by the onion_set_friend_status function. */
74
75 uint8_t know_dht_public_key; /* 0 if we don't know the dht public key of the other, 1 if we do. */
76 uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE];
77 uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE];
78
79 Onion_Node clients_list[MAX_ONION_CLIENTS];
80 uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE];
81 uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE];
82
83 uint64_t last_reported_announced;
84
85 uint64_t last_dht_pk_onion_sent;
86 uint64_t last_dht_pk_dht_sent;
87
88 uint64_t last_noreplay;
89
90 uint64_t last_seen;
91
92 Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
93 uint8_t last_pinged_index;
94
95 int (*tcp_relay_node_callback)(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key);
96 void *tcp_relay_node_callback_object;
97 uint32_t tcp_relay_node_callback_number;
98
99 void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata);
100 void *dht_pk_callback_object;
101 uint32_t dht_pk_callback_number;
102
103 uint32_t run_count;
104} Onion_Friend;
105
106struct Onion_Client {
107 DHT *dht;
108 Net_Crypto *c;
109 Networking_Core *net;
110 Onion_Friend *friends_list;
111 uint16_t num_friends;
112
113 Onion_Node clients_announce_list[MAX_ONION_CLIENTS_ANNOUNCE];
114 uint64_t last_announce;
115
116 Onion_Client_Paths onion_paths_self;
117 Onion_Client_Paths onion_paths_friends;
118
119 uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
120 uint64_t last_run, first_run;
121
122 uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE];
123 uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE];
124
125 Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
126
127 Node_format path_nodes[MAX_PATH_NODES];
128 uint16_t path_nodes_index;
129
130 Node_format path_nodes_bs[MAX_PATH_NODES];
131 uint16_t path_nodes_index_bs;
132
133 Ping_Array *announce_ping_array;
134 uint8_t last_pinged_index;
135 struct {
136 oniondata_handler_callback function;
137 void *object;
138 } Onion_Data_Handlers[256];
139
140 uint64_t last_packet_recv;
141
142 unsigned int onion_connected;
143 bool UDP_connected;
144};
145
146DHT *onion_get_dht(const Onion_Client *onion_c)
147{
148 return onion_c->dht;
149}
150
151Net_Crypto *onion_get_net_crypto(const Onion_Client *onion_c)
152{
153 return onion_c->c;
154}
155
39/* Add a node to the path_nodes bootstrap array. 156/* Add a node to the path_nodes bootstrap array.
40 * 157 *
41 * return -1 on failure 158 * return -1 on failure
@@ -1770,4 +1887,3 @@ void kill_onion_client(Onion_Client *onion_c)
1770 crypto_memzero(onion_c, sizeof(Onion_Client)); 1887 crypto_memzero(onion_c, sizeof(Onion_Client));
1771 free(onion_c); 1888 free(onion_c);
1772} 1889}
1773