Node Module#

class isek.node.node_v2.Node(host: str = 'localhost', port: int = 8080, p2p: bool = False, p2p_server_port: int = 9000, node_id: str | None = None, protocol: Protocol | None = None, registry: Registry | None = None, adapter: Adapter | None = None, **kwargs: Any)[source]#

Bases: ABC

build_server(daemon: bool = False) None[source]#
send_message(receiver_node_id: str, message: str, retry_count: int = 3)[source]#
stop_server() None[source]#
class isek.node.registry.Registry[source]#

Bases: ABC

abstractmethod deregister_node(node_id: str)[source]#
abstractmethod get_available_nodes() dict[source]#
abstractmethod lease_refresh(node_id: str)[source]#
abstractmethod register_node(node_id: str, host: str, port: int, metadata: Dict[str, str] | None = None)[source]#
class isek.node.default_registry.DefaultRegistry[source]#

Bases: Registry

deregister_node(node_id: str)[source]#
get_available_nodes() dict[source]#
lease_refresh(node_id: str)[source]#
register_node(node_id: str, host: str, port: int, metadata: Dict[str, str] | None = None)[source]#
class isek.node.etcd_registry.EtcdRegistry(host: str | None = None, port: int | None = None, parent_node_id: str | None = 'root', etcd_client: Etcd3Client | None = None, ttl: int = 30)[source]#

Bases: Registry

deregister_node(node_id: str)[source]#
get_available_nodes() Dict[str, dict][source]#
lease_refresh(node_id: str)[source]#
register_node(node_id: str, host: str, port: int, metadata: Dict[str, str] | None = None)[source]#
class isek.node.isek_center_registry.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.