Skip to content

Commit

Permalink
rpc: Drop HTTP server
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Dec 4, 2017
1 parent 62c4c98 commit 8f2ef62
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 189 deletions.
2 changes: 1 addition & 1 deletion cmake/ProjectJsonRpcCpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-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
Expand Down
72 changes: 12 additions & 60 deletions eth/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

#include <libweb3jsonrpc/AccountHolder.h>
#include <libweb3jsonrpc/Eth.h>
#include <libweb3jsonrpc/SafeHttpServer.h>
#include <libweb3jsonrpc/ModularServer.h>
#include <libweb3jsonrpc/IpcServer.h>
#include <libweb3jsonrpc/Net.h>
Expand Down Expand Up @@ -86,15 +85,10 @@ void help()
<< " --private <name> Use a private chain.\n"
<< " --test Testing mode: Disable PoW and provide test rpc interface.\n"
<< " --config <file> Configure specialised blockchain using given JSON information.\n"
<< " --oppose-dao-fork Ignore DAO hard fork (default is to participate).\n\n"
<< " -o,--mode <full/peer> 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 <n> Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ").\n"
<< " --rpccorsdomain <domain> Domain on which to send Access-Control-Allow-Origin header.\n"
<< " --admin <password> 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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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<ModularServer<>> jsonrpcHttpServer;
unique_ptr<ModularServer<>> jsonrpcIpcServer;
unique_ptr<rpc::SessionManager> sessionManager;
unique_ptr<SimpleAccountHolder> accountHolder;
Expand Down Expand Up @@ -1150,7 +1132,7 @@ int main(int argc, char** argv)

ExitHandler exitHandler;

if (jsonRPCURL > -1 || ipc)
if (ipc)
{
using FullServer = ModularServer<
rpc::EthFace,
Expand All @@ -1166,53 +1148,25 @@ 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}});
else
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)
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion libweb3jsonrpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
7 changes: 0 additions & 7 deletions libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions libweb3jsonrpc/Eth.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ struct TransactionSkeleton;
class Interface;
}

extern const unsigned SensibleHttpThreads;
extern const unsigned SensibleHttpPort;

}

namespace dev
Expand Down
69 changes: 0 additions & 69 deletions libweb3jsonrpc/SafeHttpServer.cpp

This file was deleted.

48 changes: 0 additions & 48 deletions libweb3jsonrpc/SafeHttpServer.h

This file was deleted.

0 comments on commit 8f2ef62

Please sign in to comment.