diff options
author | wu@webrtc.org <wu@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2014-02-13 23:18:49 +0000 |
---|---|---|
committer | wu@webrtc.org <wu@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2014-02-13 23:18:49 +0000 |
commit | 8a77f5bd83ba9386c19ff92f277c7268c1e9ef4a (patch) | |
tree | bafcaed4f2d4e0a15605b3d305f9a8fee4e6d4d6 /p2p | |
parent | f5b8e7a761959709cf8201685deaf35ed074cb83 (diff) | |
download | talk-8a77f5bd83ba9386c19ff92f277c7268c1e9ef4a.tar.gz |
Update talk to 61538839.
TBR=mallinath
Review URL: https://webrtc-codereview.appspot.com/8669005
git-svn-id: http://webrtc.googlecode.com/svn/trunk/talk@5548 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/base/candidate.h | 28 | ||||
-rw-r--r-- | p2p/base/p2ptransportchannel.cc | 3 | ||||
-rw-r--r-- | p2p/base/p2ptransportchannel_unittest.cc | 5 | ||||
-rw-r--r-- | p2p/base/port.cc | 2 | ||||
-rw-r--r-- | p2p/client/portallocator_unittest.cc | 19 |
5 files changed, 48 insertions, 9 deletions
diff --git a/p2p/base/candidate.h b/p2p/base/candidate.h index 19eed8c..0fa9f0e 100644 --- a/p2p/base/candidate.h +++ b/p2p/base/candidate.h @@ -33,6 +33,7 @@ #include <string> #include <sstream> #include <iomanip> + #include "talk/base/basictypes.h" #include "talk/base/socketaddress.h" #include "talk/p2p/base/constants.h" @@ -163,13 +164,30 @@ class Candidate { return ToStringInternal(true); } - uint32 GetPriority(uint32 type_preference) const { + uint32 GetPriority(uint32 type_preference, + int network_adapter_preference) const { // RFC 5245 - 4.1.2.1. // priority = (2^24)*(type preference) + // (2^8)*(local preference) + // (2^0)*(256 - component ID) + + // |local_preference| length is 2 bytes, 0-65535 inclusive. + // In our implemenation we will partion local_preference into + // 0 1 + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // | NIC Pref | Addr Pref | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // NIC Type - Type of the network adapter e.g. 3G/Wifi/Wired. + // Addr Pref - Address preference value as per RFC 3484. + // local preference is calculated as - NIC Type << 8 | Addr_Pref. + int addr_pref = IPAddressPrecedence(address_.ipaddr()); - return (type_preference << 24) | (addr_pref << 8) | (256 - component_); + int local_preference = (network_adapter_preference << 8) | addr_pref; + + return (type_preference << 24) | + (local_preference << 8) | + (256 - component_); } private: @@ -177,9 +195,9 @@ class Candidate { std::ostringstream ost; std::string address = sensitive ? address_.ToSensitiveString() : address_.ToString(); - ost << "Cand[" << id_ << ":" << component_ << ":" - << type_ << ":" << protocol_ << ":" - << network_name_ << ":" << address << ":" + ost << "Cand[" << foundation_ << ":" << component_ << ":" + << protocol_ << ":" << priority_ << ":" + << address << ":" << type_ << ":" << related_address_ << ":" << username_ << ":" << password_ << "]"; return ost.str(); } diff --git a/p2p/base/p2ptransportchannel.cc b/p2p/base/p2ptransportchannel.cc index 104b5e6..1f53874 100644 --- a/p2p/base/p2ptransportchannel.cc +++ b/p2p/base/p2ptransportchannel.cc @@ -493,7 +493,8 @@ void P2PTransportChannel::OnUnknownAddress( port->Network()->name(), 0U, talk_base::ToString<uint32>(talk_base::ComputeCrc32(id))); new_remote_candidate.set_priority( - new_remote_candidate.GetPriority(ICE_TYPE_PREFERENCE_SRFLX)); + new_remote_candidate.GetPriority(ICE_TYPE_PREFERENCE_SRFLX, + port->Network()->preference())); } if (port->IceProtocol() == ICEPROTO_RFC5245) { diff --git a/p2p/base/p2ptransportchannel_unittest.cc b/p2p/base/p2ptransportchannel_unittest.cc index 7fff3da..53a39c2 100644 --- a/p2p/base/p2ptransportchannel_unittest.cc +++ b/p2p/base/p2ptransportchannel_unittest.cc @@ -1559,8 +1559,11 @@ TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { // Test that we can quickly switch links if an interface goes down. TEST_F(P2PTransportChannelMultihomedTest, TestFailover) { AddAddress(0, kPublicAddrs[0]); - AddAddress(1, kPublicAddrs[1]); + // Adding alternate address will make sure |kPublicAddrs| has the higher + // priority than others. This is due to FakeNetwork::AddInterface method. AddAddress(1, kAlternateAddrs[1]); + AddAddress(1, kPublicAddrs[1]); + // Use only local ports for simplicity. SetAllocatorFlags(0, kOnlyLocalPorts); SetAllocatorFlags(1, kOnlyLocalPorts); diff --git a/p2p/base/port.cc b/p2p/base/port.cc index b6421ad..38031cb 100644 --- a/p2p/base/port.cc +++ b/p2p/base/port.cc @@ -258,7 +258,7 @@ void Port::AddAddress(const talk_base::SocketAddress& address, c.set_type(type); c.set_protocol(protocol); c.set_address(address); - c.set_priority(c.GetPriority(type_preference)); + c.set_priority(c.GetPriority(type_preference, network_->preference())); c.set_username(username_fragment()); c.set_password(password_); c.set_network_name(network_->name()); diff --git a/p2p/client/portallocator_unittest.cc b/p2p/client/portallocator_unittest.cc index 1417707..0ea8fb5 100644 --- a/p2p/client/portallocator_unittest.cc +++ b/p2p/client/portallocator_unittest.cc @@ -53,8 +53,8 @@ using talk_base::Thread; static const SocketAddress kClientAddr("11.11.11.11", 0); static const SocketAddress kClientIPv6Addr( "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); +static const SocketAddress kClientAddr2("22.22.22.22", 0); static const SocketAddress kNatAddr("77.77.77.77", talk_base::NAT_SERVER_PORT); -static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); @@ -492,6 +492,23 @@ TEST_F(PortAllocatorTest, TestGetAllPortsNoUdpAllowed) { EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000); } +TEST_F(PortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { + AddInterface(kClientAddr); + AddInterface(kClientAddr2); + // Allocating only host UDP ports. This is done purely for testing + // convenience. + allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | + cricket::PORTALLOCATOR_DISABLE_STUN | + cricket::PORTALLOCATOR_DISABLE_RELAY); + EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + session_->StartGettingPorts(); + EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); + ASSERT_EQ(2U, candidates_.size()); + EXPECT_EQ(2U, ports_.size()); + // Candidates priorities should be different. + EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); +} + // Test to verify ICE restart process. TEST_F(PortAllocatorTest, TestGetAllPortsRestarts) { AddInterface(kClientAddr); |