Changeset 3061
- Timestamp:
- Sep 14, 2007, 4:09:52 AM (15 years ago)
- Location:
- branches/encryption/libtransmission
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/encryption/libtransmission/clients.c
r2713 r3061 45 45 } 46 46 47 char * tr_clientForId( uint8_t * id )47 char * tr_clientForId( const uint8_t * id ) 48 48 { 49 49 char * ret = NULL; -
branches/encryption/libtransmission/clients.h
r261 r3061 23 23 *****************************************************************************/ 24 24 25 char * tr_clientForId( uint8_t * );25 char * tr_clientForId( const uint8_t * ); -
branches/encryption/libtransmission/completion.c
r3058 r3061 135 135 } 136 136 137 int tr_cpPieceIsComplete( const tr_completion * cp, int piece ) 137 int 138 tr_cpPieceIsComplete( const tr_completion * cp, int piece ) 138 139 { 139 140 return cp->completeBlocks[piece] >= tr_torPieceCountBlocks(cp->tor,piece); -
branches/encryption/libtransmission/handshake.c
r3056 r3061 91 91 int crypto_select; 92 92 uint8_t myReq1[SHA_DIGEST_LENGTH]; 93 uint8_t peer_id[20]; 94 int have_peer_id; 93 95 handshakeDoneCB doneCB; 94 96 void * doneUserData; … … 636 638 uint8_t reserved[8]; 637 639 uint8_t hash[SHA_DIGEST_LENGTH]; 638 uint8_t peer_id[20];639 640 int bytesRead = 0; 640 641 … … 647 648 pstrlen = EVBUFFER_DATA(inbuf)[0]; 648 649 fprintf( stderr, "pstrlen 1 is %d [%c]\n", (int)pstrlen, pstrlen ); 650 fprintf( stderr, "the buf is [%c][%c][%c][%c]", 651 EVBUFFER_DATA(inbuf)[0], 652 EVBUFFER_DATA(inbuf)[1], 653 EVBUFFER_DATA(inbuf)[2], 654 EVBUFFER_DATA(inbuf)[3] ); 649 655 isEncrypted = pstrlen != 19; 650 656 tr_peerIoSetEncryption( handshake->io, isEncrypted … … 692 698 693 699 /* peer id */ 694 tr_peerIoReadBytes( handshake->io, inbuf, peer_id, sizeof(peer_id) ); 695 // fprintf( stderr, "peer_id: " ); 696 // for( i=0; i<20; ++i ) fprintf( stderr, "[%c]", peer_id[i] ); 697 // fprintf( stderr, "\n" ); 698 tr_peerIoSetPeersId( handshake->io, peer_id ); 699 bytesRead += sizeof(peer_id); 700 tr_peerIoReadBytes( handshake->io, inbuf, handshake->peer_id, sizeof(handshake->peer_id) ); 701 tr_peerIoSetPeersId( handshake->io, handshake->peer_id ); 702 bytesRead += sizeof(handshake->peer_id); 703 handshake->have_peer_id = TRUE; 700 704 701 705 assert( bytesRead == HANDSHAKE_SIZE ); … … 775 779 776 780 static void 777 didWrite( struct bufferevent * evin UNUSED, void * arg )778 {779 tr_handshake * handshake = (tr_handshake *) arg;780 fprintf( stderr, "handshake %p, with a state of %s, got a didWrite event\n", handshake, getStateName(handshake->state) );781 #if 0782 abort ( );783 784 if( handshake->state == SENDING_LTEP_HANDHAKE )785 {786 fireDoneCB( handshake, TRUE );787 }788 else789 {790 cccccccccccccccccccccccccccccccccc791 int state = -1;792 switch( handshake->state )793 {794 //case SENDING_YA: state = AWAITING_YB; break;795 //case SENDING_YB: state = AWAITING_PAD_A; break;796 //case SENDING_CRYPTO_PROVIDE: state = AWAITING_VC; break;797 //case SENDING_PLAINTEXT_HANDSHAKE: state = AWAITING_HANDSHAKE; break;798 }799 assert( state != -1 );800 setState( handshake, state );801 tr_peerIoReadOrWait( handshake->io );802 }803 #endif804 }805 806 static void807 781 tr_handshakeFree( tr_handshake * handshake ) 808 782 { … … 813 787 fireDoneCB( tr_handshake * handshake, int isConnected ) 814 788 { 789 const uint8_t * peer_id = isConnected && handshake->have_peer_id 790 ? handshake->peer_id 791 : NULL; 815 792 fprintf( stderr, "handshake %p: firing done. connected==%d\n", handshake, isConnected ); 816 (*handshake->doneCB)(handshake, handshake->io, isConnected, handshake->doneUserData);793 (*handshake->doneCB)(handshake, handshake->io, isConnected, peer_id, handshake->doneUserData); 817 794 tr_handshakeFree( handshake ); 818 795 } … … 867 844 868 845 tr_peerIoSetIOMode( io, EV_READ|EV_WRITE, 0 ); 869 tr_peerIoSetIOFuncs( io, canRead, didWrite, gotError, handshake );846 tr_peerIoSetIOFuncs( io, canRead, NULL, gotError, handshake ); 870 847 871 848 fprintf( stderr, "handshake %p: new handshake for io %p\n", handshake, io ); … … 877 854 else 878 855 { 879 //handshake->encryptionPreference = HANDSHAKE_PLAINTEXT_PREFERRED; /* this line is just for testing */880 856 sendHandshake( handshake ); 881 857 } -
branches/encryption/libtransmission/handshake.h
r3049 r3061 28 28 struct tr_peerIo * io, 29 29 int isConnected, 30 const uint8_t * peerId, 30 31 void * userData ); 31 32 -
branches/encryption/libtransmission/peer-io.c
r3049 r3061 80 80 switch( ret ) { 81 81 case READ_AGAIN: if( EVBUFFER_LENGTH( e->input ) ) continue; /* note fall-through */ 82 case READ_MORE: //fprintf( stderr, "waiting for bytes from peer...\n" ); 83 tr_peerIoSetIOMode( c, EV_READ, 0 ); return; break; 84 case READ_DONE: return; fprintf( stderr, "READ_DONE\n"); break; 82 case READ_MORE: tr_peerIoSetIOMode( c, EV_READ, 0 ); return; break; 83 case READ_DONE: return; 85 84 } 86 85 } … … 110 109 tr_peerIo * c; 111 110 c = tr_new0( tr_peerIo, 1 ); 112 //fprintf( stderr, "peer-io: created %p; count is now %d\n", c, ++total_io );113 111 c->crypto = tr_cryptoNew( torrentHash, isIncoming ); 114 112 c->handle = handle; … … 118 116 c->rateToClient = tr_rcInit( ); 119 117 c->isIncoming = isIncoming ? 1 : 0; 120 fprintf( stderr, "io %p rates: peer %p client %p\n", c, c->rateToPeer, c->rateToClient );121 118 c->bufev = bufferevent_new( c->socket, 122 119 canReadWrapper, … … 180 177 181 178 tr_free( c ); 182 183 //fprintf( stderr, "peer-io: freeing %p; count is now %d\n", c, --total_io );184 179 } 185 180 } … … 238 233 assert( !tr_peerIoIsIncoming( io ) ); 239 234 240 fprintf( stderr, "tr_peerIoReconnect: io %p\n", io );241 242 235 if( io->socket >= 0 ) 243 236 tr_netClose( io->socket ); 244 237 245 238 io->socket = tr_netOpenTCP( &io->in_addr, io->port, 0 ); 246 247 fprintf( stderr, "tr_peerIoReconnect: io->socket is %d\n", io->socket );248 239 249 240 if( io->socket >= 0 ) … … 401 392 { 402 393 case PEER_ENCRYPTION_PLAINTEXT: 403 fprintf( stderr, "writing %d plaintext bytes to outbuf...\n", byteCount );394 /*fprintf( stderr, "writing %d plaintext bytes to outbuf...\n", byteCount );*/ 404 395 evbuffer_add( outbuf, bytes, byteCount ); 405 396 break; 406 397 407 398 case PEER_ENCRYPTION_RC4: 408 fprintf( stderr, "encrypting and writing %d bytes to outbuf...\n", byteCount );399 /*fprintf( stderr, "encrypting and writing %d bytes to outbuf...\n", byteCount );*/ 409 400 tmp = tr_new( uint8_t, byteCount ); 410 401 tr_cryptoEncrypt( io->crypto, byteCount, bytes, tmp ); … … 447 438 { 448 439 case PEER_ENCRYPTION_PLAINTEXT: 449 fprintf( stderr, "reading %d plaintext bytes from inbuf...\n", byteCount );440 /*fprintf( stderr, "reading %d plaintext bytes from inbuf...\n", byteCount );*/ 450 441 evbuffer_remove( inbuf, bytes, byteCount ); 451 442 tr_rcTransferred( io->rateToClient, byteCount ); … … 453 444 454 445 case PEER_ENCRYPTION_RC4: 455 fprintf( stderr, "reading AND DECRYPTING %d bytes from inbuf...\n", byteCount );446 /*fprintf( stderr, "reading AND DECRYPTING %d bytes from inbuf...\n", byteCount );*/ 456 447 evbuffer_remove( inbuf, bytes, byteCount ); 457 448 tr_cryptoDecrypt( io->crypto, byteCount, bytes, bytes ); -
branches/encryption/libtransmission/peer-mgr.c
r3057 r3061 17 17 18 18 #include "transmission.h" 19 #include "clients.h" 20 #include "completion.h" 19 21 #include "handshake.h" 20 #include "completion.h"21 22 #include "net.h" 22 23 #include "peer-io.h" … … 28 29 #include "utils.h" 29 30 30 #define MINUTES_TO_MSEC(N) ((N) * 60 * 1000)31 32 31 /* how frequently to change which peers are choked */ 33 #define RECHOKE_PERIOD_SECONDS ( MINUTES_TO_MSEC(10))32 #define RECHOKE_PERIOD_SECONDS (15 * 1000) 34 33 35 34 /* how many downloaders to unchoke per-torrent. 36 35 * http://wiki.theory.org/BitTorrentSpecification#Choking_and_Optimistic_Unchoking */ 37 #define NUM_DOWNLOADERS_TO_UNCHOKE 4 38 39 /* across all torrents, how many peers maximum do we want connected? */ 40 #define MAX_CONNECTED_PEERS 80 36 #define NUM_DOWNLOADERS_TO_UNCHOKE 6 41 37 42 38 /** … … 403 399 { 404 400 const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, begin, length ); 405 if( val == TR_ADDREQ_FULL) {406 fprintf( stderr, "peer % d of %d is full\n", (int)j, size );401 if( val==TR_ADDREQ_FULL || val==TR_ADDREQ_CLIENT_CHOKED ) { 402 fprintf( stderr, "peer %p (of %d) is full\n", peers[j]->msgs, size ); 407 403 peers[j] = peers[--size]; 408 404 } 409 405 else if( val == TR_ADDREQ_MISSING ) { 410 fprintf( stderr, "peer doesn't have it\n" );411 406 ++j; 412 407 } 413 408 else if( val == TR_ADDREQ_OK ) { 414 fprintf( stderr, "peer % d took the request for block %d\n", j, i);409 fprintf( stderr, "peer %p took the request for block %d\n", peers[j]->msgs, b ); 415 410 incrementReqCount( &t->blocks[i] ); 416 411 j = size; … … 441 436 442 437 static void 438 broadcastHave( Torrent * t, uint32_t index ) 439 { 440 int i, size; 441 tr_peer ** peers = getConnectedPeers( t, &size ); 442 for( i=0; i<size; ++i ) 443 tr_peerMsgsHave( peers[i]->msgs, index ); 444 tr_free( peers ); 445 } 446 447 static void 448 broadcastGotBlock( Torrent * t, uint32_t index, uint32_t offset, uint32_t length ) 449 { 450 int i, size; 451 tr_peer ** peers = getConnectedPeers( t, &size ); 452 for( i=0; i<size; ++i ) 453 tr_peerMsgsCancel( peers[i]->msgs, index, offset, length ); 454 tr_free( peers ); 455 } 456 457 static void 443 458 msgsCallbackFunc( void * source UNUSED, void * vevent, void * vt ) 444 459 { … … 449 464 { 450 465 case TR_PEERMSG_GOT_BITFIELD: { 451 const uint32_t begin = 0; 452 const uint32_t end = begin + t->tor->info.pieceCount; 453 uint32_t i; 454 for( i=begin; t->blocks!=NULL && i<end; ++i ) { 455 if( !tr_bitfieldHas( e->bitfield, i ) ) 456 continue; 457 assert( t->blocks[i].block == i ); 458 incrementScarcity( &t->blocks[i] ); 466 if( t->blocks!=NULL ) { 467 int i; 468 for( i=0; i<t->tor->info.pieceCount; ++i ) { 469 const uint32_t begin = tr_torPieceFirstBlock( t->tor, i ); 470 const uint32_t end = begin + tr_torPieceCountBlocks( t->tor, i ); 471 uint32_t j; 472 for( j=begin; t->blocks!=NULL && j<end; ++j ) { 473 assert( t->blocks[j].block == j ); 474 incrementScarcity( &t->blocks[j] ); 475 } 476 } 459 477 } 460 478 break; … … 469 487 incrementScarcity( &t->blocks[i] ); 470 488 } 489 broadcastHave( t, e->pieceIndex ); 471 490 break; 472 491 } 473 492 474 493 case TR_PEERMSG_GOT_BLOCK: { 475 uint32_t i = e->blockIndex;476 494 if( t->blocks != NULL ) { 495 const uint32_t i = _tr_block( t->tor, e->pieceIndex, e->offset ); 477 496 assert( t->blocks[i].block == i ); 478 497 t->blocks[i].have = 1; 479 498 } 499 broadcastGotBlock( t, e->pieceIndex, e->offset, e->length ); 480 500 break; 481 501 } … … 499 519 500 520 static void 501 myHandshakeDoneCB( tr_handshake * handshake, tr_peerIo * io, int isConnected, void * vmanager ) 521 myHandshakeDoneCB( tr_handshake * handshake, 522 tr_peerIo * io, 523 int isConnected, 524 const uint8_t * peer_id, 525 void * vmanager ) 502 526 { 503 527 int ok = isConnected; … … 559 583 peer->io = io; 560 584 peer->msgs = tr_peerMsgsNew( t->tor, peer ); 585 peer->client = peer_id ? tr_clientForId( peer_id ) : NULL; 561 586 fprintf( stderr, "PUB sub peer %p to msgs %p\n", peer, peer->msgs ); 562 587 peer->msgsTag = tr_peerMsgsSubscribe( peer->msgs, msgsCallbackFunc, t ); 563 chokePulse( t );564 588 } 565 589 } … … 643 667 const uint8_t * walk = peerCompact; 644 668 Torrent * t = getExistingTorrent( manager, torrentHash ); 645 for( i=0; i<peerCount; ++i )669 for( i=0; t!=NULL && i<peerCount; ++i ) 646 670 { 647 671 tr_peer * peer; … … 662 686 663 687 int 664 tr_peerMgrIsAcceptingConnections( const tr_peerMgr * manager )665 { 666 return manager->connectionCount < MAX_CONNECTED_PEERS;688 tr_peerMgrIsAcceptingConnections( const tr_peerMgr * manager UNUSED ) 689 { 690 return TRUE; /* manager->connectionCount < MAX_CONNECTED_PEERS; */ 667 691 } 668 692 … … 954 978 ChokeData * data; 955 979 tr_peer ** peers = getConnectedPeers( t, &size ); 956 957 fprintf( stderr, "rechoking torrent %p, with %d peers\n", t, size ); 980 const time_t now = time( NULL ); 981 982 fprintf( stderr, "[%s] rechoking torrent %p, with %d peers\n", ctime(&now), t, size ); 958 983 959 984 if( size < 1 ) -
branches/encryption/libtransmission/peer-msgs.c
r3049 r3061 44 44 #define PEX_INTERVAL (MINUTES_TO_MSEC(1)) 45 45 46 #define PEER_PULSE_INTERVAL_MSEC 50 47 46 48 /* the most requests we'll batch up for this peer */ 47 #define OUT_REQUESTS_MAX 649 #define OUT_REQUESTS_MAX 5 48 50 49 51 /* when we get down to this many requests, we ask the manager for more */ 50 #define OUT_REQUESTS_LOW 252 #define OUT_REQUESTS_LOW 3 51 53 52 54 enum … … 132 134 **/ 133 135 134 static const tr_peermsgs_event blankEvent = { 0, 0, 0, NULL };136 static const tr_peermsgs_event blankEvent = { 0, 0, 0, 0, NULL }; 135 137 136 138 static void … … 167 169 168 170 static void 169 fireGotBlock( tr_peermsgs * peer, uint32_t blockIndex)171 fireGotBlock( tr_peermsgs * peer, uint32_t pieceIndex, uint32_t offset, uint32_t length ) 170 172 { 171 173 tr_peermsgs_event e = blankEvent; 172 174 e.eventType = TR_PEERMSG_GOT_BLOCK; 173 e.pieceIndex = blockIndex; 175 e.pieceIndex = pieceIndex; 176 e.offset = offset; 177 e.length = length; 174 178 tr_publisherPublish( peer->publisher, peer, &e ); 175 179 } … … 263 267 } 264 268 265 fprintf( stderr, "peer %p: enqueuing a %s message\n", peer, (choke ? "choke" : "unchoke") );269 fprintf( stderr, "peer %p: sending a %s message\n", peer, (choke ? "CHOKE" : "UNCHOKE") ); 266 270 tr_peerIoWriteUint32( peer->io, peer->outMessages, len ); 267 271 tr_peerIoWriteBytes( peer->io, peer->outMessages, &bt_msgid, 1 ); 268 272 } 273 } 274 275 /** 276 *** 277 **/ 278 279 void 280 tr_peerMsgsCancel( tr_peermsgs * msgs, 281 uint32_t pieceIndex, 282 uint32_t offset, 283 uint32_t length ) 284 { 285 tr_list * node; 286 struct peer_request tmp; 287 288 assert( msgs != NULL ); 289 assert( length > 0 ); 290 291 tmp.index = pieceIndex; 292 tmp.offset = offset; 293 tmp.length = length; 294 295 node = tr_list_find( msgs->clientAskedFor, &tmp, peer_request_compare ); 296 if( node != NULL ) 297 { 298 /* cancel the request */ 299 const uint8_t bt_msgid = BT_CANCEL; 300 const uint32_t len = sizeof(uint8_t) + 3 * sizeof(uint32_t); 301 fprintf( stderr, "w00t peer %p: cancelling req for piece %u, offset %u\n", msgs, (unsigned)pieceIndex, (unsigned)offset ); 302 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, len ); 303 tr_peerIoWriteBytes( msgs->io, msgs->outMessages, &bt_msgid, 1 ); 304 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, pieceIndex ); 305 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, offset ); 306 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, length ); 307 308 /* remove it from our "requested" list */ 309 tr_list_remove_data( &msgs->peerAskedFor, node->data ); 310 } 311 } 312 313 /** 314 *** 315 **/ 316 317 void 318 tr_peerMsgsHave( tr_peermsgs * msgs, 319 uint32_t pieceIndex ) 320 { 321 const uint8_t bt_msgid = BT_HAVE; 322 const uint32_t len = sizeof(uint8_t) + sizeof(uint32_t); 323 fprintf( stderr, "peer %p: telling them we HAVE piece #%d\n", msgs, pieceIndex ); 324 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, len ); 325 tr_peerIoWriteBytes( msgs->io, msgs->outMessages, &bt_msgid, 1 ); 326 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, pieceIndex ); 269 327 } 270 328 … … 283 341 struct peer_request * req; 284 342 285 if( tr_list_size(peer->clientAskedFor) >= OUT_REQUESTS_MAX)286 return TR_ADDREQ_ FULL;343 if( peer->info->clientIsChoked ) 344 return TR_ADDREQ_CLIENT_CHOKED; 287 345 288 346 if( !tr_bitfieldHas( peer->info->have, index ) ) 289 347 return TR_ADDREQ_MISSING; 348 349 if( tr_list_size( peer->clientAskedFor) >= OUT_REQUESTS_MAX ) 350 return TR_ADDREQ_FULL; 290 351 291 352 /* queue the request */ … … 295 356 tr_peerIoWriteUint32( peer->io, peer->outMessages, offset ); 296 357 tr_peerIoWriteUint32( peer->io, peer->outMessages, length ); 297 fprintf( stderr, " peer %p: requesting a block from piece %u, offset %u, length %u\n",358 fprintf( stderr, "w00t peer %p: requesting a block from piece %u, offset %u, length %u\n", 298 359 peer, (unsigned int)index, (unsigned int)offset, (unsigned int)length ); 299 360 … … 303 364 req->offset = offset; 304 365 req->length = length; 305 tr_list_ prepend( &peer->clientAskedFor, req );306 fprintf( stderr, " added a request; peer %p's clientAskedFor.size() is now %d\n", peer, tr_list_size(peer->clientAskedFor));366 tr_list_append( &peer->clientAskedFor, req ); 367 fprintf( stderr, "w00t added a request; peer %p's clientAskedFor.size() is now %d\n", peer, tr_list_size(peer->clientAskedFor)); 307 368 308 369 return TR_ADDREQ_OK; … … 497 558 tr_bitfieldAdd( peer->info->have, ui32 ); 498 559 peer->info->progress = tr_bitfieldCountTrueBits( peer->info->have ) / (float)peer->torrent->info.pieceCount; 560 fprintf( stderr, "after the HAVE message, peer progress is %f\n", peer->info->progress ); 561 updateInterest( peer ); 499 562 fireGotHave( peer, ui32 ); 500 updateInterest( peer );501 563 break; 502 564 … … 506 568 tr_peerIoReadBytes( peer->io, inbuf, peer->info->have->bits, msglen ); 507 569 peer->info->progress = tr_bitfieldCountTrueBits( peer->info->have ) / (float)peer->torrent->info.pieceCount; 508 fprintf( stderr, " peer progress is %f\n", peer->info->progress );570 fprintf( stderr, "after the BITFIELD peer progress is %f\n", peer->info->progress ); 509 571 fireGotBitfield( peer, peer->info->have ); 510 572 updateInterest( peer ); … … 579 641 580 642 static int 581 canDownload( const tr_peermsgs * peer ) 582 { 643 canDownload( const tr_peermsgs * peer UNUSED ) 644 { 645 #if 0 583 646 tr_torrent * tor = peer->torrent; 584 585 #if 0586 /* FIXME: was swift worth it? did anyone notice a difference? */587 if( SWIFT_ENABLED && !isSeeding && (peer->credit<0) )588 return FALSE;589 #endif590 647 591 648 if( tor->downloadLimitMode == TR_SPEEDLIMIT_GLOBAL ) … … 594 651 if( tor->downloadLimitMode == TR_SPEEDLIMIT_SINGLE ) 595 652 return tr_rcCanTransfer( tor->download ); 653 #endif 596 654 597 655 return TRUE; … … 632 690 } 633 691 634 { 635 uint64_t block = index; 636 block *= tor->info.pieceSize; 637 block += offset; 638 block /= tor->blockSize; 639 fireGotBlock( peer, (uint32_t)block ); 640 } 692 fireGotBlock( peer, index, offset, length ); 641 693 642 694 /* write to disk */ … … 682 734 if( !peer->blockToUs.length ) 683 735 { 684 fprintf( stderr, "w00t \n");736 fprintf( stderr, "w00t -- index %u, offset %u\n", peer->blockToUs.index, peer->blockToUs.offset ); 685 737 gotBlock( peer, peer->blockToUs.index, 686 738 peer->blockToUs.offset, … … 730 782 731 783 static int 732 pulse( void * v peer)733 { 734 tr_peermsgs * peer = (tr_peermsgs *) vpeer;784 pulse( void * vmsgs ) 785 { 786 tr_peermsgs * msgs = (tr_peermsgs *) vmsgs; 735 787 size_t len; 736 788 737 789 /* if we froze out a downloaded block because of speed limits, 738 790 start listening to the peer again */ 739 if( peer->notListening ) 740 { 741 fprintf( stderr, "peer %p thawing out...\n", peer ); 742 peer->notListening = 0; 743 tr_peerIoSetIOMode ( peer->io, EV_READ, 0 ); 744 } 745 746 if(( len = EVBUFFER_LENGTH( peer->outBlock ) )) 747 { 748 if( canUpload( peer ) ) 791 if( msgs->notListening ) 792 { 793 fprintf( stderr, "msgs %p thawing out...\n", msgs ); 794 msgs->notListening = 0; 795 tr_peerIoSetIOMode ( msgs->io, EV_READ, 0 ); 796 } 797 798 /* if we're running low on requests, ask for ones */ 799 if( tr_list_size(msgs->clientAskedFor) <= OUT_REQUESTS_LOW ) 800 fireBlocksRunningLow( msgs ); 801 802 if(( len = EVBUFFER_LENGTH( msgs->outBlock ) )) 803 { 804 while ( len && canUpload( msgs ) ) 749 805 { 750 const size_t outlen = MIN( len, 4096 ); 751 tr_peerIoWrite( peer->io, EVBUFFER_DATA(peer->outBlock), outlen ); 752 evbuffer_drain( peer->outBlock, outlen ); 753 754 peer->torrent->uploadedCur += outlen; 755 tr_rcTransferred( peer->torrent->upload, outlen ); 756 tr_rcTransferred( peer->handle->upload, outlen ); 806 const size_t outlen = MIN( len, 1024 ); 807 tr_peerIoWrite( msgs->io, EVBUFFER_DATA(msgs->outBlock), outlen ); 808 evbuffer_drain( msgs->outBlock, outlen ); 809 810 msgs->torrent->uploadedCur += outlen; 811 tr_rcTransferred( msgs->torrent->upload, outlen ); 812 tr_rcTransferred( msgs->handle->upload, outlen ); 813 814 len -= outlen; 757 815 } 758 816 } 759 else if(( len = EVBUFFER_LENGTH( peer->outMessages ) )) 760 { 761 fprintf( stderr, "peer %p pulse is writing %d bytes worth of messages...\n", peer, (int)len ); 762 tr_peerIoWriteBuf( peer->io, peer->outMessages ); 763 evbuffer_drain( peer->outMessages, ~0 ); 764 } 765 else if(( peer->peerAskedFor )) 766 { 767 struct peer_request * req = (struct peer_request*) peer->peerAskedFor->data; 817 else if(( len = EVBUFFER_LENGTH( msgs->outMessages ) )) 818 { 819 tr_peerIoWriteBuf( msgs->io, msgs->outMessages ); 820 evbuffer_drain( msgs->outMessages, ~0 ); 821 } 822 else if(( msgs->peerAskedFor )) 823 { 824 struct peer_request * req = (struct peer_request*) msgs->peerAskedFor->data; 768 825 uint8_t * tmp = tr_new( uint8_t, req->length ); 769 826 const uint8_t msgid = BT_PIECE; 770 827 const uint32_t msglen = sizeof(uint8_t) + sizeof(uint32_t)*2 + req->length; 771 fprintf( stderr, "peer %p starting to upload a block...\n", peer ); 772 tr_ioRead( peer->torrent, req->index, req->offset, req->length, tmp ); 773 tr_peerIoWriteUint32( peer->io, peer->outBlock, msglen ); 774 tr_peerIoWriteBytes ( peer->io, peer->outBlock, &msgid, 1 ); 775 tr_peerIoWriteUint32( peer->io, peer->outBlock, req->index ); 776 tr_peerIoWriteUint32( peer->io, peer->outBlock, req->offset ); 777 tr_peerIoWriteBytes ( peer->io, peer->outBlock, tmp, req->length ); 828 tr_ioRead( msgs->torrent, req->index, req->offset, req->length, tmp ); 829 tr_peerIoWriteUint32( msgs->io, msgs->outBlock, msglen ); 830 tr_peerIoWriteBytes ( msgs->io, msgs->outBlock, &msgid, 1 ); 831 tr_peerIoWriteUint32( msgs->io, msgs->outBlock, req->index ); 832 tr_peerIoWriteUint32( msgs->io, msgs->outBlock, req->offset ); 833 tr_peerIoWriteBytes ( msgs->io, msgs->outBlock, tmp, req->length ); 778 834 tr_free( tmp ); 779 835 } 780 781 if( tr_list_size(peer->clientAskedFor) <= OUT_REQUESTS_LOW )782 fireBlocksRunningLow( peer );783 836 784 837 return TRUE; /* loop forever */ … … 899 952 peer->pexCount = diffs.elementCount; 900 953 901 902 954 /* build the pex payload */ 903 955 tr_bencInit( &val, TYPE_DICT ); … … 973 1025 peer->info->peerIsInterested = 0; 974 1026 peer->info->have = tr_bitfieldNew( torrent->info.pieceCount ); 975 peer->pulseTimer = tr_timerNew( peer->handle, pulse, peer, 500 ); 976 fprintf( stderr, "peer %p pulseTimer %p\n", peer, peer->pulseTimer ); 1027 peer->pulseTimer = tr_timerNew( peer->handle, pulse, peer, PEER_PULSE_INTERVAL_MSEC ); 977 1028 peer->pexTimer = tr_timerNew( peer->handle, pexPulse, peer, PEX_INTERVAL ); 978 1029 peer->outMessages = evbuffer_new( ); … … 993 1044 if( p != NULL ) 994 1045 { 995 fprintf( stderr, "peer %p destroying its pulse tag\n", p );996 1046 tr_timerFree( &p->pulseTimer ); 997 1047 tr_timerFree( &p->pexTimer ); -
branches/encryption/libtransmission/peer-msgs.h
r3021 r3061 28 28 void tr_peerMsgsSetChoke( tr_peermsgs *, int doChoke ); 29 29 30 void tr_peerMsgsHave( tr_peermsgs * msgs, 31 uint32_t pieceIndex ); 32 33 void tr_peerMsgsCancel( tr_peermsgs * msgs, 34 uint32_t pieceIndex, 35 uint32_t offset, 36 uint32_t length ); 37 30 38 void tr_peerMsgsFree( tr_peermsgs* ); 31 39 32 40 33 enum { TR_ADDREQ_OK=0, TR_ADDREQ_FULL, TR_ADDREQ_MISSING }; 41 enum { 42 TR_ADDREQ_OK=0, 43 TR_ADDREQ_FULL, 44 TR_ADDREQ_MISSING, 45 TR_ADDREQ_CLIENT_CHOKED 46 }; 34 47 35 48 int tr_peerMsgsAddRequest( tr_peermsgs * peer, … … 56 69 { 57 70 PeerMsgsEventType eventType; 58 uint32_t pieceIndex; /* for TR_PEERMSG_GOT_HAVE */ 59 uint32_t blockIndex; /* For TR_PEERMSG_GOT_BLOCK */ 71 uint32_t pieceIndex; /* for TR_PEERMSG_GOT_BLOCK, TR_PEERMSG_GOT_HAVE */ 72 uint32_t offset; /* for TR_PEERMSG_GOT_BLOCK */ 73 uint32_t length; /* for TR_PEERMSG_GOT_BLOCK */ 60 74 const struct tr_bitfield * bitfield; /* for TR_PEERMSG_GOT_BITFIELD */ 61 75 } -
branches/encryption/libtransmission/ptrarray.c
r2969 r3061 136 136 int * exact_match ) 137 137 { 138 int c = -1;139 138 int len = t->n_items; 140 139 int first = 0; … … 144 143 int half = len / 2; 145 144 int middle = first + half; 146 c = compare( t->items[middle], ptr );145 const int c = compare( t->items[middle], ptr ); 147 146 if( c < 0 ) { 148 147 first = middle + 1; -
branches/encryption/libtransmission/ratecontrol.c
r3025 r3061 39 39 { 40 40 uint64_t date; 41 intsize;41 uint64_t size; 42 42 } 43 43 tr_transfer_t; … … 134 134 135 135 void 136 tr_rcTransferred( tr_ratecontrol * r, int size )136 tr_rcTransferred( tr_ratecontrol * r, size_t size ) 137 137 { 138 138 uint64_t now; -
branches/encryption/libtransmission/ratecontrol.h
r2942 r3061 32 32 int tr_rcGetLimit( const tr_ratecontrol * ); 33 33 int tr_rcCanTransfer( const tr_ratecontrol * ); 34 void tr_rcTransferred( tr_ratecontrol *, int );34 void tr_rcTransferred( tr_ratecontrol *, size_t ); 35 35 float tr_rcRate( const tr_ratecontrol * ); 36 36 void tr_rcReset( tr_ratecontrol * ); -
branches/encryption/libtransmission/shared.c
r3049 r3061 82 82 s->natpmp = tr_natpmpInit(); 83 83 s->upnp = tr_upnpInit(); 84 s->pulseTimer = tr_timerNew( h, SharedLoop, s, 20 );84 s->pulseTimer = tr_timerNew( h, SharedLoop, s, 200 ); 85 85 86 86 return s;
Note: See TracChangeset
for help on using the changeset viewer.