Unverified 提交 c693e224 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

ICE renomination support (#756)

上级 55c6015e
...@@ -61,15 +61,15 @@ namespace RTC ...@@ -61,15 +61,15 @@ namespace RTC
{ {
return this->selectedTuple; return this->selectedTuple;
} }
void SetUsernameFragment(const std::string& usernameFragment) void RestartIce(const std::string& usernameFragment, const std::string& password)
{ {
this->oldUsernameFragment = this->usernameFragment; this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment; this->usernameFragment = usernameFragment;
}
void SetPassword(const std::string& password)
{
this->oldPassword = this->password; this->oldPassword = this->password;
this->password = password; this->password = password;
this->remoteNomination = 0u;
} }
bool IsValidTuple(const RTC::TransportTuple* tuple) const; bool IsValidTuple(const RTC::TransportTuple* tuple) const;
void RemoveTuple(RTC::TransportTuple* tuple); void RemoveTuple(RTC::TransportTuple* tuple);
...@@ -78,7 +78,8 @@ namespace RTC ...@@ -78,7 +78,8 @@ namespace RTC
void ForceSelectedTuple(const RTC::TransportTuple* tuple); void ForceSelectedTuple(const RTC::TransportTuple* tuple);
private: private:
void HandleTuple(RTC::TransportTuple* tuple, bool hasUseCandidate); void HandleTuple(
RTC::TransportTuple* tuple, bool hasUseCandidate, bool hasNomination, uint32_t nomination);
/** /**
* Store the given tuple and return its stored address. * Store the given tuple and return its stored address.
*/ */
...@@ -101,6 +102,7 @@ namespace RTC ...@@ -101,6 +102,7 @@ namespace RTC
std::string password; std::string password;
std::string oldUsernameFragment; std::string oldUsernameFragment;
std::string oldPassword; std::string oldPassword;
uint32_t remoteNomination{ 0u };
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 };
......
...@@ -41,7 +41,8 @@ namespace RTC ...@@ -41,7 +41,8 @@ namespace RTC
ALTERNATE_SERVER = 0x8023, ALTERNATE_SERVER = 0x8023,
FINGERPRINT = 0x8028, FINGERPRINT = 0x8028,
ICE_CONTROLLED = 0x8029, ICE_CONTROLLED = 0x8029,
ICE_CONTROLLING = 0x802A ICE_CONTROLLING = 0x802A,
NOMINATION = 0xC001
}; };
// Authentication result. // Authentication result.
...@@ -114,6 +115,10 @@ namespace RTC ...@@ -114,6 +115,10 @@ namespace RTC
{ {
this->hasUseCandidate = true; this->hasUseCandidate = true;
} }
void SetNomination(uint32_t nomination)
{
this->nomination = nomination;
}
void SetXorMappedAddress(const struct sockaddr* xorMappedAddress) void SetXorMappedAddress(const struct sockaddr* xorMappedAddress)
{ {
this->xorMappedAddress = xorMappedAddress; this->xorMappedAddress = xorMappedAddress;
...@@ -150,6 +155,18 @@ namespace RTC ...@@ -150,6 +155,18 @@ namespace RTC
{ {
return this->hasUseCandidate; return this->hasUseCandidate;
} }
void SetHasNomination()
{
this->hasNomination = true;
}
bool HasNomination() const
{
return this->hasNomination;
}
uint32_t GetNomination() const
{
return this->nomination;
}
uint16_t GetErrorCode() const uint16_t GetErrorCode() const
{ {
return this->errorCode; return this->errorCode;
...@@ -181,6 +198,8 @@ namespace RTC ...@@ -181,6 +198,8 @@ namespace RTC
uint32_t priority{ 0u }; // 4 bytes unsigned integer. uint32_t priority{ 0u }; // 4 bytes unsigned integer.
uint64_t iceControlling{ 0u }; // 8 bytes unsigned integer. uint64_t iceControlling{ 0u }; // 8 bytes unsigned integer.
uint64_t iceControlled{ 0u }; // 8 bytes unsigned integer. uint64_t iceControlled{ 0u }; // 8 bytes unsigned integer.
bool hasNomination{ false };
uint32_t nomination{ 0u }; // 4 bytes unsigned integer.
bool hasUseCandidate{ false }; // 0 bytes. bool hasUseCandidate{ false }; // 0 bytes.
const uint8_t* messageIntegrity{ nullptr }; // 20 bytes. const uint8_t* messageIntegrity{ nullptr }; // 20 bytes.
bool hasFingerprint{ false }; // 4 bytes. bool hasFingerprint{ false }; // 4 bytes.
......
...@@ -198,8 +198,13 @@ namespace RTC ...@@ -198,8 +198,13 @@ namespace RTC
delete response; delete response;
uint32_t nomination{ 0u };
if (packet->HasNomination())
nomination = packet->GetNomination();
// Handle the tuple. // Handle the tuple.
HandleTuple(tuple, packet->HasUseCandidate()); HandleTuple(tuple, packet->HasUseCandidate(), packet->HasNomination(), nomination);
break; break;
} }
...@@ -301,7 +306,8 @@ namespace RTC ...@@ -301,7 +306,8 @@ namespace RTC
SetSelectedTuple(storedTuple); SetSelectedTuple(storedTuple);
} }
void IceServer::HandleTuple(RTC::TransportTuple* tuple, bool hasUseCandidate) void IceServer::HandleTuple(
RTC::TransportTuple* tuple, bool hasUseCandidate, bool hasNomination, uint32_t nomination)
{ {
MS_TRACE(); MS_TRACE();
...@@ -316,9 +322,15 @@ namespace RTC ...@@ -316,9 +322,15 @@ namespace RTC
// There shouldn't be a selected tuple. // There shouldn't be a selected tuple.
MS_ASSERT(!this->selectedTuple, "state is 'new' but there is selected tuple"); MS_ASSERT(!this->selectedTuple, "state is 'new' but there is selected tuple");
if (!hasUseCandidate) if (!hasUseCandidate && !hasNomination)
{ {
MS_DEBUG_TAG(ice, "transition from state 'new' to 'connected'"); MS_DEBUG_TAG(
ice,
"transition from state 'new' to 'connected' [hasUseCandidate:%s, hasNomination:%s, nomination:%" PRIu32
"]",
hasUseCandidate ? "true" : "false",
hasNomination ? "true" : "false",
nomination);
// Store the tuple. // Store the tuple.
auto* storedTuple = AddTuple(tuple); auto* storedTuple = AddTuple(tuple);
...@@ -332,18 +344,30 @@ namespace RTC ...@@ -332,18 +344,30 @@ namespace RTC
} }
else else
{ {
MS_DEBUG_TAG(ice, "transition from state 'new' to 'completed'");
// Store the tuple. // Store the tuple.
auto* storedTuple = AddTuple(tuple); auto* storedTuple = AddTuple(tuple);
if ((hasNomination && nomination > this->remoteNomination) || !hasNomination)
{
MS_DEBUG_TAG(
ice,
"transition from state 'new' to 'completed' [hasUseCandidate:%s, hasNomination:%s, nomination:%" PRIu32
"]",
hasUseCandidate ? "true" : "false",
hasNomination ? "true" : "false",
nomination);
// Mark it as selected tuple. // Mark it as selected tuple.
SetSelectedTuple(storedTuple); SetSelectedTuple(storedTuple);
// Update state. // Update state.
this->state = IceState::COMPLETED; this->state = IceState::COMPLETED;
// Update nomination.
if (hasNomination && nomination > this->remoteNomination)
this->remoteNomination = nomination;
// Notify the listener. // Notify the listener.
this->listener->OnIceServerCompleted(this); this->listener->OnIceServerCompleted(this);
} }
}
break; break;
} }
...@@ -359,9 +383,15 @@ namespace RTC ...@@ -359,9 +383,15 @@ namespace RTC
// There shouldn't be a selected tuple. // There shouldn't be a selected tuple.
MS_ASSERT(!this->selectedTuple, "state is 'disconnected' but there is selected tuple"); MS_ASSERT(!this->selectedTuple, "state is 'disconnected' but there is selected tuple");
if (!hasUseCandidate) if (!hasUseCandidate && !hasNomination)
{ {
MS_DEBUG_TAG(ice, "transition from state 'disconnected' to 'connected'"); MS_DEBUG_TAG(
ice,
"transition from state 'disconnected' to 'connected' [hasUseCandidate:%s, hasNomination:%s, nomination:%" PRIu32
"]",
hasUseCandidate ? "true" : "false",
hasNomination ? "true" : "false",
nomination);
// Store the tuple. // Store the tuple.
auto* storedTuple = AddTuple(tuple); auto* storedTuple = AddTuple(tuple);
...@@ -375,18 +405,30 @@ namespace RTC ...@@ -375,18 +405,30 @@ namespace RTC
} }
else else
{ {
MS_DEBUG_TAG(ice, "transition from state 'disconnected' to 'completed'");
// Store the tuple. // Store the tuple.
auto* storedTuple = AddTuple(tuple); auto* storedTuple = AddTuple(tuple);
if ((hasNomination && nomination > this->remoteNomination) || !hasNomination)
{
MS_DEBUG_TAG(
ice,
"transition from state 'disconnected' to 'completed' [hasUseCandidate:%s, hasNomination:%s, nomination:%" PRIu32
"]",
hasUseCandidate ? "true" : "false",
hasNomination ? "true" : "false",
nomination);
// Mark it as selected tuple. // Mark it as selected tuple.
SetSelectedTuple(storedTuple); SetSelectedTuple(storedTuple);
// Update state. // Update state.
this->state = IceState::COMPLETED; this->state = IceState::COMPLETED;
// Update nomination.
if (hasNomination && nomination > this->remoteNomination)
this->remoteNomination = nomination;
// Notify the listener. // Notify the listener.
this->listener->OnIceServerCompleted(this); this->listener->OnIceServerCompleted(this);
} }
}
break; break;
} }
...@@ -399,7 +441,7 @@ namespace RTC ...@@ -399,7 +441,7 @@ namespace RTC
// There should be a selected tuple. // There should be a selected tuple.
MS_ASSERT(this->selectedTuple, "state is 'connected' but there is not selected tuple"); MS_ASSERT(this->selectedTuple, "state is 'connected' but there is not selected tuple");
if (!hasUseCandidate) if (!hasUseCandidate && !hasNomination)
{ {
// If a new tuple store it. // If a new tuple store it.
if (!HasTuple(tuple)) if (!HasTuple(tuple))
...@@ -407,7 +449,13 @@ namespace RTC ...@@ -407,7 +449,13 @@ namespace RTC
} }
else else
{ {
MS_DEBUG_TAG(ice, "transition from state 'connected' to 'completed'"); MS_DEBUG_TAG(
ice,
"transition from state 'connected' to 'completed' [hasUseCandidate:%s, hasNomination:%s, nomination:%" PRIu32
"]",
hasUseCandidate ? "true" : "false",
hasNomination ? "true" : "false",
nomination);
auto* storedTuple = HasTuple(tuple); auto* storedTuple = HasTuple(tuple);
...@@ -415,13 +463,19 @@ namespace RTC ...@@ -415,13 +463,19 @@ namespace RTC
if (!storedTuple) if (!storedTuple)
storedTuple = AddTuple(tuple); storedTuple = AddTuple(tuple);
if ((hasNomination && nomination > this->remoteNomination) || !hasNomination)
{
// Mark it as selected tuple. // Mark it as selected tuple.
SetSelectedTuple(storedTuple); SetSelectedTuple(storedTuple);
// Update state. // Update state.
this->state = IceState::COMPLETED; this->state = IceState::COMPLETED;
// Update nomination.
if (hasNomination && nomination > this->remoteNomination)
this->remoteNomination = nomination;
// Notify the listener. // Notify the listener.
this->listener->OnIceServerCompleted(this); this->listener->OnIceServerCompleted(this);
} }
}
break; break;
} }
...@@ -434,7 +488,7 @@ namespace RTC ...@@ -434,7 +488,7 @@ namespace RTC
// There should be a selected tuple. // There should be a selected tuple.
MS_ASSERT(this->selectedTuple, "state is 'completed' but there is not selected tuple"); MS_ASSERT(this->selectedTuple, "state is 'completed' but there is not selected tuple");
if (!hasUseCandidate) if (!hasUseCandidate && !hasNomination)
{ {
// If a new tuple store it. // If a new tuple store it.
if (!HasTuple(tuple)) if (!HasTuple(tuple))
...@@ -448,8 +502,14 @@ namespace RTC ...@@ -448,8 +502,14 @@ namespace RTC
if (!storedTuple) if (!storedTuple)
storedTuple = AddTuple(tuple); storedTuple = AddTuple(tuple);
if ((hasNomination && nomination > this->remoteNomination) || !hasNomination)
{
// Mark it as selected tuple. // Mark it as selected tuple.
SetSelectedTuple(storedTuple); SetSelectedTuple(storedTuple);
// Update nomination.
if (hasNomination && nomination > this->remoteNomination)
this->remoteNomination = nomination;
}
} }
break; break;
......
...@@ -209,6 +209,23 @@ namespace RTC ...@@ -209,6 +209,23 @@ namespace RTC
break; break;
} }
case Attribute::NOMINATION:
{
// Ensure attribute length is 4 bytes.
if (attrLength != 4)
{
MS_WARN_TAG(ice, "attribute NOMINATION must be 4 bytes length, packet discarded");
delete packet;
return nullptr;
}
packet->SetHasNomination();
packet->SetNomination(Utils::Byte::Get4Bytes(attrValuePos, 0));
break;
}
case Attribute::MESSAGE_INTEGRITY: case Attribute::MESSAGE_INTEGRITY:
{ {
// Ensure attribute length is 20 bytes. // Ensure attribute length is 20 bytes.
......
...@@ -585,8 +585,7 @@ namespace RTC ...@@ -585,8 +585,7 @@ namespace RTC
std::string usernameFragment = Utils::Crypto::GetRandomString(16); std::string usernameFragment = Utils::Crypto::GetRandomString(16);
std::string password = Utils::Crypto::GetRandomString(32); std::string password = Utils::Crypto::GetRandomString(32);
this->iceServer->SetUsernameFragment(usernameFragment); this->iceServer->RestartIce(usernameFragment, password);
this->iceServer->SetPassword(password);
MS_DEBUG_DEV( MS_DEBUG_DEV(
"WebRtcTransport ICE usernameFragment and password changed [id:%s]", this->id.c_str()); "WebRtcTransport ICE usernameFragment and password changed [id:%s]", this->id.c_str());
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论