Skip to content

Commit

Permalink
Receiving client and server messages should be working properly in da…
Browse files Browse the repository at this point in the history
…rklight_driver.
  • Loading branch information
NathanMcMillan54 committed Oct 5, 2024
1 parent 717348f commit 070f512
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion darklight_driver/src/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,21 @@ impl StreamsHandler {
let io_method = self.io_method.as_mut().unwrap();
let mut read = io_method._read();
read.0 = read.0.replace("\0", "");
println!("read: {}", read.0);
//println!("read: {}", read.0);

if read.1 == READ_SUCCESS {
let ri = Message::get_ri_from_encoded(&read.0);

if ri.rid == local_user_id().unwrap() {
println!("receving id: {}", ri.rid);
for i in 0..self.stream_info.len() {
// For servers receiving client messages
if self.stream_info[i].rid == local_user_id().unwrap() && self.stream_info[i].port == ri.port {
self.write_to_stream_file(self.stream_info[i].rid, ri.port, &read.0);
continue;
}

// For clients
if self.stream_info[i].port == ri.port {
let ti = Message::decode(&read.0, dlwp::encryption::EncryptionInfo { encode_function: libcerpton_encode, decode_function: libcerpton_decode, info: self.stream_info[i].info }).ti;
println!("writing to stream file");
Expand Down
1 change: 0 additions & 1 deletion dlwp/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ impl Stream {

for line in reader.lines() {
if line.is_ok() {
println!("reading: {:?}", line);
ret.push(line.unwrap());
}
}
Expand Down
7 changes: 7 additions & 0 deletions test_streams/test_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use dlwp::cerpton::{libcerpton_decode, libcerpton_encode};
use dlwp::codes::{Code, REQUEST_RESPONSE, STATUS_OK};
use dlwp::encryption::EncryptionInfo;
use dlwp::message::ReceiveInfo;
use dlwp::stream::{Stream, StreamType};
use std::{thread::sleep, time::Duration};
Expand All @@ -8,6 +10,11 @@ const PORT: u16 = 5000;
fn main() {
let mut stream = Stream::new(StreamType::Server { port: PORT }, false);

stream.add_encryption_info(EncryptionInfo {
encode_function: libcerpton_encode,
decode_function: libcerpton_decode,
info: [2, 1, 2, 0, 0, 0]
});
println!("starting");
let ret = stream.start();
println!("started: {:?}", ret);
Expand Down

0 comments on commit 070f512

Please sign in to comment.