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
+
1
56
#![ feature( const_trait_impl) ]
2
57
#![ feature( io_error_more) ]
3
58
#![ warn( clippy:: indexing_slicing) ]
@@ -22,9 +77,10 @@ pub use error::*;
22
77
pub type Port = u16 ;
23
78
pub type ConnectionId = u64 ;
24
79
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 ;
27
82
83
+ /// The version of this crate and the mirrord-protocol.
28
84
pub static VERSION : LazyLock < semver:: Version > = LazyLock :: new ( || {
29
85
env ! ( "CARGO_PKG_VERSION" )
30
86
. parse ( )
0 commit comments