1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

add pass subscription info into the peer-msgs constructor so that we can start getting information immediately

This commit is contained in:
Charles Kerr 2007-10-03 04:04:34 +00:00
parent 0f550043fd
commit 3d2e3cfdfb
3 changed files with 56 additions and 48 deletions

View file

@ -918,10 +918,9 @@ myHandshakeDoneCB( tr_handshake * handshake,
} else {
peer->port = port;
peer->io = io;
peer->msgs = tr_peerMsgsNew( t->tor, peer );
peer->msgs = tr_peerMsgsNew( t->tor, peer, msgsCallbackFunc, t, &peer->msgsTag );
tr_free( peer->client );
peer->client = peer_id ? tr_clientForId( peer_id ) : NULL;
peer->msgsTag = tr_peerMsgsSubscribe( peer->msgs, msgsCallbackFunc, t );
}
}
@ -1578,11 +1577,11 @@ reconnectPulse( void * vtorrent )
struct tr_connection * connections = getWeakConnections( t, &nWeak );
const int peerCount = tr_ptrArraySize( t->peers );
tordbg( t, "RECONNECT pulse for [%s]: %d weak connections, %d connection candidates, %d atoms, max per pulse is %d\n",
tordbg( t, "RECONNECT pulse for [%s]: %d weak connections, %d connection candidates, %d atoms, max per pulse is %d",
t->tor->info.name, nWeak, nCandidates, tr_ptrArraySize(t->pool), (int)MAX_RECONNECTIONS_PER_PULSE );
for( i=0; i<nWeak; ++i )
tordbg( t, "connection #%d: %s @ %.2f\n", i+1,
tordbg( t, "connection #%d: %s @ %.2f", i+1,
tr_peerIoAddrStr( &connections[i].peer->in_addr, connections[i].peer->port ), connections[i].throughput );
/* disconnect some peers */

View file

@ -1459,86 +1459,91 @@ pexPulse( void * vpeer )
**/
tr_peermsgs*
tr_peerMsgsNew( struct tr_torrent * torrent, struct tr_peer * info )
tr_peerMsgsNew( struct tr_torrent * torrent,
struct tr_peer * info,
tr_delivery_func func,
void * userData,
tr_publisher_tag * setme )
{
tr_peermsgs * msgs;
tr_peermsgs * m;
assert( info != NULL );
assert( info->io != NULL );
msgs = tr_new0( tr_peermsgs, 1 );
msgs->publisher = tr_publisherNew( );
msgs->info = info;
msgs->handle = torrent->handle;
msgs->torrent = torrent;
msgs->io = info->io;
msgs->info->clientIsChoked = 1;
msgs->info->peerIsChoked = 1;
msgs->info->clientIsInterested = 0;
msgs->info->peerIsInterested = 0;
msgs->info->have = tr_bitfieldNew( torrent->info.pieceCount );
msgs->pulseTimer = tr_timerNew( msgs->handle, pulse, msgs, PEER_PULSE_INTERVAL );
msgs->pexTimer = tr_timerNew( msgs->handle, pexPulse, msgs, PEX_INTERVAL );
msgs->outMessages = evbuffer_new( );
msgs->inBlock = evbuffer_new( );
msgs->peerAllowedPieces = NULL;
msgs->clientAllowedPieces = NULL;
m = tr_new0( tr_peermsgs, 1 );
m->publisher = tr_publisherNew( );
m->info = info;
m->handle = torrent->handle;
m->torrent = torrent;
m->io = info->io;
m->info->clientIsChoked = 1;
m->info->peerIsChoked = 1;
m->info->clientIsInterested = 0;
m->info->peerIsInterested = 0;
m->info->have = tr_bitfieldNew( torrent->info.pieceCount );
m->pulseTimer = tr_timerNew( m->handle, pulse, m, PEER_PULSE_INTERVAL );
m->pexTimer = tr_timerNew( m->handle, pexPulse, m, PEX_INTERVAL );
m->outMessages = evbuffer_new( );
m->inBlock = evbuffer_new( );
m->peerAllowedPieces = NULL;
m->clientAllowedPieces = NULL;
setme = tr_publisherSubscribe( m->publisher, func, userData );
if ( tr_peerIoSupportsFEXT( msgs->io ) )
if ( tr_peerIoSupportsFEXT( m->io ) )
{
/* This peer is fastpeer-enabled, generate its allowed set
* (before registering our callbacks) */
if ( !msgs->peerAllowedPieces ) {
const struct in_addr *peerAddr = tr_peerIoGetAddress( msgs->io, NULL );
if ( !m->peerAllowedPieces ) {
const struct in_addr *peerAddr = tr_peerIoGetAddress( m->io, NULL );
msgs->peerAllowedPieces = tr_peerMgrGenerateAllowedSet( MAX_ALLOWED_SET_COUNT,
msgs->torrent->info.pieceCount,
msgs->torrent->info.hash,
peerAddr );
m->peerAllowedPieces = tr_peerMgrGenerateAllowedSet( MAX_ALLOWED_SET_COUNT,
m->torrent->info.pieceCount,
m->torrent->info.hash,
peerAddr );
}
msgs->clientAllowedPieces = tr_bitfieldNew( msgs->torrent->info.pieceCount );
m->clientAllowedPieces = tr_bitfieldNew( m->torrent->info.pieceCount );
}
tr_peerIoSetIOFuncs( msgs->io, canRead, didWrite, gotError, msgs );
tr_peerIoSetIOMode( msgs->io, EV_READ|EV_WRITE, 0 );
tr_peerIoSetIOFuncs( m->io, canRead, didWrite, gotError, m );
tr_peerIoSetIOMode( m->io, EV_READ|EV_WRITE, 0 );
/**
*** If we initiated this connection,
*** we may need to send LTEP/AZMP handshakes.
*** Otherwise we'll wait for the peer to send theirs first.
**/
if( !tr_peerIoIsIncoming( msgs->io ) )
if( !tr_peerIoIsIncoming( m->io ) )
{
if ( tr_peerIoSupportsLTEP( msgs->io ) ) {
sendLtepHandshake( msgs );
if ( tr_peerIoSupportsLTEP( m->io ) ) {
sendLtepHandshake( m );
} else if ( tr_peerIoSupportsAZMP( msgs->io ) ) {
dbgmsg( msgs, "FIXME: need to send AZMP handshake" );
} else if ( tr_peerIoSupportsAZMP( m->io ) ) {
dbgmsg( m, "FIXME: need to send AZMP handshake" );
} else {
/* no-op */
}
}
if ( tr_peerIoSupportsFEXT( msgs->io ) )
if ( tr_peerIoSupportsFEXT( m->io ) )
{
/* This peer is fastpeer-enabled, send it have-all or have-none if appropriate */
float completion = tr_cpPercentComplete( msgs->torrent->completion );
float completion = tr_cpPercentComplete( m->torrent->completion );
if ( completion == 0.0f ) {
sendFastHave( msgs, 0 );
sendFastHave( m, 0 );
} else if ( completion == 1.0f ) {
sendFastHave( msgs, 1 );
sendFastHave( m, 1 );
} else {
sendBitfield( msgs );
sendBitfield( m );
}
uint32_t peerProgress = msgs->torrent->info.pieceCount * msgs->info->progress;
uint32_t peerProgress = m->torrent->info.pieceCount * m->info->progress;
if ( peerProgress < MAX_ALLOWED_SET_COUNT )
sendFastAllowedSet( msgs );
sendFastAllowedSet( m );
} else {
sendBitfield( msgs );
sendBitfield( m );
}
return msgs;
return m;
}
void

View file

@ -23,7 +23,11 @@ struct tr_bitfield;
typedef struct tr_peermsgs tr_peermsgs;
tr_peermsgs* tr_peerMsgsNew( struct tr_torrent * torrent,
struct tr_peer * peer );
struct tr_peer * peer,
tr_delivery_func func,
void * user,
tr_publisher_tag * setme );
void tr_peerMsgsSetChoke( tr_peermsgs *, int doChoke );