| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "webrtc/base/natsocketfactory.h" | 24 #include "webrtc/base/natsocketfactory.h" |
| 25 #include "webrtc/base/physicalsocketserver.h" | 25 #include "webrtc/base/physicalsocketserver.h" |
| 26 #include "webrtc/base/proxyserver.h" | 26 #include "webrtc/base/proxyserver.h" |
| 27 #include "webrtc/base/socketaddress.h" | 27 #include "webrtc/base/socketaddress.h" |
| 28 #include "webrtc/base/ssladapter.h" | 28 #include "webrtc/base/ssladapter.h" |
| 29 #include "webrtc/base/thread.h" | 29 #include "webrtc/base/thread.h" |
| 30 #include "webrtc/base/virtualsocketserver.h" | 30 #include "webrtc/base/virtualsocketserver.h" |
| 31 #include "webrtc/p2p/base/icetransportinternal.h" | 31 #include "webrtc/p2p/base/icetransportinternal.h" |
| 32 #include "webrtc/p2p/base/fakeportallocator.h" | 32 #include "webrtc/p2p/base/fakeportallocator.h" |
| 33 #include "webrtc/p2p/base/p2ptransportchannel.h" | 33 #include "webrtc/p2p/base/p2ptransportchannel.h" |
| 34 #include "webrtc/p2p/base/packettransportinterface.h" | 34 #include "webrtc/p2p/base/packettransportinternal.h" |
| 35 #include "webrtc/p2p/base/testrelayserver.h" | 35 #include "webrtc/p2p/base/testrelayserver.h" |
| 36 #include "webrtc/p2p/base/teststunserver.h" | 36 #include "webrtc/p2p/base/teststunserver.h" |
| 37 #include "webrtc/p2p/base/testturnserver.h" | 37 #include "webrtc/p2p/base/testturnserver.h" |
| 38 #include "webrtc/p2p/client/basicportallocator.h" | 38 #include "webrtc/p2p/client/basicportallocator.h" |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 using rtc::SocketAddress; | 42 using rtc::SocketAddress; |
| 43 | 43 |
| 44 // Default timeout for tests in this file. | 44 // Default timeout for tests in this file. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 IceTransportInternal* channel; | 280 IceTransportInternal* channel; |
| 281 Candidates candidates; | 281 Candidates candidates; |
| 282 }; | 282 }; |
| 283 | 283 |
| 284 struct Endpoint { | 284 struct Endpoint { |
| 285 Endpoint() | 285 Endpoint() |
| 286 : role_(ICEROLE_UNKNOWN), | 286 : role_(ICEROLE_UNKNOWN), |
| 287 tiebreaker_(0), | 287 tiebreaker_(0), |
| 288 role_conflict_(false), | 288 role_conflict_(false), |
| 289 save_candidates_(false) {} | 289 save_candidates_(false) {} |
| 290 bool HasTransport(const rtc::PacketTransportInterface* transport) { | 290 bool HasTransport(const rtc::PacketTransportInternal* transport) { |
| 291 return (transport == cd1_.ch_.get() || transport == cd2_.ch_.get()); | 291 return (transport == cd1_.ch_.get() || transport == cd2_.ch_.get()); |
| 292 } | 292 } |
| 293 ChannelData* GetChannelData(rtc::PacketTransportInterface* transport) { | 293 ChannelData* GetChannelData(rtc::PacketTransportInternal* transport) { |
| 294 if (!HasTransport(transport)) | 294 if (!HasTransport(transport)) |
| 295 return NULL; | 295 return NULL; |
| 296 if (cd1_.ch_.get() == transport) | 296 if (cd1_.ch_.get() == transport) |
| 297 return &cd1_; | 297 return &cd1_; |
| 298 else | 298 else |
| 299 return &cd2_; | 299 return &cd2_; |
| 300 } | 300 } |
| 301 | 301 |
| 302 void SetIceRole(IceRole role) { role_ = role; } | 302 void SetIceRole(IceRole role) { role_ = role; } |
| 303 IceRole ice_role() { return role_; } | 303 IceRole ice_role() { return role_; } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 320 ChannelData cd1_; | 320 ChannelData cd1_; |
| 321 ChannelData cd2_; | 321 ChannelData cd2_; |
| 322 IceRole role_; | 322 IceRole role_; |
| 323 uint64_t tiebreaker_; | 323 uint64_t tiebreaker_; |
| 324 bool role_conflict_; | 324 bool role_conflict_; |
| 325 bool save_candidates_; | 325 bool save_candidates_; |
| 326 std::vector<std::unique_ptr<CandidatesData>> saved_candidates_; | 326 std::vector<std::unique_ptr<CandidatesData>> saved_candidates_; |
| 327 bool ready_to_send_ = false; | 327 bool ready_to_send_ = false; |
| 328 }; | 328 }; |
| 329 | 329 |
| 330 ChannelData* GetChannelData(rtc::PacketTransportInterface* transport) { | 330 ChannelData* GetChannelData(rtc::PacketTransportInternal* transport) { |
| 331 if (ep1_.HasTransport(transport)) | 331 if (ep1_.HasTransport(transport)) |
| 332 return ep1_.GetChannelData(transport); | 332 return ep1_.GetChannelData(transport); |
| 333 else | 333 else |
| 334 return ep2_.GetChannelData(transport); | 334 return ep2_.GetChannelData(transport); |
| 335 } | 335 } |
| 336 | 336 |
| 337 IceParameters IceParamsWithRenomination(const IceParameters& ice, | 337 IceParameters IceParamsWithRenomination(const IceParameters& ice, |
| 338 bool renomination) { | 338 bool renomination) { |
| 339 IceParameters new_ice = ice; | 339 IceParameters new_ice = ice; |
| 340 new_ice.renomination = renomination; | 340 new_ice.renomination = renomination; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 675 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 676 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 676 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 677 kShortTimeout, clock); | 677 kShortTimeout, clock); |
| 678 | 678 |
| 679 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 679 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 680 ep2_ch1()->selected_connection()); | 680 ep2_ch1()->selected_connection()); |
| 681 | 681 |
| 682 TestSendRecv(clock); | 682 TestSendRecv(clock); |
| 683 } | 683 } |
| 684 | 684 |
| 685 void OnReadyToSend(rtc::PacketTransportInterface* transport) { | 685 void OnReadyToSend(rtc::PacketTransportInternal* transport) { |
| 686 GetEndpoint(transport)->ready_to_send_ = true; | 686 GetEndpoint(transport)->ready_to_send_ = true; |
| 687 } | 687 } |
| 688 | 688 |
| 689 // We pass the candidates directly to the other side. | 689 // We pass the candidates directly to the other side. |
| 690 void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) { | 690 void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) { |
| 691 if (force_relay_ && c.type() != RELAY_PORT_TYPE) | 691 if (force_relay_ && c.type() != RELAY_PORT_TYPE) |
| 692 return; | 692 return; |
| 693 | 693 |
| 694 if (GetEndpoint(ch)->save_candidates_) { | 694 if (GetEndpoint(ch)->save_candidates_) { |
| 695 GetEndpoint(ch)->saved_candidates_.push_back( | 695 GetEndpoint(ch)->saved_candidates_.push_back( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 } | 783 } |
| 784 for (Candidate& c : data->candidates) { | 784 for (Candidate& c : data->candidates) { |
| 785 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); | 785 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); |
| 786 rch->RemoveRemoteCandidate(c); | 786 rch->RemoveRemoteCandidate(c); |
| 787 } | 787 } |
| 788 break; | 788 break; |
| 789 } | 789 } |
| 790 } | 790 } |
| 791 } | 791 } |
| 792 | 792 |
| 793 void OnReadPacket(rtc::PacketTransportInterface* transport, | 793 void OnReadPacket(rtc::PacketTransportInternal* transport, |
| 794 const char* data, | 794 const char* data, |
| 795 size_t len, | 795 size_t len, |
| 796 const rtc::PacketTime& packet_time, | 796 const rtc::PacketTime& packet_time, |
| 797 int flags) { | 797 int flags) { |
| 798 std::list<std::string>& packets = GetPacketList(transport); | 798 std::list<std::string>& packets = GetPacketList(transport); |
| 799 packets.push_front(std::string(data, len)); | 799 packets.push_front(std::string(data, len)); |
| 800 } | 800 } |
| 801 | 801 |
| 802 void OnRoleConflict(IceTransportInternal* channel) { | 802 void OnRoleConflict(IceTransportInternal* channel) { |
| 803 GetEndpoint(channel)->OnRoleConflict(true); | 803 GetEndpoint(channel)->OnRoleConflict(true); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 819 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { | 819 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { |
| 820 return (ch && ch->selected_connection()) | 820 return (ch && ch->selected_connection()) |
| 821 ? &ch->selected_connection()->local_candidate() | 821 ? &ch->selected_connection()->local_candidate() |
| 822 : NULL; | 822 : NULL; |
| 823 } | 823 } |
| 824 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { | 824 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { |
| 825 return (ch && ch->selected_connection()) | 825 return (ch && ch->selected_connection()) |
| 826 ? &ch->selected_connection()->remote_candidate() | 826 ? &ch->selected_connection()->remote_candidate() |
| 827 : NULL; | 827 : NULL; |
| 828 } | 828 } |
| 829 Endpoint* GetEndpoint(rtc::PacketTransportInterface* transport) { | 829 Endpoint* GetEndpoint(rtc::PacketTransportInternal* transport) { |
| 830 if (ep1_.HasTransport(transport)) { | 830 if (ep1_.HasTransport(transport)) { |
| 831 return &ep1_; | 831 return &ep1_; |
| 832 } else if (ep2_.HasTransport(transport)) { | 832 } else if (ep2_.HasTransport(transport)) { |
| 833 return &ep2_; | 833 return &ep2_; |
| 834 } else { | 834 } else { |
| 835 return NULL; | 835 return NULL; |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 P2PTransportChannel* GetRemoteChannel(IceTransportInternal* ch) { | 838 P2PTransportChannel* GetRemoteChannel(IceTransportInternal* ch) { |
| 839 if (ch == ep1_ch1()) | 839 if (ch == ep1_ch1()) |
| 840 return ep2_ch1(); | 840 return ep2_ch1(); |
| 841 else if (ch == ep1_ch2()) | 841 else if (ch == ep1_ch2()) |
| 842 return ep2_ch2(); | 842 return ep2_ch2(); |
| 843 else if (ch == ep2_ch1()) | 843 else if (ch == ep2_ch1()) |
| 844 return ep1_ch1(); | 844 return ep1_ch1(); |
| 845 else if (ch == ep2_ch2()) | 845 else if (ch == ep2_ch2()) |
| 846 return ep1_ch2(); | 846 return ep1_ch2(); |
| 847 else | 847 else |
| 848 return NULL; | 848 return NULL; |
| 849 } | 849 } |
| 850 std::list<std::string>& GetPacketList( | 850 std::list<std::string>& GetPacketList( |
| 851 rtc::PacketTransportInterface* transport) { | 851 rtc::PacketTransportInternal* transport) { |
| 852 return GetChannelData(transport)->ch_packets_; | 852 return GetChannelData(transport)->ch_packets_; |
| 853 } | 853 } |
| 854 | 854 |
| 855 enum RemoteIceParameterSource { FROM_CANDIDATE, FROM_SETICEPARAMETERS }; | 855 enum RemoteIceParameterSource { FROM_CANDIDATE, FROM_SETICEPARAMETERS }; |
| 856 | 856 |
| 857 // How does the test pass ICE parameters to the P2PTransportChannel? | 857 // How does the test pass ICE parameters to the P2PTransportChannel? |
| 858 // On the candidate itself, or through SetRemoteIceParameters? | 858 // On the candidate itself, or through SetRemoteIceParameters? |
| 859 // Goes through the candidate itself by default. | 859 // Goes through the candidate itself by default. |
| 860 void set_remote_ice_parameter_source(RemoteIceParameterSource source) { | 860 void set_remote_ice_parameter_source(RemoteIceParameterSource source) { |
| 861 remote_ice_parameter_source_ = source; | 861 remote_ice_parameter_source_ = source; |
| (...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3049 new StunUInt32Attribute(STUN_ATTR_NOMINATION, nomination)); | 3049 new StunUInt32Attribute(STUN_ATTR_NOMINATION, nomination)); |
| 3050 } | 3050 } |
| 3051 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); | 3051 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); |
| 3052 msg.AddMessageIntegrity(conn->local_candidate().password()); | 3052 msg.AddMessageIntegrity(conn->local_candidate().password()); |
| 3053 msg.AddFingerprint(); | 3053 msg.AddFingerprint(); |
| 3054 rtc::ByteBufferWriter buf; | 3054 rtc::ByteBufferWriter buf; |
| 3055 msg.Write(&buf); | 3055 msg.Write(&buf); |
| 3056 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); | 3056 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); |
| 3057 } | 3057 } |
| 3058 | 3058 |
| 3059 void OnReadyToSend(rtc::PacketTransportInterface* transport) { | 3059 void OnReadyToSend(rtc::PacketTransportInternal* transport) { |
| 3060 channel_ready_to_send_ = true; | 3060 channel_ready_to_send_ = true; |
| 3061 } | 3061 } |
| 3062 void OnChannelStateChanged(IceTransportInternal* channel) { | 3062 void OnChannelStateChanged(IceTransportInternal* channel) { |
| 3063 channel_state_ = channel->GetState(); | 3063 channel_state_ = channel->GetState(); |
| 3064 } | 3064 } |
| 3065 | 3065 |
| 3066 CandidatePairInterface* last_selected_candidate_pair() { | 3066 CandidatePairInterface* last_selected_candidate_pair() { |
| 3067 return last_selected_candidate_pair_; | 3067 return last_selected_candidate_pair_; |
| 3068 } | 3068 } |
| 3069 int last_sent_packet_id() { return last_sent_packet_id_; } | 3069 int last_sent_packet_id() { return last_sent_packet_id_; } |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4388 | 4388 |
| 4389 // TCP Relay/Relay is the next. | 4389 // TCP Relay/Relay is the next. |
| 4390 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 4390 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
| 4391 TCP_PROTOCOL_NAME); | 4391 TCP_PROTOCOL_NAME); |
| 4392 | 4392 |
| 4393 // Finally, Local/Relay will be pinged. | 4393 // Finally, Local/Relay will be pinged. |
| 4394 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 4394 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
| 4395 } | 4395 } |
| 4396 | 4396 |
| 4397 } // namespace cricket { | 4397 } // namespace cricket { |
| OLD | NEW |