This is just a simple free-form faq for installing throttled to limit BitTorrent connections, rather than CarraFix, as I’ve had numerous requests for this.
First of all, install Throttled, download it here.
Copy the file to a directory of your choice, then ‘tar -zxvf throttled0.2.7.tar.gz; cd throttled\ 0.2.7’. If you wish to build your own copy from the source, execute ‘make’. Then, execute ‘sudo ./Install.sh’ (You’ll need root privileges). This will install throttled.
As of this writ, the initilization script is ’/usr/local/sbin/throttled-startup’. Edit this file. I’ll use ‘vi’.
%sudo vi /usr/local/sbin/throttled-startupSet your interface at the top of the file; I have an airport card, so this is ‘en1’. I’ll show a snippit of my throttled-startup file below.
Decide how much you want to limit your bandwidth. I like the idea of 56k – it’s still plenty fast, considering my upstream is barely 128k on a good day, and I’m willing to share half of it, so I set MAXSPEED=57520.
Throttled defaults to port 17777, and I use the default BitTorrent ports, so I need to mask ports 6881 to 6889.
Thus, my throttled-startup looks as follows:
#!/bin/sh #I have an airport card, that’s ‘en1’, internal ethernet will be ‘en0’. INTERFACE=en1#56k ought to be enough.
MAXSPEED=57520
IP=$(/sbin/ifconfig $INTERFACE inet | /usr/bin/sed -n ’s/^.inet\ \(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)./\1/p’ | tail -n 1)
/usr/local/sbin/throttled -s $MAXSPEED
#limit our outgoing BitTorrent.
/sbin/ipfw add divert 17777 tcp from $IP 6881-6889 to any out xmit $INTERFACE &
(You can add other ports, and other various methods for other daemons, but this is beyond the scope of this article).
Ensure that this file is executable, and saved as text. chmod 750 /usr/local/sbin/throttled-startup; chown root:admin /usr/local/sbin/throttled-startup
Startup throttled; the easiest way to do this to to execute the script: %sudo /usr/local/sbin/throttled-startup
You’ll get a display similar to:
Max bytes/sec has been set to 57520
Max queue nodes set to 380
Speed change set to 1024
Using divert port 17777
Creating a socket
Binding a socket
Priority has been set to -20
Waiting for data…
00100 divert 17777 tcp from 10.0.1.105 6881-6889 to any out xmit en1
To check that throttled is running, execute
%ps -auxww | grep throttled | grep -v grep
throttled 1261 0.0 0.0 2380 112 std S< 1:11AM 0:00.00 /usr/local/sbin/throttled -s 57520
%
You should have a line like this shown above. The number and name will be different, but that’s normal. (I’ve also setup a ‘nobody’ type user for throttled to run as; not covered (yet) in this article.)
Then, check to make sure your rules are setup properly:
%sudo ipfw list
00100 divert 17777 tcp from 10.0.1.105 6881-6889 to any out xmit en1
65535 allow ip from any to any
You can see, my list is clear, and I’ve got a mere single set for my BitTorrent client.
When you reboot, your machine will automatically start throttled with your configured settings. If you want to remove throttled, either comment out the commands in the script above, or remove the files from /Library/StartupItems.
If you temporarily want to disable throttled, it’s as simple as ’%sudo ipfw -f flush’, unless, of course you have other IPFW rules; I assume you’ll know how to prune them yourself in this case. I suggest just removing the rule; if you forget to remove your rules and you kill throttled, BitTorrent will be entirely broken because it’ll continue to divert requests to the now non-running throttled!
Optionally, you may use CarraFix, or just use the python curses or headless clients. The format for such are as follows:
% python [btdownloadcurses.py | btdownloadheadless.py]—max_upload_rate 20—responsefile theFile.torrentI hope this FAQ was useful!