astreum 0.3.25__tar.gz → 0.3.46__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.
- {astreum-0.3.25/src/astreum.egg-info → astreum-0.3.46}/PKG-INFO +12 -4
- {astreum-0.3.25 → astreum-0.3.46}/README.md +28 -20
- {astreum-0.3.25 → astreum-0.3.46}/pyproject.toml +1 -1
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/__init__.py +1 -2
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/__init__.py +15 -11
- astreum-0.3.46/src/astreum/communication/difficulty.py +39 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/handlers/handshake.py +59 -42
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/handlers/object_request.py +179 -149
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/handlers/object_response.py +7 -1
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/handlers/ping.py +9 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/handlers/route_request.py +7 -1
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/handlers/route_response.py +7 -1
- astreum-0.3.46/src/astreum/communication/incoming_queue.py +96 -0
- astreum-0.3.46/src/astreum/communication/message_pow.py +36 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/models/peer.py +4 -0
- astreum-0.3.46/src/astreum/communication/models/ping.py +54 -0
- astreum-0.3.46/src/astreum/communication/outgoing_queue.py +108 -0
- astreum-0.3.46/src/astreum/communication/processors/incoming.py +171 -0
- astreum-0.3.46/src/astreum/communication/processors/outgoing.py +53 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/processors/peer.py +122 -105
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/setup.py +196 -90
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/util.py +14 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/node.py +98 -96
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/storage/actions/get.py +79 -48
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/storage/actions/set.py +171 -155
- astreum-0.3.46/src/astreum/storage/providers.py +24 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/storage/setup.py +23 -22
- astreum-0.3.46/src/astreum/utils/config.py +265 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/__init__.py +0 -2
- astreum-0.3.46/src/astreum/validation/constants.py +2 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/genesis.py +1 -4
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/models/block.py +208 -48
- astreum-0.3.46/src/astreum/validation/models/fork.py +511 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/models/transaction.py +1 -1
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/node.py +80 -17
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/validator.py +1 -1
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/workers/validation.py +265 -253
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/verification/worker.py +145 -66
- {astreum-0.3.25 → astreum-0.3.46/src/astreum.egg-info}/PKG-INFO +12 -4
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum.egg-info/SOURCES.txt +6 -1
- astreum-0.3.25/src/astreum/communication/models/ping.py +0 -45
- astreum-0.3.25/src/astreum/communication/processors/incoming.py +0 -117
- astreum-0.3.25/src/astreum/communication/processors/outgoing.py +0 -29
- astreum-0.3.25/src/astreum/utils/config.py +0 -140
- astreum-0.3.25/src/astreum/validation/models/chain.py +0 -66
- astreum-0.3.25/src/astreum/validation/models/fork.py +0 -100
- {astreum-0.3.25 → astreum-0.3.46}/LICENSE +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/setup.cfg +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/disconnect.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/handlers/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/models/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/models/message.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/models/route.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/node.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/communication/processors/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/crypto/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/crypto/chacha20poly1305.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/crypto/ed25519.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/crypto/quadratic_form.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/crypto/wesolowski.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/crypto/x25519.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/evaluations/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/evaluations/high_evaluation.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/evaluations/low_evaluation.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/evaluations/script_evaluation.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/models/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/models/environment.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/models/expression.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/models/meter.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/parser.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/machine/tokenizer.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/storage/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/storage/models/atom.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/storage/models/trie.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/storage/requests.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/utils/bytes.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/utils/integer.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/utils/logging.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/models/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/models/account.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/models/accounts.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/models/receipt.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/validation/workers/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/verification/__init__.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/verification/discover.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum/verification/node.py +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum.egg-info/dependency_links.txt +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum.egg-info/requires.txt +0 -0
- {astreum-0.3.25 → astreum-0.3.46}/src/astreum.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: astreum
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.46
|
|
4
4
|
Summary: Python library to interact with the Astreum blockchain and its virtual machine.
|
|
5
5
|
Author-email: "Roy R. O. Okello" <roy@stelar.xyz>
|
|
6
6
|
Project-URL: Homepage, https://github.com/astreum/lib-py
|
|
@@ -45,11 +45,17 @@ When initializing an `astreum.Node`, pass a dictionary with any of the options b
|
|
|
45
45
|
| `validation_secret_key` | hex string | `None` | Optional Ed25519 key that lets the node join the validation route; leave blank to opt out of validation. |
|
|
46
46
|
| `use_ipv6` | bool | `False` | Bind the incoming/outgoing sockets on IPv6 (the OS still listens on IPv4 if a peer speaks both). |
|
|
47
47
|
| `incoming_port` | int | `52780` | UDP port the relay binds to; pass `0` or omit to let the OS pick an ephemeral port. |
|
|
48
|
-
| `
|
|
49
|
-
| `additional_seeds` | list\[str\] | `[]` | Extra addresses appended to
|
|
48
|
+
| `default_seed` | string | `"bootstrap.astreum.org:52780"` | Default address to ping before joining; set to `None` to disable the built-in default. |
|
|
49
|
+
| `additional_seeds` | list\[str\] | `[]` | Extra addresses appended to the bootstrap list; each must look like `host:port` or `[ipv6]:port`. |
|
|
50
50
|
| `peer_timeout` | int | `900` | Evict peers that have not been seen within this many seconds (15 minutes). |
|
|
51
51
|
| `peer_timeout_interval` | int | `10` | How often (seconds) the peer manager checks for stale peers. |
|
|
52
52
|
| `bootstrap_retry_interval` | int | `30` | How often (seconds) to retry bootstrapping when the peer list is empty. |
|
|
53
|
+
| `storage_index_interval` | int | `600` | How often (seconds) to re-advertise cold storage atoms to the closest known peer. |
|
|
54
|
+
| `cold_storage_advertise_limit` | int | `1000` | Max cold storage atoms advertised per cycle using last-modified time; `-1` unlimited, `0` disable. |
|
|
55
|
+
| `incoming_queue_size_limit` | int | `67108864` | Soft cap (bytes) for inbound queue usage tracked by `enqueue_incoming`; set to `0` to disable. |
|
|
56
|
+
| `incoming_queue_timeout` | float | `1.0` | When > 0, `enqueue_incoming` waits up to this many seconds for space before dropping the payload. |
|
|
57
|
+
| `outgoing_queue_size_limit` | int | `67108864` | Soft cap (bytes) for `enqueue_outgoing`-tracked outgoing queue usage; set to `0` to disable. |
|
|
58
|
+
| `outgoing_queue_timeout` | float | `1.0` | When > 0, `enqueue_outgoing` waits up to this many seconds for space before dropping the payload. |
|
|
53
59
|
|
|
54
60
|
> **Note**
|
|
55
61
|
> The peer‑to‑peer *route* used for object discovery is always enabled.
|
|
@@ -66,9 +72,10 @@ config = {
|
|
|
66
72
|
"hot_storage_limit": 1073741824, # cap hot cache at 1 GiB
|
|
67
73
|
"cold_storage_limit": 10737418240, # cap cold storage at 10 GiB
|
|
68
74
|
"cold_storage_path": "./data/node1",
|
|
75
|
+
"cold_storage_advertise_limit": 1000, # -1 unlimited, 0 disable, >0 limit
|
|
69
76
|
"incoming_port": 52780,
|
|
70
77
|
"use_ipv6": False,
|
|
71
|
-
"
|
|
78
|
+
"default_seed": None,
|
|
72
79
|
"additional_seeds": [
|
|
73
80
|
"127.0.0.1:7374"
|
|
74
81
|
]
|
|
@@ -175,6 +182,7 @@ python3 -m unittest tests.node.test_current_validator
|
|
|
175
182
|
python3 -m unittest tests.node.test_node_connection
|
|
176
183
|
python3 -m unittest tests.node.test_node_init
|
|
177
184
|
python3 -m unittest tests.node.test_node_validation
|
|
185
|
+
python3 -m unittest tests.node.config.default_seed
|
|
178
186
|
python3 -m unittest tests.node.tokenize
|
|
179
187
|
python3 -m unittest tests.node.parse
|
|
180
188
|
python3 -m unittest tests.node.function
|
|
@@ -15,23 +15,29 @@ When initializing an `astreum.Node`, pass a dictionary with any of the options b
|
|
|
15
15
|
| `hot_storage_limit` | int | `1073741824` | Maximum bytes kept in the hot cache before new atoms are skipped (1 GiB). |
|
|
16
16
|
| `cold_storage_limit` | int | `10737418240` | Cold storage write threshold (10 GiB by default); set to `0` to skip the limit. |
|
|
17
17
|
| `cold_storage_path` | string | `None` | Directory where persisted atoms live; Astreum creates it on startup and skips cold storage when unset. |
|
|
18
|
-
| `logging_retention_days` | int | `90` | Number of days to keep rotated log files (daily gzip). |
|
|
19
|
-
| `chain_id` | int | `0` | Chain identifier used for validation (0 = test, 1 = main). |
|
|
18
|
+
| `logging_retention_days` | int | `90` | Number of days to keep rotated log files (daily gzip). |
|
|
19
|
+
| `chain_id` | int | `0` | Chain identifier used for validation (0 = test, 1 = main). |
|
|
20
20
|
| `verbose` | bool | `False` | When **True**, also mirror JSON logs to stdout with a human-readable format. |
|
|
21
21
|
|
|
22
22
|
### Communication
|
|
23
23
|
|
|
24
24
|
| Parameter | Type | Default | Description |
|
|
25
25
|
| ------------------------ | ----------- | --------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
26
|
-
| `relay_secret_key` | hex string | Auto-generated | X25519 private key used for the relay route; a new keypair is created when this field is omitted. |
|
|
27
|
-
| `validation_secret_key` | hex string | `None` | Optional Ed25519 key that lets the node join the validation route; leave blank to opt out of validation. |
|
|
28
|
-
| `use_ipv6` | bool | `False` | Bind the incoming/outgoing sockets on IPv6 (the OS still listens on IPv4 if a peer speaks both). |
|
|
29
|
-
| `incoming_port` | int | `52780` | UDP port the relay binds to; pass `0` or omit to let the OS pick an ephemeral port. |
|
|
30
|
-
| `
|
|
31
|
-
| `additional_seeds` | list\[str\] | `[]` | Extra addresses appended to
|
|
32
|
-
| `peer_timeout` | int | `900` | Evict peers that have not been seen within this many seconds (15 minutes). |
|
|
33
|
-
| `peer_timeout_interval` | int | `10` | How often (seconds) the peer manager checks for stale peers. |
|
|
34
|
-
| `bootstrap_retry_interval` | int | `30` | How often (seconds) to retry bootstrapping when the peer list is empty. |
|
|
26
|
+
| `relay_secret_key` | hex string | Auto-generated | X25519 private key used for the relay route; a new keypair is created when this field is omitted. |
|
|
27
|
+
| `validation_secret_key` | hex string | `None` | Optional Ed25519 key that lets the node join the validation route; leave blank to opt out of validation. |
|
|
28
|
+
| `use_ipv6` | bool | `False` | Bind the incoming/outgoing sockets on IPv6 (the OS still listens on IPv4 if a peer speaks both). |
|
|
29
|
+
| `incoming_port` | int | `52780` | UDP port the relay binds to; pass `0` or omit to let the OS pick an ephemeral port. |
|
|
30
|
+
| `default_seed` | string | `"bootstrap.astreum.org:52780"` | Default address to ping before joining; set to `None` to disable the built-in default. |
|
|
31
|
+
| `additional_seeds` | list\[str\] | `[]` | Extra addresses appended to the bootstrap list; each must look like `host:port` or `[ipv6]:port`. |
|
|
32
|
+
| `peer_timeout` | int | `900` | Evict peers that have not been seen within this many seconds (15 minutes). |
|
|
33
|
+
| `peer_timeout_interval` | int | `10` | How often (seconds) the peer manager checks for stale peers. |
|
|
34
|
+
| `bootstrap_retry_interval` | int | `30` | How often (seconds) to retry bootstrapping when the peer list is empty. |
|
|
35
|
+
| `storage_index_interval` | int | `600` | How often (seconds) to re-advertise cold storage atoms to the closest known peer. |
|
|
36
|
+
| `cold_storage_advertise_limit` | int | `1000` | Max cold storage atoms advertised per cycle using last-modified time; `-1` unlimited, `0` disable. |
|
|
37
|
+
| `incoming_queue_size_limit` | int | `67108864` | Soft cap (bytes) for inbound queue usage tracked by `enqueue_incoming`; set to `0` to disable. |
|
|
38
|
+
| `incoming_queue_timeout` | float | `1.0` | When > 0, `enqueue_incoming` waits up to this many seconds for space before dropping the payload. |
|
|
39
|
+
| `outgoing_queue_size_limit` | int | `67108864` | Soft cap (bytes) for `enqueue_outgoing`-tracked outgoing queue usage; set to `0` to disable. |
|
|
40
|
+
| `outgoing_queue_timeout` | float | `1.0` | When > 0, `enqueue_outgoing` waits up to this many seconds for space before dropping the payload. |
|
|
35
41
|
|
|
36
42
|
> **Note**
|
|
37
43
|
> The peer‑to‑peer *route* used for object discovery is always enabled.
|
|
@@ -47,14 +53,15 @@ config = {
|
|
|
47
53
|
"validation_secret_key": "12…34", # optional – validator
|
|
48
54
|
"hot_storage_limit": 1073741824, # cap hot cache at 1 GiB
|
|
49
55
|
"cold_storage_limit": 10737418240, # cap cold storage at 10 GiB
|
|
50
|
-
"cold_storage_path": "./data/node1",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
"cold_storage_path": "./data/node1",
|
|
57
|
+
"cold_storage_advertise_limit": 1000, # -1 unlimited, 0 disable, >0 limit
|
|
58
|
+
"incoming_port": 52780,
|
|
59
|
+
"use_ipv6": False,
|
|
60
|
+
"default_seed": None,
|
|
61
|
+
"additional_seeds": [
|
|
62
|
+
"127.0.0.1:7374"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
58
65
|
|
|
59
66
|
node = Node(config)
|
|
60
67
|
# … your code …
|
|
@@ -132,7 +139,7 @@ except ParseError as e:
|
|
|
132
139
|
Every `Node` instance wires up structured logging automatically:
|
|
133
140
|
|
|
134
141
|
- Logs land in per-instance files named `node.log` under `%LOCALAPPDATA%\Astreum\lib-py\logs/<instance_id>` on Windows and `$XDG_STATE_HOME` (or `~/.local/state`)/`Astreum/lib-py/logs/<instance_id>` on other platforms. The `<instance_id>` is the first 16 hex characters of a BLAKE3 hash of the caller's file path, so running the node from different entry points keeps their logs isolated.
|
|
135
|
-
- Files rotate at midnight UTC with gzip compression (`node-YYYY-MM-DD.log.gz`) and retain 90 days by default. Override via `config["logging_retention_days"]`.
|
|
142
|
+
- Files rotate at midnight UTC with gzip compression (`node-YYYY-MM-DD.log.gz`) and retain 90 days by default. Override via `config["logging_retention_days"]`.
|
|
136
143
|
- Each event is a single JSON line containing timestamp, level, logger, message, process/thread info, module/function, and the derived `instance_id`.
|
|
137
144
|
- Set `config["verbose"] = True` to mirror logs to stdout in a human-friendly format like `[2025-04-13-42-59] [info] Starting Astreum Node`.
|
|
138
145
|
- The very first entry emitted is the banner `Starting Astreum Node`, signalling that the logging pipeline is live before other subsystems spin up.
|
|
@@ -157,6 +164,7 @@ python3 -m unittest tests.node.test_current_validator
|
|
|
157
164
|
python3 -m unittest tests.node.test_node_connection
|
|
158
165
|
python3 -m unittest tests.node.test_node_init
|
|
159
166
|
python3 -m unittest tests.node.test_node_validation
|
|
167
|
+
python3 -m unittest tests.node.config.default_seed
|
|
160
168
|
python3 -m unittest tests.node.tokenize
|
|
161
169
|
python3 -m unittest tests.node.parse
|
|
162
170
|
python3 -m unittest tests.node.function
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
from astreum.validation import Account, Accounts, Block,
|
|
2
|
+
from astreum.validation import Account, Accounts, Block, Fork, Receipt, Transaction
|
|
3
3
|
from astreum.machine import Env, Expr, parse, tokenize
|
|
4
4
|
from astreum.node import Node
|
|
5
5
|
|
|
@@ -9,7 +9,6 @@ __all__: list[str] = [
|
|
|
9
9
|
"Env",
|
|
10
10
|
"Expr",
|
|
11
11
|
"Block",
|
|
12
|
-
"Chain",
|
|
13
12
|
"Fork",
|
|
14
13
|
"Receipt",
|
|
15
14
|
"Transaction",
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
from .models.message import Message
|
|
2
|
-
from .models.peer import Peer
|
|
3
|
-
from .models.route import Route
|
|
4
|
-
from .
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
1
|
+
from .models.message import Message
|
|
2
|
+
from .models.peer import Peer
|
|
3
|
+
from .models.route import Route
|
|
4
|
+
from .incoming_queue import enqueue_incoming
|
|
5
|
+
from .outgoing_queue import enqueue_outgoing
|
|
6
|
+
from .setup import communication_setup
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"Message",
|
|
10
|
+
"Peer",
|
|
11
|
+
"Route",
|
|
12
|
+
"enqueue_incoming",
|
|
13
|
+
"enqueue_outgoing",
|
|
14
|
+
"communication_setup",
|
|
15
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from .. import Node
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def message_difficulty(node: "Node") -> int:
|
|
10
|
+
"""Compute current message difficulty based on incoming queue pressure."""
|
|
11
|
+
size = node.incoming_queue_size
|
|
12
|
+
limit = node.incoming_queue_size_limit
|
|
13
|
+
|
|
14
|
+
if limit <= 0:
|
|
15
|
+
return 1
|
|
16
|
+
|
|
17
|
+
pressure = size / limit
|
|
18
|
+
if pressure < 0.70:
|
|
19
|
+
value = 1
|
|
20
|
+
elif pressure < 0.75:
|
|
21
|
+
value = 3
|
|
22
|
+
elif pressure < 0.80:
|
|
23
|
+
value = 5
|
|
24
|
+
elif pressure < 0.85:
|
|
25
|
+
value = 8
|
|
26
|
+
elif pressure < 0.90:
|
|
27
|
+
value = 12
|
|
28
|
+
elif pressure < 0.93:
|
|
29
|
+
value = 16
|
|
30
|
+
elif pressure < 0.95:
|
|
31
|
+
value = 19
|
|
32
|
+
elif pressure < 0.97:
|
|
33
|
+
value = 22
|
|
34
|
+
elif pressure < 0.98:
|
|
35
|
+
value = 24
|
|
36
|
+
else:
|
|
37
|
+
value = 26
|
|
38
|
+
|
|
39
|
+
return max(1, min(255, value))
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING, Sequence
|
|
4
|
-
|
|
5
|
-
from cryptography.hazmat.primitives import serialization
|
|
6
|
-
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PublicKey
|
|
7
|
-
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Sequence
|
|
4
|
+
|
|
5
|
+
from cryptography.hazmat.primitives import serialization
|
|
6
|
+
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PublicKey
|
|
7
|
+
|
|
8
|
+
from ..outgoing_queue import enqueue_outgoing
|
|
8
9
|
from ..models.peer import Peer
|
|
9
10
|
from ..models.message import Message, MessageTopic
|
|
10
11
|
from ..models.ping import Ping
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
from ..difficulty import message_difficulty
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from .... import Node
|
|
16
|
+
|
|
17
|
+
|
|
16
18
|
def handle_handshake(node: "Node", addr: Sequence[object], message: Message) -> bool:
|
|
17
19
|
"""Handle incoming handshake messages.
|
|
18
20
|
|
|
@@ -25,6 +27,7 @@ def handle_handshake(node: "Node", addr: Sequence[object], message: Message) ->
|
|
|
25
27
|
try:
|
|
26
28
|
ping_payload = Ping(
|
|
27
29
|
is_validator=bool(getattr(node, "validation_public_key", None)),
|
|
30
|
+
difficulty=message_difficulty(node),
|
|
28
31
|
latest_block=latest_block,
|
|
29
32
|
).to_bytes()
|
|
30
33
|
ping_msg = Message(
|
|
@@ -33,7 +36,12 @@ def handle_handshake(node: "Node", addr: Sequence[object], message: Message) ->
|
|
|
33
36
|
sender=node.relay_public_key,
|
|
34
37
|
)
|
|
35
38
|
ping_msg.encrypt(peer.shared_key_bytes)
|
|
36
|
-
|
|
39
|
+
enqueue_outgoing(
|
|
40
|
+
node,
|
|
41
|
+
peer_address,
|
|
42
|
+
message=ping_msg,
|
|
43
|
+
difficulty=peer.difficulty,
|
|
44
|
+
)
|
|
37
45
|
except Exception as exc:
|
|
38
46
|
node.logger.debug(
|
|
39
47
|
"Failed sending handshake ping to %s:%s: %s",
|
|
@@ -41,48 +49,57 @@ def handle_handshake(node: "Node", addr: Sequence[object], message: Message) ->
|
|
|
41
49
|
peer_address[1],
|
|
42
50
|
exc,
|
|
43
51
|
)
|
|
44
|
-
sender_public_key_bytes = message.sender_bytes
|
|
45
|
-
try:
|
|
46
|
-
sender_key = X25519PublicKey.from_public_bytes(sender_public_key_bytes)
|
|
47
|
-
except Exception as exc:
|
|
48
|
-
node.logger.warning("Error extracting sender key bytes: %s", exc)
|
|
49
|
-
return True
|
|
50
|
-
|
|
51
|
-
try:
|
|
52
|
-
host = addr[0]
|
|
53
|
-
port = int.from_bytes(message.content[:2], "big", signed=False)
|
|
54
|
-
except Exception:
|
|
55
|
-
return True
|
|
56
|
-
peer_address = (host, port)
|
|
57
|
-
|
|
52
|
+
sender_public_key_bytes = message.sender_bytes
|
|
53
|
+
try:
|
|
54
|
+
sender_key = X25519PublicKey.from_public_bytes(sender_public_key_bytes)
|
|
55
|
+
except Exception as exc:
|
|
56
|
+
node.logger.warning("Error extracting sender key bytes: %s", exc)
|
|
57
|
+
return True
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
host = addr[0]
|
|
61
|
+
port = int.from_bytes(message.content[:2], "big", signed=False)
|
|
62
|
+
except Exception:
|
|
63
|
+
return True
|
|
64
|
+
peer_address = (host, port)
|
|
65
|
+
default_seed_ips = getattr(node, "default_seed_ips", None)
|
|
66
|
+
is_default_seed = bool(default_seed_ips) and host in default_seed_ips
|
|
67
|
+
|
|
58
68
|
existing_peer = node.get_peer(sender_public_key_bytes)
|
|
59
69
|
if existing_peer is not None:
|
|
60
70
|
existing_peer.address = peer_address
|
|
71
|
+
existing_peer.is_default_seed = is_default_seed
|
|
61
72
|
_queue_handshake_ping(existing_peer, peer_address)
|
|
62
73
|
return False
|
|
63
|
-
|
|
64
|
-
try:
|
|
65
|
-
peer = Peer(
|
|
66
|
-
node_secret_key=node.relay_secret_key,
|
|
67
|
-
peer_public_key=sender_key,
|
|
68
|
-
address=peer_address,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
node.
|
|
75
|
-
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
peer = Peer(
|
|
77
|
+
node_secret_key=node.relay_secret_key,
|
|
78
|
+
peer_public_key=sender_key,
|
|
79
|
+
address=peer_address,
|
|
80
|
+
is_default_seed=is_default_seed,
|
|
81
|
+
)
|
|
82
|
+
except Exception:
|
|
83
|
+
return True
|
|
84
|
+
|
|
85
|
+
node.add_peer(sender_public_key_bytes, peer)
|
|
86
|
+
node.peer_route.add_peer(sender_public_key_bytes, peer)
|
|
87
|
+
|
|
76
88
|
node.logger.info(
|
|
77
89
|
"Handshake accepted from %s:%s; peer added",
|
|
78
90
|
peer_address[0],
|
|
79
91
|
peer_address[1],
|
|
80
|
-
)
|
|
92
|
+
)
|
|
81
93
|
response = Message(
|
|
82
94
|
handshake=True,
|
|
83
95
|
sender=node.relay_public_key,
|
|
84
96
|
content=int(node.config["incoming_port"]).to_bytes(2, "big", signed=False),
|
|
85
97
|
)
|
|
86
|
-
|
|
98
|
+
enqueue_outgoing(
|
|
99
|
+
node,
|
|
100
|
+
peer_address,
|
|
101
|
+
message=response,
|
|
102
|
+
difficulty=peer.difficulty,
|
|
103
|
+
)
|
|
87
104
|
_queue_handshake_ping(peer, peer_address)
|
|
88
105
|
return True
|