Skip to content

Commit ba33bb8

Browse files
committed
Support set the ice-ufrag and ice-pwd for connectivity check. v5.0.191 (#3837)
Checking the HTTPS API or UDP connectivity for WHIP tests can be difficult. For example, if the UDP port isn't available but the API is fine, OBS only says it can't connect to the server. It's hard to see the HTTPS API response or check if the UDP port is available. This feature lets you set the ice username and password in SRS. You can then send a STUN request using nc and see the response, making it easier to check UDP port connectivity. 1. Use curl to test the WHIP API, including ice-frag and ice-pwd queries. 2. Use nc to send a STUN binding request to test UDP connectivity. 3. If both the API and UDP are working, you should get a STUN response. --------- Co-authored-by: john <[email protected]>
1 parent 3da81e4 commit ba33bb8

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

trunk/doc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77
<a name="v5-changes"></a>
88

99
## SRS 5.0 Changelog
10+
* v5.0, 2023-10-17, Merge [#3837](https://github.com/ossrs/srs/pull/3837): Support set the ice-ufrag and ice-pwd for connectivity check. v5.0.191 (#3837)
1011
* v5.0, 2023-10-17, Merge [#3758](https://github.com/ossrs/srs/pull/3758): Refine docker detect mechenism. v5.0.190 (#3758)
1112
* v5.0, 2023-10-11, Merge [#3827](https://github.com/ossrs/srs/pull/3827): Fix bug for upgrading to OpenSSL 3.0. v5.0.189 (#3827)
1213
* v5.0, 2023-10-10, Merge [#3825](https://github.com/ossrs/srs/pull/3825): SRT: Fix the missing config mss. v5.0.188 (#3825)

trunk/src/app/srs_app_rtc_api.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
#include <deque>
2121
using namespace std;
2222

23+
// To limit the ICE ufrag/username to avoid unknown issue.
24+
#define SRS_ICE_UFRAG_MIN 4
25+
#define SRS_ICE_UFRAG_MAX 32
26+
// STUN/ICE pwd should not be too short, browser will fail with error.
27+
#define SRS_ICE_PWD_MIN 22
28+
// To limit user to use too long password, to cause unknown issue.
29+
#define SRS_ICE_PWD_MAX 32
30+
2331
SrsGoApiRtcPlay::SrsGoApiRtcPlay(SrsRtcServer* server)
2432
{
2533
server_ = server;
@@ -691,15 +699,29 @@ srs_error_t SrsGoApiRtcWhip::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
691699
ruc->req_->stream = stream.empty() ? "livestream" : stream;
692700
ruc->req_->param = r->query();
693701

702+
ruc->req_->ice_ufrag_ = r->query_get("ice-ufrag");
703+
ruc->req_->ice_pwd_ = r->query_get("ice-pwd");
704+
if (!ruc->req_->ice_ufrag_.empty() && (ruc->req_->ice_ufrag_.length() < SRS_ICE_UFRAG_MIN || ruc->req_->ice_ufrag_.length() > SRS_ICE_UFRAG_MAX)) {
705+
return srs_error_new(ERROR_RTC_INVALID_ICE, "Invalid ice-ufrag %s", ruc->req_->ice_ufrag_.c_str());
706+
}
707+
if (!ruc->req_->ice_pwd_.empty() && (ruc->req_->ice_pwd_.length() < SRS_ICE_PWD_MIN || ruc->req_->ice_pwd_.length() > SRS_ICE_PWD_MAX)) {
708+
return srs_error_new(ERROR_RTC_INVALID_ICE, "Invalid ice-pwd %s", ruc->req_->ice_pwd_.c_str());
709+
}
710+
694711
// discovery vhost, resolve the vhost from config
695712
SrsConfDirective* parsed_vhost = _srs_config->get_vhost(ruc->req_->vhost);
696713
if (parsed_vhost) {
697714
ruc->req_->vhost = parsed_vhost->arg0();
698715
}
699716

700-
srs_trace("RTC whip %s %s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s, param=%s",
717+
// For client to specifies whether encrypt by SRTP.
718+
string srtp = r->query_get("encrypt");
719+
string dtls = r->query_get("dtls");
720+
721+
srs_trace("RTC whip %s %s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s, srtp=%s, dtls=%s, ufrag=%s, pwd=%s, param=%s",
701722
action.c_str(), ruc->req_->get_stream_url().c_str(), clientip.c_str(), ruc->req_->app.c_str(), ruc->req_->stream.c_str(),
702-
remote_sdp_str.length(), eip.c_str(), codec.c_str(), ruc->req_->param.c_str()
723+
remote_sdp_str.length(), eip.c_str(), codec.c_str(), srtp.c_str(), dtls.c_str(), ruc->req_->ice_ufrag_.c_str(),
724+
ruc->req_->ice_pwd_.c_str(), ruc->req_->param.c_str()
703725
);
704726

705727
ruc->eip_ = eip;

trunk/src/app/srs_app_rtc_server.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,18 @@ srs_error_t SrsRtcServer::do_create_session(SrsRtcUserConfig* ruc, SrsSdp& local
543543
// All tracks default as inactive, so we must enable them.
544544
session->set_all_tracks_status(req->get_stream_url(), ruc->publish_, true);
545545

546-
std::string local_pwd = srs_random_str(32);
547-
std::string local_ufrag = "";
546+
std::string local_pwd = ruc->req_->ice_pwd_.empty() ? srs_random_str(32) : ruc->req_->ice_pwd_;
547+
std::string local_ufrag = ruc->req_->ice_ufrag_.empty() ? srs_random_str(8) : ruc->req_->ice_ufrag_;
548548
// TODO: FIXME: Rename for a better name, it's not an username.
549549
std::string username = "";
550550
while (true) {
551-
local_ufrag = srs_random_str(8);
552-
553551
username = local_ufrag + ":" + ruc->remote_sdp_.get_ice_ufrag();
554552
if (!_srs_rtc_manager->find_by_name(username)) {
555553
break;
556554
}
555+
556+
// Username conflict, regenerate a new one.
557+
local_ufrag = srs_random_str(8);
557558
}
558559

559560
local_sdp.set_ice_ufrag(local_ufrag);

trunk/src/core/srs_core_version5.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 190
12+
#define VERSION_REVISION 191
1313

1414
#endif

trunk/src/kernel/srs_kernel_error.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@
363363
XX(ERROR_RTC_TCP_PACKET , 5033, "RtcTcpStun", "RTC TCP first packet must be STUN") \
364364
XX(ERROR_RTC_TCP_STUN , 5034, "RtcTcpSession", "RTC TCP packet is invalid for session not found") \
365365
XX(ERROR_RTC_TCP_UNIQUE , 5035, "RtcUnique", "RTC only support one UDP or TCP network") \
366-
XX(ERROR_RTC_INVALID_SESSION , 5036, "RtcInvalidSession", "Invalid request for no RTC session matched")
366+
XX(ERROR_RTC_INVALID_SESSION , 5036, "RtcInvalidSession", "Invalid request for no RTC session matched") \
367+
XX(ERROR_RTC_INVALID_ICE , 5037, "RtcInvalidIce", "Invalid ICE ufrag or pwd")
367368

368369
/**************************************************/
369370
/* SRT protocol error. */

trunk/src/protocol/srs_protocol_rtmp_stack.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ class SrsRequest
424424
std::string param;
425425
// The stream in play/publish
426426
std::string stream;
427+
// User specify the ice-ufrag, the username of ice, for test only.
428+
std::string ice_ufrag_;
429+
// User specify the ice-pwd, the password of ice, for test only.
430+
std::string ice_pwd_;
427431
// For play live stream,
428432
// used to specified the stop when exceed the duration.
429433
// in srs_utime_t.

0 commit comments

Comments
 (0)