flashflow.cmd package

Submodules

flashflow.cmd.ctrl module

flashflow.cmd.ctrl.gen_parser(sub)

Add the cmd line options for this FlashFlow command

Return type

ArgumentParser

flashflow.cmd.ctrl.main(args, conf)
Return type

None

flashflow.cmd.measurer module

class flashflow.cmd.measurer.CoordConnRes

Bases: enum.Enum

Part of the return value of try_connect_to_coord().

FATAL_ERROR = 3

We were not successful, and trying again in the future is extremely unlikely to be successful. We should give up.

RETRY_ERROR = 2

We were not successful, but whatever happened may be temporary and it’s logical to try connecting again in the future.

SUCCESS = 1

We successfully connected to the coord, shook our TLS hands, and all is well.

class flashflow.cmd.measurer.CoordProtocol

Bases: asyncio.protocols.Protocol

connection_lost(exc)

Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).

connection_made(transport)

Called when a connection is made.

The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.

data_received(data)

Receive data from the coordinator. Parse it into a FFMsg and tell other code about the message.

It’s possible that this is called before the entire message is received. In that case, we’ll need to edit this function to buffer bytes until the entire message has arrived.

transport = None
class flashflow.cmd.measurer.Measurement(connect_msg)

Bases: object

State related to a single measurement.

property alloc_bw

The amount of bandwidth, in bytes/second, the client should allocate for this measurement

Return type

int

bad_circs: Set[int] = None

Our circuit ids that we’ve been told have CLOSED or FAILED at any point

circs: Set[int] = None

Our circuit ids with the relay. Filled in once we know what they are (they’re launched) but not yet bullt

connect_msg: msg.ConnectToRelay = None

keep a copy of flashflow.msg.ConnectToRelay command so we can send it back to the coord when we’re ready to go (or have failed)

property meas_duration

The duration, in seconds, that active measurement should last.

Return type

int

property meas_id

The measurement ID

Return type

int

ready_circs: Set[int] = None

Our built circuit ids with the relay. Filled in as we learn of launched circuits becoming built.

property relay_fp

The fingerprint of the relay to measure

Return type

str

property waiting_circs

Circs that we have LAUNCHED but have not yet added to ready_circs because we haven’t seen BUILT yet.

Note that as far as this function is concerned, there’s no such thing as a circuit becoming un-BUILT. This functiion doesn’t know anything about circuits closing. Other code needs to manipulate circs and ready_circs as it deems fit.

Return type

Set[int]

class flashflow.cmd.measurer.State

Bases: object

Global state for the measurer process

coord_proto: CoordProtocol = None

how we communicate with the coord

coord_trans: asyncio.WriteTransport = None

how we communicate with the coord

measurements: Dict[int, Measurement] = None

state specific to each measurement, obviously

tor_client: Controller = None

Our Tor client, set in main

flashflow.cmd.measurer.cleanup(state)

Cleanup all of the State object while being very careful to not allow any exceptions to bubble up. Use this when in an error state and you want to cleanup before starting over or just dying.

flashflow.cmd.measurer.die()

End execution of the program.

async flashflow.cmd.measurer.ensure_conn_w_coord(conf, delay)

Repeatedly try connecting to the coordinator until we are successful or have a fatal error warranting completely giving up on life.

This function uses asynchronous python: the connection is represented by a transport and protocol, and we try connecting asynchronously and use a callback to find out the result. That said, the work done here should probably be the only thing going on.

Return type

Tuple[bool, Union[Tuple[BaseTransport, BaseProtocol], str]]

flashflow.cmd.measurer.ensure_conn_w_tor(conf)

Create a Tor client, connect to its control socket, authenticate, and return the Controller. On success, return True and the controller. Otherwise return False and an operator-meaningful error message.

flashflow.cmd.measurer.gen_parser(sub)

Add the cmd line options for this FlashFlow command

Return type

ArgumentParser

flashflow.cmd.measurer.main(args, conf)
Return type

None

flashflow.cmd.measurer.notif_circ_event(event)

Called from stem to tell us about circuit events.

We are currently in a different thread. We tell the main thread’s loop (in a threadsafe manner) to handle this event.

flashflow.cmd.measurer.notif_coord_msg(message)
flashflow.cmd.measurer.notif_ffmeas_event(event)

Called from stem to tell us about FF_MEAS events.

We are currently in a different thread. We tell the main thread’s loop (in a threadsafe manner) to handle this event.

async flashflow.cmd.measurer.try_connect_to_coord(addr_port, our_key, coord_cert)

Try to connect to the coordinator at the given (host, port) tuple. Perform the TLS handshake using our client TLS key in the file our_key and only trusting the coord server cert in the file coord_cert.

Returns a tuple in all cases. The first item indicates success with CoordConnRes. If it is an *_ERROR, then the second item is a string with more details. If it is SUCCESS, then the second item is the transport and protocol with the coordinator.

This function is a coroutine and all exceptions should be handled within this function’s body. If they aren’t, that’s a programming error.

Return type

Tuple[CoordConnRes, Union[str, Tuple[BaseTransport, BaseProtocol]]]

Module contents