Browse Source

Minor semantic updates. Support unspecified address for NodeIPEndpoint.

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

8
libp2p/Common.h

@ -163,10 +163,10 @@ using PeerSessionInfos = std::vector<PeerSessionInfo>;
*/
struct NodeIPEndpoint
{
enum InlineRLP
enum RLPAppend
{
CreateList,
InlineList
List,
Inline
};
/// Setting true causes isAllowed to return true for all addresses. (Used by test fixtures)
@ -186,7 +186,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 streamRLP(RLPStream& _s, RLPAppend _inline = List) const { if (_inline == List) _s.appendList(3); if (address.is_v4()) _s << address.to_v4().to_bytes(); else if (address.is_v6()) _s << address.to_v6().to_bytes(); else _s << ""; _s << udpPort << tcpPort; }
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>(); }
};

4
libp2p/Host.cpp

@ -686,7 +686,7 @@ bytes Host::saveNetwork() const
if (chrono::system_clock::now() - p.m_lastConnected < chrono::seconds(3600 * 48) && !!p.endpoint && p.id != id() && (p.required || p.endpoint.isAllowed()))
{
network.appendList(11);
p.endpoint.streamRLP(network, NodeIPEndpoint::InlineList);
p.endpoint.streamRLP(network, NodeIPEndpoint::Inline);
network << p.id << p.required
<< chrono::duration_cast<chrono::seconds>(p.m_lastConnected.time_since_epoch()).count()
<< chrono::duration_cast<chrono::seconds>(p.m_lastAttempted.time_since_epoch()).count()
@ -702,7 +702,7 @@ bytes Host::saveNetwork() const
for (auto const& entry: state)
{
network.appendList(4);
entry.endpoint.streamRLP(network, NodeIPEndpoint::InlineList);
entry.endpoint.streamRLP(network, NodeIPEndpoint::Inline);
network << entry.id;
count++;
}

6
libp2p/NodeTable.h

@ -299,8 +299,10 @@ struct InvalidRLP: public Exception {};
*/
struct PingNode: RLPXDatagram<PingNode>
{
PingNode(bi::udp::endpoint _ep): RLPXDatagram<PingNode>(_ep), source(UnspecifiedNodeIPEndpoint), destination(UnspecifiedNodeIPEndpoint) {}
/// Constructor used for sending PingNode.
PingNode(NodeIPEndpoint _src, NodeIPEndpoint _dest): RLPXDatagram<PingNode>(_dest), source(_src), destination(_dest), ts(futureFromEpoch(std::chrono::seconds(60))) {}
/// Constructor used to create empty PingNode for parsing inbound packets.
PingNode(bi::udp::endpoint _ep): RLPXDatagram<PingNode>(_ep), source(UnspecifiedNodeIPEndpoint), destination(UnspecifiedNodeIPEndpoint) {}
static const uint8_t type = 1;
@ -368,7 +370,7 @@ struct Neighbours: RLPXDatagram<Neighbours>
Neighbour(RLP const& _r): endpoint(_r) { node = h512(_r[3].toBytes()); }
NodeIPEndpoint endpoint;
NodeId node;
void streamRLP(RLPStream& _s) const { _s.appendList(4); endpoint.streamRLP(_s, NodeIPEndpoint::InlineList); _s << node; }
void streamRLP(RLPStream& _s) const { _s.appendList(4); endpoint.streamRLP(_s, NodeIPEndpoint::Inline); _s << node; }
};
Neighbours(bi::udp::endpoint _ep): RLPXDatagram<Neighbours>(_ep), ts(futureFromEpoch(std::chrono::seconds(30))) {}

Loading…
Cancel
Save