cttps 0.1.2

Crypto Transfer Protocol Secure (CTTPS) - A high-performance secure transport protocol using X25519 and AES-256-GCM.
use cttps::CttpsStream;
use tokio::net::TcpListener;
use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let addr = "127.0.0.1:8080";
    let listener = TcpListener::bind(addr).await?;
    println!("CTTPS Server listening on {}", addr);

    loop {
        let (stream, peer_addr) = listener.accept().await?;
        println!("New connection from {}", peer_addr);

        tokio::spawn(async move {
            match CttpsStream::accept(stream).await {
                Ok(mut cttps_stream) => {
                    println!("Handshake successful for {}", peer_addr);
                    loop {
                        match cttps_stream.read_packet().await {
                            Ok(msg) => {
                                let text = String::from_utf8_lossy(&msg);
                                println!("Received: {}", text);
                                
                                // Serve HTML
                                let response = r#"
<!DOCTYPE html>
<html>
<head><title>CTTPS Welcome</title></head>
<body style="background-color: #1a1a1a; color: #ffffff;">
    <h1>Welcome to CTTPS Secure Web</h1>
    <p>This page was delivered over an encrypted X25519/AES-GCM tunnel.</p>
    <div style="border: 1px solid #444; padding: 10px;">
        <h3>Secure HTTPS Bridge Feature:</h3>
        <p>You can embed standard web content securely:</p>
        <https>https://raw.githubusercontent.com/NotDreamPVP/cttps/main/README.md</https>
    </div>
</body>
</html>
"#.trim();
                                if let Err(e) = cttps_stream.write_packet(response.as_bytes()).await {
                                    eprintln!("Failed to send response: {}", e);
                                    break;
                                }
                            }
                            Err(e) => {
                                eprintln!("Connection closed or error: {}", e);
                                break;
                            }
                        }
                    }
                }
                Err(e) => {
                    eprintln!("Handshake failed for {}: {}", peer_addr, e);
                }
            }
            println!("Connection from {} closed", peer_addr);
        });
    }
}