From 8f2ef6258092959407aeadc7faa6260bef95fca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 22 Nov 2017 17:58:54 +0100 Subject: [PATCH] rpc: Drop HTTP server --- cmake/ProjectJsonRpcCpp.cmake | 2 +- eth/main.cpp | 72 ++++++------------------------- libweb3jsonrpc/CMakeLists.txt | 3 +- libweb3jsonrpc/Eth.cpp | 7 --- libweb3jsonrpc/Eth.h | 3 -- libweb3jsonrpc/SafeHttpServer.cpp | 69 ----------------------------- libweb3jsonrpc/SafeHttpServer.h | 48 --------------------- 7 files changed, 15 insertions(+), 189 deletions(-) delete mode 100644 libweb3jsonrpc/SafeHttpServer.cpp delete mode 100644 libweb3jsonrpc/SafeHttpServer.h diff --git a/cmake/ProjectJsonRpcCpp.cmake b/cmake/ProjectJsonRpcCpp.cmake index 2bbfa954e77..a0d8e2bc268 100644 --- a/cmake/ProjectJsonRpcCpp.cmake +++ b/cmake/ProjectJsonRpcCpp.cmake @@ -28,7 +28,7 @@ set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= -DBUILD_SHARED_LIBS=Off -DUNIX_DOMAIN_SOCKET_SERVER=Off -DUNIX_DOMAIN_SOCKET_CLIENT=Off - -DHTTP_SERVER=On + -DHTTP_SERVER=OFF -DHTTP_CLIENT=OFF -DCOMPILE_TESTS=Off -DCOMPILE_STUBGEN=Off diff --git a/eth/main.cpp b/eth/main.cpp index 674b6fd2489..d3871464771 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -47,7 +47,6 @@ #include #include -#include #include #include #include @@ -86,15 +85,10 @@ void help() << " --private Use a private chain.\n" << " --test Testing mode: Disable PoW and provide test rpc interface.\n" << " --config Configure specialised blockchain using given JSON information.\n" - << " --oppose-dao-fork Ignore DAO hard fork (default is to participate).\n\n" << " -o,--mode Start a full node or a peer node (default: full).\n\n" - << " -j,--json-rpc Enable JSON-RPC server (default: off).\n" << " --ipc Enable IPC server (default: on).\n" << " --ipcpath Set .ipc socket path (default: data directory)\n" - << " --admin-via-http Expose admin interface via http - UNSAFE! (default: off).\n" << " --no-ipc Disable IPC server.\n" - << " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ").\n" - << " --rpccorsdomain Domain on which to send Access-Control-Allow-Origin header.\n" << " --admin Specify admin session key for JSON-RPC (default: auto-generated and printed at start-up).\n" << " -K,--kill Kill the blockchain first.\n" << " -R,--rebuild Rebuild the blockchain from the existing database.\n" @@ -320,10 +314,7 @@ int main(int argc, char** argv) /// General params for Node operation NodeMode nodeMode = NodeMode::Full; - int jsonRPCURL = -1; - bool adminViaHttp = false; bool ipc = true; - std::string rpcCorsDomain = ""; string jsonAdmin; ChainParams chainParams; @@ -665,14 +656,6 @@ int main(int argc, char** argv) else if (arg == "--import-presale" && i + 1 < argc) presaleImports.push_back(argv[++i]); - else if ((arg == "-j" || arg == "--json-rpc")) - jsonRPCURL = jsonRPCURL == -1 ? SensibleHttpPort : jsonRPCURL; - else if (arg == "--admin-via-http") - adminViaHttp = true; - else if (arg == "--json-rpc-port" && i + 1 < argc) - jsonRPCURL = atoi(argv[++i]); - else if (arg == "--rpccorsdomain" && i + 1 < argc) - rpcCorsDomain = argv[++i]; else if (arg == "--json-admin" && i + 1 < argc) jsonAdmin = argv[++i]; else if (arg == "--ipc") @@ -1117,7 +1100,6 @@ int main(int argc, char** argv) else cout << "Networking disabled. To start, use netstart or pass --bootstrap or a remote host.\n"; - unique_ptr> jsonrpcHttpServer; unique_ptr> jsonrpcIpcServer; unique_ptr sessionManager; unique_ptr accountHolder; @@ -1150,7 +1132,7 @@ int main(int argc, char** argv) ExitHandler exitHandler; - if (jsonRPCURL > -1 || ipc) + if (ipc) { using FullServer = ModularServer< rpc::EthFace, @@ -1166,44 +1148,18 @@ int main(int argc, char** argv) if (testingMode) testEth = new rpc::Test(*web3.ethereum()); - if (jsonRPCURL >= 0) - { - rpc::AdminEth* adminEth = nullptr; - rpc::PersonalFace* personal = nullptr; - rpc::AdminNet* adminNet = nullptr; - if (adminViaHttp) - { - personal = new rpc::Personal(keyManager, *accountHolder, *web3.ethereum()); - adminEth = new rpc::AdminEth(*web3.ethereum(), *gasPricer.get(), keyManager, *sessionManager.get()); - adminNet = new rpc::AdminNet(web3, *sessionManager.get()); - } + jsonrpcIpcServer.reset(new FullServer( + ethFace, new rpc::Net(web3), + new rpc::Web3(web3.clientVersion()), new rpc::Personal(keyManager, *accountHolder, *web3.ethereum()), + new rpc::AdminEth(*web3.ethereum(), *gasPricer.get(), keyManager, *sessionManager.get()), + new rpc::AdminNet(web3, *sessionManager.get()), + new rpc::Debug(*web3.ethereum()), + testEth + )); + auto ipcConnector = new IpcServer("geth"); + jsonrpcIpcServer->addConnector(ipcConnector); + ipcConnector->StartListening(); - jsonrpcHttpServer.reset(new FullServer( - ethFace, - new rpc::Net(web3), new rpc::Web3(web3.clientVersion()), personal, - adminEth, adminNet, - new rpc::Debug(*web3.ethereum()), - testEth - )); - auto httpConnector = new SafeHttpServer(jsonRPCURL, "", "", SensibleHttpThreads); - httpConnector->setAllowedOrigin(rpcCorsDomain); - jsonrpcHttpServer->addConnector(httpConnector); - jsonrpcHttpServer->StartListening(); - } - if (ipc) - { - jsonrpcIpcServer.reset(new FullServer( - ethFace, new rpc::Net(web3), - new rpc::Web3(web3.clientVersion()), new rpc::Personal(keyManager, *accountHolder, *web3.ethereum()), - new rpc::AdminEth(*web3.ethereum(), *gasPricer.get(), keyManager, *sessionManager.get()), - new rpc::AdminNet(web3, *sessionManager.get()), - new rpc::Debug(*web3.ethereum()), - testEth - )); - auto ipcConnector = new IpcServer("geth"); - jsonrpcIpcServer->addConnector(ipcConnector); - ipcConnector->StartListening(); - } if (jsonAdmin.empty()) jsonAdmin = sessionManager->newSession(rpc::SessionPermissions{{rpc::Privilege::Admin}}); @@ -1211,8 +1167,6 @@ int main(int argc, char** argv) sessionManager->addSession(jsonAdmin, rpc::SessionPermissions{{rpc::Privilege::Admin}}); cout << "JSONRPC Admin Session Key: " << jsonAdmin << "\n"; - writeFile(getDataDir("web3") / fs::path("session.key"), jsonAdmin); - writeFile(getDataDir("web3") / fs::path("session.url"), "http://localhost:" + toString(jsonRPCURL)); } for (auto const& p: preferredNodes) @@ -1244,8 +1198,6 @@ int main(int argc, char** argv) while (!exitHandler.shouldExit()) this_thread::sleep_for(chrono::milliseconds(1000)); - if (jsonrpcHttpServer.get()) - jsonrpcHttpServer->StopListening(); if (jsonrpcIpcServer.get()) jsonrpcIpcServer->StopListening(); diff --git a/libweb3jsonrpc/CMakeLists.txt b/libweb3jsonrpc/CMakeLists.txt index 657693732ad..827769e52c8 100644 --- a/libweb3jsonrpc/CMakeLists.txt +++ b/libweb3jsonrpc/CMakeLists.txt @@ -2,7 +2,8 @@ file(GLOB sources "*.cpp" "*.h") add_library(web3jsonrpc ${sources}) -jsonrpcstub_create(web3jsonrpc eth.json +jsonrpcstub_create( + web3jsonrpc eth.json dev::rpc::EthFace ${CMAKE_CURRENT_SOURCE_DIR} EthFace EthClient ${CMAKE_CURRENT_BINARY_DIR} EthClient ) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 7c01197392e..89940d0dc32 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -39,13 +39,6 @@ using namespace eth; using namespace shh; using namespace dev::rpc; -#if ETH_DEBUG -const unsigned dev::SensibleHttpThreads = 1; -#else -const unsigned dev::SensibleHttpThreads = 4; -#endif -const unsigned dev::SensibleHttpPort = 8545; - Eth::Eth(eth::Interface& _eth, eth::AccountHolder& _ethAccounts): m_eth(_eth), m_ethAccounts(_ethAccounts) diff --git a/libweb3jsonrpc/Eth.h b/libweb3jsonrpc/Eth.h index 53a65908bb2..855f40abd87 100644 --- a/libweb3jsonrpc/Eth.h +++ b/libweb3jsonrpc/Eth.h @@ -43,9 +43,6 @@ struct TransactionSkeleton; class Interface; } -extern const unsigned SensibleHttpThreads; -extern const unsigned SensibleHttpPort; - } namespace dev diff --git a/libweb3jsonrpc/SafeHttpServer.cpp b/libweb3jsonrpc/SafeHttpServer.cpp deleted file mode 100644 index faae8d01028..00000000000 --- a/libweb3jsonrpc/SafeHttpServer.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file SafeHttpServer.cpp - * @authors: - * Marek - * @date 2015 - */ - -#include -#include -#include "SafeHttpServer.h" -using namespace std; -using namespace dev; - -/// structure copied from libjson-rpc-cpp httpserver version 0.6.0 -struct mhd_coninfo -{ - struct MHD_PostProcessor *postprocessor; - MHD_Connection* connection; - stringstream request; - jsonrpc::HttpServer* server; - int code; -}; - -bool SafeHttpServer::SendResponse(string const& _response, void* _addInfo) -{ - struct mhd_coninfo* client_connection = static_cast(_addInfo); - struct MHD_Response *result = MHD_create_response_from_buffer( - _response.size(), - static_cast(const_cast(_response.c_str())), - MHD_RESPMEM_MUST_COPY - ); - - MHD_add_response_header(result, "Content-Type", "application/json"); - MHD_add_response_header(result, "Access-Control-Allow-Origin", m_allowedOrigin.c_str()); - - int ret = MHD_queue_response(client_connection->connection, client_connection->code, result); - MHD_destroy_response(result); - return ret == MHD_YES; -} - -bool SafeHttpServer::SendOptionsResponse(void* _addInfo) -{ - struct mhd_coninfo* client_connection = static_cast(_addInfo); - struct MHD_Response *result = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_MUST_COPY); - - MHD_add_response_header(result, "Allow", "POST, OPTIONS"); - MHD_add_response_header(result, "Access-Control-Allow-Origin", m_allowedOrigin.c_str()); - MHD_add_response_header(result, "Access-Control-Allow-Headers", "origin, content-type, accept"); - MHD_add_response_header(result, "DAV", "1"); - - int ret = MHD_queue_response(client_connection->connection, client_connection->code, result); - MHD_destroy_response(result); - return ret == MHD_YES; -} diff --git a/libweb3jsonrpc/SafeHttpServer.h b/libweb3jsonrpc/SafeHttpServer.h deleted file mode 100644 index 18a9d1988db..00000000000 --- a/libweb3jsonrpc/SafeHttpServer.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file SafeHttpServer.h - * @authors: - * Marek - * @date 2015 - */ -#pragma once - -#include -#include - -namespace dev -{ - -class SafeHttpServer: public jsonrpc::HttpServer -{ -public: - /// "using HttpServer" won't work with msvc 2013, so we need to copy'n'paste constructor - SafeHttpServer(int _port, std::string const& _sslcert = std::string(), std::string const& _sslkey = std::string(), int _threads = 50): - HttpServer(_port, _sslcert, _sslkey, _threads) {} - - /// override HttpServer implementation - bool virtual SendResponse(std::string const& _response, void* _addInfo = nullptr) override; - bool virtual SendOptionsResponse(void* _addInfo) override; - - void setAllowedOrigin(std::string const& _origin) { m_allowedOrigin = _origin; } - std::string const& allowedOrigin() const { return m_allowedOrigin; } - -private: - std::string m_allowedOrigin; -}; - -}