提交 84218eba authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

ICE restart: keep previous usernameFragment and password until client uses the new ones

上级 7a6e7557
...@@ -76,6 +76,8 @@ namespace RTC ...@@ -76,6 +76,8 @@ namespace RTC
// Others. // Others.
std::string usernameFragment; std::string usernameFragment;
std::string password; std::string password;
std::string oldUsernameFragment;
std::string oldPassword;
IceState state{ IceState::NEW }; IceState state{ IceState::NEW };
std::list<RTC::TransportTuple> tuples; std::list<RTC::TransportTuple> tuples;
RTC::TransportTuple* selectedTuple{ nullptr }; RTC::TransportTuple* selectedTuple{ nullptr };
...@@ -95,11 +97,13 @@ namespace RTC ...@@ -95,11 +97,13 @@ namespace RTC
inline void IceServer::SetUsernameFragment(const std::string& usernameFragment) inline void IceServer::SetUsernameFragment(const std::string& usernameFragment)
{ {
this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment; this->usernameFragment = usernameFragment;
} }
inline void IceServer::SetPassword(const std::string& password) inline void IceServer::SetPassword(const std::string& password)
{ {
this->oldPassword = this->password;
this->password = password; this->password = password;
} }
......
...@@ -19,12 +19,6 @@ namespace RTC ...@@ -19,12 +19,6 @@ namespace RTC
: listener(listener), usernameFragment(usernameFragment), password(password) : listener(listener), usernameFragment(usernameFragment), password(password)
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_TAG(
ice,
"[usernameFragment:%s, password:%s]",
this->usernameFragment.c_str(),
this->password.c_str());
} }
void IceServer::ProcessStunMessage(RTC::StunMessage* msg, RTC::TransportTuple* tuple) void IceServer::ProcessStunMessage(RTC::StunMessage* msg, RTC::TransportTuple* tuple)
...@@ -104,10 +98,35 @@ namespace RTC ...@@ -104,10 +98,35 @@ namespace RTC
switch (msg->CheckAuthentication(this->usernameFragment, this->password)) switch (msg->CheckAuthentication(this->usernameFragment, this->password))
{ {
case RTC::StunMessage::Authentication::OK: case RTC::StunMessage::Authentication::OK:
{
if (!this->oldPassword.empty())
{
MS_DEBUG_TAG(ice, "new ICE credentials applied");
this->oldUsernameFragment.clear();
this->oldPassword.clear();
}
break; break;
}
case RTC::StunMessage::Authentication::UNAUTHORIZED: case RTC::StunMessage::Authentication::UNAUTHORIZED:
{ {
// We may have changed our usernameFragment and password, so check
// the old ones.
// clang-format off
if (
!this->oldUsernameFragment.empty() &&
!this->oldPassword.empty() &&
msg->CheckAuthentication(this->oldUsernameFragment, this->oldPassword) == RTC::StunMessage::Authentication::OK
)
// clang-format on
{
MS_DEBUG_TAG(ice, "using old ICE credentials");
break;
}
MS_WARN_TAG(ice, "wrong authentication in STUN Binding Request => 401"); MS_WARN_TAG(ice, "wrong authentication in STUN Binding Request => 401");
// Reply 401. // Reply 401.
...@@ -167,7 +186,10 @@ namespace RTC ...@@ -167,7 +186,10 @@ namespace RTC
response->SetXorMappedAddress(tuple->GetRemoteAddress()); response->SetXorMappedAddress(tuple->GetRemoteAddress());
// Authenticate the response. // Authenticate the response.
if (this->oldPassword.empty())
response->Authenticate(this->password); response->Authenticate(this->password);
else
response->Authenticate(this->oldPassword);
// Send back. // Send back.
response->Serialize(StunSerializeBuffer); response->Serialize(StunSerializeBuffer);
......
...@@ -1397,7 +1397,7 @@ namespace RTC ...@@ -1397,7 +1397,7 @@ namespace RTC
// Update the selected tuple. // Update the selected tuple.
this->iceSelectedTuple = tuple; this->iceSelectedTuple = tuple;
MS_DEBUG_TAG(ice, "ICE elected tuple"); MS_DEBUG_TAG(ice, "ICE selected tuple");
// Notify the Node WebRtcTransport. // Notify the Node WebRtcTransport.
json data = json::object(); json data = json::object();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论