summaryrefslogtreecommitdiff
path: root/src/runtime.rs
diff options
context:
space:
mode:
authorAndrew Guschin <guschin@altlinux.org>2026-10-30 03:10:41 +0400
committerAndrew Guschin <guschin@altlinux.org>2026-10-30 03:10:41 +0400
commitd608ffeeda1a479c9dc0e5f6ad269ba07a510d7f (patch)
tree3824ec9da5ca0adac913cc47e3e20054c3dc843a /src/runtime.rs
parent40cf3276cdc74bf6f1795990ed600891a637d1fe (diff)
Implement Linux proxy controller, subscription state, and CLI/TUI
Diffstat (limited to 'src/runtime.rs')
-rw-r--r--src/runtime.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/runtime.rs b/src/runtime.rs
new file mode 100644
index 0000000..96ffd0d
--- /dev/null
+++ b/src/runtime.rs
@@ -0,0 +1,34 @@
+use crate::model::Trojan;
+use anyhow::{Result, bail};
+use async_trait::async_trait;
+
+#[async_trait]
+pub trait Runtime: Send {
+ /// Protection must be installed before durable enabled intent changes.
+ async fn arm(&mut self) -> Result<()>;
+ async fn apply(&mut self, connection: Option<&Trojan>, generation: u64) -> Result<()>;
+ async fn maintain(&mut self, connection: Option<&Trojan>, generation: u64) -> Result<()> {
+ self.apply(connection, generation).await
+ }
+ /// Called only after disabled intent has been durably recorded.
+ async fn disable(&mut self) -> Result<()>;
+ fn routing(&self) -> &str;
+}
+
+/// Allows managing saved subscriptions without claiming that host capture is available.
+pub struct OfflineRuntime;
+#[async_trait]
+impl Runtime for OfflineRuntime {
+ async fn arm(&mut self) -> Result<()> {
+ bail!("Host networking is unavailable; install and start the Roentgen service")
+ }
+ async fn apply(&mut self, _: Option<&Trojan>, _: u64) -> Result<()> {
+ bail!("Host networking is unavailable")
+ }
+ async fn disable(&mut self) -> Result<()> {
+ Ok(())
+ }
+ fn routing(&self) -> &str {
+ "unavailable"
+ }
+}