Implement multiplexer and mini-protocols PoC
This commit is contained in:
parent
89edee6793
commit
c2d537b83f
28 changed files with 1398 additions and 0 deletions
27
pallas-multiplexer/examples/listener.rs
Normal file
27
pallas-multiplexer/examples/listener.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use std::{net::TcpListener, thread, time::Duration};
|
||||
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let server = TcpListener::bind("0.0.0.0:3001").unwrap();
|
||||
let (bearer, _) = server.accept().unwrap();
|
||||
|
||||
let handles =
|
||||
Multiplexer::new(bearer, &vec![0x8002u16, 0x8003u16][..]).unwrap();
|
||||
|
||||
for handle in handles {
|
||||
thread::spawn(move || {
|
||||
let (id, rx, tx) = handle;
|
||||
loop {
|
||||
let payload = rx.recv().unwrap();
|
||||
println!("id:{}, length:{}", id, payload.len());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loop {
|
||||
thread::sleep(Duration::from_secs(6000));
|
||||
}
|
||||
}
|
||||
29
pallas-multiplexer/examples/sender.rs
Normal file
29
pallas-multiplexer/examples/sender.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use std::{net::TcpStream, thread, time::Duration};
|
||||
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let bearer = TcpStream::connect("127.0.0.1:3001").unwrap();
|
||||
let handles =
|
||||
Multiplexer::new(bearer, &vec![0x0002u16, 0x0003u16][..]).unwrap();
|
||||
|
||||
for (idx, handle) in handles.into_iter().enumerate() {
|
||||
thread::spawn(move || {
|
||||
let (id, rx, tx) = handle;
|
||||
|
||||
loop {
|
||||
let payload = vec![1; 65545];
|
||||
tx.send(payload).unwrap();
|
||||
thread::sleep(Duration::from_millis(
|
||||
50u64 + (idx as u64 * 10u64),
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loop {
|
||||
thread::sleep(Duration::from_secs(6000));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue