naeural-client 2.5.24__tar.gz → 2.5.26__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. {naeural_client-2.5.24 → naeural_client-2.5.26}/PKG-INFO +1 -1
  2. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/__init__.py +1 -0
  3. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/_ver.py +1 -1
  4. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/generic_session.py +71 -15
  5. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/bc/base.py +4 -39
  6. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/cli/nodes.py +45 -3
  7. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/base.py +45 -2
  8. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/utils/config.py +18 -2
  9. {naeural_client-2.5.24 → naeural_client-2.5.26}/pyproject.toml +1 -1
  10. naeural_client-2.5.26/xperimental/check_local_keys/check1.py +33 -0
  11. {naeural_client-2.5.24 → naeural_client-2.5.26}/.devcontainer/Dockerfile +0 -0
  12. {naeural_client-2.5.24 → naeural_client-2.5.26}/.devcontainer/devcontainer.json +0 -0
  13. {naeural_client-2.5.24 → naeural_client-2.5.26}/.gitattributes +0 -0
  14. {naeural_client-2.5.24 → naeural_client-2.5.26}/.github/workflows/python-publish.yml +0 -0
  15. {naeural_client-2.5.24 → naeural_client-2.5.26}/.gitignore +0 -0
  16. {naeural_client-2.5.24 → naeural_client-2.5.26}/.vscode/launch.json +0 -0
  17. {naeural_client-2.5.24 → naeural_client-2.5.26}/LICENSE +0 -0
  18. {naeural_client-2.5.24 → naeural_client-2.5.26}/README.md +0 -0
  19. {naeural_client-2.5.24 → naeural_client-2.5.26}/TODOs.md +0 -0
  20. {naeural_client-2.5.24 → naeural_client-2.5.26}/__init__.py +0 -0
  21. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/__init__.py +0 -0
  22. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/distributed_custom_code_presets.py +0 -0
  23. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/instance.py +0 -0
  24. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/payload/__init__.py +0 -0
  25. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/payload/payload.py +0 -0
  26. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/pipeline.py +0 -0
  27. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/plugin_template.py +0 -0
  28. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/responses.py +0 -0
  29. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/transaction.py +0 -0
  30. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base/webapp_pipeline.py +0 -0
  31. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/base_decentra_object.py +0 -0
  32. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/bc/__init__.py +0 -0
  33. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/bc/chain.py +0 -0
  34. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/bc/ec.py +0 -0
  35. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/certs/__init__.py +0 -0
  36. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt +0 -0
  37. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/cli/README.md +0 -0
  38. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/cli/cli.py +0 -0
  39. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/cli/cli_commands.py +0 -0
  40. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/code_cheker/__init__.py +0 -0
  41. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/code_cheker/base.py +0 -0
  42. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/code_cheker/checker.py +0 -0
  43. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/comm/__init__.py +0 -0
  44. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/comm/amqp_wrapper.py +0 -0
  45. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/comm/mqtt_wrapper.py +0 -0
  46. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/README.md +0 -0
  47. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/__init__.py +0 -0
  48. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/apps.py +0 -0
  49. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/comms.py +0 -0
  50. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/environment.py +0 -0
  51. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/formatter.py +0 -0
  52. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/heartbeat.py +0 -0
  53. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/misc.py +0 -0
  54. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/const/payload.py +0 -0
  55. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/__init__.py +0 -0
  56. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/instance/__init__.py +0 -0
  57. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/instance/chain_dist_custom_job_01_plugin.py +0 -0
  58. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/instance/custom_webapi_01_plugin.py +0 -0
  59. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/instance/net_mon_01_plugin.py +0 -0
  60. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/instance/telegram_basic_bot_01_plugin.py +0 -0
  61. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/instance/telegram_conversational_bot_01_plugin.py +0 -0
  62. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/instance/view_scene_01_plugin.py +0 -0
  63. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/default/session/mqtt_session.py +0 -0
  64. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/__init__.py +0 -0
  65. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/base/__init__.py +0 -0
  66. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/base/base_formatter.py +0 -0
  67. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/default/__init__.py +0 -0
  68. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/default/a_dummy.py +0 -0
  69. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/default/aixp1.py +0 -0
  70. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/default/default.py +0 -0
  71. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/io_formatter/io_formatter_manager.py +0 -0
  72. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/__init__.py +0 -0
  73. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/base_logger.py +0 -0
  74. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/__init__.py +0 -0
  75. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/class_instance_mixin.py +0 -0
  76. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/computer_vision_mixin.py +0 -0
  77. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/datetime_mixin.py +0 -0
  78. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/download_mixin.py +0 -0
  79. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/general_serialization_mixin.py +0 -0
  80. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/json_serialization_mixin.py +0 -0
  81. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/pickle_serialization_mixin.py +0 -0
  82. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/process_mixin.py +0 -0
  83. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/resource_size_mixin.py +0 -0
  84. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/timers_mixin.py +0 -0
  85. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/upload_mixin.py +0 -0
  86. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/logger_mixins/utils_mixin.py +0 -0
  87. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/small_logger.py +0 -0
  88. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/tzlocal/__init__.py +0 -0
  89. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/tzlocal/unix.py +0 -0
  90. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/tzlocal/utils.py +0 -0
  91. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/tzlocal/win32.py +0 -0
  92. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/logging/tzlocal/windows_tz.py +0 -0
  93. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/plugins_manager_mixin.py +0 -0
  94. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/utils/__init__.py +0 -0
  95. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/utils/comm_utils.py +0 -0
  96. {naeural_client-2.5.24 → naeural_client-2.5.26}/naeural_client/utils/dotenv.py +0 -0
  97. {naeural_client-2.5.24 → naeural_client-2.5.26}/nepctl.MD +0 -0
  98. {naeural_client-2.5.24 → naeural_client-2.5.26}/requirements.txt +0 -0
  99. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/.example_env +0 -0
  100. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/8. custom_code_fastapi_assets/index.html +0 -0
  101. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/9. code_sandbox_from_scratch_assets/index.html +0 -0
  102. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/_example_pk_sdk.pem +0 -0
  103. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex01_part1_connect.py +0 -0
  104. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex01_part2_filter.py +0 -0
  105. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex01_part3_adv_filter.py +0 -0
  106. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex02_first_deploy.py +0 -0
  107. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex03_custom_code_on_one_remote__example_1.py +0 -0
  108. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex04_custom_code_on_one_remote__example_2.py +0 -0
  109. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex05_custom_code_on_one_remote__example_3.py +0 -0
  110. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex06_custom_code_on_multiple_remotes__example_1.py +0 -0
  111. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex07_custom_code_on_multiple_remotes__example_2.py +0 -0
  112. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex08_custom_webapi.py +0 -0
  113. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex09_code_sandbox_from_scratch.py +0 -0
  114. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex10_telegram_echo_bot.py +0 -0
  115. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex11_telegram_blackjack_bot.py +0 -0
  116. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex12_telegram_smart_bot.py +0 -0
  117. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/ex13_launch_repo_based_webapp.py +0 -0
  118. {naeural_client-2.5.24 → naeural_client-2.5.26}/tutorials/video_presentation/1. hello_world.ipynb +0 -0
  119. {naeural_client-2.5.24 → naeural_client-2.5.26}/winrun.bat +0 -0
  120. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/.example_env +0 -0
  121. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/_archive/test.py +0 -0
  122. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/_tutorials/3. simple_real_time_custom_code.py +0 -0
  123. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/_tutorials/4. real_time_custom_code_2.py +0 -0
  124. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/_tutorials/8. chatbot.py +0 -0
  125. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/decentralized/chain_dist_example.py +0 -0
  126. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/decentralized/chain_dist_example_initiator.py +0 -0
  127. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/decentralized/chain_dist_example_worker.py +0 -0
  128. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/enc_dec/enc_dec_test.py +0 -0
  129. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/eth/eth_sign.py +0 -0
  130. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/eth/info.md +0 -0
  131. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/eth/sign.py +0 -0
  132. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/multi-enc-dec/multi_test1.py +0 -0
  133. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/multi-enc-dec/multi_test2.py +0 -0
  134. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/sign/test_sign1.py +0 -0
  135. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/utils/get_documentation.py +0 -0
  136. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/various/README.md +0 -0
  137. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/various/attach_example.py +0 -0
  138. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/various/ex1.py +0 -0
  139. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/various/hello.py +0 -0
  140. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/various/remote_exec.py +0 -0
  141. {naeural_client-2.5.24 → naeural_client-2.5.26}/xperimental/various/save_images.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.5.24
3
+ Version: 2.5.26
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -12,4 +12,5 @@ from .plugins_manager_mixin import _PluginsManagerMixin
12
12
  from .logging import Logger
13
13
  from .code_cheker import BaseCodeChecker
14
14
  from .const import PLUGIN_SIGNATURES, PAYLOAD_DATA
15
+ from .const import HB as HEARTBEAT_DATA
15
16
  from .default.instance import PLUGIN_TYPES
@@ -1,4 +1,4 @@
1
- __VER__ = "2.5.24"
1
+ __VER__ = "2.5.26"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -179,7 +179,7 @@ class GenericSession(BaseDecentrAIObject):
179
179
  self._dct_online_nodes_pipelines: dict[str, Pipeline] = {}
180
180
  self._dct_online_nodes_last_heartbeat: dict[str, dict] = {}
181
181
  self._dct_can_send_to_node: dict[str, bool] = {}
182
- self._dct_node_last_seen_time = {}
182
+ self._dct_node_last_seen_time = {} # key is node address
183
183
  self._dct_node_addr_name = {}
184
184
  self.online_timeout = 60
185
185
  self.filter_workers = filter_workers
@@ -209,9 +209,14 @@ class GenericSession(BaseDecentrAIObject):
209
209
  self.sdk_main_loop_thread = Thread(target=self.__main_loop, daemon=True)
210
210
  self.__formatter_plugins_locations = formatter_plugins_locations
211
211
 
212
- self.__bc_engine = bc_engine
213
212
  self.__blockchain_config = blockchain_config
214
213
 
214
+ # TODO: needs refactoring - suboptimal design
215
+ self.__bc_engine : DefaultBlockEngine = bc_engine
216
+ self.bc_engine : DefaultBlockEngine = None
217
+ # END TODO
218
+
219
+
215
220
  self.__open_transactions: list[Transaction] = []
216
221
  self.__open_transactions_lock = Lock()
217
222
 
@@ -1033,10 +1038,19 @@ class GenericSession(BaseDecentrAIObject):
1033
1038
  self._config[comm_ct.SECURED] = secured
1034
1039
 
1035
1040
  return
1041
+
1042
+ def __aliases_to_addresses(self):
1043
+ """
1044
+ Convert the aliases to addresses.
1045
+ """
1046
+ dct_aliases = {v: k for k, v in self._dct_node_addr_name.items()}
1047
+ return dct_aliases
1036
1048
 
1037
1049
  def __get_node_address(self, node):
1038
1050
  """
1039
1051
  Get the address of a node. If node is an address, return it. Else, return the address of the node.
1052
+ This method is used to convert the alias of a node to its address if needed however it is
1053
+ not recommended to use it as it was created for backward compatibility reasons.
1040
1054
 
1041
1055
  Parameters
1042
1056
  ----------
@@ -1048,11 +1062,19 @@ class GenericSession(BaseDecentrAIObject):
1048
1062
  str
1049
1063
  The address of the node.
1050
1064
  """
1051
- if node not in self.get_active_nodes():
1052
- node = next((key for key, value in self._dct_node_addr_name.items() if value == node), node)
1053
- return node
1065
+ # if node not in self.get_active_nodes():
1066
+ # node = next((key for key, value in self._dct_node_addr_name.items() if value == node), node)
1067
+ result = None
1068
+ if node in self.get_active_nodes():
1069
+ # node seems to be already an address
1070
+ result = node
1071
+ else:
1072
+ # maybe node is a name
1073
+ aliases = self.__aliases_to_addresses()
1074
+ result = aliases.get(node, None)
1075
+ return result
1054
1076
 
1055
- def _send_command_to_box(self, command, worker, payload, show_command=False, session_id=None, **kwargs):
1077
+ def _send_command_to_box(self, command, worker, payload, show_command=True, session_id=None, **kwargs):
1056
1078
  """
1057
1079
  Send a command to a node.
1058
1080
 
@@ -1062,10 +1084,16 @@ class GenericSession(BaseDecentrAIObject):
1062
1084
  The command to send.
1063
1085
  worker : str
1064
1086
  The name of the Naeural Edge Protocol edge node that will receive the command.
1087
+
1088
+ Observation: this approach will be deprecated soon in favor of the direct use of the address that
1089
+ will not require the node to be already "seend" by the session.
1090
+
1065
1091
  payload : dict
1066
1092
  The payload to send.
1067
1093
  show_command : bool, optional
1068
1094
  If True, will print the complete command that is being sent, by default False
1095
+
1096
+
1069
1097
  """
1070
1098
 
1071
1099
  show_command = show_command or self.__show_commands
@@ -1080,10 +1108,17 @@ class GenericSession(BaseDecentrAIObject):
1080
1108
 
1081
1109
  # This part is duplicated with the creation of payloads
1082
1110
  encrypt_payload = self.encrypt_comms
1083
- if encrypt_payload and worker is not None:
1084
- # TODO: use safe_json_dumps
1111
+ if encrypt_payload and worker is not None:
1085
1112
  str_data = json.dumps(critical_data)
1086
- str_enc_data = self.bc_engine.encrypt(str_data, worker)
1113
+
1114
+ # Initial code `str_enc_data = self.bc_engine.encrypt(str_data, worker)` could not work under any
1115
+ # circumstances due to the fact that encrypt requires the public key of the receiver not the alias
1116
+ # of the receiver. The code below is a workaround to encrypt the message
1117
+ # TODO: furthermore the code will be migrated to the use of the address of the worker
1118
+ worker_addr = self.get_addr_by_name(worker)
1119
+ assert worker_addr is not None, f"Unknown worker address: {worker} - {worker_addr}"
1120
+
1121
+ str_enc_data = self.bc_engine.encrypt(str_data, worker_addr)
1087
1122
  critical_data = {
1088
1123
  comm_ct.COMM_SEND_MESSAGE.K_EE_IS_ENCRYPTED: True,
1089
1124
  comm_ct.COMM_SEND_MESSAGE.K_EE_ENCRYPTED_DATA: str_enc_data,
@@ -1104,10 +1139,11 @@ class GenericSession(BaseDecentrAIObject):
1104
1139
  }
1105
1140
  self.bc_engine.sign(msg_to_send, use_digest=True)
1106
1141
  if show_command:
1107
- self.P("Sending command '{}' to '{}':\n{}".format(command, worker, json.dumps(msg_to_send, indent=2)),
1108
- color='y',
1109
- verbosity=1
1110
- )
1142
+ self.P(
1143
+ "Sending command '{}' to '{}':\n{}".format(command, worker, json.dumps(msg_to_send, indent=2)),
1144
+ color='y',
1145
+ verbosity=1
1146
+ )
1111
1147
  self._send_payload(worker, msg_to_send)
1112
1148
  return
1113
1149
 
@@ -1357,6 +1393,25 @@ class GenericSession(BaseDecentrAIObject):
1357
1393
  )
1358
1394
  self.own_pipelines.append(pipeline)
1359
1395
  return pipeline
1396
+
1397
+ def get_addr_by_name(self, name):
1398
+ """
1399
+ Get the address of a node by its name.
1400
+ This function should be used with caution and it was created for backward compatibility reasons.
1401
+
1402
+ Parameters
1403
+ ----------
1404
+
1405
+ name : str
1406
+ The name of the node.
1407
+
1408
+ Returns
1409
+ -------
1410
+ str
1411
+ The address of the node.
1412
+ """
1413
+ return self.__get_node_address(name)
1414
+
1360
1415
 
1361
1416
  def get_node_name(self, node_addr):
1362
1417
  """
@@ -1376,12 +1431,13 @@ class GenericSession(BaseDecentrAIObject):
1376
1431
 
1377
1432
  def get_active_nodes(self):
1378
1433
  """
1379
- Get the list of all Naeural Edge Protocol edge nodes that sent a message since this session was created, and that are considered online
1434
+ Get the list of all Naeural Edge Protocol edge nodes addresses that sent a message since this
1435
+ session was created, and that are considered online.
1380
1436
 
1381
1437
  Returns
1382
1438
  -------
1383
1439
  list
1384
- List of names of all the Naeural Edge Protocol edge nodes that are considered online
1440
+ List of addresses of all the Naeural Edge Protocol edge nodes that are considered online
1385
1441
 
1386
1442
  """
1387
1443
  return [k for k, v in self._dct_node_last_seen_time.items() if tm() - v < self.online_timeout]
@@ -14,42 +14,7 @@ from cryptography.hazmat.primitives import serialization
14
14
 
15
15
  from ..utils.config import get_user_folder
16
16
 
17
- class BCctbase:
18
- SIGN = 'EE_SIGN'
19
- SENDER = 'EE_SENDER'
20
- HASH = 'EE_HASH'
21
-
22
- ETH_SIGN = 'EE_ETH_SIGN'
23
- ETH_SENDER= 'EE_ETH_SENDER'
24
-
25
-
26
- class BCct:
27
- SIGN = BCctbase.SIGN
28
- SENDER = BCctbase.SENDER
29
- HASH = BCctbase.HASH
30
- ETH_SIGN = BCctbase.ETH_SIGN
31
- ETH_SENDER = BCctbase.ETH_SENDER
32
-
33
- ADDR_PREFIX_OLD = "aixp_"
34
- ADDR_PREFIX = "0xai_"
35
-
36
- K_USER_CONFIG_PEM_FILE = 'NAEURAL_PEM_FILE'
37
- K_PEM_FILE = 'PEM_FILE'
38
- K_PASSWORD = 'PASSWORD'
39
- K_PEM_LOCATION = 'PEM_LOCATION'
40
-
41
- ERR_UNAVL_MSG = "Missing signature/sender data"
42
- ERR_UNAVL = 1
43
-
44
- ERR_SIGN_MSG = "Bad hash"
45
- ERR_UNAVL = 1000
46
-
47
- ERR_SIGN_MSG = "Bad signature"
48
- ERR_UNAVL = 1001
49
-
50
- AUTHORISED_ADDRS = 'authorized_addrs'
51
-
52
- DEFAULT_INFO = '0xai handshake data'
17
+ from ..const.base import BCctbase, BCct
53
18
 
54
19
 
55
20
 
@@ -342,10 +307,10 @@ class BaseBlockEngine:
342
307
 
343
308
  if user_config:
344
309
  user_folder = get_user_folder()
345
- pem_fn = str(user_folder / '_naeural.pem')
310
+ pem_fn = str(user_folder / BCct.USER_PEM_FILE)
346
311
  else:
347
- pem_name = config.get(BCct.K_PEM_FILE, '_pk.pem')
348
- pem_folder = config.get(BCct.K_PEM_LOCATION, 'data')
312
+ pem_name = config.get(BCct.K_PEM_FILE, BCct.DEFAULT_PEM_FILE)
313
+ pem_folder = config.get(BCct.K_PEM_LOCATION, BCct.DEFAULT_PEM_LOCATION)
349
314
  pem_fn = os.path.join(log.get_target_folder(pem_folder), pem_name)
350
315
  #endif pem is defined in ~/.naeural/ or in the data folder of the _local_cache
351
316
  self.__pem_file = pem_fn
@@ -1,6 +1,6 @@
1
1
  from time import time
2
2
  from naeural_client.utils.config import log_with_color
3
- from naeural_client.const import SESSION_CT
3
+ from naeural_client.const import SESSION_CT, COMMANDS
4
4
 
5
5
 
6
6
  def _get_netstats(
@@ -9,6 +9,7 @@ def _get_netstats(
9
9
  allowed_only=False,
10
10
  supervisor=None,
11
11
  supervisors_only=False,
12
+ return_session=False,
12
13
  ):
13
14
  t1 = time()
14
15
  from naeural_client import Session
@@ -23,8 +24,11 @@ def _get_netstats(
23
24
  nr_supers = dct_info[SESSION_CT.NETSTATS_NR_SUPERVISORS]
24
25
  _elapsed = dct_info[SESSION_CT.NETSTATS_ELAPSED] # computed on call
25
26
  elapsed = time() - t1 # elapsed=_elapsed
27
+ if return_session:
28
+ return df, supervisor, super_alias, nr_supers, elapsed, sess
26
29
  return df, supervisor, super_alias, nr_supers, elapsed
27
30
 
31
+
28
32
  def get_nodes(args):
29
33
  """
30
34
  This function is used to get the information about the nodes and it will perform the following:
@@ -76,6 +80,40 @@ def get_supervisors(args):
76
80
  log_with_color(f"{df}")
77
81
  return
78
82
 
83
+ def _send_command_to_node(args, command):
84
+ node = args.node
85
+ silent = not args.verbose
86
+
87
+ t1 = time()
88
+ df, _, _, _, _, sess = _get_netstats(
89
+ silent=silent, online_only=True, return_session=True
90
+ )
91
+ peered = None
92
+ selection = df.Alias == node
93
+ found = selection.any()
94
+ node_addr = None
95
+ df_found = df[selection]
96
+ if found:
97
+ peered = df_found.Peered.values[0]
98
+ node_addr = df_found.Address.values[0]
99
+ log_with_color(f"{df_found}")
100
+ if not found:
101
+ log_with_color(f"Node '{node}' <{node_addr}> not found in network.", color='r')
102
+ return
103
+ if not peered:
104
+ log_with_color(f"Node '{node}' <{node_addr}> does not accept commands from this SDK.", color='r')
105
+ return
106
+ # TODO: currently this is based on node alias, but we should be based on node address
107
+ # and maybe even node alias
108
+ if command == COMMANDS.RESTART:
109
+ sess._send_command_restart_node(node)
110
+ elif command == COMMANDS.SHUTDOWN:
111
+ sess._send_command_stop_node(node)
112
+ else:
113
+ log_with_color(f"Command '{command}' not supported.", color='r')
114
+ return
115
+ elapsed = time() - t1
116
+ return
79
117
 
80
118
  def restart_node(args):
81
119
  """
@@ -86,7 +124,9 @@ def restart_node(args):
86
124
  args : argparse.Namespace
87
125
  Arguments passed to the function.
88
126
  """
89
- log_with_color(f"Restarting node {args.node} NOT IMPLEMENTED", color='r')
127
+ node = args.node
128
+ log_with_color(f"Attempting to restart node <{node}>", color='b')
129
+ _send_command_to_node(args, COMMANDS.RESTART)
90
130
  return
91
131
 
92
132
 
@@ -99,5 +139,7 @@ def shutdown_node(args):
99
139
  args : argparse.Namespace
100
140
  Arguments passed to the function.
101
141
  """
102
- log_with_color(f"Shutting down node {args.node} NOT IMPLEMENTED", color='r')
142
+ node = args.node
143
+ log_with_color(f"Attempting to shutdown node <{node}>", color='b')
144
+ _send_command_to_node(args, COMMANDS.SHUTDOWN)
103
145
  return
@@ -1,11 +1,54 @@
1
1
  EE_ID = 'EE_ID'
2
2
  SB_ID = 'SB_ID' # change to SB_ID = EE_ID post mod from sb to ee
3
3
 
4
+
5
+ class BCctbase:
6
+ SIGN = 'EE_SIGN'
7
+ SENDER = 'EE_SENDER'
8
+ HASH = 'EE_HASH'
9
+
10
+ ETH_SIGN = 'EE_ETH_SIGN'
11
+ ETH_SENDER= 'EE_ETH_SENDER'
12
+
13
+
14
+ class BCct:
15
+ SIGN = BCctbase.SIGN
16
+ SENDER = BCctbase.SENDER
17
+ HASH = BCctbase.HASH
18
+ ETH_SIGN = BCctbase.ETH_SIGN
19
+ ETH_SENDER = BCctbase.ETH_SENDER
20
+
21
+ ADDR_PREFIX_OLD = "aixp_"
22
+ ADDR_PREFIX = "0xai_"
23
+
24
+ K_USER_CONFIG_PEM_FILE = 'NAEURAL_PEM_FILE'
25
+ K_PEM_FILE = 'PEM_FILE'
26
+ K_PASSWORD = 'PASSWORD'
27
+ K_PEM_LOCATION = 'PEM_LOCATION'
28
+
29
+ ERR_UNAVL_MSG = "Missing signature/sender data"
30
+ ERR_UNAVL = 1
31
+
32
+ ERR_SIGN_MSG = "Bad hash"
33
+ ERR_UNAVL = 1000
34
+
35
+ ERR_SIGN_MSG = "Bad signature"
36
+ ERR_UNAVL = 1001
37
+
38
+ AUTHORISED_ADDRS = 'authorized_addrs'
39
+
40
+ DEFAULT_INFO = '0xai handshake data'
41
+
42
+ USER_PEM_FILE = '_naeural.pem'
43
+ DEFAULT_PEM_FILE = '_pk.pem'
44
+ DEFAULT_PEM_LOCATION = 'data'
45
+
4
46
  BLOCKCHAIN_CONFIG = {
5
- "PEM_FILE": "_pk_sdk.pem",
47
+ "PEM_FILE": BCct.DEFAULT_PEM_FILE,
6
48
  "PASSWORD": None,
7
- "PEM_LOCATION": "data"
49
+ "PEM_LOCATION": BCct.DEFAULT_PEM_LOCATION
8
50
  }
51
+
9
52
 
10
53
  class DCT_TYPES:
11
54
  VOID_PIPELINE = 'Void'
@@ -2,6 +2,13 @@ import os
2
2
  from pathlib import Path
3
3
  import shutil
4
4
 
5
+ from naeural_client.const.base import BCct
6
+
7
+
8
+ CONFIG_FILE = "config"
9
+ SDK_HOME = ".naeural"
10
+ LOCAL_PEM_PATH = "./_local_cache/_data/" + BCct.DEFAULT_PEM_FILE
11
+
5
12
  ENV_TEMPLATE = """
6
13
 
7
14
  EE_MQTT_HOST=r9092118.ala.eu-central-1.emqxsl.com
@@ -75,13 +82,13 @@ def get_user_folder():
75
82
  """
76
83
  Returns the user folder.
77
84
  """
78
- return Path.home() / ".naeural"
85
+ return Path.home() / SDK_HOME
79
86
 
80
87
  def get_user_config_file():
81
88
  """
82
89
  Returns the user configuration file.
83
90
  """
84
- return get_user_folder() / "config"
91
+ return get_user_folder() / CONFIG_FILE
85
92
 
86
93
  def reset_config(*larg, **kwargs):
87
94
  """
@@ -93,6 +100,9 @@ def reset_config(*larg, **kwargs):
93
100
  config_dir = get_user_folder()
94
101
  config_file = get_user_config_file()
95
102
 
103
+ local_pem = Path(LOCAL_PEM_PATH)
104
+ target_pem = config_dir / BCct.USER_PEM_FILE
105
+
96
106
  # Create the ~/.naeural folder if it doesn't exist
97
107
  config_dir.mkdir(parents=True, exist_ok=True)
98
108
 
@@ -115,6 +125,12 @@ def reset_config(*larg, **kwargs):
115
125
  color='y'
116
126
  )
117
127
  log_with_color(f"Please UPDATE the configuration in the file {config_file}", color='b')
128
+
129
+ if local_pem.exists():
130
+ log_with_color(f"Copying local PEM file {local_pem} to {target_pem}", color='y')
131
+ shutil.copy(local_pem, target_pem)
132
+ else:
133
+ log_with_color(f"No local PEM file found at {local_pem}. A default private key will be generated.", color='r')
118
134
  return
119
135
 
120
136
  def show_address(args):
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "naeural_client"
7
- version = "2.5.24"
7
+ version = "2.5.26"
8
8
  authors = [
9
9
  { name="Andrei Ionut Damian", email="andrei.damian@me.com" },
10
10
  { name="Cristan Bleotiu", email="cristibleotiu@gmail.com" },
@@ -0,0 +1,33 @@
1
+ import os
2
+
3
+ from naeural_client import Logger, const
4
+ from naeural_client.bc import DefaultBlockEngine
5
+
6
+
7
+ if __name__ == '__main__':
8
+ l = Logger("ENC", base_folder=".", app_folder="_local_cache")
9
+
10
+
11
+ files = [x for x in os.listdir(l.get_data_folder()) if x.endswith(".pem")]
12
+
13
+ local_addresses = []
14
+ results = []
15
+
16
+ if len(files) > 0:
17
+ l.P("PEM files found: {}".format(files), color='g')
18
+ for pem in files:
19
+ eng = DefaultBlockEngine(
20
+ log=l, name=pem,
21
+ config={
22
+ "PEM_FILE" : pem,
23
+ "PASSWORD" : None,
24
+ "PEM_LOCATION" : "data"
25
+ }
26
+ )
27
+ local_addresses.append(eng.address)
28
+ results.append("{} - {}".format(eng.address, pem))
29
+ l.P("Local addresses:\n{}".format("\n".join(results)), color='g')
30
+ else:
31
+ l.P("No PEM files found.", color='r')
32
+
33
+
File without changes