Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from twisted.internet.task import react | ||
from twisted.internet.defer import inlineCallbacks | ||
from twisted.internet.endpoints import UNIXClientEndpoint | ||
|
||
import txtorcon | ||
|
||
|
||
@react | ||
@inlineCallbacks | ||
def main(reactor): | ||
""" | ||
Close all open streams and circuits in the Tor we connect to | ||
""" | ||
control_ep = UNIXClientEndpoint(reactor, '/var/run/tor/control') | ||
tor = yield txtorcon.connect(reactor, control_ep) | ||
state = yield tor.create_state() | ||
print("Closing all circuits:") | ||
for circuit in list(state.circuits.values()): | ||
path = '->'.join(map(lambda r: r.id_hex, circuit.path)) | ||
print("Circuit {} through {}".format(circuit.id, path)) | ||
for stream in circuit.streams: | ||
print(" Stream {} to {}".format(stream.id, stream.target_host)) | ||
yield stream.close() | ||
print(" closed") | ||
yield circuit.close() | ||
print("closed") | ||
yield tor.quit() |