From 97cc543e537fbe979307591ce5e5c7adecce83e8 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 22 Sep 2020 09:30:19 -0700 Subject: [PATCH] (cobra connection) retrieve cobra server connection id from the cobra handshake message and display it in ws clients, metrics publisher and bots --- docs/CHANGELOG.md | 4 ++++ ixbots/ixbots/IXCobraBot.cpp | 6 +++++- ixcobra/ixcobra/IXCobraConnection.cpp | 17 +++++++++++++++-- ixcobra/ixcobra/IXCobraConnection.h | 4 +++- ixcobra/ixcobra/IXCobraEvent.h | 5 ++++- ixcobra/ixcobra/IXCobraEventType.h | 3 ++- .../ixcobra/IXCobraMetricsThreadedPublisher.cpp | 4 ++++ ixwebsocket/IXWebSocketVersion.h | 2 +- 8 files changed, 38 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 33b0d974..41618efc 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [10.4.4] - 2020-09-22 + +(cobra connection) retrieve cobra server connection id from the cobra handshake message and display it in ws clients, metrics publisher and bots + ## [10.4.3] - 2020-09-22 (cobra 2 cobra) specify as an HTTP header which channel we will republish to diff --git a/ixbots/ixbots/IXCobraBot.cpp b/ixbots/ixbots/IXCobraBot.cpp index e5b10235..f75dd4b9 100644 --- a/ixbots/ixbots/IXCobraBot.cpp +++ b/ixbots/ixbots/IXCobraBot.cpp @@ -170,7 +170,11 @@ namespace ix } else if (event->type == ix::CobraEventType::Closed) { - CoreLogger::info("Subscriber closed: {}" + event->errMsg); + CoreLogger::info("Subscriber closed: " + event->errMsg); + } + else if (event->type == ix::CobraEventType::Handshake) + { + CoreLogger::info("Subscriber: Cobra handshake connection id: " + event->connectionId); } else if (event->type == ix::CobraEventType::Authenticated) { diff --git a/ixcobra/ixcobra/IXCobraConnection.cpp b/ixcobra/ixcobra/IXCobraConnection.cpp index 02de9c2b..a76c88f2 100644 --- a/ixcobra/ixcobra/IXCobraConnection.cpp +++ b/ixcobra/ixcobra/IXCobraConnection.cpp @@ -91,13 +91,14 @@ namespace ix const std::string& errorMsg, const WebSocketHttpHeaders& headers, const std::string& subscriptionId, - CobraConnection::MsgId msgId) + CobraConnection::MsgId msgId, + const std::string& connectionId) { std::lock_guard lock(_eventCallbackMutex); if (_eventCallback) { _eventCallback( - std::make_unique(eventType, errorMsg, headers, subscriptionId, msgId)); + std::make_unique(eventType, errorMsg, headers, subscriptionId, msgId, connectionId)); } } @@ -352,6 +353,18 @@ namespace ix if (!nonce.isString()) return false; + if (!data.isMember("connection_id")) return false; + Json::Value connectionId = data["connection_id"]; + + if (!connectionId.isString()) return false; + + invokeEventCallback(ix::CobraEventType::Handshake, + std::string(), + WebSocketHttpHeaders(), + std::string(), + 0, + connectionId.asString()); + return sendAuthMessage(nonce.asString()); } diff --git a/ixcobra/ixcobra/IXCobraConnection.h b/ixcobra/ixcobra/IXCobraConnection.h index ea4a7863..74a7fca6 100644 --- a/ixcobra/ixcobra/IXCobraConnection.h +++ b/ixcobra/ixcobra/IXCobraConnection.h @@ -158,7 +158,9 @@ namespace ix const std::string& errorMsg = std::string(), const WebSocketHttpHeaders& headers = WebSocketHttpHeaders(), const std::string& subscriptionId = std::string(), - uint64_t msgId = std::numeric_limits::max()); + uint64_t msgId = std::numeric_limits::max(), + const std::string& connectionId = std::string()); + void invokeErrorCallback(const std::string& errorMsg, const std::string& serializedPdu); /// Tells whether the internal queue is empty or not diff --git a/ixcobra/ixcobra/IXCobraEvent.h b/ixcobra/ixcobra/IXCobraEvent.h index 9227d743..5d00cf81 100644 --- a/ixcobra/ixcobra/IXCobraEvent.h +++ b/ixcobra/ixcobra/IXCobraEvent.h @@ -21,17 +21,20 @@ namespace ix const ix::WebSocketHttpHeaders& headers; const std::string& subscriptionId; uint64_t msgId; // CobraConnection::MsgId + const std::string& connectionId; CobraEvent(ix::CobraEventType t, const std::string& e, const ix::WebSocketHttpHeaders& h, const std::string& s, - uint64_t m) + uint64_t m, + const std::string& c) : type(t) , errMsg(e) , headers(h) , subscriptionId(s) , msgId(m) + , connectionId(c) { ; } diff --git a/ixcobra/ixcobra/IXCobraEventType.h b/ixcobra/ixcobra/IXCobraEventType.h index 1ccfbeb0..e3038c5d 100644 --- a/ixcobra/ixcobra/IXCobraEventType.h +++ b/ixcobra/ixcobra/IXCobraEventType.h @@ -20,6 +20,7 @@ namespace ix Pong = 7, HandshakeError = 8, AuthenticationError = 9, - SubscriptionError = 10 + SubscriptionError = 10, + Handshake = 11 }; } diff --git a/ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.cpp b/ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.cpp index 4d6db872..ebd77a21 100644 --- a/ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.cpp +++ b/ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.cpp @@ -35,6 +35,10 @@ namespace ix ss << it.first << ": " << it.second << std::endl; } } + else if (event->type == ix::CobraEventType::Handshake) + { + ss << "Cobra handshake connection id: " << event->connectionId; + } else if (event->type == ix::CobraEventType::Authenticated) { ss << "Authenticated"; diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 525e2209..b4366f4e 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "10.4.3" +#define IX_WEBSOCKET_VERSION "10.4.4"