Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk


2Collection of Tor control commands that now exist in Tor in support of to 

3Flashflow but for which Stem does not yet implement a better interface. 


5All messages must be of the ABC TorCtrlMsg and provide its methods. Most 

6notably this means the ``__str__`` method, which is used to turn the message 

7into a string for sending to the ControlPort. 


9New messages are free to have a more complex construction process than simply 

10passing in all necessary information at ``__init__`` time. But at the end of 

11the day they need to implement all TorCtrlMsg's methods and have a ``__str__`` 

12that turns them into a one-line string for sending to Tor. 


14from abc import ABC, abstractmethod 



17class TorCtrlMsg(ABC): 

18 ''' Base class for our control commands. ''' 

19 @abstractmethod 

20 def __str__(self) -> str: pass 



23class CoordStartMeas(TorCtrlMsg): 

24 ''' Coordinator to its client, instructing it to start the measurement 

25 processs with the given relay. 


27 :param meas_id: Measurement ID 

28 :param nick_fp: Nickname or fingerprint of the relay to measure. Always use 

29 fingerprint in practice. 

30 :param dur: The duration, in seconds, of the measurement. 

31 ''' 

32 def __init__(self, meas_id: int, nick_fp: str, dur: int): 

33 self.meas_id = meas_id 

34 self.nick_fp = nick_fp 

35 self.dur = dur 


37 def __str__(self) -> str: 

38 return 'COORD_START_MEAS %d %s %d' % ( 

39 self.meas_id, self.nick_fp, self.dur) 



42class MeasrStartMeas(TorCtrlMsg): 

43 ''' Dual-purpose message sent from a FlashFlow measurer to its Tor client. 


45 First it's used to tell it to open circuits with the given relay as part of 

46 the pre-measurement process. 


48 Later, when everything is setup and ready to go, it is used to tell the tor 

49 client to actually start sending measurement traffic with the relay. 


51 :param meas_id: Measurement ID 

52 :param nick_fp: Nickname or fingerprint of the relay to measure. Always use 

53 fingerprint in practice. 

54 :param n_circs: Number of circuits (and connections) to open with the 

55 relay. 

56 :param dur: The duration, in seconds, of the measurement. 

57 ''' 

58 def __init__(self, meas_id: int, nick_fp: str, n_circs: int, dur: int): 

59 self.meas_id = meas_id 

60 self.nick_fp = nick_fp 

61 self.n_circs = n_circs 

62 self.dur = dur 


64 def __str__(self) -> str: 

65 return 'MEASR_START_MEAS %d %s %d %d' %\ 

66 (self.meas_id, self.nick_fp, self.n_circs, self.dur)