Changeset 12121
- Timestamp:
- Mar 10, 2011, 12:35:23 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/handshake.c
r11954 r12121 51 51 HANDSHAKE_FLAGS_LEN = 8, 52 52 HANDSHAKE_SIZE = 68, 53 PEER_ID_LEN = 20,54 53 INCOMING_HANDSHAKE_LEN = 48, 55 54 … … 219 218 const uint8_t * torrentHash = tr_cryptoGetTorrentHash( handshake->crypto ); 220 219 const tr_torrent * tor = tr_torrentFindFromHash( handshake->session, torrentHash ); 221 const uint8_t * peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId();220 const uint8_t * peer_id = tor ? tor->peer_id : tr_getPeerId( handshake->session ); 222 221 223 222 memcpy( walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN ); … … 299 298 300 299 tor = tr_torrentFindFromHash( handshake->session, hash ); 301 tor_peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId();300 tor_peer_id = tor ? tor->peer_id : tr_getPeerId( handshake->session ); 302 301 if( !memcmp( peer_id, tor_peer_id, PEER_ID_LEN ) ) 303 302 { … … 742 741 /* if we've somehow connected to ourselves, don't keep the connection */ 743 742 tor = tr_torrentFindFromHash( handshake->session, tr_peerIoGetTorrentHash( handshake->io ) ); 744 tor_peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId();743 tor_peer_id = tor ? tor->peer_id : tr_getPeerId( handshake->session ); 745 744 peerIsGood = memcmp( peer_id, tor_peer_id, PEER_ID_LEN ) != 0; 746 745 dbgmsg( handshake, "isPeerGood == %d", (int)peerIsGood ); -
trunk/libtransmission/session.c
r12103 r12121 82 82 minor version number, z is the maintenance number, and b 83 83 designates beta (Azureus-style) */ 84 uint8_t* 85 tr_peerId New( void)84 void 85 tr_peerIdInit( uint8_t * buf ) 86 86 { 87 87 int i; 88 88 int val; 89 89 int total = 0; 90 uint8_t * buf = tr_new( uint8_t, 21 );91 90 const char * pool = "0123456789abcdefghijklmnopqrstuvwxyz"; 92 91 const int base = 36; … … 104 103 buf[19] = pool[val]; 105 104 buf[20] = '\0'; 106 107 return buf;108 }109 110 const uint8_t*111 tr_getPeerId( void )112 {113 static uint8_t * id = NULL;114 115 if( id == NULL )116 id = tr_peerIdNew( );117 return id;118 105 } 119 106 … … 581 568 session->magicNumber = SESSION_MAGIC_NUMBER; 582 569 session->buffer = tr_valloc( SESSION_BUFFER_SIZE ); 570 tr_peerIdInit( session->peer_id ); 583 571 tr_bencInitList( &session->removedTorrents, 0 ); 584 572 -
trunk/libtransmission/session.h
r12059 r12121 34 34 typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; 35 35 36 uint8_t* tr_peerIdNew( void ); 37 38 const uint8_t* tr_getPeerId( void ); 36 enum 37 { 38 PEER_ID_LEN = 20 39 }; 40 41 void tr_peerIdInit( uint8_t * setme ); 39 42 40 43 struct event_base; … … 207 210 208 211 tr_web_config_func * curl_easy_config_func; 212 213 uint8_t peer_id[PEER_ID_LEN+1]; 209 214 }; 210 215 … … 213 218 { 214 219 return session->public_peer_port; 220 } 221 222 static inline const uint8_t* 223 tr_getPeerId( tr_session * session ) 224 { 225 return session->peer_id; 215 226 } 216 227 -
trunk/libtransmission/test-peer-id.c
r8233 r12121 36 36 int i; 37 37 int test = 0; 38 uint8_t peer_id[PEER_ID_LEN+1]; 38 39 39 40 for( i = 0; i < 100000; ++i ) 40 41 { 41 int j; 42 int val = 0; 43 uint8_t * pch = tr_peerIdNew( ); 42 int j; 43 int val = 0; 44 44 45 check( strlen( (char*)pch ) == 20 ); 46 check( !memcmp( pch, PEERID_PREFIX, 8 ) ); 45 tr_peerIdInit( peer_id ); 47 46 48 for( j = 8; j < 20; ++j ) 47 check( strlen( (char*)peer_id ) == PEER_ID_LEN ); 48 check( !memcmp( peer_id, PEERID_PREFIX, 8 ) ); 49 50 for( j = 8; j < PEER_ID_LEN; ++j ) 49 51 { 50 char tmp[2] = { p ch[j], '\0' };52 char tmp[2] = { peer_id[j], '\0' }; 51 53 val += strtoul( tmp, NULL, 36 ); 52 54 } 53 55 54 56 check( ( val % 36 ) == 0 ); 55 56 tr_free( pch );57 57 } 58 58 -
trunk/libtransmission/torrent.c
r12096 r12121 1509 1509 tr_free( tor->downloadDir ); 1510 1510 tr_free( tor->incompleteDir ); 1511 tr_free( tor->peer_id );1512 1511 1513 1512 if( tor == session->torrentList ) … … 1618 1617 * change the peerid. It would help sometimes if a stopped event 1619 1618 * was missed to ensure that we didn't think someone was cheating. */ 1620 tr_free( tor->peer_id ); 1621 tor->peer_id = tr_peerIdNew( ); 1619 tr_peerIdInit( tor->peer_id ); 1622 1620 tor->isRunning = 1; 1623 1621 tr_torrentSetDirty( tor ); -
trunk/libtransmission/torrent.h
r12096 r12121 158 158 * and in the handshake are expected to match. 159 159 */ 160 uint8_t * peer_id;160 uint8_t peer_id[PEER_ID_LEN+1]; 161 161 162 162 /* Where the files will be when it's complete */
Note: See TracChangeset
for help on using the changeset viewer.