Skip to content

Commit

Permalink
Going to improve CNS client.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanMcMillan54 committed Oct 2, 2024
1 parent 28f00ed commit 4511075
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
9 changes: 5 additions & 4 deletions darklight_driver/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn cmd_input_thread() {
if STREAMS_HANDLER.stream_info[i].rid == rid
&& STREAMS_HANDLER.stream_info[i].port == port
{
println!("removing...");
println!("Removing...");
STREAMS_HANDLER.remove_stream_file(rid, port);
STREAMS_HANDLER.stream_info.remove(i);
}
Expand All @@ -179,15 +179,16 @@ pub fn cmd_input_thread() {
STREAMS_HANDLER.stream_info.clear();
}

if inputs.len() != 3 {
println!("Invalid arguments");
if inputs.len() != 4 {
println!("Invalid arguments {}", inputs.len());
continue;
}

let arg1 = Box::leak(inputs[1].to_string().into_boxed_str());
let arg2 = Box::leak(inputs[2].to_string().into_boxed_str());
let arg3 = Box::leak(inputs[3].to_string().into_boxed_str());
spawn(move || {
cns_add(vec![arg1, arg2]);
cns_add(vec![arg1, arg2, arg3]);
});
}
_ => {
Expand Down
26 changes: 16 additions & 10 deletions darklight_driver/src/cns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ pub fn cns_add(input: Vec<&str>) {
let readable = is_human_readable_including(input[0].to_string(), vec!['-', '_']);
let parseable = input[1].parse::<u16>().is_ok();
let name = match input[2] {
"0" => format!("{}{}{}", "info.", input[3], ".org"),
"1" => format!("{}{}{}", "info.", input[3], ".com"),
"2" => format!("{}{}{}", "visu.", input[3], ".org"),
"3" => format!("{}{}{}", "visu.", input[3], ".com"),
"4" => format!("{}{}{}", "info.", input[3], ".prs"),
"5" => format!("{}{}{}", "visu.", input[3], ".prs"),
"0" => format!("{}{}{}", "info.", input[0], ".org"),
"1" => format!("{}{}{}", "info.", input[0], ".com"),
"2" => format!("{}{}{}", "visu.", input[0], ".org"),
"3" => format!("{}{}{}", "visu.", input[0], ".com"),
"4" => format!("{}{}{}", "info.", input[0], ".prs"),
"5" => format!("{}{}{}", "visu.", input[0], ".prs"),
_ => {
println!("Invalid option: {}, read (documentation)", input[3]);
return;
Expand Down Expand Up @@ -115,9 +115,8 @@ pub fn cns_add(input: Vec<&str>) {
let mut recv_second = false;
let mut attempts = 0;

println!("sending...");
while stream.running() {
sleep(Duration::from_millis(100));
sleep(Duration::from_millis(10));
if send_first == false {
println!("Sending first...");
stream.write(
Expand All @@ -128,6 +127,11 @@ pub fn cns_add(input: Vec<&str>) {
REQUEST_RESPONSE,
);
send_first = true;

let read = stream.read();
if !read.is_empty() {

}
continue;
}

Expand All @@ -136,12 +140,14 @@ pub fn cns_add(input: Vec<&str>) {
if read.is_empty() {
attempts += 1;

if attempts > 400 {
if attempts > 40 {
attempts = 0;
send_first = false;
}

continue;
}

let contents = contents_to_string(read[0].contents).replace("\0", "");
if read[0].ti.code != REQUEST_CONNECTION.value()
&& read[0].ti.code == REGULAR_RESPONSE.value()
Expand All @@ -164,7 +170,7 @@ pub fn cns_add(input: Vec<&str>) {

if recv_first == true && recv_first == true && send_second == false {
send_second = true;
println!("sending second");
println!("Sending second");
stream.write(
format!(
"REQUEST_ADD1 {} {} {} {} {} {} {}",
Expand Down
2 changes: 2 additions & 0 deletions dl_instance/distributor/distributor/src/distributor/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl DarkLightDistributor {
self.tcp_user_write(stream, self.local_pending_messages[id].message_str.clone());
}
}*/
//println!("on user: {}", id);

if self.local_pending_messages.contains_key(id) {
if self.local_pending_messages[id].message_str == String::new() {
Expand All @@ -109,6 +110,7 @@ impl DarkLightDistributor {
continue;
}

// println!("read: {}", read);
if ri.rdid == self.info.id {
if !self.user_connections.connection_exists(&ri.rid) {
// Notify user that connection doesn't exist
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/dlcns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dlwp::id::{DId, LId, Port};
pub mod get;
pub mod name;

pub const CNS_ID: LId = 1000;
pub const CNS_ID: LId = 9711410197108107101;
pub const CNS_PORT: Port = 4999;
pub const CNS_DISTRIBUTOR: DId = 3;
pub const OWNERS_LIST: &str = "owners_list.json";

0 comments on commit 4511075

Please sign in to comment.