generated from PlexSheep/rs-base
i played a round of netpong with tls
cargo devel CI / cargo CI (push) Successful in 2m16s
Details
cargo devel CI / cargo CI (push) Successful in 2m16s
Details
This commit is contained in:
parent
25375eca32
commit
0a37691e05
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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?;
|
||||
|
|
Loading…
Reference in New Issue