void SendTest(const Sessions &sessions) { qDebug() << "Starting SendTest"; QList<QByteArray> messages; CryptoRandom rand; foreach(const QSharedPointer<BufferSink> &sink, sessions.sinks) { sink->Clear(); } SignalCounter sc; foreach(const QSharedPointer<SignalSink> &ssink, sessions.signal_sinks) { QObject::connect(ssink.data(), SIGNAL(IncomingData(const QByteArray &)), &sc, SLOT(Counter())); } foreach(const ClientPointer &cs, sessions.clients) { QByteArray msg(64, 0); rand.GenerateBlock(msg); messages.append(msg); cs->Send(msg); } RunUntil(sc, sessions.clients.size() * (sessions.clients.size() + sessions.servers.size())); foreach(const QSharedPointer<BufferSink> &sink, sessions.sinks) { ASSERT_EQ(messages.size(), sink->Count()); for(int idx = 0; idx < sink->Count(); idx++) { ASSERT_TRUE(messages.contains(sink->At(idx).second)); } } qDebug() << "Finished SendTest"; }
void CompleteRound(const Sessions &sessions) { SignalCounter counter; foreach(const ServerPointer &ss, sessions.servers) { QObject::connect(ss.data(), SIGNAL(RoundFinished(const QSharedPointer<Anonymity::Round> &)), &counter, SLOT(Counter())); } foreach(const ClientPointer &cs, sessions.clients) { QObject::connect(cs.data(), SIGNAL(RoundFinished(const QSharedPointer<Anonymity::Round> &)), &counter, SLOT(Counter())); } RunUntil(counter, sessions.servers.count() + sessions.clients.count()); }
void CMLineIndexTable::HandleMouseDown ( const JPoint& pt, const JXMouseButton button, const JSize clickCount, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { if (ScrollForWheel(button, modifiers, NULL, itsVScrollbar)) { return; } JPoint cell; if (!GetCell(pt, &cell)) { return; } itsText->SelectLine(cell.y); const JIndex lineIndex = itsText->VisualLineIndexToCRLineIndex(cell.y); if (button == kJXRightButton) { OpenLineMenu(lineIndex, pt, buttonStates, modifiers, kJFalse); } else if (button == kJXLeftButton && modifiers.GetState(JXMenu::AdjustNMShortcutModifier(kJXMetaKeyIndex)) && !modifiers.shift()) { RunUntil(lineIndex); } else if (button == kJXLeftButton && modifiers.GetState(JXMenu::AdjustNMShortcutModifier(kJXControlKeyIndex))) { SetExecutionPoint(lineIndex); } else if (button == kJXLeftButton) { AdjustBreakpoints(lineIndex, pt, buttonStates, modifiers); } }
TEST(Connection, Timeout) { Timer::GetInstance().UseVirtualTime(); SignalCounter sc_new; SignalCounter sc_close; const BufferAddress addr0(1000); QSharedPointer<EdgeListener> be0(EdgeListenerFactory::GetInstance().CreateEdgeListener(addr0)); QSharedPointer<RpcHandler> rpc0(new RpcHandler()); Id id0; ConnectionManager cm0(id0, rpc0); QObject::connect(&cm0, SIGNAL(NewConnection(const QSharedPointer<Connection> &)), &sc_new, SLOT(Counter())); cm0.AddEdgeListener(be0); be0->Start(); cm0.Start(); const BufferAddress addr1(10001); QSharedPointer<EdgeListener> be1(EdgeListenerFactory::GetInstance().CreateEdgeListener(addr1)); QSharedPointer<RpcHandler> rpc1(new RpcHandler()); Id id1; ConnectionManager cm1(id1, rpc1); QObject::connect(&cm1, SIGNAL(NewConnection(const QSharedPointer<Connection> &)), &sc_new, SLOT(Counter())); cm1.AddEdgeListener(QSharedPointer<EdgeListener>(be1)); be1->Start(); cm1.Start(); ASSERT_FALSE(cm0.GetConnectionTable().GetConnection(id1)); ASSERT_FALSE(cm1.GetConnectionTable().GetConnection(id0)); cm1.ConnectTo(addr0); RunUntil(sc_new, 2); ASSERT_TRUE(cm0.GetConnectionTable().GetConnection(id1)); ASSERT_TRUE(cm1.GetConnectionTable().GetConnection(id0)); QObject::connect(cm0.GetConnectionTable().GetConnection(id1)->GetEdge().data(), SIGNAL(StoppedSignal()), &sc_close, SLOT(Counter())); QObject::connect(cm1.GetConnectionTable().GetConnection(id0)->GetEdge().data(), SIGNAL(StoppedSignal()), &sc_close, SLOT(Counter())); cm0.GetConnectionTable().GetConnection(id1)->GetEdge()->Stop("For fun"); RunUntil(sc_close, 1); ASSERT_FALSE(cm0.GetConnectionTable().GetConnection(id1)); ASSERT_TRUE(cm1.GetConnectionTable().GetConnection(id0)); RunUntil(sc_close, 2); ASSERT_FALSE(cm0.GetConnectionTable().GetConnection(id1)); ASSERT_FALSE(cm1.GetConnectionTable().GetConnection(id0)); cm1.Stop(); cm0.Stop(); qint64 next = Timer::GetInstance().VirtualRun(); while(next != -1) { Time::GetInstance().IncrementVirtualClock(next); next = Timer::GetInstance().VirtualRun(); } }
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; }
void CMLineIndexTable::HandleLineMenu ( const JIndex index ) { // line JSize offset = 0; if (itsIsFullLineMenuFlag) { if (index == offset + kRunUntilCmd) { RunUntil(itsLineMenuLineIndex); return; } else if (index == offset + kSetExecPtCmd) { SetExecutionPoint(itsLineMenuLineIndex); return; } offset += kLineMenuItemCount; } // all breakpoints if (index == offset + kSetBreakpointCmd) { SetBreakpoint(itsLineMenuLineIndex, kJFalse); return; } else if (index == offset + kSetTempBreakpointCmd) { SetBreakpoint(itsLineMenuLineIndex, kJTrue); return; } else if (index == offset + kRemoveAllBreakpointsCmd) { RemoveAllBreakpointsOnLine(itsLineMenuLineIndex); return; } offset += kAllBreakpointsMenuItemCount; // individual breakpoints if (!itsLineMenuBPRange.IsNothing()) { for (JIndex i=itsLineMenuBPRange.first; i<=itsLineMenuBPRange.last; i++) { CMBreakpoint* bp = itsBPList->NthElement(i); if (index == offset + kShowBreakpointInfoCmd) { (itsDirector->GetCommandDirector()->GetBreakpointsDir()->GetBreakpointTable())->Show(bp); return; } else if (index == offset + kRemoveBreakpointCmd) { itsLink->RemoveBreakpoint(*bp); return; } else if (index == offset + kSetConditionCmd) { (itsDirector->GetCommandDirector()->GetBreakpointsDir()->GetBreakpointTable())->EditCondition(bp); return; } else if (index == offset + kRemoveConditionCmd) { bp->RemoveCondition(); return; } else if (index == offset + kToggleEnableCmd) { bp->ToggleEnabled(); return; } else if (index == offset + kIgnoreNextNCmd) { (itsDirector->GetCommandDirector()->GetBreakpointsDir()->GetBreakpointTable())->EditIgnoreCount(bp); return; } offset += kBreakpointMenuItemCount; } } }