oracleParser.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. self.user = None
  13. def parser(self, data, addr, Connection):
  14. try:
  15. if data["type"] == "requestOracleBroadcast":
  16. self.requestOracleBroadcast(data, addr)
  17. elif data["type"] == "socketConnecting":
  18. self.socketConnecting(data)
  19. elif data["type"] == "oracleInitial":
  20. self.user = Connection
  21. self.type.oracleInitial(data)
  22. elif data["type"] == "keyExchange":
  23. self.type.keyExchange(data)
  24. elif data["type"] == "fromContoCry":
  25. self.type.fromContoCry(data)
  26. elif data["type"] == "fromConMPC":
  27. self.type.MPC(data)
  28. elif data["type"] == "fromCrytoCon":
  29. self.type.fromCrytoCon(data)
  30. elif data["type"] == "fromContoCryHelloCLient":
  31. self.type.fromContoCryHelloCLient(data)
  32. elif data["type"] == "fromCrytoConDone":
  33. self.type.fromCrytoConDone(data)
  34. elif data["type"] == "fromContoCryDone":
  35. self.type.fromContoCryDone(data)
  36. elif data["type"] == "MPC":
  37. self.type.MPC(data)
  38. except Exception as e:
  39. rBackPrint("An exception occurred parser", e)
  40. def requestOracleBroadcast(self, data, addr):
  41. try:
  42. d = {}
  43. self.add(d, "type", "responseUserBroadcast")
  44. self.id = data["id"]
  45. self.add(d, "message", "Hello " + data["id"])
  46. self.add(d, "socket", self.socket)
  47. self.oracle.b.send(self.toSEND(d), addr)
  48. except Exception as e:
  49. rBackPrint("An exception occurred requestOracleBroadcast", e)
  50. def socketConnecting(self, data):
  51. try:
  52. if data["oracle"] == 0:
  53. self.type = Connector(self, self.socket + 1)
  54. elif data["oracle"] == 1:
  55. self.type = Cryptor(self)
  56. elif data["oracle"] == 2:
  57. self.type = Bearer(self)
  58. else:
  59. print("An exception occurred socketConnecting Oracle data ")
  60. except Exception as e:
  61. rBackPrint("An exception occurred socketConnecting", e)
  62. def parserSend(self, data, connection, typeO):
  63. try:
  64. d = {}
  65. self.add(d, "type", typeO)
  66. self.add(d, "data", data)
  67. connection.send(self.toSEND(d))
  68. except Exception as e:
  69. rBackPrint("An exception occurred parserSend", e)