Skip to content

Commit 4e0a5d8

Browse files
committed
chore: pr comments
1 parent 9157c0c commit 4e0a5d8

File tree

3 files changed

+22
-49
lines changed

3 files changed

+22
-49
lines changed

include/rtc/global.hpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ RTC_CPP_EXPORT void InitLogger(LogLevel level, LogCallback callback = nullptr);
3434
RTC_CPP_EXPORT void Preload();
3535
RTC_CPP_EXPORT std::shared_future<void> Cleanup();
3636

37-
struct UnhandledStunRequest {
37+
struct IceUdpMuxRequest {
3838
std::string localUfrag;
3939
std::string remoteUfrag;
4040
std::string remoteHost;
4141
uint16_t remotePort;
4242
};
4343

44-
RTC_CPP_EXPORT typedef std::function<void(UnhandledStunRequest request, void* userPtr)> UnhandledStunRequestCallback;
44+
RTC_CPP_EXPORT typedef std::function<void(IceUdpMuxRequest request)> IceUdpMuxCallback;
4545

46-
struct UnhandledStunRequestHandler {
47-
UnhandledStunRequestCallback callback;
48-
void *userPtr;
49-
};
50-
51-
RTC_CPP_EXPORT void OnUnhandledStunRequest(std::string host, int port, UnhandledStunRequestCallback callback = nullptr, void *userPtr = nullptr);
46+
RTC_CPP_EXPORT void ListenIceUdpMux (int port, IceUdpMuxCallback *callback, std::optional<std::string> bindAddress = nullptr);
5247

5348
struct SctpSettings {
5449
// For the following settings, not set means optimized default

include/rtc/rtc.h

-14
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,6 @@ typedef void(RTC_API *rtcAvailableCallbackFunc)(int id, void *ptr);
172172
typedef void(RTC_API *rtcPliHandlerCallbackFunc)(int tr, void *ptr);
173173
typedef void(RTC_API *rtcRembHandlerCallbackFunc)(int tr, unsigned int bitrate, void *ptr);
174174

175-
// Handle STUN requests with unexpected ufrags
176-
177-
typedef struct {
178-
const char * ufrag;
179-
const char * pwd;
180-
uint8_t family;
181-
const char * address;
182-
uint16_t port;
183-
} rtcUnhandledStunRequest;
184-
185-
typedef void(RTC_API *rtcUnhandledStunRequestCallbackFunc)(rtcUnhandledStunRequest request);
186-
187-
RTC_C_EXPORT void rtcOnUnhandledStunRequest(const char *host, int port, rtcUnhandledStunRequestCallbackFunc callback);
188-
189175
// Log
190176

191177
// NULL cb on the first call will log to stdout

src/global.cpp

+19-27
Original file line numberDiff line numberDiff line change
@@ -93,57 +93,49 @@ std::shared_future<void> Cleanup() { return impl::Init::Instance().cleanup(); }
9393

9494
void SetSctpSettings(SctpSettings s) { impl::Init::Instance().setSctpSettings(std::move(s)); }
9595

96-
std::map<int, UnhandledStunRequestHandler *> unboundStunCallbacks;
97-
9896
#if !USE_NICE
9997

100-
void InvokeUnhandledStunRequestCallback (const juice_mux_binding_request *info, void *user_ptr) {
101-
PLOG_DEBUG << "Invoking unhandled STUN request callback";
98+
void InvokeIceUdpMuxCallback (const juice_mux_binding_request *info, void *user_ptr) {
99+
PLOG_DEBUG << "Invoking ICE UDP mux callback";
102100

103-
UnhandledStunRequestHandler *handler = (struct UnhandledStunRequestHandler*)user_ptr;
101+
IceUdpMuxCallback *callback = (IceUdpMuxCallback*)user_ptr;
104102

105-
if (handler->callback) {
106-
handler->callback({
103+
if (callback) {
104+
(*callback)({
107105
std::string(info->local_ufrag),
108106
std::string(info->remote_ufrag),
109107
std::string(info->address),
110108
info->port
111-
}, handler->userPtr);
109+
});
112110
} else {
113-
PLOG_DEBUG << "No unhandled STUN request callback configured for port " << info->port;
111+
PLOG_DEBUG << "No ICE UDP mux callback configured for port " << info->port;
114112
}
115113
}
116114

117115
#endif
118116

119-
void OnUnhandledStunRequest ([[maybe_unused]] std::string host, [[maybe_unused]] int port, [[maybe_unused]] UnhandledStunRequestCallback callback, [[maybe_unused]] void *userPtr) {
117+
void ListenIceUdpMux ([[maybe_unused]] int port, [[maybe_unused]] IceUdpMuxCallback *callback, [[maybe_unused]] std::optional<std::string> bindAddress) {
120118
#if USE_NICE
121-
PLOG_WARNING << "BindStunListener is not supported with libnice, please use libjuice";
119+
PLOG_WARNING << "ListenIceUdpMux is not supported with libnice, please use libjuice";
122120
#else
123-
if (callback == NULL) {
124-
PLOG_DEBUG << "Removing unhandled STUN request listener";
121+
// NULL host binds to all available addresses
122+
const char *host = bindAddress.has_value() ? bindAddress.value().c_str() : NULL;
125123

126-
free(unboundStunCallbacks.at(port));
127-
unboundStunCallbacks.erase(port);
124+
if (callback == NULL) {
125+
PLOG_DEBUG << "Removing ICE UDP mux callback for port " << port;
128126

129-
// call with NULL callback to unbind
130-
if (juice_mux_listen(host.c_str(), port, NULL, NULL) < 0) {
131-
throw std::runtime_error("Could not unbind STUN listener");
127+
// call with NULL callback to remove the listener for the host/port
128+
if (juice_mux_listen(host, port, NULL, NULL) < 0) {
129+
throw std::runtime_error("Could not remove ICE UDP mux callback");
132130
}
133131

134132
return;
135133
}
136134

137-
PLOG_DEBUG << "Adding listener for unhandled STUN requests";
138-
139-
UnhandledStunRequestHandler *handler = (UnhandledStunRequestHandler*)calloc(1, sizeof(UnhandledStunRequestHandler));
140-
handler->callback = std::move(callback);
141-
handler->userPtr = userPtr;
142-
143-
unboundStunCallbacks[port] = handler;
135+
PLOG_DEBUG << "Adding ICE UDP mux callback for port " << port;
144136

145-
if (juice_mux_listen(host.c_str(), port, &InvokeUnhandledStunRequestCallback, handler) < 0) {
146-
throw std::invalid_argument("Could not add listener for unhandled STUN requests");
137+
if (juice_mux_listen(host, port, &InvokeIceUdpMuxCallback, callback) < 0) {
138+
throw std::invalid_argument("Could not add ICE UDP mux callback");
147139
}
148140
#endif
149141
}

0 commit comments

Comments
 (0)