No idea man

This commit is contained in:
Casey 2024-07-09 21:11:47 +03:00
parent d667e8ffd2
commit e01fd368fa
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 19 additions and 11 deletions

View File

@ -31,15 +31,16 @@ class WorkerManager:
self.n_toggles = 0 self.n_toggles = 0
self.workers: set[tuple[int, int]] = set() self.workers: set[tuple[int, int]] = set()
self._restarts: dict[int, int] = {}
async def queue_manager(self): async def queue_manager(self):
offset = random.randint(0, 999999) offset = random.randint(0, 999999)
while True: while True:
for oy in [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]: for oy in [0, 2, 1, 3]:
for y in range(oy, 1000, 16): for y in range(oy, 1000, 4):
for x in range(1000): for x in range(1000):
index = (x + y * 1000 + offset) % 1000000 index = (x + y * 1000 + offset) % 1000000
byte, bit = divmod(index, 8) byte, bit = index >> 3, index & 7
mask = 0x80 >> bit mask = 0x80 >> bit
if self.shmem.buf[OFFSET_AVOID + byte] & mask: if self.shmem.buf[OFFSET_AVOID + byte] & mask:
@ -52,21 +53,24 @@ class WorkerManager:
self.shmem.buf[OFFSET_STATE + byte] & mask self.shmem.buf[OFFSET_STATE + byte] & mask
): ):
await self.queue.put(index) await self.queue.put(index)
await asyncio.sleep(0.01)
async def writer(self, bot_index: int, proxy: Optional[str] = None): async def writer(self, bot_index: int, proxy: Optional[str] = None):
connector = ProxyConnector.from_url(proxy) if proxy else None connector = ProxyConnector.from_url(proxy) if proxy else None
async with aiohttp.ClientSession(connector=connector) as http: async with aiohttp.ClientSession(connector=connector) as http:
sio = socketio.AsyncClient(http_session=http) sio = socketio.AsyncClient(http_session=http, reconnection=False)
self._restarts[bot_index] = 0
async def writer_itself(): async def writer_itself():
while not sio.connected: while not sio.connected:
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
cookie = bot_index, random.randint(0, 9999) self._restarts[bot_index] += 1
cookie = bot_index, self._restarts[bot_index]
self.workers.add(cookie) self.workers.add(cookie)
try: try:
while sio.connected: while sio.connected:
index = await self.queue.get() index = await self.queue.get()
byte, bit = divmod(index, 8) byte, bit = index >> 3, index & 7
mask = 0x80 >> bit mask = 0x80 >> bit
if self.shmem.buf[OFFSET_AVOID + byte] & mask: if self.shmem.buf[OFFSET_AVOID + byte] & mask:
@ -98,7 +102,7 @@ class WorkerManager:
diff = time.time() - last_printout diff = time.time() - last_printout
print() print()
print(f"Workers: {len(self.workers)}") print(f"Workers: {self.workers}")
print(f"Queue size: {self.queue.qsize()}/{self.queue.maxsize}") print(f"Queue size: {self.queue.qsize()}/{self.queue.maxsize}")
print(f"Toggles: {self.n_toggles / diff:.2f}/s") print(f"Toggles: {self.n_toggles / diff:.2f}/s")
@ -125,17 +129,21 @@ async def main(config_path: str = "worker.json", *_):
workers = [] workers = []
if proxies := config.get("proxy", []): if proxies := config.get("proxy", []):
workers.extend([mgr.writer(i, proxies[i % len(proxies)]) for i in range(n_bots)]) workers.extend(
[
mgr.writer(i, proxies[i % len(proxies)])
for i in range(n_bots)
]
)
else: else:
workers.extend([mgr.writer(i) for i in range(n_bots)]) workers.extend([mgr.writer(i) for i in range(n_bots)])
await asyncio.gather( await asyncio.gather(
mgr.queue_manager(), mgr.queue_manager(), mgr.status_display(), *workers
mgr.status_display(),
*workers
) )
if __name__ == "__main__": if __name__ == "__main__":
from sys import argv from sys import argv
asyncio.run(main(*argv[1:])) asyncio.run(main(*argv[1:]))