Changeset 2312
- Timestamp:
- Jul 9, 2007, 8:26:16 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer.c
r2311 r2312 861 861 const int queueTimeSec = 5; 862 862 const int blockSizeKiB = tor->blockSize / 1024; 863 int deadbeatCount = 0;863 const int isSeeding = tr_cpGetStatus( tor->completion ) != TR_CP_INCOMPLETE; 864 864 int i; 865 tr_peer_t ** deadbeats;866 865 867 866 tr_torrentWriterLock( tor ); … … 889 888 } 890 889 891 deadbeats = tr_new( tr_peer_t*, tor->peerCount ); 892 deadbeatCount = 0; 893 for( i=0; i<tor->peerCount; ++i ) { 894 tr_peer_t * peer = tor->peers[ i ]; 895 if( tr_peerIsConnected( peer ) && ( peer->credit < 0 ) ) 896 deadbeats[deadbeatCount++] = peer; 897 } 898 899 if( deadbeatCount ) 900 { 901 const double ul_KiBsec = tr_rcRate( tor->download ); 902 const double ul_KiB = ul_KiBsec * SWIFT_REFRESH_INTERVAL_SEC; 903 const double ul_bytes = ul_KiB * 1024; 904 const double freeCreditTotal = ul_bytes * SWIFT_LARGESSE; 905 const int freeCreditPerPeer = (int)( freeCreditTotal / deadbeatCount ); 906 for( i=0; i<deadbeatCount; ++i ) 907 deadbeats[i]->credit = freeCreditPerPeer; 908 tr_dbg( "torrent %s has %d deadbeats, " 909 "who are each being granted %d bytes' credit " 910 "for a total of %.1f KiB, " 911 "%d%% of the torrent's ul speed %.1f\n", 912 tor->info.name, deadbeatCount, freeCreditPerPeer, 913 ul_KiBsec*SWIFT_LARGESSE, (int)(SWIFT_LARGESSE*100), ul_KiBsec ); 914 } 915 916 tr_free( deadbeats ); 890 /* if we're not seeding, decide on how much 891 bandwidth to allocate for leechers */ 892 if( !isSeeding ) 893 { 894 tr_peer_t ** deadbeats = tr_new( tr_peer_t*, tor->peerCount ); 895 int deadbeatCount = 0; 896 897 for( i=0; i<tor->peerCount; ++i ) { 898 tr_peer_t * peer = tor->peers[ i ]; 899 if( tr_peerIsConnected( peer ) && ( peer->credit < 0 ) ) 900 deadbeats[deadbeatCount++] = peer; 901 } 902 903 if( deadbeatCount ) 904 { 905 const double ul_KiBsec = tr_rcRate( tor->download ); 906 const double ul_KiB = ul_KiBsec * SWIFT_REFRESH_INTERVAL_SEC; 907 const double ul_bytes = ul_KiB * 1024; 908 const double freeCreditTotal = ul_bytes * SWIFT_LARGESSE; 909 const int freeCreditPerPeer = (int)( freeCreditTotal / deadbeatCount ); 910 for( i=0; i<deadbeatCount; ++i ) 911 deadbeats[i]->credit = freeCreditPerPeer; 912 tr_dbg( "torrent %s has %d deadbeats, " 913 "who are each being granted %d bytes' credit " 914 "for a total of %.1f KiB, " 915 "%d%% of the torrent's ul speed %.1f\n", 916 tor->info.name, deadbeatCount, freeCreditPerPeer, 917 ul_KiBsec*SWIFT_LARGESSE, (int)(SWIFT_LARGESSE*100), ul_KiBsec ); 918 } 919 920 tr_free( deadbeats ); 921 } 917 922 918 923 tr_torrentWriterUnlock( tor );
Note: See TracChangeset
for help on using the changeset viewer.