Browse Source

inline << operator, mute logging

cl-refactor
subtly 10 years ago
parent
commit
cffc27417a
  1. 16
      libp2p/NodeTable.cpp
  2. 4
      libp2p/NodeTable.h
  3. 14
      test/net.cpp

16
libp2p/NodeTable.cpp

@ -247,12 +247,18 @@ void NodeTable::noteNode(Public const& _pubk, bi::udp::endpoint const& _endpoint
{
node.reset(new NodeEntry(m_node, id, _pubk, _endpoint));
m_nodes[id] = node;
// clog(NodeTableMessageSummary) << "Adding node to cache: " << id;
}
else
{
node = n->second;
// clog(NodeTableMessageSummary) << "Found node in cache: " << id;
}
}
noteNode(node);
// todo: why is this necessary?
if (!!node)
noteNode(node);
}
void NodeTable::noteNode(std::shared_ptr<NodeEntry> _n)
@ -335,7 +341,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
switch (itemCount) {
case 1:
{
clog(NodeTableMessageSummary) << "Received Pong from " << _from.address().to_string() << ":" << _from.port();
// clog(NodeTableMessageSummary) << "Received Pong from " << _from.address().to_string() << ":" << _from.port();
Pong in = Pong::fromBytesConstRef(_from, rlpBytes);
// whenever a pong is received, first check if it's in m_evictions
@ -347,13 +353,13 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
if (rlp[0].isList())
{
Neighbors in = Neighbors::fromBytesConstRef(_from, rlpBytes);
clog(NodeTableMessageSummary) << "Received " << in.nodes.size() << " Neighbors from " << _from.address().to_string() << ":" << _from.port();
// clog(NodeTableMessageSummary) << "Received " << in.nodes.size() << " Neighbors from " << _from.address().to_string() << ":" << _from.port();
for (auto n: in.nodes)
noteNode(n.node, bi::udp::endpoint(bi::address::from_string(n.ipAddress), n.port));
}
else
{
clog(NodeTableMessageSummary) << "Received FindNode from " << _from.address().to_string() << ":" << _from.port();
// clog(NodeTableMessageSummary) << "Received FindNode from " << _from.address().to_string() << ":" << _from.port();
FindNode in = FindNode::fromBytesConstRef(_from, rlpBytes);
std::vector<std::shared_ptr<NodeTable::NodeEntry>> nearest = findNearest(in.target);
@ -369,7 +375,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
case 3:
{
clog(NodeTableMessageSummary) << "Received PingNode from " << _from.address().to_string() << ":" << _from.port();
// clog(NodeTableMessageSummary) << "Received PingNode from " << _from.address().to_string() << ":" << _from.port();
PingNode in = PingNode::fromBytesConstRef(_from, rlpBytes);
Pong p(_from);

4
libp2p/NodeTable.h

@ -197,7 +197,7 @@ protected:
boost::asio::deadline_timer m_evictionCheckTimer; ///< Timer for handling node evictions.
};
std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable)
inline std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable)
{
_out << _nodeTable.root().address() << "\t" << "0\t" << _nodeTable.root().endpoint.udp.address() << ":" << _nodeTable.root().endpoint.udp.port() << std::endl;
auto s = _nodeTable.state();
@ -205,7 +205,7 @@ std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable)
_out << n.address() << "\t" << n.distance << "\t" << n.endpoint.udp.address() << ":" << n.endpoint.udp.port() << std::endl;
return _out;
}
/**
* Ping packet: Check if node is alive.
* PingNode is cached and regenerated after expiration - t, where t is timeout.

14
test/net.cpp

@ -53,14 +53,14 @@ struct TestNodeTable: public NodeTable
/// Constructor
using NodeTable::NodeTable;
static std::vector<std::pair<KeyPair,unsigned>> createTestNodes(int _count = 16)
static std::vector<std::pair<KeyPair,unsigned>> createTestNodes(unsigned _count)
{
std::vector<std::pair<KeyPair,unsigned>> ret;
asserts(_count < 1000);
static uint16_t s_basePort = 30500;
ret.clear();
for (auto i = 0; i < _count; i++)
for (unsigned i = 0; i < _count; i++)
{
KeyPair k = KeyPair::create();
ret.push_back(make_pair(k,s_basePort+i));
@ -75,7 +75,7 @@ struct TestNodeTable: public NodeTable
for (auto& n: _testNodes)
{
ping(bi::udp::endpoint(ourIp, n.second));
this_thread::sleep_for(chrono::milliseconds(5));
this_thread::sleep_for(chrono::milliseconds(2));
}
}
@ -104,7 +104,7 @@ struct TestNodeTable: public NodeTable
*/
struct TestNodeTableHost: public TestHost
{
TestNodeTableHost(): m_alias(KeyPair::create()), nodeTable(new TestNodeTable(m_io, m_alias)), testNodes(TestNodeTable::createTestNodes()) {};
TestNodeTableHost(unsigned _count = 8): m_alias(KeyPair::create()), nodeTable(new TestNodeTable(m_io, m_alias)), testNodes(TestNodeTable::createTestNodes(_count)) {};
~TestNodeTableHost() { m_io.stop(); stopWorking(); }
void setup() { for (auto n: testNodes) nodeTables.push_back(make_shared<TestNodeTable>(m_io,n.first,n.second)); }
@ -135,7 +135,7 @@ public:
BOOST_AUTO_TEST_CASE(test_neighbors_packet)
{
KeyPair k = KeyPair::create();
std::vector<std::pair<KeyPair,unsigned>> testNodes(TestNodeTable::createTestNodes());
std::vector<std::pair<KeyPair,unsigned>> testNodes(TestNodeTable::createTestNodes(16));
bi::udp::endpoint to(boost::asio::ip::address::from_string("127.0.0.1"), 30000);
Neighbors out(to);
@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(test_findnode_neighbors)
BOOST_AUTO_TEST_CASE(kademlia)
{
TestNodeTableHost node;
TestNodeTableHost node(12);
node.start();
node.nodeTable->join(); // ideally, joining with empty node table logs warning we can check for
node.setup();
@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(kademlia)
clog << "NodeTable:\n" << *node.nodeTable.get() << endl;
node.pingAll();
this_thread::sleep_for(chrono::milliseconds(4000));
this_thread::sleep_for(chrono::milliseconds(1000));
clog << "NodeTable:\n" << *node.nodeTable.get() << endl;
node.nodeTable->reset();

Loading…
Cancel
Save