[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[python] __LeaveStreamsUnattached



Hi guys, I have quite special question. As I wrote many times before, Im trying to do some utility in python using Tor. Currently, Im playing again with core of utility - talking with Tor and downloading some files thru it.

Im trying to download HTTP file thru exact path (defined by router chain). So I tried to make these steps:
1) Create circuit
2) Create stream
3) Attach stream to circuit
4) Do HTTP communication

Are these steps logically OK? Because if yes, Im in problematic situation. When I tried to openstream with __LeaveStreamsUnattached=0 (default configuration), Tor automatically assign stream to any open circuit (but I want to use one specific). But when I set __LeaveStreamsUnattached=1, I obtain deadlock on "proxy.connect()" and I cannot continue with point 3). But I dont found any method, how to obtain stream id _before_ calling proxy.connect() to pair stream to circuit before calling this function...

Please tell me, what I should do different, because I think I tried everything :). Yes, I can connect specific circuit with specific stream (using REMAP), but this solution was very ugly and I dislike them, because it was firstly make own circuit and I redirect them in next step.

Note: Code bellow is just prototype, so please excuse coding culture :-).

Thank you very much,
Marek

PS: Sorry for my english, Im doing my best.
--------

ctl.ctl.set_option('__LeaveStreamsUnattached','1')

# Step 1 - create circuit thru specific routers
circ = ctl.ctl.extend_circuit(0,["ztorsrv", 'tornodeviennasil'])
print "circ id", circ

# Step 2 - open connection to local proxy
proxy = Proxy(torhost,torproxyport)
proxy.setEventHandler(events)

# Deadlock with __LeaveStreamsUnattached=1 !!!
# Method is probably waiting to attach stream with circuit
print "connecting to destination"
proxy.connect('slush.cz', 80)

# Im waiting for callback from Tor controller. In stream_id will be
# filled correct stream # assigned with my socket connection.
# In final concept, I will use standard locks etc...
while(not stream_id):
    time.sleep(1)
    print "Stream id", stream_id
print "Stream id", stream_id

# Step 3 - connect stream and circuit
ctl.ctl.attach_stream(stream_id, circ)

# Step 4 - doing communication
proxy.send("GET /tortest.php HTTP/1.1\r\nHost: slush.cz\r\n\r\n")
proxy.recv()
proxy.close()