fix(rust): ensure onward route is not empty before checking addr type
@@ -95,24 +95,11 @@ pub mod transport {
pub fn receive_message(&mut self) -> Result<bool, String> {
let mut buff = [0; 16348];
match self.socket.recv_from(&mut buff) {
- Ok((s, a)) => {
- // println!("received:");
- // let b: Vec<u8> = buff[0..100].to_vec();
- // println!("{:?}", b);
- match Message::decode(&buff[0..s]) {
+ Ok((s, a)) => match Message::decode(&buff[0..s]) {
Ok((mut m, _unused)) => {
- // println!("Received message type: {:?}\nOnward route:",
- // m.message_type); m.onward_route.
- // print_route(); println!("Return route:");
- // m.return_route.print_route();
- // match m.message_type {
- // MessageType::Payload => {
- // println!("Payload: {}",
- // std::str::from_utf8(&m.message_body).unwrap());
- // }
- // _ => {}
- // }
- if m.onward_route.addresses[0].a_type == AddressType::Udp {
+ if !m.onward_route.addresses.is_empty()
+ && m.onward_route.addresses[0].a_type == AddressType::Udp
+ {
match self.send_message(m) {
Err(s) => Err(s),
Ok(()) => Ok(true),
@@ -125,8 +112,7 @@ pub mod transport {
}
}
_ => Err("decode failed".to_string()),
- }
- }
+ },
Err(e) => match e.kind() {
io::ErrorKind::WouldBlock => Ok(false),
_ => Err("socket receive failed".to_string()),
