mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-05 22:21:31 +00:00
feat: implement request response idm system
This commit is contained in:
@ -6,7 +6,10 @@ use anyhow::Result;
|
||||
use cgroups_rs::Cgroup;
|
||||
use krata::idm::{
|
||||
client::IdmClient,
|
||||
protocol::{idm_event::Event, IdmEvent, IdmExitEvent},
|
||||
protocol::{
|
||||
idm_event::Event, idm_request::Request, idm_response::Response, IdmEvent, IdmExitEvent,
|
||||
IdmPingResponse, IdmRequest,
|
||||
},
|
||||
};
|
||||
use log::debug;
|
||||
use nix::unistd::Pid;
|
||||
@ -31,6 +34,7 @@ impl GuestBackground {
|
||||
|
||||
pub async fn run(&mut self) -> Result<()> {
|
||||
let mut event_subscription = self.idm.subscribe().await?;
|
||||
let mut requests_subscription = self.idm.requests().await?;
|
||||
loop {
|
||||
select! {
|
||||
x = event_subscription.recv() => match x {
|
||||
@ -48,6 +52,21 @@ impl GuestBackground {
|
||||
}
|
||||
},
|
||||
|
||||
x = requests_subscription.recv() => match x {
|
||||
Ok(request) => {
|
||||
self.handle_idm_request(request).await?;
|
||||
},
|
||||
|
||||
Err(broadcast::error::RecvError::Closed) => {
|
||||
debug!("idm packet channel closed");
|
||||
break;
|
||||
},
|
||||
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
},
|
||||
|
||||
event = self.wait.recv() => match event {
|
||||
Some(event) => self.child_event(event).await?,
|
||||
None => {
|
||||
@ -59,6 +78,16 @@ impl GuestBackground {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_idm_request(&mut self, packet: IdmRequest) -> Result<()> {
|
||||
let id = packet.id;
|
||||
if let Some(Request::Ping(_)) = packet.request {
|
||||
self.idm
|
||||
.respond(id, Response::Ping(IdmPingResponse {}))
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn child_event(&mut self, event: ChildEvent) -> Result<()> {
|
||||
if event.pid == self.child {
|
||||
self.idm
|
||||
|
Reference in New Issue
Block a user