Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Probe = namedtuple('Probe', 'path circs cbt streams perf bw')
- def _circuit_handler(event):
- """ Event handler for handling circuit states. """
- if not event.build_flags or 'IS_INTERNAL' not in event.build_flags:
- if event.id == self._cid:
- probe.circs.append(event)
- if self._circuit_built.is_set():
- if event.status in ('FAILED', 'CLOSED'):
- self._circuit_finished.set()
- if not self._circuit_built.is_set():
- if event.status in ('FAILED', 'BUILT'):
- self._circuit_built.set()
- elif event.status == 'LAUNCHED' and not self._cid:
- self._cid = event.id
- probe.circs.append(event)
- self._manager.circ_launched.release()
- while(true): #try until a valid circuit is received:
- probe = Probe(path=self.path, circs=[], cbt=set(), streams=[],perf=[], bw=[])
- circ_path = [node.desc.fingerprint for node in self.path] #Valid nodes already acquired and stored in path
- self._manager.circ_launched.acquire()
- self._controller.add_event_listener(_circuit_handler, EventType.CIRC)
- self._controller.add_event_listener(_cbt_check, EventType.INFO)
- circID = self._controller.extend_circuit(path=circ_path)
- self._circuit_built.wait()
- build_status = probe.circs[len(probe.circs) - 1].status
- assert build_status == 'BUILT' or build_status == 'FAILED', \
- 'Wrong circuit status: %s.' % build_statusFirst
- if build_status == 'FAILED':
- self._controller.remove_event_listener(_circuit_handler)
- self._controller.remove_event_listener(_cbt_check)
- self.path = self._manager._get_new_path()
- else:
- break
- #This works fine if the circuit is successfully established in the first attempt. However, if the circuit is not established in the first, attempt, the line:
- #build_status = probe.circs[len(probe.circs) - 1].status
- #crashes, because the event apparently does not append anything to probe.circs, and Index out of range exception is thrown
Add Comment
Please, Sign In to add comment