update write up

This commit is contained in:
ridethepig 2023-02-16 09:26:38 +00:00
parent d76022f9d1
commit cb32c293c8
5 changed files with 75 additions and 31 deletions

View File

@ -19,8 +19,7 @@ void TCPReceiver::segment_received(const TCPSegment &seg) {
}
if (!_syn)
return; // abandon packets before SYN
uint64_t checkpoint = stream_out().bytes_written() ? stream_out().bytes_written() - 1 : 0;
// special case for initial SYN
uint64_t checkpoint = stream_out().bytes_written();
uint64_t abs_seqno = unwrap(seg.header().seqno, _isn, checkpoint);
// In your TCP implementation, youll use the index of the last reassembled byte as the checkpoint.
// So, the bytes_written-1 (Stream Indices) should be this value
@ -30,7 +29,7 @@ void TCPReceiver::segment_received(const TCPSegment &seg) {
// assertion: when abs_seqno is 0, this packet must be syn
uint64_t index = abs_seqno - (abs_seqno ? 1 : 0); // special case for SYN&FIN
_reassembler.push_substring(seg.payload().copy(), index, seg.header().fin);
_abs_ackno = stream_out().bytes_written() + 1 + (stream_out().input_ended() ? 1 : 0);
auto _abs_ackno = stream_out().bytes_written() + 1 + (stream_out().input_ended() ? 1 : 0);
_ackno = wrap(_abs_ackno, _isn);
}

View File

@ -21,7 +21,6 @@ class TCPReceiver {
size_t _capacity;
WrappingInt32 _isn{0};
WrappingInt32 _ackno{0};
uint64_t _abs_ackno{0};
bool _syn{};
public:

View File

@ -1,17 +1,17 @@
Lab 0 Writeup
=============
My name: [Catfood]
My name: Catfood
My SUNet ID: [998244353]
My SUNet ID: 998244353
I collaborated with: [An orange cat]
I collaborated with: An orange cat
This lab took me about [2] hours to do. I [did not] attend the lab session.
This lab took me about `2` hours to do.
My secret code from section 2.1 was: [294080]
My secret code from section 2.1 was: `294080`
- Optional: I had unexpected difficulty with: [describe]
- Optional: I had unexpected difficulty with: [打字的手速太慢telnet会超时]
- Optional: I think you could make this lab better by: [describe]
@ -19,6 +19,9 @@ My secret code from section 2.1 was: [294080]
- Optional: I'm not sure about: [describe]
实现细节描述
============
2.1.2
```
➜ sponge git:(lab0-startercode) ✗ telnet cs144.keithw.org http
@ -68,9 +71,10 @@ Connection closed by foreign host.
```
2.2:
学校的邮件系统比较智障,做不了
2.3
2.3:
```
➜ sponge git:(lab0-startercode) ✗ telnet localhost 9090
Trying 127.0.0.1...
@ -87,3 +91,20 @@ fuck
lalal
```
3.4:
他的提示没啥用但是doxygen里面有个例子可以直接看那个例子。
地址可以直接放域名,`Address(host, protocol)`这个重载是可以DNS查询的因此直接用就行然后TCP socket`connect->write->loop read`就好了。
4:
Buffer开了一个STL的`deque`感觉是最适合做这种buffer的容器了能够前后插入删除、常数级随机访问、动态调整空间非常棒的性质。数据类型用的是`char`byte方便调整。
write接口没啥东西控制一下不要超出空间就行。
read接口比较智障需要这样一个组合但是实际上好像测试的时候都没用到。。。
```cpp
std::string data_read = peek_output(len);
pop_output(len);
return data_read;
```
最智障的是它的`peek_output`和`pop_output`这两个的设计peek只能读啥也不能动因为是个const函数pop需要再把东西删掉然后`read`就是他们的组合。需要注意一下,更新`bytes_read`是在pop里面而不是read因为大概率在上层的实现中可能需要把直接调用peek和pop而不是read。

View File

@ -1,24 +1,37 @@
Lab 1 Writeup
=============
My name: [your name here]
My name: Catfood
My SUNet ID: [your sunetid here]
My SUNet ID: 998244353
I collaborated with: [list sunetids here]
I collaborated with: An orange cat
I would like to thank/reward these classmates for their help: [list sunetids here]
This lab took me about [n] hours to do. I [did/did not] attend the lab session.
This lab took me about `3` hours to do.
Program Structure and Design of the StreamReassembler:
[]
首先写几个 dis-ambiguity
1. capacity限制容量限制指的是bytestream.size + aux_storage.size。比较具有迷惑性的是auxiliary storage的容量这里需要把中间空的字节也算进去因此就可以简单地计算为`first_unacceptable = first_unread + capacity = first_unassembled + aux_buffer.size()`。形象地理解为类似于一个大的空白数组往里面填东西填满了开头的连续部分就push到bytestream里面。
2. 关于丢弃这里是以字节为单位的丢弃而不是以packet为单位也就是一个string进来有一部分超出了容量限制这时候不能直接返回不写入而是要把不超出限制的部分写进入剩下的丢掉。
3. `unassembed_bytes`的计算这个统计的就是实际收到的但是还没push到字节流的字节不包括空白。因此需要在接受的时候动态统计。
4. `EOF`处理因为可能带EOF的packet先到达前面还有没收到的部分因此需要单独记住EOF对应的Index等push到这个Index的时候再去调用字节流的`end_input()`。
然后简单说一下实现:
- 数据结构是两个`deque`一个用来当缓冲区另一个用来标志是否是收到的字节这样就不用实现复杂的区间合并了虽然需要消耗双倍内存。开头的时候需要重新调整大小因为可能被read过了。
- 过程中需要注意各种状态的取值不要超过容量也不要出现非法操作比如取空队列的front这个好像是个UB
- 每次收到数据之后,都处理一下是否能够推进字节流,说明上是这么要求的(“尽快”)
最后简单记一下STL中`deque`的一些用法:
- 初始化:可以用`(size, data)`这样的方式一次性指定初始容量
- 入队出队:这个容器可以`push/pop_front/back`
- 调整大小:`resize(newsize, data)`这个调用的行为符合直觉data是用来填充的如果增加了大小如果减小了大小那么尾部数据会被扔掉
===
Implementation Challenges:
[]
[主要时间都浪费在了调试各种corner case上面了感觉要是自己测试根本测不出来感谢写测试的staff太强啦]
Remaining Bugs:
[]
- Optional: I had unexpected difficulty with: [describe]
@ -26,4 +39,4 @@ Remaining Bugs:
- Optional: I was surprised by: [describe]
- Optional: I'm not sure about: [describe]
- Optional: I'm not sure about: [万一eof的地方冲突了咋办虽然好像可以直接忽略来着]

View File

@ -1,24 +1,36 @@
Lab 2 Writeup
=============
My name: [your name here]
My name: Catfood
My SUNet ID: [your sunetid here]
My SUNet ID: 998244353
I collaborated with: [list sunetids here]
I collaborated with: An orange cat
I would like to thank/reward these classmates for their help: [list sunetids here]
This lab took me about [n] hours to do. I [did/did not] attend the lab session.
This lab took me about `3.5` hours to do.
Program Structure and Design of the TCPReceiver and wrap/unwrap routines:
[]
**wrap/unwrap**
这个部分有点迷惑,主要是一不小心就溢出了,然后就挂了。写的时候需要注意减法会不会出现小的-大的,因为这里是无符号操作,直接就下溢了。尤其是在比较大小的时候。
这东西我感觉有比较好的位运算解法,但是我懒得思考了。
**TCP Receiver**
这部分代码其实不多,主要是把流程整明白,以及调试各种 corner case 的过程。
- 首先判断SYN因为这个没办法通过字节流状态来判断是否已经连上了因此需要一个变量来记录状态。如果没有syn就直接返回了。发现syn之后更新一下起始序列号。
- 然后是转换成绝对序号因为要求用最后一个写入字节的序号作为checkpoint因此直接用`bytes_written`就可以了(正好对应字节的绝对序号(=流序号+1
- 接下来是一个 corner case如果一个字节的序号和SYN相同需要抛弃。因此检测绝对序号为0的时候这个数据包是不是SYN。
- 然后写入到 reassembler 里面index 需要转换一下。因为要考虑到 SYN+FIN 同时的情况因此还是选择了写一个空packet到里面然后放上 fin 的方法,这样代码会少一点。
- 最后更新 `ackno`,这里需要用到 `first unassembled = bytes_written + SYN + FIN`再wrap一下就好了。
- 其他函数的实现符合直觉,直接写就行。
Implementation Challenges:
[]
[special case 太坑了]
Remaining Bugs:
[]
[大概没有吧(悲)]
- Optional: I had unexpected difficulty with: [describe]
@ -26,4 +38,4 @@ Remaining Bugs:
- Optional: I was surprised by: [describe]
- Optional: I'm not sure about: [describe]
- Optional: I'm not sure about: [在注释里面给出了关于unwrap的时候一种特殊情况的思考]