diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index f4510882dc..c69a6cb11c 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -84,6 +84,22 @@ pub trait X // <- this trait have 3 generics, A, B, and C
fn do_other_stuff(&self, a: A, b: B); // <- this is not ideal because it does not have C.
}
```
+- Generic naming should be consistent. Do NOT use multiple name for the same generic, it just makes things more confusing. Do
+```rust
+pub struct X {
+ phantom: PhanomData,
+}
+
+impl X {}
+```
+But not,
+```rust
+pub struct X {
+ phantom: PhanomData,
+}
+
+impl X {} // <- Do NOT do that, use A instead of B
+```
- Always alphabetically order the type generics. Therefore,
```rust
pub struct X {}; // <- Generics are alphabetically ordered
diff --git a/libafl/src/events/broker_hooks/centralized.rs b/libafl/src/events/broker_hooks/centralized.rs
index 5fbb437719..28381279b0 100644
--- a/libafl/src/events/broker_hooks/centralized.rs
+++ b/libafl/src/events/broker_hooks/centralized.rs
@@ -5,7 +5,6 @@ use core::{fmt::Debug, marker::PhantomData};
use libafl_bolts::{compress::GzipCompressor, llmp::LLMP_FLAG_COMPRESSED};
use libafl_bolts::{
llmp::{Flags, LlmpBrokerInner, LlmpHook, LlmpMsgHookResult, Tag},
- shmem::ShMemProvider,
ClientId, Error,
};
use serde::de::DeserializeOwned;
@@ -21,14 +20,13 @@ pub struct CentralizedLlmpHook {
phantom: PhantomData,
}
-impl LlmpHook for CentralizedLlmpHook
+impl LlmpHook for CentralizedLlmpHook
where
I: DeserializeOwned,
- SP: ShMemProvider,
{
fn on_new_message(
&mut self,
- _broker_inner: &mut LlmpBrokerInner,
+ _broker_inner: &mut LlmpBrokerInner,
client_id: ClientId,
msg_tag: &mut Tag,
_msg_flags: &mut Flags,
diff --git a/libafl/src/events/broker_hooks/centralized_multi_machine.rs b/libafl/src/events/broker_hooks/centralized_multi_machine.rs
index e522c62831..08fdf2f7bb 100644
--- a/libafl/src/events/broker_hooks/centralized_multi_machine.rs
+++ b/libafl/src/events/broker_hooks/centralized_multi_machine.rs
@@ -11,7 +11,6 @@ use libafl_bolts::llmp::LLMP_FLAG_COMPRESSED;
use libafl_bolts::{
llmp::{Flags, LlmpBrokerInner, LlmpHook, LlmpMsgHookResult, Tag, LLMP_FLAG_FROM_MM},
ownedref::OwnedRef,
- shmem::ShMemProvider,
ClientId, Error,
};
use serde::Serialize;
@@ -149,16 +148,15 @@ where
}
}
-impl LlmpHook for TcpMultiMachineLlmpSenderHook
+impl LlmpHook for TcpMultiMachineLlmpSenderHook
where
I: Input,
A: Clone + Display + ToSocketAddrs + Send + Sync + 'static,
- SP: ShMemProvider,
{
/// check for received messages, and forward them alongside the incoming message to inner.
fn on_new_message(
&mut self,
- _broker_inner: &mut LlmpBrokerInner,
+ _broker_inner: &mut LlmpBrokerInner,
_client_id: ClientId,
_msg_tag: &mut Tag,
_msg_flags: &mut Flags,
@@ -211,16 +209,15 @@ where
}
}
-impl LlmpHook for TcpMultiMachineLlmpReceiverHook
+impl LlmpHook for TcpMultiMachineLlmpReceiverHook
where
I: Input,
A: Clone + Display + ToSocketAddrs + Send + Sync + 'static,
- SP: ShMemProvider,
{
/// check for received messages, and forward them alongside the incoming message to inner.
fn on_new_message(
&mut self,
- _broker_inner: &mut LlmpBrokerInner,
+ _broker_inner: &mut LlmpBrokerInner,
_client_id: ClientId,
_msg_tag: &mut Tag,
_msg_flags: &mut Flags,
diff --git a/libafl/src/events/broker_hooks/mod.rs b/libafl/src/events/broker_hooks/mod.rs
index baac20f950..f65f1c131d 100644
--- a/libafl/src/events/broker_hooks/mod.rs
+++ b/libafl/src/events/broker_hooks/mod.rs
@@ -6,7 +6,6 @@ use core::marker::PhantomData;
use libafl_bolts::{compress::GzipCompressor, llmp::LLMP_FLAG_COMPRESSED};
use libafl_bolts::{
llmp::{Flags, LlmpBrokerInner, LlmpHook, LlmpMsgHookResult, Tag},
- shmem::ShMemProvider,
ClientId,
};
use serde::de::DeserializeOwned;
@@ -40,15 +39,14 @@ pub struct StdLlmpEventHook {
phantom: PhantomData,
}
-impl LlmpHook for StdLlmpEventHook
+impl LlmpHook for StdLlmpEventHook
where
I: DeserializeOwned,
- SP: ShMemProvider,
MT: Monitor,
{
fn on_new_message(
&mut self,
- _broker_inner: &mut LlmpBrokerInner,
+ _broker_inner: &mut LlmpBrokerInner,
client_id: ClientId,
msg_tag: &mut Tag,
#[cfg(feature = "llmp_compression")] msg_flags: &mut Flags,
diff --git a/libafl/src/events/centralized.rs b/libafl/src/events/centralized.rs
index bc636b6bf9..0784d08c4f 100644
--- a/libafl/src/events/centralized.rs
+++ b/libafl/src/events/centralized.rs
@@ -18,7 +18,7 @@ use libafl_bolts::{
};
use libafl_bolts::{
llmp::{LlmpClient, LlmpClientDescription, Tag},
- shmem::{NopShMemProvider, ShMemProvider},
+ shmem::{NopShMem, NopShMemProvider, ShMem, ShMemProvider},
tuples::{Handle, MatchNameRef},
ClientId,
};
@@ -46,13 +46,10 @@ pub(crate) const _LLMP_TAG_TO_MAIN: Tag = Tag(0x3453453);
/// A wrapper manager to implement a main-secondary architecture with another broker
#[derive(Debug)]
-pub struct CentralizedEventManager
-where
- SP: ShMemProvider,
-{
+pub struct CentralizedEventManager {
inner: EM,
/// The centralized LLMP client for inter process communication
- client: LlmpClient,
+ client: LlmpClient,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor,
time_ref: Option>,
@@ -61,7 +58,16 @@ where
phantom: PhantomData<(I, S)>,
}
-impl CentralizedEventManager, NopShMemProvider> {
+impl
+ CentralizedEventManager<
+ NopEventManager,
+ (),
+ NopInput,
+ NopState,
+ NopShMem,
+ NopShMemProvider,
+ >
+{
/// Creates a builder for [`CentralizedEventManager`]
#[must_use]
pub fn builder() -> CentralizedEventManagerBuilder {
@@ -95,16 +101,13 @@ impl CentralizedEventManagerBuilder {
}
/// Creates a new [`CentralizedEventManager`].
- pub fn build_from_client(
+ pub fn build_from_client(
self,
inner: EM,
hooks: EMH,
- client: LlmpClient,
+ client: LlmpClient,
time_obs: Option>,
- ) -> Result, Error>
- where
- SP: ShMemProvider,
- {
+ ) -> Result, Error> {
Ok(CentralizedEventManager {
inner,
hooks,
@@ -121,16 +124,17 @@ impl CentralizedEventManagerBuilder {
///
/// If the port is not yet bound, it will act as a broker; otherwise, it
/// will act as a client.
- pub fn build_on_port(
+ pub fn build_on_port(
self,
inner: EM,
hooks: EMH,
shmem_provider: SP,
port: u16,
time_obs: Option>,
- ) -> Result, Error>
+ ) -> Result, Error>
where
- SP: ShMemProvider,
+ SHM: ShMem,
+ SP: ShMemProvider,
{
let client = LlmpClient::create_attach_to_tcp(shmem_provider, port)?;
Self::build_from_client(self, inner, hooks, client, time_obs)
@@ -138,42 +142,43 @@ impl CentralizedEventManagerBuilder {
/// If a client respawns, it may reuse the existing connection, previously
/// stored by [`LlmpClient::to_env()`].
- pub fn build_existing_client_from_env(
+ pub fn build_existing_client_from_env(
self,
inner: EM,
hooks: EMH,
shmem_provider: SP,
env_name: &str,
time_obs: Option>,
- ) -> Result, Error>
+ ) -> Result, Error>
where
- SP: ShMemProvider,
+ SHM: ShMem,
+ SP: ShMemProvider,
{
let client = LlmpClient::on_existing_from_env(shmem_provider, env_name)?;
Self::build_from_client(self, inner, hooks, client, time_obs)
}
/// Create an existing client from description
- pub fn existing_client_from_description(
+ pub fn existing_client_from_description(
self,
inner: EM,
hooks: EMH,
shmem_provider: SP,
description: &LlmpClientDescription,
time_obs: Option>,
- ) -> Result, Error>
+ ) -> Result, Error>
where
- SP: ShMemProvider,
+ SHM: ShMem,
+ SP: ShMemProvider,
{
let client = LlmpClient::existing_client_from_description(shmem_provider, description)?;
Self::build_from_client(self, inner, hooks, client, time_obs)
}
}
-impl AdaptiveSerializer for CentralizedEventManager
+impl AdaptiveSerializer for CentralizedEventManager
where
EM: AdaptiveSerializer,
- SP: ShMemProvider,
{
fn serialization_time(&self) -> Duration {
self.inner.serialization_time()
@@ -206,13 +211,14 @@ where
}
}
-impl EventFirer for CentralizedEventManager
+impl EventFirer for CentralizedEventManager
where
EM: HasEventManagerId + EventFirer,
EMH: EventManagerHooksTuple,
- SP: ShMemProvider,
S: Stoppable,
I: Input,
+ SHM: ShMem,
+ SP: ShMemProvider,
{
fn should_send(&self) -> bool {
self.inner.should_send()
@@ -262,10 +268,11 @@ where
}
}
-impl EventRestarter for CentralizedEventManager
+impl EventRestarter for CentralizedEventManager
where
- SP: ShMemProvider,
EM: EventRestarter,
+ SHM: ShMem,
+ SP: ShMemProvider,
{
#[inline]
fn on_restart(&mut self, state: &mut S) -> Result<(), Error> {
@@ -275,10 +282,10 @@ where
}
}
-impl CanSerializeObserver for CentralizedEventManager
+impl CanSerializeObserver
+ for CentralizedEventManager
where
EM: AdaptiveSerializer,
- SP: ShMemProvider,
OT: Serialize + MatchNameRef,
{
fn serialize_observers(&mut self, observers: &OT) -> Result