oracleParser.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. class OracleParser(Parser):
  6. def __init__(self,oracle):
  7. self.socket = oracle.socketPort
  8. self.oracle = oracle
  9. self.type = None
  10. self.id = None
  11. print("createt oracle Parser")
  12. def parser(self,data,addr,Connection):
  13. try:
  14. # Broadcast Parser
  15. if data["type"] == "requestOracleBroadcast":
  16. self.requestOracleBroadcast(data,addr)
  17. # Socket Parser
  18. elif data["type"] == "socketConnecting":
  19. self.socketConnecting(data)
  20. elif data["type"] == "oracleInitial":
  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. except :
  33. print("\33[41m\33[41mAn exception occurred parser" ,data["type"],self.type,"\33[0m")
  34. def requestOracleBroadcast(self,data,addr):
  35. try:
  36. d = {}
  37. self.add(d,"type","responseUserBroadcast")
  38. self.id = data["id"]
  39. self.add(d,"message","Hello "+data["id"])
  40. self.add(d,"socket",self.socket)
  41. self.oracle.b.send(self.toSEND(d),addr)
  42. except:
  43. print("\33[41mAn exception occurred requestOracleBroadcast\33[0m")
  44. def socketConnecting(self,data):
  45. try:
  46. if data["oracle"] == 0:
  47. self.type = Connector(self,self.socket+1)
  48. elif data["oracle"] == 1:
  49. self.type = Cryptor(self)
  50. elif data["oracle"] == 2:
  51. self.type = Bearer(self)
  52. else:
  53. print("An exception occurred socketConnecting Oracle data ")
  54. except:
  55. print("\33[41mAn exception occurred socketConnecting\33[0m")
  56. # def fromConMPC(self,function,port,connection):
  57. # try:
  58. # d = {}
  59. # self.add(d,"type","fromConMPC")
  60. # self.add(d,"function",function)
  61. # self.add(d,"port",port)
  62. # connection.send(self.toSEND(d))
  63. # except Exception as exception:
  64. # print("\33[41mAn exception occurred Parse fromContoCryMPC ",exception,"\33[0m")
  65. # def fromCrytoCon(self,data,connection):
  66. # try:
  67. # d = {}
  68. # self.add(d,"type","fromCrytoCon")
  69. # self.add(d,"data",data)
  70. # connection.send(self.toSEND(d))
  71. # except Exception as exception:
  72. # print("\33[41mAn exception occurred Parse fromCrytoCon ",exception,"\33[0m")
  73. def parserSend(self,data,connection,typeO):
  74. try:
  75. d = {}
  76. self.add(d,"type",typeO)
  77. self.add(d,"data",data)
  78. connection.send(self.toSEND(d))
  79. except Exception as exception:
  80. print("\33[41mAn exception occurred Parse ",typeO ,exception,"\33[0m")