Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions node/src/WebRtcServer.ts
Comment thread
penguinol marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
WebRtcServer,
IpPort,
IceUserNameFragment,
TupleHash,
WebRtcServerDump,
WebRtcServerEvents,
WebRtcServerObserver,
Expand Down Expand Up @@ -208,13 +207,6 @@ function parseIceUserNameFragment(
};
}

function parseTupleHash(binary: FbsWebRtcServer.TupleHash): TupleHash {
return {
tupleHash: Number(binary.tupleHash()),
webRtcTransportId: binary.webRtcTransportId()!,
};
}

function parseWebRtcServerDump(
data: FbsWebRtcServer.DumpResponse
): WebRtcServerDump {
Expand All @@ -228,6 +220,5 @@ function parseWebRtcServerDump(
'localIceUsernameFragments',
parseIceUserNameFragment
),
tupleHashes: fbsUtils.parseVector(data, 'tupleHashes', parseTupleHash),
};
}
6 changes: 0 additions & 6 deletions node/src/WebRtcServerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@ export type IceUserNameFragment = {
webRtcTransportId: string;
};

export type TupleHash = {
tupleHash: number;
webRtcTransportId: string;
};

export type WebRtcServerDump = {
id: string;
udpSockets: IpPort[];
tcpServers: IpPort[];
webRtcTransportIds: string[];
localIceUsernameFragments: IceUserNameFragment[];
tupleHashes: TupleHash[];
};

export type WebRtcServerEvents = {
Expand Down
7 changes: 0 additions & 7 deletions node/src/test/test-WebRtcServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ test('worker.createWebRtcServer() succeeds', async () => {
tcpServers: [{ ip: '127.0.0.1', port: port2 }],
webRtcTransportIds: [],
localIceUsernameFragments: [],
tupleHashes: [],
});

// API not exposed in the interface.
Expand Down Expand Up @@ -149,7 +148,6 @@ test('worker.createWebRtcServer() with portRange succeeds', async () => {
tcpServers: [{ ip: '127.0.0.1', port: port2 }],
webRtcTransportIds: [],
localIceUsernameFragments: [],
tupleHashes: [],
});

// API not exposed in the interface.
Expand Down Expand Up @@ -205,7 +203,6 @@ test('worker.createWebRtcServer() without specifying port/portRange succeeds', a
tcpServers: [{ ip: '127.0.0.1', port: expect.any(Number) }],
webRtcTransportIds: [],
localIceUsernameFragments: [],
tupleHashes: [],
});

// API not exposed in the interface.
Expand Down Expand Up @@ -471,7 +468,6 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is
localIceUsernameFragments: [
{ /* localIceUsernameFragment: xxx, */ webRtcTransportId: transport.id },
],
tupleHashes: [],
});

transport.close();
Expand All @@ -492,7 +488,6 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is
tcpServers: [{ ip: '127.0.0.1', port: port2 }],
webRtcTransportIds: [],
localIceUsernameFragments: [],
tupleHashes: [],
});
}, 2000);

Expand Down Expand Up @@ -575,7 +570,6 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and webRtcServer
localIceUsernameFragments: [
{ /* localIceUsernameFragment: xxx, */ webRtcTransportId: transport.id },
],
tupleHashes: [],
});

// Let's restart ICE in the transport so it should add a new entry in
Expand All @@ -591,7 +585,6 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and webRtcServer
{ /* localIceUsernameFragment: xxx, */ webRtcTransportId: transport.id },
{ /* localIceUsernameFragment: yyy, */ webRtcTransportId: transport.id },
],
tupleHashes: [],
});

const onObserverClose = jest.fn();
Expand Down
10 changes: 1 addition & 9 deletions rust/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::rtp_observer::RtpObserverId;
use crate::transport::{TransportId, TransportTraceEventType};
use crate::webrtc_server::{
WebRtcServerDump, WebRtcServerIceUsernameFragment, WebRtcServerId, WebRtcServerIpPort,
WebRtcServerListenInfos, WebRtcServerTupleHash,
WebRtcServerListenInfos,
};
use crate::webrtc_transport::{
WebRtcTransportListen, WebRtcTransportListenInfos, WebRtcTransportOptions,
Expand Down Expand Up @@ -360,14 +360,6 @@ impl Request for WebRtcServerDumpRequest {
webrtc_transport_id: username_fragment.web_rtc_transport_id.parse().unwrap(),
})
.collect(),
tuple_hashes: data
.tuple_hashes
.into_iter()
.map(|tuple_hash| WebRtcServerTupleHash {
tuple_hash: tuple_hash.tuple_hash,
webrtc_transport_id: tuple_hash.web_rtc_transport_id.parse().unwrap(),
})
.collect(),
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions rust/src/router/webrtc_transport/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ fn create_with_webrtc_server_succeeds() {
webrtc_server_dump.local_ice_username_fragments[0].webrtc_transport_id,
transport.id()
);
assert_eq!(webrtc_server_dump.tuple_hashes, vec![]);
}

{
Expand Down Expand Up @@ -222,7 +221,6 @@ fn create_with_webrtc_server_succeeds() {
HashedSet::default()
);
assert_eq!(webrtc_server_dump.local_ice_username_fragments, vec![]);
assert_eq!(webrtc_server_dump.tuple_hashes, vec![]);
}
});
}
Expand Down
10 changes: 0 additions & 10 deletions rust/src/webrtc_server.rs
Comment thread
penguinol marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ pub struct WebRtcServerIceUsernameFragment {
pub webrtc_transport_id: TransportId,
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[doc(hidden)]
pub struct WebRtcServerTupleHash {
pub tuple_hash: u64,
#[serde(rename = "webRtcTransportId")]
pub webrtc_transport_id: TransportId,
}

#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[doc(hidden)]
Expand All @@ -70,7 +61,6 @@ pub struct WebRtcServerDump {
#[serde(rename = "webRtcTransportIds")]
pub webrtc_transport_ids: HashedSet<TransportId>,
pub local_ice_username_fragments: Vec<WebRtcServerIceUsernameFragment>,
pub tuple_hashes: Vec<WebRtcServerTupleHash>,
}

/// Struct that protects an invariant of having non-empty list of listen infos.
Expand Down
2 changes: 0 additions & 2 deletions rust/tests/integration/webrtc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ fn create_webrtc_server_succeeds() {
);
assert_eq!(dump.webrtc_transport_ids, HashedSet::default());
assert_eq!(dump.local_ice_username_fragments, vec![]);
assert_eq!(dump.tuple_hashes, vec![]);
});
}

Expand Down Expand Up @@ -209,7 +208,6 @@ fn create_webrtc_server_without_specifying_port_succeeds() {

assert_eq!(dump.webrtc_transport_ids, HashedSet::default());
assert_eq!(dump.local_ice_username_fragments, vec![]);
assert_eq!(dump.tuple_hashes, vec![]);
});
}

Expand Down
6 changes: 0 additions & 6 deletions worker/fbs/webRtcServer.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ table IceUserNameFragment {
web_rtc_transport_id: string (required);
}

table TupleHash {
tuple_hash: uint64;
web_rtc_transport_id: string (required);
}

table DumpResponse {
id: string (required);
udp_sockets: [IpPort] (required);
tcp_servers: [IpPort] (required);
web_rtc_transport_ids: [string] (required);
local_ice_username_fragments: [IceUserNameFragment] (required);
tuple_hashes: [TupleHash] (required);
}

78 changes: 66 additions & 12 deletions worker/include/RTC/TransportTuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,55 @@ namespace RTC
TCP = 2
};

class TupleKey
{
private:
friend class TransportTuple;
friend class TupleKeyHash;

public:
TupleKey(Protocol protocol, const struct sockaddr* localAddr, const struct sockaddr* remoteAddr)
: protocol(protocol)
{
this->localAddr = Utils::IP::CopyAddress(localAddr);
this->remoteAddr = Utils::IP::CopyAddress(remoteAddr);
};

bool operator==(const TupleKey& other) const noexcept;
bool operator!=(const TupleKey& other) const noexcept
{
return !(*this == other);
};

private:
Protocol protocol{ Protocol::UDP };
sockaddr_storage localAddr;
sockaddr_storage remoteAddr;
};

struct TupleKeyHash
{
size_t operator()(const TupleKey& key) const noexcept;
};

static Protocol ProtocolFromFbs(FBS::Transport::Protocol protocol);
static FBS::Transport::Protocol ProtocolToFbs(Protocol protocol);
static uint64_t GenerateFnv1aHash(const uint8_t* data, size_t size);

public:
TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr)
: udpSocket(udpSocket),
udpRemoteAddr(const_cast<struct sockaddr*>(udpRemoteAddr)),
protocol(Protocol::UDP)
{
GenerateHash();
}

explicit TransportTuple(RTC::TcpConnection* tcpConnection)
: tcpConnection(tcpConnection), protocol(Protocol::TCP)
{
GenerateHash();
}

explicit TransportTuple(const TransportTuple* tuple)
: hash(tuple->hash),
udpSocket(tuple->udpSocket),
: udpSocket(tuple->udpSocket),
udpRemoteAddr(tuple->udpRemoteAddr),
tcpConnection(tuple->tcpConnection),
localAnnouncedAddress(tuple->localAnnouncedAddress),
Expand Down Expand Up @@ -74,7 +101,26 @@ namespace RTC

bool Compare(const TransportTuple* tuple) const
{
return this->hash == tuple->hash;
if (this->protocol != tuple->protocol)
{
return false;
}

switch (this->protocol)
{
case Protocol::UDP:
{
return (
this->udpSocket == tuple->udpSocket &&
Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->udpRemoteAddr));
}
case Protocol::TCP:
{
return (this->tcpConnection == tuple->tcpConnection);
}
}

return true;
Comment thread
penguinol marked this conversation as resolved.
}

void SetLocalAnnouncedAddress(std::string& localAnnouncedAddress)
Expand Down Expand Up @@ -147,12 +193,20 @@ namespace RTC
}
}

private:
void SetHash();
void GenerateHash();

public:
uint64_t hash{ 0u };
TupleKey GetTupleKey() const
{
if (this->protocol == Protocol::UDP)
{
return TupleKey(this->protocol, this->udpSocket->GetLocalAddress(), this->udpRemoteAddr);
}
else
{
return TupleKey(
this->protocol,
this->tcpConnection->GetLocalAddress(),
this->tcpConnection->GetPeerAddress());
}
}

private:
// Passed by argument.
Expand Down
4 changes: 3 additions & 1 deletion worker/include/RTC/WebRtcServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "RTC/UdpSocket.hpp"
#include "RTC/WebRtcTransport.hpp"
#include "SharedInterface.hpp"
#include "TransportTuple.hpp"
#include <flatbuffers/flatbuffers.h>
#include <ankerl/unordered_dense.h>
#include <string>
Expand Down Expand Up @@ -119,7 +120,8 @@ namespace RTC
// Map of WebRtcTransports indexed by local ICE usernameFragment.
ankerl::unordered_dense::map<std::string, RTC::WebRtcTransport*> mapLocalIceUsernameFragmentWebRtcTransport;
// Map of WebRtcTransports indexed by TransportTuple.hash.
ankerl::unordered_dense::map<uint64_t, RTC::WebRtcTransport*> mapTupleWebRtcTransport;
ankerl::unordered_dense::map<TransportTuple::TupleKey, RTC::WebRtcTransport*, TransportTuple::TupleKeyHash>
mapTupleWebRtcTransport;
// Whether the destructor has been called.
bool closing{ false };
};
Expand Down
10 changes: 10 additions & 0 deletions worker/include/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,16 @@ namespace Utils
uint32_t offset{ 0 };
};

class Hash
{
public:
static void Combine(size_t& seed, size_t value)
{
// The implementation is the same as boost::hash_combine().
seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
};
};
Comment thread
penguinol marked this conversation as resolved.

} // namespace Utils

#endif
Loading
Loading