Compare commits

..

7 Commits

Author SHA1 Message Date
Benjamin Sergeant
a788b31080 ws_cobra_to_sentry improvements 2019-06-05 18:45:31 -07:00
Benjamin Sergeant
03a2f1443b HttpClient class is not thread safe, we should protect it as we only have one socket 2019-06-05 18:43:35 -07:00
Benjamin Sergeant
6e0463c981 cobra_to_sentry / add tags 2019-06-05 17:34:33 -07:00
Benjamin Sergeant
e9399a0734 add more logging 2019-06-05 16:38:51 -07:00
Benjamin Sergeant
7b2ddb5e7c fix ws + add doc 2019-06-05 16:04:51 -07:00
Benjamin Sergeant
c7cb743a69 fix command line tools 2019-06-05 15:52:31 -07:00
Benjamin Sergeant
3257ad1363 unittest working / uses shared_ptr for a bunch of things 🗿 2019-06-05 15:26:31 -07:00
15 changed files with 49 additions and 76 deletions

View File

@@ -1 +1 @@
3.1.1 2.2.1

View File

@@ -1 +1 @@
docker/Dockerfile.alpine docker/Dockerfile.ubuntu_artful

View File

@@ -28,9 +28,6 @@ webSocket.setUrl(url);
// to make sure that load balancers do not kill an idle connection. // to make sure that load balancers do not kill an idle connection.
webSocket.setHeartBeatPeriod(45); webSocket.setHeartBeatPeriod(45);
// Per message deflate connection is enabled by default. You can tweak its parameters or disable it
webSocket.disablePerMessageDeflate();
// Setup a callback to be fired when a message or an event (open, close, error) is received // Setup a callback to be fired when a message or an event (open, close, error) is received
webSocket.setOnMessageCallback( webSocket.setOnMessageCallback(
[](ix::WebSocketMessageType messageType, [](ix::WebSocketMessageType messageType,
@@ -258,7 +255,7 @@ No manual polling to fetch data is required. Data is sent and received instantly
### Automatic reconnection ### Automatic reconnection
If the remote end (server) breaks the connection, the code will try to perpetually reconnect, by using an exponential backoff strategy, capped at one retry every 10 seconds. This behavior can be disabled. If the remote end (server) breaks the connection, the code will try to perpetually reconnect, by using an exponential backoff strategy, capped at one retry every 10 seconds.
### Large messages ### Large messages

View File

@@ -135,13 +135,6 @@ namespace ix
_enablePong = false; _enablePong = false;
} }
void WebSocket::disablePerMessageDeflate()
{
std::lock_guard<std::mutex> lock(_configMutex);
WebSocketPerMessageDeflateOptions perMessageDeflateOptions(false);
_perMessageDeflateOptions = perMessageDeflateOptions;
}
void WebSocket::start() void WebSocket::start()
{ {
if (_thread.joinable()) return; // we've already been started if (_thread.joinable()) return; // we've already been started

View File

@@ -95,7 +95,6 @@ namespace ix
void setPingTimeout(int pingTimeoutSecs); void setPingTimeout(int pingTimeoutSecs);
void enablePong(); void enablePong();
void disablePong(); void disablePong();
void disablePerMessageDeflate();
// Run asynchronously, by calling start and stop. // Run asynchronously, by calling start and stop.
void start(); void start();

View File

@@ -9,7 +9,7 @@ install: brew
# on osx it is good practice to make /usr/local user writable # on osx it is good practice to make /usr/local user writable
# sudo chown -R `whoami`/staff /usr/local # sudo chown -R `whoami`/staff /usr/local
brew: brew:
mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 .. ; make -j install) mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j install)
ws: ws:
mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j) mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j)
@@ -44,7 +44,7 @@ trail:
sh third_party/remote_trailing_whitespaces.sh sh third_party/remote_trailing_whitespaces.sh
format: format:
find test ixwebsocket ws -name '*.cpp' -o -name '*.h' -exec clang-format -i {} \; find ixwebsocket ws -name '*.cpp' -o -name '*.h' -exec clang-format -i {} \;
# That target is used to start a node server, but isn't required as we have # That target is used to start a node server, but isn't required as we have
# a builtin C++ server started in the unittest now # a builtin C++ server started in the unittest now

View File

@@ -6,13 +6,13 @@
#pragma once #pragma once
#include <iostream>
#include <ixwebsocket/IXWebSocketServer.h>
#include <mutex>
#include <spdlog/spdlog.h>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <sstream>
#include <iostream>
#include <mutex>
#include <spdlog/spdlog.h>
#include <ixwebsocket/IXWebSocketServer.h>
namespace ix namespace ix
{ {
@@ -49,4 +49,4 @@ namespace ix
int getFreePort(); int getFreePort();
bool startWebSocketEchoServer(ix::WebSocketServer& server); bool startWebSocketEchoServer(ix::WebSocketServer& server);
} // namespace ix }

View File

@@ -169,15 +169,18 @@ namespace ix
std::pair<HttpResponsePtr, std::string> SentryClient::send(const Json::Value& msg, std::pair<HttpResponsePtr, std::string> SentryClient::send(const Json::Value& msg,
bool verbose) bool verbose)
{ {
std::string log;
auto args = _httpClient.createRequest(); auto args = _httpClient.createRequest();
args->extraHeaders["X-Sentry-Auth"] = SentryClient::computeAuthHeader(); args->extraHeaders["X-Sentry-Auth"] = SentryClient::computeAuthHeader();
args->connectTimeout = 60; args->connectTimeout = 60;
args->transferTimeout = 5 * 60; args->transferTimeout = 5 * 60;
args->followRedirects = true; args->followRedirects = true;
args->verbose = verbose; args->verbose = verbose;
args->logger = [](const std::string& msg) args->logger = [&log](const std::string& msg)
{ {
spdlog::info("request logger: {}", msg); log += msg;
std::cout << msg;
}; };
std::string body = computePayload(msg); std::string body = computePayload(msg);
@@ -193,7 +196,7 @@ namespace ix
spdlog::info("Upload size: {}", response->uploadSize); spdlog::info("Upload size: {}", response->uploadSize);
spdlog::info("Download size: {}", response->downloadSize); spdlog::info("Download size: {}", response->downloadSize);
spdlog::info("Status: {}", response->statusCode); std::cerr << "Status: " << response->statusCode << std::endl;
if (response->errorCode != HttpErrorCode::Ok) if (response->errorCode != HttpErrorCode::Ok)
{ {
spdlog::info("error message: {}", response->errorMsg); spdlog::info("error message: {}", response->errorMsg);
@@ -205,6 +208,6 @@ namespace ix
} }
} }
return std::make_pair(response, body); return std::make_pair(response, log);
} }
} // namespace ix } // namespace ix

View File

@@ -6,10 +6,10 @@
#pragma once #pragma once
#include <algorithm>
#include <ixwebsocket/IXHttpClient.h> #include <ixwebsocket/IXHttpClient.h>
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
#include <regex> #include <regex>
#include <algorithm>
namespace ix namespace ix
{ {

View File

@@ -10,6 +10,7 @@
#if defined(IXWEBSOCKET_USE_MBED_TLS) #if defined(IXWEBSOCKET_USE_MBED_TLS)
# include <mbedtls/md.h> # include <mbedtls/md.h>
#elif defined(__APPLE__) #elif defined(__APPLE__)
# include <ixwebsocket/IXSocketMbedTLS.h>
# include <CommonCrypto/CommonHMAC.h> # include <CommonCrypto/CommonHMAC.h>
#else #else
# include <openssl/hmac.h> # include <openssl/hmac.h>

View File

@@ -80,7 +80,6 @@ int main(int argc, char** argv)
bool strict = false; bool strict = false;
bool stress = false; bool stress = false;
bool disableAutomaticReconnection = false; bool disableAutomaticReconnection = false;
bool disablePerMessageDeflate = false;
int port = 8008; int port = 8008;
int redisPort = 6379; int redisPort = 6379;
int statsdPort = 8125; int statsdPort = 8125;
@@ -111,7 +110,6 @@ int main(int argc, char** argv)
CLI::App* connectApp = app.add_subcommand("connect", "Connect to a remote server"); CLI::App* connectApp = app.add_subcommand("connect", "Connect to a remote server");
connectApp->add_option("url", url, "Connection url")->required(); connectApp->add_option("url", url, "Connection url")->required();
connectApp->add_flag("-d", disableAutomaticReconnection, "Disable Automatic Reconnection"); connectApp->add_flag("-d", disableAutomaticReconnection, "Disable Automatic Reconnection");
connectApp->add_flag("-x", disablePerMessageDeflate, "Disable per message deflate");
CLI::App* chatApp = app.add_subcommand("chat", "Group chat"); CLI::App* chatApp = app.add_subcommand("chat", "Group chat");
chatApp->add_option("url", url, "Connection url")->required(); chatApp->add_option("url", url, "Connection url")->required();
@@ -243,8 +241,7 @@ int main(int argc, char** argv)
} }
else if (app.got_subcommand("connect")) else if (app.got_subcommand("connect"))
{ {
ret = ix::ws_connect_main(url, disableAutomaticReconnection, ret = ix::ws_connect_main(url, disableAutomaticReconnection);
disablePerMessageDeflate);
} }
else if (app.got_subcommand("chat")) else if (app.got_subcommand("chat"))
{ {

View File

@@ -30,9 +30,7 @@ namespace ix
int ws_chat_main(const std::string& url, const std::string& user); int ws_chat_main(const std::string& url, const std::string& user);
int ws_connect_main(const std::string& url, int ws_connect_main(const std::string& url, bool disableAutomaticReconnection);
bool disableAutomaticReconnection,
bool disablePerMessageDeflate);
int ws_receive_main(const std::string& url, bool enablePerMessageDeflate, int delayMs); int ws_receive_main(const std::string& url, bool enablePerMessageDeflate, int delayMs);

View File

@@ -47,12 +47,12 @@ namespace ix
std::condition_variable progressCondition; std::condition_variable progressCondition;
std::queue<Json::Value> queue; std::queue<Json::Value> queue;
auto sentrySender = [&condition, &progressCondition, &conditionVariableMutex,
&queue, verbose, &errorSending, &sentCount,
&stop, &dsn]
{
SentryClient sentryClient(dsn); SentryClient sentryClient(dsn);
auto sentrySender = [&condition, &progressCondition, &conditionVariableMutex,
&queue, verbose, &errorSending, &sentCount,
&stop, &sentryClient]
{
while (true) while (true)
{ {
Json::Value msg; Json::Value msg;
@@ -70,8 +70,8 @@ namespace ix
if (response->statusCode != 200) if (response->statusCode != 200)
{ {
spdlog::error("Error sending data to sentry: {}", response->statusCode); spdlog::error("Error sending data to sentry: {}", response->statusCode);
spdlog::error("Body: {}", ret.second);
spdlog::error("Response: {}", response->payload); spdlog::error("Response: {}", response->payload);
spdlog::error("Log: {}", ret.second);
errorSending = true; errorSending = true;
} }
else else
@@ -192,6 +192,6 @@ namespace ix
pool[i].join(); pool[i].join();
} }
return (strict && errorSending) ? 1 : 0; return 0;
} }
} }

View File

@@ -15,8 +15,7 @@ namespace ix
{ {
public: public:
WebSocketConnect(const std::string& _url, WebSocketConnect(const std::string& _url,
bool disableAutomaticReconnection, bool disableAutomaticReconnection);
bool disablePerMessageDeflate);
void subscribe(const std::string& channel); void subscribe(const std::string& channel);
void start(); void start();
@@ -27,16 +26,13 @@ namespace ix
private: private:
std::string _url; std::string _url;
ix::WebSocket _webSocket; ix::WebSocket _webSocket;
bool _disablePerMessageDeflate;
void log(const std::string& msg); void log(const std::string& msg);
}; };
WebSocketConnect::WebSocketConnect(const std::string& url, WebSocketConnect::WebSocketConnect(const std::string& url,
bool disableAutomaticReconnection, bool disableAutomaticReconnection) :
bool disablePerMessageDeflate) : _url(url)
_url(url),
_disablePerMessageDeflate(disablePerMessageDeflate)
{ {
if (disableAutomaticReconnection) if (disableAutomaticReconnection)
{ {
@@ -58,16 +54,9 @@ namespace ix
{ {
_webSocket.setUrl(_url); _webSocket.setUrl(_url);
if (_disablePerMessageDeflate)
{
_webSocket.disablePerMessageDeflate();
}
else
{
ix::WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions( ix::WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions(
true, false, false, 15, 15); true, false, false, 15, 15);
_webSocket.setPerMessageDeflateOptions(webSocketPerMessageDeflateOptions); _webSocket.setPerMessageDeflateOptions(webSocketPerMessageDeflateOptions);
}
std::stringstream ss; std::stringstream ss;
log(std::string("Connecting to url: ") + _url); log(std::string("Connecting to url: ") + _url);
@@ -141,14 +130,10 @@ namespace ix
_webSocket.send(text); _webSocket.send(text);
} }
int ws_connect_main(const std::string& url, int ws_connect_main(const std::string& url, bool disableAutomaticReconnection)
bool disableAutomaticReconnection,
bool disablePerMessageDeflate)
{ {
std::cout << "Type Ctrl-D to exit prompt..." << std::endl; std::cout << "Type Ctrl-D to exit prompt..." << std::endl;
WebSocketConnect webSocketChat(url, WebSocketConnect webSocketChat(url, disableAutomaticReconnection);
disableAutomaticReconnection,
disablePerMessageDeflate);
webSocketChat.start(); webSocketChat.start();
while (true) while (true)