-
Notifications
You must be signed in to change notification settings - Fork 3
support non-local remote transports #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dlipicar
wants to merge
8
commits into
master
Choose a base branch
from
support-non-local-remote-transports
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d143d25
support non-local remote transports
dlipicar c38f507
fix LogosResult
dlipicar ee0fbd1
allow getting client over specific transport
dlipicar 89b0be9
fix ssl
dlipicar 4c68f68
investiage ssl error
dlipicar da7fd66
pr comments
dlipicar 0de683a
allow transport set configuration on any module
dlipicar 9a7607a
pr comments
dlipicar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include "cbor_codec.h" | ||
| #include "json_mapping.h" | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
|
|
||
| namespace logos::plain { | ||
|
|
||
| using json = nlohmann::json; | ||
|
|
||
| std::vector<uint8_t> CborCodec::encode(const AnyMessage& msg) | ||
| { | ||
| const json j = messageToJson(msg); | ||
| return json::to_cbor(j); | ||
| } | ||
|
|
||
| AnyMessage CborCodec::decode(MessageType tag, const uint8_t* data, std::size_t len) | ||
| { | ||
| json j; | ||
| try { | ||
| j = json::from_cbor(data, data + len, /*strict=*/true, /*allow_exceptions=*/true); | ||
| } catch (const std::exception& e) { | ||
| throw CodecError(std::string("cbor parse failed: ") + e.what()); | ||
| } | ||
| return jsonToMessage(tag, j); | ||
| } | ||
|
|
||
| } // namespace logos::plain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #ifndef LOGOS_PLAIN_CBOR_CODEC_H | ||
| #define LOGOS_PLAIN_CBOR_CODEC_H | ||
|
|
||
| #include "wire_codec.h" | ||
|
|
||
| namespace logos::plain { | ||
|
|
||
| // CborCodec — same logical message layout as JsonCodec (shared via | ||
| // json_mapping.{h,cpp}), serialized with nlohmann::json::to_cbor / | ||
| // from_cbor. Matches JSON wire-for-wire in logical content; wire bytes | ||
| // are binary CBOR rather than UTF-8 JSON text. | ||
| // | ||
| // Useful when you want smaller/faster on-the-wire encoding without | ||
| // swapping to a wholly different codec family. Paired transports on the | ||
| // daemon can offer both JSON and CBOR; clients pick per-connection via | ||
| // --client-codec. | ||
| class CborCodec : public IWireCodec { | ||
| public: | ||
| std::vector<uint8_t> encode(const AnyMessage&) override; | ||
| AnyMessage decode(MessageType tag, | ||
| const uint8_t* data, | ||
| std::size_t len) override; | ||
| std::string name() const override { return "cbor"; } | ||
| }; | ||
|
|
||
| } // namespace logos::plain | ||
|
|
||
| #endif // LOGOS_PLAIN_CBOR_CODEC_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #ifndef LOGOS_PLAIN_INCOMING_CALL_HANDLER_H | ||
| #define LOGOS_PLAIN_INCOMING_CALL_HANDLER_H | ||
|
|
||
| #include "rpc_message.h" | ||
|
|
||
| #include <functional> | ||
|
|
||
| namespace logos::plain { | ||
|
|
||
| // ----------------------------------------------------------------------------- | ||
| // IncomingCallHandler — provider-side dispatch hook. | ||
| // | ||
| // rpc_connection hands inbound Call / Methods / Subscribe / Unsubscribe / | ||
| // Token messages to a handler that the Qt-boundary layer implements. The | ||
| // handler is what talks to the published QObject (ModuleProxy); this | ||
| // interface deliberately speaks only plain C++ types so the wire stack | ||
| // stays Qt-free. | ||
| // | ||
| // The reply callbacks can be invoked synchronously (from inside the | ||
| // handler) or asynchronously from a different thread — rpc_connection | ||
| // serializes the actual frame write internally. | ||
| // ----------------------------------------------------------------------------- | ||
| class IncomingCallHandler { | ||
| public: | ||
| virtual ~IncomingCallHandler() = default; | ||
|
|
||
| using CallReply = std::function<void(ResultMessage)>; | ||
| using MethodsReply = std::function<void(MethodsResultMessage)>; | ||
| using EventSink = std::function<void(EventMessage)>; | ||
|
|
||
| virtual void onCall(const CallMessage& req, CallReply reply) = 0; | ||
|
|
||
| virtual void onMethods(const MethodsMessage& req, MethodsReply reply) = 0; | ||
|
|
||
| // `sink` stays alive until onUnsubscribe fires or the connection dies. | ||
| // The handler must call `sink(evt)` on every matching emission. | ||
| virtual void onSubscribe(const SubscribeMessage& req, EventSink sink) = 0; | ||
|
|
||
| virtual void onUnsubscribe(const UnsubscribeMessage& req) = 0; | ||
|
|
||
| virtual void onToken(const TokenMessage& req) = 0; | ||
| }; | ||
|
|
||
| } // namespace logos::plain | ||
|
|
||
| #endif // LOGOS_PLAIN_INCOMING_CALL_HANDLER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include "io_context_pool.h" | ||
|
|
||
| namespace logos::plain { | ||
|
|
||
| IoContextPool::IoContextPool() | ||
| : m_ioc() | ||
| , m_guard(boost::asio::make_work_guard(m_ioc)) | ||
| , m_worker([this]{ m_ioc.run(); }) | ||
| { | ||
| } | ||
|
|
||
| IoContextPool::~IoContextPool() | ||
| { | ||
| // Drop the work guard so run() can return once all outstanding work | ||
| // completes, then stop forcefully if something lingers. | ||
| m_guard.reset(); | ||
| m_ioc.stop(); | ||
| if (m_worker.joinable()) | ||
| m_worker.join(); | ||
| } | ||
|
|
||
| IoContextPool& IoContextPool::shared() | ||
| { | ||
| static IoContextPool pool; | ||
| return pool; | ||
| } | ||
|
|
||
| } // namespace logos::plain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #ifndef LOGOS_PLAIN_IO_CONTEXT_POOL_H | ||
| #define LOGOS_PLAIN_IO_CONTEXT_POOL_H | ||
|
|
||
| #include <boost/asio/executor_work_guard.hpp> | ||
| #include <boost/asio/io_context.hpp> | ||
|
|
||
| #include <memory> | ||
| #include <thread> | ||
|
|
||
| namespace logos::plain { | ||
|
|
||
| // ----------------------------------------------------------------------------- | ||
| // IoContextPool — owns a single boost::asio::io_context and a worker thread | ||
| // that runs it until the pool is destroyed. | ||
| // | ||
| // One pool per SDK process is sufficient for our traffic (a handful of | ||
| // concurrent connections). If we ever need more parallelism, swap for a | ||
| // multi-thread pool (one io_context per thread + round-robin dispatch). | ||
| // | ||
| // Access the shared pool via `sharedPool()`; tests / special cases can | ||
| // construct their own. | ||
| // ----------------------------------------------------------------------------- | ||
| class IoContextPool { | ||
| public: | ||
| IoContextPool(); | ||
| ~IoContextPool(); | ||
|
|
||
| IoContextPool(const IoContextPool&) = delete; | ||
| IoContextPool& operator=(const IoContextPool&) = delete; | ||
|
|
||
| boost::asio::io_context& ioContext() { return m_ioc; } | ||
|
|
||
| // Process-wide default pool. Thread-safe lazy init. | ||
| static IoContextPool& shared(); | ||
|
|
||
| private: | ||
| boost::asio::io_context m_ioc; | ||
| boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_guard; | ||
| std::thread m_worker; | ||
| }; | ||
|
|
||
| } // namespace logos::plain | ||
|
|
||
| #endif // LOGOS_PLAIN_IO_CONTEXT_POOL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include "json_codec.h" | ||
| #include "json_mapping.h" | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
|
|
||
| namespace logos::plain { | ||
|
|
||
| using json = nlohmann::json; | ||
|
|
||
| std::vector<uint8_t> JsonCodec::encode(const AnyMessage& msg) | ||
| { | ||
| const json j = messageToJson(msg); | ||
| const std::string s = j.dump(); | ||
| return std::vector<uint8_t>(s.begin(), s.end()); | ||
| } | ||
|
|
||
| AnyMessage JsonCodec::decode(MessageType tag, const uint8_t* data, std::size_t len) | ||
| { | ||
| json j; | ||
| try { | ||
| j = json::parse(data, data + len); | ||
| } catch (const std::exception& e) { | ||
| throw CodecError(std::string("json parse failed: ") + e.what()); | ||
| } | ||
| return jsonToMessage(tag, j); | ||
| } | ||
|
|
||
| } // namespace logos::plain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef LOGOS_PLAIN_JSON_CODEC_H | ||
| #define LOGOS_PLAIN_JSON_CODEC_H | ||
|
|
||
| #include "wire_codec.h" | ||
|
|
||
| namespace logos::plain { | ||
|
|
||
| // JsonCodec — uses nlohmann::json::dump / parse for the payload bytes. | ||
| // Default codec for now; a future CborCodec will swap in by using | ||
| // json::to_cbor / from_cbor on the same message structs. | ||
| class JsonCodec : public IWireCodec { | ||
| public: | ||
| std::vector<uint8_t> encode(const AnyMessage&) override; | ||
| AnyMessage decode(MessageType tag, | ||
| const uint8_t* data, | ||
| std::size_t len) override; | ||
| std::string name() const override { return "json"; } | ||
| }; | ||
|
|
||
| } // namespace logos::plain | ||
|
|
||
| #endif // LOGOS_PLAIN_JSON_CODEC_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plain transport uses Boost.Asio (and boost::system::error_code), which commonly requires linking Boost.System. Here the target links only
Boost::headers; that can cause downstream link errors on platforms where Boost.System is not header-only, andBoost::headersmay not exist when Boost is found via CMake’s FindBoost module. Consider requesting/linkingBoost::system(andBoost::boost/headers) explicitly.