Skip to content

Commit

Permalink
WIP fix up async types
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson committed Apr 12, 2024
1 parent 4b4e999 commit 1ff9e58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions proxy/src/bin/async.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use bip324::{Handshake, Network, Role};
use bip324_proxy::{read_v1, read_v2, write_v1, write_v2};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio::select;

/// Validate and bootstrap proxy connection.
#[allow(clippy::unused_io_amount)]
async fn proxy_conn(client: TcpStream) -> Result<(), Box<dyn std::error::Error>> {
async fn proxy_conn(mut client: TcpStream) -> Result<(), bip324_proxy::Error> {
let remote_ip = bip324_proxy::peek_addr(&client).await?;

println!("Reaching out to {}.", remote_ip);
Expand Down Expand Up @@ -40,6 +41,7 @@ async fn proxy_conn(client: TcpStream) -> Result<(), Box<dyn std::error::Error>>
remote.write_all(&local_garbage_terminator_message).await?;

println!("Authenticating garbage and version packet.");
// TODO: Make this robust.
let mut remote_garbage_and_version = vec![0u8; 5000];
remote.read(&mut remote_garbage_and_version).await?;
let packet_reader = handshake
Expand All @@ -50,7 +52,7 @@ async fn proxy_conn(client: TcpStream) -> Result<(), Box<dyn std::error::Error>>
println!("Splitting channels.");
let (mut client_reader, mut client_writer) = client.split();
let (mut remote_reader, mut remote_writer) = remote.split();
let (mut encrypter, mut decrypter) = packet_reader.split();
let (mut decrypter, mut encrypter) = packet_reader.split();

println!("Setting up proxy loop.");
loop {
Expand Down
7 changes: 7 additions & 0 deletions proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ pub async fn read_v2<T: AsyncRead + Unpin>(
input: &mut T,
decrypter: &mut PacketReader,
) -> Result<RawNetworkMessage, Error> {
let mut length_bytes = [0u8; 3];
input.read_exact(&mut length_bytes).await?;
let packet_bytes = decrypter.decypt_len(length_bytes);
let mut packet_bytes = vec![0u8; packet_bytes];
input.read_exact(&mut packet_bytes).await?;

Ok(todo!())
}

/// Write the network message to the output stream.
Expand Down

0 comments on commit 1ff9e58

Please sign in to comment.