Controlling the bridge with the Stem
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:
'''Returns a callback function for the bandwidth event'''
'''Obtains the bandwidth used from the last second from
bridge, normalizes it to the total bandwidth, and
that information to the display'''
up = int(test.get_up_ratio(event.written))
down = int(test.get_down_ratio(event.read))
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
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