Skip to content

Conversation

rustybee42
Copy link
Collaborator

@rustybee42 rustybee42 commented Sep 15, 2025

  • Take interface (App) instead of concrete object (Context) in handlers that gives access to the needed resources
  • Implement RuntimeApp for runtime and TestApp for testing, implement a simple mock
  • Move all the handlers to their own files so their associated tests can be put in the same file and they are close together and it's immediately clear where which tests are. It's also easier to locate handlers like this.
  • Add a couple of tests

How to review:

This PR looks like a lot, but most of the changes come from changing the file structure and moving (unchanged) code to new files. Thus commits should be reviewed separately, in order

  • Wait for Improve the Serializer and MsgBuf #9 being merged and this PR being rebased
  • The first two commits are moving the handlers to their own files with almost no other code changes (only what is necessary for the split up, e.g. renaming gRPC handler fuctions to match their module name, making some shared functions public and making the required macro changes for the dispatcher)
  • Then there is some setup for in memory db testing and other small stuff.
  • Then the big dependency injection commit - this is mainly replacing the ctx: Context with app: &impl App, defining the trait, providing a RuntimeApp and TestApp implementation (the latter being rudimentary for now) and modifying the calls from former ctx. to app. to match the changes. Turn off whitespace diff for this commit as in some places the indentation of some blocks changed.
  • Finally, some tests are added to some of the handlers. More can be added later.

Closes #4

@rustybee42 rustybee42 self-assigned this Sep 15, 2025
@rustybee42 rustybee42 changed the title Refactor: Overhaul message handlers so they can be tested Refactor: Overhaul message handlers so they can be tested in isolation Sep 15, 2025
@rustybee42 rustybee42 force-pushed the rb/handler-overhaul branch 8 times, most recently from dd2bea2 to 51b0674 Compare September 16, 2025 12:49
* Serializer now requires a preallocated buffer in form of a &mut
  [u8]. This moves the responsibility to allocate the required memory
  to the user. Before it used a dynamically growing buffer (which
  would reallocate internally if needed). This change is crucial for
  future RDMA support.
* Since we now no longer use `BytesMut`, remove the bytes crate.
* The buffers handled by the store have a fixed size of 4 MiB. This is
  apparently the maximum size of a BeeMsg (see `WORKER_BUF(IN|OUT)_SIZE`
  in `Worker.h`). C++ server code also uses these fixed size.
* Generalize `msg_feature_flags` to a `Header` that can be
  modified from within the `Serializable` implementation and can be
  read out from within the `Deserializable` implementation.
* Collect all BeeMsg (de)serialization functions in one module and
  provide functions for header, body and both combined. The split
  is required because depending on where the data comes from / goes
  to different actions need to be taken. This also provides an easy
  interface for potential external users to handle BeeMsges.
* Remove the MsgBuf struct, instead just pass a `&mut [u8]` into the
dispatcher.
* Add documentation
* Various small code cleanups in BeeSerde and other locations
…e logging

Found by test_empty_udp_packets_server integration test. The test needs
to be changed as well to adapt to the corrected log output (it was not
really correct before)
* Accept a trait impl (`App*` / `AppAll`) to instead of conrete
`Context` type on handlers
* Implement a runtime `App` that satifies the above and is passed to the
handlers at runtime
* Add a `TestApp` implementation with rudimentary functionality for
testing the handlers
* gRPC: get_nodes, delete_node, set_alias, get_pools
* BeeMsg: get_nodes, authenticate_channel
@rustybee42 rustybee42 force-pushed the rb/handler-overhaul branch from 51b0674 to f92dbfc Compare October 1, 2025 13:05
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.

Refactor BeeMsg and gRPC handlers to allow testing them as a whole
1 participant