aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: f2ce6f5592904880dd595db821919be7764095a1 (plain)
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
pub mod error;
pub mod handshake;
// pub mod field;
// pub mod transactions;

use crate::error::HotlineError;
use crate::handshake::accept_handshake;

use std::net::TcpStream;

/// Get the stream and act as a server. If you want to act as a client, you
/// will have to write your own handler.
///
/// # Errors
///
/// Returns error if handshake fails or stream I/O fails
pub fn handle_client(mut stream: TcpStream) -> Result<(), HotlineError> {
    let handshake_request = accept_handshake(&mut stream)?;

    eprintln!(
        "Handshake successful with sub_protocol_id: 0x{:08X}, sub_version: {}",
        handshake_request.sub_protocol_id, handshake_request.sub_version
    );

    Ok(())
}