From 3ecb9910e053566908af0fb6fef11972f943245d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 22 Dec 2007 16:11:15 +0000 Subject: [PATCH] save per-torrent peer limits in the fastresume file --- libtransmission/fastresume.c | 52 +++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index 43193cc5a..937dacdc1 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -106,7 +106,13 @@ enum /* pex flag * 't' if pex is enabled, 'f' if disabled */ - FR_ID_PEX = 13 + FR_ID_PEX = 13, + + /* max connected peers -- uint16_t */ + FR_ID_MAX_PEERS = 14, + + /* max unchoked peers -- uint8_t */ + FR_ID_MAX_UNCHOKED = 15 }; @@ -309,6 +315,14 @@ tr_fastResumeSave( const tr_torrent * tor ) total = tor->corruptCur + tor->corruptPrev; fastResumeWriteData( FR_ID_CORRUPT, &total, 8, 1, file ); + fastResumeWriteData( FR_ID_MAX_PEERS, + &tor->maxConnectedPeers, + sizeof(uint16_t), 1, file ); + + fastResumeWriteData( FR_ID_MAX_UNCHOKED, + &tor->maxUnchokedPeers, + sizeof(uint8_t), 1, file ); + if( !tor->info.isPrivate ) { tr_pex * pex; @@ -385,6 +399,24 @@ parseCorrupt( tr_torrent * tor, const uint8_t * buf, uint32_t len ) return TR_FR_CORRUPT; } +static uint64_t +parseConnections( tr_torrent * tor, const uint8_t * buf, uint32_t len ) +{ + if( len != sizeof(uint16_t) ) + return 0; + readBytes( &tor->maxConnectedPeers, &buf, sizeof(uint16_t) ); + return TR_FR_MAX_PEERS; +} + +static uint64_t +parseUnchoked( tr_torrent * tor, const uint8_t * buf, uint32_t len ) +{ + if( len != sizeof(uint8_t) ) + return 0; + readBytes( &tor->maxUnchokedPeers, &buf, sizeof(uint8_t) ); + return TR_FR_MAX_UNCHOKED; +} + static uint64_t parseProgress( const tr_torrent * tor, const uint8_t * buf, @@ -574,14 +606,16 @@ parseVersion1( tr_torrent * tor, const uint8_t * buf, const uint8_t * end, if( fieldsToLoad & internalIdToPublicBitfield( id ) ) switch( id ) { - case FR_ID_DOWNLOADED: ret |= parseDownloaded( tor, buf, len ); break; - case FR_ID_UPLOADED: ret |= parseUploaded( tor, buf, len ); break; - case FR_ID_PROGRESS: ret |= parseProgress( tor, buf, len, uncheckedPieces ); break; - case FR_ID_PRIORITY: ret |= parsePriorities( tor, buf, len ); break; - case FR_ID_SPEED: ret |= parseSpeedLimit( tor, buf, len ); break; - case FR_ID_RUN: ret |= parseRun( tor, buf, len ); break; - case FR_ID_CORRUPT: ret |= parseCorrupt( tor, buf, len ); break; - case FR_ID_PEERS: ret |= parsePeers( tor, buf, len ); break; + case FR_ID_DOWNLOADED: ret |= parseDownloaded( tor, buf, len ); break; + case FR_ID_UPLOADED: ret |= parseUploaded( tor, buf, len ); break; + case FR_ID_PROGRESS: ret |= parseProgress( tor, buf, len, uncheckedPieces ); break; + case FR_ID_PRIORITY: ret |= parsePriorities( tor, buf, len ); break; + case FR_ID_SPEED: ret |= parseSpeedLimit( tor, buf, len ); break; + case FR_ID_RUN: ret |= parseRun( tor, buf, len ); break; + case FR_ID_CORRUPT: ret |= parseCorrupt( tor, buf, len ); break; + case FR_ID_PEERS: ret |= parsePeers( tor, buf, len ); break; + case FR_ID_MAX_PEERS: ret |= parseConnections( tor, buf, len ); break; + case FR_ID_MAX_UNCHOKED: ret |= parseUnchoked( tor, buf, len ); break; case FR_ID_PEX: ret |= parsePex( tor, buf, len ); break; case FR_ID_DESTINATION: ret |= parseDestination( tor, buf, len ); break; default: tr_dbg( "Skipping unknown resume code %d", (int)id ); break;