Example #1
0
    def _parse(self):
        if self.id and not tor_tools.is_valid_circuit_id(self.id):
            raise stem.ProtocolError(
                "Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.id, self))
        elif self.inbound_queue and not tor_tools.is_valid_circuit_id(
                self.inbound_queue):
            raise stem.ProtocolError(
                "Queue IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.inbound_queue, self))
        elif self.inbound_connection and not tor_tools.is_valid_connection_id(
                self.inbound_connection):
            raise stem.ProtocolError(
                "Connection IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.inbound_connection, self))
        elif self.outbound_queue and not tor_tools.is_valid_circuit_id(
                self.outbound_queue):
            raise stem.ProtocolError(
                "Queue IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.outbound_queue, self))
        elif self.outbound_connection and not tor_tools.is_valid_connection_id(
                self.outbound_connection):
            raise stem.ProtocolError(
                "Connection IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.outbound_connection, self))

        self.inbound_added = _parse_cell_type_mapping(self.inbound_added)
        self.inbound_removed = _parse_cell_type_mapping(self.inbound_removed)
        self.inbound_time = _parse_cell_type_mapping(self.inbound_time)
        self.outbound_added = _parse_cell_type_mapping(self.outbound_added)
        self.outbound_removed = _parse_cell_type_mapping(self.outbound_removed)
        self.outbound_time = _parse_cell_type_mapping(self.outbound_time)
Example #2
0
class CircuitEvent(Event):
    """
  Event that indicates that a circuit has changed.

  The fingerprint or nickname values in our 'path' may be **None** if the
  VERBOSE_NAMES feature isn't enabled. The option was first introduced in tor
  version 0.1.2.2, and on by default after 0.2.2.1.

  The CIRC event was one of the first Control Protocol V1 events and was
  introduced in tor version 0.1.1.1-alpha.

  :var str id: circuit identifier
  :var stem.CircStatus status: reported status for the circuit
  :var tuple path: relays involved in the circuit, these are
    **(fingerprint, nickname)** tuples
  :var tuple build_flags: :data:`~stem.CircBuildFlag` attributes
    governing how the circuit is built
  :var stem.CircPurpose purpose: purpose that the circuit is intended for
  :var stem.HiddenServiceState hs_state: status if this is a hidden service circuit
  :var str rend_query: circuit's rendezvous-point if this is hidden service related
  :var datetime created: time when the circuit was created or cannibalized
  :var stem.CircClosureReason reason: reason for the circuit to be closed
  :var stem.CircClosureReason remote_reason: remote side's reason for the circuit to be closed
  """

    _POSITIONAL_ARGS = ("id", "status", "path")
    _KEYWORD_ARGS = {
        "BUILD_FLAGS": "build_flags",
        "PURPOSE": "purpose",
        "HS_STATE": "hs_state",
        "REND_QUERY": "rend_query",
        "TIME_CREATED": "created",
        "REASON": "reason",
        "REMOTE_REASON": "remote_reason",
    }

    def _parse(self):
        self.path = tuple(stem.control._parse_circ_path(self.path))

        if self.build_flags is not None:
            self.build_flags = tuple(self.build_flags.split(','))

        if self.created is not None:
            try:
                self.created = str_tools._parse_iso_timestamp(self.created)
            except ValueError, exc:
                raise stem.ProtocolError(
                    "Unable to parse create date (%s): %s" % (exc, self))

        if not tor_tools.is_valid_circuit_id(self.id):
            raise stem.ProtocolError(
                "Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.id, self))

        self._log_if_unrecognized('status', stem.CircStatus)
        self._log_if_unrecognized('build_flags', stem.CircBuildFlag)
        self._log_if_unrecognized('purpose', stem.CircPurpose)
        self._log_if_unrecognized('hs_state', stem.HiddenServiceState)
        self._log_if_unrecognized('reason', stem.CircClosureReason)
        self._log_if_unrecognized('remote_reason', stem.CircClosureReason)
Example #3
0
  def _parse(self):
    if self.id and not tor_tools.is_valid_circuit_id(self.id):
      raise stem.ProtocolError("Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.id, self))
    elif self.inbound_queue and not tor_tools.is_valid_circuit_id(self.inbound_queue):
      raise stem.ProtocolError("Queue IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.inbound_queue, self))
    elif self.inbound_connection and not tor_tools.is_valid_connection_id(self.inbound_connection):
      raise stem.ProtocolError("Connection IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.inbound_connection, self))
    elif self.outbound_queue and not tor_tools.is_valid_circuit_id(self.outbound_queue):
      raise stem.ProtocolError("Queue IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.outbound_queue, self))
    elif self.outbound_connection and not tor_tools.is_valid_connection_id(self.outbound_connection):
      raise stem.ProtocolError("Connection IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.outbound_connection, self))

    self.inbound_added = _parse_cell_type_mapping(self.inbound_added)
    self.inbound_removed = _parse_cell_type_mapping(self.inbound_removed)
    self.inbound_time = _parse_cell_type_mapping(self.inbound_time)
    self.outbound_added = _parse_cell_type_mapping(self.outbound_added)
    self.outbound_removed = _parse_cell_type_mapping(self.outbound_removed)
    self.outbound_time = _parse_cell_type_mapping(self.outbound_time)
Example #4
0
class CircMinorEvent(Event):
    """
  Event providing information about minor changes in our circuits. This was
  first added in tor version 0.2.3.11.

  The CIRC_MINOR event was introduced in tor version 0.2.3.11-alpha.

  :var str id: circuit identifier
  :var stem.CircEvent event: type of change in the circuit
  :var tuple path: relays involved in the circuit, these are
    **(fingerprint, nickname)** tuples
  :var tuple build_flags: :data:`~stem.CircBuildFlag` attributes
    governing how the circuit is built
  :var stem.CircPurpose purpose: purpose that the circuit is intended for
  :var stem.HiddenServiceState hs_state: status if this is a hidden service circuit
  :var str rend_query: circuit's rendezvous-point if this is hidden service related
  :var datetime created: time when the circuit was created or cannibalized
  :var stem.CircPurpose old_purpose: prior purpose for the circuit
  :var stem.HiddenServiceState old_hs_state: prior status as a hidden service circuit
  """

    _POSITIONAL_ARGS = ("id", "event", "path")
    _KEYWORD_ARGS = {
        "BUILD_FLAGS": "build_flags",
        "PURPOSE": "purpose",
        "HS_STATE": "hs_state",
        "REND_QUERY": "rend_query",
        "TIME_CREATED": "created",
        "OLD_PURPOSE": "old_purpose",
        "OLD_HS_STATE": "old_hs_state",
    }
    _VERSION_ADDED = stem.version.Requirement.EVENT_CIRC_MINOR

    def _parse(self):
        self.path = tuple(stem.control._parse_circ_path(self.path))

        if self.build_flags is not None:
            self.build_flags = tuple(self.build_flags.split(','))

        if self.created is not None:
            try:
                self.created = str_tools._parse_iso_timestamp(self.created)
            except ValueError, exc:
                raise stem.ProtocolError(
                    "Unable to parse create date (%s): %s" % (exc, self))

        if not tor_tools.is_valid_circuit_id(self.id):
            raise stem.ProtocolError(
                "Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.id, self))

        self._log_if_unrecognized('event', stem.CircEvent)
        self._log_if_unrecognized('build_flags', stem.CircBuildFlag)
        self._log_if_unrecognized('purpose', stem.CircPurpose)
        self._log_if_unrecognized('hs_state', stem.HiddenServiceState)
        self._log_if_unrecognized('old_purpose', stem.CircPurpose)
        self._log_if_unrecognized('old_hs_state', stem.HiddenServiceState)
Example #5
0
  def _parse(self):
    if not self.id:
      raise stem.ProtocolError('CIRC_BW event is missing its id')
    elif not self.read:
      raise stem.ProtocolError('CIRC_BW event is missing its read value')
    elif not self.written:
      raise stem.ProtocolError('CIRC_BW event is missing its written value')
    elif not self.read.isdigit() or not self.written.isdigit():
      raise stem.ProtocolError("A CIRC_BW event's bytes sent and received should be a positive numeric value, received: %s" % self)
    elif not tor_tools.is_valid_circuit_id(self.id):
      raise stem.ProtocolError("Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.id, self))

    self.read = int_type(self.read)
    self.written = int_type(self.written)
Example #6
0
    def _parse(self):
        if not self.id:
            raise stem.ProtocolError('CIRC_BW event is missing its id')
        elif not self.read:
            raise stem.ProtocolError('CIRC_BW event is missing its read value')
        elif not self.written:
            raise stem.ProtocolError(
                'CIRC_BW event is missing its written value')
        elif not self.read.isdigit() or not self.written.isdigit():
            raise stem.ProtocolError(
                "A CIRC_BW event's bytes sent and received should be a positive numeric value, received: %s"
                % self)
        elif not tor_tools.is_valid_circuit_id(self.id):
            raise stem.ProtocolError(
                "Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.id, self))

        self.read = int_type(self.read)
        self.written = int_type(self.written)
Example #7
0
  def _parse(self):
    self.path = tuple(stem.control._parse_circ_path(self.path))

    if self.build_flags is not None:
      self.build_flags = tuple(self.build_flags.split(','))

    if self.created is not None:
      try:
        self.created = str_tools._parse_iso_timestamp(self.created)
      except ValueError as exc:
        raise stem.ProtocolError('Unable to parse create date (%s): %s' % (exc, self))

    if not tor_tools.is_valid_circuit_id(self.id):
      raise stem.ProtocolError("Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.id, self))

    self._log_if_unrecognized('event', stem.CircEvent)
    self._log_if_unrecognized('build_flags', stem.CircBuildFlag)
    self._log_if_unrecognized('purpose', stem.CircPurpose)
    self._log_if_unrecognized('hs_state', stem.HiddenServiceState)
    self._log_if_unrecognized('old_purpose', stem.CircPurpose)
    self._log_if_unrecognized('old_hs_state', stem.HiddenServiceState)
Example #8
0
    def _parse(self):
        self.path = tuple(stem.control._parse_circ_path(self.path))

        if self.build_flags is not None:
            self.build_flags = tuple(self.build_flags.split(','))

        if self.created is not None:
            try:
                self.created = str_tools._parse_iso_timestamp(self.created)
            except ValueError as exc:
                raise stem.ProtocolError(
                    'Unable to parse create date (%s): %s' % (exc, self))

        if not tor_tools.is_valid_circuit_id(self.id):
            raise stem.ProtocolError(
                "Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s"
                % (self.id, self))

        self._log_if_unrecognized('event', stem.CircEvent)
        self._log_if_unrecognized('build_flags', stem.CircBuildFlag)
        self._log_if_unrecognized('purpose', stem.CircPurpose)
        self._log_if_unrecognized('hs_state', stem.HiddenServiceState)
        self._log_if_unrecognized('old_purpose', stem.CircPurpose)
        self._log_if_unrecognized('old_hs_state', stem.HiddenServiceState)