123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- from connection.broadcast import BroadcastClient
- from connection.socket import SocketClient
- import time
- import config as cfg
- from .userParser import UserParser
- import secrets
- from Utils import *
- class User:
- def __init__(self, data, server, broadcast, broadcastPort):
- time.sleep(1)
- print("user")
- self.onlineOracles = []
- self.id = "PADRA"
- self.server = server
- self.data = data
- self.dataLen = len(data) // 2
- self.parser = UserParser(self)
- self.broadcast = BroadcastClient(
- broadcast=broadcast,
- broadcastPort=broadcastPort,
- parser=self.parser,
- id=self.id,
- )
- self.keyCryptor = secrets.token_hex(16)
- self.keyConnector = secrets.token_hex(16)
- def run(self):
- self.broadcast.send(
- self.parser.requestOracleBroadcast(self.id), self.broadcast.addr
- )
- while len(self.onlineOracles) < cfg.numberOfOracles:
- l = len(self.onlineOracles)
- yBackPrint(
- "Warning",
- "We need min {cfg.numberOfOracles} Oracles. Waiting for mor Oracle. we have now {l} online Oracles",
- )
- time.sleep(0.5)
- self.broadcast.send(
- self.parser.requestOracleBroadcast(self.id), self.broadcast.addr
- )
- gBackPrint(
- "now we have min {cfg.numberOfOracles} Oracles. List of All Online Oracles",
- self.onlineOracles,
- )
- worker = []
- # Socket creation
- for i in range(cfg.numberOfOracles):
- worker.append(
- SocketClient(
- "127.0.0.1", int(self.onlineOracles[i][1]), self.parser, None
- )
- )
- # send rule to each oracle
- for i in range(cfg.numberOfOracles):
- data = self.parser.socketConnecting(i)
- worker[i].id = i
- worker[i].send(data)
- time.sleep(1)
- worker[0].send(
- self.parser.oracleInitialConnector(
- self.server,
- worker[1].Host,
- worker[2].Host,
- self.dataLen,
- self.keyConnector,
- )
- )
- worker[1].send(
- self.parser.oracleInitialCryptor(
- (worker[0].Host, worker[0].port + 1),
- self.server,
- self.dataLen,
- self.keyCryptor,
- )
- )
- worker[2].send(
- self.parser.oracleInitialBearer(
- (worker[0].Host, worker[0].port + 1), self.data
- )
- )
- # TODO response from Oracle in decrypt with
- """ if __name__ == '__main__':
- master_key = 0xb9b8887ee 6e1e8b78e2aaa2a0c522c13
- iv = 0xacf448fa5d3c87b08f549c5e
- data = b"\x00"
- my_gcm = AES_GCM(master_key, iv)
- my_gcm.decrypt(data)
- """
|