userParser.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from connection.parser import Parser
  2. from Utils import *
  3. class UserParser(Parser):
  4. def __init__(self, user):
  5. self.user = user
  6. print("createt User Parser")
  7. def parser(self, data, addr, Connection):
  8. try:
  9. if data["type"] == "responseUserBroadcast":
  10. self.responseUserBroadcast(data, addr)
  11. if data["type"] == "connectorDone":
  12. self.user.connectorDone(data)
  13. if data["type"] == "cryptorDone":
  14. self.user.cryptorDone(data)
  15. except Exception as e:
  16. rBackPrint("An exception occurred parser", e)
  17. def requestOracleBroadcast(self, id):
  18. try:
  19. data = {}
  20. self.add(data, "type", "requestOracleBroadcast")
  21. self.add(data, "id", id)
  22. return self.toSEND(data)
  23. except Exception as e:
  24. rBackPrint("An exception occurred requestOracleBroadcast", e)
  25. def responseUserBroadcast(self, data, addr):
  26. try:
  27. self.user.onlineOracles.append((addr[0], data["socket"]))
  28. except Exception as e:
  29. rBackPrint("An exception occurred responseUserBroadcast", e)
  30. def socketConnecting(self, oracleNumber):
  31. try:
  32. data = {}
  33. self.add(data, "type", "socketConnecting")
  34. self.add(data, "oracle", oracleNumber)
  35. return self.toSEND(data)
  36. except Exception as e:
  37. rBackPrint("An exception occurred socketConnecting", e)
  38. def oracleInitialConnector(self, server, cryptor, bearer, dataLen, key):
  39. try:
  40. data = {}
  41. self.add(data, "type", "oracleInitial")
  42. self.add(data, "server", server)
  43. self.add(data, "bearer", bearer)
  44. self.add(data, "cryptor", cryptor)
  45. self.add(data, "dataLen", dataLen)
  46. self.add(data, "key", key)
  47. return self.toSEND(data)
  48. except Exception as e:
  49. rBackPrint("An exception occurred oracleInitialConnector", e)
  50. def oracleInitialCryptor(self, connector, server, dataLen, key):
  51. try:
  52. data = {}
  53. self.add(data, "type", "oracleInitial")
  54. self.add(data, "connector", connector)
  55. self.add(data, "server", server)
  56. self.add(data, "dataLen", dataLen)
  57. self.add(data, "key", key)
  58. return self.toSEND(data)
  59. except Exception as e:
  60. rBackPrint("An exception occurred oracleInitialCryptor", e)
  61. def oracleInitialBearer(self, connector, d):
  62. try:
  63. data = {}
  64. self.add(data, "type", "oracleInitial")
  65. self.add(data, "connector", connector)
  66. self.add(data, "data", d)
  67. return self.toSEND(data)
  68. except Exception as e:
  69. rBackPrint("An exception occurred oracleInitialBearer", e)