Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove application-dependent code #73

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- `request::parse_args` and `request::send_response` to help implementing
request handlers.

### Changed

- `SendError::MessageTooLarge` no longer contains the underlying error,
Expand All @@ -20,8 +25,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).

- `RequestCode::Forward` and `message::send_forward_request`, since forwarding
messages between agents is no longer supported.
- `client_handshake`, `server_handshake`, `HandshakeError`, and `AgentInfo`.
These belong to the `review-protocol` crate.
- `client_handshake`, `server_handshake`, `HandshakeError`, `AgentInfo`, the
request handler implementation, and those types and functions used by the
request handler. These belong to the `review-protocol` crate.

## [0.11.0] - 2024-03-25

Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ repository = "https://github.com/petabi/oinq"
license = "Apache-2.0"

[dependencies]
async-trait = "0.1"
bincode = "1"
futures = "0.3"
ipnet = { version = "2", features = ["serde"] }
num_enum = "0.7"
quinn = "0.10"
serde = { version = "1", features = ["derive"] }
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Oinq

Oinq implements the communication protocol between agents in the REview
ecosystem using QUIC.
Oinq is a crate focused on providing low-level network communication primitives
using QUIC, suitable for applications implementing RPC-like protocols. This
crate is designed to offer foundational support for efficient and secure message
and stream handling over the network.

## License

Expand Down
88 changes: 0 additions & 88 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,3 @@ pub mod message;
pub mod request;
#[cfg(test)]
mod test;

use num_enum::{FromPrimitive, IntoPrimitive};
pub use request::{Config, Process, ResourceUsage};

/// Numeric representation of the message types.
#[derive(Clone, Copy, Debug, Eq, FromPrimitive, IntoPrimitive, PartialEq)]
#[repr(u32)]
pub enum RequestCode {
/// Start DNS filtering
DnsStart = 1,

/// Stop DNS filtering
DnsStop = 2,

/// Reboot the host
Reboot = 4,

/// Reload the configuration
ReloadConfig = 6,

/// Fetch the TI database and reload it
ReloadTi = 5,

/// Collect resource usage stats
ResourceUsage = 7,

/// Update the list of tor exit nodes
TorExitNodeList = 8,

/// Update the list of sampling policies
SamplingPolicyList = 9,

/// Update traffic filter rules
ReloadFilterRule = 10,

/// Get configuration
GetConfig = 11,

/// Set Configuration
SetConfig = 12,

/// Delete the list of sampling policies
DeleteSamplingPolicy = 13,

/// Update the list of Internal network
InternalNetworkList = 14,

/// Update the list of allow
AllowList = 15,

/// Update the list of block
BlockList = 16,

/// Request Echo (for ping)
EchoRequest = 17,

/// Update the list of trusted User-agent
TrustedUserAgentList = 18,

/// Update the list of trusted domains
TrustedDomainList = 0,

/// Collect process list
ProcessList = 19,

/// Update the semi-supervised models
SemiSupervisedModels = 20,

/// Shutdown the host
Shutdown = 21,

/// Unknown request
#[num_enum(default)]
Unknown = u32::MAX,
}

#[cfg(test)]
mod tests {
use num_enum::FromPrimitive;

use super::RequestCode;

#[test]
fn serde() {
assert_eq!(7u32, u32::from(RequestCode::ResourceUsage));
assert_eq!(RequestCode::ResourceUsage, RequestCode::from_primitive(7));
}
}
16 changes: 6 additions & 10 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,24 @@ pub async fn send_err<E: fmt::Display>(

#[cfg(test)]
mod tests {
use crate::frame;
use crate::test::{channel, TOKEN};
use crate::{frame, RequestCode};

#[tokio::test]
async fn send_and_recv() {
let _lock = TOKEN.lock().await;
let mut channel = channel().await;

const CODE: u32 = 0x1234;
let mut buf = Vec::new();
super::send_request(
&mut channel.server.send,
&mut buf,
RequestCode::ReloadTi,
(),
)
.await
.unwrap();
super::send_request(&mut channel.server.send, &mut buf, CODE, ())
.await
.unwrap();
assert!(buf.is_empty());
let (code, body) = super::recv_request_raw(&mut channel.client.recv, &mut buf)
.await
.unwrap();
assert_eq!(code, u32::from(RequestCode::ReloadTi));
assert_eq!(code, CODE);
assert!(body.is_empty());
}

Expand Down
Loading