From 752d0d5a4ae4da8a3e256645cbc2da79dd8c5790 Mon Sep 17 00:00:00 2001 From: ridethepig Date: Thu, 16 Feb 2023 05:08:25 +0000 Subject: [PATCH] comment wrap --- libsponge/stream_reassembler.cc | 4 ++-- libsponge/stream_reassembler.hh | 14 +++++++------- libsponge/tcp_receiver.cc | 6 ++---- libsponge/tcp_receiver.hh | 3 +++ libsponge/wrapping_integers.cc | 7 ++++--- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libsponge/stream_reassembler.cc b/libsponge/stream_reassembler.cc index f4f5b5f..5348af0 100644 --- a/libsponge/stream_reassembler.cc +++ b/libsponge/stream_reassembler.cc @@ -46,7 +46,7 @@ void StreamReassembler::push_substring(const string &data, const size_t index, c // watch out for fetching front from an empty queue wr_data.push_back(_aux_buffer.front()); _aux_buffer.pop_front(); - _aux_buffer_valid.pop_front(); // remember to pop assistent queue + _aux_buffer_valid.pop_front(); // remember to pop assistent queue ++_unassem; --_unassem_count; } @@ -54,7 +54,7 @@ void StreamReassembler::push_substring(const string &data, const size_t index, c _output.write(wr_data); } if (_unassem == _eof) { - _output.end_input(); // stream approached to eof + _output.end_input(); // stream approached to eof } } diff --git a/libsponge/stream_reassembler.hh b/libsponge/stream_reassembler.hh index b6bb692..68d0a18 100644 --- a/libsponge/stream_reassembler.hh +++ b/libsponge/stream_reassembler.hh @@ -13,13 +13,13 @@ class StreamReassembler { private: // Your code here -- add private members as necessary. - ByteStream _output; //!< The reassembled in-order byte stream - size_t _capacity{}; //!< The maximum number of bytes - size_t _unassem{}; //!< The index (in the stream) of the first unassembled byte - size_t _unassem_count{}; //!< Keep the number of unassembled bytes - std::deque _aux_buffer; //!< auxiliary storage, initially allocated _capacity bytes - std::deque _aux_buffer_valid; //!< indicate whether the bit in _aux_buffer is filled with a valid byte - size_t _eof{static_cast(-1)}; //!< indicate the eof byte's index in stream + ByteStream _output; //!< The reassembled in-order byte stream + size_t _capacity{}; //!< The maximum number of bytes + size_t _unassem{}; //!< The index (in the stream) of the first unassembled byte + size_t _unassem_count{}; //!< Keep the number of unassembled bytes + std::deque _aux_buffer; //!< auxiliary storage, initially allocated _capacity bytes + std::deque _aux_buffer_valid; //!< indicate whether the bit in _aux_buffer is filled with a valid byte + size_t _eof{static_cast(-1)}; //!< indicate the eof byte's index in stream public: //! \brief Construct a `StreamReassembler` that will store up to `capacity` bytes. diff --git a/libsponge/tcp_receiver.cc b/libsponge/tcp_receiver.cc index 4f0ee81..640f925 100644 --- a/libsponge/tcp_receiver.cc +++ b/libsponge/tcp_receiver.cc @@ -6,13 +6,11 @@ // automated checks run by `make check_lab2`. template -void DUMMY_CODE(Targs &&... /* unused */) {} +void DUMMY_CODE(Targs &&.../* unused */) {} using namespace std; -void TCPReceiver::segment_received(const TCPSegment &seg) { - DUMMY_CODE(seg); -} +void TCPReceiver::segment_received(const TCPSegment &seg) { DUMMY_CODE(seg); } optional TCPReceiver::ackno() const { return {}; } diff --git a/libsponge/tcp_receiver.hh b/libsponge/tcp_receiver.hh index 0856a3f..5b92180 100644 --- a/libsponge/tcp_receiver.hh +++ b/libsponge/tcp_receiver.hh @@ -19,6 +19,9 @@ class TCPReceiver { //! The maximum number of bytes we'll store. size_t _capacity; + WrappingInt32 _seqno{0}; + WrappingInt32 _ackno{0}; + bool _is_start{}; public: //! \brief Construct a TCP receiver diff --git a/libsponge/wrapping_integers.cc b/libsponge/wrapping_integers.cc index c1e3f23..f08e552 100644 --- a/libsponge/wrapping_integers.cc +++ b/libsponge/wrapping_integers.cc @@ -6,7 +6,7 @@ // automated checks run by `make check_lab2`. template -void DUMMY_CODE(Targs &&... /* unused */) {} +void DUMMY_CODE(Targs &&.../* unused */) {} using namespace std; @@ -30,13 +30,14 @@ WrappingInt32 wrap(uint64_t n, WrappingInt32 isn) { //! has a different ISN. #define MODULO (1UL << 32) uint64_t unwrap(WrappingInt32 n, WrappingInt32 isn, uint64_t checkpoint) { + // well, really ulgy impl + // have to make sure that no overflow happens uint64_t tmp = static_cast(n.raw_value() - isn.raw_value()); tmp += (checkpoint >> 32) << 32; if (tmp > checkpoint) { if (tmp < MODULO || tmp - checkpoint < checkpoint - (tmp - MODULO)) { return tmp; - } - else { + } else { return tmp - MODULO; } } else {