Browse Source

naming. consistent use of uint16_t for port.

cl-refactor
subtly 10 years ago
parent
commit
2dbee779c8
  1. 4
      libp2p/Common.h
  2. 6
      libp2p/Host.cpp
  3. 4
      libp2p/NodeTable.cpp
  4. 10
      libp2p/NodeTable.h

4
libp2p/Common.h

@ -161,7 +161,7 @@ using PeerSessionInfos = std::vector<PeerSessionInfo>;
*/
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

6
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<byte, 16>()
NodeIPEndpoint ep(bi::address_v4(i[0].toArray<byte, 4>()), i[1].toInt<short>(), i[1].toInt<short>());
NodeIPEndpoint ep({bi::address_v4(i[0].toArray<byte, 4>()), i[1].toInt<uint16_t>(), i[1].toInt<uint16_t>()});
bool required = i[3].toInt<bool>();
if (!ep.isValid() && !required)
if (!ep.isAllowed() && !required)
continue;
auto id = (NodeId)i[2];

4
libp2p/NodeTable.cpp

@ -272,7 +272,7 @@ vector<shared_ptr<NodeEntry>> NodeTable::nearestNodeEntries(NodeId _target)
vector<shared_ptr<NodeEntry>> 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<NodeEntry> _leastSeen, shared_ptr<NodeEntry> _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<NodeEntry> node = nodeEntry(_pubk);

10
libp2p/NodeTable.h

@ -320,8 +320,8 @@ struct PingNode: RLPXDatagram<PingNode>
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<Neighbours>
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<unsigned>(); node = h512(_r[2].toBytes()); }
void interpretRLP(RLP const& _r) { ipAddress = _r[0].toString(); udpPort = _r[1].toInt<uint16_t>(); node = h512(_r[2].toBytes()); }
};
Neighbours(bi::udp::endpoint _ep): RLPXDatagram<Neighbours>(_ep), ts(futureFromEpoch(std::chrono::seconds(30))) {}

Loading…
Cancel
Save