From 73b9c0b89bcb73f818e41dbde7d27cc4dce5d73c Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 28 Aug 2020 14:55:40 -0700 Subject: [PATCH] (socket servers) merge the ConnectionInfo class with the ConnectionState one, which simplify all the server apis --- CMakeLists.txt | 1 - docs/CHANGELOG.md | 4 ++++ docs/usage.md | 15 ++++++------- ixredis/ixredis/IXRedisServer.cpp | 5 ++--- ixredis/ixredis/IXRedisServer.h | 3 +-- ixsnake/ixsnake/IXSnakeServer.cpp | 3 +-- ixwebsocket/IXConnectionInfo.h | 25 --------------------- ixwebsocket/IXConnectionState.cpp | 20 +++++++++++++++++ ixwebsocket/IXConnectionState.h | 9 ++++++++ ixwebsocket/IXHttpServer.cpp | 23 +++++++++----------- ixwebsocket/IXHttpServer.h | 7 ++---- ixwebsocket/IXSocketServer.cpp | 30 ++++++++++++++------------ ixwebsocket/IXSocketServer.h | 4 +--- ixwebsocket/IXWebSocketProxyServer.cpp | 5 ++--- ixwebsocket/IXWebSocketServer.cpp | 10 ++++----- ixwebsocket/IXWebSocketServer.h | 13 ++++------- ixwebsocket/IXWebSocketVersion.h | 2 +- test/IXCobraToSentryBotTest.cpp | 7 +++--- test/IXTest.cpp | 5 ++--- test/IXWebSocketBroadcastTest.cpp | 4 +--- test/IXWebSocketChatTest.cpp | 3 +-- test/IXWebSocketCloseTest.cpp | 3 +-- test/IXWebSocketServerTest.cpp | 4 +--- test/IXWebSocketSubProtocolTest.cpp | 3 +-- ws/ws.cpp | 12 ++++------- 25 files changed, 97 insertions(+), 123 deletions(-) delete mode 100644 ixwebsocket/IXConnectionInfo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4760ca77..7cb10d8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,6 @@ set( IXWEBSOCKET_SOURCES set( IXWEBSOCKET_HEADERS ixwebsocket/IXBench.h ixwebsocket/IXCancellationRequest.h - ixwebsocket/IXConnectionInfo.h ixwebsocket/IXConnectionState.h ixwebsocket/IXDNSLookup.h ixwebsocket/IXExponentialBackoff.h diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4eae4f65..2e9fd964 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.3.1] - 2020-08-28 + +(socket servers) merge the ConnectionInfo class with the ConnectionState one, which simplify all the server apis + ## [10.3.0] - 2020-08-26 (ws) set the main thread name, to help with debugging in XCode, gdb, lldb etc... diff --git a/docs/usage.md b/docs/usage.md index 35da7f24..46cc1581 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -280,10 +280,9 @@ ix::WebSocketServer server(port); server.setOnConnectionCallback( [&server](std::weak_ptr webSocket, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) + std::shared_ptr connectionState) { - std::cout << "Remote ip: " << connectionInfo->remoteIp << std::endl; + std::cout << "Remote ip: " << connectionState->remoteIp << std::endl; auto ws = webSocket.lock(); if (ws) @@ -359,13 +358,12 @@ The webSocket reference is guaranteed to be always valid ; by design the callbac ix::WebSocketServer server(port); server.setOnClientMessageCallback(std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const WebSocketMessagePtr& msg) { - // The ConnectionInfo object contains information about the connection, + // The ConnectionState object contains information about the connection, // at this point only the client ip address and the port. - std::cout << "Remote ip: " << connectionInfo.remoteIp << std::endl; + std::cout << "Remote ip: " << connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { @@ -519,12 +517,11 @@ If you want to handle how requests are processed, implement the setOnConnectionC ```cpp setOnConnectionCallback( [this](HttpRequestPtr request, - std::shared_ptr /*connectionState*/, - std::unique_ptr connectionInfo) -> HttpResponsePtr + std::shared_ptr connectionState) -> HttpResponsePtr { // Build a string for the response std::stringstream ss; - ss << connectionInfo->remoteIp + ss << connectionState->getRemoteIp(); << " " << request->method << " " diff --git a/ixredis/ixredis/IXRedisServer.cpp b/ixredis/ixredis/IXRedisServer.cpp index 57154cb0..1267ca2a 100644 --- a/ixredis/ixredis/IXRedisServer.cpp +++ b/ixredis/ixredis/IXRedisServer.cpp @@ -45,10 +45,9 @@ namespace ix } void RedisServer::handleConnection(std::unique_ptr socket, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) + std::shared_ptr connectionState) { - logInfo("New connection from remote ip " + connectionInfo->remoteIp); + logInfo("New connection from remote ip " + connectionState->getRemoteIp()); _connectedClientsCount++; diff --git a/ixredis/ixredis/IXRedisServer.h b/ixredis/ixredis/IXRedisServer.h index c981b3a3..a94c4da0 100644 --- a/ixredis/ixredis/IXRedisServer.h +++ b/ixredis/ixredis/IXRedisServer.h @@ -44,8 +44,7 @@ namespace ix // Methods virtual void handleConnection(std::unique_ptr, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) final; + std::shared_ptr connectionState) final; virtual size_t getConnectedClientsCount() final; bool startsWith(const std::string& str, const std::string& start); diff --git a/ixsnake/ixsnake/IXSnakeServer.cpp b/ixsnake/ixsnake/IXSnakeServer.cpp index bcc38053..e1c28c02 100644 --- a/ixsnake/ixsnake/IXSnakeServer.cpp +++ b/ixsnake/ixsnake/IXSnakeServer.cpp @@ -61,11 +61,10 @@ namespace snake _server.setOnClientMessageCallback( [this](std::shared_ptr connectionState, - ix::ConnectionInfo& connectionInfo, ix::WebSocket& webSocket, const ix::WebSocketMessagePtr& msg) { auto state = std::dynamic_pointer_cast(connectionState); - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); std::stringstream ss; ss << "[" << state->getId() << "] "; diff --git a/ixwebsocket/IXConnectionInfo.h b/ixwebsocket/IXConnectionInfo.h deleted file mode 100644 index 1ef54961..00000000 --- a/ixwebsocket/IXConnectionInfo.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * IXConnectionInfo.h - * Author: Benjamin Sergeant - * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. - */ - -#pragma once - -#include - -namespace ix -{ - struct ConnectionInfo - { - std::string remoteIp; - int remotePort; - - ConnectionInfo(const std::string& r = std::string(), int p = 0) - : remoteIp(r) - , remotePort(p) - { - ; - } - }; -} // namespace ix diff --git a/ixwebsocket/IXConnectionState.cpp b/ixwebsocket/IXConnectionState.cpp index 8c273738..8a559f19 100644 --- a/ixwebsocket/IXConnectionState.cpp +++ b/ixwebsocket/IXConnectionState.cpp @@ -50,4 +50,24 @@ namespace ix _onSetTerminatedCallback(); } } + + const std::string& ConnectionState::getRemoteIp() + { + return _remoteIp; + } + + int ConnectionState::getRemotePort() + { + return _remotePort; + } + + void ConnectionState::setRemoteIp(const std::string& remoteIp) + { + _remoteIp = remoteIp; + } + + void ConnectionState::setRemotePort(int remotePort) + { + _remotePort = remotePort; + } } // namespace ix diff --git a/ixwebsocket/IXConnectionState.h b/ixwebsocket/IXConnectionState.h index e45c8d40..b7530d0b 100644 --- a/ixwebsocket/IXConnectionState.h +++ b/ixwebsocket/IXConnectionState.h @@ -28,11 +28,17 @@ namespace ix void setTerminated(); bool isTerminated() const; + const std::string& getRemoteIp(); + int getRemotePort(); + static std::shared_ptr createConnectionState(); private: void setOnSetTerminatedCallback(const OnSetTerminatedCallback& callback); + void setRemoteIp(const std::string& remoteIp); + void setRemotePort(int remotePort); + protected: std::atomic _terminated; std::string _id; @@ -40,6 +46,9 @@ namespace ix static std::atomic _globalId; + std::string _remoteIp; + int _remotePort; + friend class SocketServer; }; } // namespace ix diff --git a/ixwebsocket/IXHttpServer.cpp b/ixwebsocket/IXHttpServer.cpp index 08fc3a4c..d1ccfe4f 100644 --- a/ixwebsocket/IXHttpServer.cpp +++ b/ixwebsocket/IXHttpServer.cpp @@ -120,8 +120,7 @@ namespace ix } void HttpServer::handleConnection(std::unique_ptr socket, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) + std::shared_ptr connectionState) { _connectedClientsCount++; @@ -130,8 +129,7 @@ namespace ix if (std::get<0>(ret)) { - auto response = - _onConnectionCallback(std::get<2>(ret), connectionState, std::move(connectionInfo)); + auto response = _onConnectionCallback(std::get<2>(ret), connectionState); if (!Http::sendResponse(response, socket)) { logError("Cannot send response"); @@ -151,8 +149,7 @@ namespace ix { setOnConnectionCallback( [this](HttpRequestPtr request, - std::shared_ptr /*connectionState*/, - std::unique_ptr connectionInfo) -> HttpResponsePtr { + std::shared_ptr connectionState) -> HttpResponsePtr { std::string uri(request->uri); if (uri.empty() || uri == "/") { @@ -184,8 +181,8 @@ namespace ix // Log request std::stringstream ss; - ss << connectionInfo->remoteIp << ":" << connectionInfo->remotePort << " " - << request->method << " " << request->headers["User-Agent"] << " " + ss << connectionState->getRemoteIp() << ":" << connectionState->getRemotePort() + << " " << request->method << " " << request->headers["User-Agent"] << " " << request->uri << " " << content.size(); logInfo(ss.str()); @@ -209,16 +206,16 @@ namespace ix // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections // setOnConnectionCallback( - [this, redirectUrl](HttpRequestPtr request, - std::shared_ptr /*connectionState*/, - std::unique_ptr connectionInfo) -> HttpResponsePtr { + [this, + redirectUrl](HttpRequestPtr request, + std::shared_ptr connectionState) -> HttpResponsePtr { WebSocketHttpHeaders headers; headers["Server"] = userAgent(); // Log request std::stringstream ss; - ss << connectionInfo->remoteIp << ":" << connectionInfo->remotePort << " " - << request->method << " " << request->headers["User-Agent"] << " " + ss << connectionState->getRemoteIp() << ":" << connectionState->getRemotePort() + << " " << request->method << " " << request->headers["User-Agent"] << " " << request->uri; logInfo(ss.str()); diff --git a/ixwebsocket/IXHttpServer.h b/ixwebsocket/IXHttpServer.h index 2735e835..96b22d3f 100644 --- a/ixwebsocket/IXHttpServer.h +++ b/ixwebsocket/IXHttpServer.h @@ -23,9 +23,7 @@ namespace ix { public: using OnConnectionCallback = - std::function, - std::unique_ptr connectionInfo)>; + std::function)>; HttpServer(int port = SocketServer::kDefaultPort, const std::string& host = SocketServer::kDefaultHost, @@ -46,8 +44,7 @@ namespace ix // Methods virtual void handleConnection(std::unique_ptr, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) final; + std::shared_ptr connectionState) final; virtual size_t getConnectedClientsCount() final; void setDefaultConnectionCallback(); diff --git a/ixwebsocket/IXSocketServer.cpp b/ixwebsocket/IXSocketServer.cpp index b7affb8b..33bbfd71 100644 --- a/ixwebsocket/IXSocketServer.cpp +++ b/ixwebsocket/IXSocketServer.cpp @@ -332,12 +332,13 @@ namespace ix } // Retrieve connection info, the ip address of the remote peer/client) - std::unique_ptr connectionInfo; + std::string remoteIp; + int remotePort; if (_addressFamily == AF_INET) { - char remoteIp[INET_ADDRSTRLEN]; - if (inet_ntop(AF_INET, &client.sin_addr, remoteIp, INET_ADDRSTRLEN) == nullptr) + char remoteIp4[INET_ADDRSTRLEN]; + if (inet_ntop(AF_INET, &client.sin_addr, remoteIp4, INET_ADDRSTRLEN) == nullptr) { int err = Socket::getErrno(); std::stringstream ss; @@ -350,12 +351,13 @@ namespace ix continue; } - connectionInfo = std::make_unique(remoteIp, client.sin_port); + remotePort = client.sin_port; + remoteIp = remoteIp4; } else // AF_INET6 { - char remoteIp[INET6_ADDRSTRLEN]; - if (inet_ntop(AF_INET6, &client.sin_addr, remoteIp, INET6_ADDRSTRLEN) == nullptr) + char remoteIp6[INET6_ADDRSTRLEN]; + if (inet_ntop(AF_INET6, &client.sin_addr, remoteIp6, INET6_ADDRSTRLEN) == nullptr) { int err = Socket::getErrno(); std::stringstream ss; @@ -368,7 +370,8 @@ namespace ix continue; } - connectionInfo = std::make_unique(remoteIp, client.sin_port); + remotePort = client.sin_port; + remoteIp = remoteIp6; } std::shared_ptr connectionState; @@ -377,6 +380,8 @@ namespace ix connectionState = _connectionStateFactory(); } connectionState->setOnSetTerminatedCallback([this] { onSetTerminatedCallback(); }); + connectionState->setRemoteIp(remoteIp); + connectionState->setRemotePort(remotePort); if (_stop) return; @@ -404,13 +409,10 @@ namespace ix // Launch the handleConnection work asynchronously in its own thread. std::lock_guard lock(_connectionsThreadsMutex); - _connectionsThreads.push_back( - std::make_pair(connectionState, - std::thread(&SocketServer::handleConnection, - this, - std::move(socket), - connectionState, - std::move(connectionInfo)))); + _connectionsThreads.push_back(std::make_pair( + connectionState, + std::thread( + &SocketServer::handleConnection, this, std::move(socket), connectionState))); } } diff --git a/ixwebsocket/IXSocketServer.h b/ixwebsocket/IXSocketServer.h index caf00ee5..a4573a96 100644 --- a/ixwebsocket/IXSocketServer.h +++ b/ixwebsocket/IXSocketServer.h @@ -6,7 +6,6 @@ #pragma once -#include "IXConnectionInfo.h" #include "IXConnectionState.h" #include "IXSelectInterrupt.h" #include "IXSocketTLSOptions.h" @@ -105,8 +104,7 @@ namespace ix ConnectionStateFactory _connectionStateFactory; virtual void handleConnection(std::unique_ptr, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) = 0; + std::shared_ptr connectionState) = 0; virtual size_t getConnectedClientsCount() = 0; // Returns true if all connection threads are joined diff --git a/ixwebsocket/IXWebSocketProxyServer.cpp b/ixwebsocket/IXWebSocketProxyServer.cpp index db385aa1..4b78c63b 100644 --- a/ixwebsocket/IXWebSocketProxyServer.cpp +++ b/ixwebsocket/IXWebSocketProxyServer.cpp @@ -56,10 +56,9 @@ namespace ix server.setOnConnectionCallback( [remoteUrl, remoteUrlsMapping](std::weak_ptr webSocket, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) { + std::shared_ptr connectionState) { auto state = std::dynamic_pointer_cast(connectionState); - auto remoteIp = connectionInfo->remoteIp; + auto remoteIp = connectionState->getRemoteIp(); // Server connection state->webSocket().setOnMessageCallback( diff --git a/ixwebsocket/IXWebSocketServer.cpp b/ixwebsocket/IXWebSocketServer.cpp index 16db25bc..5c16c3b4 100644 --- a/ixwebsocket/IXWebSocketServer.cpp +++ b/ixwebsocket/IXWebSocketServer.cpp @@ -77,15 +77,14 @@ namespace ix } void WebSocketServer::handleConnection(std::unique_ptr socket, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) + std::shared_ptr connectionState) { setThreadName("WebSocketServer::" + connectionState->getId()); auto webSocket = std::make_shared(); if (_onConnectionCallback) { - _onConnectionCallback(webSocket, connectionState, std::move(connectionInfo)); + _onConnectionCallback(webSocket, connectionState); if (!webSocket->isOnMessageCallbackRegistered()) { @@ -99,9 +98,8 @@ namespace ix else if (_onClientMessageCallback) { webSocket->setOnMessageCallback( - [this, &ws = *webSocket.get(), connectionState, &ci = *connectionInfo.get()]( - const WebSocketMessagePtr& msg) { - _onClientMessageCallback(connectionState, ci, ws, msg); + [this, &ws = *webSocket.get(), connectionState](const WebSocketMessagePtr& msg) { + _onClientMessageCallback(connectionState, ws, msg); }); } else diff --git a/ixwebsocket/IXWebSocketServer.h b/ixwebsocket/IXWebSocketServer.h index 6c193aa6..86b173e4 100644 --- a/ixwebsocket/IXWebSocketServer.h +++ b/ixwebsocket/IXWebSocketServer.h @@ -23,14 +23,10 @@ namespace ix { public: using OnConnectionCallback = - std::function, - std::shared_ptr, - std::unique_ptr connectionInfo)>; + std::function, std::shared_ptr)>; - using OnClientMessageCallback = std::function, - ConnectionInfo&, - WebSocket&, - const WebSocketMessagePtr&)>; + using OnClientMessageCallback = std::function, WebSocket&, const WebSocketMessagePtr&)>; WebSocketServer(int port = SocketServer::kDefaultPort, const std::string& host = SocketServer::kDefaultHost, @@ -69,8 +65,7 @@ namespace ix // Methods virtual void handleConnection(std::unique_ptr socket, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo); + std::shared_ptr connectionState); virtual size_t getConnectedClientsCount() final; }; } // namespace ix diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 2f84eb78..9268d8fd 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "10.3.0" +#define IX_WEBSOCKET_VERSION "10.3.1" diff --git a/test/IXCobraToSentryBotTest.cpp b/test/IXCobraToSentryBotTest.cpp index aa45a283..7a64d747 100644 --- a/test/IXCobraToSentryBotTest.cpp +++ b/test/IXCobraToSentryBotTest.cpp @@ -95,15 +95,14 @@ TEST_CASE("Cobra_to_sentry_bot", "[cobra_bots]") sentryServer.setOnConnectionCallback( [](HttpRequestPtr request, - std::shared_ptr /*connectionState*/, - std::unique_ptr connectionInfo) -> HttpResponsePtr { + std::shared_ptr connectionState) -> HttpResponsePtr { WebSocketHttpHeaders headers; headers["Server"] = userAgent(); // Log request std::stringstream ss; - ss << connectionInfo->remoteIp << ":" << connectionInfo->remotePort << " " - << request->method << " " << request->headers["User-Agent"] << " " + ss << connectionState->getRemoteIp() << ":" << connectionState->getRemotePort() + << " " << request->method << " " << request->headers["User-Agent"] << " " << request->uri; if (request->method == "POST") diff --git a/test/IXTest.cpp b/test/IXTest.cpp index 3508d10f..0961751b 100644 --- a/test/IXTest.cpp +++ b/test/IXTest.cpp @@ -85,11 +85,10 @@ namespace ix bool startWebSocketEchoServer(ix::WebSocketServer& server) { server.setOnClientMessageCallback( - [&server](std::shared_ptr /*connectionState*/, - ConnectionInfo& connectionInfo, + [&server](std::shared_ptr connectionState, WebSocket& webSocket, const ix::WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { TLogger() << "New connection"; diff --git a/test/IXWebSocketBroadcastTest.cpp b/test/IXWebSocketBroadcastTest.cpp index 74ef3c7f..0c8d449a 100644 --- a/test/IXWebSocketBroadcastTest.cpp +++ b/test/IXWebSocketBroadcastTest.cpp @@ -191,11 +191,9 @@ namespace server.setOnClientMessageCallback( [&server, &connectionId](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const ix::WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; - + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { diff --git a/test/IXWebSocketChatTest.cpp b/test/IXWebSocketChatTest.cpp index 9d7aee8c..80f3acde 100644 --- a/test/IXWebSocketChatTest.cpp +++ b/test/IXWebSocketChatTest.cpp @@ -195,10 +195,9 @@ namespace { server.setOnClientMessageCallback( [&server](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const ix::WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { TLogger() << "New connection"; diff --git a/test/IXWebSocketCloseTest.cpp b/test/IXWebSocketCloseTest.cpp index bf291eb5..76404d98 100644 --- a/test/IXWebSocketCloseTest.cpp +++ b/test/IXWebSocketCloseTest.cpp @@ -171,10 +171,9 @@ namespace server.setOnClientMessageCallback( [&receivedCloseCode, &receivedCloseReason, &receivedCloseRemote, &mutexWrite]( std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& /*webSocket*/, const ix::WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { TLogger() << "New server connection"; diff --git a/test/IXWebSocketServerTest.cpp b/test/IXWebSocketServerTest.cpp index 8085d0a3..5ff58f64 100644 --- a/test/IXWebSocketServerTest.cpp +++ b/test/IXWebSocketServerTest.cpp @@ -35,11 +35,9 @@ namespace ix server.setOnClientMessageCallback( [&server, &connectionId](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const ix::WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; - + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { diff --git a/test/IXWebSocketSubProtocolTest.cpp b/test/IXWebSocketSubProtocolTest.cpp index 931c6a0d..8c18f7b2 100644 --- a/test/IXWebSocketSubProtocolTest.cpp +++ b/test/IXWebSocketSubProtocolTest.cpp @@ -18,10 +18,9 @@ bool startServer(ix::WebSocketServer& server, std::string& subProtocols) { server.setOnClientMessageCallback( [&server, &subProtocols](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const ix::WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { TLogger() << "New connection"; diff --git a/ws/ws.cpp b/ws/ws.cpp index e43b9d00..33c43377 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -412,10 +412,9 @@ namespace ix server.setOnClientMessageCallback( [&server](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { spdlog::info("New connection"); @@ -1240,10 +1239,9 @@ namespace ix server.setOnClientMessageCallback( [greetings](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { spdlog::info("New connection"); @@ -1674,10 +1672,9 @@ namespace ix server.setOnClientMessageCallback( [greetings, &sendMsg](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { spdlog::info("New connection"); @@ -2613,10 +2610,9 @@ namespace ix server.setOnClientMessageCallback( [&server](std::shared_ptr connectionState, - ConnectionInfo& connectionInfo, WebSocket& webSocket, const WebSocketMessagePtr& msg) { - auto remoteIp = connectionInfo.remoteIp; + auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { spdlog::info("ws_transfer: New connection");