Skip to content

Commit 38ec566

Browse files
authored
Added crate level docs to mirrord-protocol (#3231)
* Added crate level docs * Bump mirrord-protocol version
1 parent e7ec7bf commit 38ec566

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

changelog.d/3182.internal.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added some documentation to the `mirrord-protocol` crate.

mirrord/protocol/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mirrord-protocol"
3-
version = "1.19.2"
3+
version = "1.19.3"
44
authors.workspace = true
55
description.workspace = true
66
documentation.workspace = true

mirrord/protocol/src/lib.rs

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
//! This crate contains the definition of the mirrord-protocol,
2+
//! which is used in communication between various components of mirrord, e.g. the CLI and the agent
3+
//! or the CLI and the operator.
4+
//!
5+
//! # Protocol
6+
//!
7+
//! The protocol is based on [`bincode`]. It is defined **only** by the Rust types in this crate.
8+
//!
9+
//! Since mirrord components (namely: CLI, agent and operator) are distributed independently,
10+
//! it is important to remember that the peer might not use the same version of the protocol.
11+
//! This protocol must be kept backwards compatible.
12+
//!
13+
//! # Backwards compatibility
14+
//!
15+
//! To keep this protocol backwards compatible, limit your changes to:
16+
//! 1. Renaming types, fields, or variants.
17+
//! 2. Changing the type of a field, given that [`bincode`] representation is the same e.g. `T` ->
18+
//! `Arc<T>`.
19+
//! 3. Adding a new variant to an enum, given that the new variant is the last one. Before sending
20+
//! the new variant, make sure that the peer can handle it (check their version of
21+
//! mirrord-protocol). We usually store version requirements in static variables, e.g.
22+
//! [`tcp::HTTP_FRAMED_VERSION`].
23+
//! 4. Code unrelated to types' representation on the wire.
24+
//!
25+
//! Example changes that **do break** backwards compatibility:
26+
//! 1. Adding a new field.
27+
//! 2. Changing the type of a field from `T` to `Option<T>` and vice versa.
28+
//! 3. Reordering variants of an enum.
29+
//!
30+
//! If you're not sure whether your change is breaking,
31+
//! you can check it manually with a unit test.
32+
//!
33+
//! # Versioning
34+
//!
35+
//! The version of the protocol is stored in the [`VERSION`] static variable
36+
//! and is the same as the version of this crate.
37+
//!
38+
//! Unlike the other crates in this workspace, this crate is versioned independently.
39+
//!
40+
//! Mind that CI checks that the version of this crate is bumped
41+
//! whenever the files in this crate are modified, regardless of what the change actually is.
42+
//!
43+
//! When you make changes to this crate:
44+
//! 1. If you're extending the protocol, bump minor version.
45+
//! 2. Otherwise, bump patch version.
46+
//!
47+
//! # Utilities
48+
//!
49+
//! * [`ClientCodec`] and [`ProtocolCodec`] implement [`actix_codec::Decoder`] can be used with
50+
//! [`actix_codec::Framed`] transform an IO stream into
51+
//! [`Sink`](futures::Sink)+[`Stream`](futures::Stream) of mirrord-protocol messages.
52+
//! * Some mirrord-protocol types implement conversion to/from [`socket2`] and [`hyper`] types.
53+
//! These should probably be implemented elsewhere (to remove dependencies from this crate), but
54+
//! right now we have these deps everywhere anyway, so it's not a big deal.
55+
156
#![feature(const_trait_impl)]
257
#![feature(io_error_more)]
358
#![warn(clippy::indexing_slicing)]
@@ -22,9 +77,10 @@ pub use error::*;
2277
pub type Port = u16;
2378
pub type ConnectionId = u64;
2479

25-
/// A per-connection HTTP request ID
26-
pub type RequestId = u16; // TODO: how many requests in a single connection? is u16 appropriate?
80+
/// An HTTP request ID, unique within a single incoming connection.
81+
pub type RequestId = u16;
2782

83+
/// The version of this crate and the mirrord-protocol.
2884
pub static VERSION: LazyLock<semver::Version> = LazyLock::new(|| {
2985
env!("CARGO_PKG_VERSION")
3086
.parse()

0 commit comments

Comments
 (0)