Changeset 7419
- Timestamp:
- Dec 16, 2008, 10:08:17 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/Makefile.am
r7293 r7419 25 25 handshake.c \ 26 26 inout.c \ 27 iobuf.c \28 27 json.c \ 29 28 JSON_parser.c \ … … 71 70 handshake.h \ 72 71 inout.h \ 73 iobuf.h \74 72 json.h \ 75 73 JSON_parser.h \ -
trunk/libtransmission/bandwidth.c
r7404 r7419 19 19 #include "bandwidth.h" 20 20 #include "crypto.h" 21 #include " iobuf.h"21 #include "peer-io.h" 22 22 #include "ptrarray.h" 23 23 #include "utils.h" … … 100 100 tr_session * session; 101 101 tr_ptrArray * children; /* struct tr_bandwidth */ 102 tr_ptrArray * iobufs; /* struct tr_iobuf*/102 tr_ptrArray * peers; /* tr_peerIo */ 103 103 }; 104 104 … … 135 135 b->session = session; 136 136 b->children = tr_ptrArrayNew( ); 137 b-> iobufs = tr_ptrArrayNew( );137 b->peers = tr_ptrArrayNew( ); 138 138 b->magicNumber = MAGIC_NUMBER; 139 139 b->band[TR_UP].honorParentLimits = 1; … … 149 149 150 150 tr_bandwidthSetParent( b, NULL ); 151 tr_ptrArrayFree( b-> iobufs, NULL );151 tr_ptrArrayFree( b->peers, NULL ); 152 152 tr_ptrArrayFree( b->children, NULL ); 153 153 b->magicNumber = 0xDEAD; … … 250 250 tr_direction dir, 251 251 int period_msec, 252 tr_ptrArray * iobuf_pool )252 tr_ptrArray * peer_pool ) 253 253 { 254 254 assert( isBandwidth( b ) ); … … 271 271 { 272 272 int i; 273 const int n = tr_ptrArraySize( b-> iobufs );273 const int n = tr_ptrArraySize( b->peers ); 274 274 for( i=0; i<n; ++i ) 275 tr_ptrArrayAppend( iobuf_pool, tr_ptrArrayNth( b->iobufs, i ) );275 tr_ptrArrayAppend( peer_pool, tr_ptrArrayNth( b->peers, i ) ); 276 276 } 277 277 278 278 #ifdef DEBUG_DIRECTION 279 279 if( ( dir == DEBUG_DIRECTION ) && ( n > 1 ) ) 280 fprintf( stderr, "bandwidth %p has %d iobufs\n", b, n );280 fprintf( stderr, "bandwidth %p has %d peers\n", b, n ); 281 281 #endif 282 282 … … 286 286 struct tr_bandwidth ** children = (struct tr_bandwidth**) tr_ptrArrayPeek( b->children, &n ); 287 287 for( i=0; i<n; ++i ) 288 allocateBandwidth( children[i], dir, period_msec, iobuf_pool );288 allocateBandwidth( children[i], dir, period_msec, peer_pool ); 289 289 } 290 290 } … … 297 297 int n; 298 298 tr_ptrArray * tmp; 299 struct tr_ iobuf ** buffers;299 struct tr_peerIo ** peers; 300 300 const size_t chunkSize = 1024; /* arbitrary */ 301 301 302 302 tmp = tr_ptrArrayNew( ); 303 303 allocateBandwidth( b, dir, period_msec, tmp ); 304 buffers = (struct tr_iobuf**) tr_ptrArrayPeek( tmp, &n );304 peers = (struct tr_peerIo**) tr_ptrArrayPeek( tmp, &n ); 305 305 306 306 /* loop through all the peers, reading and writing in small chunks, 307 307 * until we run out of bandwidth or peers. we do it this way to 308 308 * prevent one peer from using up all the bandwidth */ 309 fprintf( stderr, "%s - %d peers\n", (dir==TR_UP)?"up":"down", n ); 309 310 while( n > 0 ) 310 311 { … … 312 313 for( i=0; i<n; ) 313 314 { 314 int byteCount;315 if( dir == TR_UP ) 316 byteCount = tr_iobuf_flush_output_buffer( buffers[i], chunkSize );317 else318 byteCount = tr_iobuf_tryread( buffers[i], chunkSize ); 315 const int byteCount = tr_peerIoFlush( peers[i], dir, chunkSize ); 316 317 if( byteCount ) 318 fprintf( stderr, "peer %p: %d bytes\n", peers[i], byteCount ); 319 319 320 if( byteCount == (int)chunkSize ) 320 321 ++i; 321 322 else 322 buffers[i] = buffers[--n];323 peers[i] = peers[--n]; 323 324 } 324 325 } … … 333 334 334 335 void 335 tr_bandwidthAdd Buffer( tr_bandwidth* b,336 struct tr_iobuf * iobuf)337 { 338 assert( isBandwidth( b ) ); 339 assert( iobuf);340 341 tr_ptrArrayInsertSorted( b-> iobufs, iobuf, comparePointers );342 } 343 344 void 345 tr_bandwidthRemove Buffer( tr_bandwidth* b,346 struct tr_iobuf * iobuf)347 { 348 assert( isBandwidth( b ) ); 349 assert( iobuf);350 351 tr_ptrArrayRemoveSorted( b-> iobufs, iobuf, comparePointers );336 tr_bandwidthAddPeer( tr_bandwidth * b, 337 tr_peerIo * peerIo ) 338 { 339 assert( isBandwidth( b ) ); 340 assert( peerIo ); 341 342 tr_ptrArrayInsertSorted( b->peers, peerIo, comparePointers ); 343 } 344 345 void 346 tr_bandwidthRemovePeer( tr_bandwidth * b, 347 tr_peerIo * peerIo ) 348 { 349 assert( isBandwidth( b ) ); 350 assert( peerIo ); 351 352 tr_ptrArrayRemoveSorted( b->peers, peerIo, comparePointers ); 352 353 } 353 354 -
trunk/libtransmission/bandwidth.h
r7404 r7419 59 59 * bandwidth they can safely use. 60 60 */ 61 61 62 typedef struct tr_bandwidth tr_bandwidth; 63 64 struct tr_peerIo; 62 65 63 66 /** … … 167 170 168 171 /** 169 * @brief add a n iobuf to this bandwidth's list of iobufs.172 * @brief add a tr_peerIo to this bandwidth's list. 170 173 * They will be notified when more bandwidth is made available for them to consume. 171 174 */ 172 void tr_bandwidthAdd Buffer( tr_bandwidth * bandwidth,173 struct tr_ iobuf * iobuf);175 void tr_bandwidthAddPeer ( tr_bandwidth * bandwidth, 176 struct tr_peerIo * peerIo ); 174 177 175 178 /** 176 179 * @brief remove an iobuf from this bandwidth's list of iobufs. 177 180 */ 178 void tr_bandwidthRemove Buffer( tr_bandwidth * bandwidth,179 struct tr_ iobuf * iobuf);181 void tr_bandwidthRemovePeer ( tr_bandwidth * bandwidth, 182 struct tr_peerIo * peerIo ); 180 183 181 184 #endif -
trunk/libtransmission/handshake.c
r7404 r7419 25 25 #include "crypto.h" 26 26 #include "handshake.h" 27 #include "iobuf.h"28 27 #include "peer-io.h" 29 28 #include "peer-mgr.h" … … 1005 1004 1006 1005 static ReadState 1007 canRead( struct tr_ iobuf * iobuf, void * arg, size_t * piece )1006 canRead( struct tr_peerIo * io, void * arg, size_t * piece ) 1008 1007 { 1009 1008 tr_handshake * handshake = arg; 1010 struct evbuffer * inbuf = tr_ iobuf_input( iobuf);1009 struct evbuffer * inbuf = tr_peerIoGetReadBuffer( io ); 1011 1010 ReadState ret; 1012 1011 tr_bool readyForMore = TRUE; … … 1115 1114 1116 1115 static void 1117 gotError( struct tr_iobuf * iobufUNUSED,1118 short 1119 void 1116 gotError( tr_peerIo * io UNUSED, 1117 short what, 1118 void * arg ) 1120 1119 { 1121 1120 tr_handshake * handshake = (tr_handshake *) arg; … … 1165 1164 handshake->doneUserData = doneUserData; 1166 1165 handshake->session = tr_peerIoGetSession( io ); 1167 tr_peerIoSetTimeoutSecs( io, 15 );1168 1166 1169 1167 tr_peerIoSetIOFuncs( handshake->io, canRead, NULL, gotError, handshake ); -
trunk/libtransmission/peer-io.c
r7404 r7419 28 28 #include "bandwidth.h" 29 29 #include "crypto.h" 30 #include "iobuf.h"31 30 #include "list.h" 32 31 #include "net.h" … … 80 79 struct tr_peerIo 81 80 { 82 tr_bool isEncrypted; 83 tr_bool isIncoming; 84 tr_bool peerIdIsSet; 85 tr_bool extendedProtocolSupported; 86 tr_bool fastExtensionSupported; 87 88 int magicNumber; 89 90 uint8_t encryptionMode; 91 uint8_t timeout; 92 tr_port port; 93 int socket; 94 95 uint8_t peerId[20]; 96 time_t timeCreated; 97 98 tr_session * session; 99 100 tr_address addr; 101 struct tr_iobuf * iobuf; 102 tr_list * output_datatypes; /* struct tr_datatype */ 103 104 tr_can_read_cb canRead; 105 tr_did_write_cb didWrite; 106 tr_net_error_cb gotError; 107 void * userData; 108 109 size_t bufferSize[2]; 110 111 tr_bandwidth * bandwidth; 112 tr_crypto * crypto; 81 tr_bool isEncrypted; 82 tr_bool isIncoming; 83 tr_bool peerIdIsSet; 84 tr_bool extendedProtocolSupported; 85 tr_bool fastExtensionSupported; 86 87 int magicNumber; 88 89 uint8_t encryptionMode; 90 uint8_t timeout; 91 tr_port port; 92 int socket; 93 94 uint8_t peerId[20]; 95 time_t timeCreated; 96 97 tr_session * session; 98 99 tr_address addr; 100 tr_list * output_datatypes; /* struct tr_datatype */ 101 102 tr_can_read_cb canRead; 103 tr_did_write_cb didWrite; 104 tr_net_error_cb gotError; 105 void * userData; 106 107 size_t bufferSize[2]; 108 109 tr_bandwidth * bandwidth; 110 tr_crypto * crypto; 111 112 struct evbuffer * inbuf; 113 struct evbuffer * outbuf; 113 114 }; 114 115 … … 118 119 119 120 static void 120 didWriteWrapper( struct tr_iobuf * iobuf,121 size_t 122 void 121 didWriteWrapper( void * unused UNUSED, 122 size_t bytes_transferred, 123 void * vio ) 123 124 { 124 125 tr_peerIo * io = vio; … … 143 144 tr_free( tr_list_pop_front( &io->output_datatypes ) ); 144 145 } 145 146 if( EVBUFFER_LENGTH( tr_iobuf_output( iobuf ) ) )147 tr_iobuf_enable( io->iobuf, EV_WRITE );148 146 } 149 147 150 148 static void 151 canReadWrapper( struct tr_iobuf * iobuf,152 size_t 153 void 149 canReadWrapper( void * unused UNUSED, 150 size_t bytes_transferred UNUSED, 151 void * vio ) 154 152 { 155 153 int done = 0; … … 168 166 { 169 167 size_t piece = 0; 170 const size_t oldLen = EVBUFFER_LENGTH( tr_iobuf_input( iobuf ));171 const int ret = io->canRead( io buf, io->userData, &piece );168 const size_t oldLen = EVBUFFER_LENGTH( io->inbuf ); 169 const int ret = io->canRead( io, io->userData, &piece ); 172 170 173 171 if( ret != READ_ERR ) 174 172 { 175 const size_t used = oldLen - EVBUFFER_LENGTH( tr_iobuf_input( iobuf ));173 const size_t used = oldLen - EVBUFFER_LENGTH( io->inbuf ); 176 174 if( piece ) 177 175 tr_bandwidthUsed( io->bandwidth, TR_DOWN, piece, TRUE ); … … 183 181 { 184 182 case READ_NOW: 185 if( EVBUFFER_LENGTH( tr_iobuf_input( iobuf )))183 if( EVBUFFER_LENGTH( io->inbuf ) ) 186 184 continue; 187 185 done = 1; … … 202 200 } 203 201 202 #if 0 204 203 static void 205 204 gotErrorWrapper( struct tr_iobuf * iobuf, … … 212 211 c->gotError( iobuf, what, c->userData ); 213 212 } 214 215 /** 216 *** 217 **/ 218 213 #endif 214 215 /** 216 *** 217 **/ 218 219 #if 0 219 220 static void 220 221 bufevNew( tr_peerIo * io ) … … 231 232 tr_iobuf_settimeout( io->iobuf, io->timeout, io->timeout ); 232 233 } 234 #endif 233 235 234 236 static int … … 267 269 io->timeout = IO_TIMEOUT_SECS; 268 270 io->timeCreated = time( NULL ); 271 io->inbuf = evbuffer_new( ); 272 io->outbuf = evbuffer_new( ); 273 #if 0 269 274 bufevNew( io ); 275 #endif 270 276 tr_peerIoSetBandwidth( io, session->bandwidth ); 271 277 return io; … … 310 316 311 317 tr_peerIoSetBandwidth( io, NULL ); 312 tr_iobuf_free( io->iobuf ); 318 evbuffer_free( io->outbuf ); 319 evbuffer_free( io->inbuf ); 313 320 tr_netClose( io->socket ); 314 321 tr_cryptoFree( io->crypto ); … … 371 378 } 372 379 380 #if 0 373 381 static void 374 382 tr_peerIoTryRead( tr_peerIo * io ) … … 377 385 (*canReadWrapper)( io->iobuf, ~0, io ); 378 386 } 387 #endif 379 388 380 389 void … … 390 399 io->userData = userData; 391 400 401 #if 0 392 402 tr_peerIoTryRead( io ); 393 } 394 395 int 403 #endif 404 } 405 406 tr_bool 396 407 tr_peerIoIsIncoming( const tr_peerIo * c ) 397 408 { 398 return c->isIncoming ? 1 :0;409 return c->isIncoming != 0; 399 410 } 400 411 … … 415 426 416 427 tr_netSetTOS( io->socket, io->session->peerSocketTOS ); 417 tr_iobuf_free( io->iobuf ); 428 #if 0 418 429 bufevNew( io ); 430 #endif 419 431 420 432 tr_peerIoSetBandwidth( io, bandwidth ); … … 425 437 } 426 438 439 #if 0 427 440 void 428 441 tr_peerIoSetTimeoutSecs( tr_peerIo * io, … … 433 446 tr_iobuf_enable( io->iobuf, EV_READ | EV_WRITE ); 434 447 } 448 #endif 435 449 436 450 /** … … 557 571 { 558 572 const size_t desiredLen = getDesiredOutputBufferSize( io ); 559 const size_t currentLen = EVBUFFER_LENGTH( tr_iobuf_output( io->iobuf ));573 const size_t currentLen = EVBUFFER_LENGTH( io->outbuf ); 560 574 size_t freeSpace = 0; 561 575 … … 573 587 574 588 if( io->bandwidth ) 575 tr_bandwidthRemove Buffer( io->bandwidth, io->iobuf);589 tr_bandwidthRemovePeer( io->bandwidth, io ); 576 590 577 591 io->bandwidth = bandwidth; 578 tr_iobuf_set_bandwidth( io->iobuf, bandwidth );579 592 580 593 if( io->bandwidth ) 581 tr_bandwidthAddBuffer( io->bandwidth, io->iobuf ); 582 583 tr_iobuf_enable( io->iobuf, EV_READ | EV_WRITE ); 594 tr_bandwidthAddPeer( io->bandwidth, io ); 584 595 } 585 596 … … 630 641 tr_list_append( &io->output_datatypes, datatype ); 631 642 632 evbuffer_add( tr_iobuf_output( io->iobuf ), writeme, writemeLen ); 633 tr_iobuf_enable( io->iobuf, EV_WRITE ); 643 evbuffer_add( io->outbuf, writeme, writemeLen ); 634 644 } 635 645 … … 777 787 return time( NULL ) - io->timeCreated; 778 788 } 789 790 /*** 791 **** 792 ***/ 793 794 static int 795 tr_peerIoTryRead( tr_peerIo * io, size_t howmuch ) 796 { 797 int res; 798 799 assert( isPeerIo( io ) ); 800 801 howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch ); 802 803 res = howmuch ? evbuffer_read( io->inbuf, io->socket, howmuch ) : 0; 804 805 dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(errno):"") ); 806 807 if( res > 0 ) 808 canReadWrapper( io, res, io ); 809 810 if( ( res <= 0 ) && ( io->gotError ) && ( errno != EAGAIN ) && ( errno != EINTR ) ) 811 { 812 short what = EVBUFFER_READ | EVBUFFER_ERROR; 813 if( res == 0 ) 814 what |= EVBUFFER_EOF; 815 io->gotError( io, what, io->userData ); 816 } 817 818 return res; 819 } 820 821 static int 822 tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch ) 823 { 824 int n; 825 826 assert( isPeerIo( io ) ); 827 828 howmuch = tr_bandwidthClamp( io->bandwidth, TR_UP, howmuch ); 829 howmuch = MIN( howmuch, EVBUFFER_LENGTH( io->outbuf ) ); 830 n = (int) howmuch; 831 832 #ifdef WIN32 833 n = send( io->socket, EVBUFFER_DATA( io->outbuf ), n, 0 ); 834 #else 835 n = write( io->socket, EVBUFFER_DATA( io->outbuf ), n ); 836 #endif 837 dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(errno):"") ); 838 839 if( n > 0 ) 840 { 841 evbuffer_drain( io->outbuf, n ); 842 843 didWriteWrapper( NULL, n, io ); 844 } 845 846 if( ( n < 0 ) && ( io->gotError ) && ( errno != EPIPE ) && ( errno != EAGAIN ) && ( errno != EINTR ) && ( errno != EINPROGRESS ) ) 847 { 848 short what = EVBUFFER_WRITE | EVBUFFER_ERROR; 849 io->gotError( io, what, io->userData ); 850 } 851 852 return n; 853 } 854 855 int 856 tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t limit ) 857 { 858 int ret; 859 860 assert( isPeerIo( io ) ); 861 assert( dir==TR_UP || dir==TR_DOWN ); 862 863 if( dir==TR_DOWN ) 864 ret = tr_peerIoTryRead( io, limit ); 865 else 866 ret = tr_peerIoTryWrite( io, limit ); 867 868 return ret; 869 } 870 871 struct evbuffer * 872 tr_peerIoGetReadBuffer( tr_peerIo * io ) 873 { 874 assert( isPeerIo( io ) ); 875 876 return io->inbuf; 877 } -
trunk/libtransmission/peer-io.h
r7404 r7419 81 81 int tr_peerIoReconnect( tr_peerIo * io ); 82 82 83 int tr_peerIoIsIncoming( const tr_peerIo * io ); 84 85 void tr_peerIoSetTimeoutSecs( tr_peerIo * io, 86 int secs ); 83 tr_bool tr_peerIoIsIncoming( const tr_peerIo * io ); 87 84 88 85 int tr_peerIoGetAge( const tr_peerIo * io ); … … 110 107 ReadState; 111 108 112 typedef ReadState ( *tr_can_read_cb )( struct tr_iobuf * iobuf,109 typedef ReadState ( *tr_can_read_cb )( tr_peerIo * io, 113 110 void * user_data, 114 111 size_t * setme_piece_byte_count ); … … 119 116 void * userData ); 120 117 121 typedef void ( *tr_net_error_cb )( struct tr_iobuf * ev,118 typedef void ( *tr_net_error_cb )( tr_peerIo * io, 122 119 short what, 123 120 void * userData ); … … 156 153 EncryptionMode; 157 154 158 void tr_peerIoSetEncryption( tr_peerIo * io, 159 int encryptionMode ); 160 161 int tr_peerIoIsEncrypted( const tr_peerIo * io ); 162 163 void tr_peerIoWriteBytes( tr_peerIo * io, 164 struct evbuffer * outbuf, 165 const void * bytes, 166 size_t byteCount ); 167 168 void tr_peerIoWriteUint8( tr_peerIo * io, 169 struct evbuffer * outbuf, 170 uint8_t writeme ); 171 172 void tr_peerIoWriteUint16( tr_peerIo * io, 173 struct evbuffer * outbuf, 174 uint16_t writeme ); 175 176 void tr_peerIoWriteUint32( tr_peerIo * io, 177 struct evbuffer * outbuf, 178 uint32_t writeme ); 179 180 void tr_peerIoReadBytes( tr_peerIo * io, 181 struct evbuffer * inbuf, 182 void * bytes, 183 size_t byteCount ); 184 185 void tr_peerIoReadUint8( tr_peerIo * io, 186 struct evbuffer * inbuf, 187 uint8_t * setme ); 188 189 void tr_peerIoReadUint16( tr_peerIo * io, 190 struct evbuffer * inbuf, 191 uint16_t * setme ); 192 193 void tr_peerIoReadUint32( tr_peerIo * io, 194 struct evbuffer * inbuf, 195 uint32_t * setme ); 196 197 void tr_peerIoDrain( tr_peerIo * io, 198 struct evbuffer * inbuf, 199 size_t byteCount ); 200 201 /** 202 *** 203 **/ 204 205 size_t tr_peerIoGetWriteBufferSpace( const tr_peerIo * io ); 206 207 void tr_peerIoSetBandwidth( tr_peerIo * io, 208 struct tr_bandwidth * bandwidth ); 209 210 void tr_peerIoBandwidthUsed( tr_peerIo * io, 211 tr_direction direction, 212 size_t byteCount, 213 int isPieceData ); 155 void tr_peerIoSetEncryption( tr_peerIo * io, 156 int encryptionMode ); 157 158 int tr_peerIoIsEncrypted( const tr_peerIo * io ); 159 160 void tr_peerIoWriteBytes( tr_peerIo * io, 161 struct evbuffer * outbuf, 162 const void * bytes, 163 size_t byteCount ); 164 165 void tr_peerIoWriteUint8( tr_peerIo * io, 166 struct evbuffer * outbuf, 167 uint8_t writeme ); 168 169 void tr_peerIoWriteUint16( tr_peerIo * io, 170 struct evbuffer * outbuf, 171 uint16_t writeme ); 172 173 void tr_peerIoWriteUint32( tr_peerIo * io, 174 struct evbuffer * outbuf, 175 uint32_t writeme ); 176 177 void tr_peerIoReadBytes( tr_peerIo * io, 178 struct evbuffer * inbuf, 179 void * bytes, 180 size_t byteCount ); 181 182 void tr_peerIoReadUint8( tr_peerIo * io, 183 struct evbuffer * inbuf, 184 uint8_t * setme ); 185 186 void tr_peerIoReadUint16( tr_peerIo * io, 187 struct evbuffer * inbuf, 188 uint16_t * setme ); 189 190 void tr_peerIoReadUint32( tr_peerIo * io, 191 struct evbuffer * inbuf, 192 uint32_t * setme ); 193 194 void tr_peerIoDrain( tr_peerIo * io, 195 struct evbuffer * inbuf, 196 size_t byteCount ); 197 198 /** 199 *** 200 **/ 201 202 size_t tr_peerIoGetWriteBufferSpace( const tr_peerIo * io ); 203 204 void tr_peerIoSetBandwidth( tr_peerIo * io, 205 struct tr_bandwidth * bandwidth ); 206 207 void tr_peerIoBandwidthUsed( tr_peerIo * io, 208 tr_direction direction, 209 size_t byteCount, 210 int isPieceData ); 211 212 /** 213 *** 214 **/ 215 216 int tr_peerIoFlush( tr_peerIo * io, 217 tr_direction dir, 218 size_t byteLimit ); 219 220 struct evbuffer * tr_peerIoGetReadBuffer( tr_peerIo * io ); 221 214 222 215 223 -
trunk/libtransmission/peer-msgs.c
r7404 r7419 25 25 #include "crypto.h" 26 26 #include "inout.h" 27 #include "iobuf.h"28 27 #ifdef WIN32 29 28 #include "net.h" /* for ECONN */ … … 875 874 struct request_list tmp = REQUEST_LIST_INIT; 876 875 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); 876 dbgmsg( msgs, "entering `expire old requests' block" ); 877 877 878 878 /* cancel requests that have been queued for too long */ … … 898 898 reqListClear( &tmp ); 899 899 } 900 901 dbgmsg( msgs, "leaving `expire old requests' block" ); 900 902 } 901 903 … … 1055 1057 /* if it's only in the queue and hasn't been sent yet, free it */ 1056 1058 if( reqListRemove( &msgs->clientWillAskFor, &req ) ) { 1057 dbgmsg( msgs, "cancelling %"PRIu32":%"PRIu32"->%"PRIu32 "\n", pieceIndex, offset, length );1059 dbgmsg( msgs, "cancelling %"PRIu32":%"PRIu32"->%"PRIu32, pieceIndex, offset, length ); 1058 1060 fireCancelledReq( msgs, &req ); 1059 1061 } … … 1061 1063 /* if it's already been sent, send a cancel message too */ 1062 1064 if( reqListRemove( &msgs->clientAskedFor, &req ) ) { 1063 dbgmsg( msgs, "cancelling %"PRIu32":%"PRIu32"->%"PRIu32 "\n", pieceIndex, offset, length );1065 dbgmsg( msgs, "cancelling %"PRIu32":%"PRIu32"->%"PRIu32, pieceIndex, offset, length ); 1064 1066 protocolSendCancel( msgs, &req ); 1065 1067 fireCancelledReq( msgs, &req ); … … 1722 1724 1723 1725 static ReadState 1724 canRead( struct tr_iobuf * iobuf, void * vmsgs, size_t * piece )1726 canRead( tr_peerIo * io, void * vmsgs, size_t * piece ) 1725 1727 { 1726 1728 ReadState ret; 1727 1729 tr_peermsgs * msgs = vmsgs; 1728 struct evbuffer * in = tr_ iobuf_input( iobuf);1730 struct evbuffer * in = tr_peerIoGetReadBuffer( io ); 1729 1731 const size_t inlen = EVBUFFER_LENGTH( in ); 1730 1732 … … 1768 1770 tr_peermsgs * msgs = vmsgs; 1769 1771 const double rateToClient = tr_peerGetPieceSpeed( msgs->peer, TR_PEER_TO_CLIENT ); 1770 const int estimatedBlocksInNext30Seconds = 1771 ( rateToClient * 30 * 1024 ) / msgs->torrent->blockSize; 1772 const int seconds = 10; 1773 const int estimatedBlocksInPeriod = ( rateToClient * seconds * 1024 ) / msgs->torrent->blockSize; 1774 1772 1775 msgs->minActiveRequests = 8; 1773 msgs->maxActiveRequests = msgs->minActiveRequests + estimatedBlocksInNext30Seconds; 1776 msgs->maxActiveRequests = msgs->minActiveRequests + estimatedBlocksInPeriod; 1777 1774 1778 if( msgs->reqq > 0 ) 1775 1779 msgs->maxActiveRequests = MIN( msgs->maxActiveRequests, msgs->reqq ); 1780 1776 1781 return TRUE; 1777 1782 } … … 1882 1887 tr_peerMsgsPulse( tr_peermsgs * msgs ) 1883 1888 { 1884 if( msgs != NULL)1889 if( msgs ) 1885 1890 peerPulse( msgs ); 1886 1891 } 1887 1892 1888 1893 static void 1889 gotError( struct tr_iobuf * iobufUNUSED,1890 short 1891 void 1894 gotError( tr_peerIo * io UNUSED, 1895 short what, 1896 void * vmsgs ) 1892 1897 { 1893 1898 if( what & EVBUFFER_TIMEOUT ) … … 2240 2245 tellPeerWhatWeHave( m ); 2241 2246 2242 tr_peerIoSetTimeoutSecs( m->peer->io, 150 ); /* timeout after N seconds of inactivity */2243 2247 tr_peerIoSetIOFuncs( m->peer->io, canRead, didWrite, gotError, m ); 2244 2248 ratePulse( m );
Note: See TracChangeset
for help on using the changeset viewer.