mirror of
https://github.com/logos-co/logos-protocol.git
synced 2026-08-31 14:01:14 +00:00
* Extract the Logos protocol layer from logos-cpp-sdk
Transports (plain TCP/TLS, qt_local, qt_remote/QRO, mock), token manager,
consumer core (LogosAPIClient/LogosAPIConsumer incl. the capability
auto-requestModule flow), ModuleProxy, the abstract LogosProviderObject
interface, and the canonical QVariant<->JSON conversion — now behind the
language-neutral lp_* C ABI (logos_protocol.h) carrying the protocol
semver (LOGOS_PROTOCOL_VERSION_*, lp_protocol_version()).
Bytes crossing the ABI use the lossless {"_bytes": base64url} tagging
(NUL-safe), matching the plain wire encoding.
Provider lp_* surface is compiled groundwork; serving lands with module
authoring.
* consumer: typed requestModule for the capability flow
Port of logos-cpp-sdk master f5a127dd ('use updated capability module',
cpp-sdk#85, Iuri Matias) — the touched files (logos_api_client.cpp,
logos_api_consumer.{h,cpp}) moved into this repo in the P1 extraction.
The capability auto-requestModule path now calls a typed std::string
helper on the consumer (which acquires the capability object directly)
instead of a stringly invokeRemoteMethod round-trip. 111/111 tests.
106 lines
3.5 KiB
C++
106 lines
3.5 KiB
C++
#ifndef LOGOS_PLAIN_RPC_SERVER_H
|
|
#define LOGOS_PLAIN_RPC_SERVER_H
|
|
|
|
#include "incoming_call_handler.h"
|
|
#include "rpc_connection.h"
|
|
#include "wire_codec.h"
|
|
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
#include <boost/asio/ssl/context.hpp>
|
|
#include <boost/asio/ssl/stream.hpp>
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace logos::plain {
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// RpcServer (TCP) — accepts TCP connections, wraps each in an
|
|
// RpcConnection, keeps them alive until they drop.
|
|
//
|
|
// Every accepted connection uses the same shared IncomingCallHandler so
|
|
// the provider layer can dispatch regardless of which client is talking.
|
|
// The server doesn't multiplex objects by itself; it's the handler's job
|
|
// to look up the target object for each incoming CallMessage.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
using TcpStream = boost::asio::ip::tcp::socket;
|
|
using TcpConnection = RpcConnection<TcpStream>;
|
|
|
|
class RpcServerTcp : public std::enable_shared_from_this<RpcServerTcp> {
|
|
public:
|
|
RpcServerTcp(boost::asio::io_context& ioc,
|
|
const std::string& host,
|
|
uint16_t port,
|
|
std::shared_ptr<IWireCodec> codec,
|
|
IncomingCallHandler* handler);
|
|
|
|
// Start accepting. Returns false if bind fails.
|
|
bool start();
|
|
|
|
// Actual bound port (useful when the caller requested port=0).
|
|
uint16_t boundPort() const { return m_boundPort; }
|
|
|
|
void stop();
|
|
|
|
private:
|
|
void doAccept();
|
|
|
|
boost::asio::ip::tcp::acceptor m_acceptor;
|
|
std::shared_ptr<IWireCodec> m_codec;
|
|
IncomingCallHandler* m_handler;
|
|
std::string m_host;
|
|
uint16_t m_port;
|
|
uint16_t m_boundPort = 0;
|
|
|
|
std::mutex m_mu;
|
|
std::vector<std::shared_ptr<TcpConnection>> m_conns;
|
|
bool m_stopped = false;
|
|
};
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// RpcServer (TLS) — same as TCP but wraps every accepted socket in an
|
|
// asio::ssl::stream and completes the handshake before spinning up the
|
|
// RpcConnection.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
using SslStream = boost::asio::ssl::stream<boost::asio::ip::tcp::socket>;
|
|
using SslConnection = RpcConnection<SslStream>;
|
|
|
|
class RpcServerSsl : public std::enable_shared_from_this<RpcServerSsl> {
|
|
public:
|
|
RpcServerSsl(boost::asio::io_context& ioc,
|
|
const std::string& host,
|
|
uint16_t port,
|
|
boost::asio::ssl::context sslCtx,
|
|
std::shared_ptr<IWireCodec> codec,
|
|
IncomingCallHandler* handler);
|
|
|
|
bool start();
|
|
uint16_t boundPort() const { return m_boundPort; }
|
|
void stop();
|
|
|
|
private:
|
|
void doAccept();
|
|
|
|
boost::asio::ip::tcp::acceptor m_acceptor;
|
|
boost::asio::ssl::context m_sslCtx;
|
|
std::shared_ptr<IWireCodec> m_codec;
|
|
IncomingCallHandler* m_handler;
|
|
std::string m_host;
|
|
uint16_t m_port;
|
|
uint16_t m_boundPort = 0;
|
|
|
|
std::mutex m_mu;
|
|
std::vector<std::shared_ptr<SslConnection>> m_conns;
|
|
bool m_stopped = false;
|
|
};
|
|
|
|
} // namespace logos::plain
|
|
|
|
#endif // LOGOS_PLAIN_RPC_SERVER_H
|