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

@@ -7,7 +7,6 @@ use embassy::context::{DiagnosticContext, InstallContext, SetupContext};
use embassy::disk::fsck::RepairStrategy;
use embassy::disk::main::DEFAULT_PASSWORD;
use embassy::disk::REPAIR_DISK_PATH;
use embassy::hostname::get_current_ip;
use embassy::init::STANDBY_MODE_PATH;
use embassy::net::embassy_service_http_server::EmbassyServiceHTTPServer;
#[cfg(feature = "avahi")]
@@ -32,8 +31,7 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
let ctx = InstallContext::init(cfg_path).await?;
let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?;
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr;
let embassy_fqdn: ResourceFqdn = "pureos.local".parse()?;
let localhost_fqdn = ResourceFqdn::LocalHost;
@@ -74,8 +72,7 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
let ctx = SetupContext::init(cfg_path).await?;
let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?;
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr;
let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?;
let localhost_fqdn = ResourceFqdn::LocalHost;
@@ -203,8 +200,7 @@ async fn inner_main(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Error
)
.await?;
let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?;
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr;
let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?;
let localhost_fqdn = ResourceFqdn::LocalHost;

View File

@@ -187,8 +187,7 @@ fn main() {
)
.await?;
let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?;
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr;
let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?;
let diag_ui_handler = diag_ui_file_router(ctx.clone()).await?;

View File

@@ -21,7 +21,6 @@ use crate::ResultExt;
#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CliContextConfig {
pub bind_rpc: Option<SocketAddr>,
pub host: Option<Url>,
#[serde(deserialize_with = "crate::util::serde::deserialize_from_str_opt")]
#[serde(default)]
@@ -81,11 +80,7 @@ impl CliContext {
} else if let Some(host) = base.host {
host
} else {
format!(
"http://{}",
base.bind_rpc.unwrap_or(([127, 0, 0, 1], 80).into())
)
.parse()?
format!("http://localhost").parse()?
};
let proxy = if let Some(proxy) = matches.value_of("proxy") {
Some(proxy.parse()?)

View File

@@ -15,7 +15,6 @@ use crate::Error;
#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DiagnosticContextConfig {
pub ethernet_interface: String,
pub datadir: Option<PathBuf>,
}
impl DiagnosticContextConfig {
@@ -44,7 +43,6 @@ impl DiagnosticContextConfig {
}
pub struct DiagnosticContextSeed {
pub ethernet_interface: String,
pub datadir: PathBuf,
pub shutdown: Sender<Option<Shutdown>>,
pub error: Arc<RpcError>,
@@ -68,7 +66,6 @@ impl DiagnosticContext {
let (shutdown, _) = tokio::sync::broadcast::channel(1);
Ok(Self(Arc::new(DiagnosticContextSeed {
ethernet_interface: cfg.ethernet_interface.clone(),
datadir: cfg.datadir().to_owned(),
shutdown,
disk_guid,

View File

@@ -34,7 +34,6 @@ pub struct SetupResult {
#[serde(rename_all = "kebab-case")]
pub struct SetupContextConfig {
pub os_partitions: OsPartitionInfo,
pub ethernet_interface: String,
pub migration_batch_rows: Option<usize>,
pub migration_prefetch_rows: Option<usize>,
pub datadir: Option<PathBuf>,
@@ -65,7 +64,6 @@ impl SetupContextConfig {
pub struct SetupContextSeed {
pub os_partitions: OsPartitionInfo,
pub ethernet_interface: String,
pub config_path: Option<PathBuf>,
pub migration_batch_rows: usize,
pub migration_prefetch_rows: usize,
@@ -96,7 +94,6 @@ impl SetupContext {
let datadir = cfg.datadir().to_owned();
Ok(Self(Arc::new(SetupContextSeed {
os_partitions: cfg.os_partitions,
ethernet_interface: cfg.ethernet_interface,
config_path: path.as_ref().map(|p| p.as_ref().to_owned()),
migration_batch_rows: cfg.migration_batch_rows.unwrap_or(25000),
migration_prefetch_rows: cfg.migration_prefetch_rows.unwrap_or(100_000),

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: _,

View File

@@ -1,29 +0,0 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/install;
index index.html index.htm index.nginx-debian.html;
server_name _;
proxy_buffering off;
proxy_request_buffering off;
proxy_socket_keepalive on;
proxy_http_version 1.1;
proxy_read_timeout 1800;
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
location /rpc/ {
proxy_pass http://127.0.0.1:5959/;
}
location / {
try_files $uri $uri/ =404;
}
}