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 | |
24 TransportDescriptionFactory::TransportDescriptionFactory() | 22 TransportDescriptionFactory::TransportDescriptionFactory() |
25 : protocol_(kDefaultProtocol), | 23 : secure_(SEC_DISABLED), |
26 secure_(SEC_DISABLED), | |
27 identity_(NULL) { | 24 identity_(NULL) { |
28 } | 25 } |
29 | 26 |
30 TransportDescription* TransportDescriptionFactory::CreateOffer( | 27 TransportDescription* TransportDescriptionFactory::CreateOffer( |
31 const TransportOptions& options, | 28 const TransportOptions& options, |
32 const TransportDescription* current_description) const { | 29 const TransportDescription* current_description) const { |
33 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); | 30 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); |
34 | 31 |
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 | |
45 // Generate the ICE credentials if we don't already have them. | 32 // Generate the ICE credentials if we don't already have them. |
46 if (!current_description || options.ice_restart) { | 33 if (!current_description || options.ice_restart) { |
47 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); | 34 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); |
48 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); | 35 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); |
49 } else { | 36 } else { |
50 desc->ice_ufrag = current_description->ice_ufrag; | 37 desc->ice_ufrag = current_description->ice_ufrag; |
51 desc->ice_pwd = current_description->ice_pwd; | 38 desc->ice_pwd = current_description->ice_pwd; |
52 } | 39 } |
53 | 40 |
54 // If we are trying to establish a secure transport, add a fingerprint. | 41 // If we are trying to establish a secure transport, add a fingerprint. |
55 if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) { | 42 if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) { |
56 // Fail if we can't create the fingerprint. | 43 // Fail if we can't create the fingerprint. |
57 // If we are the initiator set role to "actpass". | 44 // If we are the initiator set role to "actpass". |
58 if (!SetSecurityInfo(desc.get(), CONNECTIONROLE_ACTPASS)) { | 45 if (!SetSecurityInfo(desc.get(), CONNECTIONROLE_ACTPASS)) { |
59 return NULL; | 46 return NULL; |
60 } | 47 } |
61 } | 48 } |
62 | 49 |
63 return desc.release(); | 50 return desc.release(); |
64 } | 51 } |
65 | 52 |
66 TransportDescription* TransportDescriptionFactory::CreateAnswer( | 53 TransportDescription* TransportDescriptionFactory::CreateAnswer( |
67 const TransportDescription* offer, | 54 const TransportDescription* offer, |
68 const TransportOptions& options, | 55 const TransportOptions& options, |
69 const TransportDescription* current_description) const { | 56 const TransportDescription* current_description) const { |
70 // A NULL offer is treated as a GICE transport description. | |
71 // TODO(juberti): Figure out why we get NULL offers, and fix this upstream. | 57 // TODO(juberti): Figure out why we get NULL offers, and fix this upstream. |
72 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); | 58 if (!offer) { |
73 | 59 LOG(LS_WARNING) << "Failed to create TransportDescription answer " << |
74 // Figure out which ICE variant to negotiate; prefer RFC 5245 ICE, but fall | 60 "because offer is NULL"; |
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"; | |
94 return NULL; | 61 return NULL; |
95 } | 62 } |
96 | 63 |
| 64 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); |
97 // Generate the ICE credentials if we don't already have them or ice is | 65 // Generate the ICE credentials if we don't already have them or ice is |
98 // being restarted. | 66 // being restarted. |
99 if (!current_description || options.ice_restart) { | 67 if (!current_description || options.ice_restart) { |
100 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); | 68 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); |
101 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); | 69 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); |
102 } else { | 70 } else { |
103 desc->ice_ufrag = current_description->ice_ufrag; | 71 desc->ice_ufrag = current_description->ice_ufrag; |
104 desc->ice_pwd = current_description->ice_pwd; | 72 desc->ice_pwd = current_description->ice_pwd; |
105 } | 73 } |
106 | 74 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 << digest_alg; | 118 << digest_alg; |
151 return false; | 119 return false; |
152 } | 120 } |
153 | 121 |
154 // Assign security role. | 122 // Assign security role. |
155 desc->connection_role = role; | 123 desc->connection_role = role; |
156 return true; | 124 return true; |
157 } | 125 } |
158 | 126 |
159 } // namespace cricket | 127 } // namespace cricket |
160 | |
OLD | NEW |