Skip to content

Commit

Permalink
Merge branch 'finos:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
topilski authored Oct 23, 2024
2 parents 1710591 + faa8473 commit 49b9465
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 108 deletions.
1 change: 1 addition & 0 deletions test/integration/IntegrationTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "utils/Pacer.h"
#include <cstdint>
#include <gtest/gtest.h>
#include <iomanip>

namespace
{
Expand Down
4 changes: 2 additions & 2 deletions test/integration/emulator/FakeRecordingEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class FakeRecordingEndpoint : public transport::RecordingEndpoint
virtual ~FakeRecordingEndpoint() {}

void sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) override
{
assert(false);
}

void cancelStunTransaction(__uint128_t transactionId) override { assert(false); }
void cancelStunTransaction(ice::Int96 transactionId) override { assert(false); }

void registerListener(const std::string& stunUserName, Endpoint::IEvents* listener) override { assert(false); };
void registerListener(const transport::SocketAddress& remotePort, Endpoint::IEvents* listener) override
Expand Down
6 changes: 4 additions & 2 deletions test/integration/emulator/FakeTcpEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ FakeTcpEndpoint::FakeTcpEndpoint(jobmanager::JobManager& jobManager,
_sendJobs(jobManager, 256 * 1024),
_fakeFd(++_fdGenerator)
{
while (!_network->isLocalPortFree(_localPort.setPort(_portCounter++))) {}
while (!_network->isLocalPortFree(_localPort.setPort(_portCounter++)))
{
}
}

FakeTcpEndpoint::FakeTcpEndpoint(jobmanager::JobManager& jobManager,
Expand Down Expand Up @@ -59,7 +61,7 @@ FakeTcpEndpoint::~FakeTcpEndpoint()
}

void FakeTcpEndpoint::sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
const uint64_t timestamp)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/emulator/FakeTcpEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class FakeTcpEndpoint : public transport::TcpEndpoint, public FakeEndpointImpl

// ice::IceEndpoint
void sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) override;
ice::TransportType getTransportType() const override { return ice::TransportType::TCP; }
transport::SocketAddress getLocalPort() const override { return _localPort; };
void cancelStunTransaction(__uint128_t transactionId) override {}
void cancelStunTransaction(ice::Int96 transactionId) override {}

// transport::Endpoint
void sendTo(const transport::SocketAddress& target, memory::UniquePacket packet) override;
Expand Down
16 changes: 5 additions & 11 deletions test/integration/emulator/FakeUdpEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ FakeUdpEndpoint::~FakeUdpEndpoint()

// ice::IceEndpoint
void FakeUdpEndpoint::sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp)
Expand All @@ -73,11 +73,6 @@ void FakeUdpEndpoint::sendStunTo(const transport::SocketAddress& target,
{
logger::warn("Pending ICE request lookup table is full", _name.c_str());
}
else
{
const IndexableInteger<__uint128_t, uint32_t> id(transactionId);
// logger::debug("register ICE listener for %04x%04x%04x", _name.c_str(), id[1], id[2], id[3]);
}
}
else
{
Expand All @@ -99,7 +94,7 @@ transport::SocketAddress FakeUdpEndpoint::getLocalPort() const
return _localPort;
}

void FakeUdpEndpoint::cancelStunTransaction(__uint128_t transactionId)
void FakeUdpEndpoint::cancelStunTransaction(ice::Int96 transactionId)
{
const bool posted = _receiveJobs.post([this, transactionId]() { _iceResponseListeners.erase(transactionId); });
if (!posted)
Expand Down Expand Up @@ -448,12 +443,11 @@ void FakeUdpEndpoint::dispatchReceivedPacket(const transport::SocketAddress& src
listener = _iceResponseListeners.getItem(transactionId);
if (listener)
{
const IndexableInteger<__uint128_t, uint32_t> id(transactionId);
logger::debug("STUN response received for transaction %04x%04x%04x",
_name.c_str(),
id[1],
id[2],
id[3]);
transactionId.w2,
transactionId.w1,
transactionId.w0);
_iceResponseListeners.erase(transactionId);
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/emulator/FakeUdpEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class FakeUdpEndpoint : public transport::UdpEndpoint, public FakeEndpointImpl

// ice::IceEndpoint
void sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) override;
ice::TransportType getTransportType() const override;
transport::SocketAddress getLocalPort() const override;
void cancelStunTransaction(__uint128_t transactionId) override;
void cancelStunTransaction(ice::Int96 transactionId) override;

// transport::Endpoint
void sendTo(const transport::SocketAddress& target, memory::UniquePacket packet) override;
Expand Down Expand Up @@ -84,7 +84,7 @@ class FakeUdpEndpoint : public transport::UdpEndpoint, public FakeEndpointImpl
transport::SocketAddress _localPort;
concurrency::MpmcHashmap32<std::string, IEvents*> _iceListeners;
concurrency::MpmcHashmap32<transport::SocketAddress, IEvents*> _dtlsListeners;
concurrency::MpmcHashmap32<__uint128_t, IEvents*> _iceResponseListeners;
concurrency::MpmcHashmap32<ice::Int96, IEvents*> _iceResponseListeners;

jobmanager::JobQueue _receiveJobs;
jobmanager::JobQueue _sendJobs;
Expand Down
33 changes: 16 additions & 17 deletions test/transport/IceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TEST_F(IceTest, parseprobe)
"\x9c\x15\xa1\x33";
auto stun = StunMessage::fromPtr(raw);

EXPECT_EQ(stun->header.transactionId.get(), (__uint128_t(0x716c0acc6e502a9eull) << 4 * 8) | 0xf7df3cf2ull);
EXPECT_EQ(stun->header.transactionId.get(), ice::Int96({0x716c0acc, 0x6e502a9e, 0xf7df3cf2}));
EXPECT_EQ(stun->header.length, 60);
EXPECT_EQ(stun->header.method.get(), ice::StunHeader::BindingResponse);

Expand Down Expand Up @@ -357,7 +357,7 @@ TEST_F(IceTest, stunv6)
{
ice::StunMessage msg;
msg.header.setMethod(ice::StunHeader::BindingRequest);
msg.header.transactionId.set(0x1111222233334444ull);
msg.header.transactionId.set({0x1111u, 0x2222u, 0x3333u});
ice::StunXorMappedAddress addr;
auto address = transport::SocketAddress::parse("a000:1092:10cc:f56e::3c00", 0);
addr.setAddress(address, msg.header);
Expand All @@ -371,7 +371,7 @@ TEST_F(IceTest, build)
using namespace ice;
ice::StunMessage msg;
msg.header.setMethod(ice::StunHeader::BindingRequest);
msg.header.transactionId.set(0x1111222233334444ull);
msg.header.transactionId.set({0x1111, 0x2222, 0x3333});

uint32_t tieBreaker = 0x1234123;
msg.add(StunGenericAttribute(StunAttribute::SOFTWARE, "slice"));
Expand All @@ -394,15 +394,15 @@ class IceSocketAdapter : public ice::IceEndpoint
virtual ~IceSocketAdapter(){};

void sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) override
{
_socket.sendTo(static_cast<const char*>(data), len, target);
}

void cancelStunTransaction(__uint128_t transactionId) override {}
void cancelStunTransaction(ice::Int96 transactionId) override {}

transport::SocketAddress getLocalPort() const override { return _ip; }
ice::TransportType getTransportType() const override { return ice::TransportType::UDP; }
Expand Down Expand Up @@ -574,11 +574,11 @@ class FakeEndpoint : public ice::IceEndpoint, fakenet::NetworkNode
size_t length,
const uint64_t timestamp) override;
void sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) override;
void cancelStunTransaction(__uint128_t transactionId) override {}
void cancelStunTransaction(ice::Int96 transactionId) override {}

transport::SocketAddress getLocalPort() const override { return _address; }
bool hasIp(const transport::SocketAddress& target) override { return target == _address; }
Expand Down Expand Up @@ -654,7 +654,7 @@ void FakeEndpoint::onReceive(fakenet::Protocol protocol,
}

void FakeEndpoint::sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t length,
const uint64_t timestamp)
Expand Down Expand Up @@ -1849,12 +1849,11 @@ TEST_F(IceTest, serialize)

TEST_F(IceTest, transactionId)
{
__uint128_t id = (__uint128_t(0x9012121102568943ull) << 64) | 0x6623184555672389ull;
IndexableInteger<__uint128_t, uint32_t> id2(id);
EXPECT_EQ(id2[0], 0x90121211);
EXPECT_EQ(id2[1], 0x02568943);
EXPECT_EQ(id2[2], 0x66231845);
EXPECT_EQ(id2[3], 0x55672389);
ice::Int96 id{0x90121211, 0x02568943, 0x55672389};

EXPECT_EQ(id.w2, 0x90121211);
EXPECT_EQ(id.w1, 0x02568943);
EXPECT_EQ(id.w0, 0x55672389);
}

class IceEndpointMock : public ice::IceEndpoint
Expand All @@ -1863,15 +1862,15 @@ class IceEndpointMock : public ice::IceEndpoint
MOCK_METHOD(void,
sendStunTo,
(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp),
(override));

MOCK_METHOD(ice::TransportType, getTransportType, (), (const, override));
MOCK_METHOD(transport::SocketAddress, getLocalPort, (), (const, override));
MOCK_METHOD(void, cancelStunTransaction, (__uint128_t transactionId), (override));
MOCK_METHOD(void, cancelStunTransaction, (ice::Int96 transactionId), (override));
};

TEST_F(IceTest, retransmissions)
Expand Down Expand Up @@ -1901,7 +1900,7 @@ TEST_F(IceTest, retransmissions)
std::vector<uint64_t> timestamps;
ON_CALL(*networkMockA.get(), sendStunTo)
.WillByDefault([&timestamps](const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) { timestamps.push_back(timestamp); });
Expand Down
2 changes: 1 addition & 1 deletion test/utils/RandGeneratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(SsrcGenerator, realloc)

TEST(StunIdGenerator, realloc)
{
__uint128_t a1, a2;
ice::Int96 a1, a2;
generate<ice::StunTransactionIdGenerator>(a1);
generate<ice::StunTransactionIdGenerator>(a2);
EXPECT_NE(a1, a2);
Expand Down
1 change: 1 addition & 0 deletions test/utils/SocketAddressTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "utils/SocketAddress.h"
#include <array>
#include <gtest/gtest.h>
#include <string>

Expand Down
4 changes: 2 additions & 2 deletions transport/RecordingEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class RecordingEndpointImpl : public RecordingEndpoint
~RecordingEndpointImpl();

void sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) override
{
assert(false);
}

void cancelStunTransaction(__uint128_t transactionId) override { assert(false); }
void cancelStunTransaction(ice::Int96 transactionId) override { assert(false); }

void registerListener(const std::string& stunUserName, Endpoint::IEvents* listener) override { assert(false); };
void registerListener(const SocketAddress& remotePort, Endpoint::IEvents* listener) override { assert(false); };
Expand Down
2 changes: 1 addition & 1 deletion transport/TcpEndpointImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void TcpEndpointImpl::connect(const SocketAddress& remotePort)
}

void TcpEndpointImpl::sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
const uint64_t timestamp)
Expand Down
4 changes: 2 additions & 2 deletions transport/TcpEndpointImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TcpEndpointImpl : public TcpEndpoint, public RtcePoll::IEventListener
virtual ~TcpEndpointImpl();

void sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp) override;
Expand All @@ -103,7 +103,7 @@ class TcpEndpointImpl : public TcpEndpoint, public RtcePoll::IEventListener
void connect(const SocketAddress& remotePort);

SocketAddress getLocalPort() const override;
void cancelStunTransaction(__uint128_t transactionId) override{};
void cancelStunTransaction(ice::Int96 transactionId) override{};

bool configureBufferSizes(size_t sendBufferSize, size_t receiveBufferSize) override;

Expand Down
25 changes: 11 additions & 14 deletions transport/UdpEndpointImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ UdpEndpointImpl::~UdpEndpointImpl()
}

void UdpEndpointImpl::sendStunTo(const transport::SocketAddress& target,
__uint128_t transactionId,
ice::Int96 transactionId,
const void* data,
size_t len,
uint64_t timestamp)
Expand All @@ -84,12 +84,11 @@ void UdpEndpointImpl::sendStunTo(const transport::SocketAddress& target,
}
else
{
const IndexableInteger<__uint128_t, uint32_t> id(transactionId);
LOG("register ICE listener for %04x%04x%04x, count %" PRIu64,
_name.c_str(),
id[1],
id[2],
id[3],
transactionId.w2,
transactionId.w1,
transactionId.w0,
_iceResponseListeners.size());
}
}
Expand All @@ -107,16 +106,15 @@ void UdpEndpointImpl::unregisterListener(IEvents* listener)
}
}

void UdpEndpointImpl::cancelStunTransaction(__uint128_t transactionId)
void UdpEndpointImpl::cancelStunTransaction(ice::Int96 transactionId)
{
const bool posted = _baseUdpEndpoint._receiveJobs.post([this, transactionId]() {
_iceResponseListeners.erase(transactionId);
const IndexableInteger<__uint128_t, uint32_t> id(transactionId);
LOG("remove ICE listener for %04x%04x%04x, count %" PRIu64,
_name.c_str(),
id[1],
id[2],
id[3],
transactionId.w2,
transactionId.w1,
transactionId.w0,
_iceResponseListeners.size());
});
if (!posted)
Expand Down Expand Up @@ -193,12 +191,11 @@ void UdpEndpointImpl::dispatchReceivedPacket(const SocketAddress& srcAddress,
if (listener)
{
_iceResponseListeners.erase(transactionId);
const IndexableInteger<__uint128_t, uint32_t> id(transactionId);
LOG("STUN response received for transaction %04x%04x%04x, count %" PRIu64,
_name.c_str(),
id[1],
id[2],
id[3],
transactionId.w2,
transactionId.w1,
transactionId.w0,
_iceResponseListeners.size());
}
}
Expand Down
Loading

0 comments on commit 49b9465

Please sign in to comment.