✅ add test for old-style Response packets
parent
6dc4eb2771
commit
ca8fcc1104
14
src/main.rs
14
src/main.rs
|
@ -78,21 +78,20 @@ fn main () -> Result <(), AppError> {
|
|||
|
||||
let subcommand: Option <String> = args.next ();
|
||||
|
||||
let mut common_params = CommonParams::default ();
|
||||
|
||||
match subcommand.as_ref ().map (|x| &x[..]) {
|
||||
None => return Err (CliArgError::MissingSubcommand.into ()),
|
||||
Some ("client") => client (&common_params)?,
|
||||
Some ("server") => server (&common_params)?,
|
||||
Some ("client") => client ()?,
|
||||
Some ("server") => server (args)?,
|
||||
Some (x) => return Err (CliArgError::UnknownSubcommand (x.to_string ()).into ()),
|
||||
}
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
||||
fn client (common_params: &CommonParams) -> Result <(), AppError> {
|
||||
fn client () -> Result <(), AppError> {
|
||||
use rand::RngCore;
|
||||
|
||||
let mut common_params = CommonParams::default ();
|
||||
let socket = UdpSocket::bind ("0.0.0.0:0")?;
|
||||
|
||||
socket.join_multicast_v4 (&common_params.multicast_addr, &([0u8, 0, 0, 0].into ()))?;
|
||||
|
@ -143,8 +142,11 @@ fn client (common_params: &CommonParams) -> Result <(), AppError> {
|
|||
Ok (())
|
||||
}
|
||||
|
||||
fn server (common_params: &CommonParams) -> Result <(), AppError>
|
||||
fn server <I: Iterator <Item=String>> (args: I) -> Result <(), AppError>
|
||||
{
|
||||
let mut common_params = CommonParams::default ();
|
||||
let mut nickname = String::new ();
|
||||
|
||||
let our_mac = get_mac_address ()?.map (|x| x.bytes ());
|
||||
if our_mac.is_none () {
|
||||
println! ("Warning: Can't find our own MAC address. We won't be able to respond to MAC-specific lookaround requests");
|
||||
|
|
|
@ -113,8 +113,27 @@ impl Message {
|
|||
|
||||
#[cfg (test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_1 () {
|
||||
|
||||
for (input, expected) in [
|
||||
(
|
||||
Message::Response (Some ([0x11, 0x22, 0x33, 0x44, 0x55, 0x66])),
|
||||
vec! [
|
||||
// Magic number for LookAround packets
|
||||
154, 74, 67, 129,
|
||||
// Response tag
|
||||
2,
|
||||
// MAC is Some
|
||||
1,
|
||||
// MAC
|
||||
17, 34, 51, 68, 85, 102,
|
||||
],
|
||||
),
|
||||
].into_iter () {
|
||||
let actual = input.to_vec ().unwrap ();
|
||||
assert_eq! (actual, expected, "{:?}", input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue