<commit_before>/*
 * System_detectFailure.cpp
 *
 *  Created on: Jun 15, 2014
 *      Author: Pimenta
 */

// this
#include "System.hpp"

// local
#include "Defines.hpp"

void System::detectFailure() {
  for (auto it = users.begin(); it != users.end();) {
    if (it->second.timer.time() >= MS_DETECTFAILURE)
      users.erase(it++);
    else
      ++it;
  }
}<commit_msg>Now, we're detecting failure for REAL<commit_after>/*
 * System_detectFailure.cpp
 *
 *  Created on: Jun 15, 2014
 *      Author: Pimenta
 */

// this
#include "System.hpp"

// local
#include "Defines.hpp"
#include "FD8Protocol.hpp"

using namespace std;
using namespace network;
using namespace fd8protocol;

void System::detectFailure() {
  set<uint32_t> peers;
  for (auto it = users.begin(); it != users.end();) {
    if (it->second.timer.time() >= MS_DETECTFAILURE) {
      users.erase(it++);
    }
    else {
      peers.insert(it->first);
      ++it;
    }
  }
  
  if (state == STATE_LOGIN)
    return;
  
  uint32_t designatedPeer = 0xFFFFFFFF;
  for (auto& kv : users) {
    if (kv.first < designatedPeer)
      designatedPeer = kv.first;
  }
  if (designatedPeer == localAddress.ip) {
    list<FileSystem::DuplicationCommand> cmds = FileSystem::calculateDuplications(peers);
    for (auto& kv : users) {
      if (kv.first == localAddress.ip)
        continue;
      TCPConnection conn(Address(kv.first, Address("", TCPUDP_MAIN).port));
      conn.send(char(MTYPE_DUPLICATION));
      conn.send(uint32_t(cmds.size()));
      for (auto& cmd : cmds){
        conn.send(&cmd, 12);
      }
    }
    send_fileDuplications(cmds);
  }
}
{'fraction_non_alphanumeric': 0.15437073775573465, 'fraction_numerical': 0.01425914445133292, 'mean_word_length': 2.9851851851851854, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '492016', 'n_tokens_mistral': 585, 'n_tokens_neox': 562, 'n_words': 120}