break everything
This commit is contained in:
@@ -57,14 +57,14 @@ fn get_safety_selection(text: &str, rss: RouteSpecStore) -> Option<SafetySelecti
|
||||
if text.len() != 0 && &text[0..1] == "-" {
|
||||
// Unsafe
|
||||
let text = &text[1..];
|
||||
let seq = get_sequencing(text).unwrap_or(Sequencing::NoPreference);
|
||||
let seq = get_sequencing(text).unwrap_or_default();
|
||||
Some(SafetySelection::Unsafe(seq))
|
||||
} else {
|
||||
// Safe
|
||||
let mut preferred_route = None;
|
||||
let mut hop_count = 2;
|
||||
let mut stability = Stability::LowLatency;
|
||||
let mut sequencing = Sequencing::NoPreference;
|
||||
let mut stability = Stability::default();
|
||||
let mut sequencing = Sequencing::default();
|
||||
for x in text.split(",") {
|
||||
let x = x.trim();
|
||||
if let Some(pr) = get_route_id(rss.clone())(x) {
|
||||
@@ -134,7 +134,7 @@ fn get_destination(routing_table: RoutingTable) -> impl FnOnce(&str) -> Option<D
|
||||
};
|
||||
Some(Destination::private_route(
|
||||
private_route,
|
||||
ss.unwrap_or(SafetySelection::Unsafe(Sequencing::NoPreference)),
|
||||
ss.unwrap_or(SafetySelection::Unsafe(Sequencing::default())),
|
||||
))
|
||||
} else {
|
||||
let (text, mods) = text
|
||||
@@ -585,8 +585,8 @@ impl VeilidAPI {
|
||||
};
|
||||
|
||||
let mut ai = 1;
|
||||
let mut sequencing = Sequencing::NoPreference;
|
||||
let mut stability = Stability::LowLatency;
|
||||
let mut sequencing = Sequencing::default();
|
||||
let mut stability = Stability::default();
|
||||
let mut hop_count = default_route_hop_count;
|
||||
let mut directions = DirectionSet::all();
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ macro_rules! apibail_internal {
|
||||
|
||||
#[allow(unused_macros)]
|
||||
#[macro_export]
|
||||
macro_rules! apibail_parse {
|
||||
macro_rules! apibail_parse_error {
|
||||
($x:expr, $y:expr) => {
|
||||
return Err(VeilidAPIError::parse_error($x, $y))
|
||||
};
|
||||
@@ -563,6 +563,12 @@ pub enum Sequencing {
|
||||
EnsureOrdered,
|
||||
}
|
||||
|
||||
impl Default for Sequencing {
|
||||
fn default() -> Self {
|
||||
Self::NoPreference
|
||||
}
|
||||
}
|
||||
|
||||
// Ordering here matters, >= is used to check strength of stability requirement
|
||||
#[derive(
|
||||
Copy,
|
||||
@@ -585,6 +591,12 @@ pub enum Stability {
|
||||
Reliable,
|
||||
}
|
||||
|
||||
impl Default for Stability {
|
||||
fn default() -> Self {
|
||||
Self::LowLatency
|
||||
}
|
||||
}
|
||||
|
||||
/// The choice of safety route to include in compiled routes
|
||||
#[derive(
|
||||
Copy,
|
||||
@@ -1543,10 +1555,7 @@ impl FromStr for DialInfo {
|
||||
VeilidAPIError::parse_error(format!("unable to split WS url: {}", e), &url)
|
||||
})?;
|
||||
if split_url.scheme != "ws" || !url.starts_with("ws://") {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"incorrect scheme for WS dialinfo",
|
||||
url,
|
||||
));
|
||||
apibail_parse_error!("incorrect scheme for WS dialinfo", url);
|
||||
}
|
||||
let url_port = split_url.port.unwrap_or(80u16);
|
||||
|
||||
@@ -1574,10 +1583,7 @@ impl FromStr for DialInfo {
|
||||
VeilidAPIError::parse_error(format!("unable to split WSS url: {}", e), &url)
|
||||
})?;
|
||||
if split_url.scheme != "wss" || !url.starts_with("wss://") {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"incorrect scheme for WSS dialinfo",
|
||||
url,
|
||||
));
|
||||
apibail_parse_error!("incorrect scheme for WSS dialinfo", url);
|
||||
}
|
||||
let url_port = split_url.port.unwrap_or(443u16);
|
||||
|
||||
@@ -1628,24 +1634,18 @@ impl DialInfo {
|
||||
VeilidAPIError::parse_error(format!("unable to split WS url: {}", e), &url)
|
||||
})?;
|
||||
if split_url.scheme != "ws" || !url.starts_with("ws://") {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"incorrect scheme for WS dialinfo",
|
||||
url,
|
||||
));
|
||||
apibail_parse_error!("incorrect scheme for WS dialinfo", url);
|
||||
}
|
||||
let url_port = split_url.port.unwrap_or(80u16);
|
||||
if url_port != socket_address.port() {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"socket address port doesn't match url port",
|
||||
url,
|
||||
));
|
||||
apibail_parse_error!("socket address port doesn't match url port", url);
|
||||
}
|
||||
if let SplitUrlHost::IpAddr(a) = split_url.host {
|
||||
if socket_address.to_ip_addr() != a {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
apibail_parse_error!(
|
||||
format!("request address does not match socket address: {}", a),
|
||||
socket_address,
|
||||
));
|
||||
socket_address
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(Self::WS(DialInfoWS {
|
||||
@@ -1658,23 +1658,17 @@ impl DialInfo {
|
||||
VeilidAPIError::parse_error(format!("unable to split WSS url: {}", e), &url)
|
||||
})?;
|
||||
if split_url.scheme != "wss" || !url.starts_with("wss://") {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"incorrect scheme for WSS dialinfo",
|
||||
url,
|
||||
));
|
||||
apibail_parse_error!("incorrect scheme for WSS dialinfo", url);
|
||||
}
|
||||
let url_port = split_url.port.unwrap_or(443u16);
|
||||
if url_port != socket_address.port() {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"socket address port doesn't match url port",
|
||||
url,
|
||||
));
|
||||
apibail_parse_error!("socket address port doesn't match url port", url);
|
||||
}
|
||||
if !matches!(split_url.host, SplitUrlHost::Hostname(_)) {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
apibail_parse_error!(
|
||||
"WSS url can not use address format, only hostname format",
|
||||
url,
|
||||
));
|
||||
url
|
||||
);
|
||||
}
|
||||
Ok(Self::WSS(DialInfoWSS {
|
||||
socket_address: socket_address.to_canonical(),
|
||||
@@ -1778,10 +1772,7 @@ impl DialInfo {
|
||||
let hostname = hostname.as_ref();
|
||||
|
||||
if short.len() < 2 {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"invalid short url length",
|
||||
short,
|
||||
));
|
||||
apibail_parse_error!("invalid short url length", short);
|
||||
}
|
||||
let url = match &short[0..1] {
|
||||
"U" => {
|
||||
@@ -1797,7 +1788,7 @@ impl DialInfo {
|
||||
format!("wss://{}:{}", hostname, &short[1..])
|
||||
}
|
||||
_ => {
|
||||
return Err(VeilidAPIError::parse_error("invalid short url type", short));
|
||||
apibail_parse_error!("invalid short url type", short);
|
||||
}
|
||||
};
|
||||
Self::try_vec_from_url(url)
|
||||
@@ -1815,10 +1806,7 @@ impl DialInfo {
|
||||
"ws" => split_url.port.unwrap_or(80u16),
|
||||
"wss" => split_url.port.unwrap_or(443u16),
|
||||
_ => {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"Invalid dial info url scheme",
|
||||
split_url.scheme,
|
||||
));
|
||||
apibail_parse_error!("Invalid dial info url scheme", split_url.scheme);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2753,36 +2741,35 @@ impl VeilidAPI {
|
||||
// Private route allocation
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub async fn new_default_private_route(&self) -> Result<(DHTKey, Vec<u8>), VeilidAPIError> {
|
||||
let config = self.config()?;
|
||||
let c = config.get();
|
||||
self.new_private_route(
|
||||
Stability::LowLatency,
|
||||
Sequencing::NoPreference,
|
||||
c.network.rpc.default_route_hop_count.into(),
|
||||
)
|
||||
.await
|
||||
pub async fn new_private_route(&self) -> Result<(DHTKey, Vec<u8>), VeilidAPIError> {
|
||||
self.new_custom_private_route(Stability::default(), Sequencing::default())
|
||||
.await
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub async fn new_private_route(
|
||||
pub async fn new_custom_private_route(
|
||||
&self,
|
||||
stability: Stability,
|
||||
sequencing: Sequencing,
|
||||
hop_count: usize,
|
||||
) -> Result<(DHTKey, Vec<u8>), VeilidAPIError> {
|
||||
let default_route_hop_count: usize = {
|
||||
let config = self.config()?;
|
||||
let c = config.get();
|
||||
c.network.rpc.default_route_hop_count.into()
|
||||
};
|
||||
|
||||
let rss = self.routing_table()?.route_spec_store();
|
||||
let r = rss
|
||||
.allocate_route(
|
||||
stability,
|
||||
sequencing,
|
||||
hop_count,
|
||||
default_route_hop_count,
|
||||
Direction::Inbound.into(),
|
||||
&[],
|
||||
)
|
||||
.map_err(VeilidAPIError::internal)?;
|
||||
let Some(pr_pubkey) = r else {
|
||||
return Err(VeilidAPIError::generic("unable to allocate route"));
|
||||
apibail_generic!("unable to allocate route");
|
||||
};
|
||||
if !rss
|
||||
.test_route(&pr_pubkey)
|
||||
@@ -2790,7 +2777,7 @@ impl VeilidAPI {
|
||||
.map_err(VeilidAPIError::no_connection)?
|
||||
{
|
||||
rss.release_route(&pr_pubkey);
|
||||
return Err(VeilidAPIError::generic("allocated route failed to test"));
|
||||
apibail_generic!("allocated route failed to test");
|
||||
}
|
||||
let private_route = rss
|
||||
.assemble_private_route(&pr_pubkey, Some(true))
|
||||
@@ -2799,12 +2786,37 @@ impl VeilidAPI {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
rss.release_route(&pr_pubkey);
|
||||
return Err(VeilidAPIError::internal(e));
|
||||
apibail_internal!(e);
|
||||
}
|
||||
};
|
||||
|
||||
rss.mark_route_published(&pr_pubkey, true)
|
||||
.map_err(VeilidAPIError::internal)?;
|
||||
|
||||
Ok((pr_pubkey, blob))
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> Result<DHTKey, VeilidAPIError> {
|
||||
let rss = self.routing_table()?.route_spec_store();
|
||||
rss.import_remote_private_route(blob)
|
||||
.map_err(|e| VeilidAPIError::invalid_argument(e, "blob", "private route blob"))
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub fn release_private_route(&self, key: &DHTKey) -> Result<(), VeilidAPIError> {
|
||||
let rss = self.routing_table()?.route_spec_store();
|
||||
if rss.release_route(key) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(VeilidAPIError::invalid_argument(
|
||||
"release_private_route",
|
||||
"key",
|
||||
key,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// App Calls
|
||||
|
||||
|
||||
@@ -39,14 +39,19 @@ impl RoutingContext {
|
||||
api,
|
||||
inner: Arc::new(Mutex::new(RoutingContextInner {})),
|
||||
unlocked_inner: Arc::new(RoutingContextUnlockedInner {
|
||||
safety_selection: SafetySelection::Unsafe(Sequencing::NoPreference),
|
||||
safety_selection: SafetySelection::Unsafe(Sequencing::default()),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_default_privacy(self) -> Result<Self, VeilidAPIError> {
|
||||
pub fn with_privacy(self) -> Result<Self, VeilidAPIError> {
|
||||
self.with_custom_privacy(Stability::default())
|
||||
}
|
||||
|
||||
pub fn with_custom_privacy(self, stability: Stability) -> Result<Self, VeilidAPIError> {
|
||||
let config = self.api.config()?;
|
||||
let c = config.get();
|
||||
|
||||
Ok(Self {
|
||||
api: self.api.clone(),
|
||||
inner: Arc::new(Mutex::new(RoutingContextInner {})),
|
||||
@@ -54,22 +59,13 @@ impl RoutingContext {
|
||||
safety_selection: SafetySelection::Safe(SafetySpec {
|
||||
preferred_route: None,
|
||||
hop_count: c.network.rpc.default_route_hop_count as usize,
|
||||
stability: Stability::LowLatency,
|
||||
sequencing: Sequencing::NoPreference,
|
||||
stability,
|
||||
sequencing: self.sequencing(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
pub fn with_privacy(self, safety_spec: SafetySpec) -> Result<Self, VeilidAPIError> {
|
||||
Ok(Self {
|
||||
api: self.api.clone(),
|
||||
inner: Arc::new(Mutex::new(RoutingContextInner {})),
|
||||
unlocked_inner: Arc::new(RoutingContextUnlockedInner {
|
||||
safety_selection: SafetySelection::Safe(safety_spec),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pub fn with_sequencing(self, sequencing: Sequencing) -> Self {
|
||||
Self {
|
||||
api: self.api.clone(),
|
||||
@@ -87,18 +83,13 @@ impl RoutingContext {
|
||||
}),
|
||||
}
|
||||
}
|
||||
pub fn sequencing(&self) -> Sequencing {
|
||||
|
||||
fn sequencing(&self) -> Sequencing {
|
||||
match self.unlocked_inner.safety_selection {
|
||||
SafetySelection::Unsafe(sequencing) => sequencing,
|
||||
SafetySelection::Safe(safety_spec) => safety_spec.sequencing,
|
||||
}
|
||||
}
|
||||
pub fn safety_spec(&self) -> Option<SafetySpec> {
|
||||
match self.unlocked_inner.safety_selection {
|
||||
SafetySelection::Unsafe(_) => None,
|
||||
SafetySelection::Safe(safety_spec) => Some(safety_spec.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn api(&self) -> VeilidAPI {
|
||||
self.api.clone()
|
||||
|
||||
Reference in New Issue
Block a user