-
-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add callback for unhandled STUN requests #1211
Open
achingbrain
wants to merge
7
commits into
paullouisageneau:master
Choose a base branch
from
achingbrain:feat/expose-callback-for-unknown-stun-ufrag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+190
−2
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
311fea0
feat: add callback for unhandled STUN requests
achingbrain 9157c0c
fix: support multiple callbacks for different ports
achingbrain 4e0a5d8
chore: pr comments
achingbrain fcfcc4f
Refactor API into an IceUdpMuxListener object
paullouisageneau b8e5348
Fix warning with libnice
paullouisageneau d15c2cd
chore: whitespace
achingbrain b47bae7
Merge branch 'paullouisageneau:master' into feat/expose-callback-for-…
achingbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule libjuice
updated
9 files
+13 −0 | include/juice/juice.h | |
+8 −4 | src/agent.c | |
+67 −1 | src/conn.c | |
+2 −0 | src/conn.h | |
+34 −8 | src/conn_mux.c | |
+1 −0 | src/conn_mux.h | |
+1 −0 | src/conn_poll.c | |
+1 −0 | src/conn_thread.c | |
+9 −11 | src/juice.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright (c) 2025 Alex Potsides | ||
* Copyright (c) 2025 Paul-Louis Ageneau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef RTC_ICE_UDP_MUX_LISTENER_H | ||
#define RTC_ICE_UDP_MUX_LISTENER_H | ||
|
||
#include "common.hpp" | ||
|
||
namespace rtc { | ||
|
||
namespace impl { | ||
|
||
struct IceUdpMuxListener; | ||
|
||
} // namespace impl | ||
|
||
struct IceUdpMuxRequest { // TODO change name | ||
string localUfrag; | ||
string remoteUfrag; | ||
string remoteAddress; | ||
uint16_t remotePort; | ||
}; | ||
|
||
class RTC_CPP_EXPORT IceUdpMuxListener final : private CheshireCat<impl::IceUdpMuxListener> { | ||
public: | ||
IceUdpMuxListener(uint16_t port, optional<string> bindAddress = nullopt); | ||
~IceUdpMuxListener(); | ||
|
||
void stop(); | ||
|
||
uint16_t port() const; | ||
|
||
void OnUnhandledStunRequest(std::function<void(IceUdpMuxRequest)> callback); | ||
|
||
private: | ||
using CheshireCat<impl::IceUdpMuxListener>::impl; | ||
}; | ||
|
||
} // namespace rtc | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) 2025 Alex Potsides | ||
* Copyright (c) 2025 Paul-Louis Ageneau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "iceudpmuxlistener.hpp" | ||
|
||
#include "impl/iceudpmuxlistener.hpp" | ||
|
||
namespace rtc { | ||
|
||
IceUdpMuxListener::IceUdpMuxListener(uint16_t port, optional<string> bindAddress) | ||
: CheshireCat<impl::IceUdpMuxListener>(port, std::move(bindAddress)) {} | ||
|
||
IceUdpMuxListener::~IceUdpMuxListener() {} | ||
|
||
void IceUdpMuxListener::stop() { impl()->stop(); } | ||
|
||
uint16_t IceUdpMuxListener::port() const { return impl()->port; } | ||
|
||
void IceUdpMuxListener::OnUnhandledStunRequest(std::function<void(IceUdpMuxRequest)> callback) { | ||
impl()->unhandledStunRequestCallback = callback; | ||
} | ||
|
||
} // namespace rtc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2025 Alex Potsides | ||
* Copyright (c) 2025 Paul-Louis Ageneau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "iceudpmuxlistener.hpp" | ||
#include "internals.hpp" | ||
|
||
namespace rtc::impl { | ||
|
||
#if !USE_NICE | ||
void IceUdpMuxListener::UnhandledStunRequestCallback(const juice_mux_binding_request *info, | ||
void *user_ptr) { | ||
auto listener = static_cast<IceUdpMuxListener *>(user_ptr); | ||
if (!listener) | ||
return; | ||
|
||
IceUdpMuxRequest request; | ||
request.localUfrag = info->local_ufrag; | ||
request.remoteUfrag = info->remote_ufrag; | ||
request.remoteAddress = info->address; | ||
request.remotePort = info->port; | ||
listener->unhandledStunRequestCallback(std::move(request)); | ||
} | ||
#endif | ||
|
||
IceUdpMuxListener::IceUdpMuxListener(uint16_t port, [[maybe_unused]] optional<string> bindAddress) : port(port) { | ||
PLOG_VERBOSE << "Creating IceUdpMuxListener"; | ||
|
||
#if !USE_NICE | ||
PLOG_DEBUG << "Registering ICE UDP mux listener for port " << port; | ||
if (juice_mux_listen(bindAddress ? bindAddress->c_str() : NULL, port, | ||
IceUdpMuxListener::UnhandledStunRequestCallback, this) < 0) { | ||
throw std::runtime_error("Failed to register ICE UDP mux listener"); | ||
} | ||
#else | ||
PLOG_WARNING << "ICE UDP mux is not available with libnice"; | ||
#endif | ||
} | ||
|
||
IceUdpMuxListener::~IceUdpMuxListener() { | ||
PLOG_VERBOSE << "Destroying IceUdpMuxListener"; | ||
stop(); | ||
} | ||
|
||
void IceUdpMuxListener::stop() { | ||
if (mStopped.exchange(true)) | ||
return; | ||
|
||
#if !USE_NICE | ||
PLOG_DEBUG << "Unregistering ICE UDP mux listener for port " << port; | ||
if (juice_mux_listen(NULL, port, NULL, NULL) < 0) { | ||
PLOG_ERROR << "Failed to unregister ICE UDP mux listener"; | ||
} | ||
#endif | ||
} | ||
|
||
} // namespace rtc::impl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2025 Alex Potsides | ||
* Copyright (c) 2025 Paul-Louis Ageneau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef RTC_IMPL_ICE_UDP_MUX_LISTENER_H | ||
#define RTC_IMPL_ICE_UDP_MUX_LISTENER_H | ||
|
||
#include "common.hpp" | ||
|
||
#include "rtc/iceudpmuxlistener.hpp" | ||
|
||
#if !USE_NICE | ||
#include <juice/juice.h> | ||
#endif | ||
|
||
#include <atomic> | ||
|
||
namespace rtc::impl { | ||
|
||
struct IceUdpMuxListener final { | ||
IceUdpMuxListener(uint16_t port, optional<string> bindAddress = nullopt); | ||
~IceUdpMuxListener(); | ||
|
||
void stop(); | ||
|
||
const uint16_t port; | ||
synchronized_callback<IceUdpMuxRequest> unhandledStunRequestCallback; | ||
|
||
private: | ||
#if !USE_NICE | ||
static void UnhandledStunRequestCallback(const juice_mux_binding_request *info, void *user_ptr); | ||
#endif | ||
|
||
std::atomic<bool> mStopped; | ||
}; | ||
|
||
} | ||
|
||
#endif | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
RTC_CPP_EXPORT
has been removed here, not sure if that was intentional.