pub struct ProductOSController {
pub on_presence_lost: Option<Arc<dyn Fn() + Send + Sync>>,
/* private fields */
}Expand description
Main controller for managing a distributed command and control system.
ProductOSController is the primary interface for coordinating multiple
Product OS server instances. It handles node discovery, service management,
secure communication, and workload distribution.
§Examples
use product_os_command_control::ProductOSController;
use product_os_command_control::CommandControl;
use product_os_security::certificates::Certificates;
let config = CommandControl::default();
let certs = Certificates::new_self_signed(
vec![("CN".to_string(), "localhost".to_string())],
None, None, None, None, None,
);
let controller = ProductOSController::new(
config,
certs,
None,
#[cfg(feature = "relational_store")]
None,
);Fields§
§on_presence_lost: Option<Arc<dyn Fn() + Send + Sync>>Optional callback invoked when the node loses its presence on the remote registry.
If None, std::process::exit(8) is called instead (the legacy behavior).
Implementations§
Source§impl ProductOSController
impl ProductOSController
Sourcepub fn new(
command_control: CommandControl,
certificates: Certificates,
key_value_store: Option<Arc<ProductOSKeyValueStore>>,
) -> Self
pub fn new( command_control: CommandControl, certificates: Certificates, key_value_store: Option<Arc<ProductOSKeyValueStore>>, ) -> Self
Creates a new ProductOSController instance.
Initializes the command and control system with the provided configuration, certificates, and optional data stores.
§Arguments
command_control- Command and control configurationcertificates- TLS/SSL certificates for secure communicationkey_value_store- Optional key-value store for node registry persistencerelational_store- Optional relational database store (requiresrelational_storefeature)
Sourcepub fn get_registry(&self) -> &Registry
pub fn get_registry(&self) -> &Registry
Returns a reference to the internal node registry.
The registry contains information about all known nodes in the cluster, including their capabilities, services, and features.
Sourcepub async fn discover_nodes(&mut self)
pub async fn discover_nodes(&mut self)
Discovers remote nodes and adds their certificates to the trusted set.
Sourcepub fn get_max_servers(&self) -> u8
pub fn get_max_servers(&self) -> u8
Returns the maximum number of servers this controller manages.
Sourcepub fn upsert_node_local(&mut self, identifier: String, node: Node)
pub fn upsert_node_local(&mut self, identifier: String, node: Node)
Inserts or updates a node in the local registry.
Sourcepub fn get_certificates(&self) -> Vec<&[u8]>
pub fn get_certificates(&self) -> Vec<&[u8]>
Returns the TLS certificate chain as a vector of byte slices.
Sourcepub fn get_private_key(&self) -> &[u8] ⓘ
pub fn get_private_key(&self) -> &[u8] ⓘ
Returns the TLS private key as a byte slice.
Sourcepub fn get_certificates_and_private_key(&self) -> Certificates
pub fn get_certificates_and_private_key(&self) -> Certificates
Returns the full certificates and private key structure.
Sourcepub fn validate_certificate(&self, certificate: &[u8]) -> bool
pub fn validate_certificate(&self, certificate: &[u8]) -> bool
Validates that the given certificate matches one of the controller’s certificates.
Sourcepub fn validate_verify_tag<T>(
&self,
query: Option<&BTreeMap<String, String>>,
payload: Option<T>,
headers: Option<&BTreeMap<String, String>>,
verify_identifier: &str,
verify_tag: &str,
) -> boolwhere
T: AsByteVector,
pub fn validate_verify_tag<T>(
&self,
query: Option<&BTreeMap<String, String>>,
payload: Option<T>,
headers: Option<&BTreeMap<String, String>>,
verify_identifier: &str,
verify_tag: &str,
) -> boolwhere
T: AsByteVector,
Validates a verification tag against the stored key for the given identifier.
Sourcepub fn authenticate_command_control<T>(
&self,
query: Option<&BTreeMap<String, String>>,
payload: Option<T>,
headers: Option<&BTreeMap<String, String>>,
verify_identifier: Option<&str>,
verify_tag: Option<&str>,
) -> Result<bool, CommandControlAuthenticateError>where
T: AsByteVector,
pub fn authenticate_command_control<T>(
&self,
query: Option<&BTreeMap<String, String>>,
payload: Option<T>,
headers: Option<&BTreeMap<String, String>>,
verify_identifier: Option<&str>,
verify_tag: Option<&str>,
) -> Result<bool, CommandControlAuthenticateError>where
T: AsByteVector,
Authenticates a command and control request using the verify identifier and tag.
Returns Ok(true) if authentication succeeds, or an error if the keys are invalid.
Sourcepub fn search_and_prepare_command(
&self,
query: BTreeMap<&str, &str>,
module: String,
instruction: String,
data: Option<Value>,
) -> Result<Command, ProductOSRequestError>
pub fn search_and_prepare_command( &self, query: BTreeMap<&str, &str>, module: String, instruction: String, data: Option<Value>, ) -> Result<Command, ProductOSRequestError>
Searches for a node matching the query and prepares a command to send to it.
Sourcepub fn find_and_prepare_command(
&self,
key: &str,
manager: &str,
instruction: String,
data: Option<Value>,
) -> Result<Command, ProductOSRequestError>
pub fn find_and_prepare_command( &self, key: &str, manager: &str, instruction: String, data: Option<Value>, ) -> Result<Command, ProductOSRequestError>
Finds a node with a matching manager key/kind and prepares a command.
Sourcepub fn find_any_and_prepare_command(
&self,
capability: &str,
manager: &str,
instruction: &str,
data: Option<Value>,
) -> Result<Command, ProductOSRequestError>
pub fn find_any_and_prepare_command( &self, capability: &str, manager: &str, instruction: &str, data: Option<Value>, ) -> Result<Command, ProductOSRequestError>
Finds a node with a matching capability and prepares a command.
Sourcepub async fn find_kind_and_prepare_command(
&self,
kind: &str,
manager: &str,
instruction: &str,
data: Option<Value>,
) -> Result<Command, ProductOSRequestError>
👎Deprecated since 0.0.28: Use find_kind_and_prepare_command_sync instead; this method is not actually async
pub async fn find_kind_and_prepare_command( &self, kind: &str, manager: &str, instruction: &str, data: Option<Value>, ) -> Result<Command, ProductOSRequestError>
Use find_kind_and_prepare_command_sync instead; this method is not actually async
Finds a node with a matching kind and prepares a command.
Note: despite the async signature, this method performs no asynchronous work.
A non-async version is available as find_kind_and_prepare_command_sync.
Sourcepub fn find_kind_and_prepare_command_sync(
&self,
kind: &str,
manager: &str,
instruction: &str,
data: Option<Value>,
) -> Result<Command, ProductOSRequestError>
pub fn find_kind_and_prepare_command_sync( &self, kind: &str, manager: &str, instruction: &str, data: Option<Value>, ) -> Result<Command, ProductOSRequestError>
Finds a node with a matching kind and prepares a command (non-async).
Sourcepub fn search_and_prepare_ask(
&self,
query: BTreeMap<&str, &str>,
path: &str,
data: Option<Value>,
headers: BTreeMap<String, String>,
params: BTreeMap<String, String>,
method: Method,
) -> Result<Ask, ProductOSRequestError>
pub fn search_and_prepare_ask( &self, query: BTreeMap<&str, &str>, path: &str, data: Option<Value>, headers: BTreeMap<String, String>, params: BTreeMap<String, String>, method: Method, ) -> Result<Ask, ProductOSRequestError>
Searches for a node matching the query and prepares an HTTP request to send to it.
Sourcepub async fn find_feature_and_ask(
&self,
feature: &str,
path: &str,
data: &Option<Value>,
headers: &BTreeMap<String, String>,
params: &BTreeMap<String, String>,
method: &Method,
) -> Result<ProductOSResponse<BodyBytes>, ProductOSRequestError>
pub async fn find_feature_and_ask( &self, feature: &str, path: &str, data: &Option<Value>, headers: &BTreeMap<String, String>, params: &BTreeMap<String, String>, method: &Method, ) -> Result<ProductOSResponse<BodyBytes>, ProductOSRequestError>
Finds a node with the specified feature and sends an HTTP request to it.
Sourcepub fn find_feature_and_prepare_ask(
&self,
feature: &str,
path: &str,
data: Option<Value>,
headers: BTreeMap<String, String>,
params: BTreeMap<String, String>,
method: Method,
) -> Result<Ask, ProductOSRequestError>
pub fn find_feature_and_prepare_ask( &self, feature: &str, path: &str, data: Option<Value>, headers: BTreeMap<String, String>, params: BTreeMap<String, String>, method: Method, ) -> Result<Ask, ProductOSRequestError>
Finds a node with the specified feature and prepares an HTTP request to send to it.
Sourcepub fn get_configuration(&self) -> CommandControl
pub fn get_configuration(&self) -> CommandControl
Returns a clone of the command and control configuration.
Sourcepub fn get_key(&self, identifier: &str) -> Option<Vec<u8>>
pub fn get_key(&self, identifier: &str) -> Option<Vec<u8>>
Returns the cryptographic key associated with the given node identifier.
Sourcepub fn create_key_session(&mut self) -> (String, [u8; 32])
pub fn create_key_session(&mut self) -> (String, [u8; 32])
Creates a new Diffie-Hellman key session and returns the session ID and public key.
Sourcepub fn generate_key(
&mut self,
session_identifier: &str,
remote_public_key: &[u8],
association: String,
remote_session_identifier: Option<String>,
)
pub fn generate_key( &mut self, session_identifier: &str, remote_public_key: &[u8], association: String, remote_session_identifier: Option<String>, )
Generates a shared key from a Diffie-Hellman exchange session.
Sourcepub fn get_key_value_store(&mut self) -> Arc<ProductOSKeyValueStore>
pub fn get_key_value_store(&mut self) -> Arc<ProductOSKeyValueStore>
Returns the key-value store.
Sourcepub async fn add_feature(
&mut self,
feature: Arc<dyn Feature>,
base_path: String,
router: &mut ProductOSRouter,
)
pub async fn add_feature( &mut self, feature: Arc<dyn Feature>, base_path: String, router: &mut ProductOSRouter, )
Registers a feature on the local node and updates the router.
Sourcepub async fn add_feature_mut(
&mut self,
feature: Arc<Mutex<dyn Feature>>,
base_path: String,
router: &mut ProductOSRouter,
)
pub async fn add_feature_mut( &mut self, feature: Arc<Mutex<dyn Feature>>, base_path: String, router: &mut ProductOSRouter, )
Registers a mutable feature on the local node and updates the router.
Sourcepub async fn remove_feature(&mut self, identifier: &str)
pub async fn remove_feature(&mut self, identifier: &str)
Removes a feature from the local node.
Sourcepub async fn add_service(&mut self, service: Arc<dyn Service>)
pub async fn add_service(&mut self, service: Arc<dyn Service>)
Registers a service on the local node.
Sourcepub async fn add_service_mut(&mut self, service: Arc<Mutex<dyn Service>>)
pub async fn add_service_mut(&mut self, service: Arc<Mutex<dyn Service>>)
Registers a mutable service on the local node.
Sourcepub async fn set_service_active(&mut self, identifier: String, status: bool)
pub async fn set_service_active(&mut self, identifier: String, status: bool)
Sets the active status of a service on the local node.
Sourcepub async fn remove_service(&mut self, identifier: &str)
pub async fn remove_service(&mut self, identifier: &str)
Removes a service from the local node.
Sourcepub async fn remove_inactive_services(&mut self, query: BTreeMap<&str, &str>)
pub async fn remove_inactive_services(&mut self, query: BTreeMap<&str, &str>)
Removes all inactive services matching the query.
Sourcepub async fn start_services(&mut self) -> Result<(), ()>
pub async fn start_services(&mut self) -> Result<(), ()>
Starts all registered services on the local node.