diff --git a/libp2p/Common.h b/libp2p/Common.h index 5b770887f..9ad5bb206 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -161,7 +161,7 @@ using PeerSessionInfos = std::vector; */ struct NodeIPEndpoint { - /// Setting true causes isValid to return true for all addresses. Defaults to false. Used by test fixtures. + /// Setting true causes isAllowed to return true for all addresses. (Used by test fixtures) static bool test_allowLocal; NodeIPEndpoint(bi::address _addr, uint16_t _udp, uint16_t _tcp): address(_addr), udpPort(_udp), tcpPort(_tcp) {} @@ -175,7 +175,7 @@ struct NodeIPEndpoint operator bool() const { return !address.is_unspecified() && udpPort > 0 && tcpPort > 0; } - bool isValid() const { return NodeIPEndpoint::test_allowLocal ? true : isPublicAddress(address); } + bool isAllowed() const { return NodeIPEndpoint::test_allowLocal ? !address.is_unspecified() : isPublicAddress(address); } }; struct Node diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 4a6e704ec..f474951b9 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -684,7 +684,7 @@ bytes Host::saveNetwork() const if (!endpoint.address().is_v4()) continue; - if (chrono::system_clock::now() - p.m_lastConnected < chrono::seconds(3600 * 48) && endpoint.port() > 0 && p.id != id() && (p.required || p.endpoint.isValid())) + if (chrono::system_clock::now() - p.m_lastConnected < chrono::seconds(3600 * 48) && endpoint.port() > 0 && p.id != id() && (p.required || p.endpoint.isAllowed())) { network.appendList(10); network << endpoint.port() << p.id << p.required @@ -743,9 +743,9 @@ void Host::restoreNetwork(bytesConstRef _b) continue; // todo: ipv6, bi::address_v6(i[0].toArray() - NodeIPEndpoint ep(bi::address_v4(i[0].toArray()), i[1].toInt(), i[1].toInt()); + NodeIPEndpoint ep({bi::address_v4(i[0].toArray()), i[1].toInt(), i[1].toInt()}); bool required = i[3].toInt(); - if (!ep.isValid() && !required) + if (!ep.isAllowed() && !required) continue; auto id = (NodeId)i[2]; diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 7ddef0857..428b94e7c 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -272,7 +272,7 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) vector> ret; for (auto& nodes: found) for (auto n: nodes.second) - if (n->endpoint.isValid()) + if (n->endpoint.isAllowed()) ret.push_back(n); return move(ret); } @@ -306,7 +306,7 @@ void NodeTable::evict(shared_ptr _leastSeen, shared_ptr _n void NodeTable::noteActiveNode(Public const& _pubk, bi::udp::endpoint const& _endpoint) { - if (_pubk == m_node.address() || !NodeIPEndpoint(_endpoint.address(), _endpoint.port(), _endpoint.port()).isValid()) + if (_pubk == m_node.address() || !NodeIPEndpoint(_endpoint.address(), _endpoint.port(), _endpoint.port()).isAllowed()) return; shared_ptr node = nodeEntry(_pubk); diff --git a/libp2p/NodeTable.h b/libp2p/NodeTable.h index 9e0553590..a308883fb 100644 --- a/libp2p/NodeTable.h +++ b/libp2p/NodeTable.h @@ -320,8 +320,8 @@ struct PingNode: RLPXDatagram unsigned version = 0; std::string ipAddress; -// unsigned udpPort; - unsigned tcpPort; +// uint16_t udpPort; + uint16_t tcpPort; unsigned ts; void streamRLP(RLPStream& _s) const override; @@ -387,11 +387,11 @@ struct Neighbours: RLPXDatagram Node() = default; Node(RLP const& _r) { interpretRLP(_r); } std::string ipAddress; - unsigned udpPort; -// unsigned tcpPort; + uint16_t udpPort; +// uint16_t tcpPort; NodeId node; void streamRLP(RLPStream& _s) const { _s.appendList(3); _s << ipAddress << udpPort << node; } - void interpretRLP(RLP const& _r) { ipAddress = _r[0].toString(); udpPort = _r[1].toInt(); node = h512(_r[2].toBytes()); } + void interpretRLP(RLP const& _r) { ipAddress = _r[0].toString(); udpPort = _r[1].toInt(); node = h512(_r[2].toBytes()); } }; Neighbours(bi::udp::endpoint _ep): RLPXDatagram(_ep), ts(futureFromEpoch(std::chrono::seconds(30))) {}