user.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from connection.broadcast import BroadcastClient
  2. from connection.socket import SocketClient
  3. import time
  4. import config as cfg
  5. from .userParser import UserParser
  6. class User():
  7. def __init__(self,data, server, broadcast, broadcastPort):
  8. print("user")
  9. self.onlineOracles = []
  10. self.id = "PADRA"
  11. self.parser = UserParser(self)
  12. self.b = BroadcastClient(broadcast=broadcast,
  13. broadcastPort=broadcastPort,parser=self.parser,id=self.id)
  14. def run(self):
  15. self.b.send(self.parser.requestOracleBroadcast(self.id),self.b.addr)
  16. while(len(self.onlineOracles) < cfg.numberOfOracles):
  17. print("\tWe need min ",cfg.numberOfOracles," Oracles. Waiting for mor Oracle. we have now ",len(self.onlineOracles)," online Oracles")
  18. time.sleep(.5)
  19. print("\33[31m now we have min ",cfg.numberOfOracles,"Oracles. List of All Online Oracles ->\n",self.onlineOracles,"\n\033[0m")
  20. worker = []
  21. # Socket creation
  22. for i in range(cfg.numberOfOracles):
  23. worker.append(SocketClient("127.0.0.1",int(self.onlineOracles[i][1]),self.parser,None))
  24. # send rule to each oracle
  25. for i in range(cfg.numberOfOracles):
  26. data = self.parser.socketConnecting(i)
  27. worker[i].id = i
  28. worker[i].send(data)
  29. time.sleep(1)
  30. worker[0].send(self.parser.oracleInitialConnector("www.google.com",worker[1].Host,worker[2].Host))
  31. worker[1].send(self.parser.oracleInitialCryptor((worker[0].Host,worker[0].port+1),"www.google.com"))
  32. worker[2].send(self.parser.oracleInitialBearer((worker[0].Host,worker[0].port+1),"Masalan ina data hastand"))