Fleshed out Request and ResponseHeader

This commit is contained in:
Nathan Fisher 2023-04-06 19:11:31 -04:00
parent 44d186664a
commit dbd0340434
5 changed files with 87 additions and 26 deletions

3
Cargo.lock generated
View File

@ -329,7 +329,7 @@ dependencies = [
[[package]] [[package]]
name = "hpk-package" name = "hpk-package"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package#9cf9d469f644c43ee2c2d9ca3b16e669c2def944" source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package#723d697e9085a575c1f6d59baf1e79819452d747"
dependencies = [ dependencies = [
"chrono", "chrono",
"deku", "deku",
@ -348,6 +348,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"hpk-package", "hpk-package",
"rayon", "rayon",
"serde",
"url", "url",
] ]

View File

@ -12,4 +12,5 @@ server = []
[dependencies] [dependencies]
hpk-package = { git = "https://git.hitchhiker-linux.org/jeang3nie/hpk-package" } hpk-package = { git = "https://git.hitchhiker-linux.org/jeang3nie/hpk-package" }
rayon = "1.7" rayon = "1.7"
serde = { version = "1.0.159", features = ["derive"] }
url = "2.3.1" url = "2.3.1"

View File

@ -1,20 +1,9 @@
pub trait Client { use crate::Request;
type Error;
type Response;
fn get() -> Result<Self, Self::Error> where Self: Sized; pub fn make_request(request: Request) {
fn request(&self) -> Result<Self::Response, Self::Error>;
}
impl Client for super::Update {
type Error = Box<dyn std::error::Error>;
type Response = ();
fn get() -> Result<Self, Self::Error> {
unimplemented!(); unimplemented!();
} }
fn request(&self) -> Result<Self::Response, Self::Error> { pub fn handle_response() {
unimplemented!(); unimplemented!();
} }
}

View File

@ -1,20 +1,89 @@
use std::path::PathBuf; use hpk_package::{Arch, Package, Version};
use serde::{Deserialize, Serialize};
use std::{fmt, path::PathBuf};
#[cfg(feature = "client")] #[cfg(feature = "client")]
mod client; pub mod client;
#[cfg(feature = "client")]
pub use client::Client;
#[cfg(feature = "server")] #[cfg(feature = "server")]
pub mod server; pub mod server;
#[derive(Clone, Debug)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PackageSpec {
name: String,
version: Version,
arch: Arch,
release: u8,
}
impl fmt::Display for PackageSpec {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}-{}_{}_{}",
self.name, self.version, self.arch, self.release
)
}
}
impl From<Package> for PackageSpec {
fn from(value: Package) -> Self {
Self {
name: value.name,
version: value.version,
arch: value.arch,
release: value.release,
}
}
}
impl From<&Package> for PackageSpec {
fn from(value: &Package) -> Self {
Self {
name: value.name.to_string(),
version: value.version.clone(),
arch: value.arch,
release: value.release,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Item { pub struct Item {
pub package: String, pub pspec: PackageSpec,
pub path: PathBuf, pub path: PathBuf,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Update { pub enum Request {
pub items: Vec<Item>, Catalog,
Packages(Vec<PackageSpec>),
Updates(Vec<Item>),
}
impl From<Vec<PackageSpec>> for Request {
fn from(value: Vec<PackageSpec>) -> Self {
Self::Packages(value)
}
}
impl From<Vec<Item>> for Request {
fn from(value: Vec<Item>) -> Self {
Self::Updates(value)
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ResponseHeader {
/// The server is sending it's catalog
Catalog,
/// The server is sending a package, captured value is it's length. A new header will be sent
/// for each subsequent file.
Package(usize),
/// The server is sending an archive of updated files
Updates,
/// One or more requested packages are not on the server
PackageNotFound(Vec<PackageSpec>),
/// One or more requested update files are not on the server
FileNotFound(Vec<Item>),
} }

View File

@ -0,0 +1 @@