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.
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
webSocket.setOnMessageCallback(
[](ix::WebSocketMessageType messageType,
@@ -258,7 +255,7 @@ No manual polling to fetch data is required. Data is sent and received instantly
### 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

View File

@@ -109,7 +109,7 @@ namespace ix
HttpRequestArgsPtr args,
int redirects)
{
// We only have one socket connection, so we cannot
// We only have one socket connection, so we cannot
// make multiple requests concurrently.
std::lock_guard<std::mutex> lock(_mutex);

View File

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

View File

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

View File

@@ -9,7 +9,7 @@ install: brew
# on osx it is good practice to make /usr/local user writable
# sudo chown -R `whoami`/staff /usr/local
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:
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
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
# a builtin C++ server started in the unittest now

View File

@@ -6,13 +6,13 @@
#pragma once
#include <iostream>
#include <ixwebsocket/IXWebSocketServer.h>
#include <mutex>
#include <spdlog/spdlog.h>
#include <sstream>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <mutex>
#include <spdlog/spdlog.h>
#include <ixwebsocket/IXWebSocketServer.h>
namespace ix
{
@@ -28,20 +28,20 @@ namespace ix
struct Logger
{
public:
template<typename T>
Logger& operator<<(T const& obj)
{
std::lock_guard<std::mutex> lock(_mutex);
public:
template <typename T>
Logger& operator<<(T const& obj)
{
std::lock_guard<std::mutex> lock(_mutex);
std::stringstream ss;
ss << obj;
spdlog::info(ss.str());
return *this;
}
std::stringstream ss;
ss << obj;
spdlog::info(ss.str());
return *this;
}
private:
static std::mutex _mutex;
private:
static std::mutex _mutex;
};
void log(const std::string& msg);
@@ -49,4 +49,4 @@ namespace ix
int getFreePort();
bool startWebSocketEchoServer(ix::WebSocketServer& server);
} // namespace ix
}

View File

@@ -143,7 +143,7 @@ namespace ix
// "b"
// ],
// ]
//
//
Json::Value tags;
Json::Value gameTag;
@@ -169,15 +169,18 @@ namespace ix
std::pair<HttpResponsePtr, std::string> SentryClient::send(const Json::Value& msg,
bool verbose)
{
std::string log;
auto args = _httpClient.createRequest();
args->extraHeaders["X-Sentry-Auth"] = SentryClient::computeAuthHeader();
args->connectTimeout = 60;
args->transferTimeout = 5 * 60;
args->followRedirects = true;
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);
@@ -193,7 +196,7 @@ namespace ix
spdlog::info("Upload size: {}", response->uploadSize);
spdlog::info("Download size: {}", response->downloadSize);
spdlog::info("Status: {}", response->statusCode);
std::cerr << "Status: " << response->statusCode << std::endl;
if (response->errorCode != HttpErrorCode::Ok)
{
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

View File

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

View File

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

View File

@@ -80,7 +80,6 @@ int main(int argc, char** argv)
bool strict = false;
bool stress = false;
bool disableAutomaticReconnection = false;
bool disablePerMessageDeflate = false;
int port = 8008;
int redisPort = 6379;
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");
connectApp->add_option("url", url, "Connection url")->required();
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");
chatApp->add_option("url", url, "Connection url")->required();
@@ -243,8 +241,7 @@ int main(int argc, char** argv)
}
else if (app.got_subcommand("connect"))
{
ret = ix::ws_connect_main(url, disableAutomaticReconnection,
disablePerMessageDeflate);
ret = ix::ws_connect_main(url, disableAutomaticReconnection);
}
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_connect_main(const std::string& url,
bool disableAutomaticReconnection,
bool disablePerMessageDeflate);
int ws_connect_main(const std::string& url, bool disableAutomaticReconnection);
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::queue<Json::Value> queue;
SentryClient sentryClient(dsn);
auto sentrySender = [&condition, &progressCondition, &conditionVariableMutex,
&queue, verbose, &errorSending, &sentCount,
&stop, &dsn]
&stop, &sentryClient]
{
SentryClient sentryClient(dsn);
while (true)
{
Json::Value msg;
@@ -70,8 +70,8 @@ namespace ix
if (response->statusCode != 200)
{
spdlog::error("Error sending data to sentry: {}", response->statusCode);
spdlog::error("Body: {}", ret.second);
spdlog::error("Response: {}", response->payload);
spdlog::error("Log: {}", ret.second);
errorSending = true;
}
else
@@ -192,6 +192,6 @@ namespace ix
pool[i].join();
}
return (strict && errorSending) ? 1 : 0;
return 0;
}
}

View File

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