Skip to content

Commit

Permalink
add RequestCode::SemiSupervisedModels
Browse files Browse the repository at this point in the history
  • Loading branch information
syncpark committed Dec 6, 2023
1 parent ba4ff6e commit 607f5e6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 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]

### Added

- Add `RequestCode::SemiSupervisedModels` to update semi-supervised models of
all Hogs.

## [0.9.1] - 2023-09-06

### Added
Expand Down Expand Up @@ -235,6 +242,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.9.1...main
[0.9.1]: https://github.com/petabi/oinq/compare/0.9.0...0.9.1
[0.9.0]: https://github.com/petabi/oinq/compare/0.8.2...0.9.0
[0.8.2]: https://github.com/petabi/oinq/compare/0.8.1...0.8.2
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ pub enum RequestCode {
/// Collect process list
ProcessList = 19,

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

/// Unknown request
#[num_enum(default)]
Unknown = u32::MAX,
Expand Down
8 changes: 3 additions & 5 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub async fn client_handshake(
}

match frame::recv_raw(&mut recv, &mut buf).await {
Ok(_) => {}
Ok(()) => {}
Err(quinn::ReadExactError::FinishedEarly) => {
return Err(HandshakeError::ConnectionClosed);
}
Expand Down Expand Up @@ -317,12 +317,10 @@ pub async fn send_err<E: fmt::Display>(

#[cfg(test)]
mod tests {
use std::mem;

use bincode::Options;

use crate::test::{channel, TOKEN};
use crate::{frame, RequestCode};
use bincode::Options;
use std::mem;

#[tokio::test]
async fn handshake() {
Expand Down
9 changes: 8 additions & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ pub trait Handler: Send {
async fn process_list(&mut self) -> Result<Vec<Process>, String> {
return Err("not supported".to_string());
}
async fn update_semi_supervised_models(&mut self, _list: &[u8]) -> Result<(), String> {
return Err("not supported".to_string());
}
}

/// Handles requests to an agent.
Expand Down Expand Up @@ -294,6 +297,10 @@ pub async fn handle<H: Handler>(
RequestCode::ProcessList => {
send_response(send, &mut buf, handler.process_list().await).await?;
}
RequestCode::SemiSupervisedModels => {
let result = handler.update_semi_supervised_models(body).await;
send_response(send, &mut buf, result).await?;
}
RequestCode::Unknown => {
let err_msg = format!("unknown request code: {code}");
message::send_err(send, &mut buf, err_msg).await?;
Expand All @@ -309,7 +316,7 @@ async fn send_response<T: Serialize>(
body: T,
) -> Result<(), frame::SendError> {
match frame::send(send, buf, body).await {
Ok(_) => Ok(()),
Ok(()) => Ok(()),
Err(frame::SendError::WriteError(e)) => Err(frame::SendError::WriteError(e)),
Err(e) => message::send_err(send, buf, e).await,
}
Expand Down

0 comments on commit 607f5e6

Please sign in to comment.