Browse Source

makes websocket optional

miguelfreitas
erqan 7 years ago
parent
commit
8d060063e3
  1. 2
      bootstrap.sh
  2. 24
      configure.ac
  3. 16
      src/bitcoinrpc.cpp
  4. 2
      src/bitcoinrpc.h
  5. 8
      src/init.cpp
  6. 10
      src/twister.cpp
  7. 1
      websocketpp

2
bootstrap.sh

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
git submodule update --init
./autotool.sh ./autotool.sh
./configure $@ ./configure $@

24
configure.ac

@ -420,6 +420,14 @@ AC_ARG_WITH(
[[ARG_WITH_LIBICONV=no]] [[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 # 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_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
AS_ECHO "Checking for extra build files:" 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([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([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_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 # Other useful stuff
@ -852,6 +875,7 @@ Features:
dht support: ${ARG_ENABLE_DHT:-yes} dht support: ${ARG_ENABLE_DHT:-yes}
pool allocators: ${ARG_ENABLE_POOL_ALLOC:-yes} pool allocators: ${ARG_ENABLE_POOL_ALLOC:-yes}
rss feed: ${ARG_ENABLE_RSS:-yes} rss feed: ${ARG_ENABLE_RSS:-yes}
websocket: ${ARG_ENABLE_WS:-yes}
Extra builds: Extra builds:
examples: ${ARG_ENABLE_EXAMPLES:-no} examples: ${ARG_ENABLE_EXAMPLES:-no}

16
src/bitcoinrpc.cpp

@ -35,6 +35,7 @@
#include <fstream> #include <fstream>
#include <streambuf> #include <streambuf>
#ifdef ENABLE_WS
#include <websocketpp/config/asio_no_tls_client.hpp> #include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp> #include <websocketpp/client.hpp>
#include <websocketpp/config/asio_no_tls.hpp> #include <websocketpp/config/asio_no_tls.hpp>
@ -57,6 +58,7 @@ typedef websocketpp::lib::shared_ptr<websocketpp::lib::asio::ssl::context> conte
wsserver wss; wsserver wss;
swsserver swss; swsserver swss;
vector<websocketpp::connection_hdl> wsconnections; vector<websocketpp::connection_hdl> wsconnections;
#endif // ENABLE_WS
using namespace std; using namespace std;
using namespace boost; using namespace boost;
@ -313,7 +315,6 @@ static const CRPCCommand vRPCCommands[] =
{ "uidtousername", &uidtousername, false, true, true }, { "uidtousername", &uidtousername, false, true, true },
{ "newshorturl", &newshorturl, false, true, false }, { "newshorturl", &newshorturl, false, true, false },
{ "decodeshorturl", &decodeshorturl, false, true, true }, { "decodeshorturl", &decodeshorturl, false, true, true },
// { "openwebsocket", &openwebsocket, false, true, true },
}; };
CRPCTable::CRPCTable() CRPCTable::CRPCTable()
@ -783,6 +784,7 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol>
} }
} }
#ifdef ENABLE_WS
template <class WST> template <class WST>
void on_message_server(WST *s, websocketpp::connection_hdl hdl, message_ptr msg); void on_message_server(WST *s, websocketpp::connection_hdl hdl, message_ptr msg);
template <class WST> template <class WST>
@ -890,10 +892,12 @@ void StartWSServer(WST &ws)
std::cout << "other exception" << std::endl; std::cout << "other exception" << std::endl;
} }
} }
#endif // ENABLE_WS
void StartRPCThreads() void StartRPCThreads()
{ {
const bool fUseSSL = GetBoolArg("-rpcssl", false); const bool fUseSSL = GetBoolArg("-rpcssl", false);
#ifdef ENABLE_WS
if (GetBoolArg("-websocket", false)) if (GetBoolArg("-websocket", false))
{ {
if (fUseSSL) if (fUseSSL)
@ -901,8 +905,7 @@ void StartRPCThreads()
else else
boost::thread wst(boost::bind(&StartWSServer<wsserver>, boost::ref<wsserver>(wss))); boost::thread wst(boost::bind(&StartWSServer<wsserver>, boost::ref<wsserver>(wss)));
} }
if (!GetBoolArg("-jsonrpc", true)) #endif // ENABLE_WS
return;
strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"];
if (((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 <class WST> template <class WST>
void on_message_client(WST* c, websocketpp::connection_hdl hdl, message_ptr msg) 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")); reply.push_back(Pair("result", "OK"));
return reply; return reply;
} }
#endif // ENABLE_WS
Object CallRPC(const string& strMethod, const Array& params) Object CallRPC(const string& strMethod, const Array& params)
{ {
bool fUseSSL = GetBoolArg("-rpcssl", false); bool fUseSSL = GetBoolArg("-rpcssl", false);
#ifdef ENABLE_WS
if (strMethod == "openwebsocket") if (strMethod == "openwebsocket")
{ {
if (fUseSSL) if (fUseSSL)
@ -1461,6 +1467,7 @@ Object CallRPC(const string& strMethod, const Array& params)
else else
return StartWSClient<wsclient>(fUseSSL); return StartWSClient<wsclient>(fUseSSL);
} }
#endif // ENABLE_WS
if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "")
throw runtime_error(strprintf( throw runtime_error(strprintf(
@ -1728,6 +1735,7 @@ int CommandLineRPC(int argc, char *argv[])
return nRet; return nRet;
} }
#ifdef ENABLE_WS
template <class WST> template <class WST>
void on_message_server(WST* s, websocketpp::connection_hdl hdl, message_ptr msg) 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 #ifdef TEST
int main(int argc, char *argv[]) int main(int argc, char *argv[])

2
src/bitcoinrpc.h

@ -74,7 +74,9 @@ void StartRPCThreads();
void StopRPCThreads(); void StopRPCThreads();
int CommandLineRPC(int argc, char *argv[]); int CommandLineRPC(int argc, char *argv[]);
#ifdef ENABLE_WS
void WriteToWS(json_spirit::Value const& val); void WriteToWS(json_spirit::Value const& val);
#endif // ENABLE_WS
/** Convert parameter values for RPC call from strings to command-specific JSON objects. */ /** Convert parameter values for RPC call from strings to command-specific JSON objects. */
json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams); json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams);

8
src/init.cpp

@ -231,7 +231,6 @@ std::string HelpMessage()
#ifdef WIN32 #ifdef WIN32
strUsage += " -printtodebugger " + _("Send trace/debug info to debugger") + "\n"; strUsage += " -printtodebugger " + _("Send trace/debug info to debugger") + "\n";
#endif #endif
strUsage += " -jsonrpc " + _("Enable JSON-RPC service (default: 1)") + "\n";
strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n"; strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n";
strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n"; strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n";
strUsage += " -rpcport=<port> " + _("Listen for JSON-RPC connections on <port> (default: 28332 or testnet: 18332)") + "\n"; strUsage += " -rpcport=<port> " + _("Listen for JSON-RPC connections on <port> (default: 28332 or testnet: 18332)") + "\n";
@ -239,9 +238,10 @@ std::string HelpMessage()
if (!fHaveGUI) if (!fHaveGUI)
strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n"; strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n";
strUsage += " -rpcthreads=<n> " + _("Set the number of threads to service RPC calls (default: 10)") + "\n"; strUsage += " -rpcthreads=<n> " + _("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 += " -websocket " + _("Enables WEB Socket connections (default: 0)") + "\n";
strUsage += " -wsport=<port> " + _("Listen for WEB Socket on <port> (default: rpcport+1000)") + "\n"; strUsage += " -wsport=<port> " + _("Listen for WEB Socket on <port> (default: rpcport+1000)") + "\n";
#endif // ENABLE_WS
strUsage += " -public_server_mode " + _("Limit JSON-RPC execution to public/safe commands only.") + "\n"; strUsage += " -public_server_mode " + _("Limit JSON-RPC execution to public/safe commands only.") + "\n";
strUsage += " -blocknotify=<cmd> " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; strUsage += " -blocknotify=<cmd> " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n";
strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n";
@ -263,7 +263,11 @@ std::string HelpMessage()
strUsage += " -blockprioritysize=<n> " + _("Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)") + "\n"; strUsage += " -blockprioritysize=<n> " + _("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"; 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"; 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=<file.cert> " + _("Server certificate file (default: server.cert)") + "\n"; strUsage += " -rpcsslcertificatechainfile=<file.cert> " + _("Server certificate file (default: server.cert)") + "\n";
strUsage += " -rpcsslprivatekeyfile=<file.pem> " + _("Server private key (default: server.pem)") + "\n"; strUsage += " -rpcsslprivatekeyfile=<file.pem> " + _("Server private key (default: server.pem)") + "\n";
strUsage += " -rpcsslciphers=<ciphers> " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n"; strUsage += " -rpcsslciphers=<ciphers> " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n";

10
src/twister.cpp

@ -1440,7 +1440,7 @@ bool processReceivedDM(lazy_entry const* post)
} else { } else {
storeNewDM(item.second.username, fromMe ? to : from, stoDM); storeNewDM(item.second.username, fromMe ? to : from, stoDM);
} }
#ifdef ENABLE_WS
if (GetBoolArg("-websocket", false) && !fromMe) if (GetBoolArg("-websocket", false) && !fromMe)
{ {
Object dm; Object dm;
@ -1456,7 +1456,7 @@ bool processReceivedDM(lazy_entry const* post)
WriteToWS(dm); WriteToWS(dm);
} }
#endif // ENABLE_WS
break; break;
} }
} }
@ -1500,7 +1500,7 @@ void processReceivedPost(lazy_entry const &v, std::string &username, int64 time,
entry vEntry; entry vEntry;
vEntry = v; vEntry = v;
m_users[mentionUser].m_mentionsPosts.push_back(vEntry); m_users[mentionUser].m_mentionsPosts.push_back(vEntry);
#ifdef ENABLE_WS
if (GetBoolArg("-websocket", false)) if (GetBoolArg("-websocket", false))
{ {
Object obj; Object obj;
@ -1513,11 +1513,12 @@ void processReceivedPost(lazy_entry const &v, std::string &username, int64 time,
WriteToWS(obj); WriteToWS(obj);
} }
#endif // ENABLE_WS
} }
} }
} }
} }
#ifdef ENABLE_WS
if (GetBoolArg("-websocket", false)) if (GetBoolArg("-websocket", false))
{ {
entry vEntry; 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) bool acceptSignedPost(char const *data, int data_size, std::string username, int seq, std::string &errmsg, boost::uint32_t *flags)

1
websocketpp

@ -0,0 +1 @@
Subproject commit 378437aecdcb1dfe62096ffd5d944bf1f640ccc3
Loading…
Cancel
Save