Changeset 2954
- Timestamp:
- Aug 31, 2007, 8:43:39 PM (15 years ago)
- Location:
- branches/encryption
- Files:
-
- 3 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/encryption/libtransmission/Makefile.am
r2953 r2954 10 10 basename.c \ 11 11 bencode.c \ 12 choking.c \13 12 clients.c \ 14 13 completion.c \ … … 27 26 net.c \ 28 27 p.c \ 29 peer.c \30 28 peer-io.c \ 29 peer-mgr.c \ 31 30 platform.c \ 32 31 ptrarray.c \ … … 49 48 bsdqueue.h \ 50 49 bsdtree.h \ 51 choking.h \52 50 clients.h \ 53 51 crypto.h \ … … 66 64 net.h \ 67 65 p.h \ 68 peeraz.h \ 69 peerext.h \ 70 peer.h \ 71 peermessages.h \ 72 peerparse.h \ 73 peertree.h \ 74 peerutils.h \ 66 peer-mgr.h \ 75 67 peer-io.h \ 76 68 platform.h \ -
branches/encryption/libtransmission/fastresume.c
r2941 r2954 56 56 #include "completion.h" 57 57 #include "fastresume.h" 58 #include "peer .h"58 #include "peer-mgr.h" 59 59 #include "platform.h" 60 60 #include "utils.h" … … 294 294 { 295 295 /* Write IPs and ports of connectable peers, if any */ 296 int size;297 296 uint8_t * buf = NULL; 298 if( ( size = tr_peerGetConnectable( tor, &buf ) ) > 0 ) 297 const int size = tr_peerMgrGetPeers( tor->handle->peerMgr, 298 tor->info.hash, &buf ); 299 if( size > 0 ) 299 300 { 300 301 fastResumeWriteData( FR_ID_PEERS, buf, size, 1, file ); … … 640 641 if( !( TR_FLAG_PRIVATE & tor->info.flags ) ) 641 642 { 642 int used;643 643 uint8_t * buf = malloc( len ); 644 644 if( 1 != fread( buf, len, 1, file ) ) … … 648 648 return ret; 649 649 } 650 used = tr_torrentAddCompact( tor, TR_PEER_FROM_CACHE, 651 buf, len / 6 ); 652 tr_dbg( "found %i peers in resume file, used %i", 653 len / 6, used ); 650 651 tr_peerMgrAddPeers( tor->handle->peerMgr, 652 tor->info.hash, 653 TR_PEER_FROM_CACHE, 654 buf, len / 6 ); 655 656 tr_dbg( "found %i peers in resume file", len/6 ); 654 657 free( buf ); 655 658 ret |= TR_FR_PEERS; -
branches/encryption/libtransmission/handshake.c
r2953 r2954 385 385 assert( tor != NULL ); 386 386 fprintf( stderr, "found the torrent; it's [%s]\n", tor->info.name ); 387 tr_peerIoSetTorrent ( handshake->io, tor);387 tr_peerIoSetTorrentHash( handshake->io, tor->info.hash ); 388 388 389 389 /* next part: ENCRYPT(VC, crypto_provide, len(PadC), */ … … 680 680 /* torrent hash */ 681 681 tr_peerIoReadBytes( handshake->io, inbuf, hash, sizeof(hash) ); 682 assert( !memcmp( hash, tr_peerIoGetTorrent (handshake->io)->info.hash, SHA_DIGEST_LENGTH ) );682 assert( !memcmp( hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH ) ); 683 683 bytesRead += sizeof(hash); 684 684 -
branches/encryption/libtransmission/inout.c
r2949 r2954 25 25 #include "inout.h" 26 26 #include "net.h" 27 #include "peer .h"27 #include "peer-mgr.h" 28 28 #include "utils.h" 29 29 … … 302 302 tr_ioHash( tr_io_t * io, int pieceIndex ) 303 303 { 304 int i;305 306 304 tr_torrent * tor = io->tor; 307 305 const int success = !checkPiece( tor, pieceIndex ); … … 317 315 } 318 316 319 /* Assign blame or credit to peers */ 320 for( i = 0; i < tor->peerCount; ++i ) 321 tr_peerBlame( tor->peers[i], pieceIndex, success ); 317 tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, pieceIndex, success ); 322 318 323 319 return 0; -
branches/encryption/libtransmission/internal.h
r2942 r2954 52 52 void tr_trackerInfoClear( struct tr_tracker_info_s * info ); 53 53 54 struct tr_peer_s;55 56 54 void tr_peerIdNew ( char* buf, int buflen ); 57 55 58 56 void tr_torrentResetTransferStats( tr_torrent * ); 59 60 int tr_torrentAddCompact( tr_torrent * tor, int from,61 const uint8_t * buf, int count );62 int tr_torrentAttachPeer( tr_torrent * tor, struct tr_peer_s * );63 57 64 58 void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has ); … … 71 65 void tr_torrentChangeMyPort ( tr_torrent *, int port ); 72 66 67 tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * ); 73 68 tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* ); 74 69 … … 160 155 char fastResumeDirty; 161 156 162 int peerCount;163 struct tr_peer_s * peers[TR_MAX_PEER_COUNT];164 165 157 uint64_t downloadedCur; 166 158 uint64_t downloadedPrev; … … 181 173 struct tr_handle 182 174 { 183 struct tr_event_handle _s* events;175 struct tr_event_handle * events; 184 176 185 177 int torrentCount; … … 194 186 struct tr_ratecontrol * download; 195 187 196 struct tr_shared_s * shared; 188 struct tr_peerMgr * peerMgr; 189 struct tr_shared * shared; 197 190 198 tr_handle_status _tstats[2];191 tr_handle_status stats[2]; 199 192 int statCur; 200 193 -
branches/encryption/libtransmission/p.c
r2953 r2954 28 28 #include "list.h" 29 29 #include "peer-io.h" 30 #include "peer-mgr.h" 30 31 #include "ratecontrol.h" 31 32 #include "timer.h" … … 295 296 const int n = sub->val.s.i / 6 ; 296 297 fprintf( stderr, "got %d peers from uT pex\n", n ); 297 tr_torrentAddCompact( peer->torrent, TR_PEER_FROM_PEX, (uint8_t*)sub->val.s.s, n ); 298 tr_peerMgrAddPeers( peer->handle->peerMgr, 299 peer->torrent->info.hash, 300 TR_PEER_FROM_PEX, 301 (uint8_t*)sub->val.s.s, n ); 298 302 } 299 303 … … 684 688 685 689 void 686 tr_peer ManagerAdd( struct tr_torrent * torrent,687 690 tr_peerWorkAdd( struct tr_torrent * torrent, 691 struct tr_peerIo * io ) 688 692 { 689 693 tr_peer * peer; -
branches/encryption/libtransmission/p.h
r2953 r2954 17 17 struct tr_peerIo; 18 18 19 void tr_peer ManagerAdd( struct tr_torrent * torrent,20 19 void tr_peerWorkAdd( struct tr_torrent * torrent, 20 struct tr_peerIo * io ); 21 21 22 22 #endif -
branches/encryption/libtransmission/peer-io.c
r2953 r2954 31 31 { 32 32 struct tr_handle * handle; 33 struct tr_torrent * torrent;34 33 35 34 struct in_addr in_addr; … … 98 97 tr_peerIoNew( struct tr_handle * handle, 99 98 struct in_addr * in_addr, 100 struct tr_torrent * torrent,99 const uint8_t * torrentHash, 101 100 int isIncoming, 102 101 int socket ) … … 104 103 tr_peerIo * c; 105 104 c = tr_new0( tr_peerIo, 1 ); 106 c->torrent = torrent; 107 c->crypto = tr_cryptoNew( torrent ? torrent->info.hash : NULL, isIncoming ); 105 c->crypto = tr_cryptoNew( torrentHash, isIncoming ); 108 106 c->handle = handle; 109 107 c->in_addr = *in_addr; … … 132 130 struct in_addr * in_addr, 133 131 int port, 134 struct tr_torrent * torrent)132 const uint8_t * torrentHash ) 135 133 { 136 134 tr_peerIo * c; … … 139 137 assert( in_addr != NULL ); 140 138 assert( port >= 0 ); 141 assert( torrent != NULL );142 143 c = tr_peerIoNew( handle, in_addr, torrent , 0,139 assert( torrentHash != NULL ); 140 141 c = tr_peerIoNew( handle, in_addr, torrentHash, 0, 144 142 tr_netOpenTCP( in_addr, port, 0 ) ); 145 143 c->port = port; … … 163 161 164 162 return io->handle; 163 } 164 165 const struct in_addr* 166 tr_peerIoGetAddress( const tr_peerIo * io, uint16_t * port ) 167 { 168 assert( io != NULL ); 169 170 if( port != NULL ) 171 *port = io->port; 172 173 return &io->in_addr; 165 174 } 166 175 … … 221 230 222 231 void 223 tr_peerIoSetTorrent( tr_peerIo * io, 224 struct tr_torrent * torrent ) 225 { 226 io->torrent = torrent; 227 228 tr_cryptoSetTorrentHash( io->crypto, torrent->info.hash ); 229 } 230 231 struct tr_torrent* 232 tr_peerIoSetTorrentHash( tr_peerIo * io, 233 const uint8_t * hash ) 234 { 235 tr_cryptoSetTorrentHash( io->crypto, hash ); 236 } 237 238 const uint8_t* 232 239 tr_peerIoGetTorrent( tr_peerIo * io ) 233 240 { 234 return io->torrent;235 } 236 237 /** 238 *** 239 **/ 240 241 void 242 tr_peerIoSetPeersId( tr_peerIo * io,243 const uint8_t* peer_id )241 return tr_cryptoGetTorrentHash( io->crypto ); 242 } 243 244 /** 245 *** 246 **/ 247 248 void 249 tr_peerIoSetPeersId( tr_peerIo * io, 250 const uint8_t * peer_id ) 244 251 { 245 252 assert( io != NULL ); … … 265 272 266 273 void 267 tr_peerIoSetExtension( tr_peerIo * io,268 intextensions )274 tr_peerIoSetExtension( tr_peerIo * io, 275 int extensions ) 269 276 { 270 277 assert( io != NULL ); -
branches/encryption/libtransmission/peer-io.h
r2953 r2954 23 23 struct tr_handle; 24 24 struct tr_crypto; 25 struct tr_torrent;26 25 typedef struct tr_peerIo tr_peerIo; 27 26 … … 35 34 struct in_addr * addr, 36 35 int port, 37 struct tr_torrent * torrent);36 const uint8_t * torrentHash ); 38 37 39 38 tr_peerIo* … … 66 65 **/ 67 66 68 struct tr_torrent*69 tr_peerIoGet Torrent( tr_peerIo * io);67 const struct in_addr* 68 tr_peerIoGetAddress( const tr_peerIo * io, uint16_t * port ); 70 69 71 void tr_peerIoSetTorrent( tr_peerIo * io, 72 struct tr_torrent * tor ); 70 const uint8_t* 71 tr_peerIoGetTorrentHash( tr_peerIo * io ); 72 73 void tr_peerIoSetTorrentHash( tr_peerIo * io, 74 const uint8_t * hash ); 73 75 74 76 int tr_peerIoReconnect( tr_peerIo * io ); -
branches/encryption/libtransmission/peerext.h
r2941 r2954 327 327 if( NULL != sub && TYPE_STR == sub->type && 0 == sub->val.s.i % 6 ) 328 328 { 329 #if 0 329 330 used = tr_torrentAddCompact( tor, TR_PEER_FROM_PEX, 330 331 ( uint8_t * )sub->val.s.s, … … 332 333 peer_dbg( "GET extended-pex, got %i peers, used %i", 333 334 sub->val.s.i / 6, used ); 335 #endif 334 336 } 335 337 else -
branches/encryption/libtransmission/ptrarray.c
r2851 r2954 20 20 #define GROW 32 21 21 22 struct tr_ptrArray _s22 struct tr_ptrArray 23 23 { 24 24 void ** items; … … 27 27 }; 28 28 29 tr_ptrArray _t*29 tr_ptrArray* 30 30 tr_ptrArrayNew( void ) 31 31 { 32 tr_ptrArray _t* p;32 tr_ptrArray * p; 33 33 34 p = tr_new( tr_ptrArray _t, 1 );34 p = tr_new( tr_ptrArray, 1 ); 35 35 p->n_items = 0; 36 36 p->n_alloc = GROW; … … 41 41 42 42 void 43 tr_ptrArrayFree( tr_ptrArray _t* t )43 tr_ptrArrayFree( tr_ptrArray * t ) 44 44 { 45 45 assert( t != NULL ); … … 51 51 52 52 void** 53 tr_ptrArrayPeek( tr_ptrArray _t* t, int * size )53 tr_ptrArrayPeek( tr_ptrArray * t, int * size ) 54 54 { 55 55 *size = t->n_items; … … 58 58 59 59 int 60 tr_ptrArraySize( const tr_ptrArray _t* t )60 tr_ptrArraySize( const tr_ptrArray * t ) 61 61 { 62 62 return t->n_items; … … 64 64 65 65 int 66 tr_ptrArrayEmpty( const tr_ptrArray _t* t )66 tr_ptrArrayEmpty( const tr_ptrArray * t ) 67 67 { 68 68 return t->n_items == 0; … … 70 70 71 71 void 72 tr_ptrArrayClear( tr_ptrArray _t* t )72 tr_ptrArrayClear( tr_ptrArray * t ) 73 73 { 74 74 t->n_items = 0; … … 76 76 77 77 int 78 tr_ptrArrayInsert( tr_ptrArray _t* t, void * ptr, int pos )78 tr_ptrArrayInsert( tr_ptrArray * t, void * ptr, int pos ) 79 79 { 80 80 if( pos<0 || pos>t->n_items ) … … 96 96 97 97 int 98 tr_ptrArrayAppend( tr_ptrArray _t* t, void * ptr )98 tr_ptrArrayAppend( tr_ptrArray * t, void * ptr ) 99 99 { 100 100 return tr_ptrArrayInsert( t, ptr, -1 ); … … 102 102 103 103 void 104 tr_ptrArrayErase( tr_ptrArray _t* t, int begin, int end )104 tr_ptrArrayErase( tr_ptrArray * t, int begin, int end ) 105 105 { 106 106 assert( begin >= 0 ); … … 121 121 122 122 int 123 tr_ptrArrayLowerBound( const tr_ptrArray _t* t,124 void* ptr,125 int 126 int 123 tr_ptrArrayLowerBound( const tr_ptrArray * t, 124 const void * ptr, 125 int compare( const void *,const void * ), 126 int * exact_match ) 127 127 { 128 128 int c = -1; … … 155 155 156 156 int 157 tr_ptrArrayInsertSorted( tr_ptrArray _t* t,158 void 159 int 157 tr_ptrArrayInsertSorted( tr_ptrArray * t, 158 void * ptr, 159 int compare(const void*,const void*) ) 160 160 { 161 161 const int pos = tr_ptrArrayLowerBound( t, ptr, compare, NULL ); … … 164 164 165 165 void* 166 tr_ptrArrayFindSorted( tr_ptrArray _t* t,167 void* ptr,168 int 166 tr_ptrArrayFindSorted( tr_ptrArray * t, 167 const void * ptr, 168 int compare(const void*,const void*) ) 169 169 { 170 170 int match; … … 174 174 175 175 void* 176 tr_ptrArrayRemoveSorted( tr_ptrArray _t* t,177 void 178 int 176 tr_ptrArrayRemoveSorted( tr_ptrArray * t, 177 void * ptr, 178 int compare(const void*,const void*) ) 179 179 { 180 180 void * ret = NULL; -
branches/encryption/libtransmission/ptrarray.h
r2849 r2954 17 17 * A simple pointer array that resizes itself dynamically. 18 18 */ 19 typedef struct tr_ptrArray _s tr_ptrArray_t;19 typedef struct tr_ptrArray tr_ptrArray; 20 20 21 tr_ptrArray_t * tr_ptrArrayNew ( void ); 22 void tr_ptrArrayFree ( tr_ptrArray_t* ); 23 void** tr_ptrArrayPeek ( tr_ptrArray_t*, int * size ); 24 void** tr_ptrArrayBase ( tr_ptrArray_t* ); 25 void tr_ptrArrayClear ( tr_ptrArray_t* ); 26 int tr_ptrArrayInsert ( tr_ptrArray_t*, void*, int pos ); 27 int tr_ptrArrayAppend ( tr_ptrArray_t*, void* ); 28 void tr_ptrArrayErase ( tr_ptrArray_t*, int begin, int end ); 29 int tr_ptrArraySize ( const tr_ptrArray_t* ); 30 int tr_ptrArrayEmpty ( const tr_ptrArray_t* ); 21 tr_ptrArray * tr_ptrArrayNew ( void ); 31 22 32 int tr_ptrArrayInsertSorted( tr_ptrArray_t*, void*, 33 int compare(const void*,const void*) ); 34 void* tr_ptrArrayRemoveSorted( tr_ptrArray_t*, void*, 35 int compare(const void*,const void*) ); 36 void* tr_ptrArrayFindSorted ( tr_ptrArray_t*, void*, 37 int compare(const void*,const void*) ); 23 void tr_ptrArrayFree ( tr_ptrArray* ); 24 void** tr_ptrArrayPeek ( tr_ptrArray*, int * size ); 25 void** tr_ptrArrayBase ( tr_ptrArray* ); 26 void tr_ptrArrayClear ( tr_ptrArray* ); 27 int tr_ptrArrayInsert ( tr_ptrArray*, void*, int pos ); 28 int tr_ptrArrayAppend ( tr_ptrArray*, void* ); 29 void tr_ptrArrayErase ( tr_ptrArray*, int begin, int end ); 30 int tr_ptrArraySize ( const tr_ptrArray* ); 31 int tr_ptrArrayEmpty ( const tr_ptrArray* ); 32 int tr_ptrArrayInsertSorted ( tr_ptrArray*, void*, 33 int compare(const void*,const void*) ); 34 void* tr_ptrArrayRemoveSorted ( tr_ptrArray*, void*, 35 int compare(const void*,const void*) ); 36 void* tr_ptrArrayFindSorted ( tr_ptrArray*, const void*, 37 int compare(const void*,const void*) ); 38 38 39 39 #endif -
branches/encryption/libtransmission/shared.c
r2953 r2954 37 37 #include "peer.h" 38 38 #include "peer-io.h" 39 #include "peer-mgr.h" 39 40 #include "platform.h" 40 41 #include "shared.h" … … 46 47 #define MAX_PEER_COUNT 128 47 48 48 struct tr_shared _s49 { 50 tr_handle _t* h;49 struct tr_shared 50 { 51 tr_handle * h; 51 52 volatile int die; 52 53 tr_thread_t * thread; … … 57 58 int bindPort; 58 59 int bindSocket; 59 int peerCount;60 tr_peer_t * peers[MAX_PEER_COUNT];61 60 62 61 /* NAT-PMP/UPnP */ … … 72 71 **********************************************************************/ 73 72 static void SharedLoop( void * ); 74 static void SetPublicPort( tr_shared_t *, int ); 75 static void AcceptPeers( tr_shared_t * ); 76 static void ReadPeers( tr_shared_t * ); 77 static void DispatchPeers( tr_shared_t * ); 73 static void SetPublicPort( tr_shared *, int ); 74 static void AcceptPeers( tr_shared * ); 78 75 79 76 … … 83 80 * 84 81 **********************************************************************/ 85 tr_shared _t * tr_sharedInit( tr_handle_t* h )86 { 87 tr_shared _t * s = calloc( 1, sizeof( tr_shared_t) );82 tr_shared * tr_sharedInit( tr_handle * h ) 83 { 84 tr_shared * s = calloc( 1, sizeof( tr_shared ) ); 88 85 89 86 s->h = h; … … 106 103 * 107 104 **********************************************************************/ 108 void tr_sharedClose( tr_shared_t * s ) 109 { 110 int ii; 111 105 void tr_sharedClose( tr_shared * s ) 106 { 112 107 /* Stop the thread */ 113 108 s->die = 1; 114 109 tr_threadJoin( s->thread ); 115 110 116 /* Clean up */117 for( ii = 0; ii < s->peerCount; ii++ )118 {119 tr_peerDestroy( s->peers[ii] );120 }121 111 if( s->bindSocket > -1 ) 122 {123 112 tr_netClose( s->bindSocket ); 124 }125 113 tr_lockFree( s->lock ); 126 114 tr_natpmpClose( s->natpmp ); … … 135 123 * 136 124 **********************************************************************/ 137 void tr_sharedLock( tr_shared _t* s )125 void tr_sharedLock( tr_shared * s ) 138 126 { 139 127 tr_lockLock( s->lock ); 140 128 } 141 void tr_sharedUnlock( tr_shared _t* s )129 void tr_sharedUnlock( tr_shared * s ) 142 130 { 143 131 tr_lockUnlock( s->lock ); … … 149 137 * 150 138 **********************************************************************/ 151 void tr_sharedSetPort( tr_shared _t* s, int port )139 void tr_sharedSetPort( tr_shared * s, int port ) 152 140 { 153 141 #ifdef BEOS_NETSERVER … … 205 193 * 206 194 **********************************************************************/ 207 int tr_sharedGetPublicPort( tr_shared _t* s )195 int tr_sharedGetPublicPort( tr_shared * s ) 208 196 { 209 197 return s->publicPort; … … 215 203 * 216 204 **********************************************************************/ 217 void tr_sharedTraversalEnable( tr_shared _t* s, int enable )205 void tr_sharedTraversalEnable( tr_shared * s, int enable ) 218 206 { 219 207 if( enable ) … … 229 217 } 230 218 231 int tr_sharedTraversalStatus( tr_shared _t* s )219 int tr_sharedTraversalStatus( tr_shared * s ) 232 220 { 233 221 int statuses[] = { … … 262 250 * tr_sharedSetLimit 263 251 **********************************************************************/ 264 void tr_sharedSetLimit( tr_shared _t* s, int limit )252 void tr_sharedSetLimit( tr_shared * s, int limit ) 265 253 { 266 254 tr_chokingSetLimit( s->choking, limit ); … … 277 265 static void SharedLoop( void * _s ) 278 266 { 279 tr_shared _t* s = _s;267 tr_shared * s = _s; 280 268 uint64_t date1, date2, lastchoke = 0; 281 269 int newPort; … … 298 286 /* Handle incoming connections */ 299 287 AcceptPeers( s ); 300 ReadPeers( s );301 DispatchPeers( s );302 288 303 289 /* Update choking every second */ … … 326 312 * SetPublicPort 327 313 **********************************************************************/ 328 static void SetPublicPort( tr_shared _t* s, int port )329 { 330 tr_handle _t* h = s->h;314 static void SetPublicPort( tr_shared * s, int port ) 315 { 316 tr_handle * h = s->h; 331 317 tr_torrent * tor; 332 318 … … 337 323 } 338 324 325 /*********************************************************************** 326 * AcceptPeers 327 *********************************************************************** 328 * Check incoming connections and add the peers to our local list 329 **********************************************************************/ 339 330 340 331 static void 341 myHandshakeDoneCB( struct tr_peerIo * c, int isConnected, void * unused UNUSED ) 342 { 343 if( isConnected ) 344 fprintf( stderr, "FIXME: add some way to push this connection to the tor\n" ); 345 else 346 tr_peerIoFree( c ); 347 } 348 349 /*********************************************************************** 350 * AcceptPeers 351 *********************************************************************** 352 * Check incoming connections and add the peers to our local list 353 **********************************************************************/ 354 static void AcceptPeers( tr_shared_t * s ) 355 { 356 int socket; 357 struct in_addr addr; 358 332 AcceptPeers( tr_shared * s ) 333 { 359 334 for( ;; ) 360 335 { 361 if( s->bindSocket < 0 || s->peerCount >= MAX_PEER_COUNT ) 362 { 336 int socket; 337 struct in_addr addr; 338 339 if( s->bindSocket < 0 || !tr_peerMgrIsAcceptingConnections( s->h->peerMgr ) ) 363 340 break; 364 }365 341 366 342 socket = tr_netAccept( s->bindSocket, &addr, NULL ); 367 343 if( socket < 0 ) 368 {369 344 break; 370 } 371 372 tr_handshakeAdd( tr_peerIoNewIncoming( s->h, &addr, socket ), 373 HANDSHAKE_ENCRYPTION_PREFERRED, 374 myHandshakeDoneCB, 375 NULL ); 376 } 377 } 378 379 /*********************************************************************** 380 * ReadPeers 381 *********************************************************************** 382 * Try to read handshakes 383 **********************************************************************/ 384 static void ReadPeers( tr_shared_t * s ) 385 { 386 int ii; 387 388 for( ii = 0; ii < s->peerCount; ) 389 { 390 if( tr_peerRead( s->peers[ii] ) ) 391 { 392 tr_peerDestroy( s->peers[ii] ); 393 s->peerCount--; 394 memmove( &s->peers[ii], &s->peers[ii+1], 395 ( s->peerCount - ii ) * sizeof( tr_peer_t * ) ); 396 continue; 397 } 398 ii++; 399 } 400 } 401 402 /*********************************************************************** 403 * DispatchPeers 404 *********************************************************************** 405 * If we got a handshake, try to find the torrent for this peer 406 **********************************************************************/ 407 static void DispatchPeers( tr_shared_t * s ) 408 { 409 tr_handle_t * h = s->h; 410 int ii; 411 const uint64_t now = tr_date(); 412 413 for( ii = 0; ii < s->peerCount; ) 414 { 415 const uint8_t * hash = tr_peerHash( s->peers[ii] ); 416 417 if( !hash && now > tr_peerDate( s->peers[ii] ) + 10000 ) 418 { 419 /* 10 seconds and no handshake, drop it */ 420 tr_peerDestroy( s->peers[ii] ); 421 goto removePeer; 422 } 423 if( hash ) 424 { 425 tr_torrent * tor; 426 427 for( tor = h->torrentList; tor; tor = tor->next ) 428 { 429 tr_torrentWriterLock( tor ); 430 if( tor->runStatus != TR_RUN_RUNNING ) 431 { 432 tr_torrentWriterUnlock( tor ); 433 continue; 434 } 435 436 if( !memcmp( tor->info.hash, hash, SHA_DIGEST_LENGTH ) ) 437 { 438 /* Found it! */ 439 tr_torrentAttachPeer( tor, s->peers[ii] ); 440 tr_torrentWriterUnlock( tor ); 441 goto removePeer; 442 } 443 tr_torrentWriterUnlock( tor ); 444 } 445 446 /* Couldn't find a torrent, we probably removed it */ 447 tr_peerDestroy( s->peers[ii] ); 448 goto removePeer; 449 } 450 ii++; 451 continue; 452 453 removePeer: 454 s->peerCount--; 455 memmove( &s->peers[ii], &s->peers[ii+1], 456 ( s->peerCount - ii ) * sizeof( tr_peer_t * ) ); 457 } 458 } 459 345 346 tr_peerMgrAddIncoming( s->h->peerMgr, &addr, socket ); 347 } 348 } -
branches/encryption/libtransmission/shared.h
r2555 r2954 28 28 #include "transmission.h" 29 29 30 typedef struct tr_shared _s tr_shared_t;30 typedef struct tr_shared tr_shared; 31 31 32 32 /*********************************************************************** … … 36 36 * among the torrents: NAT-PMP/UPnP, incoming connections, peer choking 37 37 **********************************************************************/ 38 tr_shared _t * tr_sharedInit ( tr_handle_t* );39 void tr_sharedClose ( tr_shared_t* );38 tr_shared * tr_sharedInit ( tr_handle * ); 39 void tr_sharedClose ( tr_shared * ); 40 40 41 41 /*********************************************************************** … … 45 45 * thread 46 46 **********************************************************************/ 47 void tr_sharedLock ( tr_shared _t* );48 void tr_sharedUnlock ( tr_shared _t* );47 void tr_sharedLock ( tr_shared * ); 48 void tr_sharedUnlock ( tr_shared * ); 49 49 50 50 /*********************************************************************** … … 54 54 * should be called with the shared lock held. 55 55 **********************************************************************/ 56 void tr_sharedSetPort ( tr_shared _t*, int port );57 int tr_sharedGetPublicPort ( tr_shared _t* s );56 void tr_sharedSetPort ( tr_shared *, int port ); 57 int tr_sharedGetPublicPort ( tr_shared * s ); 58 58 59 59 /*********************************************************************** … … 63 63 * be called with the shared lock held. 64 64 **********************************************************************/ 65 void tr_sharedTraversalEnable ( tr_shared _t*, int enable );66 int tr_sharedTraversalStatus ( tr_shared _t* );65 void tr_sharedTraversalEnable ( tr_shared *, int enable ); 66 int tr_sharedTraversalStatus ( tr_shared * ); 67 67 68 68 /*********************************************************************** … … 71 71 * 72 72 **********************************************************************/ 73 void tr_sharedSetLimit ( tr_shared _t*, int limit );73 void tr_sharedSetLimit ( tr_shared *, int limit ); 74 74 75 75 #endif -
branches/encryption/libtransmission/torrent.c
r2953 r2954 38 38 #include "metainfo.h" 39 39 #include "net.h" /* tr_netNtop */ 40 #include "p.h"41 40 #include "peer.h" 42 #include "peer- io.h"41 #include "peer-mgr.h" 43 42 #include "platform.h" 44 43 #include "ratecontrol.h" … … 53 52 54 53 tr_torrent* 54 tr_torrentFindFromHash( tr_handle * handle, 55 const uint8_t * torrentHash ) 56 { 57 tr_torrent * tor; 58 59 for( tor = handle->torrentList; tor; tor = tor->next ) 60 if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) ) 61 return tor; 62 63 return NULL; 64 } 65 66 tr_torrent* 55 67 tr_torrentFindFromObfuscatedHash( tr_handle * handle, 56 68 const uint8_t * obfuscatedTorrentHash ) … … 148 160 { 149 161 case TR_TRACKER_PEERS: 150 tr_torrentAddCompact( tor, TR_PEER_FROM_TRACKER, 151 event->peerCompact, event->peerCount ); 162 tr_peerMgrAddPeers( tor->handle->peerMgr, 163 tor->info.hash, 164 TR_PEER_FROM_TRACKER, 165 event->peerCompact, 166 event->peerCount ); 152 167 break; 153 168 … … 647 662 if( tor->pexDisabled != disable ) 648 663 { 649 int i;650 664 tor->pexDisabled = disable; 651 for( i=0; i<tor->peerCount; ++i ) 652 tr_peerSetPrivate( tor->peers[i], disable ); 665 tr_peerMgrDisablePex( tor->handle->peerMgr, 666 tor->info.hash, 667 tor->pexDisabled ); 653 668 } 654 669 } … … 701 716 tr_stat_t * s; 702 717 struct tr_tracker * tc; 703 int i;704 718 705 719 tr_torrentReaderLock( tor ); … … 715 729 s->tracker = tr_trackerGetAddress( tor->tracker ); 716 730 717 /* peers... */ 718 memset( s->peersFrom, 0, sizeof( s->peersFrom ) ); 719 s->peersTotal = tor->peerCount; 720 s->peersConnected = 0; 721 s->peersSendingToUs = 0; 722 s->peersGettingFromUs = 0; 723 724 for( i=0; i<tor->peerCount; ++i ) 725 { 726 const tr_peer_t * peer = tor->peers[i]; 727 728 if( tr_peerIsConnected( peer ) ) 729 { 730 ++s->peersConnected; 731 ++s->peersFrom[tr_peerGetFrom(peer)]; 732 733 if( tr_peerDownloadRate( peer ) > 0.01 ) 734 ++s->peersSendingToUs; 735 736 if( tr_peerUploadRate( peer ) > 0.01 ) 737 ++s->peersGettingFromUs; 738 } 739 } 731 tr_peerMgrTorrentStats( tor->handle->peerMgr, 732 tor->info.hash, 733 &s->peersTotal, 734 &s->peersConnected, 735 &s->peersSendingToUs, 736 &s->peersGettingFromUs ); 740 737 741 738 s->percentComplete = tr_cpPercentComplete ( tor->completion ); … … 897 894 tr_torrentPeers( const tr_torrent * tor, int * peerCount ) 898 895 { 899 tr_peer_stat * peers; 900 901 tr_torrentReaderLock( tor ); 902 903 *peerCount = tor->peerCount; 904 905 peers = tr_new0( tr_peer_stat, tor->peerCount ); 906 if (peers != NULL) 907 { 908 tr_peer_t * peer; 909 struct in_addr * addr; 910 int i; 911 for( i=0; i<tor->peerCount; ++i ) 912 { 913 peer = tor->peers[i]; 914 915 addr = tr_peerAddress( peer ); 916 if( NULL != addr ) 917 { 918 tr_netNtop( addr, peers[i].addr, 919 sizeof( peers[i].addr ) ); 920 } 921 922 peers[i].client = tr_peerClient( peer ); 923 peers[i].isConnected = tr_peerIsConnected( peer ); 924 peers[i].from = tr_peerGetFrom( peer ); 925 peers[i].progress = tr_peerProgress( peer ); 926 peers[i].port = tr_peerPort( peer ); 927 928 peers[i].uploadToRate = tr_peerUploadRate( peer ); 929 peers[i].downloadFromRate = tr_peerDownloadRate( peer ); 930 931 peers[i].isDownloading = peers[i].uploadToRate > 0.01; 932 peers[i].isUploading = peers[i].downloadFromRate > 0.01; 933 } 934 } 935 936 tr_torrentReaderUnlock( tor ); 937 938 return peers; 896 return tr_peerMgrPeerStats( tor->handle->peerMgr, 897 tor->info.hash, peerCount ); 939 898 } 940 899 … … 946 905 void tr_torrentAvailability( const tr_torrent * tor, int8_t * tab, int size ) 947 906 { 948 int i, j, piece; 949 float interval; 950 951 tr_torrentReaderLock( tor ); 952 953 interval = (float)tor->info.pieceCount / (float)size; 954 for( i = 0; i < size; i++ ) 955 { 956 piece = i * interval; 957 958 if( tr_cpPieceIsComplete( tor->completion, piece ) ) 959 { 960 tab[i] = -1; 961 continue; 962 } 963 964 tab[i] = 0; 965 for( j = 0; j < tor->peerCount; j++ ) 966 { 967 if( tr_peerHasPiece( tor->peers[j], piece ) ) 968 { 969 (tab[i])++; 970 } 971 } 972 } 973 974 tr_torrentReaderUnlock( tor ); 907 return tr_peerMgrTorrentAvailability( tor->handle->peerMgr, 908 tor->info.hash, 909 tab, size ); 975 910 } 976 911 … … 1033 968 1034 969 970 #if 0 1035 971 int tr_torrentAttachPeer( tr_torrent * tor, tr_peer_t * peer ) 1036 972 { … … 1065 1001 return 1; 1066 1002 } 1067 1068 static void 1069 tr_torrentAddPeerIo( tr_torrent * torrent, 1070 tr_peerIo * io ) 1071 { 1072 tr_peerManagerAdd( torrent, io ); 1073 } 1074 1075 static void 1076 myHandshakeDoneCB( tr_peerIo * io, int isConnected, void * userData UNUSED ) 1077 { 1078 if( isConnected ) 1079 tr_torrentAddPeerIo( tr_peerIoGetTorrent(io), io ); 1080 else 1081 tr_peerIoFree( io ); 1082 } 1083 1084 int tr_torrentAddCompact( tr_torrent * tor, int from UNUSED, 1085 const uint8_t * buf, int count ) 1086 { 1087 struct in_addr addr; 1088 tr_port_t port; 1089 int i, added; 1090 1091 added = 0; 1092 for( i=0; i<count; ++i ) 1093 { 1094 memcpy( &addr, buf, 4 ); buf += 4; 1095 memcpy( &port, buf, 2 ); buf += 2; 1096 1097 tr_handshakeAdd ( 1098 tr_peerIoNewOutgoing( tor->handle, &addr, port, tor ), 1099 HANDSHAKE_ENCRYPTION_PREFERRED, 1100 myHandshakeDoneCB, 1101 NULL ); 1102 1103 //added += tr_torrentAttachPeer( tor, peer ); 1104 } 1105 1106 return added; 1107 } 1003 #endif 1108 1004 1109 1005 /*** … … 1228 1124 if( tor->runStatus == TR_RUN_STOPPING ) 1229 1125 { 1230 int i;1231 1126 tr_torrentWriterLock( tor ); 1232 1127 … … 1237 1132 1238 1133 /* close the peers */ 1239 for( i=0; i<tor->peerCount; ++i ) 1240 tr_peerDestroy( tor->peers[i] ); 1241 tor->peerCount = 0; 1134 tr_peerMgrStopTorrent( tor->handle->peerMgr, tor->info.hash ); 1242 1135 1243 1136 /* resest the transfer rates */ … … 1294 1187 if( tor->runStatus == TR_RUN_RUNNING ) 1295 1188 { 1296 int i;1297 1298 1189 /* starting to run... */ 1299 1190 if( tor->io == NULL ) … … 1307 1198 /* refresh our completion state */ 1308 1199 recheckCpState( tor ); 1309 1310 /* Shuffle peers */1311 if ( tor->peerCount > 1 ) {1312 tr_peer_t * tmp = tor->peers[0];1313 memmove( tor->peers, tor->peers+1,1314 (tor->peerCount-1) * sizeof(void*) );1315 tor->peers[tor->peerCount - 1] = tmp;1316 }1317 1318 /* receive/send messages */1319 tr_torrentWriterLock( tor );1320 for( i=0; i<tor->peerCount; ) {1321 tr_peer_t * peer = tor->peers[i];1322 int ret = tr_peerPulse( peer );1323 if( ret & TR_ERROR_IO_MASK ) {1324 tr_err( "Fatal error, stopping download (%d)", ret );1325 tor->runStatus = TR_RUN_STOPPING;1326 tor->error = ret;1327 strlcpy( tor->errorString,1328 tr_errorString(ret),1329 sizeof(tor->errorString) );1330 break;1331 }1332 if( ret ) {1333 tr_peerDestroy( peer );1334 tor->peerCount--;1335 memmove( &tor->peers[i], &tor->peers[i+1],1336 (tor->peerCount-i)*sizeof(void*) );1337 continue;1338 }1339 i++;1340 }1341 tr_torrentWriterUnlock( tor );1342 1200 } 1343 1201 } -
branches/encryption/libtransmission/tracker.c
r2941 r2954 66 66 tr_handle_t * handle; 67 67 68 tr_ptrArray _t* torrents;69 tr_ptrArray _t* scraping;70 tr_ptrArray _t* scrapeQueue;68 tr_ptrArray * torrents; 69 tr_ptrArray * scraping; 70 tr_ptrArray * scrapeQueue; 71 71 72 72 /* these are set from the latest scrape or tracker response */ … … 182 182 connection_key_t *val, tmp; 183 183 184 static tr_ptrArray _t* connections = NULL;184 static tr_ptrArray * connections = NULL; 185 185 if( !connections ) 186 186 connections = tr_ptrArrayNew( ); … … 253 253 ***/ 254 254 255 static tr_ptrArray _t*255 static tr_ptrArray * 256 256 getTrackerLookupTable( void ) 257 257 { 258 static tr_ptrArray _t* myTrackers = NULL;258 static tr_ptrArray * myTrackers = NULL; 259 259 if( !myTrackers ) 260 260 myTrackers = tr_ptrArrayNew( ); … … 291 291 { 292 292 const tr_info_t * info = &tor->info; 293 tr_ptrArray _t* trackers = getTrackerLookupTable( );293 tr_ptrArray * trackers = getTrackerLookupTable( ); 294 294 Tracker *t, tmp; 295 295 assert( info != NULL ); -
branches/encryption/libtransmission/transmission.c
r2944 r2954 38 38 #include "list.h" 39 39 #include "net.h" 40 #include "peer-mgr.h" 40 41 #include "platform.h" 41 42 #include "ratecontrol.h" … … 94 95 } 95 96 97 h->peerMgr = tr_peerMgrNew( h ); 96 98 97 99 /* Azureus identity */ … … 141 143 } 142 144 143 tr_handle_status _t* tr_handleStatus( tr_handle_t * h )144 { 145 tr_handle_status _t* s;145 tr_handle_status * tr_handleStatus( tr_handle_t * h ) 146 { 147 tr_handle_status * s; 146 148 147 149 h->statCur = ( h->statCur + 1 ) % 2; … … 238 240 tr_rcClose( h->upload ); 239 241 tr_rcClose( h->download ); 240 241 tr_ eventClose( h);242 243 tr_peerMgrFree( h->peerMgr ); 242 244 tr_sharedClose( h->shared ); 243 245 tr_fdClose(); 246 tr_eventClose( h ); 244 247 free( h->tag ); 245 248 free( h ); -
branches/encryption/libtransmission/transmission.h
r2949 r2954 104 104 typedef struct tr_handle tr_handle; 105 105 typedef struct tr_handle tr_handle_t; 106 tr_handle _t* tr_init( const char * tag );106 tr_handle * tr_init( const char * tag ); 107 107 108 108 typedef struct tr_tracker_info_s tr_tracker_info_t; … … 149 149 * This can be safely called even with active torrents. 150 150 **********************************************************************/ 151 void tr_setBindPort( tr_handle _t*, int );152 153 int tr_getPublicPort( const tr_handle _t* );151 void tr_setBindPort( tr_handle *, int ); 152 153 int tr_getPublicPort( const tr_handle * ); 154 154 155 155 /*********************************************************************** … … 159 159 * Enable or disable NAT traversal using NAT-PMP or UPnP IGD. 160 160 **********************************************************************/ 161 void tr_natTraversalEnable( tr_handle _t*, int enable );161 void tr_natTraversalEnable( tr_handle *, int enable ); 162 162 163 163 /*********************************************************************** … … 166 166 * Returns some status info for the given handle. 167 167 **********************************************************************/ 168 typedef struct tr_handle_status_s tr_handle_status_t; 169 tr_handle_status_t * tr_handleStatus( tr_handle_t * ); 168 typedef struct tr_handle_status tr_handle_status; 169 typedef struct tr_handle_status tr_handle_status_t; 170 tr_handle_status * tr_handleStatus( tr_handle * ); 170 171 171 172 … … 175 176 * Returns the count of open torrents 176 177 **********************************************************************/ 177 int tr_torrentCount( tr_handle _t* h );178 int tr_torrentCount( tr_handle * h ); 178 179 179 180 … … 186 187 typedef struct tr_torrent tr_torrent_t; 187 188 typedef void (*tr_callback_t) ( tr_torrent *, void * ); 188 void tr_torrentIterate( tr_handle _t*, tr_callback_t, void * );189 void tr_torrentIterate( tr_handle *, tr_callback_t, void * ); 189 190 190 191 … … 217 218 int up_or_down ); 218 219 219 void tr_setUseGlobalSpeedLimit( tr_handle _t* handle,220 void tr_setUseGlobalSpeedLimit( tr_handle * handle, 220 221 int up_or_down, 221 222 int use_flag ); 222 223 223 void tr_setGlobalSpeedLimit( tr_handle _t* handle,224 void tr_setGlobalSpeedLimit( tr_handle * handle, 224 225 int up_or_down, 225 226 int global_KiB_sec ); 226 227 227 void tr_getGlobalSpeedLimit( tr_handle _t* handle,228 void tr_getGlobalSpeedLimit( tr_handle * handle, 228 229 int up_or_down, 229 230 int * setme_is_enabled, … … 280 281 * Gets the total download and upload rates 281 282 **********************************************************************/ 282 void tr_torrentRates( tr_handle _t*, float *, float * );283 void tr_torrentRates( tr_handle *, float *, float * ); 283 284 284 285 /*********************************************************************** … … 287 288 * Frees memory allocated by tr_init. 288 289 **********************************************************************/ 289 void tr_close( tr_handle _t* );290 void tr_close( tr_handle * ); 290 291 291 292 … … 296 297 * from the previous session. 297 298 */ 298 tr_torrent ** tr_loadTorrents ( tr_handle _t* h,299 tr_torrent ** tr_loadTorrents ( tr_handle * h, 299 300 const char * destination, 300 301 int flags, … … 316 317 #define TR_EDUPLICATE 3 317 318 #define TR_EOTHER 666 318 tr_torrent * tr_torrentInit( tr_handle _t* handle,319 tr_torrent * tr_torrentInit( tr_handle * handle, 319 320 const char * metainfo_filename, 320 321 const char * destination, … … 340 341 * call tr_metainfoFree( setme_info ) when done with it. 341 342 */ 342 int tr_torrentParse( const tr_handle _t* handle,343 int tr_torrentParse( const tr_handle * handle, 343 344 const char * metainfo_filename, 344 345 const char * destination, … … 350 351 */ 351 352 int 352 tr_torrentParseHash( const tr_handle _t* h,353 tr_torrentParseHash( const tr_handle * h, 353 354 const char * hashStr, 354 355 const char * destination, … … 362 363 * instead of the filename. 363 364 **********************************************************************/ 364 tr_torrent * tr_torrentInitData( tr_handle _t*,365 tr_torrent * tr_torrentInitData( tr_handle *, 365 366 const uint8_t * data, size_t size, 366 367 const char * destination, … … 374 375 * are currently no valid flags for this function. 375 376 **********************************************************************/ 376 tr_torrent * tr_torrentInitSaved( tr_handle _t*,377 tr_torrent * tr_torrentInitSaved( tr_handle *, 377 378 const char * hashStr, 378 379 const char * destination, … … 685 686 }; 686 687 687 struct tr_handle_status _s688 struct tr_handle_status 688 689 { 689 690 #define TR_NAT_TRAVERSAL_MAPPING 1 -
branches/encryption/libtransmission/trevent.c
r2946 r2954 45 45 ***/ 46 46 47 typedef struct tr_event_handle _s47 typedef struct tr_event_handle 48 48 { 49 49 int fds[2];
Note: See TracChangeset
for help on using the changeset viewer.