lzkill lzkill - 8 months ago 29
Python Question

How read the bandwidth limit parameter from Tor with Stem

How could one read the Tor parameter for bandwidth limit using Stem? I've looked around theAPI and could'n find a method or GETINFO parameter to such a task.


assuming you mean the maximum bandwidth you've configured your relay for it's...

from stem.control import Controller

from stem.util.str_tools import get_size_label

with Controller.from_port() as controller:

  bw_rate = get_size_label(int(controller.get_conf('BandwidthRate', '0')))
  bw_burst = get_size_label(int(controller.get_conf('BandwidthBurst', '0')))
  print "you're configured to relay at most %s/s, with bursts up to %s/s" % (bw_rate, bw_burst)

... for example...

% python scrap.py 
you're configured to relay at most 1 GB/s, with bursts up to 1 GB/s

The git repository also has a new get_effective_rate() method which takes additional configuration attributes into account.