Broken status message to client

status
~erin 2023-04-02 22:06:51 -04:00
parent 1282848df3
commit b7251620cc
Signed by: erin
GPG Key ID: 9A8E308CEFA37A47
2 changed files with 47 additions and 9 deletions

View File

@ -2,11 +2,16 @@ use paris::{error, info, success};
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::fmt;
use tokio::io::AsyncWriteExt;
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
use tokio::net::TcpStream;
use url::Url;
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug)]
struct Status {
status: bool,
}
#[derive(Serialize, Deserialize, Debug)]
enum BuildSystem {
Cargo,
@ -80,8 +85,12 @@ struct Message {
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Connect to a peer
let mut stream = TcpStream::connect("127.0.0.1:9134").await?;
let mut stream = TcpStream::connect("127.0.0.1:9134").await.unwrap();
success!("Connected to: <green>127.0.0.1:9134<//>");
let (reader, mut writer) = stream.split();
let mut reader = BufReader::new(reader);
let mut line = String::new();
let test_command = Command {
build_system: BuildSystem::Cargo,
@ -99,12 +108,30 @@ async fn main() -> Result<(), Box<dyn Error>> {
basename: "serde_json".to_string(),
};
let j = serde_json::to_string(&test_message)?;
stream.write_all(&j.as_bytes()).await?;
let j = serde_json::to_string(&test_message).unwrap();
writer.write_all(&j.as_bytes()).await.unwrap();
info!(
"Sent JSON:\n<bright-white>{}<//>",
serde_json::to_string_pretty(&test_message)?
serde_json::to_string_pretty(&test_message).unwrap()
);
loop {
info!("{}", &line);
let bytes_read = reader.read_line(&mut line).await.unwrap();
let json: Status = match serde_json::from_str(&line) {
Ok(v) => v,
Err(e) => {
error!("{}", e);
break;
}
};
info!(
"Got JSON:\n<bright-white>{}<//>",
serde_json::to_string_pretty(&test_message).unwrap()
);
}
Ok(())
}

View File

@ -12,6 +12,11 @@ use url::Url;
use uuid::Uuid;
use uuid_simd::UuidExt;
#[derive(Serialize, Deserialize)]
struct Status {
status: bool,
}
#[derive(Serialize, Deserialize)]
struct HostConfig {
ip: String,
@ -165,7 +170,7 @@ async fn process_socket(
salt: SaltString,
argon2: Argon2<'_>,
) {
let (reader, writer) = socket.split();
let (reader, mut writer) = socket.split();
let mut reader = BufReader::new(reader);
let mut line = String::new();
@ -191,9 +196,11 @@ async fn process_socket(
.authenticate(pass.clone(), salt.clone(), argon2.clone())
.await
{
tokio::spawn(async move {
build(json, address).await;
});
build(json, address).await;
let status = Status { status: true };
let j_status = serde_json::to_string(&status).unwrap();
info!("<bright-white>{}<//>", j_status);
writer.write_all(j_status.as_bytes()).await.unwrap();
}
}
None => {
@ -202,6 +209,10 @@ async fn process_socket(
}
} else {
build(json, address).await;
let status = Status { status: true };
let j_status = serde_json::to_string(&status).unwrap();
info!("<bright-white>{}<//>", j_status);
writer.write_all(j_status.as_bytes()).await.unwrap();
}
}
}