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

1''' 

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. 

4 

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. 

8 

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. 

13''' 

14from abc import ABC, abstractmethod 

15 

16 

17class TorCtrlMsg(ABC): 

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

19 @abstractmethod 

20 def __str__(self) -> str: pass 

21 

22 

23class CoordStartMeas(TorCtrlMsg): 

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

25 processs with the given relay. 

26 

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 

36 

37 def __str__(self) -> str: 

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

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

40 

41 

42class MeasrStartMeas(TorCtrlMsg): 

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

44 

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

46 the pre-measurement process. 

47 

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. 

50 

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 

63 

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)