moved llmp to examples
This commit is contained in:
parent
752bc86203
commit
e1268fa200
@ -13,6 +13,8 @@ fxhash = "0.2.1" # yet another hash
|
||||
xxhash-rust = { version = "0.8.0", features = ["const_xxh3", "xxh3"] } # xxh3 hashing for rust
|
||||
serde_json = "1.0.60"
|
||||
|
||||
num_cpus = "1.0" # cpu count, for llmp example
|
||||
|
||||
[[bench]]
|
||||
name = "rand_speeds"
|
||||
harness = false
|
||||
@ -30,6 +32,10 @@ debug = true
|
||||
default = ["std"]
|
||||
std = []
|
||||
|
||||
[[example]]
|
||||
name = "llmp_test"
|
||||
path = "./examples/llmp_test/main.rs"
|
||||
|
||||
[dependencies]
|
||||
tuple_list = "0.1.2"
|
||||
hashbrown = { version = "0.9", features = ["serde"] } # A faster hashmap, nostd compatible
|
||||
|
@ -6,18 +6,20 @@ use std::thread;
|
||||
use std::time;
|
||||
|
||||
use afl::events::llmp;
|
||||
use afl::events::shmem::AflShmem;
|
||||
use afl::AflError;
|
||||
|
||||
const TAG_SIMPLE_U32_V1: u32 = 0x51300321;
|
||||
const TAG_MATH_RESULT_V1: u32 = 0x77474331;
|
||||
|
||||
fn adder_loop(port: u16) -> ! {
|
||||
let mut client = llmp::LlmpClient::create_attach_to_tcp(port).unwrap();
|
||||
let mut client = llmp::LlmpClient::<AflShmem>::create_attach_to_tcp(port).unwrap();
|
||||
let mut last_result: u32 = 0;
|
||||
let mut current_result: u32 = 0;
|
||||
loop {
|
||||
let mut msg_counter = 0;
|
||||
loop {
|
||||
let (tag, buf) = match client.recv_buf().unwrap() {
|
||||
let (_sender, tag, buf) = match client.recv_buf().unwrap() {
|
||||
None => break,
|
||||
Some(msg) => msg,
|
||||
};
|
||||
@ -47,29 +49,30 @@ fn adder_loop(port: u16) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn broker_message_hook(
|
||||
fn broker_message_hook(
|
||||
client_id: u32,
|
||||
message: *mut llmp::LlmpMsg,
|
||||
) -> llmp::LlmpMsgHookResult {
|
||||
match (*message).tag {
|
||||
tag: llmp::Tag,
|
||||
message: &[u8],
|
||||
) -> Result<llmp::LlmpMsgHookResult, AflError> {
|
||||
match tag {
|
||||
TAG_SIMPLE_U32_V1 => {
|
||||
println!(
|
||||
"Client {:?} sent message: {:?}",
|
||||
client_id,
|
||||
u32::from_le_bytes((*message).as_slice_unsafe().try_into().unwrap())
|
||||
u32::from_le_bytes(message.try_into().unwrap())
|
||||
);
|
||||
llmp::LlmpMsgHookResult::ForwardToClients
|
||||
Ok(llmp::LlmpMsgHookResult::ForwardToClients)
|
||||
}
|
||||
TAG_MATH_RESULT_V1 => {
|
||||
println!(
|
||||
"Adder Client has this current result: {:?}",
|
||||
u32::from_le_bytes((*message).as_slice_unsafe().try_into().unwrap())
|
||||
u32::from_le_bytes(message.try_into().unwrap())
|
||||
);
|
||||
llmp::LlmpMsgHookResult::Handled
|
||||
Ok(llmp::LlmpMsgHookResult::Handled)
|
||||
}
|
||||
_ => {
|
||||
println!("Unknwon message id received!");
|
||||
llmp::LlmpMsgHookResult::ForwardToClients
|
||||
Ok(llmp::LlmpMsgHookResult::ForwardToClients)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,13 +92,16 @@ fn main() {
|
||||
|
||||
match mode.as_str() {
|
||||
"broker" => {
|
||||
let mut broker: llmp::LlmpBroker = llmp::LlmpBroker::new().unwrap();
|
||||
broker.launch_tcp_listener(port).unwrap();
|
||||
broker.add_message_hook(broker_message_hook);
|
||||
broker.loop_forever(Some(Duration::from_millis(5)))
|
||||
let mut broker = llmp::LlmpBroker::<AflShmem>::new().unwrap();
|
||||
broker
|
||||
.launch_tcp_listener(
|
||||
std::net::TcpListener::bind(format!("127.0.0.1:{}", port)).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
broker.loop_forever(&mut broker_message_hook, Some(Duration::from_millis(5)))
|
||||
}
|
||||
"ctr" => {
|
||||
let mut client = llmp::LlmpClient::create_attach_to_tcp(port).unwrap();
|
||||
let mut client = llmp::LlmpClient::<AflShmem>::create_attach_to_tcp(port).unwrap();
|
||||
let mut counter: u32 = 0;
|
||||
loop {
|
||||
counter = counter.wrapping_add(1);
|
@ -1,11 +0,0 @@
|
||||
[package]
|
||||
name = "llmp_test"
|
||||
version = "0.1.0"
|
||||
authors = ["Dominik Maier <domenukk@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
num_cpus = "1.0"
|
||||
afl = { path = "../" }
|
@ -313,22 +313,21 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use crate::observers::{Observer, StdMapObserver};
|
||||
use crate::observers::StdMapObserver;
|
||||
use crate::tuples::Named;
|
||||
|
||||
static mut MAP: [u32; 4] = [0; 4];
|
||||
|
||||
#[test]
|
||||
fn test_observer_serde() {
|
||||
let o: Box<dyn Observer> =
|
||||
Box::new(StdMapObserver::<u32>::new("test", unsafe { &mut MAP }));
|
||||
let s = serde_json::to_string(&o).unwrap();
|
||||
println!("{}", s);
|
||||
let d: Box<dyn Observer> = serde_json::from_str(&s).unwrap();
|
||||
assert_eq!(d.name(), o.name());
|
||||
let obv = StdMapObserver::new("test", unsafe { &mut MAP });
|
||||
let vec = postcard::to_allocvec(&obv).unwrap();
|
||||
println!("{:?}", vec);
|
||||
let obv2: StdMapObserver<u32> = postcard::from_bytes(&vec).unwrap();
|
||||
assert_eq!(obv.name(), obv2.name());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -1,14 +0,0 @@
|
||||
[package]
|
||||
name = "afl_derives"
|
||||
version = "0.1.0"
|
||||
authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
syn = "0.15"
|
||||
quote = "0.6"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
@ -1,23 +0,0 @@
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
#[macro_use]
|
||||
extern crate syn;
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use syn::DeriveInput;
|
||||
|
||||
#[proc_macro_derive(MyMacro)]
|
||||
pub fn my_macro(input: TokenStream) -> TokenStream {
|
||||
// Parse the input tokens into a syntax tree
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
|
||||
// Build the output, possibly using quasi-quotation
|
||||
let expanded = quote! {
|
||||
// ...
|
||||
};
|
||||
|
||||
// Hand the output tokens back to the compiler
|
||||
TokenStream::from(expanded)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user