3

I am trying to connect few bitcoind instance running on different ports on my local machine and control the bandwidth between those connections. I used the tc utility as following:

#network interface on which to limit traffic
IF="lo"
#limit of the network interface in question
LINKCEIL="1gbit"
#limit outbound Bitcoin protocol traffic to this rate
LIMIT="80bps"

#delete existing rules
tc qdisc del dev ${IF} root

#add root class
tc qdisc add dev ${IF} root handle 1: htb default 10

#add parent class
tc class add dev ${IF} parent 1: classid 1:1 htb rate ${LINKCEIL} ceil ${LINKCEIL}

#add our two classes. one unlimited, another limited
tc class add dev ${IF} parent 1:1 classid 1:10 htb rate ${LINKCEIL} ceil ${LINKCEIL} prio 0
tc class add dev ${IF} parent 1:1 classid 1:11 htb rate ${LIMIT} ceil ${LIMIT} prio 1

#add handles to our classes so packets marked with <x> go into the class with "... handle <x> fw ..."
tc filter add dev ${IF} parent 1: protocol ip prio 1 handle 1 fw classid 1:10
tc filter add dev ${IF} parent 1: protocol ip prio 2 handle 2 fw classid 1:11

#   --set-mark marks packages matching these criteria with the number "2"
#   these packages are filtered by the tc filter with "handle 2"
#   this filter sends the packages into the 1:11 class, and this class is limited to ${LIMIT}

for ((i = 1; i <= 10; i++))
do
    iptables -t mangle -A OUTPUT -p tcp -m tcp --dport $((18440 + $i)) -j MARK --set-mark 0x2
    iptables -t mangle -A OUTPUT -p tcp -m tcp --sport $((18440 + $i)) -j MARK --set-mark 0x2
done

I have modified the script from the original version: https://github.com/bitcoin/bitcoin/blob/master/contrib/qos/tc.sh

As show in the picture below, the connection for port 18444 is reporting a rate of 128 B/s which is way more than the set LIMIT of 80bps(80 Bytes/second).

Please point me in the right direction, if I am missing out something. I am using tcptrack to monitor the port connections.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.