blob: 373c8510ac264b5785c2493cb1f4f676b48576e8 [file] [log] [blame]
Jonas Oreland1cd39fa2018-10-11 05:47:121/*
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 Anton10542f22019-01-11 17:11:0011#include "p2p/base/ice_credentials_iterator.h"
Yves Gerey3e707812018-11-28 15:47:4912
Steve Anton10542f22019-01-11 17:11:0013#include "p2p/base/p2p_constants.h"
Jonas Oreland1cd39fa2018-10-11 05:47:1214#include "rtc_base/helpers.h"
15
16namespace cricket {
17
18IceCredentialsIterator::IceCredentialsIterator(
19 const std::vector<IceParameters>& pooled_credentials)
20 : pooled_ice_credentials_(pooled_credentials) {}
21
22IceCredentialsIterator::~IceCredentialsIterator() = default;
23
24IceParameters IceCredentialsIterator::CreateRandomIceCredentials() {
25 return IceParameters(rtc::CreateRandomString(ICE_UFRAG_LENGTH),
26 rtc::CreateRandomString(ICE_PWD_LENGTH), false);
27}
28
29IceParameters 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