-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathlib.rs
More file actions
167 lines (141 loc) · 4.29 KB
/
Copy pathlib.rs
File metadata and controls
167 lines (141 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#![doc = include_str!("../README.md")]
extern crate ts_netstack_smoltcp as netstack;
use std::sync::Arc;
use kameo::message::Context;
use tokio::sync::Mutex;
use crate::{
control_runner::ControlRunner, dataplane::DataplaneActor, env::RegForwarded,
multiderp::Multiderp, netstack_actor::NetstackActor, peer_tracker::PeerTracker,
};
/// Control runner.
pub mod control_runner;
mod dataplane;
mod derp_latency;
mod env;
mod error;
mod multiderp;
mod netmon;
mod netstack_actor;
mod packetfilter;
pub mod peer_tracker;
mod registry;
mod retained_bus;
mod route_updater;
mod src_filter;
mod stunner;
mod task;
pub(crate) use env::Env;
pub use error::{Error, ErrorKind};
pub use kameo::actor::{ActorRef, Spawn};
pub use registry::Registry;
pub use task::{ErasedTask, Task};
/// The runtime for a tailscale device.
pub struct Runtime {
env: Env,
}
/// Configuration for starting a [`Runtime`].
#[derive(Debug, Clone)]
pub struct Config {
/// The control configuration to use.
pub control_config: ts_control::Config,
/// The auth key to use to connect to the control server.
pub auth_key: Option<String>,
/// The keys to use.
pub keys: ts_keys::NodeState,
}
impl kameo::Actor for Runtime {
type Error = Error;
type Args = Config;
async fn on_start(config: Config, slf: ActorRef<Self>) -> Result<Self, Self::Error> {
let env = Env::new(config.keys);
env.bus.link(&slf).await;
env.scheduler.link(&slf).await;
env.registry.link(&slf).await;
#[cfg(feature = "console")]
{
// Runs detached.
if let Err(e) =
kameo::console::serve((core::net::Ipv4Addr::new(127, 0, 0, 1), 9999)).await
{
tracing::error!(error = %e, "console died");
};
}
DataplaneActor::supervise(&slf, env.clone()).spawn().await;
let (netstack_id, netstack_up, netstack_down) = env
.ask::<DataplaneActor, _>(None, dataplane::NewOverlayTransport, true)
.await?;
Multiderp::supervise(&slf, env.clone()).spawn().await;
route_updater::RouteUpdater::supervise(&slf, (env.clone(), netstack_id))
.spawn()
.await;
packetfilter::PacketfilterUpdater::supervise(&slf, env.clone())
.spawn()
.await;
src_filter::SourceFilterUpdater::supervise(&slf, env.clone())
.spawn()
.await;
stunner::Stunner::supervise(&slf, env.clone()).spawn().await;
if let Some(mon) = ts_netmon::platform_mon() {
netmon::NetmonActor::supervise(&slf, (env.clone(), Arc::new(mon)))
.spawn()
.await;
}
PeerTracker::supervise(&slf, env.clone()).spawn().await;
NetstackActor::supervise(
&slf,
(
env.clone(),
Default::default(),
netstack_up,
Arc::new(Mutex::new(netstack_down)),
),
)
.spawn()
.await;
ControlRunner::supervise(
&slf,
control_runner::Params {
config: config.control_config,
auth_key: config.auth_key,
env: env.clone(),
},
)
.spawn()
.await;
// Actors we forward messages for:
env.wait::<ControlRunner>(None).await?;
env.wait::<NetstackActor>(None).await?;
env.wait::<PeerTracker>(None).await?;
Ok(Self { env })
}
}
macro_rules! forward {
($actor:ty, $($msg:ty),* $(,)?) => {
$(
pub use $msg;
impl kameo::message::Message<$msg> for Runtime {
type Reply = RegForwarded<$actor, $msg>;
async fn handle(
&mut self,
msg: $msg,
ctx: &mut Context<Self, Self::Reply>,
) -> RegForwarded<$actor, $msg> {
self.env.forward(ctx, None, msg).await
}
}
)*
};
}
forward!(NetstackActor, netstack_actor::GetChannel);
forward!(
ControlRunner,
control_runner::Ipv4,
control_runner::Ipv6,
control_runner::SelfNode
);
forward!(
PeerTracker,
peer_tracker::PeerByName,
peer_tracker::PeerByTailnetIp,
peer_tracker::PeerByAcceptedRoute
);