master
Dirk Engling 7 months ago
parent 64e25b681c
commit 524d78d6c7

@ -36,8 +36,8 @@ ot_vector *mutex_bucket_lock( int bucket ) {
return all_torrents + bucket;
}
ot_vector *mutex_bucket_lock_by_hash( ot_hash hash ) {
return mutex_bucket_lock( uint32_read_big( (char*)hash ) >> OT_BUCKET_COUNT_SHIFT );
ot_vector *mutex_bucket_lock_by_hash( ot_hash const hash ) {
return mutex_bucket_lock( uint32_read_big( (const char*)hash ) >> OT_BUCKET_COUNT_SHIFT );
}
void mutex_bucket_unlock( int bucket, int delta_torrentcount ) {
@ -45,7 +45,7 @@ void mutex_bucket_unlock( int bucket, int delta_torrentcount ) {
g_torrent_count += delta_torrentcount;
}
void mutex_bucket_unlock_by_hash( ot_hash hash, int delta_torrentcount ) {
void mutex_bucket_unlock_by_hash( ot_hash const hash, int delta_torrentcount ) {
mutex_bucket_unlock( uint32_read_big( (char*)hash ) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount );
}

@ -12,10 +12,10 @@ void mutex_init( void );
void mutex_deinit( void );
ot_vector *mutex_bucket_lock( int bucket );
ot_vector *mutex_bucket_lock_by_hash( ot_hash hash );
ot_vector *mutex_bucket_lock_by_hash( ot_hash const hash );
void mutex_bucket_unlock( int bucket, int delta_torrentcount );
void mutex_bucket_unlock_by_hash( ot_hash hash, int delta_torrentcount );
void mutex_bucket_unlock_by_hash( ot_hash const hash, int delta_torrentcount );
size_t mutex_get_torrent_count(void);

@ -45,7 +45,7 @@ void free_peerlist( ot_peerlist *peer_list ) {
free( peer_list );
}
void add_torrent_from_saved_state( ot_hash hash, ot_time base, size_t down_count ) {
void add_torrent_from_saved_state( ot_hash const hash, ot_time base, size_t down_count ) {
int exactmatch;
ot_torrent *torrent;
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,
}
/* Fetches scrape info for a specific torrent */
size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply ) {
size_t return_udp_scrape_for_torrent( ot_hash const hash, char *reply ) {
int exactmatch, delta_torrentcount = 0;
ot_vector *torrents_list = mutex_bucket_lock_by_hash( hash );
ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch );
@ -343,7 +343,7 @@ size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply ) {
}
/* Fetches scrape info for a specific torrent */
size_t return_tcp_scrape_for_torrent( ot_hash *hash_list, int amount, char *reply ) {
size_t return_tcp_scrape_for_torrent( ot_hash const *hash_list, int amount, char *reply ) {
char *r = reply;
int exactmatch, i;
@ -351,7 +351,7 @@ size_t return_tcp_scrape_for_torrent( ot_hash *hash_list, int amount, char *repl
for( i=0; i<amount; ++i ) {
int delta_torrentcount = 0;
ot_hash *hash = hash_list + i;
ot_hash const *hash = hash_list + i;
ot_vector *torrents_list = mutex_bucket_lock_by_hash( *hash );
ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch );

@ -82,7 +82,7 @@ typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA, FLAG_SELFPIPE } PROTO_FLAG;
#define OT_PEER_SIZE6 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE6))
#define OT_PEER_SIZE4 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE4))
typedef uint8_t ot_peer[1];
typedef uint8_t ot_peer[1]; /* Generic pointer to a v6 or v4 peer */
typedef uint8_t ot_peer6[OT_PEER_SIZE6];
typedef uint8_t ot_peer4[OT_PEER_SIZE4];
static const uint8_t PEER_FLAG_SEEDING = 0x80;
@ -96,7 +96,7 @@ ot_peer *peer_from_peer6(ot_peer6 *peer, size_t *peer_size);
size_t peer_size_from_peer6(ot_peer6 *peer);
/* New style */
#define OT_SETIP(peer,ip) memcpy((peer),(ip),OT_IP_SIZE6)
#define OT_SETIP(peer,ip) memcpy((uint8_t*)(peer),(ip),OT_IP_SIZE6)
#define OT_SETPORT(peer,port) memcpy(((uint8_t*)(peer))+(OT_IP_SIZE6),(port),2)
#define OT_PEERFLAG(peer) (((uint8_t*)(peer))[(OT_IP_SIZE6)+2])
#define OT_PEERFLAG_D(peer,peersize) (((uint8_t*)(peer))[(peersize)-2])
@ -187,9 +187,9 @@ void exerr( char * message );
otherwise it is released in return_peers_for_torrent */
size_t add_peer_to_torrent_and_return_peers( PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount );
size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws );
size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply );
size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply );
void add_torrent_from_saved_state( ot_hash hash, ot_time base, size_t down_count );
size_t return_tcp_scrape_for_torrent( ot_hash const *hash_list, int amount, char *reply );
size_t return_udp_scrape_for_torrent( ot_hash const hash, char *reply );
void add_torrent_from_saved_state( ot_hash const hash, ot_time base, size_t down_count );
/* torrent iterator */
void iterate_all_torrents( int (*for_each)( ot_torrent* torrent, uintptr_t data ), uintptr_t data );

Loading…
Cancel
Save