Sat 26 Mar 2005 08:19:13 PM UTC, original submission:
IP provides a mechanism for flagging packets as Maximize-Throughput (bulk) or Minimize-Latency (interactive). If applications that "soak up extra bandwidth" flag their packets as bulk, it can be extremely useful for bandwidth allocation on residential ADSL or cable routers, and allow users to run P2P 24/7 using all available extra bandwidth -- web browsing and the like is not affected by P2P use.
Mldonkey could provide the option to flag all of its connections as bulk. The main problem is that the current version of ocaml does not expose the required flags.
In C, flagging connections as bulk is done with these simple two lines of code:
int tos = IPTOS_THROUGHPUT;
setsockopt(sock, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(tos));
IPPROTO_IP and IP_TOS are not exposed by ocaml, so mldonkey cannot use this line.
A fix would entail adding IPPTORO_IP and IP_TOS to ocaml, and then locating all the places that sockets are created in mldonkey and setting them to bulk (if the user so desires).
Those mldonkey users who are on Linux boxes can enjoy this functionality already, without application-level support. The following configuration should work nicely out-of-box for those of you with a single computer (no NATTing routers set up or anything fancy like that) connected to an ADSL or cable line:
Simply use the following commands:
groupadd mlnet
chgrp mlnet mlnet (in the mldonkey directory, as root)
chmod g+s mlnet (in the mldonkey directory, as root)
Then use the following script (adjust the variables at the top to fit your particular configuration):
#!/bin/bash
DEV=eth0
RATE=370kbit
HIGH_RATE=200kbit
MED_RATE=100kbit
LOW_RATE=20kbit
# if there are already traffic-shaping rules in place, this removes them
# this will print an error if they don't exist, but continue to work
tc qdisc del dev $DEV root
tc qdisc add dev $DEV root handle 1: htb default 20
# PARENT CLASS
tc class add dev $DEV parent 1: classid 1:1 htb rate $RATE
# CHILD CLASSES
tc class add dev $DEV parent 1:1 classid 1:10 htb rate $HIGH_RATE ceil $RATE
tc class add dev $DEV parent 1:1 classid 1:20 htb rate $MED_RATE ceil $RATE quantum 1500
tc class add dev $DEV parent 1:1 classid 1:30 htb rate $LOW_RATE ceil $RATE quantum 1500
# interactive
tc filter add dev $DEV parent 1: prio 1 protocol ip u32 match ip tos 0x10 0x18 flowid 1:10
# bulk
tc filter add dev $DEV parent 1: prio 1 protocol ip u32 match ip tos 0x08 0x18 flowid 1:30
# make p2p bulk
iptables -t mangle -A OUTPUT -m owner -p tcp --gid-owner mlnet -j TOS --set-tos Maximize-Throughpu
|