Skip to content

Commit 397f768

Browse files
committed
comments
1 parent 96c6283 commit 397f768

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/args.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub struct Opts {
66
}
77

88
pub fn parse() -> Opts {
9+
// config path
910
let path = short('c')
1011
.long("config")
1112
.help("Path to config file")

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct HostToml {
2525
fn parsehosts(config: ConfigToml) -> HashMap<String, String> {
2626
// parse list
2727
let mut hosts = HashMap::new();
28+
2829
// add all "to" and "from" fields to the hashmap
2930
for host in config.host {
3031
for from in host.from {

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use simple_logger::SimpleLogger;
2-
use std::{collections::HashMap, error::Error};
2+
use std::error::Error;
33

44
mod args;
55
mod config;
@@ -16,14 +16,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
1616
// get config
1717
let config = config::parse(opts.path);
1818

19-
let mut hosts = HashMap::new();
20-
hosts.insert("localhost:8000".to_string(), "localhost:8080".to_string());
21-
2219
// server setup
2320
let server = server::Server {
2421
port: config.port,
25-
hosts,
22+
hosts: config.hosts,
2623
};
24+
25+
// run server
2726
server.run().await?;
27+
2828
Ok(())
2929
}

src/server.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl Server {
3636

3737
// request handler
3838
async fn handle(inbound: TcpStream, hosts: HashMap<String, String>) -> Result<(), Box<dyn Error>> {
39+
// buffer init
3940
let mut buf = vec![0; 1024];
4041
let mut headers = [httparse::EMPTY_HEADER; 16];
4142
let mut r = httparse::Request::new(&mut headers);
@@ -61,10 +62,12 @@ async fn handle(inbound: TcpStream, hosts: HashMap<String, String>) -> Result<()
6162
Ok(())
6263
}
6364

64-
// proxy a tcp stream
65+
// proxy tcpstream
6566
async fn proxy(mut inbound: TcpStream, proxy_addr: String) -> Result<(), Box<dyn Error>> {
67+
// connect to server
6668
let mut outbound = TcpStream::connect(proxy_addr).await?;
6769

70+
// split and merge streams
6871
let (mut ri, mut wi) = inbound.split();
6972
let (mut ro, mut wo) = outbound.split();
7073

0 commit comments

Comments
 (0)