summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-07-29 22:39:56 -0400
committerirungentoo <irungentoo@gmail.com>2015-07-29 22:39:56 -0400
commitdfc154cc9e55c91ed9eba7e995ee560688c1eac5 (patch)
tree19e1d7e0296be426933331b8bb8802b17ab5f738 /auto_tests
parentc989c246ead878f14ca889d5533f6bd2dad7408a (diff)
client_id -> public_key
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/assoc_test.c2
-rw-r--r--auto_tests/dht_test.c82
2 files changed, 42 insertions, 42 deletions
diff --git a/auto_tests/assoc_test.c b/auto_tests/assoc_test.c
index bcf5d3fa..9de95136 100644
--- a/auto_tests/assoc_test.c
+++ b/auto_tests/assoc_test.c
@@ -124,7 +124,7 @@ START_TEST(test_fillup)
124 124
125 for (i = 0; i < 8; ++i) { 125 for (i = 0; i < 8; ++i) {
126 for (j = 0; j < 8; ++j) { 126 for (j = 0; j < 8; ++j) {
127 if (id_equal(entri[j]->client_id, closest[i].id)) 127 if (id_equal(entri[j]->public_key, closest[i].id))
128 ++good; 128 ++good;
129 } 129 }
130 } 130 }
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c
index acbc3acb..479eb330 100644
--- a/auto_tests/dht_test.c
+++ b/auto_tests/dht_test.c
@@ -54,25 +54,25 @@ void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6)
54 } 54 }
55} 55}
56 56
57/* Returns 1 if client_id has a furthest distance to comp_client_id 57/* Returns 1 if public_key has a furthest distance to comp_client_id
58 than all client_id's in the list */ 58 than all public_key's in the list */
59uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *client_id) 59uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *public_key)
60{ 60{
61 uint32_t i; 61 uint32_t i;
62 62
63 for (i = 0; i < length; ++i) 63 for (i = 0; i < length; ++i)
64 if (id_closest(comp_client_id, client_id, list[i].client_id) == 1) 64 if (id_closest(comp_client_id, public_key, list[i].public_key) == 1)
65 return 0; 65 return 0;
66 66
67 return 1; 67 return 1;
68} 68}
69 69
70int client_in_list(Client_data *list, uint32_t length, const uint8_t *client_id) 70int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key)
71{ 71{
72 int i; 72 int i;
73 73
74 for (i = 0; i < (int)length; ++i) 74 for (i = 0; i < (int)length; ++i)
75 if (id_equal(client_id, list[i].client_id)) 75 if (id_equal(public_key, list[i].public_key))
76 return i; 76 return i;
77 77
78 return -1; 78 return -1;
@@ -104,7 +104,7 @@ void test_addto_lists_update(DHT *dht,
104 // check ip_port update for existing id 104 // check ip_port update for existing id
105 test = rand() % length; 105 test = rand() % length;
106 test_ipp.port = rand() % TOX_PORT_DEFAULT; 106 test_ipp.port = rand() % TOX_PORT_DEFAULT;
107 id_copy(test_id, list[test].client_id); 107 id_copy(test_id, list[test].public_key);
108 108
109 used = addto_lists(dht, test_ipp, test_id); 109 used = addto_lists(dht, test_ipp, test_id);
110 ck_assert_msg(used >= 1, "Wrong number of added clients"); 110 ck_assert_msg(used >= 1, "Wrong number of added clients");
@@ -118,7 +118,7 @@ void test_addto_lists_update(DHT *dht,
118 test2 = rand() % (length / 2) + length / 2; 118 test2 = rand() % (length / 2) + length / 2;
119 119
120 ipport_copy(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port); 120 ipport_copy(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port);
121 id_copy(test_id, list[test2].client_id); 121 id_copy(test_id, list[test2].public_key);
122 122
123 if (ipv6) list[test2].assoc6.ip_port.port = -1; 123 if (ipv6) list[test2].assoc6.ip_port.port = -1;
124 else list[test2].assoc4.ip_port.port = -1; 124 else list[test2].assoc4.ip_port.port = -1;
@@ -134,7 +134,7 @@ void test_addto_lists_update(DHT *dht,
134 test2 = rand() % (length / 2) + length / 2; 134 test2 = rand() % (length / 2) + length / 2;
135 135
136 ipport_copy(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port); 136 ipport_copy(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port);
137 id_copy(test_id, list[test1].client_id); 137 id_copy(test_id, list[test1].public_key);
138 138
139 if (ipv6) list[test1].assoc6.ip_port.port = -1; 139 if (ipv6) list[test1].assoc6.ip_port.port = -1;
140 else list[test1].assoc4.ip_port.port = -1; 140 else list[test1].assoc4.ip_port.port = -1;
@@ -153,10 +153,10 @@ void test_addto_lists_bad(DHT *dht,
153{ 153{
154 // check "bad" clients replacement 154 // check "bad" clients replacement
155 int used, test1, test2, test3; 155 int used, test1, test2, test3;
156 uint8_t client_id[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE]; 156 uint8_t public_key[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
157 uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; 157 uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
158 158
159 randombytes(client_id, sizeof(client_id)); 159 randombytes(public_key, sizeof(public_key));
160 mark_all_good(list, length, ipv6); 160 mark_all_good(list, length, ipv6);
161 161
162 test1 = rand() % (length / 3); 162 test1 = rand() % (length / 3);
@@ -164,9 +164,9 @@ void test_addto_lists_bad(DHT *dht,
164 test3 = rand() % (length / 3) + 2 * length / 3; 164 test3 = rand() % (length / 3) + 2 * length / 3;
165 ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen"); 165 ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen");
166 166
167 id_copy((uint8_t *)&test_id1, list[test1].client_id); 167 id_copy((uint8_t *)&test_id1, list[test1].public_key);
168 id_copy((uint8_t *)&test_id2, list[test2].client_id); 168 id_copy((uint8_t *)&test_id2, list[test2].public_key);
169 id_copy((uint8_t *)&test_id3, list[test3].client_id); 169 id_copy((uint8_t *)&test_id3, list[test3].public_key);
170 170
171 // mark nodes as "bad" 171 // mark nodes as "bad"
172 if (ipv6) { 172 if (ipv6) {
@@ -180,10 +180,10 @@ void test_addto_lists_bad(DHT *dht,
180 } 180 }
181 181
182 ip_port->port += 1; 182 ip_port->port += 1;
183 used = addto_lists(dht, *ip_port, client_id); 183 used = addto_lists(dht, *ip_port, public_key);
184 ck_assert_msg(used >= 1, "Wrong number of added clients"); 184 ck_assert_msg(used >= 1, "Wrong number of added clients");
185 185
186 ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Client id is not in the list"); 186 ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Client id is not in the list");
187 ck_assert_msg(client_in_list(list, length, test_id2) >= 0, "Wrong bad client removed"); 187 ck_assert_msg(client_in_list(list, length, test_id2) >= 0, "Wrong bad client removed");
188 ck_assert_msg(client_in_list(list, length, test_id3) >= 0, "Wrong bad client removed"); 188 ck_assert_msg(client_in_list(list, length, test_id3) >= 0, "Wrong bad client removed");
189} 189}
@@ -196,10 +196,10 @@ void test_addto_lists_possible_bad(DHT *dht,
196{ 196{
197 // check "possibly bad" clients replacement 197 // check "possibly bad" clients replacement
198 int used, test1, test2, test3; 198 int used, test1, test2, test3;
199 uint8_t client_id[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE]; 199 uint8_t public_key[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
200 uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; 200 uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
201 201
202 randombytes(client_id, sizeof(client_id)); 202 randombytes(public_key, sizeof(public_key));
203 mark_all_good(list, length, ipv6); 203 mark_all_good(list, length, ipv6);
204 204
205 test1 = rand() % (length / 3); 205 test1 = rand() % (length / 3);
@@ -207,9 +207,9 @@ void test_addto_lists_possible_bad(DHT *dht,
207 test3 = rand() % (length / 3) + 2 * length / 3; 207 test3 = rand() % (length / 3) + 2 * length / 3;
208 ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen"); 208 ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen");
209 209
210 id_copy((uint8_t *)&test_id1, list[test1].client_id); 210 id_copy((uint8_t *)&test_id1, list[test1].public_key);
211 id_copy((uint8_t *)&test_id2, list[test2].client_id); 211 id_copy((uint8_t *)&test_id2, list[test2].public_key);
212 id_copy((uint8_t *)&test_id3, list[test3].client_id); 212 id_copy((uint8_t *)&test_id3, list[test3].public_key);
213 213
214 // mark nodes as "possibly bad" 214 // mark nodes as "possibly bad"
215 if (ipv6) { 215 if (ipv6) {
@@ -223,10 +223,10 @@ void test_addto_lists_possible_bad(DHT *dht,
223 } 223 }
224 224
225 ip_port->port += 1; 225 ip_port->port += 1;
226 used = addto_lists(dht, *ip_port, client_id); 226 used = addto_lists(dht, *ip_port, public_key);
227 ck_assert_msg(used >= 1, "Wrong number of added clients"); 227 ck_assert_msg(used >= 1, "Wrong number of added clients");
228 228
229 ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Client id is not in the list"); 229 ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Client id is not in the list");
230 230
231 int inlist_id1 = client_in_list(list, length, test_id1) >= 0; 231 int inlist_id1 = client_in_list(list, length, test_id1) >= 0;
232 int inlist_id2 = client_in_list(list, length, test_id2) >= 0; 232 int inlist_id2 = client_in_list(list, length, test_id2) >= 0;
@@ -258,28 +258,28 @@ void test_addto_lists_good(DHT *dht,
258 IP_Port *ip_port, 258 IP_Port *ip_port,
259 const uint8_t *comp_client_id) 259 const uint8_t *comp_client_id)
260{ 260{
261 uint8_t client_id[CLIENT_ID_SIZE]; 261 uint8_t public_key[CLIENT_ID_SIZE];
262 uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; 262 uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
263 263
264 mark_all_good(list, length, ipv6); 264 mark_all_good(list, length, ipv6);
265 265
266 // check "good" client id replacement 266 // check "good" client id replacement
267 do { 267 do {
268 randombytes(client_id, sizeof(client_id)); 268 randombytes(public_key, sizeof(public_key));
269 } while (is_furthest(comp_client_id, list, length, client_id)); 269 } while (is_furthest(comp_client_id, list, length, public_key));
270 270
271 ip_port->port += 1; 271 ip_port->port += 1;
272 addto_lists(dht, *ip_port, client_id); 272 addto_lists(dht, *ip_port, public_key);
273 ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Good client id is not in the list"); 273 ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Good client id is not in the list");
274 274
275 // check "good" client id skip 275 // check "good" client id skip
276 do { 276 do {
277 randombytes(client_id, sizeof(client_id)); 277 randombytes(public_key, sizeof(public_key));
278 } while (!is_furthest(comp_client_id, list, length, client_id)); 278 } while (!is_furthest(comp_client_id, list, length, public_key));
279 279
280 ip_port->port += 1; 280 ip_port->port += 1;
281 addto_lists(dht, *ip_port, client_id); 281 addto_lists(dht, *ip_port, public_key);
282 ck_assert_msg(client_in_list(list, length, client_id) == -1, "Good client id is in the list"); 282 ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list");
283} 283}
284 284
285void test_addto_lists(IP ip) 285void test_addto_lists(IP ip)
@@ -291,26 +291,26 @@ void test_addto_lists(IP ip)
291 ck_assert_msg(dht != 0, "Failed to create DHT"); 291 ck_assert_msg(dht != 0, "Failed to create DHT");
292 292
293 IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT }; 293 IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT };
294 uint8_t client_id[CLIENT_ID_SIZE]; 294 uint8_t public_key[CLIENT_ID_SIZE];
295 int i, used; 295 int i, used;
296 296
297 // check lists filling 297 // check lists filling
298 for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { 298 for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
299 randombytes(client_id, sizeof(client_id)); 299 randombytes(public_key, sizeof(public_key));
300 used = addto_lists(dht, ip_port, client_id); 300 used = addto_lists(dht, ip_port, public_key);
301 ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing ip_port"); 301 ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing ip_port");
302 } 302 }
303 303
304 for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { 304 for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
305 ip_port.port += 1; 305 ip_port.port += 1;
306 used = addto_lists(dht, ip_port, client_id); 306 used = addto_lists(dht, ip_port, public_key);
307 ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing client_id"); 307 ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing public_key");
308 } 308 }
309 309
310 for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { 310 for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
311 ip_port.port += 1; 311 ip_port.port += 1;
312 randombytes(client_id, sizeof(client_id)); 312 randombytes(public_key, sizeof(public_key));
313 used = addto_lists(dht, ip_port, client_id); 313 used = addto_lists(dht, ip_port, public_key);
314 ck_assert_msg(used >= 1, "Wrong number of added clients"); 314 ck_assert_msg(used >= 1, "Wrong number of added clients");
315 } 315 }
316 316
@@ -333,14 +333,14 @@ void test_addto_lists(IP ip)
333 333
334 for (i = 0; i < dht->num_friends; ++i) 334 for (i = 0; i < dht->num_friends; ++i)
335 test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, 335 test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port,
336 dht->friends_list[i].client_id); 336 dht->friends_list[i].public_key);
337 */ 337 */
338 // check "good" entries 338 // check "good" entries
339 test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); 339 test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key);
340 340
341 for (i = 0; i < dht->num_friends; ++i) 341 for (i = 0; i < dht->num_friends; ++i)
342 test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, 342 test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port,
343 dht->friends_list[i].client_id); 343 dht->friends_list[i].public_key);
344 344
345 kill_DHT(dht); 345 kill_DHT(dht);
346 kill_networking(net); 346 kill_networking(net);