Skip to content

Commit bcb34d1

Browse files
committed
general comment improvements
1 parent 2594d23 commit bcb34d1

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ pub fn parse() -> Opts {
1717
.fallback("./cobalt.toml".to_string())
1818
.from_str();
1919

20-
// combine parsers `speed` and `distance` parsers into a parser for Opts
20+
// combine all parsers
2121
let parser = construct!(Opts { path });
2222

23-
// define help message, attach it to parser, and run the results
23+
// define help message,
2424
Info::default()
2525
.descr("cobalt - a simple reverse proxy by blobcode")
2626
.for_parser(parser)

src/config.rs

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

12-
// toml representation
12+
// toml representation (main)
1313
#[derive(Deserialize)]
1414
pub struct ConfigToml {
1515
pub port: u16,
1616
pub host: Vec<HostToml>,
1717
}
1818

19-
// toml representation
19+
// toml representation (for hosts)
2020
#[derive(Deserialize)]
2121
pub struct HostToml {
2222
pub from: Vec<String>,
@@ -38,9 +38,9 @@ fn parsehosts(config: ConfigToml) -> HashMap<String, String> {
3838
hosts
3939
}
4040

41-
// main function to get config struct
41+
// get config struct
4242
pub fn parse(file: PathBuf) -> Result<Config, Box<dyn Error>> {
43-
// load config
43+
// load config from file
4444
let buf = fs::read_to_string(file)?;
4545

4646
// parse file contents

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod server;
66

77
#[tokio::main]
88
async fn main() -> Result<(), Box<dyn Error>> {
9-
// logging setup
9+
// logging setup - log at info level
1010
simple_logger::init_with_level(log::Level::Info)?;
1111

1212
// get args

src/server.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub struct Server {
1515
impl Server {
1616
// start server
1717
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
18+
// setup address
1819
let listen_addr = "localhost:".to_string() + &self.port.to_string();
1920

20-
// start server
2121
log::info!("cobalt started");
2222
let listener = TcpListener::bind(&listen_addr).await?;
2323
log::info!("listening on: http://{}", listen_addr);
@@ -48,12 +48,11 @@ async fn handle(inbound: TcpStream, hosts: HashMap<String, String>) -> Result<()
4848
inbound.peek(&mut buf).await?;
4949
r.parse(&buf)?;
5050

51-
// parse headers
51+
// try to parse headers
5252
let p = headers.iter().position(|&h| h.name == "Host").unwrap();
5353
let host = String::from_utf8_lossy(headers[p].value).to_string();
5454
let to = &hosts[&host];
5555

56-
// proxy
5756
let proxy = proxy(inbound, to.to_string()).map(|r| {
5857
if let Err(e) = r {
5958
log::error!("failed to proxy; {}", e);
@@ -66,12 +65,12 @@ async fn handle(inbound: TcpStream, hosts: HashMap<String, String>) -> Result<()
6665
Ok(())
6766
}
6867

69-
// proxy tcpstream
68+
// proxy tcpstreams
7069
async fn proxy(mut inbound: TcpStream, proxy_addr: String) -> Result<(), Box<dyn Error>> {
71-
// connect to server
70+
// open stream
7271
let mut outbound = TcpStream::connect(proxy_addr).await?;
7372

74-
// split and merge streams
73+
// split, swap and merge streams
7574
let (mut ri, mut wi) = inbound.split();
7675
let (mut ro, mut wo) = outbound.split();
7776

0 commit comments

Comments
 (0)