diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-09-22 16:12:01 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-09-22 16:12:01 +0200 |
commit | df02bec2a1871267548494bc473711a0f9de9b43 (patch) | |
tree | 9e1951fca316ecd0ad48ee7428a0b33bdd79d4f0 /src | |
parent | bb1cc8a48f8f3472ebdfdbaa6a97ec2e1c5190c8 (diff) |
Core/Network: Minor include cleanup in SocketConnectionInitializer related files
Diffstat (limited to 'src')
9 files changed, 63 insertions, 21 deletions
diff --git a/src/common/network/ConnectionInitializers/SocketConnectionInitializer.h b/src/common/network/ConnectionInitializers/SocketConnectionInitializer.h index d3f0bb16dbf..7740837e6de 100644 --- a/src/common/network/ConnectionInitializers/SocketConnectionInitializer.h +++ b/src/common/network/ConnectionInitializers/SocketConnectionInitializer.h @@ -36,6 +36,12 @@ struct SocketConnectionInitializer : public std::enable_shared_from_this<SocketC virtual void Start() = 0; + void InvokeNext() + { + if (next) + next->Start(); + } + std::shared_ptr<SocketConnectionInitializer> next; static std::shared_ptr<SocketConnectionInitializer>& SetupChain(std::span<std::shared_ptr<SocketConnectionInitializer>> initializers) diff --git a/src/common/network/Http/BaseHttpSocket.cpp b/src/common/network/Http/BaseHttpSocket.cpp index f14c0c98a9e..1f264856ad1 100644 --- a/src/common/network/Http/BaseHttpSocket.cpp +++ b/src/common/network/Http/BaseHttpSocket.cpp @@ -16,6 +16,7 @@ */ #include "BaseHttpSocket.h" +#include "IpAddress.h" #include <boost/asio/buffers_iterator.hpp> #include <boost/beast/http/serializer.hpp> #include <boost/uuid/uuid_io.hpp> @@ -164,7 +165,7 @@ void AbstractSocket::LogRequestAndResponse(RequestContext const& context, Messag std::string AbstractSocket::GetClientInfo(boost::asio::ip::address const& address, uint16 port, SessionState const* state) { - std::string info = StringFormat("[{}:{}", address.to_string(), port); + std::string info = StringFormat("[{}:{}", address, port); if (state) { info.append(", Session Id: "); diff --git a/src/common/network/Http/BaseHttpSocket.h b/src/common/network/Http/BaseHttpSocket.h index c4d9c675de1..72b9fd6a9b7 100644 --- a/src/common/network/Http/BaseHttpSocket.h +++ b/src/common/network/Http/BaseHttpSocket.h @@ -129,8 +129,7 @@ struct HttpConnectionInitializer final : SocketConnectionInitializer { _socket->ResetHttpParser(); - if (this->next) - this->next->Start(); + this->InvokeNext(); } private: diff --git a/src/common/network/Socket.h b/src/common/network/Socket.h index c2b2c63a291..aa2060691d5 100644 --- a/src/common/network/Socket.h +++ b/src/common/network/Socket.h @@ -31,7 +31,6 @@ #include <queue> #include <type_traits> -#define READ_BLOCK_SIZE 4096 #ifdef BOOST_ASIO_HAS_IOCP #define TC_SOCKET_USE_IOCP #endif @@ -70,20 +69,21 @@ struct InvokeReadHandlerCallback SocketType* Socket; }; -template <typename SocketType> +template <typename AsyncReadObjectType, typename ReadHandlerObjectType = AsyncReadObjectType> struct ReadConnectionInitializer final : SocketConnectionInitializer { - explicit ReadConnectionInitializer(SocketType* socket) : ReadCallback({ .Socket = socket }) { } + explicit ReadConnectionInitializer(AsyncReadObjectType* socket) : Socket(socket), ReadCallback({ .Socket = socket }) { } + explicit ReadConnectionInitializer(AsyncReadObjectType* socket, ReadHandlerObjectType* callbackSocket) : Socket(socket), ReadCallback({ .Socket = callbackSocket }) { } void Start() override { - ReadCallback.Socket->AsyncRead(std::move(ReadCallback)); + Socket->AsyncRead(std::move(ReadCallback)); - if (this->next) - this->next->Start(); + this->InvokeNext(); } - InvokeReadHandlerCallback<SocketType> ReadCallback; + AsyncReadObjectType* Socket; + InvokeReadHandlerCallback<ReadHandlerObjectType> ReadCallback; }; /** @@ -383,7 +383,7 @@ private: boost::asio::ip::address _remoteAddress; uint16 _remotePort = 0; - MessageBuffer _readBuffer = MessageBuffer(READ_BLOCK_SIZE); + MessageBuffer _readBuffer = MessageBuffer(0x1000); std::queue<MessageBuffer> _writeQueue; // Socket open state "enum" (not enum to enable integral std::atomic api) diff --git a/src/common/network/SslStream.cpp b/src/common/network/SslStream.cpp new file mode 100644 index 00000000000..f2c358a4ffe --- /dev/null +++ b/src/common/network/SslStream.cpp @@ -0,0 +1,25 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "SslStream.h" +#include "IpAddress.h" +#include "Log.h" + +void Trinity::Net::SslHandshakeHelpers::LogFailure(boost::asio::ip::address const& ipAddress, uint16 port, boost::system::error_code const& error) +{ + TC_LOG_ERROR("session", "{}:{} SSL Handshake failed {}", ipAddress, port, error.message()); +} diff --git a/src/common/network/SslStream.h b/src/common/network/SslStream.h index 6bf949dcb47..47668c5003c 100644 --- a/src/common/network/SslStream.h +++ b/src/common/network/SslStream.h @@ -18,6 +18,8 @@ #ifndef TRINITYCORE_SSL_STREAM_H #define TRINITYCORE_SSL_STREAM_H +#include "Define.h" +#include "Socket.h" #include "SocketConnectionInitializer.h" #include <boost/asio/ip/tcp.hpp> #include <boost/asio/ssl/stream.hpp> @@ -25,6 +27,11 @@ namespace Trinity::Net { +namespace SslHandshakeHelpers +{ +TC_NETWORK_API void LogFailure(boost::asio::ip::address const& ipAddress, uint16 port, boost::system::error_code const& error); +} + template <typename SocketImpl> struct SslHandshakeConnectionInitializer final : SocketConnectionInitializer { @@ -41,13 +48,12 @@ struct SslHandshakeConnectionInitializer final : SocketConnectionInitializer if (error) { - TC_LOG_ERROR("session", "{} SSL Handshake failed {}", socket->GetClientInfo(), error.message()); + SslHandshakeHelpers::LogFailure(socket->GetRemoteIpAddress(), socket->GetRemotePort(), error); socket->CloseSocket(); return; } - if (self->next) - self->next->Start(); + self->InvokeNext(); }); } diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index ddee89aff1f..27d1328ec90 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -176,8 +176,7 @@ void WorldSocketProtocolInitializer::HandleDataReady() return; _socket->SendAuthSession(); - if (next) - next->Start(); + InvokeNext(); } bool WorldSocket::InitializeCompression() diff --git a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp index 4e7d9a4ab72..d80de6cab41 100644 --- a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp +++ b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp @@ -17,6 +17,8 @@ #include "IpBanCheckConnectionInitializer.h" #include "DatabaseEnv.h" +#include "IpAddress.h" +#include "Log.h" QueryCallback Trinity::Net::IpBanCheckHelpers::AsyncQuery(boost::asio::ip::address const& ipAddress) { @@ -40,3 +42,8 @@ bool Trinity::Net::IpBanCheckHelpers::IsBanned(PreparedQueryResult const& result return false; } + +void Trinity::Net::IpBanCheckHelpers::LogFailure(boost::asio::ip::address const& ipAddress) +{ + TC_LOG_ERROR("network", "IpBanCheckConnectionInitializer: IP {} is banned.", ipAddress); +} diff --git a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h index d8badeb1203..a826c6af7dc 100644 --- a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h +++ b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h @@ -18,9 +18,8 @@ #ifndef TRINITYCORE_IP_BAN_CHECK_CONNECTION_INITIALIZER_H #define TRINITYCORE_IP_BAN_CHECK_CONNECTION_INITIALIZER_H +#include "AsioHacksFwd.h" #include "DatabaseEnvFwd.h" -#include "IpAddress.h" -#include "Log.h" #include "QueryCallback.h" #include "SocketConnectionInitializer.h" @@ -30,6 +29,7 @@ namespace IpBanCheckHelpers { TC_SHARED_API QueryCallback AsyncQuery(boost::asio::ip::address const& ipAddress); TC_SHARED_API bool IsBanned(PreparedQueryResult const& result); +TC_SHARED_API void LogFailure(boost::asio::ip::address const& ipAddress); } template <typename SocketImpl> @@ -47,13 +47,12 @@ struct IpBanCheckConnectionInitializer final : SocketConnectionInitializer if (IpBanCheckHelpers::IsBanned(result)) { - TC_LOG_ERROR("network", "IpBanCheckConnectionInitializer: IP {} is banned.", socket->GetRemoteIpAddress()); + IpBanCheckHelpers::LogFailure(socket->GetRemoteIpAddress()); socket->CloseSocket(); return; } - if (self->next) - self->next->Start(); + self->InvokeNext(); })); } |