fix up url handling
This commit is contained in:
parent
2f6237c5e6
commit
feb54071f2
@ -90,13 +90,13 @@ struct DialInfoTCP {
|
||||
}
|
||||
|
||||
struct DialInfoWS {
|
||||
fqdn @0 :Text;
|
||||
host @0 :Text;
|
||||
port @1 :UInt16;
|
||||
path @2 :Text;
|
||||
}
|
||||
|
||||
struct DialInfoWSS {
|
||||
fqdn @0 :Text;
|
||||
host @0 :Text;
|
||||
port @1 :UInt16;
|
||||
path @2 :Text;
|
||||
}
|
||||
|
@ -869,10 +869,10 @@ impl Network {
|
||||
)
|
||||
};
|
||||
trace!("WS: starting listener at {:?}", listen_address);
|
||||
let (fqdn, port) = split_port(&listen_address)
|
||||
let (host, port) = split_port(&listen_address)
|
||||
.map_err(|_| "invalid WS listen address, port not specified correctly".to_owned())?;
|
||||
let port = port.ok_or_else(|| "port must be specified for WS address".to_owned())?;
|
||||
let _ = self
|
||||
let addresses = self
|
||||
.start_tcp_listener(
|
||||
listen_address.clone(),
|
||||
false,
|
||||
@ -881,11 +881,12 @@ impl Network {
|
||||
.await?;
|
||||
trace!("WS: listener started");
|
||||
|
||||
// websockets must use FQDN
|
||||
routing_table.register_local_dial_info(
|
||||
DialInfo::ws(fqdn.clone(), port, path.clone()),
|
||||
DialInfoOrigin::Static,
|
||||
);
|
||||
let mut dial_infos: Vec<DialInfo> = Vec::new();
|
||||
for (a, p) in addresses {
|
||||
let di = DialInfo::ws(a.address_string(), p, path.clone());
|
||||
dial_infos.push(di.clone());
|
||||
routing_table.register_local_dial_info(di, DialInfoOrigin::Static);
|
||||
}
|
||||
|
||||
// Add static public dialinfo if it's configured
|
||||
if let Some(url) = url.as_ref() {
|
||||
@ -922,7 +923,7 @@ impl Network {
|
||||
)
|
||||
};
|
||||
trace!("WSS: starting listener at {}", listen_address);
|
||||
let (fqdn, port) = split_port(&listen_address)
|
||||
let (host, port) = split_port(&listen_address)
|
||||
.map_err(|_| "invalid WSS listen address, port not specified correctly".to_owned())?;
|
||||
let port = port.ok_or_else(|| "port must be specified for WSS address".to_owned())?;
|
||||
|
||||
@ -935,11 +936,17 @@ impl Network {
|
||||
.await?;
|
||||
trace!("WSS: listener started");
|
||||
|
||||
// websockets must use FQDN
|
||||
routing_table.register_local_dial_info(
|
||||
DialInfo::wss(fqdn.clone(), port, path.clone()),
|
||||
DialInfoOrigin::Static,
|
||||
);
|
||||
// NOTE: No local dial info for WSS, as there is no way to connect to a local dialinfo via TLS
|
||||
// If the hostname is specified, it is the public dialinfo via the URL. If no hostname
|
||||
// is specified, then TLS won't validate, so no local dialinfo is possible.
|
||||
// This is not the case with unencrypted websockets, which can be specified solely by an IP address
|
||||
//
|
||||
// let mut dial_infos: Vec<DialInfo> = Vec::new();
|
||||
// for (a, p) in addresses {
|
||||
// let di = DialInfo::wss(a.address_string(), p, path.clone());
|
||||
// dial_infos.push(di.clone());
|
||||
// routing_table.register_local_dial_info(di, DialInfoOrigin::Static);
|
||||
// }
|
||||
|
||||
// Add static public dialinfo if it's configured
|
||||
if let Some(url) = url.as_ref() {
|
||||
|
@ -237,14 +237,14 @@ impl WebsocketProtocolHandler {
|
||||
DialInfo::WS(di) => (
|
||||
false,
|
||||
di.path.clone(),
|
||||
di.fqdn.clone(),
|
||||
di.host.clone(),
|
||||
di.port,
|
||||
ProtocolType::WS,
|
||||
),
|
||||
DialInfo::WSS(di) => (
|
||||
true,
|
||||
di.path.clone(),
|
||||
di.fqdn.clone(),
|
||||
di.host.clone(),
|
||||
di.port,
|
||||
ProtocolType::WSS,
|
||||
),
|
||||
|
@ -92,8 +92,8 @@ impl WebsocketProtocolHandler {
|
||||
) -> Result<NetworkConnection, String> {
|
||||
let url = dial_info.to_url_string(None);
|
||||
let (tls, host, port, protocol_type) = match dial_info {
|
||||
DialInfo::WS(ws) => (false, ws.fqdn.clone(), ws.port, ProtocolType::WS),
|
||||
DialInfo::WSS(wss) => (true, wss.fqdn.clone(), wss.port, ProtocolType::WSS),
|
||||
DialInfo::WS(ws) => (false, ws.host.clone(), ws.port, ProtocolType::WS),
|
||||
DialInfo::WSS(wss) => (true, wss.host.clone(), wss.port, ProtocolType::WSS),
|
||||
_ => return Err("wrong protocol for WebsocketProtocolHandler".to_owned()),
|
||||
};
|
||||
|
||||
|
@ -22,24 +22,24 @@ pub fn decode_dial_info(reader: &veilid_capnp::dial_info::Reader) -> Result<Dial
|
||||
Ok(DialInfo::tcp(address, port))
|
||||
}
|
||||
Ok(veilid_capnp::dial_info::Which::Ws(Ok(ws))) => {
|
||||
let fqdn = ws
|
||||
.get_fqdn()
|
||||
.map_err(map_error_internal!("missing ws fqdn"))?;
|
||||
let host = ws
|
||||
.get_host()
|
||||
.map_err(map_error_internal!("missing ws host"))?;
|
||||
let port = ws.get_port();
|
||||
let path = ws
|
||||
.get_path()
|
||||
.map_err(map_error_internal!("missing ws path"))?;
|
||||
Ok(DialInfo::ws(fqdn.to_owned(), port, path.to_owned()))
|
||||
Ok(DialInfo::ws(host.to_owned(), port, path.to_owned()))
|
||||
}
|
||||
Ok(veilid_capnp::dial_info::Which::Wss(Ok(wss))) => {
|
||||
let fqdn = wss
|
||||
.get_fqdn()
|
||||
.map_err(map_error_internal!("missing wss fqdn"))?;
|
||||
let host = wss
|
||||
.get_host()
|
||||
.map_err(map_error_internal!("missing wss host"))?;
|
||||
let port = wss.get_port();
|
||||
let path = wss
|
||||
.get_path()
|
||||
.map_err(map_error_internal!("missing wss path"))?;
|
||||
Ok(DialInfo::wss(fqdn.to_owned(), port, path.to_owned()))
|
||||
Ok(DialInfo::wss(host.to_owned(), port, path.to_owned()))
|
||||
}
|
||||
_ => Err(rpc_error_internal("invalid dial info type")),
|
||||
}
|
||||
@ -62,13 +62,13 @@ pub fn encode_dial_info(
|
||||
}
|
||||
DialInfo::WS(ws) => {
|
||||
let mut di_ws_builder = builder.reborrow().init_ws();
|
||||
let mut fqdnb = di_ws_builder.reborrow().init_fqdn(
|
||||
ws.fqdn
|
||||
let mut hostb = di_ws_builder.reborrow().init_host(
|
||||
ws.host
|
||||
.len()
|
||||
.try_into()
|
||||
.map_err(map_error_internal!("fqdn too long"))?,
|
||||
.map_err(map_error_internal!("host too long"))?,
|
||||
);
|
||||
fqdnb.push_str(ws.fqdn.as_str());
|
||||
hostb.push_str(ws.host.as_str());
|
||||
di_ws_builder.set_port(ws.port);
|
||||
let mut pathb = di_ws_builder.init_path(
|
||||
ws.path
|
||||
@ -80,13 +80,13 @@ pub fn encode_dial_info(
|
||||
}
|
||||
DialInfo::WSS(wss) => {
|
||||
let mut di_wss_builder = builder.reborrow().init_wss();
|
||||
let mut fqdnb = di_wss_builder.reborrow().init_fqdn(
|
||||
wss.fqdn
|
||||
let mut hostb = di_wss_builder.reborrow().init_host(
|
||||
wss.host
|
||||
.len()
|
||||
.try_into()
|
||||
.map_err(map_error_internal!("fqdn too long"))?,
|
||||
.map_err(map_error_internal!("host too long"))?,
|
||||
);
|
||||
fqdnb.push_str(wss.fqdn.as_str());
|
||||
hostb.push_str(wss.host.as_str());
|
||||
di_wss_builder.set_port(wss.port);
|
||||
let mut pathb = di_wss_builder.init_path(
|
||||
wss.path
|
||||
|
@ -175,14 +175,14 @@ pub struct DialInfoTCP {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq)]
|
||||
pub struct DialInfoWS {
|
||||
pub fqdn: String,
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq)]
|
||||
pub struct DialInfoWSS {
|
||||
pub fqdn: String,
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub path: String,
|
||||
}
|
||||
@ -220,11 +220,11 @@ impl DialInfo {
|
||||
}
|
||||
Self::TCP(DialInfoTCP { address, port })
|
||||
}
|
||||
pub fn ws(fqdn: String, port: u16, path: String) -> Self {
|
||||
Self::WS(DialInfoWS { fqdn, port, path })
|
||||
pub fn ws(host: String, port: u16, path: String) -> Self {
|
||||
Self::WS(DialInfoWS { host, port, path })
|
||||
}
|
||||
pub fn wss(fqdn: String, port: u16, path: String) -> Self {
|
||||
Self::WSS(DialInfoWSS { fqdn, port, path })
|
||||
pub fn wss(host: String, port: u16, path: String) -> Self {
|
||||
Self::WSS(DialInfoWSS { host, port, path })
|
||||
}
|
||||
pub fn protocol_type(&self) -> ProtocolType {
|
||||
match self {
|
||||
@ -294,14 +294,14 @@ impl DialInfo {
|
||||
|
||||
pub fn try_ws(&self) -> Option<String> {
|
||||
match self {
|
||||
Self::WS(v) => Some(v.fqdn.clone()),
|
||||
Self::WS(v) => Some(v.host.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_wss(&self) -> Option<String> {
|
||||
match self {
|
||||
Self::WSS(v) => Some(v.fqdn.clone()),
|
||||
Self::WSS(v) => Some(v.host.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -310,24 +310,24 @@ impl DialInfo {
|
||||
match self {
|
||||
Self::UDP(di) => di.address.address_string(),
|
||||
Self::TCP(di) => di.address.address_string(),
|
||||
Self::WS(di) => di.fqdn.clone(),
|
||||
Self::WSS(di) => di.fqdn.clone(),
|
||||
Self::WS(di) => di.host.clone(),
|
||||
Self::WSS(di) => di.host.clone(),
|
||||
}
|
||||
}
|
||||
pub fn address_string_with_port(&self) -> String {
|
||||
match self {
|
||||
Self::UDP(di) => di.address.address_string_with_port(di.port),
|
||||
Self::TCP(di) => di.address.address_string_with_port(di.port),
|
||||
Self::WS(di) => format!("{}:{}", di.fqdn.clone(), di.port),
|
||||
Self::WSS(di) => format!("{}:{}", di.fqdn.clone(), di.port),
|
||||
Self::WS(di) => format!("{}:{}", di.host.clone(), di.port),
|
||||
Self::WSS(di) => format!("{}:{}", di.host.clone(), di.port),
|
||||
}
|
||||
}
|
||||
pub fn all_but_path(&self) -> String {
|
||||
match self {
|
||||
Self::UDP(di) => format!("udp://{}", di.address.address_string_with_port(di.port)),
|
||||
Self::TCP(di) => format!("tcp://{}", di.address.address_string_with_port(di.port)),
|
||||
Self::WS(di) => format!("ws://{}:{}", di.fqdn.clone(), di.port),
|
||||
Self::WSS(di) => format!("wss://{}:{}", di.fqdn.clone(), di.port),
|
||||
Self::WS(di) => format!("ws://{}:{}", di.host.clone(), di.port),
|
||||
Self::WSS(di) => format!("wss://{}:{}", di.host.clone(), di.port),
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,14 +350,14 @@ impl DialInfo {
|
||||
Self::WS(di) => format!(
|
||||
"ws://{}{}:{}{}",
|
||||
user_string,
|
||||
di.fqdn.clone(),
|
||||
di.host.clone(),
|
||||
di.port,
|
||||
prepend_slash(di.path.clone())
|
||||
),
|
||||
Self::WSS(di) => format!(
|
||||
"wss://{}{}:{}{}",
|
||||
user_string,
|
||||
di.fqdn.clone(),
|
||||
di.host.clone(),
|
||||
di.port,
|
||||
prepend_slash(di.path.clone())
|
||||
),
|
||||
@ -376,16 +376,16 @@ impl DialInfo {
|
||||
}
|
||||
Self::WS(di) => {
|
||||
let addr: IpAddr = di
|
||||
.fqdn
|
||||
.host
|
||||
.parse()
|
||||
.map_err(|e| format!("Failed to parse WS fqdn: {}", e))?;
|
||||
.map_err(|e| format!("Failed to parse WS host '{}': {}", di.host, e))?;
|
||||
Ok(addr)
|
||||
}
|
||||
Self::WSS(di) => {
|
||||
let addr: IpAddr = di
|
||||
.fqdn
|
||||
.host
|
||||
.parse()
|
||||
.map_err(|e| format!("Failed to parse WSS fqdn: {}", e))?;
|
||||
.map_err(|e| format!("Failed to parse WSS host '{}': {}", di.host, e))?;
|
||||
Ok(addr)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user