Expand description
High-level management client with notification dispatch. High-level management client with notification dispatch.
ManagementClient wraps a Framed<T, OvpnCodec> transport and splits
the multiplexed stream into two independent channels:
- Command methods (
version,status,hold_release, etc.) send a command and return its response directly. - Notifications are forwarded to a
tokio::sync::broadcastchannel that any number of subscribers can consume independently.
§Example
use tokio::net::TcpStream;
use tokio::sync::broadcast;
use tokio_util::codec::Framed;
use openvpn_mgmt_codec::{Notification, OvpnCodec, StatusFormat};
use openvpn_mgmt_codec::client::ManagementClient;
let stream = TcpStream::connect("127.0.0.1:7505").await?;
let framed = Framed::new(stream, OvpnCodec::new());
// Create the broadcast channel — you control capacity and lifetime.
let (notification_tx, _) = broadcast::channel::<Notification>(256);
let mut rx = notification_tx.subscribe();
let mut client = ManagementClient::new(framed, notification_tx);
// Spawn a notification consumer
tokio::spawn(async move {
while let Ok(notif) = rx.recv().await {
println!("notification: {notif:?}");
}
});
// Commands return their response directly
let version = client.version().await?;
println!("management version: {:?}", version.management_version());
let status = client.status(StatusFormat::V3).await?;
client.hold_release().await?;§Extracting the transport
Call ManagementClient::into_framed to recover the underlying
Framed<T, OvpnCodec> when you need raw access or want to drop back
to the low-level stream API.
Structs§
- Management
Client - A high-level client for the OpenVPN management interface.
Enums§
- Client
Error - Errors returned by
ManagementClientcommand methods.