oracleParser.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from connection.parser import Parser
  2. from .worker.cryptor import Cryptor
  3. from .worker.connector import Connector
  4. from .worker.bearer import Bearer
  5. from Utils import *
  6. class OracleParser(Parser):
  7. def __init__(self, oracle):
  8. self.socket = oracle.socketPort
  9. self.oracle = oracle
  10. self.type = None
  11. self.id = None
  12. def parser(self, data, addr, Connection):
  13. try:
  14. if data["type"] == "requestOracleBroadcast":
  15. self.requestOracleBroadcast(data, addr)
  16. elif data["type"] == "socketConnecting":
  17. self.socketConnecting(data)
  18. elif data["type"] == "oracleInitial":
  19. self.type.oracleInitial(data)
  20. elif data["type"] == "keyExchange":
  21. self.type.keyExchange(data)
  22. elif data["type"] == "fromContoCry":
  23. self.type.fromContoCry(data)
  24. elif data["type"] == "fromConMPC":
  25. self.type.MPC(data)
  26. elif data["type"] == "fromCrytoCon":
  27. self.type.fromCrytoCon(data)
  28. elif data["type"] == "fromContoCryHelloCLient":
  29. self.type.fromContoCryHelloCLient(data)
  30. elif data["type"] == "fromCrytoConDone":
  31. self.type.fromCrytoConDone(data)
  32. elif data["type"] == "MPC":
  33. self.type.MPC(data)
  34. except Exception as e:
  35. rBackPrint("An exception occurred parser", e)
  36. def requestOracleBroadcast(self, data, addr):
  37. try:
  38. d = {}
  39. self.add(d, "type", "responseUserBroadcast")
  40. self.id = data["id"]
  41. self.add(d, "message", "Hello " + data["id"])
  42. self.add(d, "socket", self.socket)
  43. self.oracle.b.send(self.toSEND(d), addr)
  44. except Exception as e:
  45. rBackPrint("An exception occurred requestOracleBroadcast", e)
  46. def socketConnecting(self, data):
  47. try:
  48. if data["oracle"] == 0:
  49. self.type = Connector(self, self.socket + 1)
  50. elif data["oracle"] == 1:
  51. self.type = Cryptor(self)
  52. elif data["oracle"] == 2:
  53. self.type = Bearer(self)
  54. else:
  55. print("An exception occurred socketConnecting Oracle data ")
  56. except Exception as e:
  57. rBackPrint("An exception occurred socketConnecting", e)
  58. def parserSend(self, data, connection, typeO):
  59. try:
  60. d = {}
  61. self.add(d, "type", typeO)
  62. self.add(d, "data", data)
  63. connection.send(self.toSEND(d))
  64. except Exception as e:
  65. rBackPrint("An exception occurred parserSend", e)