pub fn connection_sequence(bytecount_interval: u32) -> Vec<OvpnCommand>Expand description
The standard startup sequence that most management clients send after connecting.
This is the pattern used by node-openvpn and other clients: enable
log streaming, request the PID, start byte-count notifications, and
release the hold so OpenVPN begins connecting.
§Arguments
bytecount_interval— seconds between>BYTECOUNT:notifications (pass0to skip enabling byte counts).
§Initial state
The sequence uses StreamMode::OnAll for log and state, which
enables real-time streaming and dumps the history buffer as a
multi-line response. The state history response contains the current
state as its last entry — use
parse_current_state
to extract it. Do not rely solely on >STATE: notifications for
the initial state, because notifications only fire on transitions.
§Pitfall: log on all at high verbosity
At verb 4 or above, the log history dump from log on all can be
extremely large (OpenVPN logs its own management I/O at that level).
The dump may grow faster than it drains, effectively hanging the
multi-line accumulation. Prefer StreamMode::On (no history) at
high verbosity, or use StreamMode::Recent to cap the dump size.
§Notification interleaving
The commands produce a mix of multi-line and single-line responses.
Asynchronous notifications (>STATE:, >LOG:, >HOLD:, etc.) can
arrive between any command and its response. The codec handles this
transparently, but consumers reading from the stream must handle
OvpnMessage::Notification variants at any point.
§Examples
use openvpn_mgmt_codec::command::connection_sequence;
use openvpn_mgmt_codec::OvpnCommand;
let cmds = connection_sequence(5);
assert!(cmds.iter().any(|cmd| matches!(cmd, OvpnCommand::HoldRelease)));To send these over a framed connection:
use tokio::net::TcpStream;
use tokio_util::codec::Framed;
use futures::SinkExt;
use openvpn_mgmt_codec::{OvpnCodec, OvpnCommand};
use openvpn_mgmt_codec::command::connection_sequence;
let stream = TcpStream::connect("127.0.0.1:7505").await?;
let mut framed = Framed::new(stream, OvpnCodec::new());
for cmd in connection_sequence(5) {
framed.send(cmd).await?;
}