From 8d060063e3ffb86939bfbddc0930cd11a39b01b9 Mon Sep 17 00:00:00 2001 From: erqan Date: Tue, 24 Apr 2018 16:15:45 +0300 Subject: [PATCH] makes websocket optional --- bootstrap.sh | 2 -- configure.ac | 24 ++++++++++++++++++++++++ src/bitcoinrpc.cpp | 16 ++++++++++++---- src/bitcoinrpc.h | 2 ++ src/init.cpp | 8 ++++++-- src/twister.cpp | 10 ++++++---- websocketpp | 1 + 7 files changed, 51 insertions(+), 12 deletions(-) create mode 160000 websocketpp diff --git a/bootstrap.sh b/bootstrap.sh index 6b2c9cda..3920cec8 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,7 +1,5 @@ #!/bin/sh -git submodule update --init - ./autotool.sh ./configure $@ diff --git a/configure.ac b/configure.ac index 5aca804d..454efa88 100644 --- a/configure.ac +++ b/configure.ac @@ -420,6 +420,14 @@ AC_ARG_WITH( [[ARG_WITH_LIBICONV=no]] ) +AC_ARG_ENABLE( + [websocket], + [AS_HELP_STRING( + [--enable-websocket], + [enable websocket [default=no]])], + [[ARG_ENABLE_WS=$enableval]], + [[ARG_ENABLE_WS=no]] +) ############################################################################### # Checking configure options ############################################################################### @@ -631,6 +639,20 @@ AS_CASE(["$ARG_ENABLE_RSS"], AC_MSG_ERROR([Unknown option "$ARG_ENABLE_RSS". Use either "yes" or "no".])] ) +AC_MSG_CHECKING([whether websocket should be enabled]) +AS_CASE(["$ARG_ENABLE_WS"], + ["yes"|"on"], [ + AC_MSG_RESULT([yes]) + AC_DEFINE([ENABLE_WS],[1],[Enable WebSocket]) + CXXFLAGS="$CXXFLAGS -DENABLE_WS " + ], + ["no"|"off"], [ + AC_MSG_RESULT([no]) + ], + [AC_MSG_RESULT([$ARG_ENABLE_WS]) + AC_MSG_ERROR([Unknown option "$ARG_ENABLE_WS". Use either "yes" or "no".])] +) + AS_ECHO AS_ECHO "Checking for extra build files:" @@ -749,6 +771,7 @@ AM_CONDITIONAL([WITH_SHIPPED_GEOIP], [test "x$ARG_WITH_LIBGEOIP" = "xno" ]) AM_CONDITIONAL([WITH_OPENSSL], [test "x$ARG_ENABLE_ENCRYPTION" = "xyes" -o "x$ARG_ENABLE_ENCRYPTION" = "xon" ]) AM_CONDITIONAL([USE_SSE2], [test "x$ARG_ENABLE_SSE2" = "xyes" -o "x$ARG_ENABLE_SSE2" = "xon" ]) AM_CONDITIONAL([ENABLE_RSS], [test "x$ARG_ENABLE_RSS" = "xyes" -o "x$ARG_ENABLE_RSS" = "xon" ]) +AM_CONDITIONAL([ENABLE_WS], [test "x$ARG_ENABLE_WS" = "xyes" -o "x$ARG_ENABLE_WS" = "xon" ]) ############################################################################### # Other useful stuff @@ -852,6 +875,7 @@ Features: dht support: ${ARG_ENABLE_DHT:-yes} pool allocators: ${ARG_ENABLE_POOL_ALLOC:-yes} rss feed: ${ARG_ENABLE_RSS:-yes} + websocket: ${ARG_ENABLE_WS:-yes} Extra builds: examples: ${ARG_ENABLE_EXAMPLES:-no} diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 31d3f971..01b168cc 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -35,6 +35,7 @@ #include #include +#ifdef ENABLE_WS #include #include #include @@ -57,6 +58,7 @@ typedef websocketpp::lib::shared_ptr conte wsserver wss; swsserver swss; vector wsconnections; +#endif // ENABLE_WS using namespace std; using namespace boost; @@ -313,7 +315,6 @@ static const CRPCCommand vRPCCommands[] = { "uidtousername", &uidtousername, false, true, true }, { "newshorturl", &newshorturl, false, true, false }, { "decodeshorturl", &decodeshorturl, false, true, true }, -// { "openwebsocket", &openwebsocket, false, true, true }, }; CRPCTable::CRPCTable() @@ -783,6 +784,7 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor } } +#ifdef ENABLE_WS template void on_message_server(WST *s, websocketpp::connection_hdl hdl, message_ptr msg); template @@ -890,10 +892,12 @@ void StartWSServer(WST &ws) std::cout << "other exception" << std::endl; } } +#endif // ENABLE_WS void StartRPCThreads() { const bool fUseSSL = GetBoolArg("-rpcssl", false); +#ifdef ENABLE_WS if (GetBoolArg("-websocket", false)) { if (fUseSSL) @@ -901,8 +905,7 @@ void StartRPCThreads() else boost::thread wst(boost::bind(&StartWSServer, boost::ref(wss))); } - if (!GetBoolArg("-jsonrpc", true)) - return; +#endif // ENABLE_WS strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; if (((mapArgs["-rpcpassword"] == "") || @@ -1316,6 +1319,7 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s } } +#ifdef ENABLE_WS template void on_message_client(WST* c, websocketpp::connection_hdl hdl, message_ptr msg) { @@ -1450,10 +1454,12 @@ Object StartWSClient(bool fUseSSL) reply.push_back(Pair("result", "OK")); return reply; } +#endif // ENABLE_WS Object CallRPC(const string& strMethod, const Array& params) { bool fUseSSL = GetBoolArg("-rpcssl", false); +#ifdef ENABLE_WS if (strMethod == "openwebsocket") { if (fUseSSL) @@ -1461,6 +1467,7 @@ Object CallRPC(const string& strMethod, const Array& params) else return StartWSClient(fUseSSL); } +#endif // ENABLE_WS if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") throw runtime_error(strprintf( @@ -1728,6 +1735,7 @@ int CommandLineRPC(int argc, char *argv[]) return nRet; } +#ifdef ENABLE_WS template void on_message_server(WST* s, websocketpp::connection_hdl hdl, message_ptr msg) { @@ -1817,7 +1825,7 @@ void WriteToWS(Value const& val) } } } - +#endif // ENABLE_WS #ifdef TEST int main(int argc, char *argv[]) diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 20fecc3e..19158901 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -74,7 +74,9 @@ void StartRPCThreads(); void StopRPCThreads(); int CommandLineRPC(int argc, char *argv[]); +#ifdef ENABLE_WS void WriteToWS(json_spirit::Value const& val); +#endif // ENABLE_WS /** Convert parameter values for RPC call from strings to command-specific JSON objects. */ json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector &strParams); diff --git a/src/init.cpp b/src/init.cpp index ac03a4dc..5c188d68 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -231,7 +231,6 @@ std::string HelpMessage() #ifdef WIN32 strUsage += " -printtodebugger " + _("Send trace/debug info to debugger") + "\n"; #endif - strUsage += " -jsonrpc " + _("Enable JSON-RPC service (default: 1)") + "\n"; strUsage += " -rpcuser= " + _("Username for JSON-RPC connections") + "\n"; strUsage += " -rpcpassword= " + _("Password for JSON-RPC connections") + "\n"; strUsage += " -rpcport= " + _("Listen for JSON-RPC connections on (default: 28332 or testnet: 18332)") + "\n"; @@ -239,9 +238,10 @@ std::string HelpMessage() if (!fHaveGUI) strUsage += " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n"; strUsage += " -rpcthreads= " + _("Set the number of threads to service RPC calls (default: 10)") + "\n"; +#ifdef ENABLE_WS strUsage += " -websocket " + _("Enables WEB Socket connections (default: 0)") + "\n"; strUsage += " -wsport= " + _("Listen for WEB Socket on (default: rpcport+1000)") + "\n"; - +#endif // ENABLE_WS strUsage += " -public_server_mode " + _("Limit JSON-RPC execution to public/safe commands only.") + "\n"; strUsage += " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; strUsage += " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; @@ -263,7 +263,11 @@ std::string HelpMessage() strUsage += " -blockprioritysize= " + _("Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)") + "\n"; strUsage += "\n"; _("SSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n"; +#ifdef ENABLE_WS strUsage += " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC and/or WEB Socket connections") + "\n"; +#else + strUsage += " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n"; +#endif // ENABLE_WS strUsage += " -rpcsslcertificatechainfile= " + _("Server certificate file (default: server.cert)") + "\n"; strUsage += " -rpcsslprivatekeyfile= " + _("Server private key (default: server.pem)") + "\n"; strUsage += " -rpcsslciphers= " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n"; diff --git a/src/twister.cpp b/src/twister.cpp index 6a39e597..63a698cf 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1440,7 +1440,7 @@ bool processReceivedDM(lazy_entry const* post) } else { storeNewDM(item.second.username, fromMe ? to : from, stoDM); } - +#ifdef ENABLE_WS if (GetBoolArg("-websocket", false) && !fromMe) { Object dm; @@ -1456,7 +1456,7 @@ bool processReceivedDM(lazy_entry const* post) WriteToWS(dm); } - +#endif // ENABLE_WS break; } } @@ -1500,7 +1500,7 @@ void processReceivedPost(lazy_entry const &v, std::string &username, int64 time, entry vEntry; vEntry = v; m_users[mentionUser].m_mentionsPosts.push_back(vEntry); - +#ifdef ENABLE_WS if (GetBoolArg("-websocket", false)) { Object obj; @@ -1513,11 +1513,12 @@ void processReceivedPost(lazy_entry const &v, std::string &username, int64 time, WriteToWS(obj); } +#endif // ENABLE_WS } } } } - +#ifdef ENABLE_WS if (GetBoolArg("-websocket", false)) { entry vEntry; @@ -1540,6 +1541,7 @@ void processReceivedPost(lazy_entry const &v, std::string &username, int64 time, } } } +#endif // ENABLE_WS } bool acceptSignedPost(char const *data, int data_size, std::string username, int seq, std::string &errmsg, boost::uint32_t *flags) diff --git a/websocketpp b/websocketpp new file mode 160000 index 00000000..378437ae --- /dev/null +++ b/websocketpp @@ -0,0 +1 @@ +Subproject commit 378437aecdcb1dfe62096ffd5d944bf1f640ccc3