diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index 54684516e3..8023659358 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc @@ -1206,6 +1206,12 @@ bool TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr, return CreateOrRefreshEntry(addr, channel_number, ""); } +bool TurnPort::CreateOrRefreshEntry(Connection* conn, int channel_number) { + return CreateOrRefreshEntry(conn->remote_candidate().address(), + channel_number, + conn->remote_candidate().username()); +} + bool TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr, int channel_number, absl::string_view remote_ufrag) { @@ -1214,33 +1220,34 @@ bool TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr, entry = new TurnEntry(this, channel_number, addr, remote_ufrag); entries_.push_back(entry); return true; - } else { - if (entry->destruction_timestamp()) { - // Destruction should have only been scheduled (indicated by - // destruction_timestamp being set) if there were no connections using - // this address. - RTC_DCHECK(!GetConnection(addr)); - // Resetting the destruction timestamp will ensure that any queued - // destruction tasks, when executed, will see that the timestamp doesn't - // match and do nothing. We do this because (currently) there's not a - // convenient way to cancel queued tasks. - entry->reset_destruction_timestamp(); - } else { - // The only valid reason for destruction not being scheduled is that - // there's still one connection. - RTC_DCHECK(GetConnection(addr)); - } + } - if (field_trials().IsEnabled("WebRTC-TurnAddMultiMapping")) { - if (entry->get_remote_ufrag() != remote_ufrag) { - RTC_LOG(LS_INFO) << ToString() - << ": remote ufrag updated." - " Sending new permission request"; - entry->set_remote_ufrag(remote_ufrag); - entry->SendCreatePermissionRequest(0); - } + if (entry->destruction_timestamp()) { + // Destruction should have only been scheduled (indicated by + // destruction_timestamp being set) if there were no connections using + // this address. + RTC_DCHECK(!GetConnection(addr)); + // Resetting the destruction timestamp will ensure that any queued + // destruction tasks, when executed, will see that the timestamp doesn't + // match and do nothing. We do this because (currently) there's not a + // convenient way to cancel queued tasks. + entry->reset_destruction_timestamp(); + } else { + // The only valid reason for destruction not being scheduled is that + // there's still one connection. + RTC_DCHECK(GetConnection(addr)); + } + + if (field_trials().IsEnabled("WebRTC-TurnAddMultiMapping")) { + if (entry->get_remote_ufrag() != remote_ufrag) { + RTC_LOG(LS_INFO) << ToString() + << ": remote ufrag updated." + " Sending new permission request"; + entry->set_remote_ufrag(remote_ufrag); + entry->SendCreatePermissionRequest(0); } } + return false; } diff --git a/p2p/base/turn_port.h b/p2p/base/turn_port.h index e51468770a..50d78ced61 100644 --- a/p2p/base/turn_port.h +++ b/p2p/base/turn_port.h @@ -231,7 +231,10 @@ class TurnPort : public Port { // NOTE: This method needs to be accessible for StunPort // return true if entry was created (i.e channel_number consumed). + // TODO(tommi): Remove this method in favor of the one that accepts a + // `Connection` pointer. bool CreateOrRefreshEntry(const rtc::SocketAddress& addr, int channel_number); + bool CreateOrRefreshEntry(Connection* conn, int channel_number); bool CreateOrRefreshEntry(const rtc::SocketAddress& addr, int channel_number,