Skip to content

Commit 89e3535

Browse files
committed
Adjust logging to be less verbose
1 parent 61fbca6 commit 89e3535

File tree

3 files changed

+23
-49
lines changed

3 files changed

+23
-49
lines changed

src/qos_net/src/proxy.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,19 @@ impl Proxy {
104104
Ok(conn) => {
105105
let connection_id = conn.id;
106106
let remote_ip = conn.ip.clone();
107-
println!("called new_from_name successfully. Saving connection ID {connection_id}...");
108107
match self.save_connection(conn) {
109108
Ok(()) => {
110-
println!("Connection established and saved. Returning ConnectResponse to client");
109+
println!("Connection to {hostname} established and saved as ID {connection_id}");
111110
ProxyMsg::ConnectResponse { connection_id, remote_ip }
112111
}
113112
Err(e) => {
114-
println!("error saving connection.");
113+
println!("error saving connection: {e:?}");
115114
ProxyMsg::ProxyError(e)
116115
}
117116
}
118117
}
119118
Err(e) => {
120-
println!("error calling new_from_name");
119+
println!("error while establishing connection: {e:?}");
121120
ProxyMsg::ProxyError(e)
122121
}
123122
}
@@ -126,18 +125,25 @@ impl Proxy {
126125
/// Create a new connection, targeting an IP address directly.
127126
/// address. The TCP connection is opened and saved in internal state.
128127
pub fn connect_by_ip(&mut self, ip: String, port: u16) -> ProxyMsg {
129-
match proxy_connection::ProxyConnection::new_from_ip(ip, port) {
128+
match proxy_connection::ProxyConnection::new_from_ip(ip.clone(), port) {
130129
Ok(conn) => {
131130
let connection_id = conn.id;
132131
let remote_ip = conn.ip.clone();
133132
match self.save_connection(conn) {
134133
Ok(()) => {
134+
println!("Connection to {ip} established and saved as ID {connection_id}");
135135
ProxyMsg::ConnectResponse { connection_id, remote_ip }
136136
}
137-
Err(e) => ProxyMsg::ProxyError(e),
137+
Err(e) => {
138+
println!("error saving connection: {e:?}");
139+
ProxyMsg::ProxyError(e)
140+
}
138141
}
139142
}
140-
Err(e) => ProxyMsg::ProxyError(e),
143+
Err(e) => {
144+
println!("error while establishing connection: {e:?}");
145+
ProxyMsg::ProxyError(e)
146+
}
141147
}
142148
}
143149

@@ -207,7 +213,6 @@ impl Proxy {
207213

208214
impl server::RequestProcessor for Proxy {
209215
fn process(&mut self, req_bytes: Vec<u8>) -> Vec<u8> {
210-
println!("Proxy processing request");
211216
if req_bytes.len() > MAX_ENCODED_MSG_LEN {
212217
return ProxyMsg::ProxyError(QosNetError::OversizedPayload)
213218
.try_to_vec()
@@ -217,43 +222,32 @@ impl server::RequestProcessor for Proxy {
217222
let resp = match ProxyMsg::try_from_slice(&req_bytes) {
218223
Ok(req) => match req {
219224
ProxyMsg::StatusRequest => {
220-
println!("Proxy processing StatusRequest");
221225
ProxyMsg::StatusResponse(self.connections.len())
222226
}
223227
ProxyMsg::ConnectByNameRequest {
224228
hostname,
225229
port,
226230
dns_resolvers,
227231
dns_port,
228-
} => {
229-
println!("Proxy connecting to {hostname}:{port}");
230-
let resp = self.connect_by_name(
231-
hostname.clone(),
232-
port,
233-
dns_resolvers,
234-
dns_port,
235-
);
236-
println!("Proxy connected to {hostname}:{port}");
237-
resp
238-
}
232+
} => self.connect_by_name(
233+
hostname.clone(),
234+
port,
235+
dns_resolvers,
236+
dns_port,
237+
),
239238
ProxyMsg::ConnectByIpRequest { ip, port } => {
240-
println!("Proxy connecting to {ip}:{port}");
241239
self.connect_by_ip(ip, port)
242240
}
243241
ProxyMsg::CloseRequest { connection_id } => {
244-
println!("Proxy closing connection {connection_id}");
245242
self.close(connection_id)
246243
}
247244
ProxyMsg::ReadRequest { connection_id, size } => {
248-
println!("Proxy reading {size} bytes from connection {connection_id}");
249245
self.read(connection_id, size)
250246
}
251247
ProxyMsg::WriteRequest { connection_id, data } => {
252-
println!("Proxy writing to connection {connection_id}");
253248
self.write(connection_id, data)
254249
}
255250
ProxyMsg::FlushRequest { connection_id } => {
256-
println!("Proxy flushing connection {connection_id}");
257251
self.flush(connection_id)
258252
}
259253
ProxyMsg::ProxyError(_) => {

src/qos_net/src/proxy_connection.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,15 @@ impl ProxyConnection {
3232
dns_resolvers: Vec<String>,
3333
dns_port: u16,
3434
) -> Result<ProxyConnection, QosNetError> {
35-
println!("new_from_name invoked");
3635
let ip = resolve_hostname(hostname, dns_resolvers, dns_port)?;
37-
println!("resolved name into an IP");
3836

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

4542
let tcp_addr = SocketAddr::new(ip, port);
46-
println!("TCP addr created. Connecting...");
4743
let tcp_stream = TcpStream::connect(tcp_addr)?;
48-
println!("Connected");
4944
Ok(ProxyConnection {
5045
id: connection_id,
5146
ip: ip.to_string(),
@@ -93,7 +88,6 @@ fn resolve_hostname(
9388
resolver_addrs: Vec<String>,
9489
port: u16,
9590
) -> Result<IpAddr, QosNetError> {
96-
println!("resolving hostname...");
9791
let resolver_parsed_addrs = resolver_addrs
9892
.iter()
9993
.map(|resolver_address| {
@@ -113,12 +107,8 @@ fn resolve_hostname(
113107
),
114108
);
115109
let resolver = Resolver::new(resolver_config, ResolverOpts::default())?;
116-
println!("resolver ready");
117-
let response = resolver.lookup_ip(hostname.clone()).map_err(|e| {
118-
println!("error invoking resolver: {:?}", e);
119-
QosNetError::from(e)
120-
})?;
121-
println!("resolver successfully invoked");
110+
let response =
111+
resolver.lookup_ip(hostname.clone()).map_err(QosNetError::from)?;
122112
response.iter().next().ok_or_else(|| {
123113
QosNetError::DNSResolutionError(format!(
124114
"Empty response when querying for host {hostname}"

src/qos_net/src/proxy_stream.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ impl Read for ProxyStream {
181181
for (i, b) in data.iter().enumerate() {
182182
buf[i] = *b
183183
}
184-
println!("READ {}: read {} bytes", buf.len(), size);
185184
Ok(size)
186185
}
187186
ProxyMsg::ProxyError(e) => Err(std::io::Error::new(
@@ -240,7 +239,6 @@ impl Write for ProxyStream {
240239
"Write failed: 0 bytes written",
241240
));
242241
}
243-
println!("WRITE {}: sent buf of {} bytes", buf.len(), size);
244242
Ok(size)
245243
}
246244
_ => Err(std::io::Error::new(
@@ -284,10 +282,7 @@ impl Write for ProxyStream {
284282

285283
match ProxyMsg::try_from_slice(&resp_bytes) {
286284
Ok(resp) => match resp {
287-
ProxyMsg::FlushResponse { connection_id: _ } => {
288-
println!("FLUSH OK");
289-
Ok(())
290-
}
285+
ProxyMsg::FlushResponse { connection_id: _ } => Ok(()),
291286
_ => Err(std::io::Error::new(
292287
ErrorKind::InvalidData,
293288
"unexpected response",
@@ -459,7 +454,6 @@ mod test {
459454
for (i, b) in data.iter().enumerate() {
460455
buf[i] = *b
461456
}
462-
println!("READ {}: read {} bytes", buf.len(), size);
463457
Ok(size)
464458
}
465459
ProxyMsg::ProxyError(e) => Err(std::io::Error::new(
@@ -498,7 +492,6 @@ mod test {
498492
"failed Write",
499493
));
500494
}
501-
println!("WRITE {}: sent {} bytes", buf.len(), size,);
502495
Ok(size)
503496
}
504497
_ => Err(std::io::Error::new(
@@ -522,10 +515,7 @@ mod test {
522515

523516
match ProxyMsg::try_from_slice(&resp_bytes) {
524517
Ok(resp) => match resp {
525-
ProxyMsg::FlushResponse { connection_id: _ } => {
526-
println!("FLUSH OK");
527-
Ok(())
528-
}
518+
ProxyMsg::FlushResponse { connection_id: _ } => Ok(()),
529519
_ => Err(std::io::Error::new(
530520
ErrorKind::InvalidData,
531521
"unexpected response",

0 commit comments

Comments
 (0)