bug fixes
This commit is contained in:
parent
d089612cbb
commit
10a0e3b629
@ -1682,7 +1682,7 @@ impl NetworkManager {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
inconsistent
|
inconsistent
|
||||||
} else {
|
} else if matches!(public_internet_network_class, NetworkClass::OutboundOnly) {
|
||||||
// If we are currently outbound only, we don't have any public dial info
|
// If we are currently outbound only, we don't have any public dial info
|
||||||
// but if we are starting to see consistent socket address from multiple reporting peers
|
// but if we are starting to see consistent socket address from multiple reporting peers
|
||||||
// then we may be become inbound capable, so zap the network class so we can re-detect it and any public dial info
|
// then we may be become inbound capable, so zap the network class so we can re-detect it and any public dial info
|
||||||
@ -1710,6 +1710,10 @@ impl NetworkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
consistent
|
consistent
|
||||||
|
} else {
|
||||||
|
// If we are a webapp we never do this.
|
||||||
|
// If we have invalid network class, then public address detection is already going to happen via the network_class_discovery task
|
||||||
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
if needs_public_address_detection {
|
if needs_public_address_detection {
|
||||||
|
@ -799,12 +799,12 @@ impl RoutingTableInner {
|
|||||||
pub fn transform_to_peer_info(
|
pub fn transform_to_peer_info(
|
||||||
&self,
|
&self,
|
||||||
routing_domain: RoutingDomain,
|
routing_domain: RoutingDomain,
|
||||||
own_peer_info: PeerInfo,
|
own_peer_info: &PeerInfo,
|
||||||
k: DHTKey,
|
k: DHTKey,
|
||||||
v: Option<Arc<BucketEntry>>,
|
v: Option<Arc<BucketEntry>>,
|
||||||
) -> PeerInfo {
|
) -> PeerInfo {
|
||||||
match v {
|
match v {
|
||||||
None => own_peer_info,
|
None => own_peer_info.clone(),
|
||||||
Some(entry) => entry.with(self, |_rti, e| e.make_peer_info(k, routing_domain).unwrap()),
|
Some(entry) => entry.with(self, |_rti, e| e.make_peer_info(k, routing_domain).unwrap()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,18 +92,16 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
// add node information for the requesting node to our routing table
|
// add node information for the requesting node to our routing table
|
||||||
let routing_table = self.routing_table();
|
let routing_table = self.routing_table();
|
||||||
let own_peer_info = routing_table.get_own_peer_info(RoutingDomain::PublicInternet);
|
let Some(own_peer_info) = routing_table.get_own_peer_info(RoutingDomain::PublicInternet) else {
|
||||||
let has_valid_own_node_info = own_peer_info.is_some();
|
// Our own node info is not yet available, drop this request.
|
||||||
|
return Ok(NetworkResult::service_unavailable());
|
||||||
|
};
|
||||||
|
|
||||||
// find N nodes closest to the target node in our routing table
|
// find N nodes closest to the target node in our routing table
|
||||||
|
|
||||||
let filter = Box::new(
|
let filter = Box::new(
|
||||||
move |rti: &RoutingTableInner, _k: DHTKey, v: Option<Arc<BucketEntry>>| {
|
move |rti: &RoutingTableInner, _k: DHTKey, v: Option<Arc<BucketEntry>>| {
|
||||||
rti.filter_has_valid_signed_node_info(
|
rti.filter_has_valid_signed_node_info(RoutingDomain::PublicInternet, true, v)
|
||||||
RoutingDomain::PublicInternet,
|
|
||||||
has_valid_own_node_info,
|
|
||||||
v,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
) as RoutingTableEntryFilter;
|
) as RoutingTableEntryFilter;
|
||||||
let filters = VecDeque::from([filter]);
|
let filters = VecDeque::from([filter]);
|
||||||
@ -113,12 +111,7 @@ impl RPCProcessor {
|
|||||||
filters,
|
filters,
|
||||||
// transform
|
// transform
|
||||||
|rti, k, v| {
|
|rti, k, v| {
|
||||||
rti.transform_to_peer_info(
|
rti.transform_to_peer_info(RoutingDomain::PublicInternet, &own_peer_info, k, v)
|
||||||
RoutingDomain::PublicInternet,
|
|
||||||
own_peer_info.as_ref().unwrap().clone(),
|
|
||||||
k,
|
|
||||||
v,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -541,6 +541,9 @@ impl VeilidAPI {
|
|||||||
NetworkResult::Timeout => {
|
NetworkResult::Timeout => {
|
||||||
return Ok("Timeout".to_owned());
|
return Ok("Timeout".to_owned());
|
||||||
}
|
}
|
||||||
|
NetworkResult::ServiceUnavailable => {
|
||||||
|
return Ok("ServiceUnavailable".to_owned());
|
||||||
|
}
|
||||||
NetworkResult::NoConnection(e) => {
|
NetworkResult::NoConnection(e) => {
|
||||||
return Ok(format!("NoConnection({})", e));
|
return Ok(format!("NoConnection({})", e));
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,14 @@ macro_rules! apibail_timeout {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! apibail_try_again {
|
||||||
|
() => {
|
||||||
|
return Err(VeilidAPIError::try_again())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! apibail_generic {
|
macro_rules! apibail_generic {
|
||||||
@ -95,6 +103,8 @@ pub enum VeilidAPIError {
|
|||||||
AlreadyInitialized,
|
AlreadyInitialized,
|
||||||
#[error("Timeout")]
|
#[error("Timeout")]
|
||||||
Timeout,
|
Timeout,
|
||||||
|
#[error("TryAgain")]
|
||||||
|
TryAgain,
|
||||||
#[error("Shutdown")]
|
#[error("Shutdown")]
|
||||||
Shutdown,
|
Shutdown,
|
||||||
#[error("Key not found: {key}")]
|
#[error("Key not found: {key}")]
|
||||||
@ -131,6 +141,9 @@ impl VeilidAPIError {
|
|||||||
pub fn timeout() -> Self {
|
pub fn timeout() -> Self {
|
||||||
Self::Timeout
|
Self::Timeout
|
||||||
}
|
}
|
||||||
|
pub fn try_again() -> Self {
|
||||||
|
Self::TryAgain
|
||||||
|
}
|
||||||
pub fn shutdown() -> Self {
|
pub fn shutdown() -> Self {
|
||||||
Self::Shutdown
|
Self::Shutdown
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,7 @@ impl RoutingContext {
|
|||||||
let answer = match rpc_processor.rpc_call_app_call(dest, request).await {
|
let answer = match rpc_processor.rpc_call_app_call(dest, request).await {
|
||||||
Ok(NetworkResult::Value(v)) => v,
|
Ok(NetworkResult::Value(v)) => v,
|
||||||
Ok(NetworkResult::Timeout) => apibail_timeout!(),
|
Ok(NetworkResult::Timeout) => apibail_timeout!(),
|
||||||
|
Ok(NetworkResult::ServiceUnavailable) => apibail_try_again!(),
|
||||||
Ok(NetworkResult::NoConnection(e)) | Ok(NetworkResult::AlreadyExists(e)) => {
|
Ok(NetworkResult::NoConnection(e)) | Ok(NetworkResult::AlreadyExists(e)) => {
|
||||||
apibail_no_connection!(e);
|
apibail_no_connection!(e);
|
||||||
}
|
}
|
||||||
@ -181,6 +182,7 @@ impl RoutingContext {
|
|||||||
match rpc_processor.rpc_call_app_message(dest, message).await {
|
match rpc_processor.rpc_call_app_message(dest, message).await {
|
||||||
Ok(NetworkResult::Value(())) => {}
|
Ok(NetworkResult::Value(())) => {}
|
||||||
Ok(NetworkResult::Timeout) => apibail_timeout!(),
|
Ok(NetworkResult::Timeout) => apibail_timeout!(),
|
||||||
|
Ok(NetworkResult::ServiceUnavailable) => apibail_try_again!(),
|
||||||
Ok(NetworkResult::NoConnection(e)) | Ok(NetworkResult::AlreadyExists(e)) => {
|
Ok(NetworkResult::NoConnection(e)) | Ok(NetworkResult::AlreadyExists(e)) => {
|
||||||
apibail_no_connection!(e);
|
apibail_no_connection!(e);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ impl<T, E> NetworkResultResultExt<T, E> for NetworkResult<Result<T, E>> {
|
|||||||
fn into_result_network_result(self) -> Result<NetworkResult<T>, E> {
|
fn into_result_network_result(self) -> Result<NetworkResult<T>, E> {
|
||||||
match self {
|
match self {
|
||||||
NetworkResult::Timeout => Ok(NetworkResult::<T>::Timeout),
|
NetworkResult::Timeout => Ok(NetworkResult::<T>::Timeout),
|
||||||
|
NetworkResult::ServiceUnavailable => Ok(NetworkResult::<T>::ServiceUnavailable),
|
||||||
NetworkResult::NoConnection(e) => Ok(NetworkResult::<T>::NoConnection(e)),
|
NetworkResult::NoConnection(e) => Ok(NetworkResult::<T>::NoConnection(e)),
|
||||||
NetworkResult::AlreadyExists(e) => Ok(NetworkResult::<T>::AlreadyExists(e)),
|
NetworkResult::AlreadyExists(e) => Ok(NetworkResult::<T>::AlreadyExists(e)),
|
||||||
NetworkResult::InvalidMessage(s) => Ok(NetworkResult::<T>::InvalidMessage(s)),
|
NetworkResult::InvalidMessage(s) => Ok(NetworkResult::<T>::InvalidMessage(s)),
|
||||||
@ -160,6 +161,7 @@ impl<T> FoldedNetworkResultExt<T> for io::Result<NetworkResult<T>> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub enum NetworkResult<T> {
|
pub enum NetworkResult<T> {
|
||||||
Timeout,
|
Timeout,
|
||||||
|
ServiceUnavailable,
|
||||||
NoConnection(io::Error),
|
NoConnection(io::Error),
|
||||||
AlreadyExists(io::Error),
|
AlreadyExists(io::Error),
|
||||||
InvalidMessage(String),
|
InvalidMessage(String),
|
||||||
@ -170,6 +172,9 @@ impl<T> NetworkResult<T> {
|
|||||||
pub fn timeout() -> Self {
|
pub fn timeout() -> Self {
|
||||||
Self::Timeout
|
Self::Timeout
|
||||||
}
|
}
|
||||||
|
pub fn service_unavailable() -> Self {
|
||||||
|
Self::ServiceUnavailable
|
||||||
|
}
|
||||||
pub fn no_connection(e: io::Error) -> Self {
|
pub fn no_connection(e: io::Error) -> Self {
|
||||||
Self::NoConnection(e)
|
Self::NoConnection(e)
|
||||||
}
|
}
|
||||||
@ -201,6 +206,7 @@ impl<T> NetworkResult<T> {
|
|||||||
pub fn map<X, F: Fn(T) -> X>(self, f: F) -> NetworkResult<X> {
|
pub fn map<X, F: Fn(T) -> X>(self, f: F) -> NetworkResult<X> {
|
||||||
match self {
|
match self {
|
||||||
Self::Timeout => NetworkResult::<X>::Timeout,
|
Self::Timeout => NetworkResult::<X>::Timeout,
|
||||||
|
Self::ServiceUnavailable => NetworkResult::<X>::ServiceUnavailable,
|
||||||
Self::NoConnection(e) => NetworkResult::<X>::NoConnection(e),
|
Self::NoConnection(e) => NetworkResult::<X>::NoConnection(e),
|
||||||
Self::AlreadyExists(e) => NetworkResult::<X>::AlreadyExists(e),
|
Self::AlreadyExists(e) => NetworkResult::<X>::AlreadyExists(e),
|
||||||
Self::InvalidMessage(s) => NetworkResult::<X>::InvalidMessage(s),
|
Self::InvalidMessage(s) => NetworkResult::<X>::InvalidMessage(s),
|
||||||
@ -210,6 +216,10 @@ impl<T> NetworkResult<T> {
|
|||||||
pub fn into_result(self) -> Result<T, io::Error> {
|
pub fn into_result(self) -> Result<T, io::Error> {
|
||||||
match self {
|
match self {
|
||||||
Self::Timeout => Err(io::Error::new(io::ErrorKind::TimedOut, "Timed out")),
|
Self::Timeout => Err(io::Error::new(io::ErrorKind::TimedOut, "Timed out")),
|
||||||
|
Self::ServiceUnavailable => Err(io::Error::new(
|
||||||
|
io::ErrorKind::NotFound,
|
||||||
|
"Service unavailable",
|
||||||
|
)),
|
||||||
Self::NoConnection(e) => Err(e),
|
Self::NoConnection(e) => Err(e),
|
||||||
Self::AlreadyExists(e) => Err(e),
|
Self::AlreadyExists(e) => Err(e),
|
||||||
Self::InvalidMessage(s) => Err(io::Error::new(
|
Self::InvalidMessage(s) => Err(io::Error::new(
|
||||||
@ -230,21 +240,11 @@ impl<T> From<NetworkResult<T>> for Option<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<T: Clone> Clone for NetworkResult<T> {
|
|
||||||
// fn clone(&self) -> Self {
|
|
||||||
// match self {
|
|
||||||
// Self::Timeout => Self::Timeout,
|
|
||||||
// Self::NoConnection(e) => Self::NoConnection(e.clone()),
|
|
||||||
// Self::InvalidMessage(s) => Self::InvalidMessage(s.clone()),
|
|
||||||
// Self::Value(t) => Self::Value(t.clone()),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl<T: Debug> Debug for NetworkResult<T> {
|
impl<T: Debug> Debug for NetworkResult<T> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Timeout => write!(f, "Timeout"),
|
Self::Timeout => write!(f, "Timeout"),
|
||||||
|
Self::ServiceUnavailable => write!(f, "ServiceUnavailable"),
|
||||||
Self::NoConnection(e) => f.debug_tuple("NoConnection").field(e).finish(),
|
Self::NoConnection(e) => f.debug_tuple("NoConnection").field(e).finish(),
|
||||||
Self::AlreadyExists(e) => f.debug_tuple("AlreadyExists").field(e).finish(),
|
Self::AlreadyExists(e) => f.debug_tuple("AlreadyExists").field(e).finish(),
|
||||||
Self::InvalidMessage(s) => f.debug_tuple("InvalidMessage").field(s).finish(),
|
Self::InvalidMessage(s) => f.debug_tuple("InvalidMessage").field(s).finish(),
|
||||||
@ -257,6 +257,7 @@ impl<T> Display for NetworkResult<T> {
|
|||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Timeout => write!(f, "Timeout"),
|
Self::Timeout => write!(f, "Timeout"),
|
||||||
|
Self::ServiceUnavailable => write!(f, "ServiceUnavailable"),
|
||||||
Self::NoConnection(e) => write!(f, "NoConnection({})", e.kind()),
|
Self::NoConnection(e) => write!(f, "NoConnection({})", e.kind()),
|
||||||
Self::AlreadyExists(e) => write!(f, "AlreadyExists({})", e.kind()),
|
Self::AlreadyExists(e) => write!(f, "AlreadyExists({})", e.kind()),
|
||||||
Self::InvalidMessage(s) => write!(f, "InvalidMessage({})", s),
|
Self::InvalidMessage(s) => write!(f, "InvalidMessage({})", s),
|
||||||
@ -275,6 +276,7 @@ macro_rules! network_result_try {
|
|||||||
($r: expr) => {
|
($r: expr) => {
|
||||||
match $r {
|
match $r {
|
||||||
NetworkResult::Timeout => return Ok(NetworkResult::Timeout),
|
NetworkResult::Timeout => return Ok(NetworkResult::Timeout),
|
||||||
|
NetworkResult::ServiceUnavailable => return Ok(NetworkResult::ServiceUnavailable),
|
||||||
NetworkResult::NoConnection(e) => return Ok(NetworkResult::NoConnection(e)),
|
NetworkResult::NoConnection(e) => return Ok(NetworkResult::NoConnection(e)),
|
||||||
NetworkResult::AlreadyExists(e) => return Ok(NetworkResult::AlreadyExists(e)),
|
NetworkResult::AlreadyExists(e) => return Ok(NetworkResult::AlreadyExists(e)),
|
||||||
NetworkResult::InvalidMessage(s) => return Ok(NetworkResult::InvalidMessage(s)),
|
NetworkResult::InvalidMessage(s) => return Ok(NetworkResult::InvalidMessage(s)),
|
||||||
@ -287,6 +289,10 @@ macro_rules! network_result_try {
|
|||||||
$f;
|
$f;
|
||||||
return Ok(NetworkResult::Timeout);
|
return Ok(NetworkResult::Timeout);
|
||||||
}
|
}
|
||||||
|
NetworkResult::ServiceUnavailable => {
|
||||||
|
$f;
|
||||||
|
return Ok(NetworkResult::ServiceUnavailable);
|
||||||
|
}
|
||||||
NetworkResult::NoConnection(e) => {
|
NetworkResult::NoConnection(e) => {
|
||||||
$f;
|
$f;
|
||||||
return Ok(NetworkResult::NoConnection(e));
|
return Ok(NetworkResult::NoConnection(e));
|
||||||
@ -340,6 +346,16 @@ macro_rules! network_result_value_or_log {
|
|||||||
);
|
);
|
||||||
$f
|
$f
|
||||||
}
|
}
|
||||||
|
NetworkResult::ServiceUnavailable => {
|
||||||
|
log_network_result!(
|
||||||
|
"{} at {}@{}:{}",
|
||||||
|
"ServiceUnavailable".cyan(),
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
column!()
|
||||||
|
);
|
||||||
|
$f
|
||||||
|
}
|
||||||
NetworkResult::NoConnection(e) => {
|
NetworkResult::NoConnection(e) => {
|
||||||
log_network_result!(
|
log_network_result!(
|
||||||
"{}({}) at {}@{}:{}",
|
"{}({}) at {}@{}:{}",
|
||||||
|
Loading…
Reference in New Issue
Block a user