Skip to content

Commit

Permalink
Remove Request::Forward and related functions
Browse files Browse the repository at this point in the history
Forwarding messages between agents is no longer supported.
  • Loading branch information
msk committed Mar 26, 2024
1 parent a37d92b commit 9351072
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 401 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and
this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Removed

- `RequestCode::Forward` and `message::send_forward_request`, since forwarding
messages between agents is no longer supported.

## [0.11.0] - 2024-03-25

### Changed
Expand Down Expand Up @@ -263,6 +270,7 @@ without relying on the content of the response.

- `send_frame` and `recv_frame` to send and receive length-delimited frames.

[Unreleased]: https://github.com/petabi/oinq/compare/0.11.0...main
[0.11.0]: https://github.com/petabi/oinq/compare/0.10.0...0.11.0
[0.10.0]: https://github.com/petabi/oinq/compare/0.9.3...0.10.0
[0.9.3]: https://github.com/petabi/oinq/compare/0.9.2...0.9.3
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ pub enum RequestCode {
/// Stop DNS filtering
DnsStop = 2,

/// Forward a request to another agent
Forward = 3,

/// Reboot the host
Reboot = 4,

Expand Down
61 changes: 1 addition & 60 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Functions and errors for handling messages.

use crate::{
frame::{self, RecvError, SendError},
RequestCode,
};
use crate::frame::{self, RecvError, SendError};
use bincode::Options;
use quinn::{Connection, ConnectionError, RecvStream, SendStream};
use semver::{Version, VersionReq};
Expand Down Expand Up @@ -234,38 +231,6 @@ where
Ok(())
}

/// Sends a request encapsulated in a `RequestCode::Forward` request, with a
/// big-endian 4-byte length header.
///
/// `buf` will be cleared after the response is sent.
///
/// # Errors
///
/// * `SendError::SerializationFailure` if the message could not be serialized
/// * `SendError::WriteError` if the message could not be written
pub async fn send_forward_request<C, B>(
send: &mut SendStream,
mut buf: &mut Vec<u8>,
dst: &str,
code: C,
body: B,
) -> Result<(), SendError>
where
C: Into<u32>,
B: Serialize,
{
buf.clear();
buf.extend_from_slice(&u32::from(RequestCode::Forward).to_le_bytes());
let codec = bincode::DefaultOptions::new();
codec.serialize_into(&mut buf, dst)?;
let len = codec.serialized_size(&body)? + mem::size_of::<u32>() as u64;
codec.serialize_into(&mut buf, &len)?;
serialize_request(buf, code, body)?;
frame::send_raw(send, buf).await?;
buf.clear();
Ok(())
}

/// Serializes the given request and appends it to `buf`.
///
/// # Errors
Expand Down Expand Up @@ -319,8 +284,6 @@ pub async fn send_err<E: fmt::Display>(
mod tests {
use crate::test::{channel, TOKEN};
use crate::{frame, RequestCode};
use bincode::Options;
use std::mem;

#[tokio::test]
async fn handshake() {
Expand Down Expand Up @@ -451,28 +414,6 @@ mod tests {
.unwrap();
assert_eq!(code, u32::from(RequestCode::ReloadTi));
assert!(body.is_empty());

buf.clear();
super::send_forward_request(
&mut channel.server.send,
&mut buf,
"agent@host",
RequestCode::ReloadTi,
(),
)
.await
.unwrap();
let (code, body) = super::recv_request_raw(&mut channel.client.recv, &mut buf)
.await
.unwrap();
assert_eq!(code, u32::from(RequestCode::Forward));
let (dst, msg) = bincode::DefaultOptions::new()
.deserialize::<(String, &[u8])>(body)
.unwrap();
assert_eq!(dst, "agent@host");
assert_eq!(msg.len(), mem::size_of::<u32>());
let code = u32::from_le_bytes(msg[..mem::size_of::<u32>()].try_into().expect("4 bytes"));
assert_eq!(RequestCode::from(code), RequestCode::ReloadTi);
}

#[tokio::test]
Expand Down
Loading

0 comments on commit 9351072

Please sign in to comment.