2

Is there some easy method to use circuits in parallel in TOR using the STEM API. I wanted to use Website A for Circuit A and Website B for Circuit B. The problem is using threading the event listener is global hence both threads attach streams for both websites on each circuit.

This (attached below) is the function I'm calling in each thread:

def scan(controller, path, websites, numReadings):
    circuit_id = controller.new_circuit(path, await_build = True)

    def attach_stream(stream):
        if stream.status == 'NEW':
            try:
                controller.attach_stream(stream.id, circuit_id)
            except Exception as E:
                print "Scan: " + str(E)
                return 1000


    controller.add_event_listener(attach_stream, stem.control.EventType.STREAM)

    try:
        controller.set_conf('__LeaveStreamsUnattached', '1')  # leave stream management to us
        getPage(controller, websites, numReadings, path)
    finally:
        controller.remove_event_listener(attach_stream)
        controller.reset_conf('__LeaveStreamsUnattached')
        controller.close_circuit(circuit_id)
  • Have you considered looking at the stream event to see if it's for website A or website B or is already attached to a stream before blindly attaching it to a circuit? stem.torproject.org/api/… – cacahuatl Jul 24 '16 at 21:18
  • I've checked if the stream is new. Plus there is no way to check if it's of a certain website. Because in my getPage function I get the whole webpage for google.com / yahoo.com and hence there could be multiple streams for one website. – George J. Adams Jul 24 '16 at 21:55
  • @SaimSalman: You can perhaps try to check the IP of the website attached to the stream using the target in StreamEvent over here: stem.torproject.org/api/… – QPTR Aug 21 '16 at 17:04
  • Alternatively you could just use stream.target inside attach_stream to check the website's address that the stream belongs to, and then attach that stream to the circuit you want. Or at least thats what I think. Could be wrong. – QPTR Aug 22 '16 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.