Exemple #1
0
  TEST(Session, ClientsServers)
  {
    Timer::GetInstance().UseVirtualTime();
    ConnectionManager::UseTimer = false;
    OverlayNetwork net = ConstructOverlay(10, 20);
    VerifyStoppedNetwork(net);
    StartNetwork(net);
    VerifyNetwork(net);

    Sessions sessions = BuildSessions(net);
    qDebug() << "Starting sessions...";
    StartSessions(sessions);
    StartRound(sessions);
    SendTest(sessions);
    SendTest(sessions);
    DisconnectServer(sessions, true);
    SendTest(sessions);
    DisconnectServer(sessions, false);
    SendTest(sessions);
    SendTest(sessions);
    StopSessions(sessions);

    StopNetwork(sessions.network);
    VerifyStoppedNetwork(sessions.network);
    ConnectionManager::UseTimer = true;
  }
NetworkManager::~NetworkManager()
{
    StopNetwork();

    acceptor_.reset();
    network_threads_.reset();
}
Exemple #3
0
  void TestRoundBad(CreateRound good_cr, CreateRound bad_cr,
      const BadGuyCB &callback, bool client, bool will_finish)
  {
    int servers = 3, clients = 10;
    ConnectionManager::UseTimer = false;
    Timer::GetInstance().UseVirtualTime();
    OverlayNetwork net = ConstructOverlay(servers, clients);
    VerifyStoppedNetwork(net);
    StartNetwork(net);
    VerifyNetwork(net);

    Sessions sessions = BuildSessions(net, good_cr);
    // Find a bad guy and replace him...
    int badguy = Random::GetInstance().GetInt(0, clients);
    Id badid = net.second[badguy]->GetId();

    if(!client) {
      badguy = Random::GetInstance().GetInt(0, servers);
      badid = net.first[badguy]->GetId();
    }

    qDebug() << "Bad guy at" << badguy << badid;
    QSharedPointer<AsymmetricKey> key =
      sessions.private_keys[badid.ToString()];

    if(client) {
      ClientPointer cs = MakeSession<ClientSession>(
          net.second[badguy], key, sessions.keys, bad_cr);
      cs->SetSink(sessions.sink_multiplexers[servers + badguy].data());
      sessions.clients[badguy] = cs;
    } else {
      ServerPointer ss = MakeSession<ServerSession>(
          net.first[badguy], key, sessions.keys, bad_cr);
      ss->SetSink(sessions.sink_multiplexers[badguy].data());
      sessions.servers[badguy] = ss;
    }

    // Find a sender != badguy
    int sender = Random::GetInstance().GetInt(0, clients);
    if(client) {
      while(sender == badguy) {
        sender = Random::GetInstance().GetInt(0, clients);
      }
    }
    QByteArray msg(64, 0);
    CryptoRandom().GenerateBlock(msg);
    sessions.clients[sender]->Send(msg);

    qDebug() << "Starting sessions...";
    StartSessions(sessions);
    StartRound(sessions);

    QSharedPointer<Round> bad_round;
    if(client) {
      bad_round = sessions.clients[badguy]->GetRound();
    } else {
      bad_round = sessions.servers[badguy]->GetRound();
    }

    SignalCounter sc;
    for(int idx = 0; idx < servers; idx++) {
      QObject::connect(sessions.servers[idx].data(),
          SIGNAL(RoundFinished(const QSharedPointer<Anonymity::Round> &)),
          &sc, SLOT(Counter()));
    }

    for(int idx = 0; idx < clients; idx++) {
      QObject::connect(sessions.clients[idx].data(),
          SIGNAL(RoundFinished(const QSharedPointer<Anonymity::Round> &)),
          &sc, SLOT(Counter()));
    }

    RunUntil(sc, clients + servers);
    if(will_finish) {
      ASSERT_EQ(sc.GetCount(), clients + servers);
      ASSERT_EQ(bad_round->GetBadMembers().size(), 1);
      ASSERT_EQ(badid, bad_round->GetBadMembers()[0]);
    }

    if(!callback(bad_round.data())) {
      std::cout << "RoundTest_BadGuy was never triggered, "
        "consider rerunning." << std::endl;
    }

    StopNetwork(sessions.network);
    VerifyStoppedNetwork(sessions.network);
    ConnectionManager::UseTimer = true;
  }