From 5efc046316d658bca622c585c7983b839734076f Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 22 Jan 2015 15:03:13 -0600 Subject: [PATCH 1/3] Adding http monitoring for ICE server --- ice-server/CMakeLists.txt | 16 +++++++++++++++- ice-server/src/IceServer.cpp | 36 +++++++++++++++++++++++++++++++++++- ice-server/src/IceServer.h | 14 ++++++++++---- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/ice-server/CMakeLists.txt b/ice-server/CMakeLists.txt index 24e780f9aa..a7b2a206e4 100644 --- a/ice-server/CMakeLists.txt +++ b/ice-server/CMakeLists.txt @@ -4,6 +4,20 @@ set(TARGET_NAME ice-server) setup_hifi_project(Network) # link the shared hifi libraries -link_hifi_libraries(networking shared) +link_hifi_libraries(embedded-webserver networking shared) + +# find OpenSSL +find_package(OpenSSL REQUIRED) + +if (APPLE AND ${OPENSSL_INCLUDE_DIR} STREQUAL "/usr/include") +# this is a user on OS X using system OpenSSL, which is going to throw warnings since they're deprecating for their common crypto +message(WARNING "The found version of OpenSSL is the OS X system version. This will produce deprecation warnings." +"\nWe recommend you install a newer version (at least 1.0.1h) in a different directory and set OPENSSL_ROOT_DIR in your env so Cmake can find it.") +endif () + +include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") + +# append OpenSSL to our list of libraries to link +target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES}) include_dependency_includes() \ No newline at end of file diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index c06bb0fc88..531dd4ea22 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -20,14 +20,19 @@ const int CLEAR_INACTIVE_PEERS_INTERVAL_MSECS = 1 * 1000; const int PEER_SILENCE_THRESHOLD_MSECS = 5 * 1000; +const quint16 ICE_SERVER_MONITORING_PORT = 40110; + IceServer::IceServer(int argc, char* argv[]) : QCoreApplication(argc, argv), _id(QUuid::createUuid()), _serverSocket(), - _activePeers() + _activePeers(), + _httpManager(ICE_SERVER_MONITORING_PORT, QString("%1/web/").arg(QCoreApplication::applicationDirPath()), this), + _httpsManager(NULL) { // start the ice-server socket qDebug() << "ice-server socket is listening on" << ICE_SERVER_DEFAULT_PORT; + qDebug() << "monitoring http endpoint is listening on " << ICE_SERVER_MONITORING_PORT; _serverSocket.bind(QHostAddress::AnyIPv4, ICE_SERVER_DEFAULT_PORT); // call our process datagrams slot when the UDP socket has packets ready @@ -165,3 +170,32 @@ void IceServer::clearInactivePeers() { } } } + +bool IceServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) { + // + // We need an HTTP handler in order to monitor the health of the ice server + // The correct functioning of the ICE server will first be determined by its HTTP availability, + // and then by the existence of a minimum number of peers in the list, matching the minimum number of + // domains in production by High Fidelity. + // + + int MINIMUM_PEERS = 3; + bool IS_HEALTHY = false; + + IS_HEALTHY = _activePeers.size() >= MINIMUM_PEERS ? true : false; + + if (connection->requestOperation() == QNetworkAccessManager::GetOperation) { + if (url.path() == "/status") { + if (IS_HEALTHY) { + connection->respond(HTTPConnection::StatusCode200, QByteArray::number(_activePeers.size())); + } else { + connection->respond(HTTPConnection::StatusCode404, QByteArray::number(_activePeers.size())); + } + } + } + return true; +} + +bool IceServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler) { + return true; +} diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index e15bda1211..effc8b8154 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -12,17 +12,21 @@ #ifndef hifi_IceServer_h #define hifi_IceServer_h -#include -#include -#include +#include +#include +#include #include +#include typedef QHash NetworkPeerHash; -class IceServer : public QCoreApplication { +class IceServer : public QCoreApplication, public HTTPSRequestHandler { + Q_OBJECT public: IceServer(int argc, char* argv[]); + bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false); + bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler = false); private slots: void processDatagrams(); void clearInactivePeers(); @@ -34,6 +38,8 @@ private: QUdpSocket _serverSocket; NetworkPeerHash _activePeers; QHash > _currentConnections; + HTTPManager _httpManager; + HTTPSManager* _httpsManager; }; #endif // hifi_IceServer_h \ No newline at end of file From 162c2f031bd16d5e1a5c33b2397405d6c36463ae Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 22 Jan 2015 15:33:37 -0600 Subject: [PATCH 2/3] Remove https unneeded crust --- ice-server/CMakeLists.txt | 14 -------------- ice-server/src/IceServer.cpp | 7 +------ ice-server/src/IceServer.h | 4 +--- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/ice-server/CMakeLists.txt b/ice-server/CMakeLists.txt index a7b2a206e4..6a8ca5bd9f 100644 --- a/ice-server/CMakeLists.txt +++ b/ice-server/CMakeLists.txt @@ -6,18 +6,4 @@ setup_hifi_project(Network) # link the shared hifi libraries link_hifi_libraries(embedded-webserver networking shared) -# find OpenSSL -find_package(OpenSSL REQUIRED) - -if (APPLE AND ${OPENSSL_INCLUDE_DIR} STREQUAL "/usr/include") -# this is a user on OS X using system OpenSSL, which is going to throw warnings since they're deprecating for their common crypto -message(WARNING "The found version of OpenSSL is the OS X system version. This will produce deprecation warnings." -"\nWe recommend you install a newer version (at least 1.0.1h) in a different directory and set OPENSSL_ROOT_DIR in your env so Cmake can find it.") -endif () - -include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") - -# append OpenSSL to our list of libraries to link -target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES}) - include_dependency_includes() \ No newline at end of file diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index 531dd4ea22..4648656e87 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -27,8 +27,7 @@ IceServer::IceServer(int argc, char* argv[]) : _id(QUuid::createUuid()), _serverSocket(), _activePeers(), - _httpManager(ICE_SERVER_MONITORING_PORT, QString("%1/web/").arg(QCoreApplication::applicationDirPath()), this), - _httpsManager(NULL) + _httpManager(ICE_SERVER_MONITORING_PORT, QString("%1/web/").arg(QCoreApplication::applicationDirPath()), this) { // start the ice-server socket qDebug() << "ice-server socket is listening on" << ICE_SERVER_DEFAULT_PORT; @@ -195,7 +194,3 @@ bool IceServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, b } return true; } - -bool IceServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler) { - return true; -} diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index effc8b8154..5367786d01 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -21,12 +21,11 @@ typedef QHash NetworkPeerHash; -class IceServer : public QCoreApplication, public HTTPSRequestHandler { +class IceServer : public QCoreApplication, public HTTPRequestHandler { Q_OBJECT public: IceServer(int argc, char* argv[]); bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false); - bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler = false); private slots: void processDatagrams(); void clearInactivePeers(); @@ -39,7 +38,6 @@ private: NetworkPeerHash _activePeers; QHash > _currentConnections; HTTPManager _httpManager; - HTTPSManager* _httpsManager; }; #endif // hifi_IceServer_h \ No newline at end of file From 001d6896464cf0f6c3123f99c8b6308b816f96eb Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 22 Jan 2015 15:37:58 -0600 Subject: [PATCH 3/3] Fixing includes --- ice-server/src/IceServer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index 5367786d01..be6d298e3d 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -17,7 +17,8 @@ #include #include -#include +#include +#include typedef QHash NetworkPeerHash;