mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Network: Minor include cleanup in SocketConnectionInitializer related files
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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: ");
|
||||
|
||||
@@ -129,8 +129,7 @@ struct HttpConnectionInitializer final : SocketConnectionInitializer
|
||||
{
|
||||
_socket->ResetHttpParser();
|
||||
|
||||
if (this->next)
|
||||
this->next->Start();
|
||||
this->InvokeNext();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -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)
|
||||
|
||||
25
src/common/network/SslStream.cpp
Normal file
25
src/common/network/SslStream.cpp
Normal file
@@ -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());
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -176,8 +176,7 @@ void WorldSocketProtocolInitializer::HandleDataReady()
|
||||
return;
|
||||
|
||||
_socket->SendAuthSession();
|
||||
if (next)
|
||||
next->Start();
|
||||
InvokeNext();
|
||||
}
|
||||
|
||||
bool WorldSocket::InitializeCompression()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user