From 5ce846f48b48fa795337123d2212f99a4e5bc8f0 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 20 Mar 2020 17:00:18 -0700 Subject: [PATCH] indent files --- ixwebsocket/IXSocketAppleSSL.h | 5 +- ixwebsocket/IXSocketOpenSSL.cpp | 7 +- ixwebsocket/IXWebSocket.cpp | 12 +-- ixwebsocket/IXWebSocketTransport.cpp | 9 +-- test/IXCobraChatTest.cpp | 44 +++++----- test/IXCobraMetricsPublisherTest.cpp | 22 ++--- test/IXCobraToSentryBotTest.cpp | 5 +- test/IXTest.cpp | 6 +- test/IXTest.h | 2 +- ws/ws.cpp | 7 +- ws/ws_cobra_metrics_publish.cpp | 3 +- ws/ws_cobra_subscribe.cpp | 117 +++++++++++++++------------ 12 files changed, 121 insertions(+), 118 deletions(-) diff --git a/ixwebsocket/IXSocketAppleSSL.h b/ixwebsocket/IXSocketAppleSSL.h index 8b80ef8f..988b6d0b 100644 --- a/ixwebsocket/IXSocketAppleSSL.h +++ b/ixwebsocket/IXSocketAppleSSL.h @@ -37,9 +37,8 @@ namespace ix static OSStatus writeToSocket(SSLConnectionRef connection, const void* data, size_t* len); static OSStatus readFromSocket(SSLConnectionRef connection, void* data, size_t* len); - OSStatus tlsHandShake( - std::string& errMsg, - const CancellationRequest& isCancellationRequested); + OSStatus tlsHandShake(std::string& errMsg, + const CancellationRequest& isCancellationRequested); SSLContextRef _sslContext; mutable std::mutex _mutex; // AppleSSL routines are not thread-safe diff --git a/ixwebsocket/IXSocketOpenSSL.cpp b/ixwebsocket/IXSocketOpenSSL.cpp index a6e473cc..9e07cf34 100644 --- a/ixwebsocket/IXSocketOpenSSL.cpp +++ b/ixwebsocket/IXSocketOpenSSL.cpp @@ -224,10 +224,9 @@ namespace ix return true; } - bool SocketOpenSSL::openSSLClientHandshake( - const std::string& host, - std::string& errMsg, - const CancellationRequest& isCancellationRequested) + bool SocketOpenSSL::openSSLClientHandshake(const std::string& host, + std::string& errMsg, + const CancellationRequest& isCancellationRequested) { while (true) { diff --git a/ixwebsocket/IXWebSocket.cpp b/ixwebsocket/IXWebSocket.cpp index e2a674a6..5b7d1040 100644 --- a/ixwebsocket/IXWebSocket.cpp +++ b/ixwebsocket/IXWebSocket.cpp @@ -160,10 +160,8 @@ namespace ix { { std::lock_guard lock(_configMutex); - _ws.configure(_perMessageDeflateOptions, - _socketTLSOptions, - _enablePong, - _pingIntervalSecs); + _ws.configure( + _perMessageDeflateOptions, _socketTLSOptions, _enablePong, _pingIntervalSecs); } WebSocketHttpHeaders headers(_extraHeaders); @@ -216,10 +214,8 @@ namespace ix { { std::lock_guard lock(_configMutex); - _ws.configure(_perMessageDeflateOptions, - _socketTLSOptions, - _enablePong, - _pingIntervalSecs); + _ws.configure( + _perMessageDeflateOptions, _socketTLSOptions, _enablePong, _pingIntervalSecs); } WebSocketInitResult status = _ws.connectToSocket(socket, timeoutSecs); diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 22e12fa5..728f2f98 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -251,16 +251,15 @@ namespace ix // No timeout if state is not OPEN, otherwise computed // pingIntervalOrTimeoutGCD (equals to -1 if no ping and no ping timeout are set) - int lastingTimeoutDelayInMs = - (_readyState != ReadyState::OPEN) ? 0 : _pingIntervalSecs; + int lastingTimeoutDelayInMs = (_readyState != ReadyState::OPEN) ? 0 : _pingIntervalSecs; if (_pingIntervalSecs > 0) { // compute lasting delay to wait for next ping / timeout, if at least one set auto now = std::chrono::steady_clock::now(); - lastingTimeoutDelayInMs = - (int) std::chrono::duration_cast(now - _lastSendPingTimePoint) - .count(); + lastingTimeoutDelayInMs = (int) std::chrono::duration_cast( + now - _lastSendPingTimePoint) + .count(); } #ifdef _WIN32 diff --git a/test/IXCobraChatTest.cpp b/test/IXCobraChatTest.cpp index df728263..7ef4c70c 100644 --- a/test/IXCobraChatTest.cpp +++ b/test/IXCobraChatTest.cpp @@ -126,32 +126,36 @@ namespace std::string filter; std::string position("$"); - _conn.subscribe( - channel, filter, position, [this](const Json::Value& msg, const std::string& /*position*/) { - spdlog::info("receive {}", msg.toStyledString()); + _conn.subscribe(channel, + filter, + position, + [this](const Json::Value& msg, const std::string& /*position*/) { + spdlog::info("receive {}", msg.toStyledString()); - if (!msg.isObject()) return; - if (!msg.isMember("user")) return; - if (!msg.isMember("text")) return; - if (!msg.isMember("session")) return; + if (!msg.isObject()) return; + if (!msg.isMember("user")) return; + if (!msg.isMember("text")) return; + if (!msg.isMember("session")) return; - std::string msg_user = msg["user"].asString(); - std::string msg_text = msg["text"].asString(); - std::string msg_session = msg["session"].asString(); + std::string msg_user = msg["user"].asString(); + std::string msg_text = msg["text"].asString(); + std::string msg_session = msg["session"].asString(); - // We are not interested in messages - // from a different session. - if (msg_session != _session) return; + // We are not interested in messages + // from a different session. + if (msg_session != _session) return; - // We are not interested in our own messages - if (msg_user == _user) return; + // We are not interested in our own messages + if (msg_user == _user) return; - _receivedQueue.push(msg); + _receivedQueue.push(msg); - std::stringstream ss; - ss << std::endl << msg_user << " > " << msg_text << std::endl << _user << " > "; - log(ss.str()); - }); + std::stringstream ss; + ss << std::endl + << msg_user << " > " << msg_text << std::endl + << _user << " > "; + log(ss.str()); + }); } void CobraChat::sendMessage(const std::string& text) diff --git a/test/IXCobraMetricsPublisherTest.cpp b/test/IXCobraMetricsPublisherTest.cpp index dd5dc1ed..4c78d6c7 100644 --- a/test/IXCobraMetricsPublisherTest.cpp +++ b/test/IXCobraMetricsPublisherTest.cpp @@ -77,18 +77,20 @@ namespace std::string filter; std::string position("$"); - conn.subscribe( - channel, filter, position, [](const Json::Value& msg, const std::string& /*position*/) { - log(msg.toStyledString()); + conn.subscribe(channel, + filter, + position, + [](const Json::Value& msg, const std::string& /*position*/) { + log(msg.toStyledString()); - std::string id = msg["id"].asString(); - { - std::lock_guard guard(gProtectIds); - gIds.insert(id); - } + std::string id = msg["id"].asString(); + { + std::lock_guard guard(gProtectIds); + gIds.insert(id); + } - gMessageCount++; - }); + gMessageCount++; + }); } else if (eventType == ix::CobraConnection_EventType_Subscribed) { diff --git a/test/IXCobraToSentryBotTest.cpp b/test/IXCobraToSentryBotTest.cpp index 131d36f3..dde00195 100644 --- a/test/IXCobraToSentryBotTest.cpp +++ b/test/IXCobraToSentryBotTest.cpp @@ -150,10 +150,7 @@ TEST_CASE("Cobra_to_sentry_bot", "[cobra_bots]") // -> https://github.com/openssl/openssl/issues/7967 // https://xxxxx:yyyyyy@sentry.io/1234567 std::stringstream oss; - oss << getHttpScheme() - << "xxxxxxx:yyyyyyy@localhost:" - << sentryPort - << "/1234567"; + oss << getHttpScheme() << "xxxxxxx:yyyyyyy@localhost:" << sentryPort << "/1234567"; std::string dsn = oss.str(); SocketTLSOptions tlsOptionsClient = makeClientTLSOptions(); diff --git a/test/IXTest.cpp b/test/IXTest.cpp index c5327905..26cfb033 100644 --- a/test/IXTest.cpp +++ b/test/IXTest.cpp @@ -148,7 +148,7 @@ namespace ix auto vec = load(path); return std::string(vec.begin(), vec.end()); } - + SocketTLSOptions makeClientTLSOptions() { SocketTLSOptions tlsOptionsClient; @@ -237,9 +237,7 @@ namespace ix std::string makeCobraEndpoint(int port, bool preferTLS) { std::stringstream ss; - ss << getWsScheme(preferTLS) - << "localhost:" - << port; + ss << getWsScheme(preferTLS) << "localhost:" << port; std::string endpoint = ss.str(); return endpoint; diff --git a/test/IXTest.h b/test/IXTest.h index 45af4264..4a49d38b 100644 --- a/test/IXTest.h +++ b/test/IXTest.h @@ -9,8 +9,8 @@ #include "IXGetFreePort.h" #include #include -#include #include +#include #include #include #include diff --git a/ws/ws.cpp b/ws/ws.cpp index d1825a11..452ac45a 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -171,9 +171,7 @@ int main(int argc, char** argv) connectApp->add_option("--max_wait", maxWaitBetweenReconnectionRetries, "Max Wait Time between reconnection retries"); - connectApp->add_option("--ping_interval", - pingIntervalSecs, - "Interval between sending pings"); + connectApp->add_option("--ping_interval", pingIntervalSecs, "Interval between sending pings"); connectApp->add_option("--subprotocol", subprotocol, "Subprotocol"); addTLSOptions(connectApp); @@ -475,7 +473,8 @@ int main(int argc, char** argv) } else if (app.got_subcommand("cobra_metrics_to_redis")) { - ret = ix::ws_cobra_metrics_to_redis(cobraConfig, channel, filter, position, hostname, redisPort); + ret = ix::ws_cobra_metrics_to_redis( + cobraConfig, channel, filter, position, hostname, redisPort); } else if (app.got_subcommand("snake")) { diff --git a/ws/ws_cobra_metrics_publish.cpp b/ws/ws_cobra_metrics_publish.cpp index 3c035e00..92fb5ea1 100644 --- a/ws/ws_cobra_metrics_publish.cpp +++ b/ws/ws_cobra_metrics_publish.cpp @@ -30,8 +30,7 @@ namespace ix CobraMetricsPublisher cobraMetricsPublisher; cobraMetricsPublisher.enable(true); - cobraMetricsPublisher.configure(config, - channel); + cobraMetricsPublisher.configure(config, channel); while (!cobraMetricsPublisher.isAuthenticated()) ; diff --git a/ws/ws_cobra_subscribe.cpp b/ws/ws_cobra_subscribe.cpp index 76ff95cc..3ac13341 100644 --- a/ws/ws_cobra_subscribe.cpp +++ b/ws/ws_cobra_subscribe.cpp @@ -70,63 +70,74 @@ namespace ix std::string subscriptionPosition(position); - conn.setEventCallback( - [&conn, &channel, &jsonWriter, &filter, &subscriptionPosition, &msgCount, &msgPerSeconds, &quiet, &fluentd]( - ix::CobraConnectionEventType eventType, - const std::string& errMsg, - const ix::WebSocketHttpHeaders& headers, - const std::string& subscriptionId, - CobraConnection::MsgId msgId) { - if (eventType == ix::CobraConnection_EventType_Open) - { - spdlog::info("Subscriber connected"); + conn.setEventCallback([&conn, + &channel, + &jsonWriter, + &filter, + &subscriptionPosition, + &msgCount, + &msgPerSeconds, + &quiet, + &fluentd](ix::CobraConnectionEventType eventType, + const std::string& errMsg, + const ix::WebSocketHttpHeaders& headers, + const std::string& subscriptionId, + CobraConnection::MsgId msgId) { + if (eventType == ix::CobraConnection_EventType_Open) + { + spdlog::info("Subscriber connected"); - for (auto it : headers) - { - spdlog::info("{}: {}", it.first, it.second); - } - } - else if (eventType == ix::CobraConnection_EventType_Authenticated) + for (auto it : headers) { - spdlog::info("Subscriber authenticated"); - spdlog::info("Subscribing to {} at position {}", channel, subscriptionPosition); - conn.subscribe(channel, - filter, - subscriptionPosition, - [&jsonWriter, &quiet, &msgPerSeconds, &msgCount, &fluentd, &subscriptionPosition]( - const Json::Value& msg, const std::string& position) { - if (!quiet) - { - writeToStdout(fluentd, jsonWriter, msg, position); - } + spdlog::info("{}: {}", it.first, it.second); + } + } + else if (eventType == ix::CobraConnection_EventType_Authenticated) + { + spdlog::info("Subscriber authenticated"); + spdlog::info("Subscribing to {} at position {}", channel, subscriptionPosition); + conn.subscribe( + channel, + filter, + subscriptionPosition, + [&jsonWriter, + &quiet, + &msgPerSeconds, + &msgCount, + &fluentd, + &subscriptionPosition](const Json::Value& msg, const std::string& position) { + if (!quiet) + { + writeToStdout(fluentd, jsonWriter, msg, position); + } - msgPerSeconds++; - msgCount++; + msgPerSeconds++; + msgCount++; - subscriptionPosition = position; - }); - } - else if (eventType == ix::CobraConnection_EventType_Subscribed) - { - spdlog::info("Subscriber: subscribed to channel {}", subscriptionId); - } - else if (eventType == ix::CobraConnection_EventType_UnSubscribed) - { - spdlog::info("Subscriber: unsubscribed from channel {}", subscriptionId); - } - else if (eventType == ix::CobraConnection_EventType_Error) - { - spdlog::error("Subscriber: error {}", errMsg); - } - else if (eventType == ix::CobraConnection_EventType_Published) - { - spdlog::error("Published message hacked: {}", msgId); - } - else if (eventType == ix::CobraConnection_EventType_Pong) - { - spdlog::info("Received websocket pong"); - } - }); + subscriptionPosition = position; + }); + } + else if (eventType == ix::CobraConnection_EventType_Subscribed) + { + spdlog::info("Subscriber: subscribed to channel {}", subscriptionId); + } + else if (eventType == ix::CobraConnection_EventType_UnSubscribed) + { + spdlog::info("Subscriber: unsubscribed from channel {}", subscriptionId); + } + else if (eventType == ix::CobraConnection_EventType_Error) + { + spdlog::error("Subscriber: error {}", errMsg); + } + else if (eventType == ix::CobraConnection_EventType_Published) + { + spdlog::error("Published message hacked: {}", msgId); + } + else if (eventType == ix::CobraConnection_EventType_Pong) + { + spdlog::info("Received websocket pong"); + } + }); while (true) {