Hardware Reference
In-Depth Information
Controlling the bridge with the Stem
library
The bridge is controlled using the Stem library, which communicates with the Tor process
over the Tor control protocol. The setup is managed in the BeagleBridge class. After
establishing a connection with the Tor process, this class registers two event listeners for
the Bandwidth and Configuration changed event. The bandwidth event is triggered
each second and reports, via the print_bw callback, the bytes used in the last second.
This information is used to draw the bandwidth graph. The following callback function
shows how the callback interacts with the LCD:
def make_bw_callback(test,lcd):
'''Returns a callback function for the bandwidth event'''
def print_bw(event):
'''Obtains the bandwidth used from the last second from
the
bridge, normalizes it to the total bandwidth, and
draw
that information to the display'''
up = int(test.get_up_ratio(event.written))
down = int(test.get_down_ratio(event.read))
lcd.display_graph(up, down)
return print_bw
Note
For those who want to dive deeper into the Stem library and the Tor control protocol, the
Stem library has thorough online documentation and examples ( https://stem.torproject.org/
tutorials.html ). The control protocol, for those who want an even more in-depth look, is
located at https://gitweb.torproject.org/torspec.git?a=blob_plain;hb=HEAD;f=control-
spec.txt .
The Configuration Changed event is the callback to inform the process that the
bridge's configuration was changed. This occurs when the bandwidth knob is adjusted,
which causes the update_rate method to be called, that sends a command to the
bridge to update the configuration. The end result is that by adjusting the knob, you directly
Search WWH ::




Custom Search