diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index fcd0a6d07..332a2e4d8 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -507,4 +507,36 @@ bool Application::loadOldLedger(const std::string& l) return true; } +bool serverOkay(std::string& reason) +{ + if (!theConfig.ELB_SUPPORT) + return true; + + if (!theApp) + { + reason = "Server has not started"; + return false; + } + + if (theApp->getOPs().isNeedNetworkLedger()) + { + reason = "Not synchronized with network yet"; + return false; + } + + if (theApp->getOPs().getOperatingMode() < NetworkOPs::omSYNCING) + { + reason = "Not synchronized with network"; + return false; + } + + if (theApp->getFeeTrack().isLoaded()) + { + reason = "Too much load"; + return false; + } + + return true; +} + // vim:ts=4 diff --git a/src/cpp/ripple/Config.cpp b/src/cpp/ripple/Config.cpp index 1aa05ddb4..a4a0b1a92 100644 --- a/src/cpp/ripple/Config.cpp +++ b/src/cpp/ripple/Config.cpp @@ -16,6 +16,7 @@ #define SECTION_CLUSTER_NODES "cluster_nodes" #define SECTION_DATABASE_PATH "database_path" #define SECTION_DEBUG_LOGFILE "debug_logfile" +#define SECTION_ELB_SUPPORT "elb_support" #define SECTION_FEE_DEFAULT "fee_default" #define SECTION_FEE_NICKNAME_CREATE "fee_nickname_create" #define SECTION_FEE_OFFER "fee_offer" @@ -253,6 +254,7 @@ Config::Config() NODE_DB = "sqlite"; LDB_IMPORT = false; + ELB_SUPPORT = false; RUN_STANDALONE = false; START_UP = NORMAL; } @@ -389,6 +391,9 @@ void Config::load() } } + if (sectionSingleB(secConfig, SECTION_ELB_SUPPORT, strTemp)) + ELB_SUPPORT = boost::lexical_cast(strTemp); + (void) sectionSingleB(secConfig, SECTION_WEBSOCKET_IP, WEBSOCKET_IP); if (sectionSingleB(secConfig, SECTION_WEBSOCKET_PORT, strTemp)) diff --git a/src/cpp/ripple/Config.h b/src/cpp/ripple/Config.h index 8dad49423..422e9ebb4 100644 --- a/src/cpp/ripple/Config.h +++ b/src/cpp/ripple/Config.h @@ -85,6 +85,7 @@ public: boost::filesystem::path VALIDATORS_FILE; // As specifed in rippled.cfg. std::string NODE_DB; // Database to use for nodes bool LDB_IMPORT; // Import into LevelDB + bool ELB_SUPPORT; // Support Amazon ELB std::string VALIDATORS_SITE; // Where to find validators.txt on the Internet. std::string VALIDATORS_URI; // URI of validators.txt. diff --git a/src/cpp/ripple/WSHandler.h b/src/cpp/ripple/WSHandler.h index f469cd202..0b62ec3f2 100644 --- a/src/cpp/ripple/WSHandler.h +++ b/src/cpp/ripple/WSHandler.h @@ -7,6 +7,8 @@ extern void initSSLContext(boost::asio::ssl::context& context, std::string key_file, std::string cert_file, std::string chain_file); +extern bool serverOkay(std::string& reason); + template class WSConnection; @@ -274,11 +276,18 @@ public: } // Respond to http requests. - void http(connection_ptr cpClient) + bool http(connection_ptr cpClient) { + std::string reason; + if (!serverOkay(reason)) + { + cpClient->set_body(std::string("Server cannot accept clients: ") + reason + ""); + return false; + } cpClient->set_body( "" SYSTEM_NAME " Test" "

" SYSTEM_NAME " Test

This page shows http(s) connectivity is working.

"); + return true; } }; diff --git a/src/cpp/websocketpp/src/roles/server.hpp b/src/cpp/websocketpp/src/roles/server.hpp index 868bf834e..1c2ea938f 100644 --- a/src/cpp/websocketpp/src/roles/server.hpp +++ b/src/cpp/websocketpp/src/roles/server.hpp @@ -227,7 +227,7 @@ public: virtual bool on_ping(connection_ptr con,std::string) {return true;} virtual void on_pong(connection_ptr con,std::string) {} virtual void on_pong_timeout(connection_ptr con,std::string) {} - virtual void http(connection_ptr con) {} + virtual bool http(connection_ptr con) { return true; } virtual void on_send_empty(connection_ptr con) {} }; @@ -744,9 +744,10 @@ void server::connection::handle_read_request( } // continue as HTTP? - m_endpoint.get_handler()->http(m_connection.shared_from_this()); - - m_response.set_status(http::status_code::OK); + if (m_endpoint.get_handler()->http(m_connection.shared_from_this())) + m_response.set_status(http::status_code::OK); + else + m_response.set_status(http::status_code::INTERNAL_SERVER_ERROR); } } catch (const http::exception& e) { m_endpoint.m_elog->at(log::elevel::RERROR) << e.what() << log::endl;