diff --git a/test/integration/IntegrationTest.h b/test/integration/IntegrationTest.h index e5f20c08..631ff6f2 100644 --- a/test/integration/IntegrationTest.h +++ b/test/integration/IntegrationTest.h @@ -14,6 +14,7 @@ #include "utils/Pacer.h" #include #include +#include namespace { diff --git a/test/integration/emulator/FakeRecordingEndpoint.h b/test/integration/emulator/FakeRecordingEndpoint.h index 879630b3..aed7e46a 100644 --- a/test/integration/emulator/FakeRecordingEndpoint.h +++ b/test/integration/emulator/FakeRecordingEndpoint.h @@ -8,7 +8,7 @@ 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 @@ -16,7 +16,7 @@ class FakeRecordingEndpoint : public transport::RecordingEndpoint 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 diff --git a/test/integration/emulator/FakeTcpEndpoint.cpp b/test/integration/emulator/FakeTcpEndpoint.cpp index 1fe56d7e..487cb4a0 100644 --- a/test/integration/emulator/FakeTcpEndpoint.cpp +++ b/test/integration/emulator/FakeTcpEndpoint.cpp @@ -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, @@ -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) diff --git a/test/integration/emulator/FakeTcpEndpoint.h b/test/integration/emulator/FakeTcpEndpoint.h index d3f599d8..c5f098e8 100644 --- a/test/integration/emulator/FakeTcpEndpoint.h +++ b/test/integration/emulator/FakeTcpEndpoint.h @@ -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; diff --git a/test/integration/emulator/FakeUdpEndpoint.cpp b/test/integration/emulator/FakeUdpEndpoint.cpp index 91d8e0ee..2d7e67d0 100644 --- a/test/integration/emulator/FakeUdpEndpoint.cpp +++ b/test/integration/emulator/FakeUdpEndpoint.cpp @@ -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) @@ -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 { @@ -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) @@ -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); } } diff --git a/test/integration/emulator/FakeUdpEndpoint.h b/test/integration/emulator/FakeUdpEndpoint.h index 70e76991..fd63a437 100644 --- a/test/integration/emulator/FakeUdpEndpoint.h +++ b/test/integration/emulator/FakeUdpEndpoint.h @@ -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; @@ -84,7 +84,7 @@ class FakeUdpEndpoint : public transport::UdpEndpoint, public FakeEndpointImpl transport::SocketAddress _localPort; concurrency::MpmcHashmap32 _iceListeners; concurrency::MpmcHashmap32 _dtlsListeners; - concurrency::MpmcHashmap32<__uint128_t, IEvents*> _iceResponseListeners; + concurrency::MpmcHashmap32 _iceResponseListeners; jobmanager::JobQueue _receiveJobs; jobmanager::JobQueue _sendJobs; diff --git a/test/transport/IceTest.cpp b/test/transport/IceTest.cpp index 8cb0d992..40c52f1e 100644 --- a/test/transport/IceTest.cpp +++ b/test/transport/IceTest.cpp @@ -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); @@ -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); @@ -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")); @@ -394,7 +394,7 @@ 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 @@ -402,7 +402,7 @@ class IceSocketAdapter : public ice::IceEndpoint _socket.sendTo(static_cast(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; } @@ -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; } @@ -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) @@ -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 @@ -1863,7 +1862,7 @@ 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), @@ -1871,7 +1870,7 @@ class IceEndpointMock : public ice::IceEndpoint 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) @@ -1901,7 +1900,7 @@ TEST_F(IceTest, retransmissions) std::vector timestamps; ON_CALL(*networkMockA.get(), sendStunTo) .WillByDefault([×tamps](const transport::SocketAddress& target, - __uint128_t transactionId, + ice::Int96 transactionId, const void* data, size_t len, uint64_t timestamp) { timestamps.push_back(timestamp); }); diff --git a/test/utils/RandGeneratorTest.cpp b/test/utils/RandGeneratorTest.cpp index f454a97c..91ab0d44 100644 --- a/test/utils/RandGeneratorTest.cpp +++ b/test/utils/RandGeneratorTest.cpp @@ -20,7 +20,7 @@ TEST(SsrcGenerator, realloc) TEST(StunIdGenerator, realloc) { - __uint128_t a1, a2; + ice::Int96 a1, a2; generate(a1); generate(a2); EXPECT_NE(a1, a2); diff --git a/test/utils/SocketAddressTest.cpp b/test/utils/SocketAddressTest.cpp index 9a7d1401..1c56c07e 100644 --- a/test/utils/SocketAddressTest.cpp +++ b/test/utils/SocketAddressTest.cpp @@ -1,4 +1,5 @@ #include "utils/SocketAddress.h" +#include #include #include diff --git a/transport/RecordingEndpoint.h b/transport/RecordingEndpoint.h index bade6623..26cb7b69 100644 --- a/transport/RecordingEndpoint.h +++ b/transport/RecordingEndpoint.h @@ -38,7 +38,7 @@ 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 @@ -46,7 +46,7 @@ class RecordingEndpointImpl : public RecordingEndpoint 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); }; diff --git a/transport/TcpEndpointImpl.cpp b/transport/TcpEndpointImpl.cpp index 9e878ca2..182613d6 100644 --- a/transport/TcpEndpointImpl.cpp +++ b/transport/TcpEndpointImpl.cpp @@ -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) diff --git a/transport/TcpEndpointImpl.h b/transport/TcpEndpointImpl.h index bf61f0b8..46d688ea 100644 --- a/transport/TcpEndpointImpl.h +++ b/transport/TcpEndpointImpl.h @@ -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; @@ -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; diff --git a/transport/UdpEndpointImpl.cpp b/transport/UdpEndpointImpl.cpp index 0c8e7471..897141e9 100644 --- a/transport/UdpEndpointImpl.cpp +++ b/transport/UdpEndpointImpl.cpp @@ -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) @@ -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()); } } @@ -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) @@ -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()); } } diff --git a/transport/UdpEndpointImpl.h b/transport/UdpEndpointImpl.h index b0403856..926ecf5d 100644 --- a/transport/UdpEndpointImpl.h +++ b/transport/UdpEndpointImpl.h @@ -22,12 +22,12 @@ class UdpEndpointImpl : public UdpEndpoint ~UdpEndpointImpl(); 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; void registerListener(const std::string& stunUserName, IEvents* listener) override; void registerListener(const SocketAddress& remotePort, IEvents* listener) override; @@ -67,7 +67,7 @@ class UdpEndpointImpl : public UdpEndpoint void dispatchReceivedPacket(const SocketAddress& srcAddress, memory::UniquePacket packet, const uint64_t timestamp); void internalUnregisterListener(IEvents* listener); - void internalUnregisterStunListener(__uint128_t transactionId); + void internalUnregisterStunListener(ice::Int96 transactionId); void swapListener(const SocketAddress& srcAddress, IEvents* newListener); logger::LoggableId _name; @@ -77,7 +77,7 @@ class UdpEndpointImpl : public UdpEndpoint concurrency::MpmcHashmap32 _dtlsListeners; // mainly used for client requests. SMB mainly uses dtlsListener for IP:port - concurrency::MpmcHashmap32<__uint128_t, IEvents*> _iceResponseListeners; + concurrency::MpmcHashmap32 _iceResponseListeners; std::atomic _defaultListener; }; } // namespace transport diff --git a/transport/ice/IceSession.cpp b/transport/ice/IceSession.cpp index d8935f59..bbb3f492 100644 --- a/transport/ice/IceSession.cpp +++ b/transport/ice/IceSession.cpp @@ -62,7 +62,7 @@ IceSession::IceSession(size_t sessionId, _config(config), _state(State::IDLE), _eventSink(eventSink), - _credentials(role, static_cast(_idGenerator.next() & ~(0ull))), + _credentials(role, static_cast(_idGenerator.next().w0) << 32 | _idGenerator.next().w1), _sessionStart(0), _connectedCount(0) { @@ -1554,19 +1554,22 @@ void IceSession::generateCredentialString(StunTransactionIdGenerator& idGenerato "0123456789" "+/"; const int COUNT = std::strlen(approvedLetters); - __uint64_t id = 0; + Int96 id; for (int i = 0; i < length; i++) { - if (i % 10 == 0) + if (i % 3 == 0) { id = idGenerator.next(); + targetBuffer[i] = approvedLetters[(id.w0 & 0x3Fu) % COUNT]; } - else + else if (i % 3 == 1) { - id >>= 6; + targetBuffer[i] = approvedLetters[(id.w1 & 0x3Fu) % COUNT]; + } + else if (i % 3 == 2) + { + targetBuffer[i] = approvedLetters[(id.w2 & 0x3Fu) % COUNT]; } - - targetBuffer[i] = approvedLetters[(id & 0x3Fu) % COUNT]; } targetBuffer[length] = '\0'; } diff --git a/transport/ice/IceSession.h b/transport/ice/IceSession.h index 01adb5fd..a6155d9f 100644 --- a/transport/ice/IceSession.h +++ b/transport/ice/IceSession.h @@ -5,6 +5,7 @@ #include "crypto/SslHelper.h" #include "memory/Map.h" #include "utils/SocketAddress.h" +#include "utils/StdExtensions.h" #include "utils/Time.h" #include @@ -49,14 +50,14 @@ class IceEndpoint { public: virtual void sendStunTo(const transport::SocketAddress& target, - __uint128_t transactionId, + Int96 transactionId, const void* data, size_t len, uint64_t timestamp) = 0; virtual ice::TransportType getTransportType() const = 0; virtual transport::SocketAddress getLocalPort() const = 0; - virtual void cancelStunTransaction(__uint128_t transactionId) = 0; + virtual void cancelStunTransaction(ice::Int96 transactionId) = 0; }; enum class IceRole @@ -454,4 +455,9 @@ class hash }; }; +template <> +struct hash +{ + uint64_t operator()(ice::Int96 key) const { return utils::hash::hashBuffer(&key, sizeof(key)); } +}; } // namespace std diff --git a/transport/ice/Stun.cpp b/transport/ice/Stun.cpp index 0d11e9ae..078cce97 100644 --- a/transport/ice/Stun.cpp +++ b/transport/ice/Stun.cpp @@ -22,27 +22,21 @@ StunTransactionIdGenerator::StunTransactionIdGenerator() { } -__uint128_t StunTransactionIdGenerator::next() +Int96 StunTransactionIdGenerator::next() { - return static_cast<__uint128_t>(_distribution(_generator)) << 64 | _distribution(_generator); + const uint32_t value0 = _distribution(_generator); + const uint32_t value1 = _distribution(_generator); + const uint32_t value2 = _distribution(_generator); + return Int96{value0, value1, value2}; } StunTransactionId::StunTransactionId() : w2(0), w1(0), w0(0) {} -void StunTransactionId::set(__uint128_t id) +void StunTransactionId::set(Int96 id) { - w0 = id & 0xFFFFFFFFu; - w1 = (id >> 32) & 0xFFFFFFFFu; - w2 = (id >> 64) & 0xFFFFFFFFu; -} - -__uint128_t StunTransactionId::get() const -{ - __uint128_t result = w2; - result <<= 32; - result |= w1; - result <<= 32; - return result | w0; + w0 = id.w0; + w1 = id.w1; + w2 = id.w2; } StunHeader::StunHeader() : method(BindingRequest), length(0), magicCookie(MAGIC_COOKIE) {} @@ -139,12 +133,12 @@ bool isResponse(const void* p) return msg->isResponse(); } -__uint128_t getStunTransactionId(const void* data, size_t length) +ice::Int96 getStunTransactionId(const void* data, size_t length) { auto msg = StunMessage::fromPtr(data); if (!msg->header.isValid() || msg->header.length + sizeof(StunHeader) != length) { - return 0; + return Int96(); } return msg->header.transactionId.get(); diff --git a/transport/ice/Stun.h b/transport/ice/Stun.h index 884039e3..45bb676d 100644 --- a/transport/ice/Stun.h +++ b/transport/ice/Stun.h @@ -15,6 +15,17 @@ class HMAC; namespace ice { const size_t MTU = 1280; // rfc states 576B for ipv4 and 1280 for ipv6 + +struct Int96 +{ + uint32_t w2 = 0; + uint32_t w1 = 0; + uint32_t w0 = 0; + + bool operator==(const Int96& s) const { return w0 == s.w0 && w1 == s.w1 && w2 == s.w2; } + bool operator!=(const Int96& s) const { return w0 != s.w0 || w1 != s.w1 || w2 != s.w2; } +}; + struct StunTransactionId { nwuint32_t w2; // msb @@ -22,8 +33,8 @@ struct StunTransactionId nwuint32_t w0; StunTransactionId(); - void set(__uint128_t id); - __uint128_t get() const; + Int96 get() const { return {w2.get(), w1.get(), w0.get()}; } + void set(Int96 v); }; struct StunHeader @@ -285,7 +296,7 @@ class StunTransactionIdGenerator { public: StunTransactionIdGenerator(); - __uint128_t next(); + Int96 next(); private: std::mt19937_64 _generator; @@ -339,7 +350,7 @@ class StunMessage }; bool isStunMessage(const void* data, size_t length); -__uint128_t getStunTransactionId(const void* data, size_t length); +ice::Int96 getStunTransactionId(const void* data, size_t length); bool isRequest(const void* p); bool isResponse(const void* p); diff --git a/utils/ByteOrder.h b/utils/ByteOrder.h index 2bdfbc4b..1ad1d099 100644 --- a/utils/ByteOrder.h +++ b/utils/ByteOrder.h @@ -93,20 +93,3 @@ IntT toLittleEndian(IntT value) return value; } - -template -class IndexableInteger -{ -public: - explicit IndexableInteger(const T& value) : _value(value) {} - - RT operator[](size_t i) const - { - assert(i < sizeof(_value) / sizeof(RT)); - auto v = reinterpret_cast(&_value); - return (isBigEndian() ? v[i] : v[sizeof(_value) / sizeof(RT) - i - 1]) & 0xFFFFFFFFu; - } - -private: - const T& _value; -};