Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: webrtc/p2p/base/transport.cc

Issue 1353713002: Remove GICE (again). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Undo .gclient Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/transport.h ('k') | webrtc/p2p/base/transport_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 ~ChannelParams() { 49 ~ChannelParams() {
50 delete candidate; 50 delete candidate;
51 } 51 }
52 52
53 std::string name; 53 std::string name;
54 int component; 54 int component;
55 TransportChannelImpl* channel; 55 TransportChannelImpl* channel;
56 Candidate* candidate; 56 Candidate* candidate;
57 }; 57 };
58 58
59 static std::string IceProtoToString(TransportProtocol proto) {
60 std::string proto_str;
61 switch (proto) {
62 case ICEPROTO_GOOGLE:
63 proto_str = "gice";
64 break;
65 case ICEPROTO_HYBRID:
66 proto_str = "hybrid";
67 break;
68 case ICEPROTO_RFC5245:
69 proto_str = "ice";
70 break;
71 default:
72 ASSERT(false);
73 break;
74 }
75 return proto_str;
76 }
77
78 static bool VerifyIceParams(const TransportDescription& desc) { 59 static bool VerifyIceParams(const TransportDescription& desc) {
79 // For legacy protocols. 60 // For legacy protocols.
80 if (desc.ice_ufrag.empty() && desc.ice_pwd.empty()) 61 if (desc.ice_ufrag.empty() && desc.ice_pwd.empty())
81 return true; 62 return true;
82 63
83 if (desc.ice_ufrag.length() < ICE_UFRAG_MIN_LENGTH || 64 if (desc.ice_ufrag.length() < ICE_UFRAG_MIN_LENGTH ||
84 desc.ice_ufrag.length() > ICE_UFRAG_MAX_LENGTH) { 65 desc.ice_ufrag.length() > ICE_UFRAG_MAX_LENGTH) {
85 return false; 66 return false;
86 } 67 }
87 if (desc.ice_pwd.length() < ICE_PWD_MIN_LENGTH || 68 if (desc.ice_pwd.length() < ICE_PWD_MIN_LENGTH ||
(...skipping 24 matching lines...) Expand all
112 93
113 static bool IceCredentialsChanged(const TransportDescription& old_desc, 94 static bool IceCredentialsChanged(const TransportDescription& old_desc,
114 const TransportDescription& new_desc) { 95 const TransportDescription& new_desc) {
115 return IceCredentialsChanged(old_desc.ice_ufrag, old_desc.ice_pwd, 96 return IceCredentialsChanged(old_desc.ice_ufrag, old_desc.ice_pwd,
116 new_desc.ice_ufrag, new_desc.ice_pwd); 97 new_desc.ice_ufrag, new_desc.ice_pwd);
117 } 98 }
118 99
119 Transport::Transport(rtc::Thread* signaling_thread, 100 Transport::Transport(rtc::Thread* signaling_thread,
120 rtc::Thread* worker_thread, 101 rtc::Thread* worker_thread,
121 const std::string& content_name, 102 const std::string& content_name,
122 const std::string& type,
123 PortAllocator* allocator) 103 PortAllocator* allocator)
124 : signaling_thread_(signaling_thread), 104 : signaling_thread_(signaling_thread),
125 worker_thread_(worker_thread), 105 worker_thread_(worker_thread),
126 content_name_(content_name), 106 content_name_(content_name),
127 type_(type),
128 allocator_(allocator), 107 allocator_(allocator),
129 destroyed_(false), 108 destroyed_(false),
130 readable_(TRANSPORT_STATE_NONE), 109 readable_(TRANSPORT_STATE_NONE),
131 writable_(TRANSPORT_STATE_NONE), 110 writable_(TRANSPORT_STATE_NONE),
132 receiving_(TRANSPORT_STATE_NONE), 111 receiving_(TRANSPORT_STATE_NONE),
133 was_writable_(false), 112 was_writable_(false),
134 connect_requested_(false), 113 connect_requested_(false),
135 ice_role_(ICEROLE_UNKNOWN), 114 ice_role_(ICEROLE_UNKNOWN),
136 tiebreaker_(0), 115 tiebreaker_(0),
137 protocol_(ICEPROTO_HYBRID),
138 remote_ice_mode_(ICEMODE_FULL), 116 remote_ice_mode_(ICEMODE_FULL),
139 channel_receiving_timeout_(-1) { 117 channel_receiving_timeout_(-1) {
140 } 118 }
141 119
142 Transport::~Transport() { 120 Transport::~Transport() {
143 ASSERT(signaling_thread_->IsCurrent()); 121 ASSERT(signaling_thread_->IsCurrent());
144 ASSERT(destroyed_); 122 ASSERT(destroyed_);
145 } 123 }
146 124
147 void Transport::SetIceRole(IceRole role) { 125 void Transport::SetIceRole(IceRole role) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 326
349 if (!local_description_) { 327 if (!local_description_) {
350 // TOOD(mallinath) : TransportDescription(TD) shouldn't be generated here. 328 // TOOD(mallinath) : TransportDescription(TD) shouldn't be generated here.
351 // As Transport must know TD is offer or answer and cricket::Transport 329 // As Transport must know TD is offer or answer and cricket::Transport
352 // doesn't have the capability to decide it. This should be set by the 330 // doesn't have the capability to decide it. This should be set by the
353 // Session. 331 // Session.
354 // Session must generate local TD before remote candidates pushed when 332 // Session must generate local TD before remote candidates pushed when
355 // initiate request initiated by the remote. 333 // initiate request initiated by the remote.
356 LOG(LS_INFO) << "Transport::ConnectChannels_w: No local description has " 334 LOG(LS_INFO) << "Transport::ConnectChannels_w: No local description has "
357 << "been set. Will generate one."; 335 << "been set. Will generate one.";
358 TransportDescription desc(NS_GINGLE_P2P, std::vector<std::string>(), 336 TransportDescription desc(std::vector<std::string>(),
359 rtc::CreateRandomString(ICE_UFRAG_LENGTH), 337 rtc::CreateRandomString(ICE_UFRAG_LENGTH),
360 rtc::CreateRandomString(ICE_PWD_LENGTH), 338 rtc::CreateRandomString(ICE_PWD_LENGTH),
361 ICEMODE_FULL, CONNECTIONROLE_NONE, NULL, 339 ICEMODE_FULL, CONNECTIONROLE_NONE, NULL,
362 Candidates()); 340 Candidates());
363 SetLocalTransportDescription_w(desc, CA_OFFER, NULL); 341 SetLocalTransportDescription_w(desc, CA_OFFER, NULL);
364 } 342 }
365 343
366 CallChannels_w(&TransportChannelImpl::Connect); 344 CallChannels_w(&TransportChannelImpl::Connect);
367 if (!channels_.empty()) { 345 if (!channels_.empty()) {
368 signaling_thread()->Post(this, MSG_CONNECTING, NULL); 346 signaling_thread()->Post(this, MSG_CONNECTING, NULL);
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 // If PRANSWER/ANSWER is set, we should decide transport protocol type. 802 // If PRANSWER/ANSWER is set, we should decide transport protocol type.
825 if (action == CA_PRANSWER || action == CA_ANSWER) { 803 if (action == CA_PRANSWER || action == CA_ANSWER) {
826 ret = NegotiateTransportDescription_w(CA_OFFER, error_desc); 804 ret = NegotiateTransportDescription_w(CA_OFFER, error_desc);
827 } 805 }
828 return ret; 806 return ret;
829 } 807 }
830 808
831 bool Transport::ApplyLocalTransportDescription_w(TransportChannelImpl* ch, 809 bool Transport::ApplyLocalTransportDescription_w(TransportChannelImpl* ch,
832 std::string* error_desc) { 810 std::string* error_desc) {
833 ASSERT(worker_thread()->IsCurrent()); 811 ASSERT(worker_thread()->IsCurrent());
834 // If existing protocol_type is HYBRID, we may have not chosen the final
835 // protocol type, so update the channel protocol type from the
836 // local description. Otherwise, skip updating the protocol type.
837 // We check for HYBRID to avoid accidental changes; in the case of a
838 // session renegotiation, the new offer will have the google-ice ICE option,
839 // so we need to make sure we don't switch back from ICE mode to HYBRID
840 // when this happens.
841 // There are some other ways we could have solved this, but this is the
842 // simplest. The ultimate solution will be to get rid of GICE altogether.
843 IceProtocolType protocol_type;
844 if (ch->GetIceProtocolType(&protocol_type) &&
845 protocol_type == ICEPROTO_HYBRID) {
846 ch->SetIceProtocolType(
847 TransportProtocolFromDescription(local_description()));
848 }
849 ch->SetIceCredentials(local_description_->ice_ufrag, 812 ch->SetIceCredentials(local_description_->ice_ufrag,
850 local_description_->ice_pwd); 813 local_description_->ice_pwd);
851 return true; 814 return true;
852 } 815 }
853 816
854 bool Transport::ApplyRemoteTransportDescription_w(TransportChannelImpl* ch, 817 bool Transport::ApplyRemoteTransportDescription_w(TransportChannelImpl* ch,
855 std::string* error_desc) { 818 std::string* error_desc) {
856 ch->SetRemoteIceCredentials(remote_description_->ice_ufrag, 819 ch->SetRemoteIceCredentials(remote_description_->ice_ufrag,
857 remote_description_->ice_pwd); 820 remote_description_->ice_pwd);
858 return true; 821 return true;
859 } 822 }
860 823
861 bool Transport::ApplyNegotiatedTransportDescription_w( 824 bool Transport::ApplyNegotiatedTransportDescription_w(
862 TransportChannelImpl* channel, std::string* error_desc) { 825 TransportChannelImpl* channel, std::string* error_desc) {
863 ASSERT(worker_thread()->IsCurrent()); 826 ASSERT(worker_thread()->IsCurrent());
864 channel->SetIceProtocolType(protocol_);
865 channel->SetRemoteIceMode(remote_ice_mode_); 827 channel->SetRemoteIceMode(remote_ice_mode_);
866 return true; 828 return true;
867 } 829 }
868 830
869 bool Transport::NegotiateTransportDescription_w(ContentAction local_role, 831 bool Transport::NegotiateTransportDescription_w(ContentAction local_role,
870 std::string* error_desc) { 832 std::string* error_desc) {
871 ASSERT(worker_thread()->IsCurrent()); 833 ASSERT(worker_thread()->IsCurrent());
872 // TODO(ekr@rtfm.com): This is ICE-specific stuff. Refactor into 834 // TODO(ekr@rtfm.com): This is ICE-specific stuff. Refactor into
873 // P2PTransport. 835 // P2PTransport.
874 const TransportDescription* offer;
875 const TransportDescription* answer;
876
877 if (local_role == CA_OFFER) {
878 offer = local_description_.get();
879 answer = remote_description_.get();
880 } else {
881 offer = remote_description_.get();
882 answer = local_description_.get();
883 }
884
885 TransportProtocol offer_proto = TransportProtocolFromDescription(offer);
886 TransportProtocol answer_proto = TransportProtocolFromDescription(answer);
887
888 // If offered protocol is gice/ice, then we expect to receive matching
889 // protocol in answer, anything else is treated as an error.
890 // HYBRID is not an option when offered specific protocol.
891 // If offered protocol is HYBRID and answered protocol is HYBRID then
892 // gice is preferred protocol.
893 // TODO(mallinath) - Answer from local or remote should't have both ice
894 // and gice support. It should always pick which protocol it wants to use.
895 // Once WebRTC stops supporting gice (for backward compatibility), HYBRID in
896 // answer must be treated as error.
897 if ((offer_proto == ICEPROTO_GOOGLE || offer_proto == ICEPROTO_RFC5245) &&
898 (offer_proto != answer_proto)) {
899 std::ostringstream desc;
900 desc << "Offer and answer protocol mismatch: "
901 << IceProtoToString(offer_proto)
902 << " vs "
903 << IceProtoToString(answer_proto);
904 return BadTransportDescription(desc.str(), error_desc);
905 }
906 protocol_ = answer_proto == ICEPROTO_HYBRID ? ICEPROTO_GOOGLE : answer_proto;
907 836
908 // If transport is in ICEROLE_CONTROLLED and remote end point supports only 837 // If transport is in ICEROLE_CONTROLLED and remote end point supports only
909 // ice_lite, this local end point should take CONTROLLING role. 838 // ice_lite, this local end point should take CONTROLLING role.
910 if (ice_role_ == ICEROLE_CONTROLLED && 839 if (ice_role_ == ICEROLE_CONTROLLED &&
911 remote_description_->ice_mode == ICEMODE_LITE) { 840 remote_description_->ice_mode == ICEMODE_LITE) {
912 SetIceRole_w(ICEROLE_CONTROLLING); 841 SetIceRole_w(ICEROLE_CONTROLLING);
913 } 842 }
914 843
915 // Update remote ice_mode to all existing channels. 844 // Update remote ice_mode to all existing channels.
916 remote_ice_mode_ = remote_description_->ice_mode; 845 remote_ice_mode_ = remote_description_->ice_mode;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 break; 899 break;
971 case MSG_COMPLETED: 900 case MSG_COMPLETED:
972 SignalCompleted(this); 901 SignalCompleted(this);
973 break; 902 break;
974 case MSG_FAILED: 903 case MSG_FAILED:
975 SignalFailed(this); 904 SignalFailed(this);
976 break; 905 break;
977 } 906 }
978 } 907 }
979 908
980 // We're GICE if the namespace is NS_GOOGLE_P2P, or if NS_JINGLE_ICE_UDP is
981 // used and the GICE ice-option is set.
982 TransportProtocol TransportProtocolFromDescription(
983 const TransportDescription* desc) {
984 ASSERT(desc != NULL);
985 if (desc->transport_type == NS_JINGLE_ICE_UDP) {
986 return (desc->HasOption(ICE_OPTION_GICE)) ?
987 ICEPROTO_HYBRID : ICEPROTO_RFC5245;
988 }
989 return ICEPROTO_GOOGLE;
990 }
991
992 } // namespace cricket 909 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/transport.h ('k') | webrtc/p2p/base/transport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698