<commit_before>#include "icesessiontester.h"

#include "icecandidatetester.h"
#include "ice.h"
#include "common.h"

#include <QEventLoop>
#include <QTimer>
#include <QThread>


IceSessionTester::IceSessionTester(bool controller, int timeout):
  pairs_(nullptr),
  sessionID_(0),
  controller_(controller),
  timeout_(timeout),
  components_(0)
{}


IceSessionTester::~IceSessionTester()
{}


void IceSessionTester::init(QList<std::shared_ptr<ICEPair>> *pairs,
                            uint32_t sessionID, uint8_t components)
{
  Q_ASSERT(pairs != nullptr);
  Q_ASSERT(sessionID != 0);
  pairs_ = pairs;
  sessionID_ = sessionID;
  components_ = components;
}


void IceSessionTester::nominationDone(std::shared_ptr<ICEPair> connection)
{
  Q_ASSERT(connection != nullptr);

  nominated_mtx.lock();
  finished_[connection->local->foundation][connection->local->component] = connection;

  if (finished_[connection->local->foundation].size() == components_)
  {
    for (auto& pair : finished_[connection->local->foundation])
    {
      pair->state = PAIR_SUCCEEDED;
      nominated_.push_back(pair);
    }
<commit_msg>fix(Negotiation): Avoid nominating more than one candidate.<commit_after>#include "icesessiontester.h"

#include "icecandidatetester.h"
#include "ice.h"
#include "common.h"

#include <QEventLoop>
#include <QTimer>
#include <QThread>


IceSessionTester::IceSessionTester(bool controller, int timeout):
  pairs_(nullptr),
  sessionID_(0),
  controller_(controller),
  timeout_(timeout),
  components_(0)
{}


IceSessionTester::~IceSessionTester()
{}


void IceSessionTester::init(QList<std::shared_ptr<ICEPair>> *pairs,
                            uint32_t sessionID, uint8_t components)
{
  Q_ASSERT(pairs != nullptr);
  Q_ASSERT(sessionID != 0);
  pairs_ = pairs;
  sessionID_ = sessionID;
  components_ = components;
}


void IceSessionTester::nominationDone(std::shared_ptr<ICEPair> connection)
{
  Q_ASSERT(connection != nullptr);

  nominated_mtx.lock();
  finished_[connection->local->foundation][connection->local->component] = connection;

  // nominated check makes sure only one stream is nominated.
  // if we have received all components, nominate these.
  // TODO: Do some sort of prioritization here
  if (nominated_.empty() && finished_[connection->local->foundation].size() == components_)
  {
    for (auto& pair : finished_[connection->local->foundation])
    {
      pair->state = PAIR_SUCCEEDED;
      nominated_.push_back(pair);
    }

{'fraction_non_alphanumeric': 0.13206785137318255, 'fraction_numerical': 0.004846526655896607, 'mean_word_length': 4.814553990610329, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2972350', 'n_tokens_mistral': 805, 'n_tokens_neox': 791, 'n_words': 149}