distributed-state-network 0.1.2__tar.gz → 0.1.3__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.
Files changed (31) hide show
  1. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/PKG-INFO +1 -1
  2. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/pyproject.toml +1 -1
  3. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/dsnode.py +5 -5
  4. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/handler.py +3 -1
  5. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/objects/hello_packet.py +1 -1
  6. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/objects/state_packet.py +1 -1
  7. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/util/key_manager.py +2 -2
  8. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/test.py +1 -0
  9. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/.github/workflows/publish.yml +0 -0
  10. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/.gitignore +0 -0
  11. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/LICENSE +0 -0
  12. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/README.md +0 -0
  13. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/coverage.sh +0 -0
  14. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/documentation/ds-node-config.md +0 -0
  15. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/documentation/ds-node-server.md +0 -0
  16. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/documentation/ds-node.md +0 -0
  17. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/documentation/protocol.md +0 -0
  18. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/documentation/usage.md +0 -0
  19. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/__init__.py +0 -0
  20. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/create_key.py +0 -0
  21. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/objects/config.py +0 -0
  22. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/objects/endpoint.py +0 -0
  23. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/objects/peers_packet.py +0 -0
  24. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/objects/signed_packet.py +0 -0
  25. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/util/__init__.py +0 -0
  26. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/util/aes.py +0 -0
  27. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/util/byte_helper.py +0 -0
  28. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/util/ecdsa.py +0 -0
  29. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/src/distributed_state_network/util/https.py +0 -0
  30. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/technical.md +0 -0
  31. {distributed_state_network-0.1.2 → distributed_state_network-0.1.3}/tests/connections.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: distributed-state-network
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A tool to distribute the state of a network device to other devices on the network
5
5
  Project-URL: Homepage, https://github.com/erinclemmer/distributed_state_network
6
6
  Project-URL: Issues, https://github.com/erinclemmer/distributed_state_network/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "distributed-state-network"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  authors = [{name="Erin Clemmer", email="erin.c.clemmer@gmail.com"}]
9
9
  description = "A tool to distribute the state of a network device to other devices on the network"
10
10
  keywords = ["distributed", "networking"]
@@ -150,10 +150,10 @@ class DSNode:
150
150
  def handle_peers(self, data: bytes):
151
151
  pkt = PeersPacket.from_bytes(data)
152
152
  if pkt.node_id not in self.address_book:
153
- raise Exception(401) # Not Authorized
153
+ raise Exception(401, f"Could not find {pkt.node_id} in address book") # Not Authorized
154
154
 
155
155
  if not pkt.verify_signature(self.cred_manager.read_public(pkt.node_id)):
156
- raise Exception(406) # Not Acceptable
156
+ raise Exception(406, "Could not verify ECDSA signature of packet") # Not Acceptable
157
157
 
158
158
  peers = { }
159
159
  for key in self.address_book.keys():
@@ -221,14 +221,14 @@ class DSNode:
221
221
 
222
222
  # ignore if we accidentally sent an update to ourselves
223
223
  if pkt.node_id == self.config.node_id:
224
- raise Exception(406) # Not acceptable
224
+ raise Exception(406, "Origin and destination are the same") # Not acceptable
225
225
 
226
226
  # don't use packets older than last update
227
227
  if pkt.node_id in self.node_states and self.node_states[pkt.node_id].last_update > pkt.last_update:
228
- raise Exception(406) # Not acceptable
228
+ raise Exception(406, "Update is stale") # Not acceptable
229
229
 
230
230
  if not pkt.verify_signature(self.cred_manager.read_public(pkt.node_id)):
231
- raise Exception(401) # Not authorized
231
+ raise Exception(401, "Could not verify ECDSA signature") # Not authorized
232
232
 
233
233
  if pkt.node_id not in self.node_states:
234
234
  self.node_states[pkt.node_id] = pkt
@@ -27,9 +27,11 @@ def graceful_fail(httpd: BaseHTTPRequestHandler, body: bytes, fn: Callable):
27
27
  else:
28
28
  respond_bytes(httpd, b'')
29
29
  except Exception as e:
30
- httpd.server.node.logger.error(f"Sending Error: {e.args[0]}")
30
+ httpd.server.node.logger.error(f"Sending Error: {e.args[0]} {e.args[1]}")
31
31
  httpd.send_response(e.args[0])
32
32
  httpd.end_headers()
33
+ httpd.wfile.write(e.args[1].encode('utf-8'))
34
+ httpd.wfile.flush()
33
35
 
34
36
  class DSNodeHandler(BaseHTTPRequestHandler):
35
37
  server: "NodeServer"
@@ -55,6 +55,6 @@ class HelloPacket(SignedPacket):
55
55
  https_certificate = bts.read_bytes() or None
56
56
 
57
57
  if version == '' or node_id == '' or ecdsa_public_key == b'':
58
- raise Exception(406) # Not acceptable
58
+ raise Exception(406, "Malformed packet") # Not acceptable
59
59
 
60
60
  return HelloPacket(version, node_id, connection, ecdsa_public_key, ecdsa_signature, https_certificate)
@@ -55,7 +55,7 @@ class StatePacket(SignedPacket):
55
55
  node_id = bts.read_string()
56
56
 
57
57
  if node_id == '':
58
- raise Exception(406) # Not acceptable
58
+ raise Exception(406, "Malformed packet") # Not acceptable
59
59
 
60
60
  last_update = bts.read_float()
61
61
  ecdsa_signature = bts.read_bytes()
@@ -32,7 +32,7 @@ class KeyManager:
32
32
 
33
33
  def read_public(self, node_id: str) -> bytes:
34
34
  if not os.path.exists(f'{self.folder}/{self.node_id}/{node_id}.{self.public_extension}'):
35
- raise Exception(401)
35
+ raise Exception(401, f"Cannot find public ECDSA key for {node_id}")
36
36
  with open(f'{self.folder}/{self.node_id}/{node_id}.{self.public_extension}', 'rb') as f:
37
37
  return f.read()
38
38
 
@@ -42,7 +42,7 @@ class KeyManager:
42
42
  def ensure_public(self, node_id: str, public_key: bytes):
43
43
  if self.has_public(node_id):
44
44
  if not self.verify_public(node_id, public_key):
45
- raise Exception(401)
45
+ raise Exception(401, f"Cannot verify ECDSA key for {node_id}")
46
46
  else:
47
47
  self.write_public(node_id, public_key)
48
48
 
@@ -322,6 +322,7 @@ class TestNode(unittest.TestCase):
322
322
  cm.read_public('test')
323
323
  except Exception as e:
324
324
  self.assertEqual(e.args[0], 401)
325
+ self.assertEqual(e.args[1], "Cannot find public ECDSA key for test")
325
326
 
326
327
  def test_ensure_cert(self):
327
328
  if os.path.exists('certs'):