Skip to content

feat(backend, net::tcp): implement per-board TCP clients with reconnection, keep-alive and fault broadcast - #672

Open
pminmic wants to merge 20 commits into
new-backendfrom
backend/net-tcp
Open

pminmic wants to merge 20 commits into
new-backendfrom
backend/net-tcp

Conversation

@pminmic

@pminmic pminmic commented Nov 5, 2026 •

Copy link
Copy Markdown

Summary

  • Implement per-board TCP clients with independent reconnection supervisors and capped exponential backoff.
  • Add ADJ-based order routing, validation and bounded queues.
  • Handle incoming frame reassembly, packet decoding and lifecycle/error reporting.
  • Serialize orders, configurable keep-alive and prioritized fault requests through one writer per connection.
  • Implement concurrent fault broadcasts with bounded deadlines and per-board write confirmation.
  • Document transport guarantees and provide ignored manual probes.

Validation

Automated tests and local loopback checks pass, but end-to-end validation against board firmware is still pending.

Please review propagate_fault() carefully, particularly whether its behavior matches the firmware's expectations. Its current success result confirms only the TCP write, not firmware receipt or execution.

Pending

  • Hash exchange and validation with boards.

@pminmic pminmic changed the title Backend/net tcp feat(backend, net::tcp): implement per-board TCP clients with reconnection, keep-alive and fault broadcast Nov 10, 2026
@pminmic pminmic linked an issue Nov 11, 2026 that may be closed by this pull request
@JavierRibaldelRio
JavierRibaldelRio marked this pull request as ready for review November 14, 2026 22:50
Comment thread backend/crates/core/src/net/tcp.rs Resolved
Comment thread backend/crates/core/src/net/README.md Resolved
Comment thread backend/crates/core/src/net/README.md Resolved
Comment thread backend/crates/core/src/net/README.md Outdated
index. `UnknownId`, `NoClient`, `Encode` and `Gone` are returned to the caller,
not published as transport reports. Encoding validates representation, not
application safety rules.
- Success means **queued**, not written, received or executed. A full queue waits

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptual error: success should mean order send (or even better ack recived idnk if that's posible)
Furthermore, queue should not exists. When calling the function to send should return ok if the OrderPacket was sent or Error (to Event) if it couldn't be sent (because it failed, because the connection broke or has never been established).

This can be dangerous, suppose a board is not connected and you start sending orders to it, all the orders are stored in the queue, as soon as the board connects to the backend it will recieve all the orders together, which might cause a critical situation

NO QUEUE

Comment thread backend/crates/core/src/net/README.md Resolved
.board(definition.board)
.ok_or(SendError::NoClient(definition.board))?;

handle.send(order).await

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error?

@pminmic pminmic Nov 19, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case that you try to send an order to a board that isn't connected, this board isn't maped in Handles (edit: now BoardClients), so the method board returns an error which is transformed with .ok_or() to a SendError::NoClient.

Makes sense?

/// Returns the configured boards whose write completion was not confirmed
/// (offline, session ended, I/O failure, or deadline elapsed). A failed/partial write is never
/// retried and ends that session. Failure does not prove no bytes were delivered.
pub async fn propagate_fault(&self) -> Result<(), Unreachable> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does not propagate fault, just sends it, please consider rename it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fo not understand this function, claude states that can be simplified usign future::join_all.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broadcast_fault()?

Comment thread backend/crates/core/src/net/README.md Outdated
### Reporting, framing and cancellation

TCP accumulates partial input and extracts complete ADJ-dependent frames. An
undecodable suffix waits for more bytes until it exceeds the 374-byte framing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mistaken

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks if the packet that arrives is one defined by us. If firmware or us fail to encode correctly a packet making it larger than 374 bytes, which has to be processed by this, pops an error.

@pminmic pminmic Nov 19, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the function declared in the module protocol which decodes, if fails to decode a packet with a length of 374 bytes, this means that is not well encoded or is not defined.

Comment thread backend/crates/core/src/net/tcp.rs Resolved
Comment thread backend/crates/core/src/net/tcp.rs Resolved
Comment thread backend/crates/core/src/net/tcp.rs Outdated
///
/// Starting a nonempty configuration outside a Tokio runtime panics, as does
/// [`tokio::spawn`].
pub fn spawn(config: Config, adj: Arc<Index>, reporter: Reporter) -> Handles {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not call index as adj

@GaziH GaziH left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great overall, waiting on Javier's requested changes to be implemented.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TCP Module

3 participants