aboutsummaryrefslogtreecommitdiffstats
path: root/net.cpp
diff options
context:
space:
mode:
authorsubtly <subtly@users.noreply.github.com>2014-12-23 16:25:36 +0800
committersubtly <subtly@users.noreply.github.com>2014-12-23 16:25:36 +0800
commitcb6517e99e568b01bd46eba5b1c403cea6ea3428 (patch)
tree3ce258a14bdf26415e3403d5f2b5b78f75eb1961 /net.cpp
parent1e0d4c95ce3d788b0be8cb5b8b32ede72683e7ae (diff)
downloaddexon-solidity-cb6517e99e568b01bd46eba5b1c403cea6ea3428.tar.gz
dexon-solidity-cb6517e99e568b01bd46eba5b1c403cea6ea3428.tar.zst
dexon-solidity-cb6517e99e568b01bd46eba5b1c403cea6ea3428.zip
send/receive messages (not yet interepreted)
Diffstat (limited to 'net.cpp')
-rw-r--r--net.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/net.cpp b/net.cpp
index 886e17a4..d3aaae53 100644
--- a/net.cpp
+++ b/net.cpp
@@ -49,21 +49,10 @@ protected:
struct TestNodeTable: public NodeTable
{
- void generateTestNodes(int _count = 10)
- {
- asserts(_count < 1000);
- static uint16_t s_basePort = 30500;
-
- m_testNodes.clear();
- for (auto i = 0; i < _count; i++)
- m_testNodes.push_back(make_pair(KeyPair::create(),s_basePort++));
- }
- std::vector<std::pair<KeyPair,unsigned>> m_testNodes; // keypair and port
-
/// Constructor
using NodeTable::NodeTable;
- void setup()
+ void setup(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes)
{
/// Phase 1 test: populate with pings
/// Phase 2 test: pre-populate *expected* ping-responses, send pings
@@ -72,8 +61,7 @@ struct TestNodeTable: public NodeTable
uint16_t ourPort = 30300;
bi::udp::endpoint ourEndpoint(ourIp, ourPort);
- generateTestNodes();
- for (auto& n: m_testNodes)
+ for (auto& n: _testNodes)
ping(bi::udp::endpoint(ourIp, n.second));
// wait 1ms between each send
@@ -94,8 +82,32 @@ struct TestNodeTable: public NodeTable
*/
struct TestNodeTableHost: public TestHost
{
- TestNodeTableHost(): nodeTable(new TestNodeTable(m_io)) {};
+ TestNodeTableHost(): m_alias(KeyPair::create()), nodeTable(new TestNodeTable(m_io, m_alias)) {};
+
+ void generateTestNodes(int _count = 10)
+ {
+ asserts(_count < 1000);
+ static uint16_t s_basePort = 30500;
+
+ m_testNodes.clear();
+ for (auto i = 0; i < _count; i++)
+ {
+ KeyPair k = KeyPair::create();
+ m_testNodes.push_back(make_pair(k,s_basePort+i));
+ testNodes.push_back(make_shared<TestNodeTable>(m_io,k,s_basePort+i));
+ }
+ }
+ std::vector<std::pair<KeyPair,unsigned>> m_testNodes; // keypair and port
+
+ void setup()
+ {
+ generateTestNodes();
+ nodeTable->setup(m_testNodes);
+ }
+
+ KeyPair m_alias;
shared_ptr<TestNodeTable> nodeTable;
+ std::vector<shared_ptr<TestNodeTable>> testNodes;
};
class TestUDPSocket: UDPSocketEvents, public TestHost
@@ -113,11 +125,11 @@ public:
BOOST_AUTO_TEST_CASE(kademlia)
{
-// TestNodeTableHost node;
-// node.start();
-// node.nodeTable->join(); // ideally, joining with empty node table logs warning we can check for
-// node.nodeTable->setup();
-// sleep(1);
+ TestNodeTableHost node;
+ node.start();
+ node.nodeTable->join(); // ideally, joining with empty node table logs warning we can check for
+ node.setup();
+ sleep(1);
}
BOOST_AUTO_TEST_CASE(test_txrx_one)