This commit is contained in:
Dominik Maier 2020-12-14 01:01:34 +01:00
parent e757a5da9a
commit 62e2ee9f00

View File

@ -176,9 +176,8 @@ where
} }
} }
/// Client fun /// Client fun
fn handle_in_client<C, OT, FT, I, R> ( fn handle_in_client<C, OT, FT, I, R>(
event: Event<I>, event: Event<I>,
state: &mut State<I, R, FT, OT>, state: &mut State<I, R, FT, OT>,
corpus: &mut C, corpus: &mut C,
@ -206,14 +205,13 @@ where
state.add_if_interesting(corpus, input, interestingness)?; state.add_if_interesting(corpus, input, interestingness)?;
Ok(()) Ok(())
} }
_ => Err(AflError::Unknown( _ => Err(AflError::Unknown(format!(
format!("Received illegal message that message should not have arrived: {:?}.", event), "Received illegal message that message should not have arrived: {:?}.",
)), event
))),
} }
} }
pub trait EventManager<C, E, OT, FT, I, R> pub trait EventManager<C, E, OT, FT, I, R>
where where
C: Corpus<I, R>, C: Corpus<I, R>,
@ -228,7 +226,11 @@ where
/// Lookup for incoming events and process them. /// Lookup for incoming events and process them.
/// Return the number of processes events or an error /// Return the number of processes events or an error
fn process(&mut self, state: &mut State<I, R, FT, OT>, corpus: &mut C) -> Result<usize, AflError>; fn process(
&mut self,
state: &mut State<I, R, FT, OT>,
corpus: &mut C,
) -> Result<usize, AflError>;
/// the client stat, mutable /// the client stat, mutable
fn client_stats_mut(&mut self) -> &mut Vec<ClientStats>; fn client_stats_mut(&mut self) -> &mut Vec<ClientStats>;
@ -272,7 +274,7 @@ where
} => { } => {
self.corpus_size_inc(); self.corpus_size_inc();
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
}, }
Event::NewTestcase { Event::NewTestcase {
sender_id: _, sender_id: _,
input: _, input: _,
@ -297,9 +299,7 @@ where
// TODO: The stats buffer should be added on client add. // TODO: The stats buffer should be added on client add.
let client_stat_count = self.client_stats().len(); let client_stat_count = self.client_stats().len();
for _ in client_stat_count..(*sender_id + 1) as usize { for _ in client_stat_count..(*sender_id + 1) as usize {
self.client_stats_mut().push(ClientStats { self.client_stats_mut().push(ClientStats { executions: 0 })
executions: 0,
})
} }
let mut stat = &mut self.client_stats_mut()[*sender_id as usize]; let mut stat = &mut self.client_stats_mut()[*sender_id as usize];
stat.executions = *executions as u64; stat.executions = *executions as u64;
@ -398,7 +398,9 @@ where
corpus: &mut C, corpus: &mut C,
) -> Result<usize, AflError> { ) -> Result<usize, AflError> {
let count = self.events.len(); let count = self.events.len();
self.events.drain(..).try_for_each(|event| handle_in_client(event, state, corpus))?; self.events
.drain(..)
.try_for_each(|event| handle_in_client(event, state, corpus))?;
Ok(count) Ok(count)
} }
@ -475,7 +477,8 @@ where
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl<C, E, OT, FT, I, R, W> EventManager<C, E, OT, FT, I, R> for LlmpEventManager<C, E, OT, FT, I, R, W> impl<C, E, OT, FT, I, R, W> EventManager<C, E, OT, FT, I, R>
for LlmpEventManager<C, E, OT, FT, I, R, W>
where where
C: Corpus<I, R>, C: Corpus<I, R>,
E: Executor<I>, E: Executor<I>,
@ -500,7 +503,7 @@ where
) -> Result<usize, AflError> { ) -> Result<usize, AflError> {
// TODO: Get around local event copy by moving handle_in_client // TODO: Get around local event copy by moving handle_in_client
Ok(match &mut self.llmp { Ok(match &mut self.llmp {
llmp::LlmpConnection::IsClient {client} => { llmp::LlmpConnection::IsClient { client } => {
let mut count = 0; let mut count = 0;
loop { loop {
match client.recv_buf()? { match client.recv_buf()? {
@ -511,11 +514,11 @@ where
let event: Event<I> = postcard::from_bytes(event_buf)?; let event: Event<I> = postcard::from_bytes(event_buf)?;
handle_in_client(event, state, corpus)?; handle_in_client(event, state, corpus)?;
count += 1; count += 1;
}, }
None => break count, None => break count,
} }
} }
}, }
_ => { _ => {
dbg!("Skipping process in broker"); dbg!("Skipping process in broker");
0 0
@ -549,7 +552,6 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::inputs::bytes::BytesInput; use crate::inputs::bytes::BytesInput;
use crate::observers::StdMapObserver; use crate::observers::StdMapObserver;
use crate::tuples::{tuple_list, MatchNameAndType, Named}; use crate::tuples::{tuple_list, MatchNameAndType, Named};