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