Skip to content

Commit 4bb5854

Browse files
committed
comment
1 parent 0b13928 commit 4bb5854

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use bpaf::*;
22
use std::path::PathBuf;
3+
4+
// main args struct
35
#[derive(Clone, Debug)]
46
pub struct Opts {
57
pub path: PathBuf,
68
}
79

10+
// parse cli args
811
pub fn parse() -> Opts {
912
// config path
1013
let path = short('c')

src/config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ pub struct Config {
88
pub hosts: HashMap<String, String>,
99
}
1010

11-
// structs that parse toml
11+
// toml representation
1212
#[derive(Deserialize)]
1313
pub struct ConfigToml {
1414
pub port: u16,
1515
pub host: Vec<HostToml>,
1616
}
1717

18+
// toml representation
1819
#[derive(Deserialize)]
1920
pub struct HostToml {
2021
pub from: Vec<String>,
@@ -23,10 +24,10 @@ pub struct HostToml {
2324

2425
// parse config file
2526
fn parsehosts(config: ConfigToml) -> HashMap<String, String> {
26-
// parse list
27+
// create standin hashmap
2728
let mut hosts = HashMap::new();
2829

29-
// add all "to" and "from" fields to the hashmap
30+
// unwrap fields into the hashmap
3031
for host in config.host {
3132
for from in host.from {
3233
let to = &host.to;

src/server.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::collections::HashMap;
2+
use tokio::io;
23
use tokio::io::AsyncWriteExt;
3-
use tokio::io::{self};
44
use tokio::net::{TcpListener, TcpStream};
55

66
use futures::FutureExt;
77
use std::error::Error;
88

9+
// main server state
910
pub struct Server {
1011
pub port: u16,
1112
pub hosts: HashMap<String, String>,
@@ -16,10 +17,9 @@ impl Server {
1617
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
1718
let listen_addr = "localhost:".to_string() + &self.port.to_string();
1819

20+
// start server
1921
log::info!("cobalt started");
20-
2122
let listener = TcpListener::bind(&listen_addr).await?;
22-
2323
log::info!("listening on: http://{}", listen_addr);
2424

2525
// listener loop that passes off to handler
@@ -30,6 +30,7 @@ impl Server {
3030
}
3131
});
3232

33+
// create thread for handler
3334
tokio::spawn(handler);
3435
}
3536
Ok(())
@@ -43,7 +44,7 @@ async fn handle(inbound: TcpStream, hosts: HashMap<String, String>) -> Result<()
4344
let mut headers = [httparse::EMPTY_HEADER; 16];
4445
let mut r = httparse::Request::new(&mut headers);
4546

46-
// parse request
47+
// peek into buffer and parse request
4748
inbound.peek(&mut buf).await?;
4849
r.parse(&buf)?;
4950

@@ -59,6 +60,7 @@ async fn handle(inbound: TcpStream, hosts: HashMap<String, String>) -> Result<()
5960
}
6061
});
6162

63+
// spawn thread for proxy
6264
tokio::spawn(proxy);
6365

6466
Ok(())

0 commit comments

Comments
 (0)