Skip to content
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

Fix for issue 416: Impossible to retain transfer ids #420

Merged
merged 9 commits into from
Jan 31, 2025

Conversation

serges147
Copy link
Collaborator

  • Introduced public ITransferIdMap and internal detail::ITransferIdStorage interfaces.
  • Presentation publisher and rpc client entities now...
    • try initialize (at ctor) their transfer ids with the transfer id map getIdFor method.
    • try to store their next transfer ids into the map (using setIdFor).
  • Extra unit tests and mocks to cover new transfer id map related business logic.

@serges147 serges147 self-assigned this Jan 29, 2025
@@ -0,0 +1,228 @@
/// @copyright
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

JFYI, this is not a new file, but rename and a bit modification of the above transfer_id_generators.hpp

@serges147 serges147 marked this pull request as ready for review January 29, 2025 22:16
/// B/c modulo is expected to be quite big (like >= 2^48), collisions of transfer ids are unlikely.
/// Normally in use for UDP transport, where the modulo is `2^64 - 1`.
///
class TrivialTransferIdGenerator
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably should mention that these generators are not thread-safe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whole libcyphal is not thread-safe.

/// Users may provide a custom implementation of this interface to maintain/persist transfer IDs.
/// See `Presentation::setTransferIdMap` method for more details.
///
class ITransferIdMap
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're getting a little too OOP here. The map type should be STL-compliant and defined in config.hpp (see #419). We can use cavl to implement a cetl::pmr O(log n) implementation that is enough of a std::map duck type to cover our use cases and users can chose to redefine to std::pmr::unordered_map when using C++17.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe if such type will be just memory-only container. But...

  1. the idea is to have persisting when needed
  2. currently interface is very clear. without c++20 concepts it becomes very blurry (should I use operator [] or insert/remove, and so on...)
  3. in unit tests I have and use gmock of the interface - gives me very nice observability with minimum efforts
  4. this is optional feature of libcyphal - it works totally fine without it
  5. how much do you really save avoiding one virtual call for such relatively rare operations...?
  6. it's so easy to write a simple wrapper around whatever already existing STL collection. I can even add an example in the docs if you think it could be a showstopper for the user.
  7. config.hpp is relatively hardcore feature - you normally switch it on or off for the whole project; you can't have it on and off in one single cpp unit as I DO need in tests. That is why f.e. I have one special dedicated test/unittest/presentation/test_publisher_custom_config.cpp source file.

So, IMHO we should not complicate things.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. You've convinced me.

@serges147 serges147 added this pull request to the merge queue Jan 31, 2025
Merged via the queue into main with commit d17f264 Jan 31, 2025
22 checks passed
@serges147 serges147 deleted the sshirokov/416_tid branch January 31, 2025 13:26
@serges147 serges147 mentioned this pull request Jan 31, 2025
9 tasks
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.

3 participants