diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-30 21:13:40 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-30 21:13:40 -0400 |
commit | a93980e1443972c3284db21e314e6a58bcdacdb0 (patch) | |
tree | 1b72f825316fe23952a6886627fe30fc17007548 /toxcore/DHT.c | |
parent | ecddafd3832d145f2d7bdb84bb83ba385ff3cff0 (diff) |
Cleaned up pull request.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 02e0ed08..50bddbd6 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -56,8 +56,16 @@ | |||
56 | #define NAT_PING_REQUEST 0 | 56 | #define NAT_PING_REQUEST 0 |
57 | #define NAT_PING_RESPONSE 1 | 57 | #define NAT_PING_RESPONSE 1 |
58 | 58 | ||
59 | /* Used in the comparison function for sorting lists of Client_data. */ | ||
60 | typedef struct { | ||
61 | Client_data c1; | ||
62 | Client_data c2; | ||
63 | } ClientPair; | ||
64 | |||
65 | /* Create the declaration for a quick sort for ClientPair structures. */ | ||
66 | declare_quick_sort(ClientPair); | ||
59 | /* Create the quicksort function. See misc_tools.h for the definition. */ | 67 | /* Create the quicksort function. See misc_tools.h for the definition. */ |
60 | make_quick_sort(ClientPair); | 68 | make_quick_sort(ClientPair); |
61 | 69 | ||
62 | Client_data *DHT_get_close_list(DHT *dht) | 70 | Client_data *DHT_get_close_list(DHT *dht) |
63 | { | 71 | { |
@@ -95,8 +103,10 @@ static int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2) | |||
95 | static int client_id_cmp(ClientPair p1, ClientPair p2) | 103 | static int client_id_cmp(ClientPair p1, ClientPair p2) |
96 | { | 104 | { |
97 | int c = id_closest(p1.c1.client_id, p1.c2.client_id, p2.c2.client_id); | 105 | int c = id_closest(p1.c1.client_id, p1.c2.client_id, p2.c2.client_id); |
106 | |||
98 | if (c == 2) | 107 | if (c == 2) |
99 | return -1; | 108 | return -1; |
109 | |||
100 | return c; | 110 | return c; |
101 | } | 111 | } |
102 | 112 | ||
@@ -292,7 +302,7 @@ static int replace_bad( Client_data *list, | |||
292 | return 1; | 302 | return 1; |
293 | } | 303 | } |
294 | 304 | ||
295 | /*Sort the list. It will be sorted from furthest to closest. | 305 | /*Sort the list. It will be sorted from furthest to closest. |
296 | * Turns list into data that quick sort can use and reverts it back. | 306 | * Turns list into data that quick sort can use and reverts it back. |
297 | */ | 307 | */ |
298 | static void sort_list(Client_data *list, uint32_t length, uint8_t *comp_client_id) | 308 | static void sort_list(Client_data *list, uint32_t length, uint8_t *comp_client_id) |
@@ -302,11 +312,14 @@ static void sort_list(Client_data *list, uint32_t length, uint8_t *comp_client_i | |||
302 | uint32_t i; | 312 | uint32_t i; |
303 | 313 | ||
304 | memcpy(cd.client_id, comp_client_id, CLIENT_ID_SIZE); | 314 | memcpy(cd.client_id, comp_client_id, CLIENT_ID_SIZE); |
315 | |||
305 | for (i = 0; i < length; ++i) { | 316 | for (i = 0; i < length; ++i) { |
306 | pairs[i].c1 = cd; | 317 | pairs[i].c1 = cd; |
307 | pairs[i].c2 = list[i]; | 318 | pairs[i].c2 = list[i]; |
308 | } | 319 | } |
320 | |||
309 | ClientPair_quick_sort(pairs, length, client_id_cmp); | 321 | ClientPair_quick_sort(pairs, length, client_id_cmp); |
322 | |||
310 | for (i = 0; i < length; ++i) | 323 | for (i = 0; i < length; ++i) |
311 | list[i] = pairs[i].c2; | 324 | list[i] = pairs[i].c2; |
312 | } | 325 | } |