summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-26 16:59:39 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-26 16:59:39 +0100
commit6871825565d0ba24436dbd5b92cc09e02f93af6a (patch)
tree0fbd4f05de5997d74bbc4f65d55a611e650ee83f
parent5e86efde052760a53ca92ddd411db095fcf4a970 (diff)
First run of making variable names more readable
-rw-r--r--ot_accesslist.c30
-rw-r--r--ot_accesslist.h6
-rw-r--r--ot_config.c2
-rw-r--r--ot_fullscrape.c2
-rw-r--r--ot_vector.c10
-rw-r--r--ot_vector.h2
-rw-r--r--proxy.c2
-rw-r--r--scan_urlencoded_query.c2
-rw-r--r--scan_urlencoded_query.h2
-rw-r--r--tests/t_scan_urlencoded_query.c12
-rw-r--r--tests/t_vector.c16
-rw-r--r--trackerlogic.c6
12 files changed, 46 insertions, 46 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index d7e88ee..ef845d6 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -339,7 +339,7 @@ static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_
339 } 339 }
340 } else { 340 } else {
341 int exactmatch = 0; 341 int exactmatch = 0;
342 ot_hash *insert_point = binary_search(info_hash, (*adding_to)->list, (*adding_to)->size, sizeof(ot_hash), OT_HASH_COMPARE_SIZE, &exactmatch); 342 ot_hash *insert_point = vector_binary_search(info_hash, (*adding_to)->list, (*adding_to)->size, sizeof(ot_hash), OT_HASH_COMPARE_SIZE, &exactmatch);
343 343
344 /* Only if the info hash is not in the adding_to list, create a new head with that entry */ 344 /* Only if the info hash is not in the adding_to list, create a new head with that entry */
345 if (!exactmatch) { 345 if (!exactmatch) {
@@ -416,7 +416,7 @@ void accesslist_cleanup(void) {
416} 416}
417#endif 417#endif
418 418
419int address_in_net(const ot_ip6 address, const ot_net *net) { 419int accesslist_address_in_net(const ot_ip6 address, const ot_net *net) {
420 int bits = net->bits, checkbits = (0x7f00 >> (bits & 7)); 420 int bits = net->bits, checkbits = (0x7f00 >> (bits & 7));
421 int result = memcmp(address, &net->address, bits >> 3); 421 int result = memcmp(address, &net->address, bits >> 3);
422 if (!result && (bits & 7)) 422 if (!result && (bits & 7))
@@ -424,7 +424,7 @@ int address_in_net(const ot_ip6 address, const ot_net *net) {
424 return result == 0; 424 return result == 0;
425} 425}
426 426
427void *set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size) { 427void *accesslist_set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size) {
428 size_t i; 428 size_t i;
429 int exactmatch; 429 int exactmatch;
430 430
@@ -435,7 +435,7 @@ void *set_value_for_net(const ot_net *net, ot_vector *vector, const void *value,
435 /* Check each net in vector for overlap */ 435 /* Check each net in vector for overlap */
436 uint8_t *member = ((uint8_t *)vector->data); 436 uint8_t *member = ((uint8_t *)vector->data);
437 for (i = 0; i < vector->size; ++i) { 437 for (i = 0; i < vector->size; ++i) {
438 if (address_in_net(*(ot_ip6 *)member, net) || address_in_net(net->address, (ot_net *)member)) 438 if (accesslist_address_in_net(*(ot_ip6 *)member, net) || accesslist_address_in_net(net->address, (ot_net *)member))
439 return 0; 439 return 0;
440 member += member_size; 440 member += member_size;
441 } 441 }
@@ -451,16 +451,16 @@ void *set_value_for_net(const ot_net *net, ot_vector *vector, const void *value,
451 451
452/* Takes a vector filled with { ot_net net, uint8_t[x] value }; 452/* Takes a vector filled with { ot_net net, uint8_t[x] value };
453 Returns value associated with the net, or NULL if not found */ 453 Returns value associated with the net, or NULL if not found */
454void *get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size) { 454void *accesslist_get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size) {
455 int exactmatch; 455 int exactmatch;
456 /* This binary search will return a pointer to the first non-containing network... */ 456 /* This binary search will return a pointer to the first non-containing network... */
457 ot_net *net = binary_search(address, vector->data, vector->size, member_size, sizeof(ot_ip6), &exactmatch); 457 ot_net *net = vector_binary_search(address, vector->data, vector->size, member_size, sizeof(ot_ip6), &exactmatch);
458 if (!net) 458 if (!net)
459 return NULL; 459 return NULL;
460 /* ... so we'll need to move back one step unless we've exactly hit the first address in network */ 460 /* ... so we'll need to move back one step unless we've exactly hit the first address in network */
461 if (!exactmatch && ((void *)net > vector->data)) 461 if (!exactmatch && ((void *)net > vector->data))
462 --net; 462 --net;
463 if (!address_in_net(address, net)) 463 if (!accesslist_address_in_net(address, net))
464 return NULL; 464 return NULL;
465 return (void *)net; 465 return (void *)net;
466} 466}
@@ -472,7 +472,7 @@ static pthread_mutex_t g_lognets_list_mutex = PTHREAD_MUTEX_INITIALIZER;
472 472
473void loglist_add_network(const ot_net *net) { 473void loglist_add_network(const ot_net *net) {
474 pthread_mutex_lock(&g_lognets_list_mutex); 474 pthread_mutex_lock(&g_lognets_list_mutex);
475 set_value_for_net(net, &g_lognets_list, NULL, sizeof(ot_net)); 475 accesslist_set_value_for_net(net, &g_lognets_list, NULL, sizeof(ot_net));
476 pthread_mutex_unlock(&g_lognets_list_mutex); 476 pthread_mutex_unlock(&g_lognets_list_mutex);
477} 477}
478 478
@@ -487,7 +487,7 @@ void loglist_reset(void) {
487int loglist_check_address(const ot_ip6 address) { 487int loglist_check_address(const ot_ip6 address) {
488 int result; 488 int result;
489 pthread_mutex_lock(&g_lognets_list_mutex); 489 pthread_mutex_lock(&g_lognets_list_mutex);
490 result = (NULL != get_value_for_net(address, &g_lognets_list, sizeof(ot_net))); 490 result = (NULL != accesslist_get_value_for_net(address, &g_lognets_list, sizeof(ot_net)));
491 pthread_mutex_unlock(&g_lognets_list_mutex); 491 pthread_mutex_unlock(&g_lognets_list_mutex);
492 return result; 492 return result;
493} 493}
@@ -508,17 +508,17 @@ int proxylist_add_network(const ot_net *proxy, const ot_net *net) {
508 pthread_mutex_lock(&g_proxies_list_mutex); 508 pthread_mutex_lock(&g_proxies_list_mutex);
509 509
510 /* If we have a direct hit, use and extend the vector there */ 510 /* If we have a direct hit, use and extend the vector there */
511 map = binary_search(proxy, g_proxies_list.data, g_proxies_list.size, sizeof(ot_proxymap), sizeof(ot_net), &exactmatch); 511 map = vector_binary_search(proxy, g_proxies_list.data, g_proxies_list.size, sizeof(ot_proxymap), sizeof(ot_net), &exactmatch);
512 512
513 if (!map || !exactmatch) { 513 if (!map || !exactmatch) {
514 /* else see, if we've got overlapping networks 514 /* else see, if we've got overlapping networks
515 and get a new empty vector if not */ 515 and get a new empty vector if not */
516 ot_vector empty; 516 ot_vector empty;
517 memset(&empty, 0, sizeof(ot_vector)); 517 memset(&empty, 0, sizeof(ot_vector));
518 map = set_value_for_net(proxy, &g_proxies_list, &empty, sizeof(ot_proxymap)); 518 map = accesslist_set_value_for_net(proxy, &g_proxies_list, &empty, sizeof(ot_proxymap));
519 } 519 }
520 520
521 if (map && set_value_for_net(net, &map->networks, NULL, sizeof(ot_net))) 521 if (map && accesslist_set_value_for_net(net, &map->networks, NULL, sizeof(ot_net)))
522 result = 1; 522 result = 1;
523 523
524 pthread_mutex_unlock(&g_proxies_list_mutex); 524 pthread_mutex_unlock(&g_proxies_list_mutex);
@@ -531,8 +531,8 @@ int proxylist_check_proxy(const ot_ip6 proxy, const ot_ip6 address) {
531 531
532 pthread_mutex_lock(&g_proxies_list_mutex); 532 pthread_mutex_lock(&g_proxies_list_mutex);
533 533
534 if ((map = get_value_for_net(proxy, &g_proxies_list, sizeof(ot_proxymap)))) 534 if ((map = accesslist_get_value_for_net(proxy, &g_proxies_list, sizeof(ot_proxymap))))
535 if (!address || get_value_for_net(address, &map->networks, sizeof(ot_net))) 535 if (!address || accesslist_get_value_for_net(address, &map->networks, sizeof(ot_net)))
536 result = 1; 536 result = 1;
537 537
538 pthread_mutex_unlock(&g_proxies_list_mutex); 538 pthread_mutex_unlock(&g_proxies_list_mutex);
@@ -587,7 +587,7 @@ int accesslist_bless_net(ot_net *net, ot_permissions permissions) {
587int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions) { 587int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions) {
588 size_t i; 588 size_t i;
589 for (i = 0; i < g_admin_nets_count; ++i) 589 for (i = 0; i < g_admin_nets_count; ++i)
590 if (address_in_net(ip, g_admin_nets + i) && (g_admin_nets_permissions[i] & permissions)) 590 if (accesslist_address_in_net(ip, g_admin_nets + i) && (g_admin_nets_permissions[i] & permissions))
591 return 1; 591 return 1;
592 return 0; 592 return 0;
593} 593}
diff --git a/ot_accesslist.h b/ot_accesslist.h
index 9dfdd95..0a8bf4c 100644
--- a/ot_accesslist.h
+++ b/ot_accesslist.h
@@ -40,7 +40,7 @@ extern const char *g_accesslist_pipe_delete;
40#endif 40#endif
41 41
42/* Test if an address is subset of an ot_net, return value is considered a bool */ 42/* Test if an address is subset of an ot_net, return value is considered a bool */
43int address_in_net(const ot_ip6 address, const ot_net *net); 43int accesslist_address_in_net(const ot_ip6 address, const ot_net *net);
44 44
45/* Store a value into a vector of struct { ot_net net, uint8_t[x] value } member; 45/* Store a value into a vector of struct { ot_net net, uint8_t[x] value } member;
46 returns NULL 46 returns NULL
@@ -51,13 +51,13 @@ int address_in_net(const ot_ip6 address, const ot_net *net);
51 returns pointer to new member in vector for success 51 returns pointer to new member in vector for success
52 member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping 52 member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping
53*/ 53*/
54void *set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size); 54void *accesslist_set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size);
55 55
56/* Takes a vector filled with struct { ot_net net, uint8_t[x] value } member; 56/* Takes a vector filled with struct { ot_net net, uint8_t[x] value } member;
57 Returns pointer to _member_ associated with the net, or NULL if not found 57 Returns pointer to _member_ associated with the net, or NULL if not found
58 member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping 58 member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping
59*/ 59*/
60void *get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size); 60void *accesslist_get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size);
61 61
62#ifdef WANT_IP_FROM_PROXY 62#ifdef WANT_IP_FROM_PROXY
63int proxylist_add_network(const ot_net *proxy, const ot_net *net); 63int proxylist_add_network(const ot_net *proxy, const ot_net *net);
diff --git a/ot_config.c b/ot_config.c
index e9666f9..a5fc06e 100644
--- a/ot_config.c
+++ b/ot_config.c
@@ -264,7 +264,7 @@ static config_kind parse_config_key(char **p) {
264 return CONFIG_UNKNOWN; 264 return CONFIG_UNKNOWN;
265} 265}
266 266
267int parse_configfile(char *config_filename) { 267static int parse_configfile(char *config_filename) {
268 FILE *config_file_handle; 268 FILE *config_file_handle;
269 char inbuf[512]; 269 char inbuf[512];
270 ot_ip6 tmpip; 270 ot_ip6 tmpip;
diff --git a/ot_fullscrape.c b/ot_fullscrape.c
index eade79d..788e574 100644
--- a/ot_fullscrape.c
+++ b/ot_fullscrape.c
@@ -122,7 +122,7 @@ static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_torrent *torre
122 r += 8; 122 r += 8;
123 break; 123 break;
124 case TASK_FULLSCRAPE_TPB_URLENCODED: 124 case TASK_FULLSCRAPE_TPB_URLENCODED:
125 r += fmt_urlencoded(r, *hash, sizeof(ot_hash)); 125 r += urlencoded_format(r, *hash, sizeof(ot_hash));
126 r += sprintf(r, ":%zd:%zd\n", seed_count, peer_count - seed_count); 126 r += sprintf(r, ":%zd:%zd\n", seed_count, peer_count - seed_count);
127 break; 127 break;
128 case TASK_FULLSCRAPE_TRACKERSTATE: 128 case TASK_FULLSCRAPE_TRACKERSTATE:
diff --git a/ot_vector.c b/ot_vector.c
index 7f18246..924d468 100644
--- a/ot_vector.c
+++ b/ot_vector.c
@@ -19,7 +19,7 @@ static int vector_compare_peer4(const void *peer1, const void *peer2) { return m
19 no exact match is found. In that case it sets exactmatch 0 and gives 19 no exact match is found. In that case it sets exactmatch 0 and gives
20 calling functions the chance to insert data 20 calling functions the chance to insert data
21*/ 21*/
22void *binary_search(const void *const key, const void *base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch) { 22void *vector_binary_search(const void *const key, const void *base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch) {
23 size_t interval = member_count; 23 size_t interval = member_count;
24 24
25 while (interval) { 25 while (interval) {
@@ -50,13 +50,13 @@ static uint8_t vector_hash_peer(ot_peer const *peer, size_t compare_size, size_t
50 50
51/* This is the generic insert operation for our vector type. 51/* This is the generic insert operation for our vector type.
52 It tries to locate the object at "key" with size "member_size" by comparing its first "compare_size" bytes with 52 It tries to locate the object at "key" with size "member_size" by comparing its first "compare_size" bytes with
53 those of objects in vector. Our special "binary_search" function does that and either returns the match or a 53 those of objects in vector. Our special "vector_binary_search" function does that and either returns the match or a
54 pointer to where the object is to be inserted. vector_find_or_insert makes space for the object and copies it, 54 pointer to where the object is to be inserted. vector_find_or_insert makes space for the object and copies it,
55 if it wasn't found in vector. Caller needs to check the passed "exactmatch" variable to see, whether an insert 55 if it wasn't found in vector. Caller needs to check the passed "exactmatch" variable to see, whether an insert
56 took place. If resizing the vector failed, NULL is returned, else the pointer to the object in vector. 56 took place. If resizing the vector failed, NULL is returned, else the pointer to the object in vector.
57*/ 57*/
58void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch) { 58void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch) {
59 uint8_t *match = binary_search(key, vector->data, vector->size, member_size, compare_size, exactmatch); 59 uint8_t *match = vector_binary_search(key, vector->data, vector->size, member_size, compare_size, exactmatch);
60 60
61 if (*exactmatch) 61 if (*exactmatch)
62 return match; 62 return match;
@@ -89,7 +89,7 @@ ot_peer *vector_find_or_insert_peer(ot_vector *vector, ot_peer const *peer, size
89 /* If space is zero but size is set, we're dealing with a list of vector->size buckets */ 89 /* If space is zero but size is set, we're dealing with a list of vector->size buckets */
90 if (vector->space < vector->size) 90 if (vector->space < vector->size)
91 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size); 91 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size);
92 match = binary_search(peer, vector->data, vector->size, peer_size, compare_size, exactmatch); 92 match = vector_binary_search(peer, vector->data, vector->size, peer_size, compare_size, exactmatch);
93 93
94 if (*exactmatch) 94 if (*exactmatch)
95 return match; 95 return match;
@@ -137,7 +137,7 @@ int vector_remove_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size)
137 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size); 137 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size);
138 138
139 end = ((ot_peer *)vector->data) + peer_size * vector->size; 139 end = ((ot_peer *)vector->data) + peer_size * vector->size;
140 match = (ot_peer *)binary_search(peer, vector->data, vector->size, peer_size, compare_size, &exactmatch); 140 match = (ot_peer *)vector_binary_search(peer, vector->data, vector->size, peer_size, compare_size, &exactmatch);
141 if (!exactmatch) 141 if (!exactmatch)
142 return 0; 142 return 0;
143 143
diff --git a/ot_vector.h b/ot_vector.h
index fbc75f4..d553956 100644
--- a/ot_vector.h
+++ b/ot_vector.h
@@ -26,7 +26,7 @@ typedef struct {
26/* trackerlogic.h needs ot_vector, break circular dependency here */ 26/* trackerlogic.h needs ot_vector, break circular dependency here */
27#include "trackerlogic.h" 27#include "trackerlogic.h"
28 28
29void *binary_search(const void *const key, const void *base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch); 29void *vector_binary_search(const void *const key, const void *base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch);
30void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch); 30void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch);
31ot_peer *vector_find_or_insert_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size, int *exactmatch); 31ot_peer *vector_find_or_insert_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size, int *exactmatch);
32 32
diff --git a/proxy.c b/proxy.c
index 9486e75..0cac20c 100644
--- a/proxy.c
+++ b/proxy.c
@@ -149,7 +149,7 @@ size_t add_peer_to_torrent_proxy(ot_hash hash, ot_peer *peer, size_t peer_size)
149size_t remove_peer_from_torrent_proxy(ot_hash hash, ot_peer *peer, size_t peer_size) { 149size_t remove_peer_from_torrent_proxy(ot_hash hash, ot_peer *peer, size_t peer_size) {
150 int exactmatch; 150 int exactmatch;
151 ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash); 151 ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash);
152 ot_torrent *torrent = binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch); 152 ot_torrent *torrent = vector_binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch);
153 153
154 if (exactmatch) { 154 if (exactmatch) {
155 ot_peerlist *peer_list = peer_list = peer_size == OT_PEER_SIZE6 ? torrent->peer_list6 : torrent->peer_list4; 155 ot_peerlist *peer_list = peer_list = peer_size == OT_PEER_SIZE6 ? torrent->peer_list6 : torrent->peer_list4;
diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c
index 4825a4a..cfc8708 100644
--- a/scan_urlencoded_query.c
+++ b/scan_urlencoded_query.c
@@ -160,7 +160,7 @@ ssize_t scan_fixed_int(char *data, size_t len, int *tmp) {
160 return len; 160 return len;
161} 161}
162 162
163size_t fmt_urlencoded(char *dest, const uint8_t *src, size_t len) { 163size_t urlencoded_format(char *dest, const uint8_t *src, size_t len) {
164 static const char safe[] = "$/.=~-_"; 164 static const char safe[] = "$/.=~-_";
165 static const char hexdigit[] = "0123456789abcdef"; 165 static const char hexdigit[] = "0123456789abcdef";
166 size_t written = 0, i; 166 size_t written = 0, i;
diff --git a/scan_urlencoded_query.h b/scan_urlencoded_query.h
index f71752d..24e09fd 100644
--- a/scan_urlencoded_query.h
+++ b/scan_urlencoded_query.h
@@ -56,6 +56,6 @@ ssize_t scan_fixed_int(char *data, size_t len, int *number);
56 56
57/* The other direction: percent encode len bytes from src into dest and return 57/* The other direction: percent encode len bytes from src into dest and return
58 how many characters were written. dest needs room for three times len. */ 58 how many characters were written. dest needs room for three times len. */
59size_t fmt_urlencoded(char *dest, const uint8_t *src, size_t len); 59size_t urlencoded_format(char *dest, const uint8_t *src, size_t len);
60 60
61#endif 61#endif
diff --git a/tests/t_scan_urlencoded_query.c b/tests/t_scan_urlencoded_query.c
index f660ea3..cb6c982 100644
--- a/tests/t_scan_urlencoded_query.c
+++ b/tests/t_scan_urlencoded_query.c
@@ -265,7 +265,7 @@ static void case_fmt_passes_safe_bytes(void) {
265 size_t n; 265 size_t n;
266 266
267 test_case("alphanumerics and the safe punctuation pass through"); 267 test_case("alphanumerics and the safe punctuation pass through");
268 n = fmt_urlencoded(dest, src, 11); 268 n = urlencoded_format(dest, src, 11);
269 dest[n] = 0; 269 dest[n] = 0;
270 CHECK_INT(n, 11); 270 CHECK_INT(n, 11);
271 CHECK_STR(dest, "aZ09$-./=_~"); 271 CHECK_STR(dest, "aZ09$-./=_~");
@@ -277,7 +277,7 @@ static void case_fmt_escapes_the_rest(void) {
277 size_t n; 277 size_t n;
278 278
279 test_case("everything else becomes a percent escape"); 279 test_case("everything else becomes a percent escape");
280 n = fmt_urlencoded(dest, src, sizeof(src)); 280 n = urlencoded_format(dest, src, sizeof(src));
281 dest[n] = 0; 281 dest[n] = 0;
282 CHECK_INT(n, 18); 282 CHECK_INT(n, 18);
283 CHECK_STR(dest, "%20%25%26%2b%3a%3f"); 283 CHECK_STR(dest, "%20%25%26%2b%3a%3f");
@@ -289,7 +289,7 @@ static void case_fmt_hex_is_lower_case(void) {
289 size_t n; 289 size_t n;
290 290
291 test_case("escapes use lower case hex digits"); 291 test_case("escapes use lower case hex digits");
292 n = fmt_urlencoded(dest, src, sizeof(src)); 292 n = urlencoded_format(dest, src, sizeof(src));
293 dest[n] = 0; 293 dest[n] = 0;
294 CHECK_INT(n, 9); 294 CHECK_INT(n, 9);
295 CHECK_STR(dest, "%00%ab%ff"); 295 CHECK_STR(dest, "%00%ab%ff");
@@ -300,7 +300,7 @@ static void case_fmt_zero_length(void) {
300 300
301 test_case("a zero length input writes nothing"); 301 test_case("a zero length input writes nothing");
302 memset(dest, 0x5a, sizeof(dest)); 302 memset(dest, 0x5a, sizeof(dest));
303 CHECK_INT(fmt_urlencoded(dest, (const uint8_t *)"abc", 0), 0); 303 CHECK_INT(urlencoded_format(dest, (const uint8_t *)"abc", 0), 0);
304 CHECK_MEM(dest, "\x5a\x5a\x5a\x5a", 4); 304 CHECK_MEM(dest, "\x5a\x5a\x5a\x5a", 4);
305} 305}
306 306
@@ -312,7 +312,7 @@ static void case_fmt_worst_case_fits(void) {
312 test_case("a hash of entirely unsafe bytes needs three times its length"); 312 test_case("a hash of entirely unsafe bytes needs three times its length");
313 for (i = 0; i < sizeof(src); ++i) 313 for (i = 0; i < sizeof(src); ++i)
314 src[i] = 0xff; 314 src[i] = 0xff;
315 n = fmt_urlencoded(dest, src, sizeof(src)); 315 n = urlencoded_format(dest, src, sizeof(src));
316 dest[n] = 0; 316 dest[n] = 0;
317 CHECK_INT(n, 60); 317 CHECK_INT(n, 60);
318 for (i = 0; i < 20; ++i) 318 for (i = 0; i < 20; ++i)
@@ -338,7 +338,7 @@ static void case_fmt_decoder_disagrees_on_dollar(void) {
338 ssize_t got; 338 ssize_t got;
339 339
340 test_case("the encoder passes '$' but the decoder rejects it"); 340 test_case("the encoder passes '$' but the decoder rejects it");
341 n = fmt_urlencoded(dest, src, sizeof(src)); 341 n = urlencoded_format(dest, src, sizeof(src));
342 dest[n] = 0; 342 dest[n] = 0;
343 CHECK_STR(dest, "a$b"); 343 CHECK_STR(dest, "a$b");
344 344
diff --git a/tests/t_vector.c b/tests/t_vector.c
index a8186b2..541a6da 100644
--- a/tests/t_vector.c
+++ b/tests/t_vector.c
@@ -13,7 +13,7 @@
13#include "trackerlogic.h" 13#include "trackerlogic.h"
14#include "test.h" 14#include "test.h"
15 15
16/* binary_search returns the matching member when there is one, and otherwise 16/* vector_binary_search returns the matching member when there is one, and otherwise
17 the position at which the key would have to be inserted to keep the vector 17 the position at which the key would have to be inserted to keep the vector
18 sorted. exactmatch distinguishes the two. */ 18 sorted. exactmatch distinguishes the two. */
19 19
@@ -25,7 +25,7 @@ static void case_search_finds_member(void) {
25 void *found; 25 void *found;
26 26
27 test_case("an existing key is found"); 27 test_case("an existing key is found");
28 found = binary_search(key, sorted, 5, 4, 4, &exactmatch); 28 found = vector_binary_search(key, sorted, 5, 4, 4, &exactmatch);
29 CHECK(exactmatch != 0); 29 CHECK(exactmatch != 0);
30 CHECK_PTR(found, sorted[2]); 30 CHECK_PTR(found, sorted[2]);
31} 31}
@@ -36,9 +36,9 @@ static void case_search_finds_first_and_last(void) {
36 int exactmatch; 36 int exactmatch;
37 37
38 test_case("the first and last members are found"); 38 test_case("the first and last members are found");
39 CHECK_PTR(binary_search(first, sorted, 5, 4, 4, &exactmatch), sorted[0]); 39 CHECK_PTR(vector_binary_search(first, sorted, 5, 4, 4, &exactmatch), sorted[0]);
40 CHECK(exactmatch != 0); 40 CHECK(exactmatch != 0);
41 CHECK_PTR(binary_search(last, sorted, 5, 4, 4, &exactmatch), sorted[4]); 41 CHECK_PTR(vector_binary_search(last, sorted, 5, 4, 4, &exactmatch), sorted[4]);
42 CHECK(exactmatch != 0); 42 CHECK(exactmatch != 0);
43} 43}
44 44
@@ -49,11 +49,11 @@ static void case_search_insert_position(void) {
49 void *slot; 49 void *slot;
50 50
51 test_case("a missing key yields its insert position"); 51 test_case("a missing key yields its insert position");
52 slot = binary_search(middle, sorted, 5, 4, 4, &exactmatch); 52 slot = vector_binary_search(middle, sorted, 5, 4, 4, &exactmatch);
53 CHECK_INT(exactmatch, 0); 53 CHECK_INT(exactmatch, 0);
54 CHECK_PTR(slot, sorted[2]); 54 CHECK_PTR(slot, sorted[2]);
55 55
56 slot = binary_search(before, sorted, 5, 4, 4, &exactmatch); 56 slot = vector_binary_search(before, sorted, 5, 4, 4, &exactmatch);
57 CHECK_INT(exactmatch, 0); 57 CHECK_INT(exactmatch, 0);
58 CHECK_PTR(slot, sorted[0]); 58 CHECK_PTR(slot, sorted[0]);
59} 59}
@@ -64,7 +64,7 @@ static void case_search_past_the_end(void) {
64 void *slot; 64 void *slot;
65 65
66 test_case("a key above every member yields the position past the end"); 66 test_case("a key above every member yields the position past the end");
67 slot = binary_search(beyond, sorted, 5, 4, 4, &exactmatch); 67 slot = vector_binary_search(beyond, sorted, 5, 4, 4, &exactmatch);
68 CHECK_INT(exactmatch, 0); 68 CHECK_INT(exactmatch, 0);
69 CHECK_PTR(slot, sorted[5]); 69 CHECK_PTR(slot, sorted[5]);
70} 70}
@@ -74,7 +74,7 @@ static void case_search_empty(void) {
74 void *base = (void *)sorted; 74 void *base = (void *)sorted;
75 75
76 test_case("searching an empty vector reports no match at the base"); 76 test_case("searching an empty vector reports no match at the base");
77 CHECK_PTR(binary_search(sorted[0], base, 0, 4, 4, &exactmatch), base); 77 CHECK_PTR(vector_binary_search(sorted[0], base, 0, 4, 4, &exactmatch), base);
78 CHECK_INT(exactmatch, 0); 78 CHECK_INT(exactmatch, 0);
79} 79}
80 80
diff --git a/trackerlogic.c b/trackerlogic.c
index 74fea6d..9705bd6 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -381,7 +381,7 @@ size_t return_peers_for_torrent(struct ot_workstruct *ws, ot_torrent *torrent, s
381size_t return_udp_scrape_for_torrent(ot_hash const hash, char *reply) { 381size_t return_udp_scrape_for_torrent(ot_hash const hash, char *reply) {
382 int exactmatch, delta_torrentcount = 0; 382 int exactmatch, delta_torrentcount = 0;
383 ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash); 383 ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash);
384 ot_torrent *torrent = binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch); 384 ot_torrent *torrent = vector_binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch);
385 385
386 if (!exactmatch) { 386 if (!exactmatch) {
387 memset(reply, 0, 12); 387 memset(reply, 0, 12);
@@ -414,7 +414,7 @@ size_t return_tcp_scrape_for_torrent(ot_hash const *hash_list, size_t amount, ch
414 int delta_torrentcount = 0; 414 int delta_torrentcount = 0;
415 ot_hash const *hash = hash_list + i; 415 ot_hash const *hash = hash_list + i;
416 ot_vector *torrents_list = mutex_bucket_lock_by_hash(*hash); 416 ot_vector *torrents_list = mutex_bucket_lock_by_hash(*hash);
417 ot_torrent *torrent = binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch); 417 ot_torrent *torrent = vector_binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch);
418 418
419 if (exactmatch) { 419 if (exactmatch) {
420 if (clean_single_torrent(torrent)) { 420 if (clean_single_torrent(torrent)) {
@@ -443,7 +443,7 @@ static ot_peerlist dummy_list;
443size_t remove_peer_from_torrent(PROTO_FLAG proto, struct ot_workstruct *ws) { 443size_t remove_peer_from_torrent(PROTO_FLAG proto, struct ot_workstruct *ws) {
444 int exactmatch; 444 int exactmatch;
445 ot_vector *torrents_list = mutex_bucket_lock_by_hash(*ws->hash); 445 ot_vector *torrents_list = mutex_bucket_lock_by_hash(*ws->hash);
446 ot_torrent *torrent = binary_search(ws->hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch); 446 ot_torrent *torrent = vector_binary_search(ws->hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch);
447 ot_peerlist *peer_list = &dummy_list; 447 ot_peerlist *peer_list = &dummy_list;
448 size_t peer_size; /* initialized in next line */ 448 size_t peer_size; /* initialized in next line */
449 ot_peer const *peer_src = peer_from_peer6(&ws->peer, &peer_size); 449 ot_peer const *peer_src = peer_from_peer6(&ws->peer, &peer_size);