Changeset 3104
- Timestamp:
- Sep 20, 2007, 3:59:48 PM (16 years ago)
- Location:
- branches/encryption/libtransmission
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/encryption/libtransmission/handshake.c
r3101 r3104 39 39 ***/ 40 40 41 #define HANDSHAKE_NAME "\023BitTorrent protocol" 42 #define HANDSHAKE_NAME_LEN 20 43 #define HANDSHAKE_FLAGS_LEN 8 44 #define HANDSHAKE_SIZE 68 45 46 /*** 47 **** 48 ***/ 41 #define HANDSHAKE_NAME "\023BitTorrent protocol" 49 42 50 43 enum 51 44 { 45 /* BitTorrent Handshake Constants */ 46 HANDSHAKE_NAME_LEN = 20, 47 HANDSHAKE_FLAGS_LEN = 8, 48 HANDSHAKE_SIZE = 68, 49 PEER_ID_LEN = 20, 50 51 /* Extension Negotiation Constants */ 52 52 HANDSHAKE_EXTPREF_LTEP_FORCE = 0x0, 53 53 HANDSHAKE_EXTPREF_LTEP_PREFER = 0x1, 54 54 HANDSHAKE_EXTPREF_AZMP_PREFER = 0x2, 55 HANDSHAKE_EXTPREF_AZMP_FORCE = 0x3 55 HANDSHAKE_EXTPREF_AZMP_FORCE = 0x3, 56 57 /* Encryption Constants */ 58 PadA_MAXLEN = 512, 59 PadB_MAXLEN = 512, 60 PadC_MAXLEN = 512, 61 PadD_MAXLEN = 512, 62 VC_LENGTH = 8, 63 KEY_LEN = 96 56 64 }; 57 65 … … 78 86 #define HANDSHAKE_GET_EXTPREF( reserved ) ( (reserved)[5] & 0x03 ) 79 87 #define HANDSHAKE_SET_EXTPREF( reserved, val ) ( (reserved)[5] |= 0x03 & (val) ) 80 #define HANDSHAKE_EXTPREF_LTEP_FORCE ( 0x0 )81 #define HANDSHAKE_EXTPREF_LTEP_PREFER ( 0x1 )82 #define HANDSHAKE_EXTPREF_AZMP_PREFER ( 0x2 )83 #define HANDSHAKE_EXTPREF_AZMP_FORCE ( 0x3 )84 85 enum86 {87 PadA_MAXLEN = 512,88 PadB_MAXLEN = 512,89 PadC_MAXLEN = 512,90 PadD_MAXLEN = 51291 };92 88 93 89 extern const char* getPeerId( void ) ; 94 95 #define KEY_LEN 9696 #define VC_LENGTH 897 90 98 91 struct tr_handshake … … 105 98 tr_crypto * crypto; 106 99 struct tr_handle * handle; 107 uint8_t myPublicKey[ 96];108 uint8_t mySecret[ 96];100 uint8_t myPublicKey[KEY_LEN]; 101 uint8_t mySecret[KEY_LEN]; 109 102 uint8_t state; 110 103 uint16_t pad_c_len; … … 113 106 uint32_t crypto_select; 114 107 uint8_t myReq1[SHA_DIGEST_LENGTH]; 115 uint8_t peer_id[ 20];108 uint8_t peer_id[PEER_ID_LEN]; 116 109 handshakeDoneCB doneCB; 117 110 void * doneUserData; … … 496 489 uint8_t pstrlen; 497 490 uint8_t * pstr; 498 uint8_t reserved[ 8];491 uint8_t reserved[HANDSHAKE_FLAGS_LEN]; 499 492 uint8_t hash[SHA_DIGEST_LENGTH]; 500 493 … … 503 496 if( EVBUFFER_LENGTH(inbuf) < HANDSHAKE_SIZE ) 504 497 return READ_MORE; 505 506 for( i=0; i<(int)EVBUFFER_LENGTH(inbuf); ++i )507 fprintf( stderr, "[%c]", EVBUFFER_DATA(inbuf)[i] );508 fprintf( stderr, "\n" );509 498 510 499 pstrlen = EVBUFFER_DATA(inbuf)[0]; /* peek, don't read. We may be … … 583 572 tr_peerIoSetPeersId( handshake->io, handshake->peer_id ); 584 573 handshake->havePeerID = TRUE; 574 dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, handshake->peer_id ); 575 if( !memcmp( handshake->peer_id, getPeerId(), PEER_ID_LEN ) ) { 576 dbgmsg( handshake, "streuth! we've connected to ourselves." ); 577 tr_handshakeDone( handshake, FALSE ); 578 return READ_DONE; 579 } 585 580 586 581 /** … … 890 885 return handshake; 891 886 } 887 888 const struct in_addr * 889 tr_handshakeGetAddr( const struct tr_handshake * handshake, uint16_t * port ) 890 { 891 assert( handshake != NULL ); 892 assert( handshake->io != NULL ); 893 894 return tr_peerIoGetAddress( handshake->io, port ); 895 } 896 897 -
branches/encryption/libtransmission/handshake.h
r3101 r3104 16 16 #include "transmission.h" 17 17 18 struct in_addr; 18 19 struct tr_peerIo; 19 20 typedef struct tr_handshake tr_handshake; … … 31 32 void * doneUserData ); 32 33 34 const struct in_addr * tr_handshakeGetAddr( const struct tr_handshake * handshake, 35 uint16_t * setme_port ); 36 33 37 void tr_handshakeAbort( tr_handshake * handshake ); 34 38 -
branches/encryption/libtransmission/peer-mgr.c
r3101 r3104 71 71 72 72 static int 73 handshakeCompareToAddr( const void * va, const void * vb ) 74 { 75 const tr_handshake * a = va; 76 const struct in_addr * b = vb; 77 return memcmp( tr_handshakeGetAddr( a, NULL ), b, sizeof( struct in_addr ) ); 78 } 79 80 static int 81 handshakeCompare( const void * va, const void * vb ) 82 { 83 const tr_handshake * a = va; 84 const tr_handshake * b = vb; 85 return memcmp( tr_handshakeGetAddr( a, NULL ), 86 tr_handshakeGetAddr( b, NULL ), 87 sizeof( struct in_addr ) ); 88 } 89 90 static tr_handshake* 91 getExistingHandshake( tr_peerMgr * mgr, const struct in_addr * in_addr ) 92 { 93 return tr_ptrArrayFindSorted( mgr->handshakes, 94 in_addr, 95 handshakeCompareToAddr ); 96 } 97 98 /** 99 *** 100 **/ 101 102 static int 73 103 torrentCompare( const void * va, const void * vb ) 74 104 { 75 const Torrent * a = (const Torrent*)va;76 const Torrent * b = (const Torrent*)vb;105 const Torrent * a = va; 106 const Torrent * b = vb; 77 107 return memcmp( a->hash, b->hash, SHA_DIGEST_LENGTH ); 78 108 } … … 546 576 ours = tr_ptrArrayRemoveSorted( manager->handshakes, 547 577 handshake, 548 tr_comparePointers);578 handshakeCompare ); 549 579 assert( handshake == ours ); 550 580 … … 609 639 ++manager->connectionCount; 610 640 611 tr_ptrArrayInsertSorted( manager->handshakes, handshake, tr_comparePointers);641 tr_ptrArrayInsertSorted( manager->handshakes, handshake, handshakeCompare ); 612 642 } 613 643 … … 617 647 int socket ) 618 648 { 619 tr_peerIo * io = tr_peerIoNewIncoming( manager->handle, addr, socket ); 620 initiateHandshake( manager, io ); 649 if( getExistingHandshake( manager, addr ) == NULL ) 650 { 651 tr_peerIo * io = tr_peerIoNewIncoming( manager->handle, addr, socket ); 652 initiateHandshake( manager, io ); 653 } 621 654 } 622 655 … … 636 669 if( !t->isRunning ) { /* torrent's not running */ 637 670 fprintf( stderr, "OUTGOING connection not being made because t [%s] is not running\n", t->tor->info.name ); 671 return; 672 } 673 if( getExistingHandshake( manager, &peer->in_addr ) != NULL ) { /* already have a handshake pending */ 674 fprintf( stderr, "already have a handshake for that address\n" ); 638 675 return; 639 676 } -
branches/encryption/libtransmission/utils.c
r3090 r3104 333 333 } 334 334 335 int336 tr_comparePointers( const void * a, const void * b )337 {338 return a - b;339 }340 341 335 /** 342 336 *** -
branches/encryption/libtransmission/utils.h
r3049 r3104 155 155 int tr_compareUint64( uint64_t a, uint64_t b ); 156 156 157 int tr_comparePointers( const void * a, const void * b );158 159 157 /*** 160 158 ****
Note: See TracChangeset
for help on using the changeset viewer.