summaryrefslogtreecommitdiffstats
path: root/src/sandbox/remote.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sandbox/remote.rs')
-rw-r--r--src/sandbox/remote.rs41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/sandbox/remote.rs b/src/sandbox/remote.rs
index 8366e97..f881eb0 100644
--- a/src/sandbox/remote.rs
+++ b/src/sandbox/remote.rs
@@ -14,7 +14,7 @@ use crate::sandbox::{Exit, Sandbox, SandboxBackend, SandboxInfo, SandboxSpec};
/// only way to reach it, and the alias is what carries the
/// feature-conditional visibility.
mod remote_backend {
- use super::*;
+ use super::{Config, Receiver};
// `pub` fields inside a private module are not nameable from
// outside; they stay readable by the impls below.
@@ -61,20 +61,16 @@ impl RemoteBackend {
impl SandboxBackend for RemoteBackend {
fn acquire(&self, spec: &SandboxSpec) -> Result<Arc<dyn Sandbox>> {
- let stream = self.queue.recv_timeout(spec.ttl).map_err(|_| {
- Error::other(format!(
- "no sandbox connected to {} within the lease window",
- self.addr
- ))
- })?;
+ let stream = self
+ .queue
+ .recv_timeout(spec.ttl)
+ .map_err(|_| Error::other(format!("no sandbox connected to {} within the lease window", self.addr)))?;
let _ = stream.set_read_timeout(Some(spec.ttl));
let mut reader = BufReader::new(stream.try_clone()?);
let agent_id = match wire::read_frame(&mut reader)? {
Some(Frame::Hello { token, agent_id, profiles }) => {
if token != self.token {
- return Err(Error::fail_closed(format!(
- "sandbox {agent_id} presented the wrong token"
- )));
+ return Err(Error::fail_closed(format!("sandbox {agent_id} presented the wrong token")));
}
if !profiles.is_empty() && !profiles.contains(&spec.profile) {
return Err(Error::fail_closed(format!(
@@ -89,16 +85,11 @@ impl SandboxBackend for RemoteBackend {
};
wire::write_frame(&mut stream.try_clone()?, &Frame::HelloAck { ttl_secs: spec.ttl.as_secs().max(1) })?;
let _ = stream.set_read_timeout(None);
- Ok(Arc::new(RemoteSandbox::after_hello(
- &self.cfg, stream, agent_id, spec.ttl,
- )))
+ Ok(Arc::new(RemoteSandbox::after_hello(&self.cfg, stream, agent_id, spec.ttl)))
}
fn status(&self) -> Result<Vec<SandboxInfo>> {
- Ok(vec![SandboxInfo {
- id: format!("remote@{}", self.addr),
- profile: self.cfg.build_profile.clone(),
- }])
+ Ok(vec![SandboxInfo { id: format!("remote@{}", self.addr), profile: self.cfg.build_profile.clone() }])
}
}
@@ -112,10 +103,13 @@ pub(crate) struct RemoteSandbox {
}
impl RemoteSandbox {
- pub(crate) fn after_hello(cfg: &Config, stream: std::net::TcpStream, agent_id: String, ttl: std::time::Duration) -> Self {
- let reader = BufReader::new(
- stream.try_clone().expect("cloning a connected tcp stream cannot fail"),
- );
+ pub(crate) fn after_hello(
+ cfg: &Config,
+ stream: std::net::TcpStream,
+ agent_id: String,
+ ttl: std::time::Duration,
+ ) -> Self {
+ let reader = BufReader::new(stream.try_clone().expect("cloning a connected tcp stream cannot fail"));
Self {
cfg: cfg.clone(),
id: agent_id,
@@ -132,9 +126,8 @@ impl RemoteSandbox {
fn pump(&self, req: u64, sink: &mut dyn FnMut(&str, &[u8])) -> Result<Frame> {
loop {
- let frame = match wire::read_frame(&mut *self.reader.lock().unwrap())? {
- Some(f) => f,
- None => return Err(Error::other(format!("sandbox {} vanished", self.id))),
+ let Some(frame) = wire::read_frame(&mut *self.reader.lock().unwrap())? else {
+ return Err(Error::other(format!("sandbox {} vanished", self.id)));
};
match frame {
Frame::Log { req: r, ref stream, ref data } if r == req => {