Example #1
0
 def get_exit_node(self):
     ret = copy.copy(self.last_exit)  # GIL FTW
     if ret:
         plog("DEBUG", "Got last exit of " + ret.idhex)
     else:
         plog("DEBUG", "No last exit.")
     return ret
Example #2
0
 def notlambda(this):
     cond.acquire()
     SQLSupport.tc_session.close()
     try:
         shutil.copy(sql_file, new_file)
     except Exception, e:
         plog("WARN", "Error moving sql file: " + str(e))
Example #3
0
 def get_exit_node(self):
     ret = copy.copy(self.last_exit)  # GIL FTW
     if ret:
         plog("DEBUG", "Got last exit of " + ret.idhex)
     else:
         plog("DEBUG", "No last exit.")
     return ret
Example #4
0
def get_continent(country_code):
    """ Perform country -- continent mapping """
    for c in continents:
        if c.contains(country_code):
            return c
    plog("INFO", country_code + " is not on any continent")
    return None
def get_continent(country_code):
  """ Perform country -- continent mapping """
  for c in continents:
    if c.contains(country_code):
      return c
  plog("INFO", country_code + " is not on any continent")
  return None
Example #6
0
 def notlambda(this):
     cond.acquire()
     SQLSupport.tc_session.close()
     try:
         shutil.copy(sql_file, new_file)
     except Exception, e:
         plog("WARN", "Error moving sql file: " + str(e))
Example #7
0
 def notlambda(sm):
   plog("DEBUG", "Job for setexit: "+exit_name)
   cond.acquire()
   # Clear last successful exit, we're running a new test
   self.last_exit = None
   sm.set_exit(exit_name)
   cond.notify()
   cond.release()
Example #8
0
 def notlambda(sm):
     plog("DEBUG", "Job for setexit: " + exit_name)
     cond.acquire()
     # Clear last successful exit, we're running a new test
     self.last_exit = None
     sm.set_exit(exit_name)
     cond.notify()
     cond.release()
Example #9
0
 def notlambda(this):
     if this.sql_consensus_listener.last_desc_at != SQLSupport.ConsensusTrackerListener.CONSENSUS_DONE:
         this.sql_consensus_listener.wait_for_signal = False
         plog("INFO", "Waiting on consensus result: " + str(this.run_all_jobs))
         this.schedule_low_prio(notlambda)
     else:
         cond.acquire()
         this.sql_consensus_listener.wait_for_signal = True
         cond.notify()
         cond.release()
Example #10
0
 def notlambda(this):
   if this.sql_consensus_listener.last_desc_at \
              != SQLSupport.ConsensusTrackerListener.CONSENSUS_DONE:
     this.sql_consensus_listener.wait_for_signal = False
     plog("INFO", "Waiting on consensus result: "+str(this.run_all_jobs))
     this.schedule_low_prio(notlambda)
   else:
     cond.acquire()
     this.sql_consensus_listener.wait_for_signal = True
     cond.notify()
     cond.release()
Example #11
0
 def notlambda(this):
     cond.acquire()
     this.new_nym = True
     if this.selmgr.bad_restrictions:
         plog("NOTICE", "Clearing bad restrictions with reconfigure..")
         this.selmgr.reconfigure(this.current_consensus())
     lines = this.c.sendAndRecv("SIGNAL CLEARDNSCACHE\r\n")
     for _, msg, more in lines:
         plog("DEBUG", msg)
     cond.notify()
     cond.release()
 def __init__(self, router):
   self.__dict__ = router.__dict__
   self.country_code = get_country(self.get_ip_dotted())
   if self.country_code != None: 
     c = get_continent(self.country_code)
     if c != None:
       self.continent = c.code
       self.cont_group = c.group
   else: 
     plog("INFO", self.nickname + ": Country code not found")
     self.continent = None
Example #13
0
 def __init__(self, router):
     self.__dict__ = router.__dict__
     self.country_code = get_country(self.get_ip_dotted())
     if self.country_code != None:
         c = get_continent(self.country_code)
         if c != None:
             self.continent = c.code
             self.cont_group = c.group
     else:
         plog("INFO", self.nickname + ": Country code not found")
         self.continent = None
Example #14
0
 def notlambda(this):
     cond.acquire()
     this.new_nym = True
     if this.selmgr.bad_restrictions:
         plog("NOTICE", "Clearing bad restrictions with reconfigure..")
         this.selmgr.reconfigure(this.current_consensus())
     lines = this.c.sendAndRecv("SIGNAL CLEARDNSCACHE\r\n")
     for _, msg, more in lines:
         plog("DEBUG", msg)
     cond.notify()
     cond.release()
Example #15
0
 def close_streams(self, reason):
   cond = threading.Condition()
   plog("NOTICE", "Wedged Tor stream. Closing all streams")
   def notlambda(this):
     cond.acquire()
     this.close_all_streams(reason)
     cond.notify()
     cond.release()
   cond.acquire()
   self.schedule_low_prio(notlambda)
   cond.wait()
   cond.release()
Example #16
0
 def close_streams(self, reason):
   cond = threading.Condition()
   plog("NOTICE", "Wedged Tor stream. Closing all streams")
   def notlambda(this):
     cond.acquire()
     this.close_all_streams(reason)
     cond.notify()
     cond.release()
   cond.acquire()
   self.schedule_low_prio(notlambda)
   cond.wait()
   cond.release()
Example #17
0
 def set_exit_node(self, arg):
   cond = threading.Condition()
   exit_name = arg
   plog("DEBUG", "Got Setexit: "+exit_name)
   def notlambda(sm):
     plog("DEBUG", "Job for setexit: "+exit_name)
     cond.acquire()
     sm.set_exit(exit_name)
     cond.notify()
     cond.release()
   cond.acquire()
   self.schedule_selmgr(notlambda)
   cond.wait()
   cond.release()
Example #18
0
 def set_exit_node(self, arg):
   cond = threading.Condition()
   exit_name = arg
   plog("DEBUG", "Got Setexit: "+exit_name)
   def notlambda(sm):
     plog("DEBUG", "Job for setexit: "+exit_name)
     cond.acquire()
     sm.set_exit(exit_name)
     cond.notify()
     cond.release()
   cond.acquire()
   self.schedule_selmgr(notlambda)
   cond.wait()
   cond.release()
Example #19
0
 def set_exit_node(self, arg):
   cond = threading.Condition()
   exit_name = arg
   plog("DEBUG", "Got Setexit: "+exit_name)
   def notlambda(sm):
     plog("DEBUG", "Job for setexit: "+exit_name)
     cond.acquire()
     # Clear last successful exit, we're running a new test
     self.last_exit = None
     sm.set_exit(exit_name)
     cond.notify()
     cond.release()
   cond.acquire()
   self.schedule_selmgr(notlambda)
   cond.wait()
   cond.release()
Example #20
0
    def set_exit_node(self, arg):
        cond = threading.Condition()
        exit_name = arg
        plog("DEBUG", "Got Setexit: " + exit_name)

        def notlambda(sm):
            plog("DEBUG", "Job for setexit: " + exit_name)
            cond.acquire()
            # Clear last successful exit, we're running a new test
            self.last_exit = None
            sm.set_exit(exit_name)
            cond.notify()
            cond.release()

        cond.acquire()
        self.schedule_selmgr(notlambda)
        cond.wait()
        cond.release()
Example #21
0
 def wait_for_consensus(self):
   cond = threading.Condition()
   def notlambda(this):
     if this.sql_consensus_listener.last_desc_at \
                != SQLSupport.ConsensusTrackerListener.CONSENSUS_DONE:
       this.sql_consensus_listener.wait_for_signal = False
       plog("INFO", "Waiting on consensus result: "+str(this.run_all_jobs))
       this.schedule_low_prio(notlambda)
     else:
       cond.acquire()
       this.sql_consensus_listener.wait_for_signal = True
       cond.notify()
       cond.release()
   plog("DEBUG", "Checking for consensus")
   cond.acquire()
   self.schedule_low_prio(notlambda)
   cond.wait()
   cond.release()
   plog("INFO", "Consensus OK")
Example #22
0
 def wait_for_consensus(self):
   cond = threading.Condition()
   def notlambda(this):
     if this.sql_consensus_listener.last_desc_at \
                != SQLSupport.ConsensusTrackerListener.CONSENSUS_DONE:
       this.sql_consensus_listener.wait_for_signal = False
       plog("INFO", "Waiting on consensus result: "+str(this.run_all_jobs))
       this.schedule_low_prio(notlambda)
     else:
       cond.acquire()
       this.sql_consensus_listener.wait_for_signal = True
       cond.notify()
       cond.release()
   plog("DEBUG", "Checking for consensus")
   cond.acquire()
   self.schedule_low_prio(notlambda)
   cond.wait()
   cond.release()
   plog("INFO", "Consensus OK")
Example #23
0
  def commit(self):
    plog("INFO", "Scanner committing jobs...")
    cond = threading.Condition()
    def notlambda2(this):
      cond.acquire()
      this.run_all_jobs = False
      plog("INFO", "Commit done.")
      cond.notify()
      cond.release()

    def notlambda1(this):
      plog("INFO", "Committing jobs...")
      this.run_all_jobs = True
      self.schedule_low_prio(notlambda2)

    cond.acquire()
    self.schedule_immediate(notlambda1)

    cond.wait()
    cond.release()
    plog("INFO", "Scanner commit done.")
Example #24
0
  def commit(self):
    plog("INFO", "Scanner committing jobs...")
    cond = threading.Condition()
    def notlambda2(this):
      cond.acquire()
      this.run_all_jobs = False
      plog("INFO", "Commit done.")
      cond.notify()
      cond.release()

    def notlambda1(this):
      plog("INFO", "Committing jobs...")
      this.run_all_jobs = True
      self.schedule_low_prio(notlambda2)

    cond.acquire()
    self.schedule_immediate(notlambda1)

    cond.wait()
    cond.release()
    plog("INFO", "Scanner commit done.")
Example #25
0
 def notlambda2(this):
     cond.acquire()
     this.run_all_jobs = False
     plog("INFO", "Commit done.")
     cond.notify()
     cond.release()
Example #26
0
 def notlambda(sm):
     plog("DEBUG", "Job for setexit: " + exit_name)
     cond.acquire()
     sm.set_exit(exit_name)
     cond.notify()
     cond.release()
Example #27
0
 def attach_sql_listener(self, db_uri):
     plog("DEBUG", "Got sqlite: " + db_uri)
     SQLSupport.setup_db(db_uri, echo=False, drop=True)
     self.sql_consensus_listener = SQLSupport.ConsensusTrackerListener()
     self.add_event_listener(self.sql_consensus_listener)
     self.add_event_listener(SQLSupport.StreamListener())
Example #28
0
 def notlambda(sm):
     plog("DEBUG", "Job for setexit: " + exit_name)
     cond.acquire()
     sm.set_exit(exit_name)
     cond.notify()
     cond.release()
Example #29
0
 def attach_sql_listener(self, db_uri):
     plog("DEBUG", "Got sqlite: " + db_uri)
     SQLSupport.setup_db(db_uri, echo=False, drop=True)
     self.sql_consensus_listener = SQLSupport.ConsensusTrackerListener()
     self.add_event_listener(self.sql_consensus_listener)
     self.add_event_listener(SQLSupport.StreamListener())
Example #30
0
 def notlambda2(this):
     cond.acquire()
     this.run_all_jobs = False
     plog("INFO", "Commit done.")
     cond.notify()
     cond.release()
Example #31
0
 def notlambda1(this):
     plog("INFO", "Committing jobs...")
     this.run_all_jobs = True
     self.schedule_low_prio(notlambda2)
Example #32
0
 def notlambda1(this):
     plog("INFO", "Committing jobs...")
     this.run_all_jobs = True
     self.schedule_low_prio(notlambda2)
Example #33
0
#!/usr/bin/python
# Copyright 2007 Johannes Renner and Mike Perry. See LICENSE file.

import struct
import socket
import TorCtl
import StatsSupport

from TorUtil import plog
try:
  import GeoIP
  # GeoIP data object: choose database here
  geoip = GeoIP.new(GeoIP.GEOIP_STANDARD)
  #geoip = GeoIP.open("./GeoLiteCity.dat", GeoIP.GEOIP_STANDARD)
except:
  plog("NOTICE", "No GeoIP library. GeoIPSupport.py will not work correctly")
  # XXX: How do we bail entirely..  


class Continent:
  """ Continent class: The group attribute is to partition the continents
      in groups, to determine the number of ocean crossings """
  def __init__(self, continent_code):
    self.code = continent_code 
    self.group = None
    self.countries = []

  def contains(self, country_code):
    return country_code in self.countries

# Set countries to continents
#!/usr/bin/python

import struct
import socket
import TorCtl
import StatsSupport

from TorUtil import plog
try:
  import GeoIP
  # GeoIP data object: choose database here
  geoip = GeoIP.new(GeoIP.GEOIP_STANDARD)
  #geoip = GeoIP.open("./GeoLiteCity.dat", GeoIP.GEOIP_STANDARD)
except:
  plog("NOTICE", "No GeoIP library. GeoIPSupport.py will not work correctly")
  # XXX: How do we bail entirely..  


class Continent:
  """ Continent class: The group attribute is to partition the continents
      in groups, to determine the number of ocean crossings """
  def __init__(self, continent_code):
    self.code = continent_code 
    self.group = None
    self.countries = []

  def contains(self, country_code):
    return country_code in self.countries

# Set countries to continents
africa = Continent("AF")