Changeset 3076
- Timestamp:
- Sep 15, 2007, 8:36:46 PM (16 years ago)
- Location:
- branches/encryption/libtransmission
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/encryption/libtransmission/handshake.c
r3065 r3076 79 79 struct tr_handshake 80 80 { 81 unsigned int peerSupportsEncryption : 1; 81 82 tr_peerIo * io; 82 83 tr_crypto * crypto; … … 451 452 452 453 fprintf( stderr, "got a %s handshake\n", (isEncrypted ? "encrypted" : "plaintext") ); 454 handshake->peerSupportsEncryption = isEncrypted; 453 455 tr_peerIoSetEncryption( handshake->io, isEncrypted 454 456 ? PEER_ENCRYPTION_RC4 … … 657 659 EVBUFFER_DATA(inbuf)[3] ); 658 660 isEncrypted = pstrlen != 19; 661 handshake->peerSupportsEncryption = isEncrypted; 659 662 tr_peerIoSetEncryption( handshake->io, isEncrypted 660 663 ? PEER_ENCRYPTION_RC4 … … 798 801 ? handshake->peer_id 799 802 : NULL; 800 fprintf( stderr, "handshake %p: firing done. connected==%d\n", handshake, isConnected ); 801 (*handshake->doneCB)(handshake, handshake->io, isConnected, peer_id, handshake->doneUserData); 803 (*handshake->doneCB)( handshake, 804 handshake->io, 805 isConnected, 806 peer_id, 807 handshake->peerSupportsEncryption, 808 handshake->doneUserData ); 802 809 tr_handshakeFree( handshake ); 803 810 } -
branches/encryption/libtransmission/handshake.h
r3061 r3076 29 29 int isConnected, 30 30 const uint8_t * peerId, 31 int peerSupportsEncryption, 31 32 void * userData ); 32 33 -
branches/encryption/libtransmission/internal.h
r3072 r3076 149 149 uint64_t startDate; 150 150 uint64_t stopDate; 151 char ioLoaded;152 151 153 152 uint64_t downloadedCur; -
branches/encryption/libtransmission/peer-mgr-private.h
r3070 r3076 24 24 typedef struct tr_peer 25 25 { 26 unsigned int pexEnabled : 1;27 26 unsigned int peerIsChoked : 1; 28 27 unsigned int peerIsInterested : 1; 29 28 unsigned int clientIsChoked : 1; 30 29 unsigned int clientIsInterested : 1; 30 unsigned int peerSupportsEncryption : 1; 31 31 32 32 struct in_addr in_addr; 33 33 uint16_t port; 34 34 struct tr_peerIo * io; 35 int from;35 uint8_t from; 36 36 37 37 struct tr_bitfield * banned; … … 47 47 struct tr_peermsgs * msgs; 48 48 tr_publisher_tag msgsTag; 49 50 struct tr_pex * lastPex;51 int lastPexCount;52 49 } 53 50 tr_peer; -
branches/encryption/libtransmission/peer-mgr.c
r3072 r3076 520 520 int isConnected, 521 521 const uint8_t * peer_id, 522 int peerSupportsEncryption, 522 523 void * vmanager ) 523 524 { … … 531 532 532 533 assert( io != NULL ); 534 assert( isConnected==0 || isConnected==1 ); 535 assert( peerSupportsEncryption==0 || peerSupportsEncryption==1 ); 533 536 534 537 ours = tr_ptrArrayRemoveSorted( manager->handshakes, … … 581 584 peer->msgs = tr_peerMsgsNew( t->tor, peer ); 582 585 peer->client = peer_id ? tr_clientForId( peer_id ) : NULL; 586 peer->peerSupportsEncryption = peerSupportsEncryption ? 1 : 0; 583 587 fprintf( stderr, "PUB sub peer %p to msgs %p\n", peer, peer->msgs ); 584 588 peer->msgsTag = tr_peerMsgsSubscribe( peer->msgs, msgsCallbackFunc, t ); … … 723 727 for( i=0; i<peerCount; ++i, ++walk ) 724 728 { 725 walk->in_addr = peers[i]->in_addr; 726 walk->port = peers[i]->port; 727 walk->flags = '\0'; /* FIXME */ 729 const tr_peer * peer = peers[i]; 730 731 walk->in_addr = peer->in_addr; 732 733 walk->port = peer->port; 734 735 walk->flags = 0; 736 if( peer->peerSupportsEncryption ) walk->flags |= 1; 737 if( peer->progress >= 1.0 ) walk->flags |= 2; 728 738 } 729 739 … … 909 919 } 910 920 911 void912 tr_peerMgrDisablePex( tr_peerMgr * manager,913 const uint8_t * torrentHash,914 int disable)915 {916 Torrent * t = getExistingTorrent( manager, torrentHash );917 tr_torrent * tor = t->tor;918 919 if( ( tor->pexDisabled != disable ) && ! ( TR_FLAG_PRIVATE & tor->info.flags ) )920 {921 int i, size;922 tr_peer ** peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &size );923 for( i=0; i<size; ++i )924 peers[i]->pexEnabled = disable ? 0 : 1;925 926 tor->pexDisabled = disable;927 }928 }929 930 921 /** 931 922 *** -
branches/encryption/libtransmission/peer-mgr.h
r2989 r3076 80 80 const uint8_t * torrentHash ); 81 81 82 void tr_peerMgrDisablePex( tr_peerMgr * manager,83 const uint8_t * torrentHash,84 int disable );85 86 82 void tr_peerMgrTorrentAvailability( const tr_peerMgr * manager, 87 83 const uint8_t * torrentHash, -
branches/encryption/libtransmission/peer-msgs.c
r3070 r3076 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 46 #define PEER_PULSE_INTERVAL_MSEC 50 41 #define PEX_INTERVAL (60 * 1000) 42 43 #define PEER_PULSE_INTERVAL (50) 47 44 48 45 enum … … 91 88 struct tr_peermsgs 92 89 { 93 uint8_t state;94 95 90 tr_peer * info; 96 91 … … 110 105 tr_timer * pexTimer; 111 106 112 unsigned int notListening : 1; 107 unsigned int notListening : 1; 108 unsigned int peerSupportsPex : 1; 113 109 114 110 struct peer_request blockToUs; /* the block currntly being sent to us */ 115 116 uint32_t incomingMessageLength;117 111 118 112 time_t gotKeepAliveTime; 119 113 time_t clientSentPexAt; 120 114 115 uint8_t state; 116 121 117 uint8_t ut_pex_id; 122 118 uint16_t listeningPort; 123 119 124 120 uint16_t pexCount; 121 122 uint32_t incomingMessageLength; 123 125 124 tr_pex * pex; 126 125 }; … … 269 268 assert( msgs != NULL ); 270 269 assert( msgs->info != NULL ); 271 272 if( msgs->info->peerIsChoked != !!choke ) 270 assert( choke==0 || choke==1 ); 271 272 if( msgs->info->peerIsChoked != choke ) 273 273 { 274 274 const uint32_t len = sizeof(uint8_t); … … 411 411 sub = tr_bencDictFind( sub, "ut_pex" ); 412 412 if( tr_bencIsInt( sub ) ) { 413 peer->peerSupportsPex = 1; 413 414 peer->ut_pex_id = (uint8_t) sub->val.i; 414 415 fprintf( stderr, "peer->ut_pex is %d\n", (int)peer->ut_pex_id ); … … 416 417 } 417 418 419 #if 0 418 420 /* get peer's client name */ 419 421 sub = tr_bencDictFind( &val, "v" ); … … 427 429 fprintf( stderr, "peer->client is now [%s]\n", peer->info->client ); 428 430 } 431 #endif 429 432 430 433 /* get peer's listening port */ … … 440 443 441 444 static void 442 parseUtPex( tr_peermsgs * peer, int msglen, struct evbuffer * inbuf )445 parseUtPex( tr_peermsgs * msgs, int msglen, struct evbuffer * inbuf ) 443 446 { 444 447 benc_val_t val, * sub; 445 448 uint8_t * tmp; 446 449 447 if( !peer->info->pexEnabled ) /* no sharing! */450 if( msgs->torrent->pexDisabled ) /* no sharing! */ 448 451 return; 449 452 … … 461 464 const int n = sub->val.s.i / 6 ; 462 465 fprintf( stderr, "got %d peers from uT pex\n", n ); 463 tr_peerMgrAddPeers( peer->handle->peerMgr,464 peer->torrent->info.hash,466 tr_peerMgrAddPeers( msgs->handle->peerMgr, 467 msgs->torrent->info.hash, 465 468 TR_PEER_FROM_PEX, 466 469 (uint8_t*)sub->val.s.s, n ); 467 470 } 468 471 469 fireGotPex( peer);472 fireGotPex( msgs ); 470 473 471 474 tr_bencFree( &val ); … … 492 495 { 493 496 fprintf( stderr, "got ut pex\n" ); 494 msgs-> info->pexEnabled= 1;497 msgs->peerSupportsPex = 1; 495 498 parseUtPex( msgs, msglen, inbuf ); 496 //sendPex( msgs );497 499 } 498 500 else … … 980 982 PexDiffs; 981 983 982 static void pexAddedCb( void * vpex, void * userData ) 984 static void 985 pexAddedCb( void * vpex, void * userData ) 983 986 { 984 987 PexDiffs * diffs = (PexDiffs *) userData; … … 992 995 } 993 996 994 static void pexRemovedCb( void * vpex, void * userData ) 997 static void 998 pexRemovedCb( void * vpex, void * userData ) 995 999 { 996 1000 PexDiffs * diffs = (PexDiffs *) userData; … … 1003 1007 } 1004 1008 1005 static void pexElementCb( void * vpex, void * userData ) 1009 static void 1010 pexElementCb( void * vpex, void * userData ) 1006 1011 { 1007 1012 PexDiffs * diffs = (PexDiffs *) userData; … … 1017 1022 sendPex( tr_peermsgs * msgs ) 1018 1023 { 1019 if( msgs-> info->pexEnabled )1024 if( msgs->peerSupportsPex && !msgs->torrent->pexDisabled ) 1020 1025 { 1021 1026 int i; … … 1066 1071 flags = tr_bencDictAdd( &val, "added.f" ); 1067 1072 tmp = walk = tr_new( uint8_t, diffs.addedCount ); 1068 for( i=0; i<diffs.addedCount; ++i ) 1073 for( i=0; i<diffs.addedCount; ++i ) { 1074 fprintf( stderr, "PEX -->> -->> flag is %d\n", (int)diffs.added[i].flags ); 1069 1075 *walk++ = diffs.added[i].flags; 1076 } 1070 1077 assert( ( walk - tmp ) == diffs.addedCount ); 1071 1078 tr_bencInitStr( flags, tmp, walk-tmp, FALSE ); … … 1129 1136 peer->info->peerIsInterested = 0; 1130 1137 peer->info->have = tr_bitfieldNew( torrent->info.pieceCount ); 1131 peer->pulseTimer = tr_timerNew( peer->handle, pulse, peer, PEER_PULSE_INTERVAL _MSEC);1138 peer->pulseTimer = tr_timerNew( peer->handle, pulse, peer, PEER_PULSE_INTERVAL ); 1132 1139 peer->pexTimer = tr_timerNew( peer->handle, pexPulse, peer, PEX_INTERVAL ); 1133 1140 peer->outMessages = evbuffer_new( ); -
branches/encryption/libtransmission/torrent.c
r3072 r3076 677 677 } 678 678 679 /*********************************************************************** 680 * torrentReallyStop 681 *********************************************************************** 682 * Joins the download thread and frees/closes everything related to it. 683 **********************************************************************/ 684 685 void tr_torrentDisablePex( tr_torrent * tor, int disable ) 686 { 687 tr_torrentLock( tor ); 688 689 if( ! ( TR_FLAG_PRIVATE & tor->info.flags ) ) 690 { 691 if( tor->pexDisabled != disable ) 692 { 693 tor->pexDisabled = disable; 694 tr_peerMgrDisablePex( tor->handle->peerMgr, 695 tor->info.hash, 696 tor->pexDisabled ); 697 } 698 } 699 700 tr_torrentUnlock( tor ); 679 680 void 681 tr_torrentDisablePex( tr_torrent * tor, int disable ) 682 { 683 assert( tor != NULL ); 684 assert( disable==0 || disable==1 ); 685 //assert( tor->runStatus != TR_RUN_RUNNING ); 686 687 /* pex is ALWAYS disabled for private torrents */ 688 if( tor->info.flags & TR_FLAG_PRIVATE ) 689 disable = TRUE; 690 691 tor->pexDisabled = disable; 701 692 } 702 693 -
branches/encryption/libtransmission/utils.c
r3049 r3076 200 200 void * userData ) 201 201 { 202 size_t ai, bi;203 202 const uint8_t * a = (const uint8_t *) va; 204 203 const uint8_t * b = (const uint8_t *) vb; 205 206 for( ai=bi=0; ai<aCount && bi<bCount; ) 207 { 208 if( ai==aCount ) 204 const uint8_t * aend = a + elementSize*aCount; 205 const uint8_t * bend = b + elementSize*bCount; 206 207 while( a!=aend || b!=bend ) 208 { 209 if( a==aend ) 209 210 { 210 211 (*in_b_cb)( (void*)b, userData ); 211 212 b += elementSize; 212 213 } 213 else if ( b i==bCount)214 else if ( b==bend ) 214 215 { 215 216 (*in_a_cb)( (void*)a, userData );
Note: See TracChangeset
for help on using the changeset viewer.