Browse Source

More explicit initialization of nodes and peers.

cl-refactor
subtly 10 years ago
parent
commit
280df58d94
  1. 3
      libp2p/Common.cpp
  2. 13
      libp2p/Common.h
  3. 2
      libp2p/NodeTable.cpp
  4. 1
      libp2p/Peer.h

3
libp2p/Common.cpp

@ -27,6 +27,9 @@ using namespace dev::p2p;
const unsigned dev::p2p::c_protocolVersion = 3;
const unsigned dev::p2p::c_defaultIPPort = 30303;
const dev::p2p::NodeIPEndpoint dev::p2p::UnspecifiedNodeIPEndpoint = NodeIPEndpoint(bi::address(), 0, 0);
const dev::p2p::Node dev::p2p::UnspecifiedNode = dev::p2p::Node(NodeId(), UnspecifiedNodeIPEndpoint);
bool dev::p2p::NodeIPEndpoint::test_allowLocal = false;
bool p2p::isPublicAddress(std::string const& _addressToCheck)

13
libp2p/Common.h

@ -52,6 +52,11 @@ namespace p2p
extern const unsigned c_protocolVersion;
extern const unsigned c_defaultIPPort;
struct NodeIPEndpoint;
struct Node;
extern const NodeIPEndpoint UnspecifiedNodeIPEndpoint;
extern const Node UnspecifiedNode;
using NodeId = h512;
bool isPrivateAddress(bi::address const& _addressToCheck);
@ -158,13 +163,12 @@ struct NodeIPEndpoint
{
/// Setting true causes isValid to return true for all addresses. Defaults to false. Used by test fixtures.
static bool test_allowLocal;
NodeIPEndpoint(): address() {}
NodeIPEndpoint(bi::address _addr, uint16_t _udp, uint16_t _tcp): address(_addr), udpPort(_udp), tcpPort(_tcp) {}
bi::address address;
uint16_t udpPort = 0;
uint16_t tcpPort = 0;
uint16_t udpPort;
uint16_t tcpPort;
operator bi::udp::endpoint() const { return std::move(bi::udp::endpoint(address, udpPort)); }
operator bi::tcp::endpoint() const { return std::move(bi::tcp::endpoint(address, tcpPort)); }
@ -176,7 +180,6 @@ struct NodeIPEndpoint
struct Node
{
Node(): endpoint(NodeIPEndpoint()) {};
Node(Public _pubk, NodeIPEndpoint _ip, bool _required = false): id(_pubk), endpoint(_ip), required(_required) {}
virtual NodeId const& address() const { return id; }

2
libp2p/NodeTable.cpp

@ -144,7 +144,7 @@ Node NodeTable::node(NodeId const& _id)
Node n(_id, entry->endpoint, entry->required);
return move(n);
}
return move(Node());
return UnspecifiedNode;
}
shared_ptr<NodeEntry> NodeTable::nodeEntry(NodeId _id)

1
libp2p/Peer.h

@ -57,6 +57,7 @@ class Peer: public Node
friend class RLPXHandshake;
public:
Peer(): Node(NodeId(), UnspecifiedNodeIPEndpoint) {}
bool isOffline() const { return !m_session.lock(); }
virtual bool operator<(Peer const& _p) const;

Loading…
Cancel
Save