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 stream = self.connector.connect(self.domain, self.stream).await?;
|
||||||
let mut buf = [0; BUF_SIZE];
|
let mut buf = [0; BUF_SIZE];
|
||||||
stream.write_all(b"ping").await?;
|
stream.write_all(b"ping").await?;
|
||||||
info!("> {:?} ping", self.cfg.hostname);
|
info!("> {} ping", self.cfg.hostname);
|
||||||
while stream.read(&mut buf).await? > 0 {
|
while stream.read(&mut buf).await? > 0 {
|
||||||
let response = decode(&buf)?;
|
let response = decode(&buf)?;
|
||||||
info!("< {:?}\n{}", self.cfg.hostname, response);
|
info!("< {} \"{}\"", self.cfg.hostname, response);
|
||||||
stream.write_all(b"ping").await?;
|
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
|
// we should wait, so that we don't spam the client
|
||||||
std::thread::sleep(self.cfg.delay);
|
std::thread::sleep(self.cfg.delay);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ pub mod conf;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn decode(buf: &[u8]) -> Result<String, Utf8Error> {
|
pub fn decode(buf: &[u8]) -> Result<String, Utf8Error> {
|
||||||
match std::str::from_utf8(buf) {
|
Ok(match std::str::from_utf8(buf) {
|
||||||
Ok(s) => Ok(s.to_string()),
|
Ok(s) => s.to_string(),
|
||||||
Err(err) => Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
}
|
}.trim_matches(char::from(0)).to_string())
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,8 +162,8 @@ impl Server {
|
||||||
debug!("new peer: {:?}", addr);
|
debug!("new peer: {:?}", addr);
|
||||||
while stream.read(&mut buf).await? > 0 {
|
while stream.read(&mut buf).await? > 0 {
|
||||||
let request = decode(&buf)?;
|
let request = decode(&buf)?;
|
||||||
debug!("< {:?}\n{}", addr, request);
|
debug!(pings, "< {:?}\n\"{:X?}\"", addr, request);
|
||||||
if request == "ping" {
|
if request == format!("ping") {
|
||||||
pings += 1;
|
pings += 1;
|
||||||
if pings > self.cfg.win_after {
|
if pings > self.cfg.win_after {
|
||||||
stream.write_all(b"You win!").await?;
|
stream.write_all(b"You win!").await?;
|
||||||
|
|
Loading…
Reference in New Issue