back to main page


p2pshaper version 2 is an alternative to p2pshaper. Its primary use is to divide bandwidth evenly among a lot of users, when bandwidth is limited. It is now being optimized for use in dormitories with an ADSL connection with 4MBit/768kbit U/D bandwidth, and about 100 users.

The idea behind p2pshaper v2, is to ensure that bandwidth gets divided equally amongst the users using the line. If 3 users are using a 4MBit/768kbit line, each user will be ensured 1366kbit/256kbit bandwidth. Also, if one of the users aren't using all his bandwidth, the others share the spare bandwidth evenly.

This is done by making a kernel patch for netfilter, and one for iptables. These patches is a iptables "match" extension which works much like the iptables "limit" match, but this matches the rate in kbit/s instead of packets/s

These patches will be used together with iproute2's excellent traffic control tc. In iptables, packets will be marked according to how much bandwidth they are using, and a number of other factors. tc will then divide them into classes in the classful HTB.

The way it works

Using HTB or the PRIO qdisc. A link is split up into subsections (bands) with different priorities. Currently the PRIO qdisc allows only 8 bands, but with some crude hacking, you can make more. As normal, the first band has the highest priority, and the second band will not be emptied until the first band is empty. The same goes for band 2 and 3, where the 3rd band wont be emptied before band 2 is empty.

The idea is then, to put hosts that are not downloading much in the high priority bands, and hosts that are downloading much in the low priority bands. The bands can borrow from each other, so all the bandwidth will be used. When hosts in the low priority bands tries to download at a rate exceeding the specified rate for that particular band, it will be moved to a lower priority band. Similarily, when hosts in the low priority band downloads less than the specified rate in their band, they will be moved to a higher priority band.

This means, that if 2 hosts are downloading full speed, they will both end up in the same band. If one of the hosts downloads faster than that band allows, it will be moved to a lower priority band, which will slow down the download, and eventually put that host back in the higher priority band again.