OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 "webrtc/p2p/base/transportdescriptionfactory.h" | 11 #include "webrtc/p2p/base/transportdescriptionfactory.h" |
12 | 12 |
13 #include "webrtc/p2p/base/transportdescription.h" | 13 #include "webrtc/p2p/base/transportdescription.h" |
14 #include "webrtc/base/helpers.h" | 14 #include "webrtc/base/helpers.h" |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
16 #include "webrtc/base/messagedigest.h" | 16 #include "webrtc/base/messagedigest.h" |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/base/sslfingerprint.h" | 18 #include "webrtc/base/sslfingerprint.h" |
19 | 19 |
20 namespace cricket { | 20 namespace cricket { |
21 | 21 |
| 22 static TransportProtocol kDefaultProtocol = ICEPROTO_RFC5245; |
| 23 |
22 TransportDescriptionFactory::TransportDescriptionFactory() | 24 TransportDescriptionFactory::TransportDescriptionFactory() |
23 : secure_(SEC_DISABLED), | 25 : protocol_(kDefaultProtocol), |
| 26 secure_(SEC_DISABLED), |
24 identity_(NULL) { | 27 identity_(NULL) { |
25 } | 28 } |
26 | 29 |
27 TransportDescription* TransportDescriptionFactory::CreateOffer( | 30 TransportDescription* TransportDescriptionFactory::CreateOffer( |
28 const TransportOptions& options, | 31 const TransportOptions& options, |
29 const TransportDescription* current_description) const { | 32 const TransportDescription* current_description) const { |
30 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); | 33 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); |
31 | 34 |
| 35 // Set the transport type depending on the selected protocol. |
| 36 if (protocol_ == ICEPROTO_RFC5245) { |
| 37 desc->transport_type = NS_JINGLE_ICE_UDP; |
| 38 } else if (protocol_ == ICEPROTO_HYBRID) { |
| 39 desc->transport_type = NS_JINGLE_ICE_UDP; |
| 40 desc->AddOption(ICE_OPTION_GICE); |
| 41 } else if (protocol_ == ICEPROTO_GOOGLE) { |
| 42 desc->transport_type = NS_GINGLE_P2P; |
| 43 } |
| 44 |
32 // Generate the ICE credentials if we don't already have them. | 45 // Generate the ICE credentials if we don't already have them. |
33 if (!current_description || options.ice_restart) { | 46 if (!current_description || options.ice_restart) { |
34 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); | 47 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); |
35 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); | 48 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); |
36 } else { | 49 } else { |
37 desc->ice_ufrag = current_description->ice_ufrag; | 50 desc->ice_ufrag = current_description->ice_ufrag; |
38 desc->ice_pwd = current_description->ice_pwd; | 51 desc->ice_pwd = current_description->ice_pwd; |
39 } | 52 } |
40 | 53 |
41 // If we are trying to establish a secure transport, add a fingerprint. | 54 // If we are trying to establish a secure transport, add a fingerprint. |
42 if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) { | 55 if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) { |
43 // Fail if we can't create the fingerprint. | 56 // Fail if we can't create the fingerprint. |
44 // If we are the initiator set role to "actpass". | 57 // If we are the initiator set role to "actpass". |
45 if (!SetSecurityInfo(desc.get(), CONNECTIONROLE_ACTPASS)) { | 58 if (!SetSecurityInfo(desc.get(), CONNECTIONROLE_ACTPASS)) { |
46 return NULL; | 59 return NULL; |
47 } | 60 } |
48 } | 61 } |
49 | 62 |
50 return desc.release(); | 63 return desc.release(); |
51 } | 64 } |
52 | 65 |
53 TransportDescription* TransportDescriptionFactory::CreateAnswer( | 66 TransportDescription* TransportDescriptionFactory::CreateAnswer( |
54 const TransportDescription* offer, | 67 const TransportDescription* offer, |
55 const TransportOptions& options, | 68 const TransportOptions& options, |
56 const TransportDescription* current_description) const { | 69 const TransportDescription* current_description) const { |
| 70 // A NULL offer is treated as a GICE transport description. |
57 // TODO(juberti): Figure out why we get NULL offers, and fix this upstream. | 71 // TODO(juberti): Figure out why we get NULL offers, and fix this upstream. |
58 if (!offer) { | 72 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); |
59 LOG(LS_WARNING) << "Failed to create TransportDescription answer " << | 73 |
60 "because offer is NULL"; | 74 // Figure out which ICE variant to negotiate; prefer RFC 5245 ICE, but fall |
| 75 // back to G-ICE if needed. Note that we never create a hybrid answer, since |
| 76 // we know what the other side can support already. |
| 77 if (offer && offer->transport_type == NS_JINGLE_ICE_UDP && |
| 78 (protocol_ == ICEPROTO_RFC5245 || protocol_ == ICEPROTO_HYBRID)) { |
| 79 // Offer is ICE or hybrid, we support ICE or hybrid: use ICE. |
| 80 desc->transport_type = NS_JINGLE_ICE_UDP; |
| 81 } else if (offer && offer->transport_type == NS_JINGLE_ICE_UDP && |
| 82 offer->HasOption(ICE_OPTION_GICE) && |
| 83 protocol_ == ICEPROTO_GOOGLE) { |
| 84 desc->transport_type = NS_GINGLE_P2P; |
| 85 // Offer is hybrid, we support GICE: use GICE. |
| 86 } else if ((!offer || offer->transport_type == NS_GINGLE_P2P) && |
| 87 (protocol_ == ICEPROTO_HYBRID || protocol_ == ICEPROTO_GOOGLE)) { |
| 88 // Offer is GICE, we support hybrid or GICE: use GICE. |
| 89 desc->transport_type = NS_GINGLE_P2P; |
| 90 } else { |
| 91 // Mismatch. |
| 92 LOG(LS_WARNING) << "Failed to create TransportDescription answer " |
| 93 "because of incompatible transport types"; |
61 return NULL; | 94 return NULL; |
62 } | 95 } |
63 | 96 |
64 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); | |
65 // Generate the ICE credentials if we don't already have them or ice is | 97 // Generate the ICE credentials if we don't already have them or ice is |
66 // being restarted. | 98 // being restarted. |
67 if (!current_description || options.ice_restart) { | 99 if (!current_description || options.ice_restart) { |
68 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); | 100 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); |
69 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); | 101 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); |
70 } else { | 102 } else { |
71 desc->ice_ufrag = current_description->ice_ufrag; | 103 desc->ice_ufrag = current_description->ice_ufrag; |
72 desc->ice_pwd = current_description->ice_pwd; | 104 desc->ice_pwd = current_description->ice_pwd; |
73 } | 105 } |
74 | 106 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 << digest_alg; | 150 << digest_alg; |
119 return false; | 151 return false; |
120 } | 152 } |
121 | 153 |
122 // Assign security role. | 154 // Assign security role. |
123 desc->connection_role = role; | 155 desc->connection_role = role; |
124 return true; | 156 return true; |
125 } | 157 } |
126 | 158 |
127 } // namespace cricket | 159 } // namespace cricket |
| 160 |
OLD | NEW |