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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
mod crypto;
mod data;
mod handshake;
#[macro_use]
mod macros;
mod msg;
mod rc4;
pub mod stream;
pub use stream::*;
#[cfg(test)]
mod test {
use crate::stream::{BlazeListener, BlazeStream};
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::time::sleep;
#[tokio::test]
async fn test_server() {
let listener = BlazeListener::bind(("0.0.0.0", 42127))
.await
.expect("Failed to bind blaze listener");
loop {
let (stream, _) = listener
.blocking_accept()
.await
.expect("Failed to accept stream");
tokio::spawn(handle(stream));
}
}
async fn handle(mut stream: BlazeStream) {
let mut buf = [0u8; 20];
loop {
buf.fill(0);
let read_count = stream.read(&mut buf).await.unwrap();
if read_count > 0 {
println!("{:?}", &buf[..read_count]);
}
sleep(Duration::from_secs(5)).await
}
}
#[tokio::test]
async fn test_client() {
let addr = ("159.153.64.175", 42127);
let mut stream = BlazeStream::connect(addr)
.await
.expect("Failed to create blaze stream");
let test = [0u8; 12];
stream.write_all(&test).await.expect("Failed to write");
stream.flush().await.expect("Failed to flush");
let mut buf = [0u8; 12];
stream.read_exact(&mut buf).await.expect("Read bytes");
println!("{:?} Bytes", buf)
}
}