def circ_status_event(self, circ_event): """ handles circuit status event """ if circ_event.circ_id in self.circuits: if circ_event.status == 'EXTENDED': extend_time = circ_event.arrived_at-self.circuits[circ_event.circ_id].last_extended_at self.circuits[circ_event.circ_id].extend_times.append(extend_time) self.circuits[circ_event.circ_id].last_extended_at = circ_event.arrived_at if circ_event.status == 'BUILT': circ = self.circuits[circ_event.circ_id] buildtime = reduce(lambda x,y:x+y,circ.extend_times,0.0) self.extendtimesfile.write(str(circ.circ_id)+'\t'+'\t'.join(map(str, circ.extend_times))+'\n') self.extendtimesfile.flush() self.nodesfile.write(str(circ.circ_id)+'\t'+'\t'.join(circ.id_path())+'\n') self.nodesfile.flush() self.buildtimesfile.write(str(circ.circ_id) + '\t' + str(buildtime) + '\n') self.buildtimesfile.flush() # check to see if done gathering data if circ_event.status == 'BUILT': self.circ_built += 1 self.close_circuit(circ_event.circ_id) if circ_event.status == 'FAILED': circ = self.circuits[circ_event.circ_id] # Record it to the failed file.. self.failfile.write(str(circ.circ_id)+'\t'+'\t'.join(circ.id_path())+'\n') self.failfile.flush() StatsHandler.circ_status_event(self,circ_event)
def circ_status_event(self, circ_event): """ handles circuit status event """ if circ_event.circ_id in self.circuits: if circ_event.status == 'EXTENDED': extend_time = circ_event.arrived_at - self.circuits[ circ_event.circ_id].last_extended_at self.circuits[circ_event.circ_id].extend_times.append( extend_time) self.circuits[circ_event. circ_id].last_extended_at = circ_event.arrived_at if circ_event.status == 'BUILT': circ = self.circuits[circ_event.circ_id] buildtime = reduce(lambda x, y: x + y, circ.extend_times, 0.0) self.extendtimesfile.write( str(circ.circ_id) + '\t' + '\t'.join(map(str, circ.extend_times)) + '\n') self.extendtimesfile.flush() self.nodesfile.write( str(circ.circ_id) + '\t' + '\t'.join(circ.id_path()) + '\n') self.nodesfile.flush() self.buildtimesfile.write( str(circ.circ_id) + '\t' + str(buildtime) + '\n') self.buildtimesfile.flush() # check to see if done gathering data if circ_event.status == 'BUILT': self.circ_built += 1 self.close_circuit(circ_event.circ_id) if circ_event.status == 'FAILED': circ = self.circuits[circ_event.circ_id] # Record it to the failed file.. self.failfile.write( str(circ.circ_id) + '\t' + '\t'.join(circ.id_path()) + '\n') self.failfile.flush() StatsHandler.circ_status_event(self, circ_event)
def __init__(self,c, selmgr,basefile_name,nstats): StatsHandler.__init__(self,c, selmgr, BTRouter, track_ranks=True) self.nodesfile = open(basefile_name + '.nodes','w') self.failfile = open(basefile_name + '.failed','w') self.extendtimesfile = open(basefile_name + '.extendtimes','w') self.buildtimesfile = open(basefile_name + '.buildtimes','w') self.circ_built = 0 self.nstats = nstats self.done = False if self.selmgr.bad_restrictions: raise PathSupport.NoNodesRemain("No nodes remain after init") # Set up the exit restriction to include either 443 or 80 exits. # Since Tor dynamically pre-builds circuits depending on port usage, and # these are the two most commonly used user ports, this seems as good # first approximation to model the dynamic behavior of a real client's # circuit choice. self.selmgr.exit_rstr.del_restriction(ExitPolicyRestriction) self.selmgr.exit_rstr.del_restriction(OrNodeRestriction) self.selmgr.exit_rstr.add_restriction(OrNodeRestriction([ ExitPolicyRestriction("255.255.255.255", 80), ExitPolicyRestriction("255.255.255.255", 443)])) self.selmgr.path_selector.exit_gen.rebuild()
def __init__(self, c, selmgr, basefile_name, nstats): StatsHandler.__init__(self, c, selmgr, BTRouter, track_ranks=True) self.nodesfile = open(basefile_name + '.nodes', 'w') self.failfile = open(basefile_name + '.failed', 'w') self.extendtimesfile = open(basefile_name + '.extendtimes', 'w') self.buildtimesfile = open(basefile_name + '.buildtimes', 'w') self.circ_built = 0 self.nstats = nstats self.done = False if self.selmgr.bad_restrictions: raise PathSupport.NoNodesRemain("No nodes remain after init") # Set up the exit restriction to include either 443 or 80 exits. # Since Tor dynamically pre-builds circuits depending on port usage, and # these are the two most commonly used user ports, this seems as good # first approximation to model the dynamic behavior of a real client's # circuit choice. self.selmgr.exit_rstr.del_restriction(ExitPolicyRestriction) self.selmgr.exit_rstr.del_restriction(OrNodeRestriction) self.selmgr.exit_rstr.add_restriction( OrNodeRestriction([ ExitPolicyRestriction("255.255.255.255", 80), ExitPolicyRestriction("255.255.255.255", 443) ])) self.selmgr.path_selector.exit_gen.rebuild()