Exemple #1
0
    def __init__(self, rate):
        super(ConnectionTracker, self).__init__(rate)

        self._connections = []
        self._start_times = {}  # connection => (unix_timestamp, is_legacy)
        self._custom_resolver = None
        self._is_first_run = True

        # Number of times in a row we've either failed with our current resolver or
        # concluded that our rate is too low.

        self._failure_count = 0
        self._rate_too_low_count = 0

        # If 'DisableDebuggerAttachment 0' is set we can do normal connection
        # resolution. Otherwise connection resolution by inference is the only game
        # in town.

        self._resolvers = []

        if tor_controller().get_conf('DisableDebuggerAttachment', None) == '0':
            self._resolvers = connection.system_resolvers()

        if stem.util.proc.is_available():
            self._resolvers = [CustomResolver.INFERENCE] + self._resolvers

        stem.util.log.info('Operating System: %s, Connection Resolvers: %s' %
                           (os.uname()[0], ', '.join(self._resolvers)))
Exemple #2
0
    def __init__(self, rate):
        super(ConnectionTracker, self).__init__(rate)

        self._connections = []
        self._start_times = {}  # connection => (unix_timestamp, is_legacy)
        self._custom_resolver = None
        self._is_first_run = True

        # Number of times in a row we've either failed with our current resolver or
        # concluded that our rate is too low.

        self._failure_count = 0
        self._rate_too_low_count = 0

        # If 'DisableDebuggerAttachment 0' is set we can do normal connection
        # resolution. Otherwise connection resolution by inference is the only game
        # in town.

        self._resolvers = [CustomResolver.INFERENCE
                           ] if stem.util.proc.is_available() else []

        if tor_controller().get_conf('DisableDebuggerAttachment', None) == '0':
            self._resolvers = self._resolvers + connection.system_resolvers()
        elif not self._resolvers:
            stem.util.log.notice(
                "Tor connection information is unavailable. This is fine, but if you would like to have it please see https://nyx.torproject.org/#no_connections"
            )

        stem.util.log.info('Operating System: %s, Connection Resolvers: %s' %
                           (os.uname()[0], ', '.join(self._resolvers)))
Exemple #3
0
    def check_resolver(self, resolver):
        runner = test.runner.get_runner()

        if test.runner.Torrc.PORT not in runner.get_options():
            self.skipTest('(no control port)')
            return
        elif resolver not in system_resolvers():
            self.skipTest('(resolver unavailable on this platform)')
            return

        with runner.get_tor_socket():
            connections = get_connections(resolver,
                                          process_pid=runner.get_pid())

            for conn in connections:
                if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT:
                    return

            resolver_command = RESOLVER_COMMAND[resolver].format(
                pid=runner.get_pid())
            resolver_output = stem.util.system.call(resolver_command)

            self.fail(
                'Unable to find our controller connection with %s (%s). Connections found were...\n\n%s\n\nCommand output was...\n\n%s'
                % (resolver, resolver_command, '\n'.join(map(
                    str, connections)), resolver_output))
Exemple #4
0
  def __init__(self, rate):
    super(ConnectionTracker, self).__init__(rate)

    self._connections = []
    self._start_times = {}  # connection => (unix_timestamp, is_legacy)
    self._resolvers = connection.system_resolvers()
    self._custom_resolver = None
    self._is_first_run = True

    # Number of times in a row we've either failed with our current resolver or
    # concluded that our rate is too low.

    self._failure_count = 0
    self._rate_too_low_count = 0
Exemple #5
0
def get_entry_ip():
    resolvers = system_resolvers()  # check avaiable resolvers
    tor_pids = pid_by_name('tor', multiple=True)  # gets tor's PID

    if len(resolvers) > 0 and len(tor_pids) > 0:

        picked_resolver = resolvers[0]  # getting the first one
        try:
            process_pid = tor_pids[0]
            # getting the first, if we are running tor only as a service it must have just one PID
            cons = get_connections(picked_resolver, process_pid, process_name='tor')
            return cons

        except ValueError, IOError:
            print "Error getting connections to entry point"
Exemple #6
0
  def check_resolver(self, resolver):
    runner = test.runner.get_runner()

    if test.runner.Torrc.PORT not in runner.get_options():
      self.skipTest('(no control port)')
      return
    elif resolver not in system_resolvers():
      self.skipTest('(resolver unavailable on this platform)')
      return

    with runner.get_tor_socket():
      connections = get_connections(resolver, process_pid = runner.get_pid())

      for conn in connections:
        if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT:
          return

      self.fail('Unable to find localhost connection with %s:\n%s' % (resolver, '\n'.join(connections)))
Exemple #7
0
    def check_resolver(self, resolver):
        runner = test.runner.get_runner()

        if test.runner.Torrc.PORT not in runner.get_options():
            self.skipTest('(no control port)')
            return
        elif resolver not in system_resolvers():
            self.skipTest('(resolver unavailable on this platform)')
            return

        with runner.get_tor_socket():
            connections = get_connections(resolver,
                                          process_pid=runner.get_pid())

            for conn in connections:
                if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT:
                    return

            self.fail('Unable to find localhost connection with %s:\n%s' %
                      (resolver, '\n'.join(connections)))
Exemple #8
0
  def __init__(self, rate):
    super(ConnectionTracker, self).__init__(rate)

    self._connections = []
    self._start_times = {}  # connection => (unix_timestamp, is_legacy)
    self._custom_resolver = None
    self._is_first_run = True

    # Number of times in a row we've either failed with our current resolver or
    # concluded that our rate is too low.

    self._failure_count = 0
    self._rate_too_low_count = 0

    # If 'DisableDebuggerAttachment 0' is set we can do normal connection
    # resolution. Otherwise connection resolution by inference is the only game
    # in town.

    if tor_controller().get_conf('DisableDebuggerAttachment', None) == '0':
      self._resolvers = connection.system_resolvers()
    else:
      self._resolvers = [CustomResolver.INFERENCE]

    log.info('tracker.available_resolvers', os = os.uname()[0], resolvers = ', '.join(self._resolvers))
Exemple #9
0
import sys

from stem.util.connection import get_connections, system_resolvers
from stem.util.system import pid_by_name

resolvers = system_resolvers()

if not resolvers:
  print("Stem doesn't support any connection resolvers on our platform.")
  sys.exit(1)

picked_resolver = resolvers[0]  # lets just opt for the first
print("Our platform supports connection resolution via: %s (picked %s)" % (', '.join(resolvers), picked_resolver))

tor_pids = pid_by_name('tor', multiple = True)

if not tor_pids:
  print("Unable to get tor's pid. Is it running?")
  sys.exit(1)
elif len(tor_pids) > 1:
  print("You're running %i instances of tor, picking the one with pid %i" % (len(tor_pids), tor_pids[0]))
else:
  print("Tor is running with pid %i" % tor_pids[0])

print("\nConnections:\n")

for conn in get_connections(picked_resolver, process_pid = tor_pids[0], process_name = 'tor'):
  print("  %s:%s => %s:%s" % (conn.local_address, conn.local_port, conn.remote_address, conn.remote_port))
Exemple #10
0
import sys

from stem.util.connection import get_connections, system_resolvers
from stem.util.system import pid_by_name

resolvers = system_resolvers()

if not resolvers:
    print("Stem doesn't support any connection resolvers on our platform.")
    sys.exit(1)

picked_resolver = resolvers[0]  # lets just opt for the first
print('Our platform supports connection resolution via: %s (picked %s)' %
      (', '.join(resolvers), picked_resolver))

tor_pids = pid_by_name('tor', multiple=True)

if not tor_pids:
    print("Unable to get tor's pid. Is it running?")
    sys.exit(1)
elif len(tor_pids) > 1:
    print("You're running %i instances of tor, picking the one with pid %i" %
          (len(tor_pids), tor_pids[0]))
else:
    print('Tor is running with pid %i' % tor_pids[0])

print('\nConnections:\n')

for conn in get_connections(picked_resolver,
                            process_pid=tor_pids[0],
                            process_name='tor'):