Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Jun 27, 2024
1 parent a000ba0 commit 9908906
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/qos_net/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,22 @@ impl Proxy {
Ok(conn) => {
let connection_id = conn.id;
let remote_ip = conn.ip.clone();
println!("called new_from_name successfully. Saving connection ID {connection_id}...");
match self.save_connection(conn) {
Ok(()) => {
println!("Connection established and saved. Returning ConnectResponse to client");
ProxyMsg::ConnectResponse { connection_id, remote_ip }
}
Err(e) => ProxyMsg::ProxyError(e),
Err(e) => {
println!("error saving connection.");
ProxyMsg::ProxyError(e)
}
}
}
Err(e) => ProxyMsg::ProxyError(e),
Err(e) => {
println!("error calling new_from_name");
ProxyMsg::ProxyError(e)
}
}
}

Expand Down Expand Up @@ -214,12 +222,14 @@ impl server::RequestProcessor for Proxy {
dns_port,
} => {
println!("Proxy connecting to {hostname}:{port}");
self.connect_by_name(
hostname,
let resp = self.connect_by_name(
hostname.clone(),
port,
dns_resolvers,
dns_port,
)
);
println!("Proxy connected to {hostname}:{port}");
resp
}
ProxyMsg::ConnectByIpRequest { ip, port } => {
println!("Proxy connecting to {ip}:{port}");
Expand Down
8 changes: 8 additions & 0 deletions src/qos_net/src/proxy_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ impl ProxyConnection {
dns_resolvers: Vec<String>,
dns_port: u16,
) -> Result<ProxyConnection, QosNetError> {
println!("new_from_name invoked");
let ip = resolve_hostname(hostname, dns_resolvers, dns_port)?;
println!("resolved name into an IP");

// Generate a new random u32 to get an ID. We'll use it to name our
// socket. This will be our connection ID.
let mut rng = rand::thread_rng();
let connection_id: u32 = rng.gen::<u32>();
println!("Random connection ID generated");

let tcp_addr = SocketAddr::new(ip, port);
println!("TCP addr created. Connecting...");
let tcp_stream = TcpStream::connect(tcp_addr)?;
println!("Connected");
Ok(ProxyConnection {
id: connection_id,
ip: ip.to_string(),
Expand Down Expand Up @@ -88,6 +93,7 @@ fn resolve_hostname(
resolver_addrs: Vec<String>,
port: u16,
) -> Result<IpAddr, QosNetError> {
println!("resolving hostname...");
let resolver_parsed_addrs = resolver_addrs
.iter()
.map(|resolver_address| {
Expand All @@ -107,7 +113,9 @@ fn resolve_hostname(
),
);
let resolver = Resolver::new(resolver_config, ResolverOpts::default())?;
println!("resolver ready");
let response = resolver.lookup_ip(hostname.clone())?;
println!("resolver successfully invoked");
response.iter().next().ok_or_else(|| {
QosNetError::DNSResolutionError(format!(
"Empty response when querying for host {hostname}"
Expand Down

0 comments on commit 9908906

Please sign in to comment.