Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Aug 25, 2024
1 parent d6e6340 commit 7717091
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/drivers/tcp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ use tokio::net::{TcpListener, TcpStream};
use tokio::sync::{broadcast, Mutex};
use tracing::*;

use crate::drivers::{Driver, DriverInfo};
use crate::drivers::{Driver, DriverExt, DriverInfo};

pub struct TcpServer {
pub local_addr: String,
}

impl TcpServer {
#[instrument(level = "debug")]
pub fn new(local_addr: &str) -> Self {
Self {
local_addr: local_addr.to_string(),
}
}
}

impl TcpServer {
#[instrument(level = "debug")]
pub fn new(local_addr: &str) -> Self {
Expand Down Expand Up @@ -83,3 +92,30 @@ impl Driver for TcpServer {
}
}
}

pub struct TcpServerExt;
impl DriverExt for TcpServerExt {
fn valid_schemes(&self) -> Vec<String> {
vec!["tcps".to_string(), "tcpserver".to_string()]
}

fn url_from_legacy(&self, legacy_entry: crate::drivers::DriverDescriptionLegacy) -> url::Url {
let scheme = legacy_entry.typ.get_default_scheme();
let mut ip = std::net::Ipv4Addr::UNSPECIFIED.to_string();
let mut port: u16 = 0;
if let Ok(p) = legacy_entry.arg1.parse::<u16>() {
port = p;
} else {
ip = legacy_entry.arg2.clone().unwrap(); // todo: error here
};

// Deal with error here
url::Url::parse(&format!("{scheme}://{ip}:{port}")).unwrap()
}

fn create_endpoint_from_url(&self, url: &url::Url) -> Option<Arc<dyn Driver>> {
let host = url.host_str().unwrap();
let port = url.port().unwrap();
return Some(Arc::new(TcpServer::new(&format!("{host}:{port}"))));
}
}

0 comments on commit 7717091

Please sign in to comment.