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

Kitsune2 Top-Level P2P Protocol #38

Merged
merged 13 commits into from
Dec 4, 2024
187 changes: 187 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ ctrlc = { version = "3.4.5", features = ["termination"] }
ed25519-dalek = "2.1.1"
# bootstrap_srv uses this to determine worker thread count.
num_cpus = "1.16.0"
# api uses this for the kitsune2 wire protocol.
prost = "0.13.3"
# kitsune types need to be serializable for network transmission.
serde = { version = "1.0.215", features = ["derive"] }
# kitsune2 agent info is serialized as json to improve debugability of
Expand All @@ -41,6 +43,13 @@ tempfile = "3.14.0"
thiserror = "2.0.3"
# this is used by bootstrap_srv as the http server implementation.
tiny_http = "0.12.0"
# --- build-dependencies ---
# The following workspace dependencies are thus-far only used in build-deps.
# Please be careful to only include them in build dependencies or move them
# above this section.
# --- build-dependencies ---
prost-build = "0.13.3"
protobuf-src = "2.1.0"
neonphog marked this conversation as resolved.
Show resolved Hide resolved
# --- dev-dependencies ---
# The following workspace dependencies are used in crate dev-dependencies.
# Please be careful to only include them in dev dependencies or move them
Expand Down
5 changes: 5 additions & 0 deletions crates/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ edition = "2021"
[dependencies]
base64 = { workspace = true }
bytes = { workspace = true }
prost = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
futures = { workspace = true }

[build-dependencies]
prost-build = { workspace = true }
protobuf-src = { workspace = true }

[dev-dependencies]
tokio = { workspace = true, features = ["full"] }
7 changes: 7 additions & 0 deletions crates/api/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() -> std::io::Result<()> {
std::env::set_var("PROTOC", protobuf_src::protoc());
prost_build::Config::new()
.bytes(["."])
.compile_protos(&["src/wire.proto"], &["src/"])?;
neonphog marked this conversation as resolved.
Show resolved Hide resolved
Ok(())
}
2 changes: 2 additions & 0 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ pub use timestamp::*;

pub mod op_store;
pub use op_store::*;

pub mod protocol;
43 changes: 43 additions & 0 deletions crates/api/src/protocol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Kitsune2 wire protocol types.

include!(concat!(env!("OUT_DIR"), "/kitsune2.wire.rs"));

#[cfg(test)]
mod test {
use super::*;

#[test]
fn happy_encode_decode() {
use prost::Message;

let m = K2Proto {
ty: Some(k2_proto::Ty::Module as i32),
data: Some(bytes::Bytes::from_static(b"a")),
space: Some(bytes::Bytes::from_static(b"b")),
module: Some("c".into()),
};

let m_enc = m.encode_to_vec();

let d = K2Proto {
ty: Some(k2_proto::Ty::DisconnectGeneral as i32),
data: Some(bytes::Bytes::from_static(b"d")),
space: None,
module: None,
};

let d_enc = d.encode_to_vec();

// the disconnect message doesn't have a space or module,
// the encoded message should be smaller.
assert!(d_enc.len() < m_enc.len());

let m_dec = K2Proto::decode(std::io::Cursor::new(m_enc)).unwrap();

assert_eq!(m, m_dec);

let d_dec = K2Proto::decode(std::io::Cursor::new(d_enc)).unwrap();

assert_eq!(d, d_dec);
}
}
Loading
Loading