If using bundled Tor, wait for rendezvous circuits to close before killing the tor process

This commit is contained in:
Micah Lee 2020-11-25 11:25:32 -08:00
parent cb598ee697
commit 0eee8ce05b
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73

View File

@ -749,6 +749,32 @@ class Onion(object):
if stop_tor:
# Stop tor process
if self.tor_proc:
rendevouz_circuit_ids = []
for c in self.c.get_circuits():
if c.purpose == "HS_SERVICE_REND":
rendevouz_circuit_ids.append(c.id)
# print(f"id={c.id} purpose={c.purpose} rend_query={c.rend_query} type={c.type}")
while True:
num_rend_circuits = 0
for c in self.c.get_circuits():
if c.id in rendevouz_circuit_ids:
num_rend_circuits += 1
if num_rend_circuits == 0:
print("Tor rendevous circuits have closed" + " " * 20)
break
if num_rend_circuits == 1:
circuits = "circuit"
else:
circuits = "circuits"
print(
f"\rWaiting for {num_rend_circuits} Tor rendezvous {circuits} to close ... ",
end="",
)
time.sleep(1)
self.tor_proc.terminate()
time.sleep(0.2)
if self.tor_proc.poll() is None: