diff --git a/MODERNIZATION.md b/MODERNIZATION.md index 542edeb5..296a642f 100644 --- a/MODERNIZATION.md +++ b/MODERNIZATION.md @@ -909,7 +909,41 @@ exactly that. So consolidation walks the dependency chain from the top: Verified: Release build, dht tests 83/83 (incl. the two new PR #43 race tests), tn 12+1, proxyclient 15/15, standalone builds of the whole chain, lint green over all module units. -4. C-4 streamr-proto-rpc +4. **C-4 streamr-proto-rpc** ✅ — the step that removed the LAST textual + dependency chain in the tree: the protoc plugin's generated RPC stub + headers (`*.client.pb.h` / `*.server.pb.h`), which `#include`d + `RpcCommunicator.hpp` and thereby dragged the whole proto-rpc + + logger header web into every package that uses generated stubs. + **The plugin now emits C++ module units instead of headers** + (`PluginCodeGenerator.hpp` rewritten): for each proto service file it + generates `X.client.cppm` / `X.server.cppm`, named + `.XClient` / `.XServer` where the consuming package + passes its module family as a protoc plugin parameter + (`--streamr_out=module_prefix=streamr.dht:./modules/gen`). Server + stubs are pure interfaces (no proto-rpc dependency at all); client + stubs `import streamr.protorpc.RpcCommunicator;`. Generated units + land in `modules/gen/` (library packages — picked up by the existing + recursive module glob, excluded from linting like all generated + code) or next to the generated message code (proto-rpc tests and + examples). The six proto-rpc public headers became named sub-modules + under `modules/` per the settled architecture; include/ deleted; the + plugin's own sources moved to `src/` (host tooling, not a public + API). Two headers survive INTENTIONALLY, both generated message + code: `*.pb.h` stays textual (`#include` in global module fragments) + because protoc emits headers — exactly the end-state carve-out the + consolidation decision defined. + One duplicate-stub hazard removed: trackerless-network used to + REGENERATE the dht stubs into its own tree (harmless as textual + headers, an ODR violation as module-attached classes) — its proto.sh + now generates DhtRpc message types only, and dht's own stub modules + are the single definition. Tests and examples import the generated + stub modules directly (`streamr.protorpc.test.*`, + `streamr.protorpc.examples.*`), and the last `import + streamr.protorpc;` umbrella consumers (4 dht units, 5 proto-rpc + test/example files, 1 dht test) flipped to narrow imports. + Verified: whole-tree build, 309/309 tests, standalone chain + (proto-rpc → dht → trackerless-network → proxyclient), lint green + over the module units. 5. C-5 streamr-utils 6. C-6 streamr-logger 7. C-7 streamr-json diff --git a/packages/streamr-dht/lint.sh b/packages/streamr-dht/lint.sh index 739ec944..b6238a76 100755 --- a/packages/streamr-dht/lint.sh +++ b/packages/streamr-dht/lint.sh @@ -21,7 +21,10 @@ echo "Running clang-format --dry-run on $FILES" # clangd-tidy as the source of truth (the consolidated units carry no # export-using re-export blocks, which caused the earlier clangd false # positives). -MODULE_FILES=$(find ./modules -type f -name "*.cppm" 2>/dev/null | xargs echo) +# modules/gen/ holds protoc-plugin GENERATED module units (RPC stubs): +# excluded from linting like all generated code (see the src/proto +# exclusion above); the compiler builds them on every platform. +MODULE_FILES=$(find ./modules -type f -name "*.cppm" ! -path './modules/gen/*' 2>/dev/null | xargs echo) if [ -n "$MODULE_FILES" ]; then echo "Running clangd-tidy on $MODULE_FILES" clangd-tidy -p ./build $MODULE_FILES diff --git a/packages/streamr-dht/modules/connection/ConnectionLockRpcLocal.cppm b/packages/streamr-dht/modules/connection/ConnectionLockRpcLocal.cppm index ed27e2f3..02d38195 100644 --- a/packages/streamr-dht/modules/connection/ConnectionLockRpcLocal.cppm +++ b/packages/streamr-dht/modules/connection/ConnectionLockRpcLocal.cppm @@ -7,12 +7,12 @@ module; #include #include #include "packages/dht/protos/DhtRpc.pb.h" -#include "packages/dht/protos/DhtRpc.server.pb.h" #include export module streamr.dht.ConnectionLockRpcLocal; +import streamr.dht.DhtRpcServer; import streamr.logger; import streamr.dht.ConnectionLockStates; import streamr.dht.DhtCallContext; diff --git a/packages/streamr-dht/modules/connection/ConnectionLockRpcRemote.cppm b/packages/streamr-dht/modules/connection/ConnectionLockRpcRemote.cppm index 9071c5d3..2a866368 100644 --- a/packages/streamr-dht/modules/connection/ConnectionLockRpcRemote.cppm +++ b/packages/streamr-dht/modules/connection/ConnectionLockRpcRemote.cppm @@ -7,13 +7,13 @@ module; #include #include #include -#include "packages/dht/protos/DhtRpc.client.pb.h" #include "packages/dht/protos/DhtRpc.pb.h" #include export module streamr.dht.ConnectionLockRpcRemote; +import streamr.dht.DhtRpcClient; import streamr.logger; import streamr.dht.ConnectionLockStates; import streamr.dht.DhtCallContext; diff --git a/packages/streamr-dht/modules/connection/ConnectionManager.cppm b/packages/streamr-dht/modules/connection/ConnectionManager.cppm index 312fa81c..bbc5e0ae 100644 --- a/packages/streamr-dht/modules/connection/ConnectionManager.cppm +++ b/packages/streamr-dht/modules/connection/ConnectionManager.cppm @@ -19,7 +19,7 @@ module; export module streamr.dht.ConnectionManager; -import streamr.protorpc; +import streamr.protorpc.RpcCommunicator; import streamr.dht.ConnectionLockStates; import streamr.logger; import streamr.utils; diff --git a/packages/streamr-dht/modules/connection/ConnectorFacade.cppm b/packages/streamr-dht/modules/connection/ConnectorFacade.cppm index 127cb764..dba375df 100644 --- a/packages/streamr-dht/modules/connection/ConnectorFacade.cppm +++ b/packages/streamr-dht/modules/connection/ConnectorFacade.cppm @@ -14,7 +14,7 @@ export module streamr.dht.ConnectorFacade; import streamr.dht.Identifiers; import streamr.logger; -import streamr.protorpc; +import streamr.protorpc.RpcCommunicator; import streamr.dht.IPendingConnection; import streamr.dht.ListeningRpcCommunicator; import streamr.dht.PendingConnection; diff --git a/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcLocal.cppm b/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcLocal.cppm index 999ce5d4..993f92c9 100644 --- a/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcLocal.cppm +++ b/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcLocal.cppm @@ -6,12 +6,12 @@ module; #include #include "packages/dht/protos/DhtRpc.pb.h" -#include "packages/dht/protos/DhtRpc.server.pb.h" #include export module streamr.dht.WebsocketClientConnectorRpcLocal; +import streamr.dht.DhtRpcServer; import streamr.utils; import streamr.dht.DhtCallContext; import streamr.dht.IPendingConnection; diff --git a/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcRemote.cppm b/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcRemote.cppm index 51ff3e40..3cf66a17 100644 --- a/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcRemote.cppm +++ b/packages/streamr-dht/modules/connection/websocket/WebsocketClientConnectorRpcRemote.cppm @@ -5,10 +5,12 @@ module; #include -#include "packages/dht/protos/DhtRpc.client.pb.h" +#include "packages/dht/protos/DhtRpc.pb.h" export module streamr.dht.WebsocketClientConnectorRpcRemote; +import streamr.dht.DhtRpcClient; +import streamr.protorpc.RpcCommunicator; import streamr.logger; import streamr.dht.DhtCallContext; import streamr.dht.Identifiers; diff --git a/packages/streamr-dht/src/proto/packages/dht/protos/DhtRpc.client.pb.h b/packages/streamr-dht/modules/gen/DhtRpc.client.cppm similarity index 97% rename from packages/streamr-dht/src/proto/packages/dht/protos/DhtRpc.client.pb.h rename to packages/streamr-dht/modules/gen/DhtRpc.client.cppm index d2e1823b..16b182ec 100644 --- a/packages/streamr-dht/src/proto/packages/dht/protos/DhtRpc.client.pb.h +++ b/packages/streamr-dht/modules/gen/DhtRpc.client.cppm @@ -1,18 +1,21 @@ // generated by the protocol buffer streamr pluging. DO NOT EDIT! // generated from protobuf file "packages/dht/protos/DhtRpc.proto" -#ifndef STREAMR_PROTORPC_DHTRPC_CLIENT_PB_H -#define STREAMR_PROTORPC_DHTRPC_CLIENT_PB_H +module; #include #include #include -#include "DhtRpc.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" +#include "packages/dht/protos/DhtRpc.pb.h" // NOLINT -namespace dht { +export module streamr.dht.DhtRpcClient; + +import streamr.protorpc.RpcCommunicator; + using streamr::protorpc::RpcCommunicator; + +export namespace dht { template class DhtNodeRpcClient { private: @@ -138,5 +141,3 @@ RpcCommunicator& communicator; }; // class ExternalApiRpcClient }; // namespace dht -#endif // STREAMR_PROTORPC_DHTRPC_CLIENT_PB_H - diff --git a/packages/streamr-dht/src/proto/packages/dht/protos/DhtRpc.server.pb.h b/packages/streamr-dht/modules/gen/DhtRpc.server.cppm similarity index 95% rename from packages/streamr-dht/src/proto/packages/dht/protos/DhtRpc.server.pb.h rename to packages/streamr-dht/modules/gen/DhtRpc.server.cppm index 6be4a534..68bbf645 100644 --- a/packages/streamr-dht/src/proto/packages/dht/protos/DhtRpc.server.pb.h +++ b/packages/streamr-dht/modules/gen/DhtRpc.server.cppm @@ -1,13 +1,14 @@ // Generated by the protocol buffer streamr pluging. DO NOT EDIT! // Generated from protobuf file "packages/dht/protos/DhtRpc.proto" -#ifndef STREAMR_PROTORPC_DHTRPC_SERVER_PB_H -#define STREAMR_PROTORPC_DHTRPC_SERVER_PB_H +module; -#include "DhtRpc.pb.h" // NOLINT +#include "packages/dht/protos/DhtRpc.pb.h" // NOLINT #include -namespace dht { +export module streamr.dht.DhtRpcServer; + +export namespace dht { template class DhtNodeRpc { public: @@ -75,5 +76,3 @@ class ExternalApiRpc { }; // class ExternalApiRpc }; // namespace dht -#endif // STREAMR_PROTORPC_DHTRPC_SERVER_PB_H - diff --git a/packages/streamr-dht/modules/streamr.dht-protos.cppm b/packages/streamr-dht/modules/streamr.dht-protos.cppm index b84c3384..fd6dad57 100644 --- a/packages/streamr-dht/modules/streamr.dht-protos.cppm +++ b/packages/streamr-dht/modules/streamr.dht-protos.cppm @@ -1,14 +1,14 @@ -// :protos partition — wraps the GENERATED DhtRpc protobuf trio (messages, -// enums, and the protoc-plugin-generated client/server stubs) in the -// global module fragment and re-exports the types used across this -// package's public APIs. Generated protobuf code stays #include-based -// permanently; this partition is how importers see the types without -// re-parsing the 12k-line header stack. +// Wraps the GENERATED DhtRpc protobuf messages and enums in the global +// module fragment and re-exports the types used across this package's +// public APIs. Generated protobuf MESSAGE code stays #include-based +// permanently; this module is how importers see the types without +// re-parsing the 12k-line header stack. The RPC client/server stubs are +// no longer here: the protoc plugin now emits them as their own module +// units (streamr.dht.DhtRpcClient / streamr.dht.DhtRpcServer under +// modules/gen/) — import those directly where the stubs are used. module; -#include "packages/dht/protos/DhtRpc.client.pb.h" #include "packages/dht/protos/DhtRpc.pb.h" -#include "packages/dht/protos/DhtRpc.server.pb.h" export module streamr.dht.protos; @@ -65,26 +65,4 @@ using enum ::dht::RouteMessageError; using ::dht::RpcResponseError; using enum ::dht::RpcResponseError; -// generated client stubs -using ::dht::ConnectionLockRpcClient; -using ::dht::DhtNodeRpcClient; -using ::dht::ExternalApiRpcClient; -using ::dht::RecursiveOperationRpcClient; -using ::dht::RecursiveOperationSessionRpcClient; -using ::dht::RouterRpcClient; -using ::dht::StoreRpcClient; -using ::dht::WebrtcConnectorRpcClient; -using ::dht::WebsocketClientConnectorRpcClient; - -// generated server stubs -using ::dht::ConnectionLockRpc; -using ::dht::DhtNodeRpc; -using ::dht::ExternalApiRpc; -using ::dht::RecursiveOperationRpc; -using ::dht::RecursiveOperationSessionRpc; -using ::dht::RouterRpc; -using ::dht::StoreRpc; -using ::dht::WebrtcConnectorRpc; -using ::dht::WebsocketClientConnectorRpc; - } // namespace dht diff --git a/packages/streamr-dht/modules/transport/ListeningRpcCommunicator.cppm b/packages/streamr-dht/modules/transport/ListeningRpcCommunicator.cppm index 4d5ef704..25c7c403 100644 --- a/packages/streamr-dht/modules/transport/ListeningRpcCommunicator.cppm +++ b/packages/streamr-dht/modules/transport/ListeningRpcCommunicator.cppm @@ -11,7 +11,8 @@ module; export module streamr.dht.ListeningRpcCommunicator; import streamr.eventemitter; -import streamr.protorpc; +import streamr.protorpc.Errors; +import streamr.protorpc.RpcCommunicator; import streamr.dht.RoutingRpcCommunicator; import streamr.dht.Transport; diff --git a/packages/streamr-dht/modules/transport/RoutingRpcCommunicator.cppm b/packages/streamr-dht/modules/transport/RoutingRpcCommunicator.cppm index f57bbc08..9a92102a 100644 --- a/packages/streamr-dht/modules/transport/RoutingRpcCommunicator.cppm +++ b/packages/streamr-dht/modules/transport/RoutingRpcCommunicator.cppm @@ -12,7 +12,8 @@ module; export module streamr.dht.RoutingRpcCommunicator; import streamr.logger; -import streamr.protorpc; +import streamr.protorpc.RpcCommunicator; +import streamr.protorpc.protos; import streamr.utils; import streamr.dht.DhtCallContext; import streamr.dht.Identifiers; diff --git a/packages/streamr-dht/proto.sh b/packages/streamr-dht/proto.sh index 96100466..e0660450 100755 --- a/packages/streamr-dht/proto.sh +++ b/packages/streamr-dht/proto.sh @@ -12,7 +12,11 @@ mkdir -p protos/packages/proto-rpc/protos mkdir -p protos/packages/dht/protos cp -r ../streamr-proto-rpc/protos/* protos/packages/proto-rpc/protos cp protos/DhtRpc.proto protos/packages/dht/protos -${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} --streamr_out=./src/proto/packages/dht/protos --proto_path=./protos --cpp_out=./src/proto packages/dht/protos/DhtRpc.proto +mkdir -p ./modules/gen +# The plugin emits C++ module units (Phase 2.6): module_prefix names the +# module family; the units land under modules/gen so the module FILE_SET +# glob picks them up. +${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} "--streamr_out=module_prefix=streamr.dht:./modules/gen" --proto_path=./protos --cpp_out=./src/proto packages/dht/protos/DhtRpc.proto ${PROTOC} --proto_path=./protos --cpp_out=./src/proto packages/proto-rpc/protos/ProtoRpc.proto rm -rf protos/packages diff --git a/packages/streamr-dht/test/unit/WebsocketClientConnectorRpcRemoteTest.cpp b/packages/streamr-dht/test/unit/WebsocketClientConnectorRpcRemoteTest.cpp index 26cc5bd6..63fc7020 100644 --- a/packages/streamr-dht/test/unit/WebsocketClientConnectorRpcRemoteTest.cpp +++ b/packages/streamr-dht/test/unit/WebsocketClientConnectorRpcRemoteTest.cpp @@ -3,7 +3,8 @@ import streamr.dht.DhtCallContext; import streamr.dht.WebsocketClientConnectorRpcRemote; import streamr.dht.protos; -import streamr.protorpc; +import streamr.dht.DhtRpcClient; +import streamr.protorpc.RpcCommunicator; using ::dht::PeerDescriptor; using ::dht::WebsocketClientConnectorRpcClient; diff --git a/packages/streamr-proto-rpc/CMakeLists.txt b/packages/streamr-proto-rpc/CMakeLists.txt index 92bcd33c..8a409f1e 100644 --- a/packages/streamr-proto-rpc/CMakeLists.txt +++ b/packages/streamr-proto-rpc/CMakeLists.txt @@ -39,19 +39,19 @@ add_library(streamr-proto-rpc) set_property(TARGET streamr-proto-rpc PROPERTY CXX_STANDARD 26) add_library(streamr::streamr-proto-rpc ALIAS streamr-proto-rpc) -# Module façade (MODERNIZATION.md Part 2), added to the existing library -# (it also compiles the generated ProtoRpc.pb.cc). :protos wraps the -# generated header; the other partitions mirror the public headers. +# CONSOLIDATED (MODERNIZATION.md Phase 2.6): one named sub-module per +# former public header (settled architecture: no umbrella; consumers and +# tests import the individual sub-modules), plus streamr.protorpc.protos +# over the generated ProtoRpc types. The library also compiles the +# generated ProtoRpc.pb.cc. +file(GLOB_RECURSE STREAMR_PROTORPC_MODULE_UNITS CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/modules/*.cppm) streamr_target_module_sources(streamr-proto-rpc - FILES - modules/streamr.protorpc.cppm - modules/streamr.protorpc-protos.cppm - modules/streamr.protorpc-all.cppm) -target_include_directories(streamr-proto-rpc - PUBLIC $ - PUBLIC $ + FILES ${STREAMR_PROTORPC_MODULE_UNITS}) +# Only the generated protobuf code remains a header consumers may need +# textually. +target_include_directories(streamr-proto-rpc PUBLIC $ - PUBLIC $ ) target_sources(streamr-proto-rpc @@ -101,7 +101,7 @@ file(WRITE "${CMAKE_BINARY_DIR}/streamr-proto-rpc-config.cmake" # SDK/sysroot — see homebrewClang.cmake), so CMAKE_CROSSCOMPILING is # FALSE there; IOS is set by toolchains/ios.toolchain.cmake. if(NOT IOS AND NOT CMAKE_CROSSCOMPILING) - add_executable(protobuf-streamr-plugin src/PluginCodeGeneratorMain.cpp include/streamr-proto-rpc/PluginCodeGenerator.hpp) + add_executable(protobuf-streamr-plugin src/PluginCodeGeneratorMain.cpp src/PluginCodeGenerator.hpp) target_include_directories( protobuf-streamr-plugin PRIVATE $ @@ -157,13 +157,23 @@ if(NOT IOS AND STREAMR_MODULES_SUPPORTED) add_executable(streamr-proto-rpc-test-integration test/proto/HelloRpc.pb.cc - test/proto/HelloRpc.client.pb.h - test/proto/TestProtos.pb.cc + test/proto/TestProtos.pb.cc test/proto/WakeUpRpc.pb.cc test/integration/ProtoRpcTest.cpp ) streamr_enable_imports(streamr-proto-rpc-test-integration) + # The protoc plugin emits the RPC stubs as module units next to the + # generated message code; the test imports them directly + # (streamr.protorpc.test.*). PRIVATE: test-only modules, not part of + # any export. + file(GLOB STREAMR_PROTORPC_TEST_STUB_UNITS CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/test/proto/*.cppm) + target_sources(streamr-proto-rpc-test-integration + PRIVATE + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/test/proto + FILES ${STREAMR_PROTORPC_TEST_STUB_UNITS}) target_include_directories(streamr-proto-rpc-test-integration PUBLIC $ ) @@ -194,6 +204,13 @@ if(NOT IOS AND STREAMR_MODULES_SUPPORTED) ) streamr_enable_imports(streamr-proto-rpc-example-hello) + file(GLOB STREAMR_PROTORPC_HELLO_STUB_UNITS CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello/proto/*.cppm) + target_sources(streamr-proto-rpc-example-hello + PRIVATE + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello/proto + FILES ${STREAMR_PROTORPC_HELLO_STUB_UNITS}) target_include_directories(streamr-proto-rpc-example-hello PUBLIC $ ) @@ -209,6 +226,13 @@ if(NOT IOS AND STREAMR_MODULES_SUPPORTED) ) streamr_enable_imports(streamr-proto-rpc-example-routed-hello) + file(GLOB STREAMR_PROTORPC_ROUTED_STUB_UNITS CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/examples/routed-hello/proto/*.cppm) + target_sources(streamr-proto-rpc-example-routed-hello + PRIVATE + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/examples/routed-hello/proto + FILES ${STREAMR_PROTORPC_ROUTED_STUB_UNITS}) target_include_directories(streamr-proto-rpc-example-routed-hello PUBLIC $ ) diff --git a/packages/streamr-proto-rpc/examples/hello/hello.cpp b/packages/streamr-proto-rpc/examples/hello/hello.cpp index 439ab9ff..53e9d8fe 100644 --- a/packages/streamr-proto-rpc/examples/hello/hello.cpp +++ b/packages/streamr-proto-rpc/examples/hello/hello.cpp @@ -1,11 +1,13 @@ #include #include #include -#include "HelloRpc.client.pb.h" #include "HelloRpc.pb.h" -#include "HelloRpc.server.pb.h" -import streamr.protorpc; +import streamr.protorpc.ProtoCallContext; +import streamr.protorpc.RpcCommunicator; +import streamr.protorpc.protos; +import streamr.protorpc.examples.HelloRpcClient; +import streamr.protorpc.examples.HelloRpcServer; using streamr::protorpc::HelloRpcService; using streamr::protorpc::HelloRpcServiceClient; diff --git a/packages/streamr-proto-rpc/test/proto/HelloRpc.client.pb.h b/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.client.cppm similarity index 80% rename from packages/streamr-proto-rpc/test/proto/HelloRpc.client.pb.h rename to packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.client.cppm index 1b43e7a5..9ef8e112 100644 --- a/packages/streamr-proto-rpc/test/proto/HelloRpc.client.pb.h +++ b/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.client.cppm @@ -1,18 +1,21 @@ // generated by the protocol buffer streamr pluging. DO NOT EDIT! // generated from protobuf file "HelloRpc.proto" -#ifndef STREAMR_PROTORPC_HELLORPC_CLIENT_PB_H -#define STREAMR_PROTORPC_HELLORPC_CLIENT_PB_H +module; #include #include #include #include "HelloRpc.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" -namespace streamr::protorpc { +export module streamr.protorpc.examples.HelloRpcClient; + +import streamr.protorpc.RpcCommunicator; + using streamr::protorpc::RpcCommunicator; + +export namespace streamr::protorpc { template class HelloRpcServiceClient { private: @@ -25,5 +28,3 @@ RpcCommunicator& communicator; }; // class HelloRpcServiceClient }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_HELLORPC_CLIENT_PB_H - diff --git a/packages/streamr-proto-rpc/test/proto/HelloRpc.server.pb.h b/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.server.cppm similarity index 73% rename from packages/streamr-proto-rpc/test/proto/HelloRpc.server.pb.h rename to packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.server.cppm index 46ec383f..92c2dacd 100644 --- a/packages/streamr-proto-rpc/test/proto/HelloRpc.server.pb.h +++ b/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.server.cppm @@ -1,13 +1,14 @@ // Generated by the protocol buffer streamr pluging. DO NOT EDIT! // Generated from protobuf file "HelloRpc.proto" -#ifndef STREAMR_PROTORPC_HELLORPC_SERVER_PB_H -#define STREAMR_PROTORPC_HELLORPC_SERVER_PB_H +module; #include "HelloRpc.pb.h" // NOLINT #include -namespace streamr::protorpc { +export module streamr.protorpc.examples.HelloRpcServer; + +export namespace streamr::protorpc { template class HelloRpcService { public: @@ -16,5 +17,3 @@ class HelloRpcService { }; // class HelloRpcService }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_HELLORPC_SERVER_PB_H - diff --git a/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.client.pb.h b/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.client.cppm similarity index 80% rename from packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.client.pb.h rename to packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.client.cppm index fd1d169b..ed88284d 100644 --- a/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.client.pb.h +++ b/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.client.cppm @@ -1,18 +1,21 @@ // generated by the protocol buffer streamr pluging. DO NOT EDIT! // generated from protobuf file "RoutedHelloRpc.proto" -#ifndef STREAMR_PROTORPC_ROUTEDHELLORPC_CLIENT_PB_H -#define STREAMR_PROTORPC_ROUTEDHELLORPC_CLIENT_PB_H +module; #include #include #include #include "RoutedHelloRpc.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" -namespace streamr::protorpc { +export module streamr.protorpc.examples.routed.RoutedHelloRpcClient; + +import streamr.protorpc.RpcCommunicator; + using streamr::protorpc::RpcCommunicator; + +export namespace streamr::protorpc { template class RoutedHelloRpcServiceClient { private: @@ -25,5 +28,3 @@ RpcCommunicator& communicator; }; // class RoutedHelloRpcServiceClient }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_ROUTEDHELLORPC_CLIENT_PB_H - diff --git a/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.server.pb.h b/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.server.cppm similarity index 73% rename from packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.server.pb.h rename to packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.server.cppm index e829eb76..78e5054e 100644 --- a/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.server.pb.h +++ b/packages/streamr-proto-rpc/examples/routed-hello/proto/RoutedHelloRpc.server.cppm @@ -1,13 +1,14 @@ // Generated by the protocol buffer streamr pluging. DO NOT EDIT! // Generated from protobuf file "RoutedHelloRpc.proto" -#ifndef STREAMR_PROTORPC_ROUTEDHELLORPC_SERVER_PB_H -#define STREAMR_PROTORPC_ROUTEDHELLORPC_SERVER_PB_H +module; #include "RoutedHelloRpc.pb.h" // NOLINT #include -namespace streamr::protorpc { +export module streamr.protorpc.examples.routed.RoutedHelloRpcServer; + +export namespace streamr::protorpc { template class RoutedHelloRpcService { public: @@ -16,5 +17,3 @@ class RoutedHelloRpcService { }; // class RoutedHelloRpcService }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_ROUTEDHELLORPC_SERVER_PB_H - diff --git a/packages/streamr-proto-rpc/examples/routed-hello/routedhello.cpp b/packages/streamr-proto-rpc/examples/routed-hello/routedhello.cpp index ecc744e4..1be4bb63 100644 --- a/packages/streamr-proto-rpc/examples/routed-hello/routedhello.cpp +++ b/packages/streamr-proto-rpc/examples/routed-hello/routedhello.cpp @@ -2,11 +2,13 @@ #include #include #include -#include "RoutedHelloRpc.client.pb.h" #include "RoutedHelloRpc.pb.h" -#include "RoutedHelloRpc.server.pb.h" -import streamr.protorpc; +import streamr.protorpc.ProtoCallContext; +import streamr.protorpc.RpcCommunicator; +import streamr.protorpc.protos; +import streamr.protorpc.examples.routed.RoutedHelloRpcClient; +import streamr.protorpc.examples.routed.RoutedHelloRpcServer; using ::RoutedHelloResponse; using streamr::protorpc::ProtoCallContext; diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/ProtoCallContext.hpp b/packages/streamr-proto-rpc/include/streamr-proto-rpc/ProtoCallContext.hpp deleted file mode 100644 index 7a8b16b9..00000000 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/ProtoCallContext.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef STREAMR_PROTO_RPC_PROTO_CALL_CONTEXT_HPP -#define STREAMR_PROTO_RPC_PROTO_CALL_CONTEXT_HPP - -#include -#include - -namespace streamr::protorpc { - -using ProtoCallContext = std::map; - -} // namespace streamr::protorpc - -#endif // STREAMR_PROTO_RPC_PROTO_CALL_CONTEXT_HPP \ No newline at end of file diff --git a/packages/streamr-proto-rpc/lint.sh b/packages/streamr-proto-rpc/lint.sh index 6d3a7497..6822e60c 100755 --- a/packages/streamr-proto-rpc/lint.sh +++ b/packages/streamr-proto-rpc/lint.sh @@ -10,11 +10,16 @@ clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES -# Module interface units: format check only. clangd-tidy is not run on -# .cppm files (headers remain the fully linted source of truth during the -# façade migration; clangd modules support is still experimental). +# CONSOLIDATED (MODERNIZATION.md Phase 2.6): the include/ tree is gone — +# the code lives in the module interface units, which are linted with +# clangd-tidy as the source of truth. (The generated RPC stub module +# units live outside modules/ — under test/proto and examples/*/proto — +# and are excluded from linting like all generated code.) MODULE_FILES=$(find ./modules -type f -name "*.cppm" 2>/dev/null | xargs echo) if [ -n "$MODULE_FILES" ]; then + echo "Running clangd-tidy on $MODULE_FILES" + clangd-tidy -p ./build $MODULE_FILES + echo "Running clang-format --dry-run on $MODULE_FILES" ../../run-clang-format.py $MODULE_FILES fi diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/Errors.hpp b/packages/streamr-proto-rpc/modules/Errors.cppm similarity index 95% rename from packages/streamr-proto-rpc/include/streamr-proto-rpc/Errors.hpp rename to packages/streamr-proto-rpc/modules/Errors.cppm index 90b2e881..5688749f 100644 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/Errors.hpp +++ b/packages/streamr-proto-rpc/modules/Errors.cppm @@ -1,5 +1,7 @@ -#ifndef STREAMR_PROTO_RPC_ERRORS_HPP -#define STREAMR_PROTO_RPC_ERRORS_HPP +// Module streamr.protorpc.Errors +// CONSOLIDATED from the former header streamr-proto-rpc/Errors.hpp +// (MODERNIZATION.md Phase 2.6): this file is now the source of truth. +module; #include #include @@ -7,7 +9,8 @@ #include #include -namespace streamr::protorpc { +export module streamr.protorpc.Errors; +export namespace streamr::protorpc { // NOLINTBEGIN enum class ErrorCode { @@ -173,5 +176,3 @@ super(ErrorCode.FAILED_TO_SERIALIZE, message, originalError) } } */ } // namespace streamr::protorpc - -#endif // STREAMR_PROTO_RPC_ERRORS_HPP diff --git a/packages/streamr-proto-rpc/modules/ProtoCallContext.cppm b/packages/streamr-proto-rpc/modules/ProtoCallContext.cppm new file mode 100644 index 00000000..424dff43 --- /dev/null +++ b/packages/streamr-proto-rpc/modules/ProtoCallContext.cppm @@ -0,0 +1,14 @@ +// Module streamr.protorpc.ProtoCallContext +// CONSOLIDATED from the former header streamr-proto-rpc/ProtoCallContext.hpp +// (MODERNIZATION.md Phase 2.6): this file is now the source of truth. +module; + +#include +#include + +export module streamr.protorpc.ProtoCallContext; +export namespace streamr::protorpc { + +using ProtoCallContext = std::map; + +} // namespace streamr::protorpc diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicator.hpp b/packages/streamr-proto-rpc/modules/RpcCommunicator.cppm similarity index 91% rename from packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicator.hpp rename to packages/streamr-proto-rpc/modules/RpcCommunicator.cppm index c2c0988f..f6449e97 100644 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicator.hpp +++ b/packages/streamr-proto-rpc/modules/RpcCommunicator.cppm @@ -1,32 +1,40 @@ -#ifndef STREAMR_PROTO_RPC_RPC_COMMUNICATOR_HPP -#define STREAMR_PROTO_RPC_RPC_COMMUNICATOR_HPP +// Module streamr.protorpc.RpcCommunicator +// CONSOLIDATED from the former header streamr-proto-rpc/RpcCommunicator.hpp +// (MODERNIZATION.md Phase 2.6): this file is now the source of truth. +module; #include #include #include +#include +#include +#include "packages/proto-rpc/protos/ProtoRpc.pb.h" + +export module streamr.protorpc.RpcCommunicator; + +import streamr.logger; +import streamr.protorpc.Errors; +import streamr.protorpc.RpcCommunicatorClientApi; +import streamr.protorpc.RpcCommunicatorServerApi; +import streamr.protorpc.ServerRegistry; + +// Hoisted from the former header (file scope, NOT exported); +// fully qualified: relative namespace names resolve differently +// at file scope than inside the package namespace. +using folly::coro::Task; +using google::protobuf::Any; +using streamr::logger::SLogger; // #include // #include // #include // #include // #include -#include - -#include -#include "RpcCommunicatorClientApi.hpp" -#include "RpcCommunicatorServerApi.hpp" -#include "ServerRegistry.hpp" -#include "packages/proto-rpc/protos/ProtoRpc.pb.h" - -#include "streamr-logger/SLogger.hpp" -namespace streamr::protorpc { +export namespace streamr::protorpc { using namespace std::chrono_literals; -using google::protobuf::Any; -using streamr::logger::SLogger; using RpcMessage = ::protorpc::RpcMessage; using RpcErrorType = ::protorpc::RpcErrorType; -using folly::coro::Task; inline constexpr std::chrono::milliseconds defaultRpcRequestTimeout = 5000ms; @@ -218,5 +226,3 @@ class RpcCommunicator { }; } // namespace streamr::protorpc - -#endif // STREAMR_PROTO_RPC_RPC_COMMUNICATOR_HPP \ No newline at end of file diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicatorClientApi.hpp b/packages/streamr-proto-rpc/modules/RpcCommunicatorClientApi.cppm similarity index 96% rename from packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicatorClientApi.hpp rename to packages/streamr-proto-rpc/modules/RpcCommunicatorClientApi.cppm index 3ca6b42f..788bd419 100644 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicatorClientApi.hpp +++ b/packages/streamr-proto-rpc/modules/RpcCommunicatorClientApi.cppm @@ -1,5 +1,8 @@ -#ifndef STREAMR_PROTO_RPC_RPC_COMMUNICATOR_CLIENT_API_HPP -#define STREAMR_PROTO_RPC_RPC_COMMUNICATOR_CLIENT_API_HPP +// Module streamr.protorpc.RpcCommunicatorClientApi +// CONSOLIDATED from the former header +// streamr-proto-rpc/RpcCommunicatorClientApi.hpp (MODERNIZATION.md Phase 2.6): +// this file is now the source of truth. +module; #include #include @@ -8,20 +11,26 @@ #include #include #include -#include "Errors.hpp" #include "packages/proto-rpc/protos/ProtoRpc.pb.h" -#include "streamr-logger/SLogger.hpp" -#include "streamr-utils/Branded.hpp" -#include "streamr-utils/Uuid.hpp" -namespace streamr::protorpc { +export module streamr.protorpc.RpcCommunicatorClientApi; + +import streamr.logger; +import streamr.utils; +import streamr.protorpc.Errors; + +// Hoisted from the former header (file scope, NOT exported); +// fully qualified: relative namespace names resolve differently +// at file scope than inside the package namespace. +using folly::coro::Task; using google::protobuf::Any; using streamr::logger::SLogger; -using RpcMessage = ::protorpc::RpcMessage; -using RpcErrorType = ::protorpc::RpcErrorType; -using folly::coro::Task; using streamr::utils::Branded; using streamr::utils::Uuid; +export namespace streamr::protorpc { + +using RpcMessage = ::protorpc::RpcMessage; +using RpcErrorType = ::protorpc::RpcErrorType; inline constexpr size_t threadPoolSize = 20; @@ -397,4 +406,3 @@ class RpcCommunicatorClientApi { }; } // namespace streamr::protorpc -#endif // STREAMR_PROTO_RPC_RPC_COMMUNICATOR_CLIENT_API_HPP \ No newline at end of file diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicatorServerApi.hpp b/packages/streamr-proto-rpc/modules/RpcCommunicatorServerApi.cppm similarity index 91% rename from packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicatorServerApi.hpp rename to packages/streamr-proto-rpc/modules/RpcCommunicatorServerApi.cppm index 3030bb39..4868fa2a 100644 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/RpcCommunicatorServerApi.hpp +++ b/packages/streamr-proto-rpc/modules/RpcCommunicatorServerApi.cppm @@ -1,11 +1,25 @@ -#ifndef STREAMR_PROTO_RPC_RPC_COMMUNICATOR_SERVER_API_HPP -#define STREAMR_PROTO_RPC_RPC_COMMUNICATOR_SERVER_API_HPP +// Module streamr.protorpc.RpcCommunicatorServerApi +// CONSOLIDATED from the former header +// streamr-proto-rpc/RpcCommunicatorServerApi.hpp (MODERNIZATION.md Phase 2.6): +// this file is now the source of truth. +module; #include -#include "Errors.hpp" -#include "ServerRegistry.hpp" - -namespace streamr::protorpc { +#include +#include +#include +#include +#include +#include +#include +#include +#include "packages/proto-rpc/protos/ProtoRpc.pb.h" + +export module streamr.protorpc.RpcCommunicatorServerApi; + +import streamr.protorpc.Errors; +import streamr.protorpc.ServerRegistry; +export namespace streamr::protorpc { using RpcMessage = ::protorpc::RpcMessage; using RpcErrorType = ::protorpc::RpcErrorType; @@ -167,5 +181,3 @@ class RpcCommunicatorServerApi { }; } // namespace streamr::protorpc - -#endif // STREAMR_PROTO_RPC_RPC_COMMUNICATOR_SERVER_API_HPP \ No newline at end of file diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/ServerRegistry.hpp b/packages/streamr-proto-rpc/modules/ServerRegistry.cppm similarity index 91% rename from packages/streamr-proto-rpc/include/streamr-proto-rpc/ServerRegistry.hpp rename to packages/streamr-proto-rpc/modules/ServerRegistry.cppm index 2b854690..8072ba55 100644 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/ServerRegistry.hpp +++ b/packages/streamr-proto-rpc/modules/ServerRegistry.cppm @@ -1,13 +1,17 @@ -#ifndef STREAMR_PROTO_RPC_SERVER_REGISTRY_HPP -#define STREAMR_PROTO_RPC_SERVER_REGISTRY_HPP +// Module streamr.protorpc.ServerRegistry +// CONSOLIDATED from the former header streamr-proto-rpc/ServerRegistry.hpp +// (MODERNIZATION.md Phase 2.6): this file is now the source of truth. +module; #include #include #include "packages/proto-rpc/protos/ProtoRpc.pb.h" -#include "streamr-logger/SLogger.hpp" -#include "streamr-proto-rpc/Errors.hpp" -namespace streamr::protorpc { +export module streamr.protorpc.ServerRegistry; + +import streamr.logger; +import streamr.protorpc.Errors; +export namespace streamr::protorpc { using Any = google::protobuf::Any; using Empty = google::protobuf::Empty; @@ -113,5 +117,3 @@ class ServerRegistry { }; } // namespace streamr::protorpc - -#endif // STREAMR_PROTO_RPC_SERVER_REGISTRY_HPP \ No newline at end of file diff --git a/packages/streamr-proto-rpc/modules/streamr.protorpc-all.cppm b/packages/streamr-proto-rpc/modules/streamr.protorpc-all.cppm deleted file mode 100644 index f72ebaae..00000000 --- a/packages/streamr-proto-rpc/modules/streamr.protorpc-all.cppm +++ /dev/null @@ -1,77 +0,0 @@ -// Coarse façade partition over ALL public headers of streamr-proto-rpc. -// One partition (instead of one per header) keeps the number of -// module units — and thus repeated global-module-fragment parses -// of the expensive header stacks — minimal during the façade -// stage (measured at the Phase 2.4 bench checkpoint). Per-header -// granularity returns at consolidation if needed. -module; - -#include "streamr-proto-rpc/Errors.hpp" -#include "streamr-proto-rpc/ProtoCallContext.hpp" -#include "streamr-proto-rpc/RpcCommunicator.hpp" -#include "streamr-proto-rpc/RpcCommunicatorClientApi.hpp" -#include "streamr-proto-rpc/RpcCommunicatorServerApi.hpp" -#include "streamr-proto-rpc/ServerRegistry.hpp" -#include "streamr-proto-rpc/StreamPrinter.hpp" - -export module streamr.protorpc:all; - -export namespace streamr::protorpc { - -using streamr::protorpc::Err; -using streamr::protorpc::ErrorCode; -using streamr::protorpc::FailedToParse; -using streamr::protorpc::FailedToSerialize; -using streamr::protorpc::RpcClientError; -using streamr::protorpc::RpcException; -using streamr::protorpc::RpcRequestError; -using streamr::protorpc::RpcServerError; -using streamr::protorpc::RpcTimeout; -using streamr::protorpc::UnknownRpcMethod; - -} // namespace streamr::protorpc - -export namespace streamr::protorpc { - -using streamr::protorpc::ProtoCallContext; - -} // namespace streamr::protorpc - -export namespace streamr::protorpc { - -using streamr::protorpc::defaultRpcRequestTimeout; -using streamr::protorpc::RpcCommunicator; -using streamr::protorpc::RpcCommunicatorOptions; -using streamr::protorpc::RpcErrorType; -using streamr::protorpc::RpcMessage; -using streamr::protorpc::StatusCode; - -} // namespace streamr::protorpc - -export namespace streamr::protorpc { - -using streamr::protorpc::RpcCommunicatorClientApi; -using streamr::protorpc::threadPoolSize; - -} // namespace streamr::protorpc - -export namespace streamr::protorpc { - -using streamr::protorpc::RpcCommunicatorServerApi; - -} // namespace streamr::protorpc - -export namespace streamr::protorpc { - -using streamr::protorpc::Any; -using streamr::protorpc::Empty; -using streamr::protorpc::MethodOptions; -using streamr::protorpc::ServerRegistry; - -} // namespace streamr::protorpc - -export namespace streamr::protorpc { - -using streamr::protorpc::StreamPrinter; - -} // namespace streamr::protorpc diff --git a/packages/streamr-proto-rpc/modules/streamr.protorpc-protos.cppm b/packages/streamr-proto-rpc/modules/streamr.protorpc-protos.cppm index ef4839a9..c0ed0de6 100644 --- a/packages/streamr-proto-rpc/modules/streamr.protorpc-protos.cppm +++ b/packages/streamr-proto-rpc/modules/streamr.protorpc-protos.cppm @@ -7,7 +7,7 @@ module; #include "packages/proto-rpc/protos/ProtoRpc.pb.h" -export module streamr.protorpc:protos; +export module streamr.protorpc.protos; export namespace protorpc { diff --git a/packages/streamr-proto-rpc/modules/streamr.protorpc.cppm b/packages/streamr-proto-rpc/modules/streamr.protorpc.cppm deleted file mode 100644 index 684676b7..00000000 --- a/packages/streamr-proto-rpc/modules/streamr.protorpc.cppm +++ /dev/null @@ -1,5 +0,0 @@ -// Primary module interface unit of streamr.protorpc. -export module streamr.protorpc; - -export import :protos; -export import :all; diff --git a/packages/streamr-proto-rpc/proto.sh b/packages/streamr-proto-rpc/proto.sh index 8405aa05..f38ad39b 100755 --- a/packages/streamr-proto-rpc/proto.sh +++ b/packages/streamr-proto-rpc/proto.sh @@ -14,12 +14,12 @@ rm -rf protos/packages mkdir -p ./test/proto ${PROTOC} -I=test/protos --cpp_out=./test/proto test/protos/*.proto -${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} --streamr_out=./test/proto --proto_path=test/protos test/protos/*.proto +${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} "--streamr_out=module_prefix=streamr.protorpc.test:./test/proto" --proto_path=test/protos test/protos/*.proto mkdir -p ./examples/hello/proto ${PROTOC} -I=examples/hello --cpp_out=./examples/hello/proto examples/hello/*.proto -${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} --streamr_out=./examples/hello/proto --proto_path=examples/hello examples/hello/*.proto +${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} "--streamr_out=module_prefix=streamr.protorpc.examples:./examples/hello/proto" --proto_path=examples/hello examples/hello/*.proto mkdir -p ./examples/routed-hello/proto ${PROTOC} -I=examples/routed-hello --cpp_out=./examples/routed-hello/proto examples/routed-hello/*.proto -${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} --streamr_out=./examples/routed-hello/proto --proto_path=examples/routed-hello examples/routed-hello/*.proto +${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} "--streamr_out=module_prefix=streamr.protorpc.examples.routed:./examples/routed-hello/proto" --proto_path=examples/routed-hello examples/routed-hello/*.proto diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/PluginCodeGenerator.hpp b/packages/streamr-proto-rpc/src/PluginCodeGenerator.hpp similarity index 76% rename from packages/streamr-proto-rpc/include/streamr-proto-rpc/PluginCodeGenerator.hpp rename to packages/streamr-proto-rpc/src/PluginCodeGenerator.hpp index 7a0d2a2e..1135d7ba 100644 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/PluginCodeGenerator.hpp +++ b/packages/streamr-proto-rpc/src/PluginCodeGenerator.hpp @@ -9,7 +9,7 @@ #include #include #include -#include "streamr-proto-rpc/StreamPrinter.hpp" +#include "StreamPrinter.hpp" namespace streamr::protorpc { @@ -41,6 +41,27 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { return result; } + // The plugin emits C++ module units (Phase 2.6 consolidation), so it + // must know which module family the generated units belong to. The + // consuming package passes it through protoc's plugin parameter: + // --streamr_out=module_prefix=streamr.dht: + [[nodiscard]] static std::string getModulePrefix( + const std::string& parameter, std::string* error) { + const std::string key = "module_prefix="; + size_t pos = parameter.find(key); + if (pos == std::string::npos) { + *error = + "the streamr plugin now generates C++ module units and " + "requires the module_prefix parameter, e.g. " + "--streamr_out=module_prefix=streamr.dht:"; + return ""; + } + size_t start = pos + key.size(); + size_t end = parameter.find(',', start); + return parameter.substr( + start, end == std::string::npos ? std::string::npos : end - start); + } + [[nodiscard]] static std::string getFilenameWithoutExtension( const std::string& filepath) { // Find the last directory separator @@ -55,19 +76,40 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { return filename.substr(0, lastDot); } + // Include path for the generated message-types header: the full proto + // path with the extension swapped, NOT just the basename. The module + // units land under modules/gen/ (away from the .pb.h), so the include + // must resolve through the package's proto include root (src/proto), + // where protoc mirrors the proto file's directory structure. + [[nodiscard]] static std::string getPathWithoutExtension( + const std::string& filepath) { + size_t lastDot = filepath.find_last_of('.'); + size_t lastSlash = filepath.find_last_of("/\\"); + if (lastDot == std::string::npos || + (lastSlash != std::string::npos && lastDot < lastSlash)) { + return filepath; // No extension found + } + return filepath.substr(0, lastDot); + } + bool GenerateServerHeader( // NOLINT const google::protobuf::FileDescriptor* file, - const std::string& /* parameter */, + const std::string& parameter, google::protobuf::compiler::GeneratorContext* generatorContext, - std::string* /* error */) const { + std::string* error) const { bool emptyIncluded = false; const std::string protoFilename(file->name()); const std::string protoFilenameWe = getFilenameWithoutExtension(protoFilename); - const std::string headerFilename = protoFilenameWe + ".server.pb.h"; - const std::string typesFilename = protoFilenameWe + ".pb.h"; - const std::string headerGuard = - "STREAMR_PROTORPC_" + toUpperCase(protoFilenameWe) + "_SERVER_PB_H"; + const std::string modulePrefix = getModulePrefix(parameter, error); + if (modulePrefix.empty()) { + return false; + } + const std::string headerFilename = protoFilenameWe + ".server.cppm"; + const std::string typesFilename = + getPathWithoutExtension(protoFilename) + ".pb.h"; + const std::string moduleName = + modulePrefix + "." + protoFilenameWe + "Server"; std::stringstream headerSs; @@ -76,17 +118,17 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { headerSs << "// Generated from protobuf file \"" << protoFilename << "\"\n"; headerSs << "\n"; - headerSs << "#ifndef " << headerGuard << "\n"; - headerSs << "#define " << headerGuard << "\n\n"; + headerSs << "module;\n\n"; headerSs << "#include \"" << typesFilename << "\" // NOLINT\n"; headerSs << "#include \n"; std::stringstream sourceSs; + sourceSs << "export module " << moduleName << ";\n\n"; if (file->package().empty()) { - sourceSs << "namespace streamr::protorpc {\n"; + sourceSs << "export namespace streamr::protorpc {\n"; } else { - sourceSs << "namespace " << file->package() << " {\n"; + sourceSs << "export namespace " << file->package() << " {\n"; } // for each services int numServices = file->service_count(); @@ -125,7 +167,8 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { methodInputName = "google::protobuf::Empty"; } - const std::string methodOutputFullname(methodOutput->full_name()); + const std::string methodOutputFullname( + methodOutput->full_name()); std::string methodOutputName(methodOutput->name()); if (methodOutputName == "Empty") { @@ -146,9 +189,7 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { sourceSs << "}; // namespace " << file->package() << "\n"; } - sourceSs << "\n"; - sourceSs << "#endif // " << headerGuard << "\n"; - // output to header file + // output to the module unit file google::protobuf::io::ZeroCopyOutputStream* stream = generatorContext->Open(headerFilename); StreamPrinter printer( @@ -167,17 +208,22 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { bool GenerateClientHeader( // NOLINT const google::protobuf::FileDescriptor* file, - const std::string& /* parameter */, + const std::string& parameter, google::protobuf::compiler::GeneratorContext* generatorContext, - std::string* /* error */) const { + std::string* error) const { bool emptyIncluded = false; const std::string protoFilename(file->name()); const std::string protoFilenameWe = getFilenameWithoutExtension(protoFilename); - const std::string headerFilename = protoFilenameWe + ".client.pb.h"; - const std::string typesFilename = protoFilenameWe + ".pb.h"; - const std::string headerGuard = - "STREAMR_PROTORPC_" + toUpperCase(protoFilenameWe) + "_CLIENT_PB_H"; + const std::string modulePrefix = getModulePrefix(parameter, error); + if (modulePrefix.empty()) { + return false; + } + const std::string headerFilename = protoFilenameWe + ".client.cppm"; + const std::string typesFilename = + getPathWithoutExtension(protoFilename) + ".pb.h"; + const std::string moduleName = + modulePrefix + "." + protoFilenameWe + "Client"; std::stringstream headerSs; @@ -186,24 +232,27 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { headerSs << "// generated from protobuf file \"" << protoFilename << "\"\n"; headerSs << "\n"; - headerSs << "#ifndef " << headerGuard << "\n"; - headerSs << "#define " << headerGuard << "\n\n"; + headerSs << "module;\n\n"; headerSs << "#include \n"; headerSs << "#include \n"; headerSs << "#include \n"; headerSs << "#include \"" << typesFilename << "\" // NOLINT\n"; - headerSs << "#include \"streamr-proto-rpc/RpcCommunicator.hpp\"\n"; headerSs << "\n"; std::stringstream sourceSs; + sourceSs << "export module " << moduleName << ";\n\n"; + // RpcCommunicator is consumed as a module (the textual header no + // longer exists after the Phase 2.6 consolidation); the shorthand + // stays at file scope so it is not exported. + sourceSs << "import streamr.protorpc.RpcCommunicator;\n\n"; + sourceSs << "using streamr::protorpc::RpcCommunicator;\n\n"; if (file->package().empty()) { - sourceSs << "namespace streamr::protorpc {\n"; + sourceSs << "export namespace streamr::protorpc {\n"; } else { - sourceSs << "namespace " << file->package() << " {\n"; + sourceSs << "export namespace " << file->package() << " {\n"; } - sourceSs << "using streamr::protorpc::RpcCommunicator;\n"; // for each services int numServices = file->service_count(); @@ -245,7 +294,8 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { methodInputName = "google::protobuf::Empty"; } - const std::string methodOutputFullname(methodOutput->full_name()); + const std::string methodOutputFullname( + methodOutput->full_name()); std::string methodOutputName(methodOutput->name()); if (methodOutputName == "Empty") { @@ -277,9 +327,7 @@ class PluginCodeGenerator : public google::protobuf::compiler::CodeGenerator { sourceSs << "}; // namespace " << file->package() << "\n"; } - sourceSs << "\n"; - sourceSs << "#endif // " << headerGuard << "\n"; - // output to header file + // output to the module unit file google::protobuf::io::ZeroCopyOutputStream* stream = generatorContext->Open(headerFilename); StreamPrinter printer( diff --git a/packages/streamr-proto-rpc/src/PluginCodeGeneratorMain.cpp b/packages/streamr-proto-rpc/src/PluginCodeGeneratorMain.cpp index 45e66c3d..0233db00 100644 --- a/packages/streamr-proto-rpc/src/PluginCodeGeneratorMain.cpp +++ b/packages/streamr-proto-rpc/src/PluginCodeGeneratorMain.cpp @@ -1,5 +1,5 @@ #include -#include "streamr-proto-rpc/PluginCodeGenerator.hpp" +#include "PluginCodeGenerator.hpp" int main(int argc, char** argv) { streamr::protorpc::PluginCodeGenerator generator; diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/StreamPrinter.hpp b/packages/streamr-proto-rpc/src/StreamPrinter.hpp similarity index 100% rename from packages/streamr-proto-rpc/include/streamr-proto-rpc/StreamPrinter.hpp rename to packages/streamr-proto-rpc/src/StreamPrinter.hpp diff --git a/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp b/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp index e08a1a99..bbeee76c 100644 --- a/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp +++ b/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp @@ -2,12 +2,18 @@ #include #include #include -#include "HelloRpc.client.pb.h" -#include "TestProtos.client.pb.h" -#include "WakeUpRpc.client.pb.h" -#include "WakeUpRpc.server.pb.h" - -import streamr.protorpc; +#include "HelloRpc.pb.h" +#include "TestProtos.pb.h" +#include "WakeUpRpc.pb.h" + +import streamr.protorpc.Errors; +import streamr.protorpc.ProtoCallContext; +import streamr.protorpc.RpcCommunicator; +import streamr.protorpc.protos; +import streamr.protorpc.test.HelloRpcClient; +import streamr.protorpc.test.TestProtosClient; +import streamr.protorpc.test.WakeUpRpcClient; +import streamr.protorpc.test.WakeUpRpcServer; import streamr.logger; import streamr.eventemitter; diff --git a/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.client.pb.h b/packages/streamr-proto-rpc/test/proto/HelloRpc.client.cppm similarity index 80% rename from packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.client.pb.h rename to packages/streamr-proto-rpc/test/proto/HelloRpc.client.cppm index 1b43e7a5..9cb1199a 100644 --- a/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.client.pb.h +++ b/packages/streamr-proto-rpc/test/proto/HelloRpc.client.cppm @@ -1,18 +1,21 @@ // generated by the protocol buffer streamr pluging. DO NOT EDIT! // generated from protobuf file "HelloRpc.proto" -#ifndef STREAMR_PROTORPC_HELLORPC_CLIENT_PB_H -#define STREAMR_PROTORPC_HELLORPC_CLIENT_PB_H +module; #include #include #include #include "HelloRpc.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" -namespace streamr::protorpc { +export module streamr.protorpc.test.HelloRpcClient; + +import streamr.protorpc.RpcCommunicator; + using streamr::protorpc::RpcCommunicator; + +export namespace streamr::protorpc { template class HelloRpcServiceClient { private: @@ -25,5 +28,3 @@ RpcCommunicator& communicator; }; // class HelloRpcServiceClient }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_HELLORPC_CLIENT_PB_H - diff --git a/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.server.pb.h b/packages/streamr-proto-rpc/test/proto/HelloRpc.server.cppm similarity index 73% rename from packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.server.pb.h rename to packages/streamr-proto-rpc/test/proto/HelloRpc.server.cppm index 46ec383f..143117bf 100644 --- a/packages/streamr-proto-rpc/examples/hello/proto/HelloRpc.server.pb.h +++ b/packages/streamr-proto-rpc/test/proto/HelloRpc.server.cppm @@ -1,13 +1,14 @@ // Generated by the protocol buffer streamr pluging. DO NOT EDIT! // Generated from protobuf file "HelloRpc.proto" -#ifndef STREAMR_PROTORPC_HELLORPC_SERVER_PB_H -#define STREAMR_PROTORPC_HELLORPC_SERVER_PB_H +module; #include "HelloRpc.pb.h" // NOLINT #include -namespace streamr::protorpc { +export module streamr.protorpc.test.HelloRpcServer; + +export namespace streamr::protorpc { template class HelloRpcService { public: @@ -16,5 +17,3 @@ class HelloRpcService { }; // class HelloRpcService }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_HELLORPC_SERVER_PB_H - diff --git a/packages/streamr-proto-rpc/test/proto/TestProtos.client.pb.h b/packages/streamr-proto-rpc/test/proto/TestProtos.client.cppm similarity index 90% rename from packages/streamr-proto-rpc/test/proto/TestProtos.client.pb.h rename to packages/streamr-proto-rpc/test/proto/TestProtos.client.cppm index 384bea7c..fa596d14 100644 --- a/packages/streamr-proto-rpc/test/proto/TestProtos.client.pb.h +++ b/packages/streamr-proto-rpc/test/proto/TestProtos.client.cppm @@ -1,18 +1,21 @@ // generated by the protocol buffer streamr pluging. DO NOT EDIT! // generated from protobuf file "TestProtos.proto" -#ifndef STREAMR_PROTORPC_TESTPROTOS_CLIENT_PB_H -#define STREAMR_PROTORPC_TESTPROTOS_CLIENT_PB_H +module; #include #include #include #include "TestProtos.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" -namespace streamr::protorpc { +export module streamr.protorpc.test.TestProtosClient; + +import streamr.protorpc.RpcCommunicator; + using streamr::protorpc::RpcCommunicator; + +export namespace streamr::protorpc { template class DhtRpcServiceClient { private: @@ -41,5 +44,3 @@ RpcCommunicator& communicator; }; // class OptionalServiceClient }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_TESTPROTOS_CLIENT_PB_H - diff --git a/packages/streamr-proto-rpc/test/proto/TestProtos.server.pb.h b/packages/streamr-proto-rpc/test/proto/TestProtos.server.cppm similarity index 84% rename from packages/streamr-proto-rpc/test/proto/TestProtos.server.pb.h rename to packages/streamr-proto-rpc/test/proto/TestProtos.server.cppm index f891fb58..72443952 100644 --- a/packages/streamr-proto-rpc/test/proto/TestProtos.server.pb.h +++ b/packages/streamr-proto-rpc/test/proto/TestProtos.server.cppm @@ -1,13 +1,14 @@ // Generated by the protocol buffer streamr pluging. DO NOT EDIT! // Generated from protobuf file "TestProtos.proto" -#ifndef STREAMR_PROTORPC_TESTPROTOS_SERVER_PB_H -#define STREAMR_PROTORPC_TESTPROTOS_SERVER_PB_H +module; #include "TestProtos.pb.h" // NOLINT #include -namespace streamr::protorpc { +export module streamr.protorpc.test.TestProtosServer; + +export namespace streamr::protorpc { template class DhtRpcService { public: @@ -24,5 +25,3 @@ class OptionalService { }; // class OptionalService }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_TESTPROTOS_SERVER_PB_H - diff --git a/packages/streamr-proto-rpc/test/proto/WakeUpRpc.client.pb.h b/packages/streamr-proto-rpc/test/proto/WakeUpRpc.client.cppm similarity index 79% rename from packages/streamr-proto-rpc/test/proto/WakeUpRpc.client.pb.h rename to packages/streamr-proto-rpc/test/proto/WakeUpRpc.client.cppm index f76948e9..138244ac 100644 --- a/packages/streamr-proto-rpc/test/proto/WakeUpRpc.client.pb.h +++ b/packages/streamr-proto-rpc/test/proto/WakeUpRpc.client.cppm @@ -1,18 +1,21 @@ // generated by the protocol buffer streamr pluging. DO NOT EDIT! // generated from protobuf file "WakeUpRpc.proto" -#ifndef STREAMR_PROTORPC_WAKEUPRPC_CLIENT_PB_H -#define STREAMR_PROTORPC_WAKEUPRPC_CLIENT_PB_H +module; #include #include #include #include "WakeUpRpc.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" -namespace streamr::protorpc { +export module streamr.protorpc.test.WakeUpRpcClient; + +import streamr.protorpc.RpcCommunicator; + using streamr::protorpc::RpcCommunicator; + +export namespace streamr::protorpc { template class WakeUpRpcServiceClient { private: @@ -25,5 +28,3 @@ RpcCommunicator& communicator; }; // class WakeUpRpcServiceClient }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_WAKEUPRPC_CLIENT_PB_H - diff --git a/packages/streamr-proto-rpc/test/proto/WakeUpRpc.server.pb.h b/packages/streamr-proto-rpc/test/proto/WakeUpRpc.server.cppm similarity index 72% rename from packages/streamr-proto-rpc/test/proto/WakeUpRpc.server.pb.h rename to packages/streamr-proto-rpc/test/proto/WakeUpRpc.server.cppm index 6a354d11..2f0c19fa 100644 --- a/packages/streamr-proto-rpc/test/proto/WakeUpRpc.server.pb.h +++ b/packages/streamr-proto-rpc/test/proto/WakeUpRpc.server.cppm @@ -1,13 +1,14 @@ // Generated by the protocol buffer streamr pluging. DO NOT EDIT! // Generated from protobuf file "WakeUpRpc.proto" -#ifndef STREAMR_PROTORPC_WAKEUPRPC_SERVER_PB_H -#define STREAMR_PROTORPC_WAKEUPRPC_SERVER_PB_H +module; #include "WakeUpRpc.pb.h" // NOLINT #include -namespace streamr::protorpc { +export module streamr.protorpc.test.WakeUpRpcServer; + +export namespace streamr::protorpc { template class WakeUpRpcService { public: @@ -16,5 +17,3 @@ class WakeUpRpcService { }; // class WakeUpRpcService }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_WAKEUPRPC_SERVER_PB_H - diff --git a/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp b/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp index 57f06672..e791a6d4 100644 --- a/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp +++ b/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp @@ -10,7 +10,11 @@ #include #include "HelloRpc.pb.h" -import streamr.protorpc; +import streamr.protorpc.Errors; +import streamr.protorpc.ProtoCallContext; +import streamr.protorpc.RpcCommunicator; +import streamr.protorpc.RpcCommunicatorClientApi; +import streamr.protorpc.protos; import streamr.logger; namespace streamr::protorpc { diff --git a/packages/streamr-proto-rpc/test/unit/ServerRegistryTest.cpp b/packages/streamr-proto-rpc/test/unit/ServerRegistryTest.cpp index a7b89948..3db1f216 100644 --- a/packages/streamr-proto-rpc/test/unit/ServerRegistryTest.cpp +++ b/packages/streamr-proto-rpc/test/unit/ServerRegistryTest.cpp @@ -3,7 +3,10 @@ #include #include "HelloRpc.pb.h" -import streamr.protorpc; +import streamr.protorpc.Errors; +import streamr.protorpc.ProtoCallContext; +import streamr.protorpc.ServerRegistry; +import streamr.protorpc.protos; // BEGINNOLINT diff --git a/packages/streamr-trackerless-network/lint.sh b/packages/streamr-trackerless-network/lint.sh index 3f464b02..bf20e9f6 100755 --- a/packages/streamr-trackerless-network/lint.sh +++ b/packages/streamr-trackerless-network/lint.sh @@ -25,7 +25,10 @@ echo "Running clang-format --dry-run on $TESTFILES" # with clangd-tidy as the source of truth (verified working with clangd # 22; the consolidated units carry no export-using re-export blocks, # which were the source of the earlier false positives). -MODULE_FILES=$(find ./modules -type f -name "*.cppm" 2>/dev/null | xargs echo) +# modules/gen/ holds protoc-plugin GENERATED module units (RPC stubs): +# excluded from linting like all generated code (see the src/proto +# exclusion above); the compiler builds them on every platform. +MODULE_FILES=$(find ./modules -type f -name "*.cppm" ! -path './modules/gen/*' 2>/dev/null | xargs echo) if [ -n "$MODULE_FILES" ]; then echo "Running clangd-tidy on $MODULE_FILES" clangd-tidy -p ./build $MODULE_FILES diff --git a/packages/streamr-trackerless-network/src/proto/packages/network/protos/NetworkRpc.client.pb.h b/packages/streamr-trackerless-network/modules/gen/NetworkRpc.client.cppm similarity index 95% rename from packages/streamr-trackerless-network/src/proto/packages/network/protos/NetworkRpc.client.pb.h rename to packages/streamr-trackerless-network/modules/gen/NetworkRpc.client.cppm index db967af7..030d51e7 100644 --- a/packages/streamr-trackerless-network/src/proto/packages/network/protos/NetworkRpc.client.pb.h +++ b/packages/streamr-trackerless-network/modules/gen/NetworkRpc.client.cppm @@ -1,18 +1,21 @@ // generated by the protocol buffer streamr pluging. DO NOT EDIT! // generated from protobuf file "packages/network/protos/NetworkRpc.proto" -#ifndef STREAMR_PROTORPC_NETWORKRPC_CLIENT_PB_H -#define STREAMR_PROTORPC_NETWORKRPC_CLIENT_PB_H +module; #include #include #include -#include "NetworkRpc.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" +#include "packages/network/protos/NetworkRpc.pb.h" // NOLINT -namespace streamr::protorpc { +export module streamr.trackerlessnetwork.NetworkRpcClient; + +import streamr.protorpc.RpcCommunicator; + using streamr::protorpc::RpcCommunicator; + +export namespace streamr::protorpc { template class ContentDeliveryRpcClient { private: @@ -84,5 +87,3 @@ RpcCommunicator& communicator; }; // class NodeInfoRpcClient }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_NETWORKRPC_CLIENT_PB_H - diff --git a/packages/streamr-trackerless-network/src/proto/packages/network/protos/NetworkRpc.server.pb.h b/packages/streamr-trackerless-network/modules/gen/NetworkRpc.server.cppm similarity index 90% rename from packages/streamr-trackerless-network/src/proto/packages/network/protos/NetworkRpc.server.pb.h rename to packages/streamr-trackerless-network/modules/gen/NetworkRpc.server.cppm index c36da3c9..786d236b 100644 --- a/packages/streamr-trackerless-network/src/proto/packages/network/protos/NetworkRpc.server.pb.h +++ b/packages/streamr-trackerless-network/modules/gen/NetworkRpc.server.cppm @@ -1,13 +1,14 @@ // Generated by the protocol buffer streamr pluging. DO NOT EDIT! // Generated from protobuf file "packages/network/protos/NetworkRpc.proto" -#ifndef STREAMR_PROTORPC_NETWORKRPC_SERVER_PB_H -#define STREAMR_PROTORPC_NETWORKRPC_SERVER_PB_H +module; -#include "NetworkRpc.pb.h" // NOLINT +#include "packages/network/protos/NetworkRpc.pb.h" // NOLINT #include -namespace streamr::protorpc { +export module streamr.trackerlessnetwork.NetworkRpcServer; + +export namespace streamr::protorpc { template class ContentDeliveryRpc { public: @@ -49,5 +50,3 @@ class NodeInfoRpc { }; // class NodeInfoRpc }; // namespace streamr::protorpc -#endif // STREAMR_PROTORPC_NETWORKRPC_SERVER_PB_H - diff --git a/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcLocal.cppm b/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcLocal.cppm index 44e470bf..d1d6da1d 100644 --- a/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcLocal.cppm +++ b/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcLocal.cppm @@ -5,10 +5,10 @@ module; #include "packages/dht/protos/DhtRpc.pb.h" #include "packages/network/protos/NetworkRpc.pb.h" -#include "packages/network/protos/NetworkRpc.server.pb.h" export module streamr.trackerlessnetwork.ContentDeliveryRpcLocal; +import streamr.trackerlessnetwork.NetworkRpcServer; import streamr.dht.DhtCallContext; import streamr.dht.Identifiers; import streamr.dht.ListeningRpcCommunicator; diff --git a/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcRemote.cppm b/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcRemote.cppm index eb91c911..e50f933c 100644 --- a/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcRemote.cppm +++ b/packages/streamr-trackerless-network/modules/logic/ContentDeliveryRpcRemote.cppm @@ -6,11 +6,11 @@ module; #include #include #include "packages/dht/protos/DhtRpc.pb.h" -#include "packages/network/protos/NetworkRpc.client.pb.h" #include "packages/network/protos/NetworkRpc.pb.h" export module streamr.trackerlessnetwork.ContentDeliveryRpcRemote; +import streamr.trackerlessnetwork.NetworkRpcClient; import streamr.dht.DhtCallContext; import streamr.dht.RpcRemote; import streamr.dht.protos; diff --git a/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcLocal.cppm b/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcLocal.cppm index 7af40249..5a085d6c 100644 --- a/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcLocal.cppm +++ b/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcLocal.cppm @@ -6,10 +6,10 @@ module; #include #include "packages/dht/protos/DhtRpc.pb.h" #include "packages/network/protos/NetworkRpc.pb.h" -#include "packages/network/protos/NetworkRpc.server.pb.h" export module streamr.trackerlessnetwork.ProxyConnectionRpcLocal; +import streamr.trackerlessnetwork.NetworkRpcServer; import streamr.logger; import streamr.dht.DhtCallContext; import streamr.dht.Identifiers; diff --git a/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcRemote.cppm b/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcRemote.cppm index b7ae3af3..25f1ec9f 100644 --- a/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcRemote.cppm +++ b/packages/streamr-trackerless-network/modules/logic/proxy/ProxyConnectionRpcRemote.cppm @@ -5,11 +5,11 @@ module; #include #include "packages/dht/protos/DhtRpc.pb.h" -#include "packages/network/protos/NetworkRpc.client.pb.h" #include "packages/network/protos/NetworkRpc.pb.h" export module streamr.trackerlessnetwork.ProxyConnectionRpcRemote; +import streamr.trackerlessnetwork.NetworkRpcClient; import streamr.dht.DhtCallContext; import streamr.dht.RpcRemote; import streamr.dht.protos; diff --git a/packages/streamr-trackerless-network/modules/streamr.trackerlessnetwork-protos.cppm b/packages/streamr-trackerless-network/modules/streamr.trackerlessnetwork-protos.cppm index 45e48e70..9a2d0cc9 100644 --- a/packages/streamr-trackerless-network/modules/streamr.trackerlessnetwork-protos.cppm +++ b/packages/streamr-trackerless-network/modules/streamr.trackerlessnetwork-protos.cppm @@ -1,12 +1,14 @@ -// :protos partition — wraps the GENERATED NetworkRpc protobuf trio in the +// Wraps the GENERATED NetworkRpc protobuf messages and enums in the // global module fragment and re-exports the types used in this package's // public APIs. NB: NetworkRpc.proto declares no package, so the generated // types live in the GLOBAL namespace — hence plain `export using ::X;`. +// The RPC client/server stubs are no longer here: the protoc plugin now +// emits them as their own module units +// (streamr.trackerlessnetwork.NetworkRpcClient / ...NetworkRpcServer +// under modules/gen/) — import those directly where the stubs are used. module; -#include "packages/network/protos/NetworkRpc.client.pb.h" #include "packages/network/protos/NetworkRpc.pb.h" -#include "packages/network/protos/NetworkRpc.server.pb.h" export module streamr.trackerlessnetwork.protos; @@ -40,25 +42,6 @@ export using ::EncryptionType; export using ::ProxyDirection; export using ::SignatureType; -// generated client/server stubs (the protoc plugin emits them in -// namespace streamr::protorpc) -export namespace streamr::protorpc { - -using streamr::protorpc::ContentDeliveryRpc; -using streamr::protorpc::ContentDeliveryRpcClient; -using streamr::protorpc::HandshakeRpc; -using streamr::protorpc::HandshakeRpcClient; -using streamr::protorpc::NeighborUpdateRpc; -using streamr::protorpc::NeighborUpdateRpcClient; -using streamr::protorpc::NodeInfoRpc; -using streamr::protorpc::NodeInfoRpcClient; -using streamr::protorpc::ProxyConnectionRpc; -using streamr::protorpc::ProxyConnectionRpcClient; -using streamr::protorpc::TemporaryConnectionRpc; -using streamr::protorpc::TemporaryConnectionRpcClient; - -} // namespace streamr::protorpc - // Ordering for MessageRef (used as an ordered-container key across the // package). Exported here, next to the type's re-export, so every // importer of the protos module can order MessageRef values; the diff --git a/packages/streamr-trackerless-network/proto.sh b/packages/streamr-trackerless-network/proto.sh index c7fad533..b1b3d139 100755 --- a/packages/streamr-trackerless-network/proto.sh +++ b/packages/streamr-trackerless-network/proto.sh @@ -13,7 +13,11 @@ mkdir -p protos/packages/network/protos cp -r ../streamr-proto-rpc/protos/* protos/packages/proto-rpc/protos cp -r ../streamr-dht/protos/* protos/packages/dht/protos cp protos/NetworkRpc.proto protos/packages/network/protos -${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} --streamr_out=./src/proto/packages/network/protos --proto_path=./protos --cpp_out=./src/proto packages/network/protos/NetworkRpc.proto -${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} --streamr_out=./src/proto/packages/dht/protos --proto_path=./protos --cpp_out=./src/proto packages/dht/protos/DhtRpc.proto +mkdir -p ./modules/gen +${PROTOC} --plugin=protoc-gen-streamr=${PLUGIN} "--streamr_out=module_prefix=streamr.trackerlessnetwork:./modules/gen" --proto_path=./protos --cpp_out=./src/proto packages/network/protos/NetworkRpc.proto +# DhtRpc: message types only. The RPC stub modules are generated (and +# exported) by streamr-dht itself - duplicate stub classes attached to +# two different modules would violate the one-definition rule. +${PROTOC} --proto_path=./protos --cpp_out=./src/proto packages/dht/protos/DhtRpc.proto ${PROTOC} --proto_path=./protos --cpp_out=./src/proto packages/proto-rpc/protos/ProtoRpc.proto rm -rf protos/packages diff --git a/packages/streamr-trackerless-network/src/proto/packages/dht/protos/DhtRpc.client.pb.h b/packages/streamr-trackerless-network/src/proto/packages/dht/protos/DhtRpc.client.pb.h deleted file mode 100644 index d2e1823b..00000000 --- a/packages/streamr-trackerless-network/src/proto/packages/dht/protos/DhtRpc.client.pb.h +++ /dev/null @@ -1,142 +0,0 @@ -// generated by the protocol buffer streamr pluging. DO NOT EDIT! -// generated from protobuf file "packages/dht/protos/DhtRpc.proto" - -#ifndef STREAMR_PROTORPC_DHTRPC_CLIENT_PB_H -#define STREAMR_PROTORPC_DHTRPC_CLIENT_PB_H - -#include -#include -#include -#include "DhtRpc.pb.h" // NOLINT -#include "streamr-proto-rpc/RpcCommunicator.hpp" - - -namespace dht { -using streamr::protorpc::RpcCommunicator; -template -class DhtNodeRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit DhtNodeRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task getClosestPeers(ClosestPeersRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("getClosestPeers", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task getClosestRingPeers(ClosestRingPeersRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("getClosestRingPeers", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task ping(PingRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("ping", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task leaveNotice(LeaveNotice&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("leaveNotice", std::move(request), std::move(callContext), timeout); - } -}; // class DhtNodeRpcClient -template -class RouterRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit RouterRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task routeMessage(RouteMessageWrapper&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("routeMessage", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task forwardMessage(RouteMessageWrapper&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("forwardMessage", std::move(request), std::move(callContext), timeout); - } -}; // class RouterRpcClient -template -class RecursiveOperationRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit RecursiveOperationRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task routeRequest(RouteMessageWrapper&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("routeRequest", std::move(request), std::move(callContext), timeout); - } -}; // class RecursiveOperationRpcClient -template -class StoreRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit StoreRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task storeData(StoreDataRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("storeData", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task replicateData(ReplicateDataRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("replicateData", std::move(request), std::move(callContext), timeout); - } -}; // class StoreRpcClient -template -class RecursiveOperationSessionRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit RecursiveOperationSessionRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task sendResponse(RecursiveOperationResponse&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("sendResponse", std::move(request), std::move(callContext), timeout); - } -}; // class RecursiveOperationSessionRpcClient -template -class WebsocketClientConnectorRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit WebsocketClientConnectorRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task requestConnection(WebsocketConnectionRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("requestConnection", std::move(request), std::move(callContext), timeout); - } -}; // class WebsocketClientConnectorRpcClient -template -class WebrtcConnectorRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit WebrtcConnectorRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task requestConnection(WebrtcConnectionRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("requestConnection", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task rtcOffer(RtcOffer&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("rtcOffer", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task rtcAnswer(RtcAnswer&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("rtcAnswer", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task iceCandidate(IceCandidate&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("iceCandidate", std::move(request), std::move(callContext), timeout); - } -}; // class WebrtcConnectorRpcClient -template -class ConnectionLockRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit ConnectionLockRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task lockRequest(LockRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("lockRequest", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task unlockRequest(UnlockRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("unlockRequest", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task gracefulDisconnect(DisconnectNotice&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template notify("gracefulDisconnect", std::move(request), std::move(callContext), timeout); - } -}; // class ConnectionLockRpcClient -template -class ExternalApiRpcClient { -private: -RpcCommunicator& communicator; -public: - explicit ExternalApiRpcClient(RpcCommunicator& communicator) : communicator(communicator) {} - folly::coro::Task externalFetchData(ExternalFetchDataRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("externalFetchData", std::move(request), std::move(callContext), timeout); - } - folly::coro::Task externalStoreData(ExternalStoreDataRequest&& request, CallContextType&& callContext, std::optional timeout = std::nullopt) { - return communicator.template request("externalStoreData", std::move(request), std::move(callContext), timeout); - } -}; // class ExternalApiRpcClient -}; // namespace dht - -#endif // STREAMR_PROTORPC_DHTRPC_CLIENT_PB_H - diff --git a/packages/streamr-trackerless-network/src/proto/packages/dht/protos/DhtRpc.server.pb.h b/packages/streamr-trackerless-network/src/proto/packages/dht/protos/DhtRpc.server.pb.h deleted file mode 100644 index 6be4a534..00000000 --- a/packages/streamr-trackerless-network/src/proto/packages/dht/protos/DhtRpc.server.pb.h +++ /dev/null @@ -1,79 +0,0 @@ -// Generated by the protocol buffer streamr pluging. DO NOT EDIT! -// Generated from protobuf file "packages/dht/protos/DhtRpc.proto" - -#ifndef STREAMR_PROTORPC_DHTRPC_SERVER_PB_H -#define STREAMR_PROTORPC_DHTRPC_SERVER_PB_H - -#include "DhtRpc.pb.h" // NOLINT -#include - -namespace dht { -template -class DhtNodeRpc { -public: - virtual ~DhtNodeRpc() = default; - virtual ClosestPeersResponse getClosestPeers(const ClosestPeersRequest& request, const CallContextType& callContext) = 0; - virtual ClosestRingPeersResponse getClosestRingPeers(const ClosestRingPeersRequest& request, const CallContextType& callContext) = 0; - virtual PingResponse ping(const PingRequest& request, const CallContextType& callContext) = 0; - virtual void leaveNotice(const LeaveNotice& request, const CallContextType& callContext) = 0; -}; // class DhtNodeRpc -template -class RouterRpc { -public: - virtual ~RouterRpc() = default; - virtual RouteMessageAck routeMessage(const RouteMessageWrapper& request, const CallContextType& callContext) = 0; - virtual RouteMessageAck forwardMessage(const RouteMessageWrapper& request, const CallContextType& callContext) = 0; -}; // class RouterRpc -template -class RecursiveOperationRpc { -public: - virtual ~RecursiveOperationRpc() = default; - virtual RouteMessageAck routeRequest(const RouteMessageWrapper& request, const CallContextType& callContext) = 0; -}; // class RecursiveOperationRpc -template -class StoreRpc { -public: - virtual ~StoreRpc() = default; - virtual StoreDataResponse storeData(const StoreDataRequest& request, const CallContextType& callContext) = 0; - virtual void replicateData(const ReplicateDataRequest& request, const CallContextType& callContext) = 0; -}; // class StoreRpc -template -class RecursiveOperationSessionRpc { -public: - virtual ~RecursiveOperationSessionRpc() = default; - virtual void sendResponse(const RecursiveOperationResponse& request, const CallContextType& callContext) = 0; -}; // class RecursiveOperationSessionRpc -template -class WebsocketClientConnectorRpc { -public: - virtual ~WebsocketClientConnectorRpc() = default; - virtual void requestConnection(const WebsocketConnectionRequest& request, const CallContextType& callContext) = 0; -}; // class WebsocketClientConnectorRpc -template -class WebrtcConnectorRpc { -public: - virtual ~WebrtcConnectorRpc() = default; - virtual void requestConnection(const WebrtcConnectionRequest& request, const CallContextType& callContext) = 0; - virtual void rtcOffer(const RtcOffer& request, const CallContextType& callContext) = 0; - virtual void rtcAnswer(const RtcAnswer& request, const CallContextType& callContext) = 0; - virtual void iceCandidate(const IceCandidate& request, const CallContextType& callContext) = 0; -}; // class WebrtcConnectorRpc -template -class ConnectionLockRpc { -public: - virtual ~ConnectionLockRpc() = default; - virtual LockResponse lockRequest(const LockRequest& request, const CallContextType& callContext) = 0; - virtual void unlockRequest(const UnlockRequest& request, const CallContextType& callContext) = 0; - virtual void gracefulDisconnect(const DisconnectNotice& request, const CallContextType& callContext) = 0; -}; // class ConnectionLockRpc -template -class ExternalApiRpc { -public: - virtual ~ExternalApiRpc() = default; - virtual ExternalFetchDataResponse externalFetchData(const ExternalFetchDataRequest& request, const CallContextType& callContext) = 0; - virtual ExternalStoreDataResponse externalStoreData(const ExternalStoreDataRequest& request, const CallContextType& callContext) = 0; -}; // class ExternalApiRpc -}; // namespace dht - -#endif // STREAMR_PROTORPC_DHTRPC_SERVER_PB_H -