Browse Source

fix for insensitive windows compiler which reserves 'inline'. default initial values for packet timestamps.

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

6
libp2p/Common.h

@ -165,8 +165,8 @@ struct NodeIPEndpoint
{
enum RLPAppend
{
List,
Inline
StreamList,
StreamInline
};
/// 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, 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 streamRLP(RLPStream& _s, RLPAppend _inline = StreamList) const { if (_inline == StreamList) _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::Inline);
p.endpoint.streamRLP(network, NodeIPEndpoint::StreamInline);
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::Inline);
entry.endpoint.streamRLP(network, NodeIPEndpoint::StreamInline);
network << entry.id;
count++;
}

10
libp2p/NodeTable.h

@ -309,7 +309,7 @@ struct PingNode: RLPXDatagram<PingNode>
unsigned version = 0;
NodeIPEndpoint source;
NodeIPEndpoint destination;
uint32_t ts;
uint32_t ts = 0;
void streamRLP(RLPStream& _s) const override;
void interpretRLP(bytesConstRef _bytes) override;
@ -327,7 +327,7 @@ struct Pong: RLPXDatagram<Pong>
NodeIPEndpoint destination;
h256 echo; ///< MCD of PingNode
uint32_t ts;
uint32_t ts = 0;
void streamRLP(RLPStream& _s) const { _s.appendList(2); _s << echo << ts; }
void interpretRLP(bytesConstRef _bytes) { RLP r(_bytes); echo = (h256)r[0]; ts = r[1].toInt<uint32_t>(); }
@ -353,7 +353,7 @@ struct FindNode: RLPXDatagram<FindNode>
static const uint8_t type = 3;
h512 target;
uint32_t ts;
uint32_t ts = 0;
void streamRLP(RLPStream& _s) const { _s.appendList(2); _s << target << ts; }
void interpretRLP(bytesConstRef _bytes) { RLP r(_bytes); target = r[0].toHash<h512>(); ts = r[1].toInt<uint32_t>(); }
@ -370,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::Inline); _s << node; }
void streamRLP(RLPStream& _s) const { _s.appendList(4); endpoint.streamRLP(_s, NodeIPEndpoint::StreamInline); _s << node; }
};
Neighbours(bi::udp::endpoint _ep): RLPXDatagram<Neighbours>(_ep), ts(secondsSinceEpoch()) {}
@ -383,7 +383,7 @@ struct Neighbours: RLPXDatagram<Neighbours>
static const uint8_t type = 4;
std::vector<Neighbour> neighbours;
uint32_t ts = 1;
uint32_t ts = 0;
void streamRLP(RLPStream& _s) const { _s.appendList(2); _s.appendList(neighbours.size()); for (auto& n: neighbours) n.streamRLP(_s); _s << ts; }
void interpretRLP(bytesConstRef _bytes) { RLP r(_bytes); for (auto n: r[0]) neighbours.push_back(Neighbour(n)); ts = r[1].toInt<uint32_t>(); }

Loading…
Cancel
Save