Changeset 1060
- Timestamp:
- Nov 9, 2006, 4:45:14 AM (16 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/fastresume.h
r931 r1060 51 51 /* number of bytes uploaded */ 52 52 #define FR_ID_UPLOADED 0x03 53 /* IPs and ports of connectable peers */ 54 #define FR_ID_PEERS 0x04 53 55 54 56 /* macros for the length of various pieces of the progress data */ … … 127 129 uint8_t * buf; 128 130 uint64_t total; 131 int size; 129 132 130 133 buf = malloc( FR_PROGRESS_LEN( tor ) ); … … 167 170 total = tor->uploadedCur + tor->uploadedPrev; 168 171 fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file ); 172 173 /* Write IPs and ports of connectable peers, if any */ 174 if( ( size = tr_peerGetConnectable( tor, &buf ) ) > 0 ) 175 { 176 fastResumeWriteData( FR_ID_PEERS, buf, size, 1, file ); 177 free( buf ); 178 } 169 179 170 180 fclose( file ); … … 359 369 break; 360 370 371 case FR_ID_PEERS: 372 { 373 uint8_t * buf = malloc( len ); 374 if( 1 != fread( buf, len, 1, file ) ) 375 { 376 free( buf ); 377 fclose( file ); 378 return 1; 379 } 380 tr_peerAddCompactMany( tor, buf, len ); 381 free( buf ); 382 continue; 383 } 384 361 385 default: 362 386 break; -
trunk/libtransmission/peer.c
r931 r1060 152 152 153 153 /*********************************************************************** 154 * tr_peerAddCompactMany 155 *********************************************************************** 156 * Adds several peers in compact form 157 **********************************************************************/ 158 void tr_peerAddCompactMany( tr_torrent_t * tor, uint8_t * buf, int len ) 159 { 160 struct in_addr addr; 161 in_port_t port; 162 int i; 163 164 len /= 6; 165 for( i = 0; i < len; i++ ) 166 { 167 memcpy( &addr, buf, 4 ); buf += 4; 168 memcpy( &port, buf, 2 ); buf += 2; 169 tr_peerAddCompact( tor, addr, port ); 170 } 171 } 172 173 /*********************************************************************** 154 174 * tr_peerInit 155 175 *********************************************************************** … … 617 637 tr_bitfieldRem( peer->blamefield, piece ); 618 638 } 639 640 int tr_peerGetConnectable( tr_torrent_t * tor, uint8_t ** _buf ) 641 { 642 int count = 0; 643 uint8_t * buf = malloc( 6 * tor->peerCount ); 644 tr_peer_t * peer; 645 int i; 646 647 for( i = 0; i < tor->peerCount; i++ ) 648 { 649 peer = tor->peers[i]; 650 651 /* Skip peers for which the connection isn't established, 652 * and peers that came from incoming connections */ 653 if( peer->status < PEER_STATUS_CONNECTED ) 654 continue; 655 if( peer->incoming ) 656 continue; 657 658 memcpy( &buf[count*6], &peer->addr, 4 ); 659 memcpy( &buf[count*6+4], &peer->port, 2 ); 660 count++; 661 } 662 663 if( count < 1 ) 664 { 665 free( buf ); 666 *_buf = NULL; 667 } 668 else 669 { 670 *_buf = buf; 671 } 672 673 return count * 6; 674 } -
trunk/libtransmission/peer.h
r932 r1060 30 30 void tr_peerAddOld ( tr_torrent_t *, char *, int ); 31 31 void tr_peerAddCompact ( tr_torrent_t *, struct in_addr, in_port_t ); 32 void tr_peerAddCompactMany( tr_torrent_t *, uint8_t *, int ); 32 33 tr_peer_t * tr_peerInit ( struct in_addr, in_port_t, int ); 33 34 void tr_peerAttach ( tr_torrent_t *, tr_peer_t * ); … … 55 56 int piece, int success ); 56 57 struct in_addr * tr_peerAddress ( tr_peer_t * ); 58 int tr_peerGetConnectable( tr_torrent_t *, uint8_t ** ); 57 59 58 60 #endif
Note: See TracChangeset
for help on using the changeset viewer.