diff options
Diffstat (limited to 'src/sandbox/remote.rs')
| -rw-r--r-- | src/sandbox/remote.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/sandbox/remote.rs b/src/sandbox/remote.rs index c1ad998..e68ea0f 100644 --- a/src/sandbox/remote.rs +++ b/src/sandbox/remote.rs @@ -98,14 +98,9 @@ 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 { - cfg: self.cfg.clone(), - id: agent_id, - ttl: spec.ttl, - reader: Mutex::new(reader), - writer: Mutex::new(stream), - req: AtomicU64::new(1), - })) + Ok(Arc::new(RemoteSandbox::after_hello( + &self.cfg, stream, agent_id, spec.ttl, + ))) } fn status(&self) -> Result<Vec<SandboxInfo>> { @@ -127,6 +122,23 @@ pub struct RemoteSandbox { } impl RemoteSandbox { + /// Wrap a stream whose `Hello` has been verified and answered. Split out + /// so the kata backend can lease a rendezvoused connection with its own + /// accept loop without duplicating the sandbox half. + 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, + ttl, + reader: Mutex::new(reader), + writer: Mutex::new(stream), + req: AtomicU64::new(1), + } + } + fn send(&self, frame: &Frame) -> Result<()> { wire::write_frame(&mut *self.writer.lock().unwrap(), frame).map_err(Into::into) } |
