neuronum 4.0.1__tar.gz → 5.0.0__tar.gz
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.
Potentially problematic release.
This version of neuronum might be problematic. Click here for more details.
- {neuronum-4.0.1/neuronum.egg-info → neuronum-5.0.0}/PKG-INFO +12 -3
- {neuronum-4.0.1 → neuronum-5.0.0}/README.md +11 -2
- {neuronum-4.0.1 → neuronum-5.0.0}/neuronum/neuronum.py +127 -77
- {neuronum-4.0.1 → neuronum-5.0.0/neuronum.egg-info}/PKG-INFO +12 -3
- {neuronum-4.0.1 → neuronum-5.0.0}/setup.py +1 -1
- {neuronum-4.0.1 → neuronum-5.0.0}/LICENSE +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/cli/__init__.py +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/cli/main.py +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/neuronum/__init__.py +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/neuronum.egg-info/SOURCES.txt +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/neuronum.egg-info/dependency_links.txt +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/neuronum.egg-info/entry_points.txt +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/neuronum.egg-info/requires.txt +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/neuronum.egg-info/top_level.txt +0 -0
- {neuronum-4.0.1 → neuronum-5.0.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: neuronum
|
|
3
|
-
Version:
|
|
3
|
+
Version: 5.0.0
|
|
4
4
|
Summary: Official client library to interact with the Neuronum Network
|
|
5
5
|
Home-page: https://neuronum.net
|
|
6
6
|
Author: Neuronum Cybernetics
|
|
@@ -86,11 +86,20 @@ neuronum view-cell # view Cell / output = Connected Cell: '
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
### **Build on Neuronum**
|
|
89
|
+
**Node Examples:**
|
|
90
|
+
Visit: https://github.com/neuronumcybernetics/neuronum/tree/main/how_tos/nodes
|
|
91
|
+
|
|
89
92
|
Initialize Node (default template):
|
|
90
93
|
```sh
|
|
91
94
|
neuronum init-node # initialize a Node with default template
|
|
92
95
|
```
|
|
93
96
|
|
|
97
|
+
Start Node:
|
|
98
|
+
```sh
|
|
99
|
+
neuronum start-node # start Node
|
|
100
|
+
```
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
Stop Node:
|
|
103
|
+
```sh
|
|
104
|
+
neuronum stop-node # stop Node
|
|
105
|
+
```
|
|
@@ -54,11 +54,20 @@ neuronum view-cell # view Cell / output = Connected Cell: '
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
### **Build on Neuronum**
|
|
57
|
+
**Node Examples:**
|
|
58
|
+
Visit: https://github.com/neuronumcybernetics/neuronum/tree/main/how_tos/nodes
|
|
59
|
+
|
|
57
60
|
Initialize Node (default template):
|
|
58
61
|
```sh
|
|
59
62
|
neuronum init-node # initialize a Node with default template
|
|
60
63
|
```
|
|
61
64
|
|
|
65
|
+
Start Node:
|
|
66
|
+
```sh
|
|
67
|
+
neuronum start-node # start Node
|
|
68
|
+
```
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
Stop Node:
|
|
71
|
+
```sh
|
|
72
|
+
neuronum stop-node # stop Node
|
|
73
|
+
```
|
|
@@ -13,6 +13,7 @@ class Cell:
|
|
|
13
13
|
self.synapse = synapse
|
|
14
14
|
self.queue = asyncio.Queue()
|
|
15
15
|
|
|
16
|
+
|
|
16
17
|
def to_dict(self) -> dict:
|
|
17
18
|
return {
|
|
18
19
|
"host": self.host,
|
|
@@ -20,8 +21,98 @@ class Cell:
|
|
|
20
21
|
"synapse": self.synapse
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
|
|
23
25
|
def __repr__(self) -> str:
|
|
24
26
|
return f"Cell(host={self.host}, password={self.password}, network={self.network}, synapse={self.synapse})"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def stream(self, label: str, data: dict, stx: Optional[str] = None, retry_delay: int = 3):
|
|
30
|
+
context = ssl.create_default_context()
|
|
31
|
+
context.check_hostname = True
|
|
32
|
+
context.verify_mode = ssl.CERT_REQUIRED
|
|
33
|
+
|
|
34
|
+
while True:
|
|
35
|
+
try:
|
|
36
|
+
reader, writer = await asyncio.open_connection(self.network, 55555, ssl=context, server_hostname=self.network)
|
|
37
|
+
|
|
38
|
+
credentials = f"{self.host}\n{self.password}\n{self.synapse}\n{stx}\n"
|
|
39
|
+
writer.write(credentials.encode("utf-8"))
|
|
40
|
+
await writer.drain()
|
|
41
|
+
|
|
42
|
+
response = await reader.read(1024)
|
|
43
|
+
response_text = response.decode("utf-8").strip()
|
|
44
|
+
|
|
45
|
+
if "Authentication successful" not in response_text:
|
|
46
|
+
print("Authentication failed, retrying...")
|
|
47
|
+
writer.close()
|
|
48
|
+
await writer.wait_closed()
|
|
49
|
+
await asyncio.sleep(retry_delay)
|
|
50
|
+
continue
|
|
51
|
+
|
|
52
|
+
stream_payload = {
|
|
53
|
+
"label": label,
|
|
54
|
+
"data": data,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
writer.write(json.dumps(stream_payload).encode("utf-8"))
|
|
58
|
+
await writer.drain()
|
|
59
|
+
|
|
60
|
+
response = await reader.read(1024)
|
|
61
|
+
response_text = response.decode("utf-8").strip()
|
|
62
|
+
|
|
63
|
+
if response_text == "Sent":
|
|
64
|
+
print(f"Success: {response_text} - {stream_payload}")
|
|
65
|
+
break
|
|
66
|
+
else:
|
|
67
|
+
print(f"Error sending: {stream_payload}")
|
|
68
|
+
|
|
69
|
+
except (ssl.SSLError, ConnectionError) as e:
|
|
70
|
+
print(f"Connection error: {e}, retrying...")
|
|
71
|
+
await asyncio.sleep(retry_delay)
|
|
72
|
+
|
|
73
|
+
except Exception as e:
|
|
74
|
+
print(f"Unexpected error: {e}, retrying...")
|
|
75
|
+
await asyncio.sleep(retry_delay)
|
|
76
|
+
|
|
77
|
+
finally:
|
|
78
|
+
if 'writer' in locals():
|
|
79
|
+
writer.close()
|
|
80
|
+
await writer.wait_closed()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async def sync(self, stx: Optional[str] = None) -> AsyncGenerator[str, None]:
|
|
84
|
+
full_url = f"wss://{self.network}/sync/{stx}"
|
|
85
|
+
|
|
86
|
+
auth_payload = {
|
|
87
|
+
"host": self.host,
|
|
88
|
+
"password": self.password,
|
|
89
|
+
"synapse": self.synapse,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
async with websockets.connect(full_url) as ws:
|
|
94
|
+
await ws.send(json.dumps(auth_payload))
|
|
95
|
+
print("Listening to Stream...")
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
while True:
|
|
99
|
+
try:
|
|
100
|
+
raw_operation = await ws.recv()
|
|
101
|
+
operation = json.loads(raw_operation)
|
|
102
|
+
yield operation
|
|
103
|
+
|
|
104
|
+
except asyncio.TimeoutError:
|
|
105
|
+
print("No initial data received. Continuing to listen...")
|
|
106
|
+
continue
|
|
107
|
+
|
|
108
|
+
except asyncio.CancelledError:
|
|
109
|
+
print("Connection closed.")
|
|
110
|
+
|
|
111
|
+
except websockets.exceptions.WebSocketException as e:
|
|
112
|
+
print(f"WebSocket error occurred: {e}")
|
|
113
|
+
|
|
114
|
+
except Exception as e:
|
|
115
|
+
print(f"An unexpected error occurred: {e}")
|
|
25
116
|
|
|
26
117
|
|
|
27
118
|
async def create_tx(self, descr: str, key_values: dict, stx: str, label: str, partners: list):
|
|
@@ -85,7 +176,17 @@ class Cell:
|
|
|
85
176
|
response.raise_for_status()
|
|
86
177
|
response.raise_for_status()
|
|
87
178
|
data = await response.json()
|
|
88
|
-
|
|
179
|
+
if data["success"] == "activated":
|
|
180
|
+
async for operation in self.sync():
|
|
181
|
+
label = operation.get("label")
|
|
182
|
+
if label == "tx_response":
|
|
183
|
+
operation_id = operation.get("operationID")
|
|
184
|
+
if operation_id == data["operationID"]:
|
|
185
|
+
tx_response = operation.get("data")
|
|
186
|
+
return tx_response
|
|
187
|
+
|
|
188
|
+
else:
|
|
189
|
+
print(data["success"], data["message"])
|
|
89
190
|
|
|
90
191
|
except aiohttp.ClientError as e:
|
|
91
192
|
print(f"Error sending request: {e}")
|
|
@@ -93,6 +194,31 @@ class Cell:
|
|
|
93
194
|
print(f"Unexpected error: {e}")
|
|
94
195
|
|
|
95
196
|
|
|
197
|
+
async def tx_response(self, txID: str, cc: str, operationID: str, data: dict):
|
|
198
|
+
url = f"https://{self.network}/api/tx_response/{txID}"
|
|
199
|
+
|
|
200
|
+
tx_response = {
|
|
201
|
+
"cc": cc,
|
|
202
|
+
"operationID": operationID,
|
|
203
|
+
"data": data,
|
|
204
|
+
"cell": self.to_dict()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async with aiohttp.ClientSession() as session:
|
|
208
|
+
for attempt in range(5):
|
|
209
|
+
try:
|
|
210
|
+
async with session.post(url, json=tx_response) as response:
|
|
211
|
+
response.raise_for_status()
|
|
212
|
+
data = await response.json()
|
|
213
|
+
|
|
214
|
+
except aiohttp.ClientError as e:
|
|
215
|
+
print(f"Attempt {attempt + 1}: Error sending request: {e}")
|
|
216
|
+
except Exception as e:
|
|
217
|
+
print(f"Attempt {attempt + 1}: Unexpected error: {e}")
|
|
218
|
+
|
|
219
|
+
print(data["message"])
|
|
220
|
+
|
|
221
|
+
|
|
96
222
|
async def create_ctx(self, descr: str, partners: list):
|
|
97
223
|
url = f"https://{self.network}/api/create_ctx"
|
|
98
224
|
|
|
@@ -368,80 +494,4 @@ class Cell:
|
|
|
368
494
|
print(f"Unexpected error: {e}")
|
|
369
495
|
|
|
370
496
|
|
|
371
|
-
async def stream(self, label: str, data: dict, stx: Optional[str] = None):
|
|
372
|
-
context = ssl.create_default_context()
|
|
373
|
-
context.check_hostname = True
|
|
374
|
-
context.verify_mode = ssl.CERT_REQUIRED
|
|
375
|
-
|
|
376
|
-
try:
|
|
377
|
-
reader, writer = await asyncio.open_connection(self.network, 55555, ssl=context, server_hostname=self.network)
|
|
378
|
-
|
|
379
|
-
credentials = f"{self.host}\n{self.password}\n{self.synapse}\n{stx}\n"
|
|
380
|
-
writer.write(credentials.encode("utf-8"))
|
|
381
|
-
await writer.drain()
|
|
382
|
-
|
|
383
|
-
response = await reader.read(1024)
|
|
384
|
-
response_text = response.decode("utf-8")
|
|
385
|
-
|
|
386
|
-
if "Authentication successful" not in response_text:
|
|
387
|
-
print("Authentication failed")
|
|
388
|
-
writer.close()
|
|
389
|
-
await writer.wait_closed()
|
|
390
|
-
return
|
|
391
|
-
|
|
392
|
-
stream_payload = {
|
|
393
|
-
"label": label,
|
|
394
|
-
"data": data,
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
writer.write(json.dumps(stream_payload).encode("utf-8"))
|
|
398
|
-
await writer.drain()
|
|
399
|
-
print(f"Sent: {stream_payload}")
|
|
400
|
-
|
|
401
|
-
except ssl.SSLError as e:
|
|
402
|
-
print(f"SSL error occurred: {e}")
|
|
403
|
-
|
|
404
|
-
except Exception as e:
|
|
405
|
-
print(f"An unexpected error occurred: {e}")
|
|
406
|
-
|
|
407
|
-
finally:
|
|
408
|
-
writer.close()
|
|
409
|
-
await writer.wait_closed()
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
async def sync(self, stx: Optional[str] = None) -> AsyncGenerator[str, None]:
|
|
413
|
-
full_url = f"wss://{self.network}/sync/{stx}"
|
|
414
|
-
|
|
415
|
-
auth_payload = {
|
|
416
|
-
"host": self.host,
|
|
417
|
-
"password": self.password,
|
|
418
|
-
"synapse": self.synapse,
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
try:
|
|
422
|
-
async with websockets.connect(full_url) as ws:
|
|
423
|
-
await ws.send(json.dumps(auth_payload))
|
|
424
|
-
print("Listening to Stream...")
|
|
425
|
-
|
|
426
|
-
try:
|
|
427
|
-
while True:
|
|
428
|
-
try:
|
|
429
|
-
raw_operation = await ws.recv()
|
|
430
|
-
operation = json.loads(raw_operation)
|
|
431
|
-
yield operation
|
|
432
|
-
|
|
433
|
-
except asyncio.TimeoutError:
|
|
434
|
-
print("No initial data received. Continuing to listen...")
|
|
435
|
-
continue
|
|
436
|
-
|
|
437
|
-
except asyncio.CancelledError:
|
|
438
|
-
print("Connection closed.")
|
|
439
|
-
|
|
440
|
-
except websockets.exceptions.WebSocketException as e:
|
|
441
|
-
print(f"WebSocket error occurred: {e}")
|
|
442
|
-
|
|
443
|
-
except Exception as e:
|
|
444
|
-
print(f"An unexpected error occurred: {e}")
|
|
445
|
-
|
|
446
|
-
|
|
447
497
|
__all__ = ['Cell']
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: neuronum
|
|
3
|
-
Version:
|
|
3
|
+
Version: 5.0.0
|
|
4
4
|
Summary: Official client library to interact with the Neuronum Network
|
|
5
5
|
Home-page: https://neuronum.net
|
|
6
6
|
Author: Neuronum Cybernetics
|
|
@@ -86,11 +86,20 @@ neuronum view-cell # view Cell / output = Connected Cell: '
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
### **Build on Neuronum**
|
|
89
|
+
**Node Examples:**
|
|
90
|
+
Visit: https://github.com/neuronumcybernetics/neuronum/tree/main/how_tos/nodes
|
|
91
|
+
|
|
89
92
|
Initialize Node (default template):
|
|
90
93
|
```sh
|
|
91
94
|
neuronum init-node # initialize a Node with default template
|
|
92
95
|
```
|
|
93
96
|
|
|
97
|
+
Start Node:
|
|
98
|
+
```sh
|
|
99
|
+
neuronum start-node # start Node
|
|
100
|
+
```
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
Stop Node:
|
|
103
|
+
```sh
|
|
104
|
+
neuronum stop-node # stop Node
|
|
105
|
+
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|