diff --git a/libp2p/Common.cpp b/libp2p/Common.cpp index 5a3803563..7206ec835 100644 --- a/libp2p/Common.cpp +++ b/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) diff --git a/libp2p/Common.h b/libp2p/Common.h index cd18c54f3..5b770887f 100644 --- a/libp2p/Common.h +++ b/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; } diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 31a612128..7ddef0857 100644 --- a/libp2p/NodeTable.cpp +++ b/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 NodeTable::nodeEntry(NodeId _id) diff --git a/libp2p/Peer.h b/libp2p/Peer.h index 18809d075..547d7371f 100644 --- a/libp2p/Peer.h +++ b/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;