1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

(1) fix choke/unchoke error. (2) if a peer keeps trying to reconnect to us, hang up during the handshake.

This commit is contained in:
Charles Kerr 2008-04-17 03:48:56 +00:00
parent 62709b7ca2
commit ea9e0b260f
4 changed files with 44 additions and 4 deletions

View file

@ -26,6 +26,7 @@
#include "crypto.h"
#include "handshake.h"
#include "peer-io.h"
#include "peer-mgr.h"
#include "torrent.h"
#include "trevent.h"
#include "utils.h"
@ -810,11 +811,22 @@ readCryptoProvide( tr_handshake * handshake, struct evbuffer * inbuf )
tr_sha1( req3, "req3", 4, handshake->mySecret, KEY_LEN, NULL );
for( i=0; i<SHA_DIGEST_LENGTH; ++i )
obfuscatedTorrentHash[i] = req2[i] ^ req3[i];
tor = tr_torrentFindFromObfuscatedHash( handshake->handle, obfuscatedTorrentHash );
if( tor != NULL ) {
if(( tor = tr_torrentFindFromObfuscatedHash( handshake->handle, obfuscatedTorrentHash )))
{
dbgmsg( handshake, "found the torrent; it's [%s]", tor->info.name );
tr_peerIoSetTorrentHash( handshake->io, tor->info.hash );
} else {
if( !tr_torrentAllowsPex( tor ) &&
tr_peerMgrPeerIsSeed( handshake->handle->peerMgr,
tor->info.hash,
tr_peerIoGetAddress( handshake->io, NULL )))
{
dbgmsg( handshake, "a peer has tried to reconnect to us!" );
tr_handshakeDone( handshake, FALSE );
return READ_DONE;
}
}
else
{
dbgmsg( handshake, "can't find that torrent..." );
tr_handshakeDone( handshake, FALSE );
return READ_DONE;

View file

@ -558,6 +558,28 @@ clientIsUploadingTo( const tr_peer * peer )
return peer->peerIsInterested && !peer->peerIsChoked;
}
/***
****
***/
int
tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,
const uint8_t * torrentHash,
const struct in_addr * addr )
{
int isSeed = FALSE;
const Torrent * t = NULL;
const struct peer_atom * atom = NULL;
t = getExistingTorrent( (tr_peerMgr*)mgr, torrentHash );
if( t )
atom = getExistingAtom( t, addr );
if( atom )
isSeed = ( atom->flags & ADDED_F_SEED_FLAG ) != 0;
return isSeed;
}
/***
**** Refill
***/

View file

@ -41,6 +41,10 @@ tr_peerMgr* tr_peerMgrNew( struct tr_handle * );
void tr_peerMgrFree( tr_peerMgr * manager );
int tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,
const uint8_t * torrentHash,
const struct in_addr * addr );
void tr_peerMgrAddIncoming( tr_peerMgr * manager,
struct in_addr * addr,
uint16_t port,

View file

@ -1278,12 +1278,14 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
case BT_BITFIELD: {
const int clientIsSeed = tr_torrentIsSeed( msgs->torrent );
int peerIsSeed;
dbgmsg( msgs, "got a bitfield" );
msgs->peerSentBitfield = 1;
tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen );
updatePeerProgress( msgs );
maybeSendFastAllowedSet( msgs );
tr_peerMsgsSetChoke( msgs, !clientIsSeed || (msgs->info->progress<1.0) );
peerIsSeed = msgs->info->progress >= 1.0;
tr_peerMsgsSetChoke( msgs, clientIsSeed && peerIsSeed );
fireNeedReq( msgs );
break;
}