Example #1
0
Simulation::pointer
Topologies::separate(int nNodes, float quorumThresoldFraction,
                     Simulation::Mode mode, Hash const& networkID,
                     std::function<Config()> confGen)
{
    Simulation::pointer simulation =
        make_shared<Simulation>(mode, networkID, confGen);

    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());
    }
    return simulation;
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}
namespace stellar
{

TEST_CASE("TCPPeer can communicate", "[overlay]")
{
    Simulation::pointer s = std::make_shared<Simulation>(Simulation::OVER_TCP);

    auto v10SecretKey = SecretKey::fromSeed(sha256("v10"));
    auto v11SecretKey = SecretKey::fromSeed(sha256("v11"));

    SCPQuorumSet n0_qset;
    n0_qset.threshold = 1;
    n0_qset.validators.push_back(v10SecretKey.getPublicKey());
    auto n0 =
        s->getNode(s->addNode(v10SecretKey, n0_qset, s->getClock()));

    SCPQuorumSet n1_qset;
    n1_qset.threshold = 1;
    n1_qset.validators.push_back(v11SecretKey.getPublicKey());
    auto n1 =
        s->getNode(s->addNode(v11SecretKey, n1_qset, s->getClock()));

    s->startAllNodes();

    auto b = TCPPeer::initiate(*n0, "127.0.0.1", n1->getConfig().PEER_PORT);

    s->crankForAtLeast(std::chrono::seconds(3), false);

    REQUIRE(n0->getOverlayManager()
                .getConnectedPeer("127.0.0.1", n1->getConfig().PEER_PORT)
namespace stellar
{

TEST_CASE("TCPPeer can communicate", "[overlay]")
{
    Hash networkID = sha256(getTestConfig().NETWORK_PASSPHRASE);
    Simulation::pointer s =
        std::make_shared<Simulation>(Simulation::OVER_TCP, networkID);

    auto v10SecretKey = SecretKey::fromSeed(sha256("v10"));
    auto v11SecretKey = SecretKey::fromSeed(sha256("v11"));

    SCPQuorumSet n0_qset;
    n0_qset.threshold = 1;
    n0_qset.validators.push_back(v10SecretKey.getPublicKey());
    auto n0 = s->getNode(s->addNode(v10SecretKey, n0_qset, s->getClock()));

    SCPQuorumSet n1_qset;
    n1_qset.threshold = 1;
    n1_qset.validators.push_back(v11SecretKey.getPublicKey());
    auto n1 = s->getNode(s->addNode(v11SecretKey, n1_qset, s->getClock()));

    s->addPendingConnection(v10SecretKey.getPublicKey(),
                            v11SecretKey.getPublicKey());
    s->startAllNodes();
    s->crankForAtLeast(std::chrono::seconds(1), false);

    auto p0 = n0->getOverlayManager().getConnectedPeer(
                  "127.0.0.1", n1->getConfig().PEER_PORT);

    auto p1 = n1->getOverlayManager().getConnectedPeer(