Skip to content

Commit

Permalink
improve debugability
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesFoundation committed Aug 28, 2024
1 parent 8f8e460 commit 87462a8
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions stratum-v1/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
.position(|&c| c == b'\n')
{
let line = &self.rx_buf[start..stop];
debug!("Received Message: {}", core::str::from_utf8(line).unwrap());
trace!(
"^^^ start: {}, stop: {}, free: {} ^^^",
start,
stop,
self.rx_free_pos
debug!(
"Received Message [{}..{}], free pos: {}",
start, stop, self.rx_free_pos
);
trace!("{}", line);
if let Some(id) = response::parse_id(line)? {
// it's a Response
match self.reqs.get(&id) {
Expand Down Expand Up @@ -187,6 +185,7 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
start = stop + 1;
}
if start > 0 && self.rx_free_pos > start {
debug!("copy {} bytes @0", self.rx_free_pos - start);
self.rx_buf.copy_within(start..self.rx_free_pos, 0);
self.rx_free_pos -= start;
}
Expand All @@ -200,12 +199,8 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
.read(self.rx_buf[self.rx_free_pos..].as_mut())
.await
.map_err(|_| Error::NetworkError)?;
trace!(
"read {} bytes, free {}: {}",
n,
self.rx_free_pos,
core::str::from_utf8(&self.rx_buf[self.rx_free_pos..self.rx_free_pos + n]).unwrap()
);
debug!("read {} bytes @{}", n, self.rx_free_pos);
trace!("{}", &self.rx_buf[self.rx_free_pos..self.rx_free_pos + n]);
self.rx_free_pos += n;
}
Ok(msg)
Expand All @@ -221,6 +216,7 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u

async fn send_req(&mut self, req_len: usize) -> Result<()> {
self.tx_buf[req_len] = 0x0a;
trace!("{}", &self.tx_buf[..req_len + 1]);
self.network_conn
.write_all(&self.tx_buf[..req_len + 1])
.await
Expand All @@ -239,10 +235,7 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
}
self.prepare_req(ReqKind::Configure)?;
let n = request::configure(self.req_id, exts, self.tx_buf.as_mut_slice())?;
debug!(
"Send Configure: {}",
core::str::from_utf8(&self.tx_buf[..n]).unwrap()
);
debug!("Send Configure: {} bytes, id = {}", n, self.req_id);
self.send_req(n).await
}

Expand All @@ -261,10 +254,7 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
}
self.prepare_req(ReqKind::Connect)?;
let n = request::connect(self.req_id, identifier, self.tx_buf.as_mut_slice())?;
debug!(
"Send Connect: {}",
core::str::from_utf8(&self.tx_buf[..n]).unwrap()
);
debug!("Send Connect: {} bytes, id = {}", n, self.req_id);
self.send_req(n).await
}

Expand All @@ -287,10 +277,7 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
self.prepare_req(ReqKind::Authorize)?;
self.user = user.clone();
let n = request::authorize(self.req_id, user, pass, self.tx_buf.as_mut_slice())?;
debug!(
"Send Authorize: {}",
core::str::from_utf8(&self.tx_buf[..n]).unwrap()
);
debug!("Send Authorize: {} bytes, id = {}", n, self.req_id);
self.send_req(n).await
}

Expand Down Expand Up @@ -319,10 +306,7 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
share,
self.tx_buf.as_mut_slice(),
)?;
debug!(
"Send Submit: {}",
core::str::from_utf8(&self.tx_buf[..n]).unwrap()
);
debug!("Send Submit: {} bytes, id = {}", n, self.req_id);
self.send_req(n).await
}
}

0 comments on commit 87462a8

Please sign in to comment.