Пример #1
0
Simulation::pointer
Topologies::cycle4(Hash const& networkID, std::function<Config()> confGen)
{
    Simulation::pointer simulation =
        make_shared<Simulation>(Simulation::OVER_LOOPBACK, networkID, confGen);

    SIMULATION_CREATE_NODE(0);
    SIMULATION_CREATE_NODE(1);
    SIMULATION_CREATE_NODE(2);
    SIMULATION_CREATE_NODE(3);

    SCPQuorumSet qSet0;
    qSet0.threshold = 2;
    qSet0.validators.push_back(v1NodeID);
    qSet0.validators.push_back(v0NodeID);
    SCPQuorumSet qSet1;
    qSet1.threshold = 2;
    qSet1.validators.push_back(v1NodeID);
    qSet1.validators.push_back(v2NodeID);
    SCPQuorumSet qSet2;
    qSet2.threshold = 2;
    qSet2.validators.push_back(v2NodeID);
    qSet2.validators.push_back(v3NodeID);
    SCPQuorumSet qSet3;
    qSet3.threshold = 2;
    qSet3.validators.push_back(v3NodeID);
    qSet3.validators.push_back(v0NodeID);

    auto n0 = simulation->addNode(v0SecretKey, qSet0, simulation->getClock());
    auto n1 = simulation->addNode(v1SecretKey, qSet1, simulation->getClock());
    auto n2 = simulation->addNode(v2SecretKey, qSet2, simulation->getClock());
    auto n3 = simulation->addNode(v3SecretKey, qSet3, simulation->getClock());

    simulation->addPendingConnection(n0, n1);
    simulation->addPendingConnection(n1, n2);
    simulation->addPendingConnection(n2, n3);
    simulation->addPendingConnection(n3, n0);

    simulation->addPendingConnection(n0, n2);
    simulation->addPendingConnection(n1, n3);

    return simulation;
}
Пример #2
0
Simulation::pointer
Topologies::pair(Simulation::Mode mode, Hash const& networkID)
{
    Simulation::pointer simulation = make_shared<Simulation>(mode, networkID);

    SIMULATION_CREATE_NODE(10);
    SIMULATION_CREATE_NODE(11);

    SCPQuorumSet qSet0;
    qSet0.threshold = 2;
    qSet0.validators.push_back(v10NodeID);
    qSet0.validators.push_back(v11NodeID);

    auto n0 = simulation->addNode(v10SecretKey, qSet0, simulation->getClock());
    auto n1 = simulation->addNode(v11SecretKey, qSet0, simulation->getClock());

    simulation->addPendingConnection(n0, n1);
    return simulation;
}
Пример #3
0
Simulation::pointer
Topologies::core(int nNodes, float quorumThresoldFraction,
                 Simulation::Mode mode, Hash const& networkID)
{
    Simulation::pointer simulation = make_shared<Simulation>(mode, networkID);

    vector<SecretKey> keys;
    for (int i = 0; i < nNodes; i++)
    {
        keys.push_back(SecretKey::fromSeed(
            sha256("NODE_SEED_" + to_string(i))));
    }

    SCPQuorumSet qSet;
    assert(quorumThresoldFraction >= 0.5);
    qSet.threshold =
        min(nNodes, static_cast<int>(ceil(nNodes * quorumThresoldFraction)));
    for (auto const& k : keys)
    {
        qSet.validators.push_back(k.getPublicKey());
    }

    for (auto const& k : keys)
    {
        simulation->addNode(k, qSet, simulation->getClock());
    }
    for (int from = 0; from < nNodes - 1; from++)
    {
        for (int to = from + 1; to < nNodes; to++)
        {
            simulation->addPendingConnection(keys[from].getPublicKey(),
                                             keys[to].getPublicKey());
        }
    }

    return simulation;
}