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