|
|
@ -1,9 +1,7 @@ |
|
|
|
use std::net; |
|
|
|
use std::net; |
|
|
|
use alloc::vec; |
|
|
|
|
|
|
|
use alloc::vec::Vec; |
|
|
|
use alloc::vec::Vec; |
|
|
|
use alloc::string::String; |
|
|
|
use alloc::string::String; |
|
|
|
|
|
|
|
|
|
|
|
use crate::interface; |
|
|
|
|
|
|
|
use crate::interface::{Interface, InterfaceRequirements, TargetingData}; |
|
|
|
use crate::interface::{Interface, InterfaceRequirements, TargetingData}; |
|
|
|
use crate::message::MessageBytes; |
|
|
|
use crate::message::MessageBytes; |
|
|
|
use crate::res::{IFError, IFResult}; |
|
|
|
use crate::res::{IFError, IFResult}; |
|
|
@ -18,6 +16,8 @@ pub struct IPInterface { |
|
|
|
pub listener: net::TcpListener, |
|
|
|
pub listener: net::TcpListener, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl InterfaceRequirements for IPInterface {} |
|
|
|
|
|
|
|
|
|
|
|
impl Interface for IPInterface { |
|
|
|
impl Interface for IPInterface { |
|
|
|
fn main_loop_iteration(&mut self) -> IFResult<()> { |
|
|
|
fn main_loop_iteration(&mut self) -> IFResult<()> { |
|
|
|
println!("Mainloop {:?}", self.listener.local_addr()); |
|
|
|
println!("Mainloop {:?}", self.listener.local_addr()); |
|
|
@ -43,10 +43,10 @@ impl Interface for IPInterface { |
|
|
|
for mut connection in &self.connections { |
|
|
|
for mut connection in &self.connections { |
|
|
|
|
|
|
|
|
|
|
|
let mut size_arr: [u8; 4] = [0, 0, 0, 0]; |
|
|
|
let mut size_arr: [u8; 4] = [0, 0, 0, 0]; |
|
|
|
connection.read(&mut size_arr); |
|
|
|
connection.read_exact(&mut size_arr)?; |
|
|
|
let mut size: u32 = 0; |
|
|
|
let mut size: u32 = 0; |
|
|
|
for i in 0..4 { |
|
|
|
for size_byte in &size_arr { |
|
|
|
size = size * 256 + size_arr[i] as u32; |
|
|
|
size = size * 256 + *size_byte as u32; |
|
|
|
} |
|
|
|
} |
|
|
|
println!("Size: {:?}", size); |
|
|
|
println!("Size: {:?}", size); |
|
|
|
|
|
|
|
|
|
|
@ -63,7 +63,7 @@ impl Interface for IPInterface { |
|
|
|
&*self.id |
|
|
|
&*self.id |
|
|
|
} |
|
|
|
} |
|
|
|
fn send(&mut self, message: &[u8], interface_data: Option<TargetingData>) -> IFResult<()> { |
|
|
|
fn send(&mut self, message: &[u8], interface_data: Option<TargetingData>) -> IFResult<()> { |
|
|
|
let mut addr: net::SocketAddr = match interface_data { |
|
|
|
let addr: net::SocketAddr = match interface_data { |
|
|
|
Some(ip_string) => ip_string.parse().expect("Unable to parse address"), |
|
|
|
Some(ip_string) => ip_string.parse().expect("Unable to parse address"), |
|
|
|
None => return Err(IFError::General(String::from("Not enough info to create connection"))) |
|
|
|
None => return Err(IFError::General(String::from("Not enough info to create connection"))) |
|
|
|
}; |
|
|
|
}; |
|
|
@ -79,7 +79,7 @@ impl Interface for IPInterface { |
|
|
|
|
|
|
|
|
|
|
|
println!("Sending message to {:?}", self.connections[index].peer_addr().unwrap()); |
|
|
|
println!("Sending message to {:?}", self.connections[index].peer_addr().unwrap()); |
|
|
|
|
|
|
|
|
|
|
|
self.connections[index].write(message); |
|
|
|
self.connections[index].write_all(message)?; |
|
|
|
|
|
|
|
|
|
|
|
println!("Sent message"); |
|
|
|
println!("Sent message"); |
|
|
|
|
|
|
|
|
|
|
|