unaiverse.networking.node.profile¶
A node describes itself to the UNaIVERSE server and to its peers with a profile. The profile has three parts with different lifetimes. The static part comes from the account and the server (the id, the name and the type of the node, its owner, its access lists). The dynamic part describes the running process (the machine, the network addresses, the streams, the current connections) and changes while the node runs. The CV is the list of badges that worlds assigned to the node.
NodeProfile holds the three parts in one dictionary. Every node builds its own profile in the constructor of Node from the static part fetched from the server, the peer ids and addresses of its two network identities and its CV. It offers the whole profile to every peer in the handshake of a Session. On the other side, the peer turns the offered dictionary back into a NodeProfile with NodeProfile.from_dict. The profiles of the peers that an agent knows are the values of agent.all_agents and the profile of the world that an agent is in is agent.world_profile (see Agents).
Application code mostly reads profiles. A world reads the profile of a joining agent in assign_role (see Worlds) and an action reads the profile of a peer to decide how to treat it:
profile = agent.all_agents[peer_id]
static = profile.get_static_profile()
dynamic = profile.get_dynamic_profile()
print(f"{static['nickname']}/{static['node_name']}", dynamic["connections"]["role"])
The three parts¶
The static part has these fields. A field that the server does not send stays None. The fields that the server sends beyond this list are kept as they arrive.
| Field | Type | Meaning |
|---|---|---|
node_id |
str |
The id of the node. Required. |
node_type |
str |
"agent", "world" or the type of a human node. Required. |
node_name |
str |
The name of the node on its account. Required. |
node_description |
str |
The description written by the owner. |
created_utc |
str |
The creation time of the node on the server. |
nickname |
str |
The nickname of the owner account. It is the owner part of owner/name. |
name, surname, title |
str |
The public identity of the owner. |
organization, email |
str |
Legacy fields that current servers no longer send. |
max_nr_connections |
int |
The maximum number of connections of the node. It sizes the connection pools. |
allowed_node_ids |
list of str |
The node ids that may connect. The list exists only when the owner restricted access. |
world_masters_node_ids |
list of str |
World nodes only. The node ids that join as world masters. |
certified |
bool |
Whether the node is certified. |
inspector_node_id |
str |
The node id of the inspector that may attach to this node. |
location_method |
str |
"manual" (the default) or a method that derives the location from the public IP address. |
location |
dict |
The location written by the owner (default {}). |
The dynamic part has these fields.
| Field | Type | Meaning |
|---|---|---|
timestamp |
str |
The ISO 8601 UTC time at which the machine fields were read. |
os |
str |
The platform string of the machine (platform.platform()). |
cpu_cores, logical_cpus |
int |
The physical and logical CPU cores. |
memory_gb, memory_avail, memory_used |
float |
Total, available and used memory in GB. |
public_ip_address |
str |
The public IP address. It is 'Public IP not available.' when no lookup service answered. |
guessed_location |
dict |
The static location when location_method is "manual". Otherwise the result of a geolocation lookup of the public IP address. |
peer_id, peer_addresses |
str, list of str |
The identity and the addresses of the node on the public network. |
private_peer_id, private_peer_addresses |
str, list of str |
The identity and the addresses of the node on the world network. |
is_relay |
bool |
True for a world node whose world network is publicly reachable and therefore offers a relay to its members. |
max_message_size |
int |
The largest message in bytes that the node accepts (0 means no limit). |
accept_files, max_file_size |
bool, int |
Whether the node accepts files and the largest file in bytes (0 means no limit). |
proc_inputs, proc_outputs, streams |
list | The descriptions of the processor inputs, the processor outputs and the streams of the hosted entity. |
connections |
dict |
public_agents, world_agents and world_masters (lists of dicts that describe the connected peers), world_peer_id (the world the node is in) and role (the role name of the node). |
world_summary |
dict |
World nodes only. world_title, the lists world_agents and world_masters of the confirmed members, their counts world_agents_count, world_masters_count, total_agents and the badge and stream counters. |
hidden |
bool or None |
The visibility asked for in the constructor of Node. None leaves the visibility on the server untouched. |
tmp_<option> |
any | The options of a join request (see Node.run_async). They exist only in a profile offered to a world. |
The CV is a list of dicts, one per badge, each with at least the key last_edit_utc.
NodeProfile
¶
Source code in unaiverse/networking/node/profile.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 | |
Holds the static part, the dynamic part and the CV of one node.
| Argument | Type | Default | Meaning |
|---|---|---|---|
static |
dict |
required | The static fields. Every key is copied (the keys outside the table above included). node_id, node_type and node_name are required. |
dynamic |
dict |
required | The dynamic fields. The constructor copies the keys of the table above and every key that starts with tmp_. The nested keys of connections and world_summary are copied one by one. Other keys are discarded. |
cv |
list[dict] |
required | The CV. The constructor sorts the entries by last_edit_utc and the keys of each entry alphabetically because the server computes the CV hash in this order. |
When location and location_method are missing, the constructor writes location = {} and location_method = "manual" into the static dict of the caller. That dict therefore changes too. It then fills the dynamic fields that describe the machine (timestamp, os, the CPU and memory fields, public_ip_address and guessed_location) and are still None. The values come from the machine that runs the code.
Lookups on every construction
The filling runs whenever at least one dynamic field is None. Almost every profile has such a field and the profiles of remote peers built with from_dict are no exception. The filling reads the public IP address from external services that it tries in order with a timeout of 5 seconds each (api.ipify.org, icanhazip.com, ident.me, checkip.amazonaws.com). When location_method is not "manual" it also asks ip-api.com for the location of that address. These are blocking HTTP requests. A remote profile that lacks a machine field receives the value of the local machine.
Raises ValueError when static is empty or lacks one of the three required keys and KeyError when an entry of cv lacks last_edit_utc.
from_dict
classmethod
¶
from_dict(combined_data: dict) -> NodeProfile
Source code in unaiverse/networking/node/profile.py
Builds a NodeProfile from a dictionary in the shape that get_all_profile returns. Profiles travel in this shape between nodes and inside the world grant.
| Argument | Type | Default | Meaning |
|---|---|---|---|
combined_data |
dict |
required | A dict with the keys static, dynamic and cv. |
Returns a new NodeProfile. The constructor that builds it also runs the lookups described above.
Raises ValueError when static is missing or its node_id is missing or empty and KeyError when dynamic or cv is missing. The constructor raises the errors listed above.
The node calls it on every profile that a peer offers in a handshake, on the world profile carried by a grant and on the profile kept by a Session that resumes. An offered profile that fails to parse makes the node reject the peer.
get_static_profile
¶
Source code in unaiverse/networking/node/profile.py
Returns the static part as a dict. The method returns the dict stored inside the profile and not a copy. Changing it therefore changes the profile.
get_dynamic_profile
¶
Source code in unaiverse/networking/node/profile.py
Returns the stored dynamic part as a dict and not a copy. The node relies on this to update its addresses and its connections in place.
get_cv
¶
Returns the CV as the stored list of dicts. After the constructor the list is sorted by last_edit_utc. After update_cv it is in the order that the caller passed.
get_all_profile
¶
Returns the stored dict with the keys static, dynamic and cv. json.dumps of this dict is what the node offers to its peers and what a world puts in its grants.
update_cv
¶
Replaces the CV with new_cv (list[dict]) exactly as given. Unlike the constructor it sorts neither the entries nor their keys. Returns None.
The node calls it when a world announces new badges with a GET_CV_FROM_ROOT message. The node then downloads its CV from the server, stores it with this method and requests a new token that carries the new CV hash.
check_and_update_specs
¶
Source code in unaiverse/networking/node/profile.py
Reads the machine fields again (timestamp, os, the CPU and memory fields, public_ip_address, guessed_location) with the same lookups as the constructor and merges them into the dynamic part.
| Argument | Type | Default | Meaning |
|---|---|---|---|
update_only |
bool |
True |
True merges the fresh values without comparing them. False compares each field with the stored value (floats with a tolerance of 1e-6, timestamp ignored), merges only when something changed and prints the changes. |
Returns True when update_only=False and at least one field changed. In every other case it returns False. No code of the SDK calls this method.
mark_change_in_connections
¶
Raises the flag that says that the dynamic part changed since it was last sent to the server. Returns None. The node raises it when its connections, its addresses or the summary of its world change. The flag is a plain boolean and many changes before the next send count as one.
unmark_change_in_connections
¶
Clears the flag of mark_change_in_connections. Returns None. The node clears it right before it sends the dynamic part to the server.
connections_changed
¶
Returns the flag of mark_change_in_connections as a bool. The network task of the node reads it and sends the dynamic part to the server when it is True and at least 10 seconds (Custom.SEND_DYNAMIC_PROFILE_EVERY) have passed since the previous send.
verify_cv_hash
¶
Source code in unaiverse/networking/node/profile.py
Checks that the stored CV is the one that the server attested.
| Argument | Type | Default | Meaning |
|---|---|---|---|
cv_hash |
str |
required | The expected digest, usually the cv_hash claim of the node token of the peer. |
The method computes the 16-byte BLAKE2b digest of json.dumps(cv) (default separators, with the list and its dicts in the order in which they are stored) and compares its hex form with cv_hash.
Returns the tuple (match, (cv_hash, computed_hash)) where match is a bool. The second element carries both digests for diagnostics.
The decision policy of a node calls it on every offered profile whose token was verified. A mismatch means that the offered CV differs from the attested one and the peer is rejected with CV_HASH_MISMATCH.