It's alive

This commit is contained in:
John Doty 2022-10-07 13:56:59 +00:00
parent 5e26860731
commit c5bf78fc71
2 changed files with 271 additions and 81 deletions

View file

@ -17,10 +17,10 @@ pub struct PortDesc {
#[derive(Debug, PartialEq)]
pub enum Message {
Ping,
Connect(u64, u16), // Request to connect on a port from client to server.
Connected(u64, u16), // Sucessfully connected from server to client.
Close(u64), // Request to close from client to server.
Abort(u64), // Notify of close from server to client.
Connect(u64, u16), // Request to connect on a port from client to server.
Connected(u64), // Sucessfully connected from server to client.
Close(u64), // Request to close connection on either end.
// Abort(u64), // Notify of close from server to client.
Closed(u64), // Response to Close or Abort.
Refresh, // Request to refresh list of ports from client.
Ports(Vec<PortDesc>), // List of available ports from server to client.
@ -40,19 +40,18 @@ impl Message {
result.put_u64(*channel);
result.put_u16(*port);
}
Connected(channel, port) => {
Connected(channel) => {
result.put_u8(0x02);
result.put_u64(*channel);
result.put_u16(*port);
}
Close(channel) => {
result.put_u8(0x03);
result.put_u64(*channel);
}
Abort(channel) => {
result.put_u8(0x04);
result.put_u64(*channel);
}
// Abort(channel) => {
// result.put_u8(0x04);
// result.put_u64(*channel);
// }
Closed(channel) => {
result.put_u8(0x05);
result.put_u64(*channel);
@ -93,17 +92,16 @@ impl Message {
}
0x02 => {
let channel = get_u64(cursor)?;
let port = get_u16(cursor)?;
Ok(Connected(channel, port))
Ok(Connected(channel))
}
0x03 => {
let channel = get_u64(cursor)?;
Ok(Close(channel))
}
0x04 => {
let channel = get_u64(cursor)?;
Ok(Abort(channel))
}
// 0x04 => {
// let channel = get_u64(cursor)?;
// Ok(Abort(channel))
// }
0x05 => {
let channel = get_u64(cursor)?;
Ok(Closed(channel))
@ -155,9 +153,9 @@ mod message_tests {
fn round_trip() {
assert_round_trip(Ping);
assert_round_trip(Connect(0x1234567890123456, 0x1234));
assert_round_trip(Connected(0x1234567890123456, 0x1234));
assert_round_trip(Connected(0x1234567890123456));
assert_round_trip(Close(0x1234567890123456));
assert_round_trip(Abort(0x1234567890123456));
// assert_round_trip(Abort(0x1234567890123456));
assert_round_trip(Closed(0x1234567890123456));
assert_round_trip(Refresh);
assert_round_trip(Ports(vec![