diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-13 17:06:18 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-14 16:20:43 +0000 |
commit | c28d362dd238aefdafe16711dc3645e73b113c21 (patch) | |
tree | 571fbf488e18df87c19baf319e752fde30a775b3 /toxcore | |
parent | d8fcac5b4f66efcec961cf30cb461ab9231c6a67 (diff) |
Make Onion_Client a module-private type.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/friend_connection.c | 4 | ||||
-rw-r--r-- | toxcore/onion_client.c | 118 | ||||
-rw-r--r-- | toxcore/onion_client.h | 115 |
3 files changed, 125 insertions, 112 deletions
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 6998fab7..3f9d79c1 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -825,8 +825,8 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_dis | |||
825 | return NULL; | 825 | return NULL; |
826 | } | 826 | } |
827 | 827 | ||
828 | temp->dht = onion_c->dht; | 828 | temp->dht = onion_get_dht(onion_c); |
829 | temp->net_crypto = onion_c->c; | 829 | temp->net_crypto = onion_get_net_crypto(onion_c); |
830 | temp->onion_c = onion_c; | 830 | temp->onion_c = onion_c; |
831 | temp->local_discovery_enabled = local_discovery_enabled; | 831 | temp->local_discovery_enabled = local_discovery_enabled; |
832 | // Don't include default port in port range | 832 | // Don't include default port in port range |
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 | ||
39 | typedef 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 | |||
57 | typedef 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 | |||
66 | typedef struct { | ||
67 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
68 | uint64_t timestamp; | ||
69 | } Last_Pinged; | ||
70 | |||
71 | typedef 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 | |||
106 | struct 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 | |||
146 | DHT *onion_get_dht(const Onion_Client *onion_c) | ||
147 | { | ||
148 | return onion_c->dht; | ||
149 | } | ||
150 | |||
151 | Net_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 | |||
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 9acb9bac..327d4923 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -65,116 +65,10 @@ | |||
65 | #define ONION_DATA_FRIEND_REQ CRYPTO_PACKET_FRIEND_REQ | 65 | #define ONION_DATA_FRIEND_REQ CRYPTO_PACKET_FRIEND_REQ |
66 | #define ONION_DATA_DHTPK CRYPTO_PACKET_DHTPK | 66 | #define ONION_DATA_DHTPK CRYPTO_PACKET_DHTPK |
67 | 67 | ||
68 | typedef struct { | 68 | typedef struct Onion_Client Onion_Client; |
69 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
70 | IP_Port ip_port; | ||
71 | uint8_t ping_id[ONION_PING_ID_SIZE]; | ||
72 | uint8_t data_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
73 | uint8_t is_stored; | ||
74 | |||
75 | uint64_t added_time; | ||
76 | |||
77 | uint64_t timestamp; | ||
78 | |||
79 | uint64_t last_pinged; | ||
80 | |||
81 | uint8_t unsuccessful_pings; | ||
82 | |||
83 | uint32_t path_used; | ||
84 | } Onion_Node; | ||
85 | |||
86 | typedef struct { | ||
87 | Onion_Path paths[NUMBER_ONION_PATHS]; | ||
88 | uint64_t last_path_success[NUMBER_ONION_PATHS]; | ||
89 | uint64_t last_path_used[NUMBER_ONION_PATHS]; | ||
90 | uint64_t path_creation_time[NUMBER_ONION_PATHS]; | ||
91 | /* number of times used without success. */ | ||
92 | unsigned int last_path_used_times[NUMBER_ONION_PATHS]; | ||
93 | } Onion_Client_Paths; | ||
94 | |||
95 | typedef struct { | ||
96 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
97 | uint64_t timestamp; | ||
98 | } Last_Pinged; | ||
99 | |||
100 | typedef struct { | ||
101 | uint8_t status; /* 0 if friend is not valid, 1 if friend is valid.*/ | ||
102 | uint8_t is_online; /* Set by the onion_set_friend_status function. */ | ||
103 | |||
104 | uint8_t know_dht_public_key; /* 0 if we don't know the dht public key of the other, 1 if we do. */ | ||
105 | uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
106 | uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
107 | |||
108 | Onion_Node clients_list[MAX_ONION_CLIENTS]; | ||
109 | uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
110 | uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE]; | ||
111 | |||
112 | uint64_t last_reported_announced; | ||
113 | |||
114 | uint64_t last_dht_pk_onion_sent; | ||
115 | uint64_t last_dht_pk_dht_sent; | ||
116 | |||
117 | uint64_t last_noreplay; | ||
118 | |||
119 | uint64_t last_seen; | ||
120 | |||
121 | Last_Pinged last_pinged[MAX_STORED_PINGED_NODES]; | ||
122 | uint8_t last_pinged_index; | ||
123 | |||
124 | int (*tcp_relay_node_callback)(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key); | ||
125 | void *tcp_relay_node_callback_object; | ||
126 | uint32_t tcp_relay_node_callback_number; | ||
127 | |||
128 | void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata); | ||
129 | void *dht_pk_callback_object; | ||
130 | uint32_t dht_pk_callback_number; | ||
131 | |||
132 | uint32_t run_count; | ||
133 | } Onion_Friend; | ||
134 | |||
135 | typedef int (*oniondata_handler_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, | ||
136 | uint16_t len, void *userdata); | ||
137 | |||
138 | typedef struct { | ||
139 | DHT *dht; | ||
140 | Net_Crypto *c; | ||
141 | Networking_Core *net; | ||
142 | Onion_Friend *friends_list; | ||
143 | uint16_t num_friends; | ||
144 | |||
145 | Onion_Node clients_announce_list[MAX_ONION_CLIENTS_ANNOUNCE]; | ||
146 | uint64_t last_announce; | ||
147 | |||
148 | Onion_Client_Paths onion_paths_self; | ||
149 | Onion_Client_Paths onion_paths_friends; | ||
150 | |||
151 | uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE]; | ||
152 | uint64_t last_run, first_run; | ||
153 | |||
154 | uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
155 | uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE]; | ||
156 | |||
157 | Last_Pinged last_pinged[MAX_STORED_PINGED_NODES]; | ||
158 | |||
159 | Node_format path_nodes[MAX_PATH_NODES]; | ||
160 | uint16_t path_nodes_index; | ||
161 | |||
162 | Node_format path_nodes_bs[MAX_PATH_NODES]; | ||
163 | uint16_t path_nodes_index_bs; | ||
164 | |||
165 | Ping_Array *announce_ping_array; | ||
166 | uint8_t last_pinged_index; | ||
167 | struct { | ||
168 | oniondata_handler_callback function; | ||
169 | void *object; | ||
170 | } Onion_Data_Handlers[256]; | ||
171 | |||
172 | uint64_t last_packet_recv; | ||
173 | |||
174 | unsigned int onion_connected; | ||
175 | bool UDP_connected; | ||
176 | } Onion_Client; | ||
177 | 69 | ||
70 | DHT *onion_get_dht(const Onion_Client *onion_c); | ||
71 | Net_Crypto *onion_get_net_crypto(const Onion_Client *onion_c); | ||
178 | 72 | ||
179 | /* Add a node to the path_nodes bootstrap array. | 73 | /* Add a node to the path_nodes bootstrap array. |
180 | * | 74 | * |
@@ -283,6 +177,9 @@ unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_ | |||
283 | */ | 177 | */ |
284 | int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length); | 178 | int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length); |
285 | 179 | ||
180 | typedef int (*oniondata_handler_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, | ||
181 | uint16_t len, void *userdata); | ||
182 | |||
286 | /* Function to call when onion data packet with contents beginning with byte is received. */ | 183 | /* Function to call when onion data packet with contents beginning with byte is received. */ |
287 | void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object); | 184 | void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object); |
288 | 185 | ||