Skip to content

Commit

Permalink
Merge pull request #65 from aivve/ssl/alt_server
Browse files Browse the repository at this point in the history
Alt https server for RPC
  • Loading branch information
aivve authored Jul 22, 2022
2 parents 60fbf49 + 2f48ad1 commit c3717ea
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 56 deletions.
55 changes: 29 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,30 @@ set(CRYPTONOTE_SOURCES
cryptonote/src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp
cryptonote/src/InProcessNode/InProcessNode.cpp
cryptonote/src/InProcessNode/InProcessNodeErrors.cpp
cryptonote/src/HTTP/httplib.h
cryptonote/src/HTTP/HttpRequest.cpp
cryptonote/src/HTTP/HttpParser.cpp
cryptonote/src/HTTP/HttpParserErrorCodes.cpp
cryptonote/src/HTTP/HttpResponse.cpp
cryptonote/src/Logging/ILogger.cpp
cryptonote/src/Logging/LoggerGroup.cpp
cryptonote/src/Logging/CommonLogger.cpp
cryptonote/src/Logging/LoggerManager.cpp
cryptonote/src/Logging/FileLogger.cpp
cryptonote/src/Logging/StreamLogger.cpp
cryptonote/src/Logging/ConsoleLogger.cpp
cryptonote/src/Logging/LoggerMessage.cpp
cryptonote/src/Logging/LoggerRef.cpp
cryptonote/src/NodeRpcProxy/NodeErrors.cpp
cryptonote/src/NodeRpcProxy/NodeRpcProxy.cpp
cryptonote/src/P2p/LevinProtocol.cpp
cryptonote/src/P2p/NetNodeConfig.cpp
cryptonote/src/P2p/NetNode.cpp
cryptonote/src/P2p/NetNodeConfig.cpp
cryptonote/src/P2p/PeerListManager.cpp
cryptonote/src/Rpc/JsonRpc.cpp
cryptonote/src/Rpc/RpcServer.cpp
cryptonote/src/Rpc/RpcServerConfig.cpp
cryptonote/src/Serialization/BinaryInputStreamSerializer.cpp
cryptonote/src/Serialization/BinaryOutputStreamSerializer.cpp
cryptonote/src/Serialization/JsonInputValueSerializer.cpp
Expand All @@ -226,6 +247,13 @@ set(CRYPTONOTE_SOURCES
cryptonote/src/Serialization/KVBinaryOutputStreamSerializer.cpp
cryptonote/src/Serialization/BlockchainExplorerDataSerialization.cpp
cryptonote/src/Serialization/SerializationOverloads.cpp
cryptonote/src/System/ContextGroup.cpp
cryptonote/src/System/Event.cpp
cryptonote/src/System/EventLock.cpp
cryptonote/src/System/InterruptedException.cpp
cryptonote/src/System/Ipv4Address.cpp
cryptonote/src/System/SocketStream.cpp
cryptonote/src/System/TcpStream.cpp
cryptonote/src/Transfers/BlockchainSynchronizer.cpp
cryptonote/src/Transfers/SynchronizationState.cpp
cryptonote/src/Transfers/TransfersConsumer.cpp
Expand All @@ -246,32 +274,6 @@ set(CRYPTONOTE_SOURCES
cryptonote/src/WalletLegacy/WalletTransactionSender.cpp
cryptonote/src/WalletLegacy/WalletUnconfirmedTransactions.cpp
cryptonote/src/WalletLegacy/WalletUserTransactionsCache.cpp
cryptonote/src/System/ContextGroup.cpp
cryptonote/src/System/Event.cpp
cryptonote/src/System/EventLock.cpp
cryptonote/src/System/InterruptedException.cpp
cryptonote/src/System/Ipv4Address.cpp
cryptonote/src/System/SocketStream.cpp
cryptonote/src/System/TcpStream.cpp
cryptonote/src/HTTP/HttpRequest.cpp
cryptonote/src/HTTP/HttpParser.cpp
cryptonote/src/HTTP/HttpParserErrorCodes.cpp
cryptonote/src/HTTP/HttpResponse.cpp
cryptonote/src/Rpc/HttpClient.cpp
cryptonote/src/Rpc/JsonRpc.cpp
cryptonote/src/P2p/NetNode.cpp
cryptonote/src/P2p/LevinProtocol.cpp
cryptonote/src/P2p/NetNodeConfig.cpp
cryptonote/src/P2p/PeerListManager.cpp
cryptonote/src/Logging/ILogger.cpp
cryptonote/src/Logging/LoggerGroup.cpp
cryptonote/src/Logging/CommonLogger.cpp
cryptonote/src/Logging/LoggerManager.cpp
cryptonote/src/Logging/FileLogger.cpp
cryptonote/src/Logging/StreamLogger.cpp
cryptonote/src/Logging/ConsoleLogger.cpp
cryptonote/src/Logging/LoggerMessage.cpp
cryptonote/src/Logging/LoggerRef.cpp
cryptonote/src/BlockchainExplorer/BlockchainExplorer.cpp
cryptonote/src/BlockchainExplorer/BlockchainExplorerDataBuilder.cpp
cryptonote/src/BlockchainExplorer/BlockchainExplorerErrors.cpp
Expand Down Expand Up @@ -506,6 +508,7 @@ if (WIN32)
endif ()

if (OPENSSL_FOUND)
add_definitions(-DCPPHTTPLIB_OPENSSL_SUPPORT)
target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES})
if (MSVC)
target_link_libraries(${PROJECT_NAME} Rpcrt4 ws2_32 advapi32 crypt32 gdi32 user32)
Expand Down
2 changes: 1 addition & 1 deletion cryptonote
Submodule cryptonote updated 49 files
+9 −6 CMakeLists.txt
+0 −37 src/BinaryInfo/connectivity_tool.rc
+2 −0 src/BlockchainExplorer/BlockchainExplorerDataBuilder.cpp
+7 −13 src/CMakeLists.txt
+1 −1 src/Checkpoints/Checkpoints.cpp
+3 −2 src/Common/ConsoleHandler.cpp
+1 −1 src/CryptoNoteConfig.h
+2 −2 src/CryptoNoteCore/CryptoNoteBasicImpl.h
+1 −1 src/CryptoNoteCore/Miner.cpp
+0 −5 src/CryptoNoteCore/TransactionPool.cpp
+2 −2 src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp
+78 −97 src/Daemon/Daemon.cpp
+1 −1 src/Daemon/DaemonCommandsHandler.cpp
+121 −0 src/HTTP/TaskQueue.h
+8,229 −0 src/HTTP/httplib.h
+110 −26 src/JsonRpcServer/JsonRpcServer.cpp
+28 −11 src/JsonRpcServer/JsonRpcServer.h
+101 −81 src/NodeRpcProxy/NodeRpcProxy.cpp
+6 −5 src/NodeRpcProxy/NodeRpcProxy.h
+7 −7 src/Optimizer/Optimizer.cpp
+72 −71 src/P2p/NetNode.cpp
+54 −60 src/P2p/NetNode.h
+8 −5 src/P2p/NetNodeCommon.h
+1 −1 src/P2p/P2pNetworks.h
+1 −1 src/PaymentGate/PaymentServiceJsonRpcServer.h
+33 −63 src/PaymentGateService/PaymentGateService.cpp
+0 −6 src/PaymentGateService/PaymentServiceConfiguration.cpp
+0 −1 src/PaymentGateService/PaymentServiceConfiguration.h
+2 −31 src/PaymentGateService/RpcNodeConfiguration.cpp
+1 −5 src/PaymentGateService/RpcNodeConfiguration.h
+11 −11 src/Platform/Windows/System/Dispatcher.cpp
+2 −2 src/Platform/Windows/System/TcpListener.cpp
+69 −1 src/Rpc/CoreRpcServerCommandsDefinitions.h
+0 −301 src/Rpc/HttpClient.cpp
+0 −157 src/Rpc/HttpClient.h
+0 −386 src/Rpc/HttpServer.cpp
+0 −85 src/Rpc/HttpServer.h
+8 −12 src/Rpc/JsonRpc.cpp
+28 −4 src/Rpc/JsonRpc.h
+970 −218 src/Rpc/RpcServer.cpp
+52 −20 src/Rpc/RpcServer.h
+97 −19 src/Rpc/RpcServerConfig.cpp
+12 −4 src/Rpc/RpcServerConfig.h
+114 −74 src/SimpleWallet/SimpleWallet.cpp
+10 −7 src/SimpleWallet/SimpleWallet.h
+20 −20 src/Transfers/BlockchainSynchronizer.cpp
+124 −40 src/Wallet/WalletRpcServer.cpp
+25 −15 src/Wallet/WalletRpcServer.h
+7 −7 src/crypto/oaes_lib.c
24 changes: 24 additions & 0 deletions src/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ CommandLineParser::CommandLineParser(QObject* _parent) : QObject(_parent), m_par
m_withoutCheckpointsOption("without-checkpoints", tr("Do not load checkpoints for full blocks validation")),
m_p2pBindIpOption("p2p-bind-ip", tr("Interface for p2p network protocol"), tr("ip"), "0.0.0.0"),
m_p2pBindPortOption("p2p-bind-port", tr("Port for p2p network protocol"), tr("port"), QString::number(CryptoNote::P2P_DEFAULT_PORT)),
m_rpcBindIpOption("rpc-bind-ip", tr("Interface for RPC server"), tr("ip"), "127.0.0.1"),
m_rpcBindPortOption("rpc-bind-port", tr("Port for RPC server"), tr("port"), QString::number(CryptoNote::RPC_DEFAULT_PORT)),
m_rpcOption("rpc-server", tr("Run RPC server")),
m_restrictedRpcOption("restricted-rpc", tr("Disallow some RPC server queries")),
m_p2pExternalOption("p2p-external-port", tr("External port for p2p network protocol (if port forwarding used with NAT)"),
tr("port"), 0),
m_allowLocalIpOption("allow-local-ip", tr("Allow local ip add to peer list, mostly in debug purposes")),
Expand All @@ -39,6 +43,10 @@ CommandLineParser::CommandLineParser(QObject* _parent) : QObject(_parent), m_par
m_parser.addOption(m_withoutCheckpointsOption);
m_parser.addOption(m_p2pBindIpOption);
m_parser.addOption(m_p2pBindPortOption);
m_parser.addOption(m_rpcBindIpOption);
m_parser.addOption(m_rpcBindPortOption);
m_parser.addOption(m_rpcOption);
m_parser.addOption(m_restrictedRpcOption);
m_parser.addOption(m_p2pExternalOption);
m_parser.addOption(m_allowLocalIpOption);
m_parser.addOption(m_addPeerOption);
Expand Down Expand Up @@ -117,6 +125,22 @@ quint16 CommandLineParser::getP2pBindPort() const {
return m_parser.value(m_p2pBindPortOption).toUShort();
}

QString CommandLineParser::getRpcBindIp() const {
return m_parser.value(m_rpcBindIpOption);
}

quint16 CommandLineParser::getRpcBindPort() const {
return m_parser.value(m_rpcBindPortOption).toUShort();
}

bool CommandLineParser::hasRpcOption() const {
return m_parser.isSet(m_rpcOption);
}

bool CommandLineParser::hasRestrictedRpcOption() const {
return m_parser.isSet(m_restrictedRpcOption);
}

quint16 CommandLineParser::getP2pExternalPort() const {
return m_parser.value(m_p2pExternalOption).toUShort();
}
Expand Down
8 changes: 8 additions & 0 deletions src/CommandLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ class CommandLineParser : public QObject {
bool hasHideMyPortOption() const;
bool hasPortableOption() const;
bool hasAllowReorgOption() const;
bool hasRpcOption() const;
bool hasRestrictedRpcOption() const;
QString getErrorText() const;
QString getHelpText() const;
QString getP2pBindIp() const;
quint16 getP2pBindPort() const;
QString getRpcBindIp() const;
quint16 getRpcBindPort() const;
quint16 getP2pExternalPort() const;
QStringList getPeers() const;
QStringList getPiorityNodes() const;
Expand All @@ -49,6 +53,10 @@ class CommandLineParser : public QObject {
QCommandLineOption m_withoutCheckpointsOption;
QCommandLineOption m_p2pBindIpOption;
QCommandLineOption m_p2pBindPortOption;
QCommandLineOption m_rpcBindIpOption;
QCommandLineOption m_rpcBindPortOption;
QCommandLineOption m_rpcOption;
QCommandLineOption m_restrictedRpcOption;
QCommandLineOption m_p2pExternalOption;
QCommandLineOption m_allowLocalIpOption;
QCommandLineOption m_addPeerOption;
Expand Down
40 changes: 23 additions & 17 deletions src/CryptoNoteWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#include "CryptoNoteCore/Miner.h"
#include "CryptoNoteCore/MinerConfig.h"
#include "CryptoNoteCore/TransactionExtra.h"
#include "HTTP/httplib.h"
#include "Rpc/CoreRpcServerCommandsDefinitions.h"
#include "Rpc/HttpClient.h"
#include "Rpc/RpcServer.h"
#include "Rpc/JsonRpc.h"
#include "CryptoNoteProtocol/CryptoNoteProtocolHandler.h"
#include "InProcessNode/InProcessNode.h"
#include "P2p/NetNode.h"
Expand Down Expand Up @@ -214,8 +216,8 @@ class RpcNode : public CryptoNote::INodeObserver, public CryptoNote::INodeRpcPro
CryptoNote::COMMAND_RPC_GETBLOCKTEMPLATE::response rsp = AUTO_VAL_INIT(rsp);
req.miner_spend_key = Common::podToHex(acc.spendSecretKey);
req.miner_view_key = Common::podToHex(acc.viewSecretKey);
CryptoNote::HttpClient httpClient(m_dispatcher, m_node.m_nodeHost, m_node.m_nodePort, false);
CryptoNote::invokeJsonRpcCommand(httpClient, "getblocktemplate", req, rsp);
httplib::Client httpClient (m_node.m_nodeHost, m_node.m_nodePort);
CryptoNote::JsonRpc::invokeJsonRpcCommand(httpClient, "getblocktemplate", req, rsp);
std::string err = interpret_rpc_response(true, rsp.status);
if (err.empty()) {
if (!CryptoNote::fromBinaryArray(b, Common::fromHex(rsp.blocktemplate_blob))) {
Expand All @@ -231,10 +233,6 @@ class RpcNode : public CryptoNote::INodeObserver, public CryptoNote::INodeRpcPro
m_logger(Logging::INFO) << "Failed to invoke request: " << err;
}
}
catch (const CryptoNote::ConnectException&) {
m_logger(Logging::INFO) << "Wallet failed to connect to daemon.";
return false;
}
catch (const std::exception& e) {
m_logger(Logging::INFO) << "Failed to invoke RPC method: " << e.what();
return false;
Expand All @@ -248,8 +246,8 @@ class RpcNode : public CryptoNote::INodeObserver, public CryptoNote::INodeRpcPro
CryptoNote::COMMAND_RPC_SUBMITBLOCK::request req;
req.emplace_back(Common::toHex(CryptoNote::toBinaryArray(b)));
CryptoNote::COMMAND_RPC_SUBMITBLOCK::response res;
CryptoNote::HttpClient httpClient(m_dispatcher, m_node.m_nodeHost, m_node.m_nodePort, false);
CryptoNote::invokeJsonRpcCommand(httpClient, "submitblock", req, res);
httplib::Client httpClient(m_node.m_nodeHost, m_node.m_nodePort);
CryptoNote::JsonRpc::invokeJsonRpcCommand(httpClient, "submitblock", req, res);
std::string err = interpret_rpc_response(true, res.status);
if (err.empty()) {
return true;
Expand All @@ -258,10 +256,6 @@ class RpcNode : public CryptoNote::INodeObserver, public CryptoNote::INodeRpcPro
m_logger(Logging::INFO) << "Failed to invoke request: " << err;
}
}
catch (const CryptoNote::ConnectException&) {
m_logger(Logging::INFO) << "Wallet failed to connect to daemon.";
return false;
}
catch (const std::exception& e) {
m_logger(Logging::INFO) << "Failed to invoke RPC method: " << e.what();
return false;
Expand Down Expand Up @@ -337,15 +331,16 @@ class InprocessNode : public CryptoNote::INodeObserver, public Node {
public:
Logging::LoggerManager& m_logManager;
InprocessNode(const CryptoNote::Currency& currency, Logging::LoggerManager& logManager, const CryptoNote::CoreConfig& coreConfig,
const CryptoNote::NetNodeConfig& netNodeConfig, INodeCallback& callback) :
const CryptoNote::NetNodeConfig& netNodeConfig, const CryptoNote::RpcServerConfig& rpcServerConfig, INodeCallback& callback) :
m_currency(currency), m_dispatcher(),
m_callback(callback),
m_logManager(logManager),
m_logger(m_logManager, "InprocessNode"),
m_coreConfig(coreConfig),
m_netNodeConfig(netNodeConfig),
m_rpcServerConfig(rpcServerConfig),
m_protocolHandler(currency, m_dispatcher, m_core, nullptr, logManager),
m_core(currency, &m_protocolHandler, logManager, m_dispatcher, true),
m_core(currency, &m_protocolHandler, logManager, m_dispatcher, true, false, false),
m_nodeServer(m_dispatcher, m_protocolHandler, logManager),
m_node(m_core, m_protocolHandler)
{
Expand Down Expand Up @@ -393,6 +388,14 @@ class InprocessNode : public CryptoNote::INodeObserver, public Node {
callback(make_error_code(CryptoNote::error::NOT_INITIALIZED));
return;
}

if (Settings::instance().hasRunRpc()) {
m_logger(Logging::INFO) << "Starting core rpc server...";
m_rpcServer = new CryptoNote::RpcServer(m_rpcServerConfig, m_dispatcher, m_logManager, m_core, m_nodeServer, m_protocolHandler);
m_rpcServer->start();
m_logger(Logging::INFO) << "Core rpc server started ok";
}

} catch (std::runtime_error& _err) {
callback(make_error_code(CryptoNote::error::NOT_INITIALIZED));
return;
Expand All @@ -405,6 +408,7 @@ class InprocessNode : public CryptoNote::INodeObserver, public Node {

m_nodeServer.run();
m_nodeServer.deinit();
m_rpcServer->stop();
m_core.deinit();
m_node.shutdown();
}
Expand Down Expand Up @@ -548,12 +552,14 @@ class InprocessNode : public CryptoNote::INodeObserver, public Node {
System::Dispatcher m_dispatcher;
CryptoNote::CoreConfig m_coreConfig;
CryptoNote::NetNodeConfig m_netNodeConfig;
CryptoNote::RpcServerConfig m_rpcServerConfig;
CryptoNote::Core m_core;
CryptoNote::CryptoNoteProtocolHandler m_protocolHandler;
CryptoNote::NodeServer m_nodeServer;
CryptoNote::InProcessNode m_node;
std::future<bool> m_nodeServerFuture;
Logging::LoggerRef m_logger;
CryptoNote::RpcServer* m_rpcServer;

void peerCountUpdated(size_t count) override {
m_callback.peerCountUpdated(*this, count);
Expand All @@ -578,8 +584,8 @@ Node* createRpcNode(const CryptoNote::Currency& currency, INodeCallback& callbac
}

Node* createInprocessNode(const CryptoNote::Currency& currency, Logging::LoggerManager& logManager,
const CryptoNote::CoreConfig& coreConfig, const CryptoNote::NetNodeConfig& netNodeConfig, INodeCallback& callback) {
return new InprocessNode(currency, logManager, coreConfig, netNodeConfig, callback);
const CryptoNote::CoreConfig& coreConfig, const CryptoNote::NetNodeConfig& netNodeConfig, const CryptoNote::RpcServerConfig& rpcServerConfig, INodeCallback& callback) {
return new InprocessNode(currency, logManager, coreConfig, netNodeConfig, rpcServerConfig, callback);
}

}
4 changes: 3 additions & 1 deletion src/CryptoNoteWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <system_error>
#include <INode.h>
#include <Logging/LoggerRef.h>
#include <Rpc/RpcServerConfig.h>

namespace CryptoNote {

Expand All @@ -19,6 +20,7 @@ class IWalletLegacy;
class Currency;
class CoreConfig;
class NetNodeConfig;
class RpcServerConfig;

}

Expand Down Expand Up @@ -80,6 +82,6 @@ class INodeCallback {

Node* createRpcNode(const CryptoNote::Currency& currency, INodeCallback& callback, Logging::LoggerManager& logManager, const std::string& nodeHost, unsigned short nodePort, bool enableSSL);
Node* createInprocessNode(const CryptoNote::Currency& currency, Logging::LoggerManager& logManager,
const CryptoNote::CoreConfig& coreConfig, const CryptoNote::NetNodeConfig& netNodeConfig, INodeCallback& callback);
const CryptoNote::CoreConfig& coreConfig, const CryptoNote::NetNodeConfig& netNodeConfig, const CryptoNote::RpcServerConfig& rpcServerConfig, INodeCallback& callback);

}
51 changes: 44 additions & 7 deletions src/NodeAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
#include <QTimer>
#include <QUrl>

#include <CryptoNoteCore/CoreConfig.h>
#include <P2p/NetNodeConfig.h>
#include <Wallet/WalletErrors.h>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>

#include "CryptoNoteCore/CoreConfig.h"
#include "CurrencyAdapter.h"
#include "LoggerAdapter.h"
#include "NodeAdapter.h"
#include "P2p/NetNodeConfig.h"
#include "Rpc/RpcServerConfig.h"
#include "Settings.h"
#include <boost/program_options/variables_map.hpp>
#include "Wallet/WalletErrors.h"

namespace WalletGui {

Expand Down Expand Up @@ -51,8 +53,8 @@ class InProcessNodeInitializer : public QObject {
}

void start(Node** _node, const CryptoNote::Currency* currency, INodeCallback* _callback, Logging::LoggerManager* _loggerManager,
const CryptoNote::CoreConfig& _coreConfig, const CryptoNote::NetNodeConfig& _netNodeConfig) {
(*_node) = createInprocessNode(*currency, *_loggerManager, _coreConfig, _netNodeConfig, *_callback);
const CryptoNote::CoreConfig& _coreConfig, const CryptoNote::NetNodeConfig& _netNodeConfig, const CryptoNote::RpcServerConfig& _rpcServerConfig) {
(*_node) = createInprocessNode(*currency, *_loggerManager, _coreConfig, _netNodeConfig, _rpcServerConfig, *_callback);
try {
(*_node)->init([this](std::error_code _err) {
if (_err) {
Expand Down Expand Up @@ -91,6 +93,7 @@ NodeAdapter::NodeAdapter() : QObject(), m_node(nullptr), m_nodeInitializerThread

qRegisterMetaType<CryptoNote::CoreConfig>("CryptoNote::CoreConfig");
qRegisterMetaType<CryptoNote::NetNodeConfig>("CryptoNote::NetNodeConfig");
qRegisterMetaType<CryptoNote::RpcServerConfig>("CryptoNote::RpcServerConfig");

connect(m_nodeInitializer, &InProcessNodeInitializer::nodeInitCompletedSignal, this, &NodeAdapter::nodeInitCompletedSignal, Qt::QueuedConnection);
connect(this, &NodeAdapter::initNodeSignal, m_nodeInitializer, &InProcessNodeInitializer::start, Qt::QueuedConnection);
Expand Down Expand Up @@ -354,7 +357,8 @@ bool NodeAdapter::initInProcessNode() {
m_nodeInitializerThread.start();
CryptoNote::CoreConfig coreConfig = makeCoreConfig();
CryptoNote::NetNodeConfig netNodeConfig = makeNetNodeConfig();
Q_EMIT initNodeSignal(&m_node, &CurrencyAdapter::instance().getCurrency(), this, &LoggerAdapter::instance().getLoggerManager(), coreConfig, netNodeConfig);
CryptoNote::RpcServerConfig rpcServerConfig = makeRpcServerConfig();
Q_EMIT initNodeSignal(&m_node, &CurrencyAdapter::instance().getCurrency(), this, &LoggerAdapter::instance().getLoggerManager(), coreConfig, netNodeConfig, rpcServerConfig);
QEventLoop waitLoop;
connect(m_nodeInitializer, &InProcessNodeInitializer::nodeInitCompletedSignal, &waitLoop, &QEventLoop::quit);
connect(m_nodeInitializer, &InProcessNodeInitializer::nodeInitFailedSignal, &waitLoop, &QEventLoop::exit);
Expand Down Expand Up @@ -441,6 +445,39 @@ CryptoNote::NetNodeConfig NodeAdapter::makeNetNodeConfig() const {
return config;
}

CryptoNote::RpcServerConfig NodeAdapter::makeRpcServerConfig() const {
CryptoNote::RpcServerConfig config;
boost::filesystem::path dataDir = std::string(Settings::instance().getDataDir().absolutePath().toLocal8Bit().data());
config.setDataDir(dataDir.string());
boost::program_options::variables_map options;
boost::any rpcBindIp = Settings::instance().getRpcBindIp().toStdString();
boost::any rpcBindPort = static_cast<uint16_t>(Settings::instance().getRpcBindPort());

options.insert(std::make_pair("rpc-bind-ip", boost::program_options::variable_value(rpcBindIp, false)));
options.insert(std::make_pair("rpc-bind-port", boost::program_options::variable_value(rpcBindPort, false)));

// dummy defaults
std::string dummy = "", cors = "*";
uint16_t sslport = CryptoNote::RPC_DEFAULT_SSL_PORT;
bool no = false;
options.insert(std::make_pair("rpc-bind-ssl-port", boost::program_options::variable_value(sslport, false)));
options.insert(std::make_pair("rpc-bind-ssl-enable", boost::program_options::variable_value(no, false)));
options.insert(std::make_pair("rpc-chain-file", boost::program_options::variable_value(dummy, false)));
options.insert(std::make_pair("rpc-key-file", boost::program_options::variable_value(dummy, false)));
options.insert(std::make_pair("rpc-bind-ssl-enable", boost::program_options::variable_value(dummy, false)));
options.insert(std::make_pair("enable-cors", boost::program_options::variable_value(cors, false)));
options.insert(std::make_pair("contact", boost::program_options::variable_value(dummy, false)));
options.insert(std::make_pair("fee-address", boost::program_options::variable_value(dummy, false)));
options.insert(std::make_pair("fee-amount", boost::program_options::variable_value(dummy, false)));
options.insert(std::make_pair("view-key", boost::program_options::variable_value(dummy, false)));

options.insert(std::make_pair("restricted-rpc", boost::program_options::variable_value(Settings::instance().hasRestrictedRpc(), false)));

config.init(options);

return config;
}

bool NodeAdapter::isOffline() {
return getConnectionsCount() == 0;
}
Expand Down
Loading

0 comments on commit c3717ea

Please sign in to comment.