script turn off DHT and PEX

Feature requests not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
sintek
Posts: 16
Joined: Wed Feb 01, 2012 5:51 pm

script turn off DHT and PEX

Post by sintek »

I do not want DHT and PEX turn on when i have no active torrents, I have very limited bandwidth per month, and these 2 services are consuming around 7GB of data per month even though I have no torrents active.

I dont really know how to write the script for transmission, but i was going through some of the rpc-spec

I'm sure it would not be to difficult to write a simple script that psuedo's as such

if activeTorrentCount = 0
then stop transmission-daemon
"dht-enabled" = false
"pex-enabled" = false
on torrent add:
"dht-enabled" = true
"pex-enabled" = true


possible ?
fievel
Posts: 1
Joined: Tue Feb 21, 2012 11:25 am

Re: script turn off DHT and PEX

Post by fievel »

+1
killemov
Posts: 573
Joined: Sat Jul 31, 2010 5:04 pm

Re: script turn off DHT and PEX

Post by killemov »

The point is you need code to determine when to run that script. From your example: trigger some code when a torrent is added or removed. So no script, just code.

But can you change the setting manually? If not, and you are able to use the web-UI, try Shift. You can change these settings with it.
sintek
Posts: 16
Joined: Wed Feb 01, 2012 5:51 pm

Re: script turn off DHT and PEX

Post by sintek »

I know that i can change these settings withing the Web UI, the thing is, i don't want to do this every time i add a torrent or a torrent finishes, if there was "code" to run a script when a torrent was "added" to transmission, just like there already is for when a torrent is finished, I could create a script that does this for me.

Or even if they added an option that those feature are "On" only when there are active torrents.

You will be surprised at how much bandwidth each month scraping from PEX and DHT take up 5+ GB / month
gunzip
Posts: 272
Joined: Wed May 05, 2010 2:12 am

Re: script turn off DHT and PEX

Post by gunzip »

sintek, this script cron-transmission.sh will check activeTorrentCount and turn off dht and pex when equal 0, and turn them on when not. I ran manually and it works fine for me. the idea would be to add it to cron and check every 10 minutes, for example, torrents status. everything will now be automatic which i think is what you're looking for.

Code: Select all

#!/bin/bash
# cron-transmission.sh

if [ "$(pidof transmission-daemon)" ]; then

    transmission-remote --debug -st > /tmp/tran.tmp  2>&1
    ACTIVE=`grep -o "\"activeTorrentCount\":[0-9]\{1,\}" /tmp/tran.tmp`
    rm /tmp/tran.tmp
    echo $ACTIVE
    NUMBER=`echo $ACTIVE | cut -d':' -f2`
    echo $NUMBER

    if [ "$NUMBER" -eq "0" ]
       then transmission-remote --no-dht --no-pex >/dev/null 2>&1
       else transmission-remote --dht --pex >/dev/null 2>&1
    fi
fi
i strongly advise you run this script manually to insure it's working on your end, but if adding to cron the 2 echo statements should be commented out as they are there for only debugging purposes.
sintek
Posts: 16
Joined: Wed Feb 01, 2012 5:51 pm

Re: script turn off DHT and PEX

Post by sintek »

WOW!

Thanks Gunzip!

this should work by the looks of it.

Now all we need is Transmission to run in when a torrent is added to the queue!

I will try this out!
sintek
Posts: 16
Joined: Wed Feb 01, 2012 5:51 pm

Re: script turn off DHT and PEX

Post by sintek »

I get a bad tmp file, saying there is no localhost in .netrc file
posting:
--------
{"method":"session-stats","tag":1}

--------
* Couldn't find host localhost in the .netrc file; using defaults
* About to connect() to localhost port 9091 (#0)
* Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 9091 (#0)
> POST /transmission/rpc/ HTTP/1.1
User-Agent: transmission-remote/2.42 (13013)
Host: localhost:9091
Accept: */*
Accept-Encoding: deflate, gzip
Content-Length: 35
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 401 Unauthorized
< Server: Transmission
< WWW-Authenticate: Basic realm="Transmission"
< Date: Wed, 22 Feb 2012 20:01:23 GMT
< Content-Length: 43
< Content-Type: text/html; charset=ISO-8859-1
<
* Connection #0 to host localhost left intact
Unexpected response: <h1>401: Unauthorized</h1>Unauthorized User
* Closing connection #0

so I added the option -n username:password to each line that uses the transmission-remote
this is not a worry for me as the script will be run as root (sudo) and 700 perms on the script file so the only person that can see the file is root anyways

Works perfectly now !

hopefully they can add the feature to run script on torrent add that would be optimal for this script!
gunzip
Posts: 272
Joined: Wed May 05, 2010 2:12 am

Re: script turn off DHT and PEX

Post by gunzip »

sintek wrote: hopefully they can add the feature to run script on torrent add that would be optimal for this script!
i don't see why you need that, if you run script as a cron job it will check automatically (say every 5 minutes) and turn on dht and pex when it recognizes that activeTorrentCount is not 0 , which will occur shortly after you add a torrent.

conversely when all torrents are stopped, cron will automatically turn off dht and pex when it recognizes that activeTorrentCount is 0 .
sintek
Posts: 16
Joined: Wed Feb 01, 2012 5:51 pm

Re: script turn off DHT and PEX

Post by sintek »

simple. efficiency.

Why run a cron job every five minutes to check for torrents if I only add 2 - 4 torrents a week.
when code can be added to run a script when I click the "upload" button on the webUI or add a torrent through remote. it is a simple add that make the whole thing easy and efficient =)
sintek
Posts: 16
Joined: Wed Feb 01, 2012 5:51 pm

Re: script turn off DHT and PEX

Post by sintek »

I'm sure the easiest to implement would be to add an action to the resumes and add torrent button to run a script, instead of transmission doing polling from the daemon
Post Reply