feat(rust): add source and destination access controls
use crate::compat::boxed::Box;
+use crate::compat::vec::Vec;
use crate::{RelayMessage, Result, LOCAL};
use core::fmt::Debug;
@@ -71,6 +72,21 @@ impl AccessControl for AllowSourceAddress {
}
}
+/// An Access Control type that allows messages from the given source address to go through
+#[derive(Debug)]
+pub struct AllowSourceAddresses(pub Vec<Address>);
+
+#[async_trait]
+impl AccessControl for AllowSourceAddresses {
+ async fn is_authorized(&self, relay_msg: &RelayMessage) -> Result<bool> {
+ if self.0.contains(&relay_msg.source) {
+ crate::allow()
+ } else {
+ crate::deny()
+ }
+ }
+}
+
/// An Access Control type that allows messages to the given destination address to go through
#[derive(Debug)]
// FIXME: @ac rename
@@ -90,6 +106,24 @@ impl AccessControl for AllowDestinationAddress {
}
}
+/// An Access Control type that allows messages to the given destination address to go through
+#[derive(Debug)]
+pub struct AllowDestinationAddresses(pub Vec<Address>);
+
+#[async_trait]
+impl AccessControl for AllowDestinationAddresses {
+ async fn is_authorized(&self, relay_msg: &RelayMessage) -> Result<bool> {
+ let onward_route = &relay_msg.onward;
+
+ // Check if next hop is equal to expected value. Further hops are not checked
+ if !self.0.contains(onward_route.next()?) {
+ return crate::deny();
+ }
+
+ crate::allow()
+ }
+}
+
/// Allows only messages to local workers
#[derive(Debug)]
pub struct LocalDestinationOnly;
