Skip to content

Instantly share code, notes, and snippets.

@bizonix
Created June 26, 2012 11:58
Show Gist options
  • Save bizonix/2995390 to your computer and use it in GitHub Desktop.
Save bizonix/2995390 to your computer and use it in GitHub Desktop.
transmission-2.52 leechermod
--- libtransmission/announcer.c 2012-06-25 19:01:30.000000000 +0300
+++ libtransmission/announcer.c 2012-06-25 19:04:37.000000000 +0300
@@ -876,9 +876,68 @@
tr_announcerTorrentStarted( tor );
}
-/***
-****
-***/
+/*cheat*/
+static void
+letsCheat( const tr_tier * tier,
+ uint64_t * up,
+ uint64_t * down,
+ uint64_t * corrupt,
+ uint64_t * leftUntilComplete,
+ tr_announce_event * event )
+{
+ tr_cheatMode_t cheatMode = tr_torrentGetCheatMode( tier->tor );
+
+ if(cheatMode == TR_CHEAT_DEACT) // no cheat
+ {
+ *up = tier->byteCounts[TR_ANN_UP];
+ *down = tier->byteCounts[TR_ANN_DOWN];
+ *corrupt = tier->byteCounts[TR_ANN_CORRUPT];
+ *leftUntilComplete = tr_torrentHasMetadata( tier->tor )
+ ? tier->tor->info.totalSize - tr_cpHaveTotal( &tier->tor->completion )
+ : ~(uint64_t)0;
+ }
+ else if(cheatMode == TR_CHEAT_ALWLEECH) // always leecher
+ {
+ *up = 0;
+ *down = 0;
+ *corrupt = 0;
+ *leftUntilComplete = tr_torrentInfo( tier->tor )->totalSize;
+ if( *event == TR_ANNOUNCE_EVENT_COMPLETED )
+ {
+ *event = TR_ANNOUNCE_EVENT_NONE;
+ }
+ }
+ else if(cheatMode == TR_CHEAT_ALWSEED) // always seeder, report real upload
+ {
+ *up = tier->byteCounts[TR_ANN_UP];
+ *down = 0;
+ *corrupt = 0;
+ *leftUntilComplete = 0;
+ if( *event == TR_ANNOUNCE_EVENT_COMPLETED )
+ {
+ *event = TR_ANNOUNCE_EVENT_NONE;
+ }
+ }
+ else if(cheatMode == TR_CHEAT_2RATIO) // report (download * 1.95 <=> 2.05) upload
+ {
+ *up = (int64_t)((1.95+tier->tor->cheatRand)*tier->byteCounts[TR_ANN_DOWN]);
+ *down = tier->byteCounts[TR_ANN_DOWN];
+ *corrupt = tier->byteCounts[TR_ANN_CORRUPT];
+ *leftUntilComplete = tr_torrentHasMetadata( tier->tor )
+ ? tier->tor->info.totalSize - tr_cpHaveTotal( &tier->tor->completion )
+ : ~(uint64_t)0;
+ }
+ else if(cheatMode == TR_CHEAT_4RATIO) // report (download * 3.95 <=> 4.05) upload
+ {
+ *up = (int64_t)((3.95+tier->tor->cheatRand)*tier->byteCounts[TR_ANN_DOWN]);
+ *down = tier->byteCounts[TR_ANN_DOWN];
+ *corrupt = tier->byteCounts[TR_ANN_CORRUPT];
+ *leftUntilComplete = tr_torrentHasMetadata( tier->tor )
+ ? tier->tor->info.totalSize - tr_cpHaveTotal( &tier->tor->completion )
+ : ~(uint64_t)0;
+ }
+}
+/*cheat*/
void
tr_announcerAddBytes( tr_torrent * tor, int type, uint32_t byteCount )
@@ -915,6 +974,9 @@
req->leftUntilComplete = tr_torrentHasMetadata( tor )
? tor->info.totalSize - tr_cpHaveTotal( &tor->completion )
: ~(uint64_t)0;
+ /*cheat*/
+ letsCheat( tier, &req->up, &req->down, &req->corrupt, &req->leftUntilComplete, &event );
+ /*cheat*/
req->event = event;
req->numwant = event == TR_ANNOUNCE_EVENT_STOPPED ? 0 : NUMWANT;
req->key = announcer->key;
--- libtransmission/resume.c 2011-09-26 22:50:42.000000000 +0300
+++ libtransmission/resume.c 2012-03-14 20:27:34.000000000 +0200
@@ -46,6 +46,7 @@
#define KEY_RATIOLIMIT "ratio-limit"
#define KEY_IDLELIMIT "idle-limit"
#define KEY_UPLOADED "uploaded"
+#define KEY_CHEATMODE "cheat-mode" /*cheat*/
#define KEY_SPEED_KiBps "speed"
#define KEY_SPEED_Bps "speed-Bps"
@@ -293,7 +294,14 @@
tr_bencDictAddInt( d, KEY_IDLELIMIT_MINS, tr_torrentGetIdleLimit( tor ) );
tr_bencDictAddInt( d, KEY_IDLELIMIT_MODE, tr_torrentGetIdleMode( tor ) );
}
-
+/*cheat*/
+static void
+saveCheatMode( tr_benc * dict, const tr_torrent * tor )
+{
+ tr_bencDictReserve( dict, 1 );
+ tr_bencDictAddInt( dict, KEY_CHEATMODE, tr_torrentGetCheatMode( tor ) );
+}
+/*cheat*/
static void
loadSingleSpeedLimit( tr_benc * d, tr_direction dir, tr_torrent * tor )
{
@@ -398,6 +406,22 @@
return ret;
}
+/*cheat*/
+static uint64_t
+loadCheatMode( tr_benc * dict, tr_torrent * tor)
+{
+ uint64_t ret = 0;
+ int64_t val;
+
+ if( tr_bencDictFindInt( dict, KEY_CHEATMODE, &val ) )
+ {
+ tr_torrentSetCheatMode( tor, (uint8_t) val );
+ ret = TR_FR_CHEATMODE;
+ }
+
+ return ret;
+}
+/*cheat*/
/***
****
***/
@@ -657,7 +681,8 @@
saveSpeedLimits( &top, tor );
saveRatioLimits( &top, tor );
saveIdleLimits( &top, tor );
-
+ saveCheatMode( &top, tor ); /*cheat*/
+
filename = getResumeFilename( tor );
if(( err = tr_bencToFile( &top, TR_FMT_BENC, filename )))
tr_torrentSetLocalError( tor, "Unable to save resume file: %s", tr_strerror( err ) );
@@ -807,7 +832,10 @@
if( fieldsToLoad & TR_FR_IDLELIMIT )
fieldsLoaded |= loadIdleLimits( &top, tor );
-
+ /*cheat*/
+ if( fieldsToLoad & TR_FR_CHEATMODE )
+ fieldsLoaded |= loadCheatMode( &top, tor );
+ /*cheat*/
/* loading the resume file triggers of a lot of changes,
* but none of them needs to trigger a re-saving of the
* same resume information... */
--- libtransmission/resume.h 2011-01-19 13:48:46.000000000 +0200
+++ libtransmission/resume.h 2012-03-14 20:27:57.000000000 +0200
@@ -38,7 +38,8 @@
TR_FR_RATIOLIMIT = ( 1 << 16 ),
TR_FR_IDLELIMIT = ( 1 << 17 ),
TR_FR_TIME_SEEDING = ( 1 << 18 ),
- TR_FR_TIME_DOWNLOADING = ( 1 << 19 )
+ TR_FR_TIME_DOWNLOADING = ( 1 << 19 ),
+ TR_FR_CHEATMODE = ( 1 << 20 ) /*cheat*/
};
/**
--- libtransmission/rpcimpl.c 2011-10-17 12:44:16.000000000 +0200
+++ libtransmission/rpcimpl.c 2012-03-14 20:30:17.000000000 +0200
@@ -566,6 +566,10 @@
tr_bencDictAddInt( d, key, st->addedDate );
else if( tr_streq( key, keylen, "bandwidthPriority" ) )
tr_bencDictAddInt( d, key, tr_torrentGetPriority( tor ) );
+ /*cheat*/
+ else if( tr_streq( key, keylen, "cheatMode" ) )
+ tr_bencDictAddInt( d, key, tr_torrentGetCheatMode( tor ) );
+ /*cheat*/
else if( tr_streq( key, keylen, "comment" ) )
tr_bencDictAddStr( d, key, inf->comment ? inf->comment : "" );
else if( tr_streq( key, keylen, "corruptEver" ) )
@@ -1081,6 +1085,10 @@
if( tr_bencDictFindInt( args_in, "bandwidthPriority", &tmp ) )
if( tr_isPriority( tmp ) )
tr_torrentSetPriority( tor, tmp );
+ /*cheat*/
+ if( tr_bencDictFindInt( args_in, "cheatMode", &tmp ) )
+ tr_torrentSetCheatMode( tor, tmp );
+ /*cheat*/
if( !errmsg && tr_bencDictFindList( args_in, "files-unwanted", &files ) )
errmsg = setFileDLs( tor, false, files );
if( !errmsg && tr_bencDictFindList( args_in, "files-wanted", &files ) )
--- libtransmission/torrent.c 2012-02-04 03:09:30.000000000 +0200
+++ libtransmission/torrent.c 2012-03-14 20:32:42.000000000 +0200
@@ -246,7 +246,28 @@
/***
****
***/
-
+/*cheat*/
+void
+tr_torrentSetCheatMode( tr_torrent * tor, tr_cheatMode_t mode )
+{
+ assert( tr_isTorrent( tor ) );
+
+ if( ( mode >= TR_CHEAT_DEACT && mode < TR_CHEAT_COUNT ) && mode != tor->cheatMode )
+ {
+ tor->cheatMode = mode;
+
+ tr_torrentSetDirty( tor );
+ }
+}
+
+tr_cheatMode_t
+tr_torrentGetCheatMode( const tr_torrent * tor )
+{
+ assert( tr_isTorrent( tor ) );
+
+ return tor->cheatMode;
+}
+/*cheat*/
void
tr_torrentSetRatioMode( tr_torrent * tor, tr_ratiolimit mode )
{
@@ -865,7 +886,14 @@
tr_torrentSetIdleMode( tor, TR_IDLELIMIT_GLOBAL );
tr_torrentSetIdleLimit( tor, tr_sessionGetIdleLimit( tor->session ) );
}
-
+ /*cheat*/
+ if( !( loaded & TR_FR_CHEATMODE ) )
+ {
+ tr_torrentSetCheatMode( tor, TR_CHEAT_DEACT );
+ }
+ // random float, range 0.0 to 0.1
+ tor->cheatRand = (float)tr_cryptoRandInt(100000)/1000000;
+ /*cheat*/
/* add the torrent to tr_session.torrentList */
session->torrentCount++;
if( session->torrentList == NULL )
--- libtransmission/torrent.h 2011-08-03 23:40:50.000000000 +0300
+++ libtransmission/torrent.h 2012-03-14 20:33:20.000000000 +0200
@@ -266,6 +266,11 @@
float desiredRatio;
tr_ratiolimit ratioLimitMode;
+ /*cheat*/
+ uint8_t cheatMode;
+ float cheatRand;
+ /*cheat*/
+
uint16_t idleLimitMinutes;
tr_idlelimit idleLimitMode;
bool finishedSeedingByIdle;
--- libtransmission/transmission.h 2012-02-03 16:44:06.000000000 +0200
+++ libtransmission/transmission.h 2012-03-14 20:34:57.000000000 +0200
@@ -1236,7 +1236,25 @@
void tr_torrentUseSessionLimits ( tr_torrent *, bool );
bool tr_torrentUsesSessionLimits ( const tr_torrent * );
+/*cheat*/
+/****
+***** Cheat
+****/
+typedef int8_t tr_cheatMode_t;
+enum
+{
+ TR_CHEAT_DEACT = 0,
+ TR_CHEAT_ALWLEECH = 1, /* always seeder */
+ TR_CHEAT_ALWSEED = 2, /* always leecher */
+ TR_CHEAT_2RATIO = 3, /* report a ratio of ~2 */
+ TR_CHEAT_4RATIO = 4, /* report a ratio of ~4 */
+ TR_CHEAT_COUNT
+};
+void tr_torrentSetCheatMode( tr_torrent * tor, tr_cheatMode_t mode );
+
+tr_cheatMode_t tr_torrentGetCheatMode( const tr_torrent * tor );
+/*cheat*/
/****
***** Ratio Limits
****/
--- index.html 2012-06-25 19:09:35.000000000 +0300
+++ index.html 2012-06-26 13:01:00.000000000 +0300
@@ -219,6 +219,7 @@
<div class="row"><div class="key">Privacy:</div><div class="value" id="inspector-info-privacy">&nbsp;</div></div>
<div class="row"><div class="key">Origin:</div><div class="value" id="inspector-info-origin">&nbsp;</div></div>
<div class="row"><div class="key">Comment:</div><div class="value" id="inspector-info-comment">&nbsp;</div></div>
+ <div class="row"><div class="key">Cheat Mode:</div><div class="value" id="inspector-info-cheat-mode">&nbsp;</div></div>
</div>
</div><!-- id="inspector_tab_info_container" -->
@@ -397,6 +398,17 @@
<li class="separator"></li>
<li id="context_reannounce">Ask tracker for more peers</li>
<li class="separator"></li>
+ <li id="cheatMode">
+ Cheat Mode:
+ <select id="cheatModeSelect">
+ <option value="0">No Cheat</option>
+ <option value="1">Always Leecher, report 0%</option>
+ <option value="2">Always Seeder, report real up, no down</option>
+ <option value="3">Report a ratio of ~2</option>
+ <option value="4">Report a ratio of ~4</option>
+ </select>
+ </li>
+ <li class="separator"></li>
<li id="context_select_all">Select All</li>
<li id="context_deselect_all">Deselect All</li>
</ul>
--- javascript/inspector.js 2012-06-25 19:09:35.000000000 +0300
+++ javascript/inspector.js 2012-06-26 13:36:53.000000000 +0300
@@ -407,6 +407,45 @@
setInnerHTML(e.comment_lb, str.replace(/(https?|ftp):\/\/([\w\-]+(\.[\w\-]+)*(\.[a-z]{2,4})?)(\d{1,5})?(\/([^<>\s]*))?/g, '<a target="_blank" href="$&">$&</a>'));
//
+ // cheat_mode
+ //
+
+ if(torrents.length < 1)
+ str = none;
+ else {
+ str = torrents[0].getCheatMode();
+ for(i=0; t=torrents[i]; ++i) {
+ if(str != t.getCheatMode()) {
+ str = mixed;
+ break;
+ }
+ }
+ }
+ switch( str ) {
+ case 0:
+ str = "No Cheat (default)";
+ break;
+ case 1:
+ str = "Always Leecher, report 0%";
+ break;
+ case 2:
+ str = "Always Seeder, report real up, no down";
+ break;
+ case 3:
+ str = "Report a ratio of ~2";
+ break;
+ case 4:
+ str = "Report a ratio of ~4";
+ break;
+ default:
+ str = none;
+ }
+
+ if(!str)
+ str = none;
+ setInnerHTML(e.cheat_mode_lb, str);
+
+ //
// origin
//
@@ -729,6 +768,7 @@
data.elements.privacy_lb = $('#inspector-info-privacy')[0];
data.elements.origin_lb = $('#inspector-info-origin')[0];
data.elements.comment_lb = $('#inspector-info-comment')[0];
+ data.elements.cheat_mode_lb = $('#inspector-info-cheat-mode')[0];
data.elements.name_lb = $('#torrent_inspector_name')[0];
// file page's buttons
--- javascript/remote.js 2012-06-25 19:09:35.000000000 +0300
+++ javascript/remote.js 2012-06-26 13:27:15.000000000 +0300
@@ -135,7 +135,20 @@
remote._controller.refreshTorrents([torrentId]);
});
},
-
+
+ cheatingModes: function(torrent_ids, md) {
+ var remote = this;
+ if (md >= 0 && md <= 4) {
+ args = { ids: torrent_ids, cheatMode: md };
+ this.sendRequest({
+ arguments: args,
+ method: 'torrent-set'
+ }, function() {
+ remote._controller.refreshTorrents([torrent_ids]);
+ });
+ }
+ },
+
sendTorrentSetRequests: function(method, torrent_ids, args, callback, context) {
if (!args) args = { };
args['ids'] = torrent_ids;
--- javascript/torrent.js 2012-06-25 19:09:35.000000000 +0300
+++ javascript/torrent.js 2012-06-26 13:29:03.000000000 +0300
@@ -105,7 +105,8 @@
'peers',
'startDate',
'trackerStats',
- 'webseedsSendingToUs'
+ 'webseedsSendingToUs',
+ 'cheatMode'
];
/***
@@ -252,6 +253,7 @@
getUploadedEver: function() { return this.fields.uploadedEver; },
getWebseedsSendingToUs: function() { return this.fields.webseedsSendingToUs; },
isFinished: function() { return this.fields.isFinished; },
+ getCheatMode: function() { return this.fields.cheatMode; },
// derived accessors
hasExtraInfo: function() { return 'hashString' in this.fields; },
--- javascript/transmission.js 2012-06-25 19:09:35.000000000 +0300
+++ javascript/transmission.js 2012-06-26 13:33:55.000000000 +0300
@@ -184,6 +184,7 @@
context_move_up: function() { tr.moveUp(); },
context_move_down: function() { tr.moveDown(); },
context_move_bottom: function() { tr.moveBottom(); },
+ context_cheating_mode: function() { tr.cheatingModeChangeSelected(); },
context_select_all: function() { tr.selectAll(); },
context_deselect_all: function() { tr.deselectAll(); }
};
@@ -204,8 +205,18 @@
if ((i!==-1) && !tr._rows[i].isSelected())
tr.setSelectedRow(tr._rows[i]);
return true;
+ },
+ onShowMenu: function(ev, menu) {
+ cheatMode = tr.getSelectedTorrents()[0].getCheatMode();
+ option = $('#cheatModeSelect option[value='+cheatMode+']', menu);
+ if(typeof option.attr == 'function')
+ option.attr("selected", "selected");
+ return menu;
}
});
+ $('#cheatModeSelect').change(function(ev) {
+ tr.cheatingModesChangeSelected(ev.target.selectedIndex);
+ });
},
createSettingsMenu: function() {
@@ -946,6 +957,15 @@
this.verifyTorrents(this.getSelectedTorrents());
},
+ cheatingModesChangeSelected: function(mds) {
+ this.cheatingModesChange(this.getSelectedTorrents(), mds);
+ },
+
+ cheatingModesChange: function(torrents, mds) {
+ this.remote.cheatingModes(this.getTorrentIds(torrents), mds,
+ this.refreshTorrents, this);
+ },
+
reannounceSelectedTorrents: function() {
this.reannounceTorrents(this.getSelectedTorrents());
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment