summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/trackerlogic.c b/trackerlogic.c
index e9b9b2e..7b3c5db 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -18,9 +18,7 @@
18// Helper functions for binary_find 18// Helper functions for binary_find
19// 19//
20int compare_hash( const void *hash1, const void *hash2 ) { return memcmp( hash1, hash2, sizeof( ot_hash )); } 20int compare_hash( const void *hash1, const void *hash2 ) { return memcmp( hash1, hash2, sizeof( ot_hash )); }
21int compare_ip_port( const void *peer1, const void *peer2 ) { 21int compare_ip_port( const void *peer1, const void *peer2 ) { return memcmp( peer1, peer2, 6 ); }
22if( ((ot_peer*)peer1)->ip != ((ot_peer*)peer2)->ip ) return ((ot_peer*)peer1)->ip - ((ot_peer*)peer2)->ip;
23return ((ot_peer*)peer1)->port_flags - ((ot_peer*)peer2)->port_flags; }
24 22
25static void *binary_search( const void *key, const void *base, 23static void *binary_search( const void *key, const void *base,
26 unsigned long member_count, const unsigned long member_size, 24 unsigned long member_count, const unsigned long member_size,
@@ -82,7 +80,7 @@ static int vector_remove_peer( ot_vector *vector, ot_peer *peer ) {
82 match = BINARY_FIND( peer, vector->data, vector->size, sizeof( ot_peer ), compare_ip_port, &exactmatch ); 80 match = BINARY_FIND( peer, vector->data, vector->size, sizeof( ot_peer ), compare_ip_port, &exactmatch );
83 81
84 if( !exactmatch ) return 0; 82 if( !exactmatch ) return 0;
85 exactmatch = match->port_flags & PEER_FLAG_SEEDING ? 2 : 1; 83 exactmatch = OT_FLAG( match ) & PEER_FLAG_SEEDING ? 2 : 1;
86 MEMMOVE( match, match + 1, ((ot_peer*)vector->data) + vector->size - match - 1 ); 84 MEMMOVE( match, match + 1, ((ot_peer*)vector->data) + vector->size - match - 1 );
87 vector->size--; 85 vector->size--;
88 return exactmatch; 86 return exactmatch;
@@ -164,7 +162,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
164 if( !exactmatch ) { 162 if( !exactmatch ) {
165 int i; 163 int i;
166 MEMMOVE( peer_dest, peer, sizeof( ot_peer ) ); 164 MEMMOVE( peer_dest, peer, sizeof( ot_peer ) );
167 if( peer->port_flags & PEER_FLAG_SEEDING ) 165 if( OT_FLAG(peer) & PEER_FLAG_SEEDING )
168 torrent->peer_list->seed_count[0]++; 166 torrent->peer_list->seed_count[0]++;
169 for( i=1; i<OT_POOLS_COUNT; ++i ) { 167 for( i=1; i<OT_POOLS_COUNT; ++i ) {
170 switch( vector_remove_peer( &torrent->peer_list->peers[i], peer ) ) { 168 switch( vector_remove_peer( &torrent->peer_list->peers[i], peer ) ) {
@@ -174,12 +172,12 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
174 } 172 }
175 } 173 }
176 } else { 174 } else {
177 if( (peer_dest->port_flags & PEER_FLAG_SEEDING ) && !(peer->port_flags & PEER_FLAG_SEEDING ) ) 175 if( (OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && !(OT_FLAG(peer) & PEER_FLAG_SEEDING ) )
178 torrent->peer_list->seed_count[0]--; 176 torrent->peer_list->seed_count[0]--;
179 if( !(peer_dest->port_flags & PEER_FLAG_SEEDING ) && (peer->port_flags & PEER_FLAG_SEEDING ) ) 177 if( !(OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && (OT_FLAG(peer) & PEER_FLAG_SEEDING ) )
180 torrent->peer_list->seed_count[0]++; 178 torrent->peer_list->seed_count[0]++;
181 } 179 }
182 if( peer->port_flags & PEER_FLAG_COMPLETED ) 180 if( OT_FLAG(peer) & PEER_FLAG_COMPLETED )
183 torrent->peer_list->downloaded++; 181 torrent->peer_list->downloaded++;
184 182
185 return torrent; 183 return torrent;