Browse Source

Remove packet copy constructor. Simplify bool use.

cl-refactor
subtly 10 years ago
parent
commit
20ca0ff247
  1. 2
      libp2p/RLPXFrameWriter.cpp
  2. 2
      libp2p/RLPXPacket.h
  3. 13
      test/libp2p/rlpx.cpp

2
libp2p/RLPXFrameWriter.cpp

@ -66,7 +66,7 @@ size_t RLPXFrameWriter::mux(RLPXFrameCoder& _coder, unsigned _size, vector<bytes
return ret;
// first run when !swapQueues, high > low, otherwise low > high
bool high = highPending && !swapQueues ? true : lowPending ? false : true;
bool high = highPending && !swapQueues ? true : !lowPending;
WriterState &qs = high ? m_q.first : m_q.second;
size_t frameAllot = (!swapQueues && highPending && lowPending ? frameLen / 2 - (c_overhead + c_blockSize) > 0 ? frameLen / 2 : frameLen : frameLen) - c_overhead;
size_t offset = 0;

2
libp2p/RLPXPacket.h

@ -45,7 +45,7 @@ public:
/// Construct packet from single bytestream. RLPStream data is invalidated.
RLPXPacket(unsigned _capId, bytesConstRef _in): m_cap(_capId), m_type(nextRLP(_in).toBytes()) { if (_in.size() > m_type.size()) { m_data.resize(_in.size() - m_type.size()); _in.cropped(m_type.size()).copyTo(&m_data); } }
RLPXPacket(RLPXPacket const& _p): m_cap(_p.m_cap), m_type(_p.m_type), m_data(_p.m_data) {}
RLPXPacket(RLPXPacket const& _p) = delete;
RLPXPacket(RLPXPacket&& _p): m_cap(_p.m_cap), m_type(std::move(_p.m_type)), m_data(std::move(_p.m_data)) {}
bytes const& type() const { return m_type; }

13
test/libp2p/rlpx.cpp

@ -518,9 +518,8 @@ BOOST_AUTO_TEST_CASE(segmentedPacketFlush)
BOOST_REQUIRE(decryptedHeader);
bytesRef frame = frameWithHeader.cropped(h256::size);
RLPXFrameInfo f(header);
auto p = r.demux(decoder, f, frame);
if (p.size())
packets += move(p);
for (RLPXPacket& p: r.demux(decoder, f, frame))
packets.push_back(move(p));
}
BOOST_REQUIRE_EQUAL(packets.size(), 1);
BOOST_REQUIRE_EQUAL(packets.front().size(), packetTypeRLP.size() + rlpPayload.out().size());
@ -571,8 +570,8 @@ BOOST_AUTO_TEST_CASE(coalescedPacketsPadded)
bytesRef frame = frameWithHeader.cropped(h256::size);
RLPXFrameInfo f(header);
BOOST_REQUIRE_EQUAL(f.multiFrame, false);
auto p = r.demux(decoder, f, frame);
packets += move(p);
for (RLPXPacket& p: r.demux(decoder, f, frame))
packets.push_back(move(p));
RLPStream rlpPayload;
rlpPayload << stuff;
@ -623,8 +622,8 @@ BOOST_AUTO_TEST_CASE(singleFramePacketFlush)
bytesRef frame = frameWithHeader.cropped(h256::size);
RLPXFrameInfo f(header);
BOOST_REQUIRE_EQUAL(f.multiFrame, false);
auto p = r.demux(decoder, f, frame);
packets += move(p);
for (RLPXPacket& p: r.demux(decoder, f, frame))
packets.push_back(move(p));
RLPStream rlpPayload;
rlpPayload << stuff;

Loading…
Cancel
Save