Repository navigation
feat(backend, net::tcp): implement per-board TCP clients with reconnection, keep-alive and fault broadcast #672
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
Open
pminmic
wants to merge
20
commits into
new-backend
Choose a base branch
from
backend/net-tcp
base: new-backend
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c6679ce
wip: net
JavierRibaldelRio 7b98b80
wip(backend, net): upload cargo.toml
JavierRibaldelRio 1b388e5
feat(backend, net::tcp): add TCP handles and in-memory framing
pminmic 64dd0bc
feat(backend, net::tcp): TCP connection with single board
pminmic 1ae8c5c
feat(backend, net::tcp): reusable reader using tcp::framing and repor…
pminmic de39ade
test(backend, net::tcp): manual test to test recieved packets
pminmic 8eadd92
feat(backend, net::tcp): write in the intern tcp buffer and add some …
pminmic 4819713
feat(backend, net::tcp): add configurable TCP keep-alive to session w…
pminmic 2585e81
Merge branch 'new-backend' into backend/net-tcp
pminmic 290d558
feat(backend, net::tcp): selection of the reader/writer for each acti…
pminmic 4da970b
feat(backend, net::tcp): add reconnection supervisor with exponential…
pminmic 194ba14
feat(backend, net::tcp): spawn per-board supervisors
pminmic f41e562
feat(backend, net::tcp): add prioritized fault boradcast with per-boa…
pminmic 911e39c
tests(backend, net::tcp): add manual test for spawn conections per-bo…
pminmic d94304c
docs(backend, net::tcp): update README
pminmic 888f4c2
refactor(backend, net::tcp): restrict public API to transport entry p…
pminmic cfcda70
refactor(backend, tcp): separate tests from tcp.rs file
pminmic d387cf5
fix(backend, tcp): fixing after pr review (separate tcp tests, change…
pminmic 1ed490b
Merge branch 'new-backend' into backend/net-tcp
pminmic c21aa0d
fix(backend, tcp): merge conflicts
pminmic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //! Real sockets, on top of tokio (feature `net`). | ||
| //! | ||
| //! Two submodules do the actual I/O: [`crate::net::tcp`], a client that | ||
| //! keeps one task per board and recovers frames out of a byte stream, | ||
| //! and [`crate::net::udp`], a single shared receive-only socket. This module opens nothing. It defines only what | ||
| //! both of them need to agree on: [`crate::net::Event`] (what happened on | ||
| //! a link, carried by a [`crate::net::Notification`]) and | ||
| //! [`crate::net::Reporter`] (the two sinks they report through — one for | ||
| //! notifications, one for errors). | ||
| //! | ||
| //! Everything that reaches a [`crate::net::Reporter`] has already been | ||
| //! decoded by [`crate::protocol`], which this module layers on top of: | ||
| //! `protocol` turns bytes into packets and never touches a socket, `net` | ||
| //! owns the socket and calls into it. A sniffer or a simulator can use | ||
| //! `protocol` on its own, against a capture, without any of this. | ||
| //! | ||
| //! # Identity | ||
| //! | ||
| //! Everything that travels down the notification channel carries its | ||
| //! board: [`crate::net::Notification`] holds a | ||
| //! [`crate::model::BoardId`] next to the timestamp, whatever the event | ||
| //! is. No consumer ever has to go and look up whose packet it just got. | ||
| //! | ||
| //! It is never a second source of truth, though — it is resolved from | ||
| //! what the ADJ already says, once, here. A TCP task was spawned for one | ||
| //! board and knows it without asking; [`crate::net::udp`] resolves it | ||
| //! from the decoded packet's id through [`crate::protocol::Index`] (every | ||
| //! [`crate::model::PacketDef`] carries its `board`), which is one | ||
| //! `HashMap` lookup per datagram instead of one per consumer downstream. | ||
| //! | ||
| //! A board id is all the identity there is: one connection per board, and | ||
| //! one shared socket for UDP, so nothing needs telling apart beyond it. | ||
| //! | ||
| //! Addresses are for the operator, not for the domain types: they show | ||
| //! up interpolated in each submodule's error messages (`tcp::Error`, | ||
| //! `udp::Error`), which is where somebody actually reads them. | ||
|
|
||
| mod error; | ||
| mod report; | ||
|
|
||
| pub mod tcp; | ||
| pub mod udp; | ||
|
|
||
| pub use error::Error; | ||
| use report::Closed; | ||
| pub use report::{ErrorReport, Event, Notification, Reporter, Sinks}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # `net` — socket transport (feature `net`) | ||
|
|
||
| `net` owns Tokio sockets and uses the synchronous, socket-free `protocol` codecs. | ||
| The parent module opens no sockets itself: it exposes transports and defines | ||
| their shared reporting types and errors. | ||
|
|
||
| Application policy, ADJ loading, logging to disk and frontend integration belong | ||
| outside this module. Transport errors and received protections never trigger a | ||
| fault automatically; the application decides how to respond. | ||
|
|
||
| ## Transports | ||
|
|
||
| | Module | Status / purpose | | ||
| | --- | --- | | ||
| | [TCP](tcp/README.md) | A client with one independently reconnecting connection per configured board. Receives messages/protections and writes orders, keep-alive and faults. | | ||
| | UDP | Telemetry reception is **not implemented yet**; `udp::spawn` is a placeholder that panics. | | ||
|
|
||
| TCP configuration, API usage, guarantees, limitations and manual probes are | ||
| documented in [tcp/README.md](tcp/README.md). | ||
|
|
||
| ## Shared API | ||
|
|
||
| | Type / entry point | Purpose | | ||
| | --- | --- | | ||
| | `Reporter::channels(notifications, errors)` | Create bounded reporting channels and their receiving ends (`Sinks`). Both capacities must be nonzero. | | ||
| | `Reporter` | Cloneable reporting handle supplied to transports; publication methods are internal. | | ||
| | `Sinks` | Application-owned receivers for notifications and errors. | | ||
| | `Notification`, `Event` | Identify a board, timestamp and lifecycle event or decoded packet. | | ||
| | `ErrorReport`, `net::Error` | Timestamp transport failures and preserve their transport-specific identity. | | ||
|
|
||
| ## Reporting | ||
|
|
||
| `Notification { board, at, event }` always carries the board's identity alongside | ||
| its timestamp. `Event` is `Connected`, `Disconnected` or `Received(Packet)`; | ||
| connection lifecycle events are TCP-only. `ErrorReport { at, error }` contains | ||
| the failure's own identity through the corresponding `net::Error` variant. | ||
| The transport's `Reporter` stamps events when publishing them. | ||
|
|
||
| Consume **both** channels concurrently with application operations. Both apply | ||
| backpressure rather than dropping on congestion, so leaving either consumer | ||
| idle can block publication. There is no ordering guarantee between the two | ||
| channels or across independent boards. Cancellation can discard a publication | ||
| waiting for capacity; already queued reports remain available to drain. | ||
|
|
||
| Closing a consumer is also a transport cancellation signal. The exact shutdown | ||
| behavior is transport-specific; see [TCP cancellation](tcp/README.md#reporting-framing-and-cancellation). | ||
|
|
||
| ## Tests | ||
|
|
||
| From `backend/`: | ||
|
|
||
| ```sh | ||
| cargo test -p software-core --features net | ||
| ``` | ||
|
|
||
| See [TCP tests and manual probes](tcp/README.md#tests) for hardware requirements, | ||
| simulator setup and safety warnings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| //! The one error type an [`super::ErrorReport`] can carry. | ||
|
|
||
| use super::{tcp, udp}; | ||
|
|
||
| /// Anything that went wrong in `net`. | ||
| /// | ||
| /// Aggregation only: this enum adds no identity and no message of its | ||
| /// own. Each submodule owns its own error type and puts the identity of | ||
| /// whatever failed — the board, or the peer address — | ||
| /// *inside* the variant, not just in its text, so that the identity | ||
| /// survives being sent down a channel. The Go backend lost it exactly | ||
| /// there: the log line before the send had the board, the error value | ||
| /// that travelled did not. | ||
| /// | ||
| /// Both variants are `#[error(transparent)]`, so `to_string()` on this | ||
| /// enum is the submodule's own message, identity interpolated and all — | ||
| /// which is what gets shown to the operator — and `source()` still walks | ||
| /// down to the original `io::Error` or | ||
| /// [`crate::protocol::DecodeError`]. | ||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum Error { | ||
| /// On a board's TCP connection. | ||
| #[error(transparent)] | ||
| Tcp(#[from] tcp::Error), | ||
| /// On the shared UDP socket. | ||
| #[error(transparent)] | ||
| Udp(#[from] udp::Error), | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.