Guest User

Untitled

a guest
May 23rd, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. Probe = namedtuple('Probe', 'path circs cbt streams perf bw')
  2.  
  3. def _circuit_handler(event):
  4.     """ Event handler for handling circuit states. """
  5.     if not event.build_flags or 'IS_INTERNAL' not in event.build_flags:
  6.         if event.id == self._cid:
  7.             probe.circs.append(event)
  8.             if self._circuit_built.is_set():
  9.                 if event.status in ('FAILED', 'CLOSED'):
  10.                     self._circuit_finished.set()
  11.             if not self._circuit_built.is_set():
  12.                 if event.status in ('FAILED', 'BUILT'):
  13.                     self._circuit_built.set()
  14.         elif event.status == 'LAUNCHED' and not self._cid:
  15.             self._cid = event.id
  16.             probe.circs.append(event)
  17.             self._manager.circ_launched.release()
  18.  
  19. while(true):        #try until a valid circuit is received:
  20.     probe = Probe(path=self.path, circs=[], cbt=set(), streams=[],perf=[], bw=[])
  21.     circ_path = [node.desc.fingerprint for node in self.path]       #Valid nodes already acquired and stored in path
  22.     self._manager.circ_launched.acquire()
  23.     self._controller.add_event_listener(_circuit_handler, EventType.CIRC)
  24.     self._controller.add_event_listener(_cbt_check, EventType.INFO)
  25.     circID = self._controller.extend_circuit(path=circ_path)
  26.     self._circuit_built.wait()
  27.     build_status = probe.circs[len(probe.circs) - 1].status
  28.     assert build_status == 'BUILT' or build_status == 'FAILED', \
  29.         'Wrong circuit status: %s.' % build_statusFirst
  30.     if build_status == 'FAILED':
  31.         self._controller.remove_event_listener(_circuit_handler)
  32.         self._controller.remove_event_listener(_cbt_check)
  33.         self.path = self._manager._get_new_path()
  34.     else:
  35.         break
  36. #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:
  37. #build_status = probe.circs[len(probe.circs) - 1].status
  38. #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