Changeset 3759
- Timestamp:
- Nov 8, 2007, 9:20:08 PM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/handshake.c
r3753 r3759 90 90 unsigned int havePeerID : 1; 91 91 unsigned int haveSentBitTorrentHandshake : 1; 92 unsigned int allowUnencryptedPeers : 1;93 92 tr_peerIo * io; 94 93 tr_crypto * crypto; … … 97 96 uint8_t mySecret[KEY_LEN]; 98 97 uint8_t state; 98 tr_encryption_mode encryptionMode; 99 99 uint16_t pad_c_len; 100 100 uint16_t pad_d_len; … … 325 325 326 326 static uint32_t 327 getCryptoProvide( const tr_handshake * handshake UNUSED ) 328 { 329 uint32_t i = 0; 330 331 i |= CRYPTO_PROVIDE_CRYPTO; /* always allow crypto */ 332 333 #if 0 334 /* by the time we send a crypto_provide, we _know_ 335 * the peer supports encryption. */ 336 if( handshake->allowUnencryptedPeers ) 337 i |= CRYPTO_PROVIDE_PLAINTEXT; 338 #endif 339 340 return i; 327 getCryptoProvide( const tr_handshake * handshake ) 328 { 329 uint32_t provide = 0; 330 331 switch( handshake->encryptionMode ) 332 { 333 case TR_ENCRYPTION_REQUIRED: 334 case TR_ENCRYPTION_PREFERRED: 335 provide |= CRYPTO_PROVIDE_CRYPTO; 336 break; 337 338 case TR_PLAINTEXT_PREFERRED: 339 provide |= CRYPTO_PROVIDE_CRYPTO | CRYPTO_PROVIDE_PLAINTEXT; 340 break; 341 } 342 343 return provide; 344 } 345 346 static uint32_t 347 getCryptoSelect( const tr_handshake * handshake, uint32_t crypto_provide ) 348 { 349 uint32_t choices[4]; 350 int i, nChoices=0; 351 352 switch( handshake->encryptionMode ) 353 { 354 case TR_ENCRYPTION_REQUIRED: 355 choices[nChoices++] = CRYPTO_PROVIDE_CRYPTO; 356 break; 357 358 case TR_ENCRYPTION_PREFERRED: 359 choices[nChoices++] = CRYPTO_PROVIDE_CRYPTO; 360 choices[nChoices++] = CRYPTO_PROVIDE_PLAINTEXT; 361 break; 362 363 case TR_PLAINTEXT_PREFERRED: 364 choices[nChoices++] = CRYPTO_PROVIDE_PLAINTEXT; 365 choices[nChoices++] = CRYPTO_PROVIDE_CRYPTO; 366 break; 367 } 368 369 for( i=0; i<nChoices; ++i ) 370 if( crypto_provide & choices[i] ) 371 return choices[i]; 372 373 return 0; 341 374 } 342 375 … … 545 578 tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_NONE ); 546 579 547 if( !handshake->allowUnencryptedPeers)580 if( handshake->encryptionMode == TR_ENCRYPTION_REQUIRED ) 548 581 { 549 582 dbgmsg( handshake, "peer is unencrypted, and we're disallowing that" ); … … 841 874 } 842 875 843 dbgmsg( handshake, "sending crypto_select" );844 876 /* send crypto_select */ 845 { 846 dbgmsg( handshake, "handshake->crypto_provide is %d", (int)handshake->crypto_provide ); 847 if( handshake->crypto_provide & CRYPTO_PROVIDE_CRYPTO ) 848 crypto_select = CRYPTO_PROVIDE_CRYPTO; 849 else if( handshake->allowUnencryptedPeers ) 850 crypto_select = CRYPTO_PROVIDE_PLAINTEXT; 851 else { 852 dbgmsg( handshake, "gronk..." ); 853 evbuffer_free( outbuf ); 854 tr_handshakeDone( handshake, FALSE ); 855 return READ_DONE; 856 } 857 858 dbgmsg( handshake, "we select crypto_select as %d...", (int)crypto_select ); 877 crypto_select = getCryptoSelect( handshake, handshake->crypto_provide ); 878 if( crypto_select ) { 879 dbgmsg( handshake, "selecting crypto mode '%d'", (int)crypto_select ); 859 880 tr_peerIoWriteUint32( handshake->io, outbuf, crypto_select ); 881 } else { 882 dbgmsg( handshake, "peer didn't offer an encryption mode we like." ); 883 evbuffer_free( outbuf ); 884 tr_handshakeDone( handshake, FALSE ); 885 return READ_DONE; 860 886 } 861 887 … … 965 991 * try a plaintext handshake */ 966 992 if( ( ( handshake->state == AWAITING_YB ) || ( handshake->state == AWAITING_VC ) ) 967 && ( handshake-> allowUnencryptedPeers)993 && ( handshake->encryptionMode != TR_ENCRYPTION_REQUIRED ) 968 994 && ( !tr_peerIoReconnect( handshake->io ) ) ) 969 995 { … … 991 1017 tr_handshake* 992 1018 tr_handshakeNew( tr_peerIo * io, 993 tr_encryption_mode encryption _mode,1019 tr_encryption_mode encryptionMode, 994 1020 handshakeDoneCB doneCB, 995 1021 void * doneUserData ) … … 1000 1026 handshake->io = io; 1001 1027 handshake->crypto = tr_peerIoGetCrypto( io ); 1002 handshake-> allowUnencryptedPeers = encryption_mode!=TR_ENCRYPTION_REQUIRED;1028 handshake->encryptionMode = encryptionMode; 1003 1029 handshake->doneCB = doneCB; 1004 1030 handshake->doneUserData = doneUserData; … … 1010 1036 if( tr_peerIoIsIncoming( handshake->io ) ) 1011 1037 setReadState( handshake, AWAITING_HANDSHAKE ); 1012 else 1038 else if( encryptionMode != TR_PLAINTEXT_PREFERRED ) 1013 1039 sendYa( handshake ); 1040 else { 1041 int msgSize; 1042 uint8_t * msg = buildHandshakeMessage( handshake, &msgSize ); 1043 handshake->haveSentBitTorrentHandshake = 1; 1044 setReadState( handshake, AWAITING_HANDSHAKE ); 1045 tr_peerIoWrite( handshake->io, msg, msgSize ); 1046 tr_free( msg ); 1047 } 1014 1048 1015 1049 return handshake; -
trunk/libtransmission/transmission.h
r3666 r3759 117 117 typedef enum 118 118 { 119 TR_PLAINTEXT_PREFERRED, 119 120 TR_ENCRYPTION_PREFERRED, 120 121 TR_ENCRYPTION_REQUIRED
Note: See TracChangeset
for help on using the changeset viewer.