Skip to content

Commit

Permalink
Improve Sustenet as a whole, primarily the Client.
Browse files Browse the repository at this point in the history
Create macros for client. Integrate joining a cluster.

Improve both master and cluster.

Remove the FromCluster and ToCluster packet sections.

Create a ClusterInfo struct to track clusters easier.
  • Loading branch information
Makosai committed Dec 28, 2024
1 parent 1098e7b commit cd48aa0
Show file tree
Hide file tree
Showing 6 changed files with 471 additions and 140 deletions.
47 changes: 47 additions & 0 deletions rust/client/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// This calls loop and select! in a single macro.
#[macro_export]
macro_rules! lselect {
($($select_body:tt)*) => {
loop {
tokio::select! {
$($select_body)*
}
}
};
}

/// This reads a u8 for the length and then calls read_exact
/// to read the bytes then converts it to a string.
///
/// This is used in a loop to continue if an error occurs.
#[macro_export]
macro_rules! lread_string {
($reader:expr, $error:expr, $name:expr) => {
{
let len = match $reader.read_u8().await {
Ok(len) => len,
Err(e) => {
$error(format!("Failed to read the {} len. {:?}", $name, e).as_str());
continue;
}
} as usize;

let mut val = vec![0u8; len];
match $reader.read_exact(&mut val).await {
Ok(_) => (),
Err(e) => {
$error(format!("Failed to read the {}. {:?}", $name, e).as_str());
continue;
}
};

match String::from_utf8(val) {
Ok(val) => val,
Err(e) => {
$error(format!("Failed to convert the {} to a String. {:?}", $name, e).as_str());
continue;
}
}
}
};
}
Loading

0 comments on commit cd48aa0

Please sign in to comment.