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