i played a round of netpong with tls
cargo devel CI / cargo CI (push) Successful in 2m16s Details

This commit is contained in:
Christoph J. Scherr 2024-01-24 16:12:31 +01:00
parent 25375eca32
commit 0a37691e05
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
3 changed files with 9 additions and 9 deletions

View File

@ -62,12 +62,12 @@ impl Client {
let mut stream = self.connector.connect(self.domain, self.stream).await?;
let mut buf = [0; BUF_SIZE];
stream.write_all(b"ping").await?;
info!("> {:?} ping", self.cfg.hostname);
info!("> {} ping", self.cfg.hostname);
while stream.read(&mut buf).await? > 0 {
let response = decode(&buf)?;
info!("< {:?}\n{}", self.cfg.hostname, response);
info!("< {} \"{}\"", self.cfg.hostname, response);
stream.write_all(b"ping").await?;
info!("> {:?} ping", self.cfg.hostname);
info!("> {} ping", self.cfg.hostname);
// we should wait, so that we don't spam the client
std::thread::sleep(self.cfg.delay);
}

View File

@ -5,8 +5,8 @@ pub mod conf;
#[inline]
pub fn decode(buf: &[u8]) -> Result<String, Utf8Error> {
match std::str::from_utf8(buf) {
Ok(s) => Ok(s.to_string()),
Err(err) => Err(err.into()),
}
Ok(match std::str::from_utf8(buf) {
Ok(s) => s.to_string(),
Err(err) => return Err(err.into()),
}.trim_matches(char::from(0)).to_string())
}

View File

@ -162,8 +162,8 @@ impl Server {
debug!("new peer: {:?}", addr);
while stream.read(&mut buf).await? > 0 {
let request = decode(&buf)?;
debug!("< {:?}\n{}", addr, request);
if request == "ping" {
debug!(pings, "< {:?}\n\"{:X?}\"", addr, request);
if request == format!("ping") {
pings += 1;
if pings > self.cfg.win_after {
stream.write_all(b"You win!").await?;