naeural-client 2.5.11__py3-none-any.whl → 2.5.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
naeural_client/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "2.5.11"
1
+ __VER__ = "2.5.13"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -1374,7 +1374,8 @@ class GenericSession(BaseDecentrAIObject):
1374
1374
 
1375
1375
  def get_allowed_nodes(self):
1376
1376
  """
1377
- Get the list of all active Naeural Edge Protocol edge nodes to whom this session can send messages
1377
+ Get the list of all active Naeural Edge Protocol edge nodes to whom this
1378
+ ssion can send messages. This is based on the last heartbeat received from each individual node.
1378
1379
 
1379
1380
  Returns
1380
1381
  -------
@@ -2238,11 +2239,43 @@ class GenericSession(BaseDecentrAIObject):
2238
2239
  online_only=False,
2239
2240
  supervisors_only=False,
2240
2241
  min_supervisors=2,
2242
+ allowed_only=False,
2241
2243
  supervisor=None,
2242
2244
  ):
2243
2245
  """
2244
2246
  This function will return a Pandas dataframe known nodes in the network based on
2245
2247
  all the net-mon messages received so far.
2248
+
2249
+ Parameters
2250
+ ----------
2251
+
2252
+ timeout : int, optional
2253
+ The maximum time to wait for the desired number of supervisors to appear online.
2254
+ Defaults to 10.
2255
+
2256
+ online_only : bool, optional
2257
+ If True, will return only the online nodes. Defaults to False.
2258
+
2259
+ supervisors_only : bool, optional
2260
+ If True, will return only the supervisors. Defaults to False.
2261
+
2262
+ min_supervisors : int, optional
2263
+ The minimum number of supervisors to wait for. Defaults to 2.
2264
+
2265
+ allowed_only : bool, optional
2266
+ If True, will return only the allowed nodes. Defaults to False.
2267
+
2268
+ supervisor : str, optional
2269
+ The supervisor to wait for. Defaults to None.
2270
+
2271
+ Returns
2272
+ -------
2273
+
2274
+ dict
2275
+ A dictionary containing the report, the reporter and the number of supervisors.
2276
+
2277
+
2278
+
2246
2279
  """
2247
2280
  mapping = OrderedDict({
2248
2281
  'Address': PAYLOAD_DATA.NETMON_ADDRESS,
@@ -2252,13 +2285,16 @@ class GenericSession(BaseDecentrAIObject):
2252
2285
  'Last probe' : PAYLOAD_DATA.NETMON_LAST_REMOTE_TIME,
2253
2286
  'Zone' : PAYLOAD_DATA.NETMON_NODE_UTC,
2254
2287
  'Supervisor' : PAYLOAD_DATA.NETMON_IS_SUPERVISOR,
2288
+ 'Peered' : PAYLOAD_DATA.NETMON_WHITELIST,
2255
2289
  })
2256
2290
  reverse_mapping = {v: k for k, v in mapping.items()}
2257
2291
  res = OrderedDict()
2258
2292
  for k in mapping:
2259
2293
  res[k] = []
2294
+
2295
+ # the following loop will wait for the desired number of supervisors to appear online
2296
+ # for the current session
2260
2297
  start = tm()
2261
-
2262
2298
  while (tm() - start) < timeout:
2263
2299
  if supervisor is not None:
2264
2300
  if supervisor in self.__current_network_statuses:
@@ -2266,7 +2302,10 @@ class GenericSession(BaseDecentrAIObject):
2266
2302
  elif len(self.__current_network_statuses) >= min_supervisors:
2267
2303
  break
2268
2304
  sleep(0.1)
2305
+ elapsed = tm() - start
2269
2306
  # end while
2307
+ # done waiting for supervisors
2308
+
2270
2309
  if len(self.__current_network_statuses) > 0:
2271
2310
  best_info = {}
2272
2311
  best_super = None
@@ -2274,10 +2313,17 @@ class GenericSession(BaseDecentrAIObject):
2274
2313
  if len(net_info) > len(best_info):
2275
2314
  best_info = net_info
2276
2315
  best_super = supervisor
2316
+ best_super_alias = None
2277
2317
  # done found best supervisor
2278
2318
  for _, node_info in best_info.items():
2279
2319
  is_online = node_info.get(PAYLOAD_DATA.NETMON_STATUS_KEY, None) == PAYLOAD_DATA.NETMON_STATUS_ONLINE
2280
2320
  is_supervisor = node_info.get(PAYLOAD_DATA.NETMON_IS_SUPERVISOR, False)
2321
+ # the following will get the whitelist for the current inspected node
2322
+ # without calling self.get_allowed_nodes but instead using the netmon data
2323
+ whitelist = node_info.get(PAYLOAD_DATA.NETMON_WHITELIST, [])
2324
+ client_is_allowed = self.bc_engine.contains_current_address(whitelist)
2325
+ if allowed_only and not client_is_allowed:
2326
+ continue
2281
2327
  if online_only and not is_online:
2282
2328
  continue
2283
2329
  if supervisors_only and not is_supervisor:
@@ -2292,9 +2338,21 @@ class GenericSession(BaseDecentrAIObject):
2292
2338
  # convert val (seconds) to a human readable format
2293
2339
  val = seconds_to_short_format(val)
2294
2340
  elif key == PAYLOAD_DATA.NETMON_ADDRESS:
2341
+ if self.bc_engine._remove_prefix(val) == self.bc_engine._remove_prefix(best_super):
2342
+ # again self.get_node_name(best_super) might not work if using the hb data
2343
+ best_super_alias = node_info.get(PAYLOAD_DATA.NETMON_EEID, None)
2295
2344
  val = self.bc_engine._add_prefix(val)
2345
+ elif key == PAYLOAD_DATA.NETMON_WHITELIST:
2346
+ val = client_is_allowed
2296
2347
  res[column].append(val)
2297
2348
  # end for
2298
2349
  # end if
2299
2350
  pd.options.display.float_format = '{:.1f}'.format
2300
- return pd.DataFrame(res), best_super
2351
+ dct_result ={
2352
+ 'report' : pd.DataFrame(res),
2353
+ 'reporter' : best_super,
2354
+ 'reporter_alias' : best_super_alias,
2355
+ 'nr_super' : len(self.__current_network_statuses),
2356
+ 'elapsed' : elapsed,
2357
+ }
2358
+ return dct_result
naeural_client/bc/base.py CHANGED
@@ -847,10 +847,30 @@ class BaseBlockEngine:
847
847
  #### ####
848
848
  #############################################################################
849
849
 
850
+
851
+ def contains_current_address(self, lst_addresses):
852
+ """
853
+ Checks if the current address is in the list of addresses
854
+
855
+ Parameters
856
+ ----------
857
+ lst_addresses : list
858
+ the list of addresses.
859
+
860
+ Returns
861
+ -------
862
+ bool
863
+ True if the current address is in the list.
864
+
865
+ """
866
+ lst = [self._remove_prefix(x) for x in lst_addresses]
867
+ return self.address_no_prefix in lst
868
+
850
869
  @property
851
870
  def address(self):
852
871
  """Returns the public address"""
853
872
  return self.__address
873
+
854
874
 
855
875
  @property
856
876
  def address_no_prefix(self):
naeural_client/cli/cli.py CHANGED
@@ -52,7 +52,7 @@ def build_parser():
52
52
  if isinstance(subcmd_info, dict) and "params" in subcmd_info:
53
53
  for param, description in subcmd_info["params"].items():
54
54
  if param.startswith("--"):
55
- if description.upper().endswith("FLAG"):
55
+ if description.lower().endswith("(flag)"):
56
56
  subcommand_parser.add_argument(
57
57
  param, action="store_true", help=description
58
58
  )
@@ -11,10 +11,12 @@ CLI_COMMANDS = {
11
11
  "nodes": {
12
12
  "func": get_nodes,
13
13
  "params": {
14
- "--all": "Get all known nodes flag", # DONE
15
- "--online" : "Get only online nodes flag", # DONE
16
- # "--peered": "Get only peered nodes"
17
- "--supervisor" : "Use a specific supervisor node"
14
+ ### use "(flag)" at the end of the description to indicate a boolean flag
15
+ ### otherwise it will be treated as a str parameter
16
+ "--all": "Get all known nodes including those that have been gone missing (flag)", # DONE
17
+ "--online" : "Get only online nodes as seen by a active supervisor (flag)", # DONE
18
+ "--peered": "Get only peered nodes - ie nodes that can be used by current client address (flag)", # DONE
19
+ "--supervisor" : "Use a specific supervisor node"
18
20
  }
19
21
  },
20
22
  "supervisors": {
@@ -15,22 +15,20 @@ def get_nodes(args):
15
15
  log_with_color(f"Getting nodes from supervisor <{supervisor_addr}>...", color='b')
16
16
  from naeural_client import Session
17
17
  sess = Session(silent=not args.verbose)
18
- if args.all:
19
- df, supervisor = sess.get_network_known_nodes(supervisor=supervisor_addr)
20
- log_with_color(f"Network full map reported by <{supervisor}>:", color='b')
21
- log_with_color(f"{df}")
22
- elif args.online:
23
- df, supervisor = sess.get_network_known_nodes(
24
- online_only=True, supervisor=supervisor_addr
25
- )
26
- log_with_color(f"Online nodes reported by <{supervisor}>:", color='b')
27
- log_with_color(f"{df}")
28
- else:
29
- df, supervisor = sess.get_network_known_nodes(
30
- online_only=True, supervisor=supervisor_addr
31
- )
32
- log_with_color(f"Online nodes reported by <{supervisor}>:", color='b')
33
- log_with_color(f"{df}")
18
+ online_only = args.online or args.peered
19
+ allowed_only = args.peered
20
+
21
+ dct_info = sess.get_network_known_nodes(
22
+ online_only=online_only, allowed_only=allowed_only, supervisor=supervisor_addr
23
+ )
24
+ df = dct_info['report']
25
+ supervisor = dct_info['reporter']
26
+ super_alias = dct_info['reporter_alias']
27
+ nr_supers = dct_info['nr_super']
28
+ elapsed = dct_info['elapsed']
29
+ prefix = "Online n" if online_only else "N"
30
+ log_with_color(f"{prefix}odes reported by <{supervisor}> '{super_alias}' in {elapsed:.1f}s ({nr_supers} supervisors seen):", color='b')
31
+ log_with_color(f"{df}")
34
32
  return
35
33
 
36
34
 
@@ -42,8 +40,12 @@ def get_supervisors(args):
42
40
  log_with_color("Getting supervisors...", color='b')
43
41
  from naeural_client import Session
44
42
  sess = Session(silent=not args.verbose)
45
- df, supervisor = sess.get_network_known_nodes(online_only=True, supervisors_only=True)
46
- log_with_color(f"Supervisors reported by <{supervisor}>", color='b')
43
+ dct_info = sess.get_network_known_nodes(online_only=True, supervisors_only=True)
44
+ df = dct_info['report']
45
+ supervisor = dct_info['reporter']
46
+ super_alias = dct_info['reporter_alias']
47
+ elapsed = dct_info['elapsed']
48
+ log_with_color(f"Supervisors reported by <{supervisor}> '{super_alias}' in {elapsed:.1f}s", color='b')
47
49
  log_with_color(f"{df}")
48
50
  return
49
51
 
@@ -204,6 +204,7 @@ class PAYLOAD_DATA:
204
204
  NETMON_NODE_UTC = 'node_utc'
205
205
  NETMON_LAST_SEEN = 'last_seen_sec'
206
206
  NETMON_IS_SUPERVISOR = 'is_supervisor'
207
+ NETMON_WHITELIST = 'whitelist'
207
208
 
208
209
 
209
210
  class NET_CONFIG:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.5.11
3
+ Version: 2.5.13
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
@@ -1,10 +1,10 @@
1
1
  naeural_client/__init__.py,sha256=GP8WSrn87sjTPO-QRNL2PG8JK5Mixbiea_HrtbG8RAQ,592
2
- naeural_client/_ver.py,sha256=IdfZWUnwl4zBYBAU3-uWWoRHoL8PekhfbG6gV1dQpa8,331
2
+ naeural_client/_ver.py,sha256=X8jG_pnMmkhenukxV6xSzGjehYk7LMlNwojkR7RFc5E,331
3
3
  naeural_client/base_decentra_object.py,sha256=C4iwZTkhKNBS4VHlJs5DfElRYLo4Q9l1V1DNVSk1fyQ,4412
4
4
  naeural_client/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  naeural_client/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
6
6
  naeural_client/base/distributed_custom_code_presets.py,sha256=cvz5R88P6Z5V61Ce1vHVVh8bOkgXd6gve_vdESDNAsg,2544
7
- naeural_client/base/generic_session.py,sha256=wIUhOTRzG6X-3N5xC7qk6yYFvHlVLqD0VJUppB3Zeos,85786
7
+ naeural_client/base/generic_session.py,sha256=6dc7oiKSw0Tc1pOh1WiE4XI8qX-hch-EKLozqsBiJ7o,88092
8
8
  naeural_client/base/instance.py,sha256=kcZJmjLBtx8Bjj_ysIOx1JmLA-qSpG7E28j5rq6IYus,20444
9
9
  naeural_client/base/pipeline.py,sha256=b4uNHrEIOlAtw4PGUx20dxwBhDck5__SrVXaHcSi8ZA,58251
10
10
  naeural_client/base/plugin_template.py,sha256=qGaXByd_JZFpjvH9GXNbT7KaitRxIJB6-1IhbKrZjq4,138123
@@ -14,15 +14,15 @@ naeural_client/base/webapp_pipeline.py,sha256=QmPLVmhP0CPdi0YuvbZEH4APYz2Amtw3gy
14
14
  naeural_client/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
15
15
  naeural_client/base/payload/payload.py,sha256=x-au7l67Z_vfn_4R2C_pjZCaFuUVXHngJiGOfIAYVdE,2690
16
16
  naeural_client/bc/__init__.py,sha256=FQj23D1PrY06NUOARiKQi4cdj0-VxnoYgYDEht8lpr8,158
17
- naeural_client/bc/base.py,sha256=ZXJkP0ainztIf0ehUOBUrqOr6msrfCyF8MvAklTxoDo,31773
17
+ naeural_client/bc/base.py,sha256=Uzpv0_YAM-lVV0mRJkt2cCy3z107BI50R-xWf-i32hw,32184
18
18
  naeural_client/bc/chain.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  naeural_client/bc/ec.py,sha256=mWjodWCRgC3omVXOA9jtNdtPVNn2kMKV3Dcjt9oFUCQ,22974
20
20
  naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt,sha256=y-6io0tseyx9-a4Pmde1z1gPULtJNSYUpG_YFkYaMKU,1337
22
22
  naeural_client/cli/README.md,sha256=WPdI_EjzAbUW1aPyj1sSR8rLydcJKZtoiaEtklQrjHo,74
23
- naeural_client/cli/cli.py,sha256=GyQhw16LrCbXU0JLH0HlbyYvKqa15K5RIhQ-Pgi7Gy4,3752
24
- naeural_client/cli/cli_commands.py,sha256=BtByinaxFvThyQdeu8Moz2aMioR5MW5GTiI1bGjbfwQ,1392
25
- naeural_client/cli/nodes.py,sha256=Q26sJpDCOd0oqpNonqEoCc1EcLVnf2CaGFzrG1wyzhA,2363
23
+ naeural_client/cli/cli.py,sha256=Yni8USLNK9g9G-l8_XomppZ5tKhduvA8wS4xOw3KODc,3754
24
+ naeural_client/cli/cli_commands.py,sha256=Y81oKz5Rx8qxYgzEzCwI9eB8iVL6iET7dETLVygs_VE,1686
25
+ naeural_client/cli/nodes.py,sha256=aCbSDFhTnub18LdrOPzu3kvx6acaBqHRgmyAdgqblP8,2459
26
26
  naeural_client/code_cheker/__init__.py,sha256=pwkdeZGVL16ZA4Qf2mRahEhoOvKhL7FyuQbMFLr1E5M,33
27
27
  naeural_client/code_cheker/base.py,sha256=lT5DRIFO5rqzsMNCmdMRfkAeevmezozehyfgmhnKpuI,19074
28
28
  naeural_client/code_cheker/checker.py,sha256=QWupeM7ToancVIq1tRUxRNUrI8B5l5eoY0kDU4-O5aE,7365
@@ -38,7 +38,7 @@ naeural_client/const/environment.py,sha256=iytmTDgbOjvORPwHQmc0K0r-xJx7dnnzNnqAJ
38
38
  naeural_client/const/formatter.py,sha256=AW3bWlqf39uaqV4BBUuW95qKYfF2OkkU4f9hy3kSVhM,200
39
39
  naeural_client/const/heartbeat.py,sha256=jGHmKfeHTFOXJaKUT3o_ocnQyF-EpcLeunW-ifkYKfU,2534
40
40
  naeural_client/const/misc.py,sha256=Y6x00YDtY1_nAk4OvikCLlfp8ggn11WQYTBGYzFlJPk,211
41
- naeural_client/const/payload.py,sha256=fHhhdSv1o_5Ldy72jO7m3YZtMmJOpOHaVhfjbNCuuzo,6446
41
+ naeural_client/const/payload.py,sha256=vHKxSrPXnfBTBwD_xp9Aw7nue0_gxz4r01YjXRYiTIM,6479
42
42
  naeural_client/default/__init__.py,sha256=ozU6CMMuWl0LhG8Ae3LrZ65a6tLrptfscVYGf83zjxM,46
43
43
  naeural_client/default/instance/__init__.py,sha256=w1de6OMj9a5GPGF-Wl1b_I_YAy9fWBEss2QnyPPyaB0,546
44
44
  naeural_client/default/instance/chain_dist_custom_job_01_plugin.py,sha256=QtHi3uXKsVs9eyMgbnvBVbMylErhV1Du4X2-7zDL7Y0,1915
@@ -81,8 +81,8 @@ naeural_client/utils/__init__.py,sha256=mAnke3-MeRzz3nhQvhuHqLnpaaCSmDxicd7Ck9uw
81
81
  naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,1072
82
82
  naeural_client/utils/config.py,sha256=aUVyi5rZjvnbUwM5mmj0E2IHvURdrlHSgleqZvJBNuU,5202
83
83
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
84
- naeural_client-2.5.11.dist-info/METADATA,sha256=-YWNOTUZO2cZEAaxd-PRBtX34Dh6yZit85NSuSSuaSM,14494
85
- naeural_client-2.5.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
86
- naeural_client-2.5.11.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
87
- naeural_client-2.5.11.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
88
- naeural_client-2.5.11.dist-info/RECORD,,
84
+ naeural_client-2.5.13.dist-info/METADATA,sha256=IrxAiqktgV62i7ztjMjrtXIzugDvd5difPNzdq-YkgI,14494
85
+ naeural_client-2.5.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
86
+ naeural_client-2.5.13.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
87
+ naeural_client-2.5.13.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
88
+ naeural_client-2.5.13.dist-info/RECORD,,