Skip to content

Commit

Permalink
[Network] Fix comment and handle else branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLind committed Sep 14, 2022
1 parent 28e8fcf commit 8f4a190
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 17 additions & 6 deletions network/netcore/src/transport/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,26 @@ async fn connect_via_proxy(proxy_addr: String, addr: NetworkAddress) -> io::Resu
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"HTTP proxy CONNECT failed: {}",
"HTTP proxy CONNECT failed. Len == 0. Message: {}",
String::from_utf8_lossy(msg)
),
));
} else if msg.len() >= 16
&& (msg.starts_with(b"HTTP/1.1 200") || msg.starts_with(b"HTTP/1.0 200"))
&& msg.ends_with(b"\r\n\r\n")
{
return Ok(stream);
} else if msg.len() >= 16 {
if (msg.starts_with(b"HTTP/1.1 200") || msg.starts_with(b"HTTP/1.0 200"))
&& msg.ends_with(b"\r\n\r\n")
{
return Ok(stream);
} else {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"HTTP proxy CONNECT failed! Unexpected message: {}",
String::from_utf8_lossy(msg)
),
));
}
} else {
// Keep reading until we get at least 16 bytes
}
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions network/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ fn add_pp_addr(proxy_protocol_enabled: bool, error: io::Error, addr: &NetworkAdd

/// Upgrade an inbound connection. This means we run a Noise IK handshake for
/// authentication and then negotiate common supported protocols. If
/// `ctxt.trusted_peers` is `Some(_)`, then we will only allow connections from
/// peers with a pubkey in this set. Otherwise, we will allow inbound connections
/// from any pubkey.
/// `ctxt.noise.auth_mode` is `HandshakeAuthMode::Mutual( anti_replay_timestamps , trusted_peers )`,
/// then we will only allow connections from peers with a pubkey in the `trusted_peers`
/// set. Otherwise, we will allow inbound connections from any pubkey.
async fn upgrade_inbound<T: TSocket>(
ctxt: Arc<UpgradeContext>,
fut_socket: impl Future<Output = io::Result<T>>,
Expand Down Expand Up @@ -322,7 +322,7 @@ async fn upgrade_inbound<T: TSocket>(
})
}

/// Upgrade an inbound connection. This means we run a Noise IK handshake for
/// Upgrade an outbound connection. This means we run a Noise IK handshake for
/// authentication and then negotiate common supported protocols.
pub async fn upgrade_outbound<T: TSocket>(
ctxt: Arc<UpgradeContext>,
Expand Down

0 comments on commit 8f4a190

Please sign in to comment.