Browse Source

update peer host test. support unspecified ip.

cl-refactor
subtly 10 years ago
parent
commit
d76dfef797
  1. 2
      libp2p/Common.h
  2. 3
      libp2p/NodeTable.cpp
  3. 4
      test/libp2p/peer.cpp

2
libp2p/Common.h

@ -187,7 +187,7 @@ struct NodeIPEndpoint
bool isAllowed() const { return NodeIPEndpoint::test_allowLocal ? !address.is_unspecified() : isPublicAddress(address); }
void streamRLP(RLPStream& _s, bool _inline = CreateList) const { if (_inline == CreateList) _s.appendList(3); if (address.is_v4()) _s << address.to_v4().to_bytes(); else _s << address.to_v6().to_bytes(); _s << udpPort << tcpPort; }
void interpretRLP(RLP const& _r) { if (_r[0].size() == 4) address = bi::address_v4(_r[0].toArray<byte, 4>()); else address = bi::address_v6(_r[0].toArray<byte, 16>()); udpPort = _r[1].toInt<uint16_t>(); tcpPort = _r[2].toInt<uint16_t>(); }
void interpretRLP(RLP const& _r) { if (_r[0].size() == 0) address = bi::address(); else if (_r[0].size() == 4) address = bi::address_v4(_r[0].toArray<byte, 4>()); else address = bi::address_v6(_r[0].toArray<byte, 16>()); udpPort = _r[1].toInt<uint16_t>(); tcpPort = _r[2].toInt<uint16_t>(); }
};
struct Node

3
libp2p/NodeTable.cpp

@ -512,7 +512,8 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
if (in.version != dev::p2p::c_protocolVersion)
{
if (auto n = nodeEntry(nodeid))
dropNode(n);
if (n)
dropNode(n);
return;
}

4
test/libp2p/peer.cpp

@ -51,9 +51,11 @@ BOOST_AUTO_TEST_CASE(host)
auto node2 = host2.id();
host2.start();
while (!host2.isStarted())
this_thread::sleep_for(chrono::milliseconds(20));
host1.addNode(node2, NodeIPEndpoint(bi::address::from_string("127.0.0.1"), host2prefs.listenPort, host2prefs.listenPort));
this_thread::sleep_for(chrono::seconds(3));
this_thread::sleep_for(chrono::seconds(10));
auto host1peerCount = host1.peerCount();
auto host2peerCount = host2.peerCount();

Loading…
Cancel
Save