mirror of
https://github.com/YGGverse/titanit.git
synced 2026-03-31 09:05:45 +00:00
add comments, update debug messages
This commit is contained in:
parent
8ee71e0166
commit
e20969c28d
1 changed files with 10 additions and 4 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -56,17 +56,22 @@ fn handle(
|
|||
connection: Result<TlsStream<TcpStream>, HandshakeError<TcpStream>>,
|
||||
) {
|
||||
use titanite::*;
|
||||
//println!("[{}] [info] [{peer}] New connection", now());
|
||||
println!("[{}] [info] [{peer}] New peer connected..", now());
|
||||
match connection {
|
||||
Ok(mut stream) => {
|
||||
// server should work with large files without memory overload,
|
||||
// because of that incoming data read partially, using chunks;
|
||||
// collect header bytes first to route the request
|
||||
let mut header = Vec::with_capacity(HEADER_MAX_LEN);
|
||||
loop {
|
||||
let mut buffer = vec![0];
|
||||
match stream.read(&mut buffer) {
|
||||
Ok(0) => println!("[{}] [warning] [{peer}] Peer closed connection", now()),
|
||||
Ok(0) => println!("[{}] [warning] [{peer}] Peer closed connection.", now()),
|
||||
Ok(_) => {
|
||||
header.push(buffer[0]);
|
||||
// header bytes collected
|
||||
if header.len() > HEADER_MAX_LEN || buffer[0] == b'\n' {
|
||||
// detect controller for the request by parse its header bytes
|
||||
return match Request::from_bytes(&header) {
|
||||
Ok(request) => match request {
|
||||
Request::Gemini(this) => {
|
||||
|
|
@ -136,9 +141,10 @@ fn gemini(
|
|||
// println!("[{}] [info] [{peer}] Chunk sent: {l} ({read} total)", now());
|
||||
// EOF
|
||||
if l == 0 {
|
||||
println!("[{}] [info] [{peer}] Response: {read} bytes", now());
|
||||
stream.flush().unwrap();
|
||||
stream.shutdown().unwrap();
|
||||
println!("[{}] [info] [{peer}] Response: {read} bytes", now());
|
||||
println!("[{}] [info] [{peer}] Connection closed by server.", now());
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
@ -194,7 +200,7 @@ fn titan(
|
|||
let mut input = vec![0; argument.chunk];
|
||||
match stream.read(&mut input) {
|
||||
Ok(0) => {
|
||||
println!("[{}] [warning] [{peer}] Peer closed connection", now());
|
||||
println!("[{}] [warning] [{peer}] Peer closed connection.", now());
|
||||
if let Err(e) = tmp.delete() {
|
||||
println!("[{}] [error] [{peer}] {e}", now());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue