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/sslfingerprint.h" | 17 #include "webrtc/base/sslfingerprint.h" |
18 | 18 |
19 namespace cricket { | 19 namespace cricket { |
20 | 20 |
21 TransportDescriptionFactory::TransportDescriptionFactory() | 21 TransportDescriptionFactory::TransportDescriptionFactory() |
22 : secure_(SEC_DISABLED) { | 22 : secure_(SEC_DISABLED) { |
23 } | 23 } |
24 | 24 |
25 TransportDescription* TransportDescriptionFactory::CreateOffer( | 25 TransportDescription* TransportDescriptionFactory::CreateOffer( |
26 const TransportOptions& options, | 26 const TransportOptions& options, |
| 27 bool ice_restart, |
27 const TransportDescription* current_description) const { | 28 const TransportDescription* current_description) const { |
28 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); | 29 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); |
29 | 30 |
30 // Generate the ICE credentials if we don't already have them. | 31 // Generate the ICE credentials if we don't already have them. |
31 if (!current_description || options.ice_restart) { | 32 if (!current_description || ice_restart) { |
32 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); | 33 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); |
33 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); | 34 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); |
34 } else { | 35 } else { |
35 desc->ice_ufrag = current_description->ice_ufrag; | 36 desc->ice_ufrag = current_description->ice_ufrag; |
36 desc->ice_pwd = current_description->ice_pwd; | 37 desc->ice_pwd = current_description->ice_pwd; |
37 } | 38 } |
38 | 39 |
39 // If we are trying to establish a secure transport, add a fingerprint. | 40 // If we are trying to establish a secure transport, add a fingerprint. |
40 if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) { | 41 if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) { |
41 // Fail if we can't create the fingerprint. | 42 // Fail if we can't create the fingerprint. |
42 // If we are the initiator set role to "actpass". | 43 // If we are the initiator set role to "actpass". |
43 if (!SetSecurityInfo(desc.get(), CONNECTIONROLE_ACTPASS)) { | 44 if (!SetSecurityInfo(desc.get(), CONNECTIONROLE_ACTPASS)) { |
44 return NULL; | 45 return NULL; |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 return desc.release(); | 49 return desc.release(); |
49 } | 50 } |
50 | 51 |
51 TransportDescription* TransportDescriptionFactory::CreateAnswer( | 52 TransportDescription* TransportDescriptionFactory::CreateAnswer( |
52 const TransportDescription* offer, | 53 const TransportDescription* offer, |
53 const TransportOptions& options, | 54 const TransportOptions& options, |
| 55 bool ice_restart, |
54 const TransportDescription* current_description) const { | 56 const TransportDescription* current_description) const { |
55 // 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. |
56 if (!offer) { | 58 if (!offer) { |
57 LOG(LS_WARNING) << "Failed to create TransportDescription answer " << | 59 LOG(LS_WARNING) << "Failed to create TransportDescription answer " << |
58 "because offer is NULL"; | 60 "because offer is NULL"; |
59 return NULL; | 61 return NULL; |
60 } | 62 } |
61 | 63 |
62 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); | 64 rtc::scoped_ptr<TransportDescription> desc(new TransportDescription()); |
63 // 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 |
64 // being restarted. | 66 // being restarted. |
65 if (!current_description || options.ice_restart) { | 67 if (!current_description || ice_restart) { |
66 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); | 68 desc->ice_ufrag = rtc::CreateRandomString(ICE_UFRAG_LENGTH); |
67 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); | 69 desc->ice_pwd = rtc::CreateRandomString(ICE_PWD_LENGTH); |
68 } else { | 70 } else { |
69 desc->ice_ufrag = current_description->ice_ufrag; | 71 desc->ice_ufrag = current_description->ice_ufrag; |
70 desc->ice_pwd = current_description->ice_pwd; | 72 desc->ice_pwd = current_description->ice_pwd; |
71 } | 73 } |
72 | 74 |
73 // Negotiate security params. | 75 // Negotiate security params. |
74 if (offer && offer->identity_fingerprint.get()) { | 76 if (offer && offer->identity_fingerprint.get()) { |
75 // The offer supports DTLS, so answer with DTLS, as long as we support it. | 77 // The offer supports DTLS, so answer with DTLS, as long as we support it. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 << digest_alg; | 119 << digest_alg; |
118 return false; | 120 return false; |
119 } | 121 } |
120 | 122 |
121 // Assign security role. | 123 // Assign security role. |
122 desc->connection_role = role; | 124 desc->connection_role = role; |
123 return true; | 125 return true; |
124 } | 126 } |
125 | 127 |
126 } // namespace cricket | 128 } // namespace cricket |
OLD | NEW |