forked from txpipe/pallas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistener.rs
40 lines (29 loc) · 1009 Bytes
/
listener.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::{net::TcpListener, thread, time::Duration};
use log::info;
use pallas_multiplexer::{Channel, Multiplexer};
const PROTOCOLS: [u16; 2] = [0x8002u16, 0x8003u16];
fn main() {
env_logger::init();
let server = TcpListener::bind("0.0.0.0:3001").unwrap();
info!("listening for connections on port 3001");
let (bearer, _) = server.accept().unwrap();
let mut muxer = Multiplexer::setup(bearer, &PROTOCOLS).unwrap();
for protocol in PROTOCOLS {
let handle = muxer.use_channel(protocol);
thread::spawn(move || {
info!("starting thread for protocol: {}", protocol);
let Channel(_, rx) = handle;
loop {
let payload = rx.recv().unwrap();
info!(
"got message within thread, id:{}, length:{}",
protocol,
payload.len()
);
}
});
}
loop {
thread::sleep(Duration::from_secs(6000));
}
}