Changeset 1942
- Timestamp:
- May 24, 2007, 8:09:32 PM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer.c
r1870 r1942 26 26 #include "peertree.h" 27 27 28 #define PERCENT_PEER_WANTED 25 /* Percent before we start relax peers min activeness */ 29 #define MIN_UPLOAD_IDLE 60000 /* In high peer situations we wait only 1 min 30 until dropping peers for idling */ 31 #define MAX_UPLOAD_IDLE 240000 /* In low peer situations we wait the 32 4 mins until dropping peers for idling */ 33 #define MIN_KEEP_ALIVE 180000 /* In high peer situations we wait only 3 min 34 without a keep-alive */ 35 #define MAX_KEEP_ALIVE 360000 /* In low peer situations we wait the 36 6 mins without a keep-alive */ 37 #define MIN_CON_TIMEOUT 8000 /* Time to timeout connecting to peer, 38 during low peer situations */ 39 #define MAX_CON_TIMEOUT 30000 /* Time to timeout connecting to peer, 40 during high peer situations */ 28 41 #define MAX_REQUEST_COUNT 32 29 42 #define OUR_REQUEST_COUNT 8 /* TODO: we should detect if we are on a -
trunk/libtransmission/peerutils.h
r1600 r1942 63 63 uint64_t now; 64 64 int ret; 65 int peersWanted; 66 int idleTime; 67 int sizeOfRange; 65 68 66 69 now = tr_date(); 67 68 if( peer->status < PEER_STATUS_CONNECTED && 69 now > peer->date + 8000 ) 70 { 71 /* If it has been too long, don't wait for the socket 72 to timeout - forget about it now */ 73 peer_dbg( "connection timeout" ); 74 return TR_ERROR; 75 } 76 77 /* Drop peers who haven't even sent a keep-alive within the 78 last 3 minutes */ 79 if( now > peer->date + 180000 ) 80 { 81 peer_dbg( "read timeout" ); 82 return TR_ERROR; 83 } 84 85 /* Drop peers which are supposed to upload but actually 86 haven't sent anything within the last minute */ 87 if( peer->inRequestCount && now > peer->date + 60000 ) 88 { 89 peer_dbg( "bad uploader" ); 90 return TR_ERROR; 91 } 70 idleTime = now - peer->date; 71 if ( idleTime > MIN_CON_TIMEOUT ) /* get rid of clients with timeout less than 8 seconds and saves on a check later */ 72 { 73 peersWanted = TR_MAX_PEER_COUNT * PERCENT_PEER_WANTED / 100; 74 if ( tor->peerCount > peersWanted ) 75 { 76 /* strict requirements for connecting timeout */ 77 if ( peer->status < PEER_STATUS_CONNECTED ) 78 { 79 peer_dbg( "connection timeout, idled %i seconds", (idleTime / 1000) ); 80 return TR_ERROR; 81 } 82 83 /* strict requirements for idle uploading timeout */ 84 if ( peer->inRequestCount && idleTime > MIN_UPLOAD_IDLE ) 85 { 86 peer_dbg( "idle uploader timeout, idled %i seconds", (idleTime / 1000) ); 87 return TR_ERROR; 88 } 89 90 /* strict requirements for keep-alive timeout */ 91 if ( idleTime > MIN_KEEP_ALIVE ) 92 { 93 peer_dbg( "peer timeout, idled %i seconds", (idleTime / 1000) ); 94 return TR_ERROR; 95 } 96 } 97 else /* if we are tight for peers be more relaxed on enforcing timeouts, 98 basic equation min + ((max-min) / sizeOfRange) * tor->peerCount */ 99 { 100 sizeOfRange = TR_MAX_PEER_COUNT - peersWanted; 101 102 /* relax requirements for connecting timeout */ 103 if ( peer->status < PEER_STATUS_CONNECTED && idleTime > MIN_CON_TIMEOUT 104 + (MAX_CON_TIMEOUT - MIN_CON_TIMEOUT) * tor->peerCount / sizeOfRange) 105 { 106 peer_dbg( "connection timeout, idled %i seconds", (idleTime / 1000) ); 107 return TR_ERROR; 108 } 109 110 /* relax requirements for idle uploading timeout */ 111 if ( peer->inRequestCount && idleTime > MIN_UPLOAD_IDLE 112 + (MAX_UPLOAD_IDLE - MIN_UPLOAD_IDLE) * tor->peerCount / sizeOfRange) 113 { 114 peer_dbg( "idle uploader timeout, idled %i seconds", (idleTime / 1000) ); 115 return TR_ERROR; 116 } 117 118 /* relax requirements for keep-alive timeout */ 119 if ( idleTime > MIN_KEEP_ALIVE + (MAX_KEEP_ALIVE - MIN_KEEP_ALIVE) * tor->peerCount / sizeOfRange) 120 { 121 peer_dbg( "peer timeout, idled %i seconds", (idleTime / 1000) ); 122 return TR_ERROR; 123 } 124 } 125 } 92 126 93 127 if( PEER_STATUS_CONNECTED == peer->status ) 94 128 { 95 /* Send keep-alive every 2 minutes */96 if( now > peer->keepAlive + 1 20000 )129 /* Send keep-alive every 1 minute and 45 seconds */ 130 if( now > peer->keepAlive + 105000 ) 97 131 { 98 132 sendKeepAlive( peer );
Note: See TracChangeset
for help on using the changeset viewer.