cell

class cell.cell.Cell[source]

Bases: object

An abstract base class for other kinds of cells.

getPayload()[source]

Return just the payload bytes of a cell.

For fixed-length cells, pad with null bytes to the appropriate length according to Link Protocol version. Primarily useful for encrypting or decrypting cells.

Returns:str cell payload bytes
payloadRange()[source]

Return the (start, end) indices of this cell’s payload as a 2-tuple.

Returns:tuple, int (start, end) payload indices.
static enoughDataForCell(data, link_version=3)[source]

Return True iff the str data contains enough bytes to build a cell.

The command byte is checked to determine the general type of cell to look for. For fixed-length cells, this is enough to know how much data is required. For variable-length cells, additionally check the length bytes.

Parameters:
  • data (str) – The raw string to check.
  • link_version (int) – Link Protocol version in use. In version 3, 512 bytes are required for a fixed-length cell. In version 4, 514 bytes are required.
Returns:

bool that’s True iff data is long enough to build the type of cell indicated by the command byte.

static parse(data, link_version=3, encrypted=False)[source]

Return an instance of a cell constructed from the str data.

If encrypted is True and the type if cell is RELAY or RELAY_EARLY, don’t try to parse the payload and just return a EncryptedCell. Otherwise, instantiate and return the appropriate cell type.

Note

data str is not modified.

Parameters:
  • data (str) – raw bytes to parse and extract a cell from
  • link_verison (int) – Link Protocol version in use. For fixed- length cells, this parameter dictates whether we expect 512 bytes (Link Protocol <= 3) or 514 bytes.
  • encrypted (bool) – whether or not we think this cell is encrypted. If True and we see a RELAY or RELAY_EARLY command do not attempt to parse payload.
Returns:

instantiated cell type as dictated by the command byte, parsed and extracted from data.

class Header[source]

Bases: object

A dummy header type that exists only to be overriden by classes that inherit from Cell.

Previous topic

cell

Next topic

fixedlen

This Page