Nothing limited how many connections one address could hold open, and a connection that never logged in stayed open for good, on both servers. worldserver: Network.ConnectionsPerIp (16; a player uses two) and Network.AuthTimeout (60 s to log in). bnetserver: Network.ConnectionsPerIp (16), Network.HandshakeTimeout (30 s for the TLS handshake) and Network.LoginTimeout (600 s to log in). 0 turns each off, and connections from the server's own PC (loopback) are never limited, so the local launcher and a single-PC realm are unaffected. The count lives in Trinity::Net::IpConnectionLimit (common/network), with a test.
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#include "tc_catch2.h"
|
|
#include "IpConnectionLimit.h"
|
|
|
|
using Trinity::Net::IpConnectionLimit;
|
|
|
|
TEST_CASE("An address gets no more than the limit of connections", "[IpConnectionLimit]")
|
|
{
|
|
IpConnectionLimit limit;
|
|
auto a = limit.TryAcquire("10.0.0.5", false, 2);
|
|
auto b = limit.TryAcquire("10.0.0.5", false, 2);
|
|
REQUIRE(a);
|
|
REQUIRE(b);
|
|
CHECK(!limit.TryAcquire("10.0.0.5", false, 2));
|
|
CHECK(limit.GetCount("10.0.0.5") == 2);
|
|
|
|
// another address has its own count
|
|
CHECK(limit.TryAcquire("10.0.0.6", false, 2));
|
|
}
|
|
|
|
TEST_CASE("A closed connection frees its place", "[IpConnectionLimit]")
|
|
{
|
|
IpConnectionLimit limit;
|
|
auto a = limit.TryAcquire("10.0.0.5", false, 1);
|
|
REQUIRE(a);
|
|
CHECK(!limit.TryAcquire("10.0.0.5", false, 1));
|
|
a.reset();
|
|
CHECK(limit.GetCount("10.0.0.5") == 0);
|
|
CHECK(limit.TryAcquire("10.0.0.5", false, 1));
|
|
}
|
|
|
|
TEST_CASE("Loopback and a limit of 0 are never limited or counted", "[IpConnectionLimit]")
|
|
{
|
|
IpConnectionLimit limit;
|
|
for (int i = 0; i < 50; ++i)
|
|
{
|
|
CHECK(limit.TryAcquire("127.0.0.1", true, 1));
|
|
CHECK(limit.TryAcquire("10.0.0.5", false, 0));
|
|
}
|
|
CHECK(limit.GetCount("127.0.0.1") == 0);
|
|
CHECK(limit.GetCount("10.0.0.5") == 0);
|
|
}
|