changing ip addr type (#1950)

* changing ip addr type

* fixing parse fn and improving proxy fn

* Update net_controller.rs

* remove extra fn call
This commit is contained in:
Stephen Chavez
2022-11-16 23:00:28 +00:00
committed by Aiden McClelland
parent 8b6eac3c1c
commit 373e11495d
9 changed files with 30 additions and 108 deletions

View File

@@ -115,12 +115,11 @@ impl NetController {
async fn setup_embassy_http_ui_handle(rpc_ctx: RpcContext) -> Result<(), Error> {
let host_name = rpc_ctx.net_controller.proxy.get_hostname().await;
let ip = get_current_ip(rpc_ctx.ethernet_interface.to_owned()).await?;
let embassy_tor_addr = get_embassyd_tor_addr(rpc_ctx.clone()).await?;
let embassy_tor_fqdn: ResourceFqdn = embassy_tor_addr.parse()?;
let host_name_fqdn: ResourceFqdn = host_name.parse()?;
let ip_fqdn: ResourceFqdn = ip.parse()?;
let ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr;
let localhost_fqdn = ResourceFqdn::LocalHost;

View File

@@ -29,7 +29,7 @@ pub fn host_addr_fqdn(req: &Request<Body>) -> Result<ResourceFqdn, Error> {
#[derive(Eq, PartialEq, PartialOrd, Ord, Debug, Clone)]
pub enum ResourceFqdn {
IpAddr(IpAddr),
IpAddr,
Uri {
full_uri: String,
root: String,
@@ -41,9 +41,6 @@ pub enum ResourceFqdn {
impl fmt::Display for ResourceFqdn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ResourceFqdn::IpAddr(ip) => {
write!(f, "{}", ip)
}
ResourceFqdn::Uri {
full_uri,
root: _,
@@ -52,6 +49,7 @@ impl fmt::Display for ResourceFqdn {
write!(f, "{}", full_uri)
}
ResourceFqdn::LocalHost => write!(f, "localhost"),
ResourceFqdn::IpAddr => write!(f, "ip-address"),
}
}
}
@@ -77,12 +75,12 @@ impl FromStr for ResourceFqdn {
type Err = Error;
fn from_str(input: &str) -> Result<ResourceFqdn, Self::Err> {
if input == "localhost" {
return Ok(ResourceFqdn::LocalHost);
if input.parse::<IpAddr>().is_ok() {
return Ok(ResourceFqdn::IpAddr);
}
if let Ok(ip) = input.parse::<IpAddr>() {
return Ok(ResourceFqdn::IpAddr(ip));
if input == "localhost" {
return Ok(ResourceFqdn::LocalHost);
}
let hostname_split: Vec<&str> = input.split('.').collect();

View File

@@ -103,52 +103,21 @@ impl ProxyController {
// Note: only after client received an empty body with STATUS_OK can the
// connection be upgraded, so we can't return a response inside
// `on_upgrade` future.
match host_addr_fqdn(&req) {
Ok(host) => {
tokio::task::spawn(async move {
match hyper::upgrade::on(req).await {
Ok(upgraded) => match host {
ResourceFqdn::IpAddr(ip) => {
if let Err(e) = Self::tunnel(upgraded, ip.to_string()).await {
error!("server io error: {}", e);
};
}
ResourceFqdn::Uri {
full_uri,
root: _,
tld: _,
} => {
if let Err(e) =
Self::tunnel(upgraded, full_uri.to_string()).await
{
error!("server io error: {}", e);
};
}
ResourceFqdn::LocalHost => {
if let Err(e) =
Self::tunnel(upgraded, "localhost".to_string()).await
{
error!("server io error: {}", e);
};
}
},
Err(e) => error!("upgrade error: {}", e),
tokio::task::spawn(async move {
let addr = req.uri().clone();
match hyper::upgrade::on(req).await {
Ok(upgraded) => {
if let Err(e) = Self::tunnel(upgraded, addr.to_string()).await {
error!("server io error: {}", e);
}
});
Ok(Response::new(Body::empty()))
}
Err(e) => error!("upgrade error: {}", e),
}
Err(e) => {
let err_txt = format!("CONNECT host is not socket addr: {:?}", &req.uri());
let mut resp = Response::new(Body::from(format!(
"CONNECT must be to a socket address: {}: {}",
err_txt, e
)));
*resp.status_mut() = http::StatusCode::BAD_REQUEST;
});
Ok(resp)
}
}
Ok(Response::new(Body::empty()))
} else {
client.request(req).await
}
@@ -221,10 +190,11 @@ impl ProxyControllerInner {
pkg_id: PackageId,
) -> Result<(), Error> {
let package_cert = match resource_fqdn.clone() {
ResourceFqdn::IpAddr(ip) => {
self.ssl_manager
.certificate_for(&ip.to_string(), &pkg_id)
.await?
ResourceFqdn::IpAddr => {
return Err(Error::new(
eyre!("ssl not supported for ip addresses"),
crate::ErrorKind::Network,
))
}
ResourceFqdn::Uri {
full_uri: _,