summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
authorerdgeist <>2007-01-27 16:35:56 +0000
committererdgeist <>2007-01-27 16:35:56 +0000
commit6603b51576a5e6c597c0588566c8b66b5a7d1afd (patch)
tree5bd6174f8d8f517bc1abbae9aae3d80295f59e7e /trackerlogic.c
parentc094695add94493ab46d535b6fca1801efa127c2 (diff)
Due to recent issues... assert() seed counts
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/trackerlogic.c b/trackerlogic.c
index 6b8dba5..dfff041 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -14,6 +14,7 @@
14#include <math.h> 14#include <math.h>
15#include <glob.h> 15#include <glob.h>
16 16
17#include <assert.h>
17#include <errno.h> 18#include <errno.h>
18#include "scan.h" 19#include "scan.h"
19#include "byte.h" 20#include "byte.h"
@@ -205,11 +206,17 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
205 memmove( peer_dest, peer, sizeof( ot_peer ) ); 206 memmove( peer_dest, peer, sizeof( ot_peer ) );
206 if( OT_FLAG(peer) & PEER_FLAG_SEEDING ) 207 if( OT_FLAG(peer) & PEER_FLAG_SEEDING )
207 torrent->peer_list->seed_count[0]++; 208 torrent->peer_list->seed_count[0]++;
209
210 assert( torrent->peer_list->seed_count[0] <= torrent->peer_list->peers[0].size );
211
208 for( i=1; i<OT_POOLS_COUNT; ++i ) { 212 for( i=1; i<OT_POOLS_COUNT; ++i ) {
209 switch( vector_remove_peer( &torrent->peer_list->peers[i], peer ) ) { 213 switch( vector_remove_peer( &torrent->peer_list->peers[i], peer ) ) {
210 case 0: continue; 214 case 0: continue;
211 case 2: torrent->peer_list->seed_count[i]--; 215 case 2: torrent->peer_list->seed_count[i]--;
212 case 1: default: return torrent; 216 case 1: default:
217 assert( torrent->peer_list->seed_count[i] > 0 );
218 assert( torrent->peer_list->seed_count[i] <= torrent->peer_list->peers[i].size );
219 return torrent;
213 } 220 }
214 } 221 }
215 } else { 222 } else {
@@ -217,6 +224,9 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
217 torrent->peer_list->seed_count[0]--; 224 torrent->peer_list->seed_count[0]--;
218 if( !(OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && (OT_FLAG(peer) & PEER_FLAG_SEEDING ) ) 225 if( !(OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && (OT_FLAG(peer) & PEER_FLAG_SEEDING ) )
219 torrent->peer_list->seed_count[0]++; 226 torrent->peer_list->seed_count[0]++;
227
228 assert( torrent->peer_list->seed_count[0] > 0 );
229 assert( torrent->peer_list->seed_count[0] <= torrent->peer_list->peers[0].size );
220 } 230 }
221 231
222 return torrent; 232 return torrent;
@@ -452,7 +462,10 @@ void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) {
452 switch( vector_remove_peer( &torrent->peer_list->peers[i], peer ) ) { 462 switch( vector_remove_peer( &torrent->peer_list->peers[i], peer ) ) {
453 case 0: continue; 463 case 0: continue;
454 case 2: torrent->peer_list->seed_count[i]--; 464 case 2: torrent->peer_list->seed_count[i]--;
455 case 1: default: return; 465 case 1: default:
466 assert( torrent->peer_list->seed_count[i] > 0 );
467 assert( torrent->peer_list->seed_count[i] <= torrent->peer_list->peers[i].size );
468 return;
456 } 469 }
457} 470}
458 471