Node#

class isek.node.EtcdRegistry(host: str | None = None, port: int | None = None, parent_node_id: str = 'root', etcd_client: Etcd3Client | None = None, ttl: int = 30)[source]#

Bases: Registry

An implementation of the Registry interface that uses etcd as a distributed key-value store for service discovery.

Nodes register themselves with their connection information and metadata. The registry uses leases to automatically deregister nodes if they fail to refresh their lease, providing a degree of fault tolerance. Node information is signed to ensure integrity and authenticity, although the current signature verification logic in __verify_signature appears to verify a signature it just created, rather than a signature from a remote node.

deregister_node(node_id: str) None[source]#

Deregisters a node from the etcd service registry.

This involves deleting the node's entry from etcd and revoking its lease.

Note

Similar to lease_refresh, the __verify_signature call here checks the integrity of the data based on this registry's signature.

Parameters:

node_id (str) -- The ID of the node to deregister.

Raises:
  • ValueError -- If the node is not found or signature verification fails.

  • Exception -- If etcd operations (delete, lease revoke) fail.

get_available_nodes() Dict[str, Dict[str, Any]][source]#

Retrieves information about all currently registered and available nodes.

It fetches all entries under the configured parent_node_id prefix in etcd.

Returns:

A dictionary where keys are node IDs and values are dictionaries containing the 'node_info' (host, port, metadata, public_key) for each available node.

Return type:

Dict[str, NodeInfo]

lease_refresh(node_id: str) None[source]#

Refreshes the lease for a registered node.

This method should be called periodically by the node (or on its behalf) to prevent its registration from expiring.

Note

The current __verify_signature call within this method appears to re-verify a signature generated by this same registry instance, which might not be the intended security check if nodes have their own identities. If the goal is for the node to prove its identity to refresh, it would need to provide a signature that this registry verifies against the node's stored public key.

Parameters:

node_id (str) -- The ID of the node whose lease needs to be refreshed.

Raises:
  • KeyError -- If the node_id is not found in the local lease cache.

  • ValueError -- If signature verification fails (as per current __verify_signature logic).

  • Exception -- If the etcd lease refresh operation fails.

register_node(node_id: str, host: str, port: int, metadata: Dict[str, str] | None = None) None[source]#

Registers a node with the etcd service registry.

A lease is created for the node, and its information (including a public key derived from this registry's signing key) is stored in etcd. The node's information is signed by this registry instance.

Warning

The public key stored (vk_base64) is derived from this EtcdRegistry instance's private key (self.sk). This means the registry is asserting the identity of the node by signing its details. If nodes are meant to have their own identities, they should generate their own key pairs and provide their public key for registration.

Parameters:
  • node_id (str) -- The unique identifier for the node.

  • host (str) -- The hostname or IP address where the node can be reached.

  • port (int) -- The port number on which the node is listening.

  • metadata (Optional[NodeMetadata]) -- Optional dictionary of key-value pairs providing additional information about the node. Defaults to an empty dictionary.

class isek.node.IsekCenterRegistry(host: str = 'localhost', port: int = 8088)[source]#

Bases: Registry

An implementation of the Registry interface that interacts with a centralized "Isek Center" service via HTTP API calls.

This registry delegates node registration, deregistration, lease renewal, and discovery to an external Isek Center. All operations involve sending HTTP requests to predefined endpoints on this central service.

deregister_node(node_id: str) None[source]#

Deregisters a node from the Isek Center.

Sends a POST request with the node_id to the center's /isek_center/deregister endpoint.

Parameters:

node_id (str) -- The ID of the node to deregister.

Raises:
  • RuntimeError -- If the Isek Center returns an error code in its response.

  • requests.exceptions.RequestException -- For network errors or HTTP error statuses.

get_available_nodes() Dict[str, Dict[str, Any]][source]#

Retrieves information about all currently available nodes from the Isek Center.

Sends a GET request to the center's /isek_center/available_nodes endpoint. The expected response structure from Isek Center is a JSON object with a 'data' key, which in turn has an 'available_nodes' key containing the dictionary of nodes.

Returns:

A dictionary where keys are node IDs and values are dictionaries containing the node information (host, port, metadata, etc.) as provided by the Isek Center.

Return type:

Dict[str, NodeInfo]

Raises:
  • RuntimeError -- If the Isek Center returns an error code or an unexpected data structure.

  • requests.exceptions.RequestException -- For network errors or HTTP error statuses.

lease_refresh(node_id: str) None[source]#

Refreshes the lease for a registered node with the Isek Center.

Sends a POST request with the node_id to the center's /isek_center/renew endpoint.

Parameters:

node_id (str) -- The ID of the node whose lease needs to be refreshed.

Raises:
  • RuntimeError -- If the Isek Center returns an error code in its response.

  • requests.exceptions.RequestException -- For network errors or HTTP error statuses.

register_node(node_id: str, host: str, port: int, metadata: Dict[str, str] | None = None) None[source]#

Registers a node with the Isek Center.

Sends a POST request with node information to the center's /isek_center/register endpoint.

Parameters:
  • node_id (str) -- The unique identifier for the node.

  • host (str) -- The hostname or IP address where the node can be reached.

  • port (int) -- The port number on which the node is listening.

  • metadata (Optional[NodeMetadata]) -- Optional dictionary of key-value pairs providing additional information about the node. Defaults to an empty dictionary.

Raises:
  • RuntimeError -- If the Isek Center returns an error code in its response.

  • requests.exceptions.RequestException -- For network errors or HTTP error statuses.