diff --git a/src/qos_net/src/proxy.rs b/src/qos_net/src/proxy.rs index a9d65f74..437d5287 100644 --- a/src/qos_net/src/proxy.rs +++ b/src/qos_net/src/proxy.rs @@ -104,20 +104,19 @@ 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"); + println!("Connection to {hostname} established and saved as ID {connection_id}"); ProxyMsg::ConnectResponse { connection_id, remote_ip } } Err(e) => { - println!("error saving connection."); + println!("error saving connection: {e:?}"); ProxyMsg::ProxyError(e) } } } Err(e) => { - println!("error calling new_from_name"); + println!("error while establishing connection: {e:?}"); ProxyMsg::ProxyError(e) } } @@ -126,18 +125,25 @@ impl Proxy { /// Create a new connection, targeting an IP address directly. /// address. The TCP connection is opened and saved in internal state. pub fn connect_by_ip(&mut self, ip: String, port: u16) -> ProxyMsg { - match proxy_connection::ProxyConnection::new_from_ip(ip, port) { + match proxy_connection::ProxyConnection::new_from_ip(ip.clone(), port) { Ok(conn) => { let connection_id = conn.id; let remote_ip = conn.ip.clone(); match self.save_connection(conn) { Ok(()) => { + println!("Connection to {ip} established and saved as ID {connection_id}"); ProxyMsg::ConnectResponse { connection_id, remote_ip } } - Err(e) => ProxyMsg::ProxyError(e), + Err(e) => { + println!("error saving connection: {e:?}"); + ProxyMsg::ProxyError(e) + } } } - Err(e) => ProxyMsg::ProxyError(e), + Err(e) => { + println!("error while establishing connection: {e:?}"); + ProxyMsg::ProxyError(e) + } } } @@ -207,7 +213,6 @@ impl Proxy { impl server::RequestProcessor for Proxy { fn process(&mut self, req_bytes: Vec) -> Vec { - println!("Proxy processing request"); if req_bytes.len() > MAX_ENCODED_MSG_LEN { return ProxyMsg::ProxyError(QosNetError::OversizedPayload) .try_to_vec() @@ -217,7 +222,6 @@ impl server::RequestProcessor for Proxy { let resp = match ProxyMsg::try_from_slice(&req_bytes) { Ok(req) => match req { ProxyMsg::StatusRequest => { - println!("Proxy processing StatusRequest"); ProxyMsg::StatusResponse(self.connections.len()) } ProxyMsg::ConnectByNameRequest { @@ -225,35 +229,25 @@ impl server::RequestProcessor for Proxy { port, dns_resolvers, dns_port, - } => { - println!("Proxy connecting to {hostname}:{port}"); - let resp = self.connect_by_name( - hostname.clone(), - port, - dns_resolvers, - dns_port, - ); - println!("Proxy connected to {hostname}:{port}"); - resp - } + } => self.connect_by_name( + hostname.clone(), + port, + dns_resolvers, + dns_port, + ), ProxyMsg::ConnectByIpRequest { ip, port } => { - println!("Proxy connecting to {ip}:{port}"); self.connect_by_ip(ip, port) } ProxyMsg::CloseRequest { connection_id } => { - println!("Proxy closing connection {connection_id}"); self.close(connection_id) } ProxyMsg::ReadRequest { connection_id, size } => { - println!("Proxy reading {size} bytes from connection {connection_id}"); self.read(connection_id, size) } ProxyMsg::WriteRequest { connection_id, data } => { - println!("Proxy writing to connection {connection_id}"); self.write(connection_id, data) } ProxyMsg::FlushRequest { connection_id } => { - println!("Proxy flushing connection {connection_id}"); self.flush(connection_id) } ProxyMsg::ProxyError(_) => { diff --git a/src/qos_net/src/proxy_connection.rs b/src/qos_net/src/proxy_connection.rs index ef6b390e..c44a6e63 100644 --- a/src/qos_net/src/proxy_connection.rs +++ b/src/qos_net/src/proxy_connection.rs @@ -32,20 +32,15 @@ impl ProxyConnection { dns_resolvers: Vec, dns_port: u16, ) -> Result { - 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::(); - 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(), @@ -93,7 +88,6 @@ fn resolve_hostname( resolver_addrs: Vec, port: u16, ) -> Result { - println!("resolving hostname..."); let resolver_parsed_addrs = resolver_addrs .iter() .map(|resolver_address| { @@ -113,12 +107,8 @@ fn resolve_hostname( ), ); let resolver = Resolver::new(resolver_config, ResolverOpts::default())?; - println!("resolver ready"); - let response = resolver.lookup_ip(hostname.clone()).map_err(|e| { - println!("error invoking resolver: {:?}", e); - QosNetError::from(e) - })?; - println!("resolver successfully invoked"); + let response = + resolver.lookup_ip(hostname.clone()).map_err(QosNetError::from)?; response.iter().next().ok_or_else(|| { QosNetError::DNSResolutionError(format!( "Empty response when querying for host {hostname}" diff --git a/src/qos_net/src/proxy_stream.rs b/src/qos_net/src/proxy_stream.rs index a9f63a46..b3e35fe1 100644 --- a/src/qos_net/src/proxy_stream.rs +++ b/src/qos_net/src/proxy_stream.rs @@ -181,7 +181,6 @@ impl Read for ProxyStream { for (i, b) in data.iter().enumerate() { buf[i] = *b } - println!("READ {}: read {} bytes", buf.len(), size); Ok(size) } ProxyMsg::ProxyError(e) => Err(std::io::Error::new( @@ -240,7 +239,6 @@ impl Write for ProxyStream { "Write failed: 0 bytes written", )); } - println!("WRITE {}: sent buf of {} bytes", buf.len(), size); Ok(size) } _ => Err(std::io::Error::new( @@ -284,10 +282,7 @@ impl Write for ProxyStream { match ProxyMsg::try_from_slice(&resp_bytes) { Ok(resp) => match resp { - ProxyMsg::FlushResponse { connection_id: _ } => { - println!("FLUSH OK"); - Ok(()) - } + ProxyMsg::FlushResponse { connection_id: _ } => Ok(()), _ => Err(std::io::Error::new( ErrorKind::InvalidData, "unexpected response", @@ -459,7 +454,6 @@ mod test { for (i, b) in data.iter().enumerate() { buf[i] = *b } - println!("READ {}: read {} bytes", buf.len(), size); Ok(size) } ProxyMsg::ProxyError(e) => Err(std::io::Error::new( @@ -498,7 +492,6 @@ mod test { "failed Write", )); } - println!("WRITE {}: sent {} bytes", buf.len(), size,); Ok(size) } _ => Err(std::io::Error::new( @@ -522,10 +515,7 @@ mod test { match ProxyMsg::try_from_slice(&resp_bytes) { Ok(resp) => match resp { - ProxyMsg::FlushResponse { connection_id: _ } => { - println!("FLUSH OK"); - Ok(()) - } + ProxyMsg::FlushResponse { connection_id: _ } => Ok(()), _ => Err(std::io::Error::new( ErrorKind::InvalidData, "unexpected response",