Changeset 2978
- Timestamp:
- Sep 6, 2007, 12:33:33 AM (16 years ago)
- Location:
- branches/encryption/libtransmission
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/encryption/libtransmission/fastresume.c
r2954 r2978 75 75 76 76 /* IPs and ports of connectable peers */ 77 FR_ID_PEERS = 4,77 FR_ID_PEERS_OLD = 4, 78 78 79 79 /* progress data: … … 101 101 102 102 /* number of corrupt bytes downloaded */ 103 FR_ID_CORRUPT = 10 103 FR_ID_CORRUPT = 10, 104 105 /* IPs and ports of connectable peers */ 106 FR_ID_PEERS = 11 104 107 }; 105 108 … … 284 287 285 288 /* Write download and upload totals */ 289 286 290 total = tor->downloadedCur + tor->downloadedPrev; 287 291 fastResumeWriteData( FR_ID_DOWNLOADED, &total, 8, 1, file ); 292 288 293 total = tor->uploadedCur + tor->uploadedPrev; 289 294 fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file ); 295 290 296 total = tor->corruptCur + tor->corruptPrev; 291 297 fastResumeWriteData( FR_ID_CORRUPT, &total, 8, 1, file ); … … 293 299 if( !( TR_FLAG_PRIVATE & tor->info.flags ) ) 294 300 { 295 /* Write IPs and ports of connectable peers, if any */ 296 uint8_t * buf = NULL; 297 const int size = tr_peerMgrGetPeers( tor->handle->peerMgr, 298 tor->info.hash, &buf ); 299 if( size > 0 ) 300 { 301 fastResumeWriteData( FR_ID_PEERS, buf, size, 1, file ); 302 free( buf ); 303 } 301 tr_pex * pex; 302 const int count = tr_peerMgrGetPeers( tor->handle->peerMgr, 303 tor->info.hash, 304 &pex ); 305 if( count > 0 ) 306 fastResumeWriteData( FR_ID_PEERS, pex, sizeof(tr_pex), count, file ); 307 tr_free( pex ); 304 308 } 305 309 … … 638 642 break; 639 643 640 case FR_ID_PEERS :644 case FR_ID_PEERS_OLD: 641 645 if( !( TR_FLAG_PRIVATE & tor->info.flags ) ) 642 646 { … … 658 662 ret |= TR_FR_PEERS; 659 663 } 664 665 case FR_ID_PEERS: 666 if( !( TR_FLAG_PRIVATE & tor->info.flags ) ) 667 { 668 const int count = len / sizeof(tr_pex); 669 tr_pex * pex = tr_new0( tr_pex, count ); 670 if( 1 != fread( pex, sizeof(tr_pex), count, file ) ) 671 { 672 free( pex ); 673 fclose( file ); 674 return ret; 675 } 676 677 tr_peerMgrAddPex( tor->handle->peerMgr, 678 tor->info.hash, 679 TR_PEER_FROM_CACHE, 680 pex, count ); 681 682 tr_dbg( "found %i peers in resume file", len/6 ); 683 free( pex ); 684 ret |= TR_FR_PEERS; 685 } 660 686 continue; 661 687 -
branches/encryption/libtransmission/handshake.c
r2972 r2978 12 12 13 13 #include <assert.h> 14 #include <errno.h> 14 15 #include <inttypes.h> 15 16 #include <limits.h> /* UCHAR_MAX */ … … 32 33 33 34 /* enable Azureus messaging protocol */ 34 #define ENABLE_AZMP35 //#define ENABLE_AZMP 35 36 36 37 /*** … … 433 434 int isEncrypted; 434 435 const uint8_t * secret; 435 const size_t needlen = KEY_LEN;436 436 uint8_t yb[KEY_LEN]; 437 437 struct evbuffer * outbuf; 438 size_t needlen = HANDSHAKE_NAME_LEN; 438 439 439 440 if( EVBUFFER_LENGTH(inbuf) < needlen ) 440 441 return READ_MORE; 442 fprintf( stderr, "%*.*s\n", HANDSHAKE_NAME_LEN, HANDSHAKE_NAME_LEN, EVBUFFER_DATA(inbuf) ); 441 443 442 444 isEncrypted = memcmp( EVBUFFER_DATA(inbuf), HANDSHAKE_NAME, HANDSHAKE_NAME_LEN ); 445 if( isEncrypted ) { 446 needlen = KEY_LEN; 447 if( EVBUFFER_LENGTH(inbuf) < needlen ) 448 return READ_MORE; 449 } 450 443 451 fprintf( stderr, "got a %s handshake\n", (isEncrypted ? "encrypted" : "plaintext") ); 444 452 tr_peerIoSetEncryption( handshake->io, isEncrypted … … 671 679 /* peer id */ 672 680 tr_peerIoReadBytes( handshake->io, inbuf, peer_id, sizeof(peer_id) ); 673 fprintf( stderr, "peer_id: " );674 for( i=0; i<20; ++i ) fprintf( stderr, "[%c]", peer_id[i] );675 fprintf( stderr, "\n" );681 // fprintf( stderr, "peer_id: " ); 682 // for( i=0; i<20; ++i ) fprintf( stderr, "[%c]", peer_id[i] ); 683 // fprintf( stderr, "\n" ); 676 684 tr_peerIoSetPeersId( handshake->io, peer_id ); 677 685 bytesRead += sizeof(peer_id); … … 801 809 { 802 810 tr_handshake * handshake = (tr_handshake *) arg; 803 fprintf( stderr, "handshake %p: got error ; what==%hd\n", handshake, what);811 fprintf( stderr, "handshake %p: got error [%s]; what==%hd... state was [%s]\n", handshake, strerror(errno), what, getStateName(handshake->state) ); 804 812 805 813 … … 807 815 * have encountered a peer that doesn't do encryption... reconnect and 808 816 * try a plaintext handshake */ 809 if( ( handshake->state == AWAITING_YB)817 if( ( ( handshake->state == AWAITING_YB ) || ( handshake->state == AWAITING_VC ) ) 810 818 && ( handshake->encryptionPreference != HANDSHAKE_ENCRYPTION_REQUIRED ) 811 819 && ( !tr_peerIoReconnect( handshake->io ) ) ) 812 820 { 821 fprintf( stderr, "handshake %p trying again in plaintext...\n", handshake ); 813 822 handshake->encryptionPreference = HANDSHAKE_PLAINTEXT_REQUIRED; 814 823 sendPlaintextHandshake( handshake ); -
branches/encryption/libtransmission/peer-io.c
r2971 r2978 226 226 assert( !tr_peerIoIsIncoming( io ) ); 227 227 228 fprintf( stderr, "tr_peerIoReconnect: io %p\n", io ); 229 228 230 if( io->socket >= 0 ) 229 231 tr_netClose( io->socket ); 230 232 231 io->socket = tr_netOpenTCP( &io->in_addr, 232 io->port, 0 ); 233 234 return io->socket >= 0 ? 0 : -1; 233 io->socket = tr_netOpenTCP( &io->in_addr, io->port, 0 ); 234 235 fprintf( stderr, "tr_peerIoReconnect: io->socket is %d\n", io->socket ); 236 237 if( io->socket >= 0 ) 238 { 239 bufferevent_free( io->bufev ); 240 241 io->bufev = bufferevent_new( io->socket, 242 canReadWrapper, 243 didWriteWrapper, 244 gotErrorWrapper, 245 io ); 246 bufferevent_enable( io->bufev, EV_READ|EV_WRITE ); 247 248 return 0; 249 } 250 251 return -1; 235 252 } 236 253 -
branches/encryption/libtransmission/peer-mgr-private.h
r2968 r2978 16 16 #include <inttypes.h> /* uint16_t */ 17 17 #include <arpa/inet.h> /* struct in_addr */ 18 18 19 struct tr_bitfield; 19 20 struct tr_peerIo; … … 44 45 45 46 struct tr_peermsgs * msgs; 47 48 struct tr_pex * lastPex; 49 int lastPexCount; 46 50 } 47 51 tr_peer; -
branches/encryption/libtransmission/peer-mgr.c
r2971 r2978 226 226 peer->port = port; 227 227 peer->msgs = tr_peerMsgsNew( t->tor, peer ); 228 chokePulse( t ); 228 229 } 229 230 } … … 240 241 myHandshakeDoneCB, 241 242 manager ); 243 } 244 245 static void 246 maybeConnect( tr_peerMgr * manager, Torrent * t, tr_peer * peer ) 247 { 248 if( tr_peerMgrIsAcceptingConnections( manager ) ) 249 { 250 fprintf( stderr, "peer-mgr: torrent [%s] is handshaking with a new peer %08x:%04x\n", 251 t->tor->info.name, 252 (uint32_t) peer->in_addr.s_addr, peer->port ); 253 254 peer->io = tr_peerIoNewOutgoing( manager->handle, &peer->in_addr, peer->port, t->hash ); 255 256 tr_handshakeAdd( peer->io, HANDSHAKE_ENCRYPTION_PREFERRED, 257 myHandshakeDoneCB, manager ); 258 } 259 } 260 261 void 262 tr_peerMgrAddPex( tr_peerMgr * manager, 263 const uint8_t * torrentHash, 264 int from, 265 const tr_pex * pex, 266 int pexCount ) 267 { 268 int i; 269 const tr_pex * walk = pex; 270 Torrent * t = getExistingTorrent( manager, torrentHash ); 271 for( i=0; i<pexCount; ++i ) 272 { 273 tr_peer * peer = getPeer( t, &walk->in_addr ); 274 peer->port = walk->port; 275 peer->from = from; 276 maybeConnect( manager, t, peer ); 277 } 242 278 } 243 279 … … 252 288 const uint8_t * walk = peerCompact; 253 289 Torrent * t = getExistingTorrent( manager, torrentHash ); 254 255 290 for( i=0; i<peerCount; ++i ) 256 291 { … … 258 293 struct in_addr addr; 259 294 uint16_t port; 260 261 295 memcpy( &addr, walk, 4 ); walk += 4; 262 296 memcpy( &port, walk, 2 ); walk += 2; 263 264 297 peer = getPeer( t, &addr ); 265 298 peer->port = port; 266 299 peer->from = from; 267 268 if( tr_peerMgrIsAcceptingConnections( manager ) ) 269 { 270 fprintf( stderr, "peer-mgr: torrent [%s] is handshaking with a new peer...\n", t->tor->info.name ); 271 272 peer->io = tr_peerIoNewOutgoing( manager->handle, &addr, port, t->hash ); 273 274 tr_handshakeAdd( peer->io, HANDSHAKE_ENCRYPTION_PREFERRED, 275 myHandshakeDoneCB, manager ); 276 } 300 maybeConnect( manager, t, peer ); 277 301 } 278 302 } … … 298 322 299 323 int 324 tr_pexCompare( const void * va, const void * vb ) 325 { 326 const tr_pex * a = (const tr_pex *) va; 327 const tr_pex * b = (const tr_pex *) vb; 328 int i = memcmp( &a->in_addr, &b->in_addr, sizeof(struct in_addr) ); 329 if( i ) return i; 330 if( a->port < b->port ) return -1; 331 if( a->port > b->port ) return 1; 332 return 0; 333 } 334 335 int tr_pexCompare( const void * a, const void * b ); 336 337 338 int 300 339 tr_peerMgrGetPeers( tr_peerMgr * manager, 301 340 const uint8_t * torrentHash, 302 uint8_t ** setme_compact)341 tr_pex ** setme_pex ) 303 342 { 304 343 const Torrent * t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 305 344 int i, peerCount; 306 345 const tr_peer ** peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount ); 307 uint8_t * ret = tr_new( uint8_t, peerCount * 6);308 uint8_t * walk = ret;309 310 for( i=0; i<peerCount; ++i )311 { 312 memcpy( walk, &peers[i]->in_addr, sizeof( struct in_addr ) );313 walk += sizeof( struct in_addr );314 memcpy( walk, &peers[i]->port, sizeof( uint16_t ) );315 walk += sizeof( uint16_t );316 } 317 318 assert( ( walk - ret ) == peerCount * 6);319 *setme_ compact = ret;346 tr_pex * pex = tr_new( tr_pex, peerCount ); 347 tr_pex * walk = pex; 348 349 for( i=0; i<peerCount; ++i, ++walk ) 350 { 351 walk->in_addr = peers[i]->in_addr; 352 walk->port = peers[i]->port; 353 walk->flags = '\0'; /* FIXME */ 354 } 355 356 assert( ( walk - pex ) == peerCount ); 357 qsort( pex, peerCount, sizeof(tr_pex), tr_pexCompare ); 358 *setme_pex = pex; 320 359 return peerCount; 321 360 } … … 524 563 525 564 static int 526 chokePulse( void * vtorrent UNUSED)565 chokePulse( void * vtorrent ) 527 566 { 528 567 Torrent * t = (Torrent *) vtorrent; 529 int i, size, optimistic;568 int i, size, unchoked; 530 569 const int done = tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE; 531 570 tr_peer ** peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &size ); … … 549 588 qsort( data, size, sizeof(ChokeData), compareChokeByDownloader ); 550 589 bestDownloaderRate = data[0].rate; 551 for( i=0; i<size && i<NUM_DOWNLOADERS_TO_UNCHOKE; ++i ) 552 tr_peerMsgsSetChoke( data[i].peer->msgs, FALSE ); 590 for( i=unchoked=0; i<size && unchoked<NUM_DOWNLOADERS_TO_UNCHOKE; ++i ) { 591 if( data[i].peer->msgs != NULL ) { 592 tr_peerMsgsSetChoke( data[i].peer->msgs, FALSE ); 593 ++unchoked; 594 } 595 } 553 596 memmove( data, data+i, sizeof(ChokeData)*(size-i) ); 554 597 size -= i; … … 562 605 563 606 /* of those remaining, optimistically unchoke one; choke the rest */ 564 optimistic = tr_rand( size ); 565 for( i=0; i<size; ++i ) 566 tr_peerMsgsSetChoke( data[i].peer->msgs, i!=optimistic ); 607 if( size > 0 ) { 608 const int optimistic = tr_rand( size ); 609 for( i=0; i<size; ++i ) 610 tr_peerMsgsSetChoke( data[i].peer->msgs, i!=optimistic ); 611 } 567 612 568 613 /* cleanup */ -
branches/encryption/libtransmission/peer-mgr.h
r2969 r2978 14 14 #define TR_PEER_MGR_H 15 15 16 #include <inttypes.h> /* uint16_t */ 17 #include <arpa/inet.h> /* struct in_addr */ 18 16 19 struct in_addr; 17 20 struct tr_handle; … … 19 22 struct tr_torrent; 20 23 typedef struct tr_peerMgr tr_peerMgr; 24 25 typedef struct tr_pex 26 { 27 struct in_addr in_addr; 28 uint16_t port; 29 uint8_t flags; 30 } 31 tr_pex; 32 33 int tr_pexCompare( const void * a, const void * b ); 21 34 22 35 tr_peerMgr* tr_peerMgrNew( struct tr_handle * ); … … 36 49 int peerCount ); 37 50 51 void tr_peerMgrAddPex( tr_peerMgr * manager, 52 const uint8_t * torrentHash, 53 int from, 54 const tr_pex * pex, 55 int pexCount ); 56 38 57 void tr_peerMgrSetBlame( tr_peerMgr * manager, 39 58 const uint8_t * torrentHash, … … 43 62 int tr_peerMgrGetPeers( tr_peerMgr * manager, 44 63 const uint8_t * torrentHash, 45 uint8_t ** setme_compact);64 tr_pex ** setme_pex ); 46 65 47 66 void tr_peerMgrStartTorrent( tr_peerMgr * manager, -
branches/encryption/libtransmission/peer-msgs.c
r2972 r2978 39 39 **/ 40 40 41 #define MINUTES_TO_MSEC(N) ((N) * 60 * 1000) 42 43 /* pex attempts are made this frequently */ 44 #define PEX_INTERVAL (MINUTES_TO_MSEC(1)) 45 41 46 enum 42 47 { … … 110 115 111 116 tr_timer_tag pulseTag; 117 tr_timer_tag pexTag; 112 118 113 119 unsigned int notListening : 1; … … 121 127 uint64_t gotKeepAliveTime; 122 128 123 uint 16_t ut_pex;129 uint8_t ut_pex; 124 130 uint16_t listeningPort; 131 132 tr_pex * pex; 133 int pexCount; 125 134 }; 126 135 … … 186 195 tr_peerMsgsSetChoke( tr_peermsgs * peer, int choke ) 187 196 { 197 assert( peer != NULL ); 198 188 199 if( peer->info->peerIsChoked != !!choke ) 189 200 { … … 228 239 sub = tr_bencDictFind( sub, "ut_pex" ); 229 240 if( tr_bencIsInt( sub ) ) { 230 peer->ut_pex = sub->val.i;241 peer->ut_pex = (uint8_t) sub->val.i; 231 242 fprintf( stderr, "peer->ut_pex is %d\n", peer->ut_pex ); 232 243 } … … 598 609 size_t len; 599 610 611 fprintf( stderr, "peer %p pulse... notlistening %d, outblock size: %d, outmessages size %d, peerAskedFor %p\n", 612 vpeer, 613 (int)peer->notListening, 614 (int)EVBUFFER_LENGTH( peer->outBlock ), 615 (int)EVBUFFER_LENGTH( peer->outMessages ), 616 peer->peerAskedFor ); 617 600 618 /* if we froze out a downloaded block because of speed limits, 601 619 start listening to the peer again */ … … 609 627 if(( len = EVBUFFER_LENGTH( peer->outBlock ) )) 610 628 { 629 fprintf( stderr, "peer %p needing to upload... canUpload %d\n", peer, canUpload(peer) ); 611 630 if( canUpload( peer ) ) 612 631 { 613 632 const size_t outlen = MIN( len, 2048 ); 633 fprintf( stderr, "peer %p writing %d bytes...\n", peer, (int)outlen ); 614 634 tr_peerIoWrite( peer->io, EVBUFFER_DATA(peer->outBlock), outlen ); 615 635 evbuffer_drain( peer->outBlock, outlen ); 636 637 peer->torrent->uploadedCur += outlen; 638 tr_rcTransferred( peer->torrent->upload, outlen ); 639 tr_rcTransferred( peer->handle->upload, outlen ); 616 640 } 617 641 } … … 628 652 const uint8_t msgid = BT_PIECE; 629 653 const uint32_t msglen = sizeof(uint8_t) + sizeof(uint32_t)*2 + req->length; 654 fprintf( stderr, "peer %p starting to upload a block...\n", peer ); 630 655 tr_ioRead( peer->torrent, req->index, req->offset, req->length, tmp ); 631 656 tr_peerIoWriteUint32( peer->io, peer->outBlock, msglen ); … … 667 692 tr_peerIoWriteBytes( peer->io, peer->outMessages, bitfield->bits, bitfield->len ); 668 693 } 694 695 /** 696 *** 697 **/ 698 699 #define MAX_DIFFS 50 700 701 typedef struct 702 { 703 tr_pex * added; 704 tr_pex * dropped; 705 tr_pex * elements; 706 int addedCount; 707 int droppedCount; 708 int elementCount; 709 int diffCount; 710 } 711 PexDiffs; 712 713 static void pexAddedCb( void * vpex, void * userData ) 714 { 715 PexDiffs * diffs = (PexDiffs *) userData; 716 tr_pex * pex = (tr_pex *) vpex; 717 if( diffs->diffCount < MAX_DIFFS ) 718 { 719 diffs->diffCount++; 720 diffs->added[diffs->addedCount++] = *pex; 721 diffs->elements[diffs->elementCount++] = *pex; 722 } 723 } 724 725 static void pexRemovedCb( void * vpex, void * userData ) 726 { 727 PexDiffs * diffs = (PexDiffs *) userData; 728 tr_pex * pex = (tr_pex *) vpex; 729 if( diffs->diffCount < MAX_DIFFS ) 730 { 731 diffs->diffCount++; 732 diffs->dropped[diffs->droppedCount++] = *pex; 733 } 734 } 735 736 static void pexElementCb( void * vpex, void * userData ) 737 { 738 PexDiffs * diffs = (PexDiffs *) userData; 739 tr_pex * pex = (tr_pex *) vpex; 740 if( diffs->diffCount < MAX_DIFFS ) 741 { 742 diffs->diffCount++; 743 diffs->elements[diffs->elementCount++] = *pex; 744 } 745 } 746 747 static int 748 pexPulse( void * vpeer ) 749 { 750 tr_peermsgs * peer = (tr_peermsgs *) vpeer; 751 752 if( peer->info->pexEnabled ) 753 { 754 int i; 755 tr_pex * newPex = NULL; 756 const int newCount = tr_peerMgrGetPeers( peer->handle->peerMgr, peer->torrent->info.hash, &newPex ); 757 PexDiffs diffs; 758 benc_val_t val, *added, *dropped, *flags; 759 uint8_t *tmp, *walk; 760 char * benc; 761 int bencLen; 762 const uint8_t bt_msgid = BT_LTEP; 763 const uint8_t ltep_msgid = peer->ut_pex; 764 765 /* build the diffs */ 766 diffs.added = tr_new( tr_pex, newCount ); 767 diffs.addedCount = 0; 768 diffs.dropped = tr_new( tr_pex, peer->pexCount ); 769 diffs.droppedCount = 0; 770 diffs.elements = tr_new( tr_pex, newCount + peer->pexCount ); 771 diffs.elementCount = 0; 772 diffs.diffCount = 0; 773 tr_set_compare( peer->pex, peer->pexCount, 774 newPex, newCount, 775 tr_pexCompare, sizeof(tr_pex), 776 pexRemovedCb, pexAddedCb, pexElementCb, &diffs ); 777 fprintf( stderr, "pex: old peer count %d, new peer count %d, added %d, removed %d\n", peer->pexCount, newCount, diffs.addedCount, diffs.droppedCount ); 778 779 /* update peer */ 780 tr_free( peer->pex ); 781 peer->pex = diffs.elements; 782 peer->pexCount = diffs.elementCount; 783 784 785 /* build the pex payload */ 786 tr_bencInit( &val, TYPE_DICT ); 787 tr_bencDictReserve( &val, 3 ); 788 789 /* "added" */ 790 added = tr_bencDictAdd( &val, "added" ); 791 tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 ); 792 for( i=0; i<diffs.addedCount; ++i ) { 793 memcpy( walk, &diffs.added[i].in_addr, 4 ); walk += 4; 794 memcpy( walk, &diffs.added[i].port, 2 ); walk += 2; 795 } 796 assert( ( walk - tmp ) == diffs.addedCount * 6 ); 797 tr_bencInitStr( added, tmp, walk-tmp, FALSE ); 798 799 /* "added.f" */ 800 flags = tr_bencDictAdd( &val, "added.f" ); 801 tmp = walk = tr_new( uint8_t, diffs.addedCount ); 802 for( i=0; i<diffs.addedCount; ++i ) 803 *walk++ = diffs.added[i].flags; 804 assert( ( walk - tmp ) == diffs.addedCount ); 805 tr_bencInitStr( flags, tmp, walk-tmp, FALSE ); 806 807 /* "dropped" */ 808 dropped = tr_bencDictAdd( &val, "dropped" ); 809 tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 ); 810 for( i=0; i<diffs.droppedCount; ++i ) { 811 memcpy( walk, &diffs.dropped[i].in_addr, 4 ); walk += 4; 812 memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2; 813 } 814 assert( ( walk - tmp ) == diffs.droppedCount * 6 ); 815 tr_bencInitStr( dropped, tmp, walk-tmp, FALSE ); 816 817 /* write the pex message */ 818 benc = tr_bencSaveMalloc( &val, &bencLen ); 819 tr_peerIoWriteUint32( peer->io, peer->outBlock, 1 + 1 + bencLen ); 820 tr_peerIoWriteBytes ( peer->io, peer->outBlock, &bt_msgid, 1 ); 821 tr_peerIoWriteBytes ( peer->io, peer->outBlock, <ep_msgid, 1 ); 822 tr_peerIoWriteBytes ( peer->io, peer->outBlock, benc, bencLen ); 823 824 /* cleanup */ 825 tr_free( benc ); 826 tr_bencFree( &val ); 827 tr_free( diffs.added ); 828 tr_free( diffs.dropped ); 829 tr_free( newPex ); 830 } 831 832 return TRUE; 833 } 834 835 /** 836 *** 837 **/ 669 838 670 839 tr_peermsgs* … … 686 855 peer->info->peerIsInterested = 0; 687 856 peer->info->have = tr_bitfieldNew( torrent->info.pieceCount ); 688 peer->pulseTag = tr_timerNew( peer->handle, pulse, peer, NULL, 200 ); 857 peer->pulseTag = tr_timerNew( peer->handle, pulse, peer, NULL, 500 ); 858 fprintf( stderr, "peer %p pulseTag %p\n", peer, peer->pulseTag ); 859 peer->pexTag = tr_timerNew( peer->handle, pexPulse, peer, NULL, PEX_INTERVAL ); 689 860 peer->outMessages = evbuffer_new( ); 690 861 peer->outBlock = evbuffer_new( ); … … 704 875 if( p != NULL ) 705 876 { 877 fprintf( stderr, "peer %p destroying its pulse tag\n", p ); 706 878 tr_timerFree( &p->pulseTag ); 879 tr_timerFree( &p->pexTag ); 707 880 evbuffer_free( p->outMessages ); 708 881 evbuffer_free( p->outBlock ); -
branches/encryption/libtransmission/utils.c
r2941 r2978 186 186 } 187 187 188 /*** 189 **** 190 ***/ 191 192 void 193 tr_set_compare( const void * va, size_t aCount, 194 const void * vb, size_t bCount, 195 int compare( const void * a, const void * b ), 196 size_t elementSize, 197 tr_set_func in_a_cb, 198 tr_set_func in_b_cb, 199 tr_set_func in_both_cb, 200 void * userData ) 201 { 202 size_t ai, bi; 203 const uint8_t * a = (const uint8_t *) va; 204 const uint8_t * b = (const uint8_t *) vb; 205 206 for( ai=bi=0; ai<aCount && bi<bCount; ) 207 { 208 if( ai==aCount ) 209 { 210 (*in_b_cb)( (void*)b, userData ); 211 b += elementSize; 212 } 213 else if ( bi==bCount ) 214 { 215 (*in_a_cb)( (void*)a, userData ); 216 a += elementSize; 217 } 218 else 219 { 220 const int val = (*compare)( a, b ); 221 222 if( !val ) 223 { 224 (*in_both_cb)( (void*)a, userData ); 225 a += elementSize; 226 b += elementSize; 227 } 228 else if( val < 0 ) 229 { 230 (*in_a_cb)( (void*)a, userData ); 231 a += elementSize; 232 } 233 else if( val > 0 ) 234 { 235 (*in_b_cb)( (void*)b, userData ); 236 b += elementSize; 237 } 238 } 239 } 240 } 241 242 /*** 243 **** 244 ***/ 245 188 246 189 247 #if 0 -
branches/encryption/libtransmission/utils.h
r2941 r2978 139 139 ***/ 140 140 141 typedef void (tr_set_func)(void * element, void * userData ); 142 143 void tr_set_compare( const void * a, size_t aCount, 144 const void * b, size_t bCount, 145 int compare( const void * a, const void * b ), 146 size_t elementSize, 147 tr_set_func in_a_cb, 148 tr_set_func in_b_cb, 149 tr_set_func in_both_cb, 150 void * userData ); 151 152 153 /*** 154 **** 155 ***/ 156 141 157 struct tr_bitfield 142 158 {
Note: See TracChangeset
for help on using the changeset viewer.