| 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 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "webrtc/api/fakemetricsobserver.h" | 14 #include "webrtc/api/fakemetricsobserver.h" |
| 15 #include "webrtc/p2p/base/fakeportallocator.h" | 15 #include "webrtc/p2p/base/fakeportallocator.h" |
| 16 #include "webrtc/p2p/base/packettransportinterface.h" |
| 16 #include "webrtc/p2p/base/p2ptransportchannel.h" | 17 #include "webrtc/p2p/base/p2ptransportchannel.h" |
| 17 #include "webrtc/p2p/base/testrelayserver.h" | 18 #include "webrtc/p2p/base/testrelayserver.h" |
| 18 #include "webrtc/p2p/base/teststunserver.h" | 19 #include "webrtc/p2p/base/teststunserver.h" |
| 19 #include "webrtc/p2p/base/testturnserver.h" | 20 #include "webrtc/p2p/base/testturnserver.h" |
| 20 #include "webrtc/p2p/client/basicportallocator.h" | 21 #include "webrtc/p2p/client/basicportallocator.h" |
| 21 #include "webrtc/base/dscp.h" | 22 #include "webrtc/base/dscp.h" |
| 22 #include "webrtc/base/fakeclock.h" | 23 #include "webrtc/base/fakeclock.h" |
| 23 #include "webrtc/base/fakenetwork.h" | 24 #include "webrtc/base/fakenetwork.h" |
| 24 #include "webrtc/base/firewallsocketserver.h" | 25 #include "webrtc/base/firewallsocketserver.h" |
| 25 #include "webrtc/base/gunit.h" | 26 #include "webrtc/base/gunit.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 TransportChannel* channel; | 274 TransportChannel* channel; |
| 274 Candidates candidates; | 275 Candidates candidates; |
| 275 }; | 276 }; |
| 276 | 277 |
| 277 struct Endpoint { | 278 struct Endpoint { |
| 278 Endpoint() | 279 Endpoint() |
| 279 : role_(ICEROLE_UNKNOWN), | 280 : role_(ICEROLE_UNKNOWN), |
| 280 tiebreaker_(0), | 281 tiebreaker_(0), |
| 281 role_conflict_(false), | 282 role_conflict_(false), |
| 282 save_candidates_(false) {} | 283 save_candidates_(false) {} |
| 283 bool HasChannel(TransportChannel* ch) { | 284 bool HasTransport(const rtc::PacketTransportInterface* transport) { |
| 284 return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get()); | 285 return (transport == cd1_.ch_.get() || transport == cd2_.ch_.get()); |
| 285 } | 286 } |
| 286 ChannelData* GetChannelData(TransportChannel* ch) { | 287 ChannelData* GetChannelData(rtc::PacketTransportInterface* transport) { |
| 287 if (!HasChannel(ch)) return NULL; | 288 if (!HasTransport(transport)) |
| 288 if (cd1_.ch_.get() == ch) | 289 return NULL; |
| 290 if (cd1_.ch_.get() == transport) |
| 289 return &cd1_; | 291 return &cd1_; |
| 290 else | 292 else |
| 291 return &cd2_; | 293 return &cd2_; |
| 292 } | 294 } |
| 293 | 295 |
| 294 void SetIceRole(IceRole role) { role_ = role; } | 296 void SetIceRole(IceRole role) { role_ = role; } |
| 295 IceRole ice_role() { return role_; } | 297 IceRole ice_role() { return role_; } |
| 296 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } | 298 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } |
| 297 uint64_t GetIceTiebreaker() { return tiebreaker_; } | 299 uint64_t GetIceTiebreaker() { return tiebreaker_; } |
| 298 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } | 300 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 312 ChannelData cd1_; | 314 ChannelData cd1_; |
| 313 ChannelData cd2_; | 315 ChannelData cd2_; |
| 314 IceRole role_; | 316 IceRole role_; |
| 315 uint64_t tiebreaker_; | 317 uint64_t tiebreaker_; |
| 316 bool role_conflict_; | 318 bool role_conflict_; |
| 317 bool save_candidates_; | 319 bool save_candidates_; |
| 318 std::vector<std::unique_ptr<CandidatesData>> saved_candidates_; | 320 std::vector<std::unique_ptr<CandidatesData>> saved_candidates_; |
| 319 bool ready_to_send_ = false; | 321 bool ready_to_send_ = false; |
| 320 }; | 322 }; |
| 321 | 323 |
| 322 ChannelData* GetChannelData(TransportChannel* channel) { | 324 ChannelData* GetChannelData(rtc::PacketTransportInterface* transport) { |
| 323 if (ep1_.HasChannel(channel)) | 325 if (ep1_.HasTransport(transport)) |
| 324 return ep1_.GetChannelData(channel); | 326 return ep1_.GetChannelData(transport); |
| 325 else | 327 else |
| 326 return ep2_.GetChannelData(channel); | 328 return ep2_.GetChannelData(transport); |
| 327 } | 329 } |
| 328 | 330 |
| 329 IceParameters IceParamsWithRenomination(const IceParameters& ice, | 331 IceParameters IceParamsWithRenomination(const IceParameters& ice, |
| 330 bool renomination) { | 332 bool renomination) { |
| 331 IceParameters new_ice = ice; | 333 IceParameters new_ice = ice; |
| 332 new_ice.renomination = renomination; | 334 new_ice.renomination = renomination; |
| 333 return new_ice; | 335 return new_ice; |
| 334 } | 336 } |
| 335 | 337 |
| 336 void CreateChannels(const IceConfig& ep1_config, | 338 void CreateChannels(const IceConfig& ep1_config, |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 ep2_ch1()->receiving() && | 665 ep2_ch1()->receiving() && |
| 664 ep2_ch1()->writable(), | 666 ep2_ch1()->writable(), |
| 665 1000); | 667 1000); |
| 666 | 668 |
| 667 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 669 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 668 ep2_ch1()->selected_connection()); | 670 ep2_ch1()->selected_connection()); |
| 669 | 671 |
| 670 TestSendRecv(); | 672 TestSendRecv(); |
| 671 } | 673 } |
| 672 | 674 |
| 673 void OnReadyToSend(TransportChannel* ch) { | 675 void OnReadyToSend(rtc::PacketTransportInterface* transport) { |
| 674 GetEndpoint(ch)->ready_to_send_ = true; | 676 GetEndpoint(transport)->ready_to_send_ = true; |
| 675 } | 677 } |
| 676 | 678 |
| 677 // We pass the candidates directly to the other side. | 679 // We pass the candidates directly to the other side. |
| 678 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { | 680 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { |
| 679 if (force_relay_ && c.type() != RELAY_PORT_TYPE) | 681 if (force_relay_ && c.type() != RELAY_PORT_TYPE) |
| 680 return; | 682 return; |
| 681 | 683 |
| 682 if (GetEndpoint(ch)->save_candidates_) { | 684 if (GetEndpoint(ch)->save_candidates_) { |
| 683 GetEndpoint(ch)->saved_candidates_.push_back( | 685 GetEndpoint(ch)->saved_candidates_.push_back( |
| 684 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); | 686 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 return; | 772 return; |
| 771 } | 773 } |
| 772 for (Candidate& c : data->candidates) { | 774 for (Candidate& c : data->candidates) { |
| 773 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); | 775 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); |
| 774 rch->RemoveRemoteCandidate(c); | 776 rch->RemoveRemoteCandidate(c); |
| 775 } | 777 } |
| 776 break; | 778 break; |
| 777 } | 779 } |
| 778 } | 780 } |
| 779 } | 781 } |
| 780 void OnReadPacket(TransportChannel* channel, | 782 |
| 783 void OnReadPacket(rtc::PacketTransportInterface* transport, |
| 781 const char* data, | 784 const char* data, |
| 782 size_t len, | 785 size_t len, |
| 783 const rtc::PacketTime& packet_time, | 786 const rtc::PacketTime& packet_time, |
| 784 int flags) { | 787 int flags) { |
| 785 std::list<std::string>& packets = GetPacketList(channel); | 788 std::list<std::string>& packets = GetPacketList(transport); |
| 786 packets.push_front(std::string(data, len)); | 789 packets.push_front(std::string(data, len)); |
| 787 } | 790 } |
| 791 |
| 788 void OnRoleConflict(TransportChannelImpl* channel) { | 792 void OnRoleConflict(TransportChannelImpl* channel) { |
| 789 GetEndpoint(channel)->OnRoleConflict(true); | 793 GetEndpoint(channel)->OnRoleConflict(true); |
| 790 IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING | 794 IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING |
| 791 ? ICEROLE_CONTROLLED | 795 ? ICEROLE_CONTROLLED |
| 792 : ICEROLE_CONTROLLING; | 796 : ICEROLE_CONTROLLING; |
| 793 channel->SetIceRole(new_role); | 797 channel->SetIceRole(new_role); |
| 794 } | 798 } |
| 795 | 799 |
| 796 int SendData(TransportChannel* channel, const char* data, size_t len) { | 800 int SendData(TransportChannel* channel, const char* data, size_t len) { |
| 797 rtc::PacketOptions options; | 801 rtc::PacketOptions options; |
| 798 return channel->SendPacket(data, len, options, 0); | 802 return channel->SendPacket(data, len, options, 0); |
| 799 } | 803 } |
| 800 bool CheckDataOnChannel(TransportChannel* channel, | 804 bool CheckDataOnChannel(TransportChannel* channel, |
| 801 const char* data, | 805 const char* data, |
| 802 int len) { | 806 int len) { |
| 803 return GetChannelData(channel)->CheckData(data, len); | 807 return GetChannelData(channel)->CheckData(data, len); |
| 804 } | 808 } |
| 805 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { | 809 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { |
| 806 return (ch && ch->selected_connection()) | 810 return (ch && ch->selected_connection()) |
| 807 ? &ch->selected_connection()->local_candidate() | 811 ? &ch->selected_connection()->local_candidate() |
| 808 : NULL; | 812 : NULL; |
| 809 } | 813 } |
| 810 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { | 814 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { |
| 811 return (ch && ch->selected_connection()) | 815 return (ch && ch->selected_connection()) |
| 812 ? &ch->selected_connection()->remote_candidate() | 816 ? &ch->selected_connection()->remote_candidate() |
| 813 : NULL; | 817 : NULL; |
| 814 } | 818 } |
| 815 Endpoint* GetEndpoint(TransportChannel* ch) { | 819 Endpoint* GetEndpoint(rtc::PacketTransportInterface* transport) { |
| 816 if (ep1_.HasChannel(ch)) { | 820 if (ep1_.HasTransport(transport)) { |
| 817 return &ep1_; | 821 return &ep1_; |
| 818 } else if (ep2_.HasChannel(ch)) { | 822 } else if (ep2_.HasTransport(transport)) { |
| 819 return &ep2_; | 823 return &ep2_; |
| 820 } else { | 824 } else { |
| 821 return NULL; | 825 return NULL; |
| 822 } | 826 } |
| 823 } | 827 } |
| 824 P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) { | 828 P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) { |
| 825 if (ch == ep1_ch1()) | 829 if (ch == ep1_ch1()) |
| 826 return ep2_ch1(); | 830 return ep2_ch1(); |
| 827 else if (ch == ep1_ch2()) | 831 else if (ch == ep1_ch2()) |
| 828 return ep2_ch2(); | 832 return ep2_ch2(); |
| 829 else if (ch == ep2_ch1()) | 833 else if (ch == ep2_ch1()) |
| 830 return ep1_ch1(); | 834 return ep1_ch1(); |
| 831 else if (ch == ep2_ch2()) | 835 else if (ch == ep2_ch2()) |
| 832 return ep1_ch2(); | 836 return ep1_ch2(); |
| 833 else | 837 else |
| 834 return NULL; | 838 return NULL; |
| 835 } | 839 } |
| 836 std::list<std::string>& GetPacketList(TransportChannel* ch) { | 840 std::list<std::string>& GetPacketList( |
| 837 return GetChannelData(ch)->ch_packets_; | 841 rtc::PacketTransportInterface* transport) { |
| 842 return GetChannelData(transport)->ch_packets_; |
| 838 } | 843 } |
| 839 | 844 |
| 840 enum RemoteIceParameterSource { FROM_CANDIDATE, FROM_SETICEPARAMETERS }; | 845 enum RemoteIceParameterSource { FROM_CANDIDATE, FROM_SETICEPARAMETERS }; |
| 841 | 846 |
| 842 // How does the test pass ICE parameters to the P2PTransportChannel? | 847 // How does the test pass ICE parameters to the P2PTransportChannel? |
| 843 // On the candidate itself, or through SetRemoteIceParameters? | 848 // On the candidate itself, or through SetRemoteIceParameters? |
| 844 // Goes through the candidate itself by default. | 849 // Goes through the candidate itself by default. |
| 845 void set_remote_ice_parameter_source(RemoteIceParameterSource source) { | 850 void set_remote_ice_parameter_source(RemoteIceParameterSource source) { |
| 846 remote_ice_parameter_source_ = source; | 851 remote_ice_parameter_source_ = source; |
| 847 } | 852 } |
| (...skipping 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2902 new StunUInt32Attribute(STUN_ATTR_NOMINATION, nomination)); | 2907 new StunUInt32Attribute(STUN_ATTR_NOMINATION, nomination)); |
| 2903 } | 2908 } |
| 2904 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); | 2909 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); |
| 2905 msg.AddMessageIntegrity(conn->local_candidate().password()); | 2910 msg.AddMessageIntegrity(conn->local_candidate().password()); |
| 2906 msg.AddFingerprint(); | 2911 msg.AddFingerprint(); |
| 2907 rtc::ByteBufferWriter buf; | 2912 rtc::ByteBufferWriter buf; |
| 2908 msg.Write(&buf); | 2913 msg.Write(&buf); |
| 2909 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); | 2914 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); |
| 2910 } | 2915 } |
| 2911 | 2916 |
| 2912 void OnReadyToSend(TransportChannel* channel) { | 2917 void OnReadyToSend(rtc::PacketTransportInterface* transport) { |
| 2913 channel_ready_to_send_ = true; | 2918 channel_ready_to_send_ = true; |
| 2914 } | 2919 } |
| 2915 void OnChannelStateChanged(TransportChannelImpl* channel) { | 2920 void OnChannelStateChanged(TransportChannelImpl* channel) { |
| 2916 channel_state_ = channel->GetState(); | 2921 channel_state_ = channel->GetState(); |
| 2917 } | 2922 } |
| 2918 | 2923 |
| 2919 CandidatePairInterface* last_selected_candidate_pair() { | 2924 CandidatePairInterface* last_selected_candidate_pair() { |
| 2920 return last_selected_candidate_pair_; | 2925 return last_selected_candidate_pair_; |
| 2921 } | 2926 } |
| 2922 int last_sent_packet_id() { return last_sent_packet_id_; } | 2927 int last_sent_packet_id() { return last_sent_packet_id_; } |
| (...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4216 | 4221 |
| 4217 // TCP Relay/Relay is the next. | 4222 // TCP Relay/Relay is the next. |
| 4218 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 4223 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
| 4219 TCP_PROTOCOL_NAME); | 4224 TCP_PROTOCOL_NAME); |
| 4220 | 4225 |
| 4221 // Finally, Local/Relay will be pinged. | 4226 // Finally, Local/Relay will be pinged. |
| 4222 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 4227 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
| 4223 } | 4228 } |
| 4224 | 4229 |
| 4225 } // namespace cricket { | 4230 } // namespace cricket { |
| OLD | NEW |