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...