more llmp

This commit is contained in:
Dominik Maier 2020-12-13 22:37:05 +01:00
parent d4081af8ed
commit c0b0ccccf3

View File

@ -352,6 +352,7 @@ where
writer: W, writer: W,
count: usize, count: usize,
events: Vec<Event<I>>,
// stats (maybe we need a separated struct?) // stats (maybe we need a separated struct?)
executions: usize, executions: usize,
execs_over_sec: u64, execs_over_sec: u64,
@ -377,7 +378,7 @@ where
#[inline] #[inline]
fn fire<'a>(&mut self, event: Event<I>) -> Result<(), AflError> { fn fire<'a>(&mut self, event: Event<I>) -> Result<(), AflError> {
match self.handle_in_broker(&event)? { match self.handle_in_broker(&event)? {
BrokerEventResult::Forward => (), //self.handle_in_client(event, state, corpus)?, BrokerEventResult::Forward => self.events.push(event),
// Ignore broker-only events // Ignore broker-only events
BrokerEventResult::Handled => (), BrokerEventResult::Handled => (),
} }
@ -386,12 +387,13 @@ where
fn process( fn process(
&mut self, &mut self,
_state: &mut State<I, R, FT>, state: &mut State<I, R, FT>,
_corpus: &mut C, corpus: &mut C,
) -> Result<usize, AflError> { ) -> Result<usize, AflError> {
let c = self.count; let count = self.events.len();
self.count = 0; let events: Vec<Event<I>> = self.events.drain(..).collect();
Ok(c) events.into_iter().try_for_each(|x| self.handle_in_client(x, state, corpus))?;
Ok(count)
} }
fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> { fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> {
@ -438,6 +440,7 @@ where
execs_over_sec: 0, execs_over_sec: 0,
corpus_size: 0, corpus_size: 0,
phantom: PhantomData, phantom: PhantomData,
events: vec![],
} }
} }
} }
@ -453,7 +456,7 @@ const _LLMP_TAG_EVENT_TO_BROKER: llmp::Tag = 0x2B80438;
const _LLMP_TAG_EVENT_TO_BOTH: llmp::Tag = 0x2B0741; const _LLMP_TAG_EVENT_TO_BOTH: llmp::Tag = 0x2B0741;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub struct LlmpEventManager<C, E, I, R, W> pub struct LlmpEventManager<C, E, OT, FT, I, R, W>
where where
W: Write, W: Write,
//CE: CustomEvent<I>, //CE: CustomEvent<I>,
@ -468,11 +471,11 @@ where
start_time: time::Duration, start_time: time::Duration,
client_stats: Vec<ClientStats>, client_stats: Vec<ClientStats>,
llmp: llmp::LlmpConnection, llmp: llmp::LlmpConnection,
phantom: PhantomData<(C, E, I, R)>, phantom: PhantomData<(C, E, OT, FT, I, R)>,
} }
#[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, 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>,
@ -492,12 +495,33 @@ where
fn process( fn process(
&mut self, &mut self,
_state: &mut State<I, R, FT>, state: &mut State<I, R, FT>,
_corpus: &mut C, corpus: &mut C,
) -> Result<usize, AflError> { ) -> Result<usize, AflError> {
let c = self.count; let count = match &mut self.llmp {
self.count = 0; llmp::LlmpConnection::IsClient {client} => {
Ok(c) let mut msg_count = 0;
loop {
match client.recv_buf()? {
Some((tag, event_buf)) => {
if tag == _LLMP_TAG_EVENT_TO_BROKER {
continue;
}
let event = postcard::from_bytes(event_buf)?;
// TODO: self.handle_in_client(event, state, corpus)?;
msg_count += 1;
},
None => break msg_count,
}
}
},
_ => {
dbg!("Skipping process in broker");
0
}
};
Ok(count)
} }
fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> { fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> {