comment wrap

This commit is contained in:
ridethepig 2023-02-16 05:08:25 +00:00
parent cc7dcc0225
commit 752d0d5a4a
5 changed files with 18 additions and 16 deletions

View File

@ -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 // watch out for fetching front from an empty queue
wr_data.push_back(_aux_buffer.front()); wr_data.push_back(_aux_buffer.front());
_aux_buffer.pop_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;
--_unassem_count; --_unassem_count;
} }
@ -54,7 +54,7 @@ void StreamReassembler::push_substring(const string &data, const size_t index, c
_output.write(wr_data); _output.write(wr_data);
} }
if (_unassem == _eof) { if (_unassem == _eof) {
_output.end_input(); // stream approached to eof _output.end_input(); // stream approached to eof
} }
} }

View File

@ -13,13 +13,13 @@ class StreamReassembler {
private: private:
// Your code here -- add private members as necessary. // Your code here -- add private members as necessary.
ByteStream _output; //!< The reassembled in-order byte stream ByteStream _output; //!< The reassembled in-order byte stream
size_t _capacity{}; //!< The maximum number of bytes size_t _capacity{}; //!< The maximum number of bytes
size_t _unassem{}; //!< The index (in the stream) of the first unassembled byte size_t _unassem{}; //!< The index (in the stream) of the first unassembled byte
size_t _unassem_count{}; //!< Keep the number of unassembled bytes size_t _unassem_count{}; //!< Keep the number of unassembled bytes
std::deque<char> _aux_buffer; //!< auxiliary storage, initially allocated _capacity bytes std::deque<char> _aux_buffer; //!< auxiliary storage, initially allocated _capacity bytes
std::deque<bool> _aux_buffer_valid; //!< indicate whether the bit in _aux_buffer is filled with a valid byte std::deque<bool> _aux_buffer_valid; //!< indicate whether the bit in _aux_buffer is filled with a valid byte
size_t _eof{static_cast<size_t>(-1)}; //!< indicate the eof byte's index in stream size_t _eof{static_cast<size_t>(-1)}; //!< indicate the eof byte's index in stream
public: public:
//! \brief Construct a `StreamReassembler` that will store up to `capacity` bytes. //! \brief Construct a `StreamReassembler` that will store up to `capacity` bytes.

View File

@ -6,13 +6,11 @@
// automated checks run by `make check_lab2`. // automated checks run by `make check_lab2`.
template <typename... Targs> template <typename... Targs>
void DUMMY_CODE(Targs &&... /* unused */) {} void DUMMY_CODE(Targs &&.../* unused */) {}
using namespace std; using namespace std;
void TCPReceiver::segment_received(const TCPSegment &seg) { void TCPReceiver::segment_received(const TCPSegment &seg) { DUMMY_CODE(seg); }
DUMMY_CODE(seg);
}
optional<WrappingInt32> TCPReceiver::ackno() const { return {}; } optional<WrappingInt32> TCPReceiver::ackno() const { return {}; }

View File

@ -19,6 +19,9 @@ class TCPReceiver {
//! The maximum number of bytes we'll store. //! The maximum number of bytes we'll store.
size_t _capacity; size_t _capacity;
WrappingInt32 _seqno{0};
WrappingInt32 _ackno{0};
bool _is_start{};
public: public:
//! \brief Construct a TCP receiver //! \brief Construct a TCP receiver

View File

@ -6,7 +6,7 @@
// automated checks run by `make check_lab2`. // automated checks run by `make check_lab2`.
template <typename... Targs> template <typename... Targs>
void DUMMY_CODE(Targs &&... /* unused */) {} void DUMMY_CODE(Targs &&.../* unused */) {}
using namespace std; using namespace std;
@ -30,13 +30,14 @@ WrappingInt32 wrap(uint64_t n, WrappingInt32 isn) {
//! has a different ISN. //! has a different ISN.
#define MODULO (1UL << 32) #define MODULO (1UL << 32)
uint64_t unwrap(WrappingInt32 n, WrappingInt32 isn, uint64_t checkpoint) { 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<uint64_t>(n.raw_value() - isn.raw_value()); uint64_t tmp = static_cast<uint64_t>(n.raw_value() - isn.raw_value());
tmp += (checkpoint >> 32) << 32; tmp += (checkpoint >> 32) << 32;
if (tmp > checkpoint) { if (tmp > checkpoint) {
if (tmp < MODULO || tmp - checkpoint < checkpoint - (tmp - MODULO)) { if (tmp < MODULO || tmp - checkpoint < checkpoint - (tmp - MODULO)) {
return tmp; return tmp;
} } else {
else {
return tmp - MODULO; return tmp - MODULO;
} }
} else { } else {