| Index: webrtc/p2p/base/port.cc
|
| diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc
|
| index b08cc4c91039f8149fac115a17e70f70236698ff..95fae737005590a75e476a4ffcdd477dcaa4631a 100644
|
| --- a/webrtc/p2p/base/port.cc
|
| +++ b/webrtc/p2p/base/port.cc
|
| @@ -270,8 +270,18 @@ void Port::AddAddress(const rtc::SocketAddress& address,
|
| }
|
| }
|
|
|
| -void Port::AddConnection(Connection* conn) {
|
| - connections_[conn->remote_candidate().address()] = conn;
|
| +void Port::AddOrReplaceConnection(Connection* conn) {
|
| + auto ret = connections_.insert(
|
| + std::make_pair(conn->remote_candidate().address(), conn));
|
| + // If there is a different connection on the same remote address, replace
|
| + // it with the new one and destroy the old one.
|
| + if (ret.second == false && ret.first->second != conn) {
|
| + LOG_J(LS_WARNING, this)
|
| + << "A new connection was created on an existing remote address. "
|
| + << "New remote candidate: " << conn->remote_candidate().ToString();
|
| + ret.first->second->Destroy();
|
| + ret.first->second = conn;
|
| + }
|
| conn->SignalDestroyed.connect(this, &Port::OnConnectionDestroyed);
|
| SignalConnectionCreated(this, conn);
|
| }
|
| @@ -687,7 +697,12 @@ void Port::OnConnectionDestroyed(Connection* conn) {
|
| AddressMap::iterator iter =
|
| connections_.find(conn->remote_candidate().address());
|
| ASSERT(iter != connections_.end());
|
| + if (iter->second != conn) {
|
| + // If the deleted connection is different than what we have now, ignore it.
|
| + return;
|
| + }
|
| connections_.erase(iter);
|
| + HandleConnectionDestroyed(conn);
|
|
|
| // On the controlled side, ports time out after all connections fail.
|
| // Note: If a new connection is added after this message is posted, but it
|
|
|