Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "p2p/base/ice_credentials_iterator.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 12 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 13 | #include "p2p/base/p2p_constants.h" |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 14 | #include "rtc_base/helpers.h" |
| 15 | |
| 16 | namespace cricket { |
| 17 | |
| 18 | IceCredentialsIterator::IceCredentialsIterator( |
| 19 | const std::vector<IceParameters>& pooled_credentials) |
| 20 | : pooled_ice_credentials_(pooled_credentials) {} |
| 21 | |
| 22 | IceCredentialsIterator::~IceCredentialsIterator() = default; |
| 23 | |
| 24 | IceParameters IceCredentialsIterator::CreateRandomIceCredentials() { |
| 25 | return IceParameters(rtc::CreateRandomString(ICE_UFRAG_LENGTH), |
| 26 | rtc::CreateRandomString(ICE_PWD_LENGTH), false); |
| 27 | } |
| 28 | |
| 29 | IceParameters IceCredentialsIterator::GetIceCredentials() { |
| 30 | if (pooled_ice_credentials_.empty()) { |
| 31 | return CreateRandomIceCredentials(); |
| 32 | } |
| 33 | IceParameters credentials = pooled_ice_credentials_.back(); |
| 34 | pooled_ice_credentials_.pop_back(); |
| 35 | return credentials; |
| 36 | } |
| 37 | |
| 38 | } // namespace cricket |