Tor runner has a run function to replay the history

This commit is contained in:
Rémi Oudin 2018-02-25 21:53:28 +01:00
parent 0a676a2f65
commit f66c978466
1 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import shutil
import asyncio
import aiohttp
from aiosocks.connector import ProxyConnector, ProxyClientRequest
from time import sleep
import async_timeout
import stem.process as tor
@ -51,6 +52,19 @@ class TorInstance():
self.session = None
self.process = None
def run(self):
""" Runs the Tor Instance on the history.
"""
t_start = time.now()
while history:
item = history.pop(0)
async with async_timeout.timeout(30):
await(self.query(item[0]))
t_end = time.now()
diff = (history[0][1] - item[0]) - (t_end - t_start)
if diff > 0
sleep(diff)
def create_session(self):
""" Create a aiohttp session.