🔴 unaiverse.networking.node.profile
What this module does 🔴
Defines NodeProfile, which collects and validates a node's static, dynamic, and CV metadata (OS, memory, peer ID, identity fields) for the peer-to-peer network.
profile
¶
█████ █████ ██████ █████ █████ █████ █████ ██████████ ███████████ █████████ ██████████
░░███ ░░███ ░░██████ ░░███ ░░███ ░░███ ░░███ ░░███░░░░░█░░███░░░░░███ ███░░░░░███░░███░░░░░█
░███ ░███ ░███░███ ░███ ██████ ░███ ░███ ░███ ░███ █ ░ ░███ ░███ ░███ ░░░ ░███ █ ░
░███ ░███ ░███░░███░███ ░░░░░███ ░███ ░███ ░███ ░██████ ░██████████ ░░█████████ ░██████
░███ ░███ ░███ ░░██████ ███████ ░███ ░░███ ███ ░███░░█ ░███░░░░░███ ░░░░░░░░███ ░███░░█
░███ ░███ ░███ ░░█████ ███░░███ ░███ ░░░█████░ ░███ ░ █ ░███ ░███ ███ ░███ ░███ ░ █
░░████████ █████ ░░█████░░████████ █████ ░░███ ██████████ █████ █████░░█████████ ██████████
░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░░░░░
A Collectionless AI Project (https://collectionless.ai)
Registration/Login: https://unaiverse.io
Code Repositories: https://github.com/collectionlessai/
Main Developers: Stefano Melacci (Project Leader), Christian Di Maio, Tommaso Guidi
NodeProfile
¶
Profile information for a UNaIVERSE node, combining static identity, dynamic system state, and CV data.
A NodeProfile is the canonical representation of a peer's identity and runtime
state within the UNaIVERSE network. It is created when a node starts up and is
continuously updated to reflect changes in system resources, network addresses, and
connection status. Profiles are exchanged between peers during the handshake phase
so that each side knows the other's capabilities and identity.
The profile is divided into three sections:
static: fields that do not change during a node's lifetime (node ID, type, owner identity, creation date, and so on).dynamic: fields that may change at runtime (IP address, peer addresses, memory usage, connection state, world summary, and similar).cv: a chronologically sorted list of achievement/badge dictionaries awarded to this node by worlds it has visited.
Internally all data is stored in a single nested dictionary accessible via
get_static_profile, get_dynamic_profile, get_cv, and get_all_profile.
Only the keys defined in the internal template are accepted for the dynamic section;
unknown keys are silently dropped unless they start with tmp_, in which case they
are stored as temporary fields.
Note
Use from_dict to reconstruct a NodeProfile from a serialized dictionary
received over the network rather than constructing it directly.
Initialize a NodeProfile from static, dynamic, and CV data.
The CV list is sorted by last_edit_utc and each entry's keys are
canonically ordered before storage, so that the resulting JSON serialization
produces a deterministic hash regardless of insertion order. After all data is
merged, _fill_missing_specs is called to populate any dynamic fields that
were not supplied by querying the local system (OS, CPU, memory, and public IP).
The dynamic section uses an internal template that defines every accepted key.
Only keys present in that template (or prefixed with tmp_) are stored; all
other keys in dynamic are silently ignored. Nested dictionaries under
connections and world_summary are merged key by key using the same
filter: only None-valued template slots are filled from the provided data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
static
|
dict
|
Dictionary of static profile fields. Must be non-empty and must
contain all required keys ( |
required |
dynamic
|
dict
|
Dictionary of dynamic profile fields. Only keys that match the
internal template (or start with |
required |
cv
|
list
|
List of CV entry dictionaries. Each entry must contain a
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If any required static key (other than |
Source code in unaiverse/networking/node/profile.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
update_cv
¶
Replace the stored CV data with a new list of CV entries.
The provided list is stored as-is, without re-sorting or re-ordering keys.
Callers that need canonical ordering should pre-sort the list or pass data
through __init__ instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_cv
|
list[dict]
|
The replacement CV data as a list of dictionaries. Each dictionary represents one CV entry (for example a badge record). Passing an empty list effectively clears the CV. |
required |
Source code in unaiverse/networking/node/profile.py
from_dict
classmethod
¶
from_dict(combined_data: dict) -> NodeProfile
Create a NodeProfile instance from a combined profile dictionary.
This is the preferred way to reconstruct a NodeProfile from data received
over the network or loaded from persistent storage. The dictionary layout must
mirror the internal _profile_data structure: a top-level "static" key,
a "dynamic" key, and a "cv" key. The __init__ constructor is
invoked with those three sub-dictionaries, so all the same validation and
auto-fill logic applies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
combined_data
|
dict
|
A dictionary representing the full node profile. Expected
to contain a |
required |
Returns:
| Type | Description |
|---|---|
NodeProfile
|
A new |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If any other required static key is missing (raised by
|
Source code in unaiverse/networking/node/profile.py
check_and_update_specs
¶
Check current system specs and merge them into the dynamic profile.
When update_only is True (the default), all fields returned by
_get_current_specs are unconditionally written into the dynamic profile
via a dictionary merge. This is the fast path used during periodic refreshes.
When update_only is False, each spec field is compared against its
stored value. Floats are compared with a tolerance of 1e-6 to avoid
spurious updates from minor fluctuations. If any field changed, the full set
of current specs is merged into the dynamic profile and a summary of the
changes is printed via log.print. This mode is more expensive but lets
callers react only when hardware state actually changes.
In both modes, _profile_last_updated is set to the current UTC time upon
completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_only
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Source code in unaiverse/networking/node/profile.py
get_static_profile
¶
Return the static portion of the profile data.
The returned dictionary is the live internal object, not a copy. Callers should not mutate it directly to avoid corrupting the profile state.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing static profile fields such as |
dict
|
|
dict
|
|
dict
|
|
dict
|
|
Source code in unaiverse/networking/node/profile.py
get_dynamic_profile
¶
Return the dynamic portion of the profile data.
The returned dictionary is the live internal object, not a copy. Several
callers (for example set_addresses_in_profile in World) mutate the
private_peer_addresses list inside this dictionary in place, relying on
the fact that the same list object is shared by reference. Do not replace the
dictionary or any of its nested container values.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing dynamic profile fields including |
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
and peer lists), |
Source code in unaiverse/networking/node/profile.py
get_cv
¶
Return the CV data associated with this node profile.
The returned list is the live internal object. Its initial order reflects the
sort applied in __init__ (chronological by last_edit_utc), but
subsequent calls to update_cv may replace it with an unsorted list.
Returns:
| Type | Description |
|---|---|
list
|
A list of CV entry dictionaries. Each dictionary represents one awarded |
list
|
badge or achievement record, sorted by |
list
|
time. |
Source code in unaiverse/networking/node/profile.py
get_all_profile
¶
Return the complete profile data dictionary.
Provides a single-call way to retrieve the full profile for serialization (for example, before JSON-encoding a profile to send over the network). The returned object is the live internal dictionary; callers should not mutate it directly.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary with three top-level keys: |
dict
|
|
dict
|
and |
Source code in unaiverse/networking/node/profile.py
mark_change_in_connections
¶
Flag that a connection change has occurred since the last reset.
Sets the internal _connections_updated flag to True. The node
infrastructure reads this flag (via connections_changed) to decide
whether the dynamic profile must be re-broadcast to the network. Call
unmark_change_in_connections to clear the flag after broadcasting.
Source code in unaiverse/networking/node/profile.py
unmark_change_in_connections
¶
Clear the connection-change flag.
Sets the internal _connections_updated flag back to False. Typically
called by the node infrastructure after the updated dynamic profile has been
successfully broadcast, so the flag does not trigger another unnecessary
broadcast at the next scheduled instant. See mark_change_in_connections.
Source code in unaiverse/networking/node/profile.py
connections_changed
¶
Return whether a connection change has been recorded since the last reset.
Reads the internal _connections_updated flag that is set by
mark_change_in_connections and cleared by unmark_change_in_connections.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
call to |
Source code in unaiverse/networking/node/profile.py
verify_cv_hash
¶
Verify a CV hash against the hash computed from the stored CV data.
The stored CV list is JSON-serialized and hashed with BLAKE2b (16-byte digest)
to produce a compact, collision-resistant fingerprint. The provided hash is then
compared to this computed value. Because __init__ sorts the CV entries and
canonically orders their keys, the same list always produces the same hash
regardless of insertion order, making this comparison safe across different
serialization paths.
This method is used during the peer handshake to confirm that both sides hold identical CV data without transmitting the full list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cv_hash
|
str
|
The hexadecimal hash string received from the remote peer or stored externally, to be compared against the locally computed hash. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A two-element tuple |
tuple[str, str]
|
is |
tuple[bool, tuple[str, str]]
|
|