提交 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
// Others.
std::string usernameFragment;
std::string password;
std::string oldUsernameFragment;
std::string oldPassword;
IceState state{ IceState::NEW };
std::list<RTC::TransportTuple> tuples;
RTC::TransportTuple* selectedTuple{ nullptr };
......@@ -95,12 +97,14 @@ namespace RTC
inline void IceServer::SetUsernameFragment(const std::string& usernameFragment)
{
this->usernameFragment = usernameFragment;
this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment;
}
inline void IceServer::SetPassword(const std::string& password)
{
this->password = password;
this->oldPassword = this->password;
this->password = password;
}
inline IceServer::IceState IceServer::GetState() const
......
......@@ -19,12 +19,6 @@ namespace RTC
: listener(listener), usernameFragment(usernameFragment), password(password)
{
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)
......@@ -104,10 +98,35 @@ namespace RTC
switch (msg->CheckAuthentication(this->usernameFragment, this->password))
{
case RTC::StunMessage::Authentication::OK:
{
if (!this->oldPassword.empty())
{
MS_DEBUG_TAG(ice, "new ICE credentials applied");
this->oldUsernameFragment.clear();
this->oldPassword.clear();
}
break;
}
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");
// Reply 401.
......@@ -167,7 +186,10 @@ namespace RTC
response->SetXorMappedAddress(tuple->GetRemoteAddress());
// Authenticate the response.
response->Authenticate(this->password);
if (this->oldPassword.empty())
response->Authenticate(this->password);
else
response->Authenticate(this->oldPassword);
// Send back.
response->Serialize(StunSerializeBuffer);
......
......@@ -1397,7 +1397,7 @@ namespace RTC
// Update the selected tuple.
this->iceSelectedTuple = tuple;
MS_DEBUG_TAG(ice, "ICE elected tuple");
MS_DEBUG_TAG(ice, "ICE selected tuple");
// Notify the Node WebRtcTransport.
json data = json::object();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论