diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2024-04-05 16:30:02 +0200 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2024-04-05 16:30:02 +0200 |
commit | 524d78d6c7552cd4c44be7cea1ccc7cdbb11b490 (patch) | |
tree | fb2de9f3255e9e3a05cf91438eeba7d5c4265251 | |
parent | 64e25b681c4668577fa54ead3215442ad707440d (diff) |
constify
-rw-r--r-- | ot_mutex.c | 6 | ||||
-rw-r--r-- | ot_mutex.h | 4 | ||||
-rw-r--r-- | trackerlogic.c | 14 | ||||
-rw-r--r-- | trackerlogic.h | 14 |
4 files changed, 19 insertions, 19 deletions
@@ -36,8 +36,8 @@ ot_vector *mutex_bucket_lock( int bucket ) { | |||
36 | return all_torrents + bucket; | 36 | return all_torrents + bucket; |
37 | } | 37 | } |
38 | 38 | ||
39 | ot_vector *mutex_bucket_lock_by_hash( ot_hash hash ) { | 39 | ot_vector *mutex_bucket_lock_by_hash( ot_hash const hash ) { |
40 | return mutex_bucket_lock( uint32_read_big( (char*)hash ) >> OT_BUCKET_COUNT_SHIFT ); | 40 | return mutex_bucket_lock( uint32_read_big( (const char*)hash ) >> OT_BUCKET_COUNT_SHIFT ); |
41 | } | 41 | } |
42 | 42 | ||
43 | void mutex_bucket_unlock( int bucket, int delta_torrentcount ) { | 43 | void mutex_bucket_unlock( int bucket, int delta_torrentcount ) { |
@@ -45,7 +45,7 @@ void mutex_bucket_unlock( int bucket, int delta_torrentcount ) { | |||
45 | g_torrent_count += delta_torrentcount; | 45 | g_torrent_count += delta_torrentcount; |
46 | } | 46 | } |
47 | 47 | ||
48 | void mutex_bucket_unlock_by_hash( ot_hash hash, int delta_torrentcount ) { | 48 | void mutex_bucket_unlock_by_hash( ot_hash const hash, int delta_torrentcount ) { |
49 | mutex_bucket_unlock( uint32_read_big( (char*)hash ) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount ); | 49 | mutex_bucket_unlock( uint32_read_big( (char*)hash ) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount ); |
50 | } | 50 | } |
51 | 51 | ||
@@ -12,10 +12,10 @@ void mutex_init( void ); | |||
12 | void mutex_deinit( void ); | 12 | void mutex_deinit( void ); |
13 | 13 | ||
14 | ot_vector *mutex_bucket_lock( int bucket ); | 14 | ot_vector *mutex_bucket_lock( int bucket ); |
15 | ot_vector *mutex_bucket_lock_by_hash( ot_hash hash ); | 15 | ot_vector *mutex_bucket_lock_by_hash( ot_hash const hash ); |
16 | 16 | ||
17 | void mutex_bucket_unlock( int bucket, int delta_torrentcount ); | 17 | void mutex_bucket_unlock( int bucket, int delta_torrentcount ); |
18 | void mutex_bucket_unlock_by_hash( ot_hash hash, int delta_torrentcount ); | 18 | void mutex_bucket_unlock_by_hash( ot_hash const hash, int delta_torrentcount ); |
19 | 19 | ||
20 | size_t mutex_get_torrent_count(void); | 20 | size_t mutex_get_torrent_count(void); |
21 | 21 | ||
diff --git a/trackerlogic.c b/trackerlogic.c index 9d564c1..81bee94 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -45,7 +45,7 @@ void free_peerlist( ot_peerlist *peer_list ) { | |||
45 | free( peer_list ); | 45 | free( peer_list ); |
46 | } | 46 | } |
47 | 47 | ||
48 | void add_torrent_from_saved_state( ot_hash hash, ot_time base, size_t down_count ) { | 48 | void add_torrent_from_saved_state( ot_hash const hash, ot_time base, size_t down_count ) { |
49 | int exactmatch; | 49 | int exactmatch; |
50 | ot_torrent *torrent; | 50 | ot_torrent *torrent; |
51 | ot_vector *torrents_list = mutex_bucket_lock_by_hash( hash ); | 51 | ot_vector *torrents_list = mutex_bucket_lock_by_hash( hash ); |
@@ -317,7 +317,7 @@ size_t return_peers_for_torrent( struct ot_workstruct * ws, ot_torrent *torrent, | |||
317 | } | 317 | } |
318 | 318 | ||
319 | /* Fetches scrape info for a specific torrent */ | 319 | /* Fetches scrape info for a specific torrent */ |
320 | size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply ) { | 320 | size_t return_udp_scrape_for_torrent( ot_hash const hash, char *reply ) { |
321 | int exactmatch, delta_torrentcount = 0; | 321 | int exactmatch, delta_torrentcount = 0; |
322 | ot_vector *torrents_list = mutex_bucket_lock_by_hash( hash ); | 322 | ot_vector *torrents_list = mutex_bucket_lock_by_hash( hash ); |
323 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); | 323 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); |
@@ -343,17 +343,17 @@ size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply ) { | |||
343 | } | 343 | } |
344 | 344 | ||
345 | /* Fetches scrape info for a specific torrent */ | 345 | /* Fetches scrape info for a specific torrent */ |
346 | size_t return_tcp_scrape_for_torrent( ot_hash *hash_list, int amount, char *reply ) { | 346 | size_t return_tcp_scrape_for_torrent( ot_hash const *hash_list, int amount, char *reply ) { |
347 | char *r = reply; | 347 | char *r = reply; |
348 | int exactmatch, i; | 348 | int exactmatch, i; |
349 | 349 | ||
350 | r += sprintf( r, "d5:filesd" ); | 350 | r += sprintf( r, "d5:filesd" ); |
351 | 351 | ||
352 | for( i=0; i<amount; ++i ) { | 352 | for( i=0; i<amount; ++i ) { |
353 | int delta_torrentcount = 0; | 353 | int delta_torrentcount = 0; |
354 | ot_hash *hash = hash_list + i; | 354 | ot_hash const *hash = hash_list + i; |
355 | ot_vector *torrents_list = mutex_bucket_lock_by_hash( *hash ); | 355 | ot_vector *torrents_list = mutex_bucket_lock_by_hash( *hash ); |
356 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); | 356 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); |
357 | 357 | ||
358 | if( exactmatch ) { | 358 | if( exactmatch ) { |
359 | if( clean_single_torrent( torrent ) ) { | 359 | if( clean_single_torrent( torrent ) ) { |
diff --git a/trackerlogic.h b/trackerlogic.h index 24ef097..4fb8bc7 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -82,7 +82,7 @@ typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA, FLAG_SELFPIPE } PROTO_FLAG; | |||
82 | #define OT_PEER_SIZE6 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE6)) | 82 | #define OT_PEER_SIZE6 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE6)) |
83 | #define OT_PEER_SIZE4 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE4)) | 83 | #define OT_PEER_SIZE4 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE4)) |
84 | 84 | ||
85 | typedef uint8_t ot_peer[1]; | 85 | typedef uint8_t ot_peer[1]; /* Generic pointer to a v6 or v4 peer */ |
86 | typedef uint8_t ot_peer6[OT_PEER_SIZE6]; | 86 | typedef uint8_t ot_peer6[OT_PEER_SIZE6]; |
87 | typedef uint8_t ot_peer4[OT_PEER_SIZE4]; | 87 | typedef uint8_t ot_peer4[OT_PEER_SIZE4]; |
88 | static const uint8_t PEER_FLAG_SEEDING = 0x80; | 88 | static const uint8_t PEER_FLAG_SEEDING = 0x80; |
@@ -96,11 +96,11 @@ ot_peer *peer_from_peer6(ot_peer6 *peer, size_t *peer_size); | |||
96 | size_t peer_size_from_peer6(ot_peer6 *peer); | 96 | size_t peer_size_from_peer6(ot_peer6 *peer); |
97 | 97 | ||
98 | /* New style */ | 98 | /* New style */ |
99 | #define OT_SETIP(peer,ip) memcpy((peer),(ip),OT_IP_SIZE6) | 99 | #define OT_SETIP(peer,ip) memcpy((uint8_t*)(peer),(ip),OT_IP_SIZE6) |
100 | #define OT_SETPORT(peer,port) memcpy(((uint8_t*)(peer))+(OT_IP_SIZE6),(port),2) | 100 | #define OT_SETPORT(peer,port) memcpy(((uint8_t*)(peer))+(OT_IP_SIZE6),(port),2) |
101 | #define OT_PEERFLAG(peer) (((uint8_t*)(peer))[(OT_IP_SIZE6)+2]) | 101 | #define OT_PEERFLAG(peer) (((uint8_t*)(peer))[(OT_IP_SIZE6)+2]) |
102 | #define OT_PEERFLAG_D(peer,peersize) (((uint8_t*)(peer))[(peersize)-2]) | 102 | #define OT_PEERFLAG_D(peer,peersize) (((uint8_t*)(peer))[(peersize)-2]) |
103 | #define OT_PEERTIME(peer,peersize) (((uint8_t*)(peer))[(peersize)-1]) | 103 | #define OT_PEERTIME(peer,peersize) (((uint8_t*)(peer))[(peersize)-1]) |
104 | 104 | ||
105 | #define PEERS_BENCODED6 "6:peers6" | 105 | #define PEERS_BENCODED6 "6:peers6" |
106 | #define PEERS_BENCODED4 "5:peers" | 106 | #define PEERS_BENCODED4 "5:peers" |
@@ -187,9 +187,9 @@ void exerr( char * message ); | |||
187 | otherwise it is released in return_peers_for_torrent */ | 187 | otherwise it is released in return_peers_for_torrent */ |
188 | size_t add_peer_to_torrent_and_return_peers( PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount ); | 188 | size_t add_peer_to_torrent_and_return_peers( PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount ); |
189 | size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws ); | 189 | size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws ); |
190 | size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); | 190 | size_t return_tcp_scrape_for_torrent( ot_hash const *hash_list, int amount, char *reply ); |
191 | size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply ); | 191 | size_t return_udp_scrape_for_torrent( ot_hash const hash, char *reply ); |
192 | void add_torrent_from_saved_state( ot_hash hash, ot_time base, size_t down_count ); | 192 | void add_torrent_from_saved_state( ot_hash const hash, ot_time base, size_t down_count ); |
193 | 193 | ||
194 | /* torrent iterator */ | 194 | /* torrent iterator */ |
195 | void iterate_all_torrents( int (*for_each)( ot_torrent* torrent, uintptr_t data ), uintptr_t data ); | 195 | void iterate_all_torrents( int (*for_each)( ot_torrent* torrent, uintptr_t data ), uintptr_t data ); |