mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-14 00:43:28 +00:00
Fixed CoT queue during armatak connection to the TAK Server, running soft as butter
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
use log::info;
|
||||
use rustls::{ClientConnection, StreamOwned};
|
||||
use std::io::Write;
|
||||
use std::net::TcpStream;
|
||||
use std::net::{SocketAddr, TcpStream, ToSocketAddrs};
|
||||
use std::time::Duration;
|
||||
|
||||
use super::config::ConnectionConfig;
|
||||
use super::tls::{connect_mtls, enroll_and_connect};
|
||||
|
||||
const TCP_CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
const SOCKET_IO_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
pub enum TransportStream {
|
||||
Plain(TcpStream),
|
||||
Mtls(StreamOwned<ClientConnection, TcpStream>),
|
||||
@@ -25,11 +30,34 @@ impl TransportStream {
|
||||
}
|
||||
}
|
||||
|
||||
fn connect_plain(address: &str) -> Result<TransportStream, String> {
|
||||
let socket_addr: SocketAddr = address
|
||||
.to_socket_addrs()
|
||||
.map_err(|e| format!("failed to resolve {}: {}", address, e))?
|
||||
.next()
|
||||
.ok_or_else(|| format!("failed to resolve {}: no socket addresses returned", address))?;
|
||||
|
||||
info!(
|
||||
"Opening plain TCP connection to {} (resolved={}) with timeout {:?}",
|
||||
address, socket_addr, TCP_CONNECT_TIMEOUT
|
||||
);
|
||||
|
||||
let stream = TcpStream::connect_timeout(&socket_addr, TCP_CONNECT_TIMEOUT)
|
||||
.map_err(|e| format!("failed to connect to {}: {}", address, e))?;
|
||||
stream
|
||||
.set_read_timeout(Some(SOCKET_IO_TIMEOUT))
|
||||
.map_err(|e| format!("failed to set read timeout on {}: {}", address, e))?;
|
||||
stream
|
||||
.set_write_timeout(Some(SOCKET_IO_TIMEOUT))
|
||||
.map_err(|e| format!("failed to set write timeout on {}: {}", address, e))?;
|
||||
|
||||
Ok(TransportStream::Plain(stream))
|
||||
}
|
||||
|
||||
pub fn connect_stream(config: &ConnectionConfig) -> Result<TransportStream, String> {
|
||||
info!("connect_stream invoked for {}", config.describe());
|
||||
match config {
|
||||
ConnectionConfig::Plain { address } => TcpStream::connect(address)
|
||||
.map(TransportStream::Plain)
|
||||
.map_err(|e| format!("failed to connect to {}: {}", address, e)),
|
||||
ConnectionConfig::Plain { address } => connect_plain(address),
|
||||
ConnectionConfig::Mtls {
|
||||
address,
|
||||
server_name,
|
||||
|
||||
Reference in New Issue
Block a user