Skip to content

Commit

Permalink
Tcp Broker to Broker Communication (#66)
Browse files Browse the repository at this point in the history
* initial b2b implementation

* no_std and clippy fixes

* b2b testcase added

* more correct testcases

* fixed b2b

* typo

* fixed unused warning
  • Loading branch information
domenukk authored and andreafioraldi committed May 6, 2021
1 parent a78a4b7 commit b175500
Show file tree
Hide file tree
Showing 6 changed files with 553 additions and 98 deletions.
4 changes: 3 additions & 1 deletion libafl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ anymap_debug = ["serde_json"] # uses serde_json to Debug the anymap trait. Disab
derive = ["libafl_derive"] # provide derive(SerdeAny) macro.
llmp_small_maps = [] # reduces initial map size for llmp
llmp_debug = ["backtrace"] # Enables debug output for LLMP
llmp_compression = [] #llmp compression using GZip
llmp_compression = [] # llmp compression using GZip
llmp_bind_public = [] # If set, llmp will bind to 0.0.0.0, allowing cross-device communication. Binds to localhost by default.

[[example]]
name = "llmp_test"
Expand All @@ -61,6 +62,7 @@ libafl_derive = { version = "0.1.0", optional = true, path = "../libafl_derive"
serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap
compression = { version = "0.1.5" }
num_enum = "0.5.1"
hostname = "^0.3" # Is there really no gethostname in the stdlib?

[target.'cfg(target_os = "android")'.dependencies]
backtrace = { version = "0.3", optional = true, default-features = false, features = ["std", "libbacktrace"] } # for llmp_debug
Expand Down
23 changes: 16 additions & 7 deletions libafl/examples/llmp_test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn large_msg_loop(port: u16) -> ! {
fn broker_message_hook(
client_id: u32,
tag: llmp::Tag,
_flags: llmp::Flag,
_flags: llmp::Flags,
message: &[u8],
) -> Result<llmp::LlmpMsgHookResult, Error> {
match tag {
Expand Down Expand Up @@ -120,22 +120,31 @@ fn main() {

let mode = std::env::args()
.nth(1)
.expect("no mode specified, chose 'broker', 'ctr', 'adder', or 'large'");
.expect("no mode specified, chose 'broker', 'b2b', 'ctr', 'adder', or 'large'");
let port: u16 = std::env::args()
.nth(2)
.unwrap_or("1337".into())
.parse::<u16>()
.unwrap();
// in the b2b use-case, this is our "own" port, we connect to the "normal" broker node on startup.
let b2b_port: u16 = std::env::args()
.nth(3)
.unwrap_or("4242".into())
.parse::<u16>()
.unwrap();
println!("Launching in mode {} on port {}", mode, port);

match mode.as_str() {
"broker" => {
let mut broker = llmp::LlmpBroker::new(StdShMemProvider::new().unwrap()).unwrap();
broker
.launch_listener(llmp::Listener::Tcp(
std::net::TcpListener::bind(format!("127.0.0.1:{}", port)).unwrap(),
))
.unwrap();
broker.launch_tcp_listener_on(port).unwrap();
broker.loop_forever(&mut broker_message_hook, Some(Duration::from_millis(5)))
}
"b2b" => {
let mut broker = llmp::LlmpBroker::new(StdShMemProvider::new().unwrap()).unwrap();
broker.launch_tcp_listener_on(b2b_port).unwrap();
// connect back to the main broker.
broker.connect_b2b(("127.0.0.1", port)).unwrap();
broker.loop_forever(&mut broker_message_hook, Some(Duration::from_millis(5)))
}
"ctr" => {
Expand Down
1 change: 1 addition & 0 deletions libafl/src/bolts/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl GzipCompressor {

/// Decompression.
/// Flag is used to indicate if it's compressed or not
#[allow(clippy::unused_self)]
pub fn decompress(&self, buf: &[u8]) -> Result<Vec<u8>, Error> {
Ok(buf
.iter()
Expand Down
Loading

0 comments on commit b175500

Please sign in to comment.