CS144Lab/writeups/lab2.md
2023-02-16 09:26:38 +00:00

42 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Lab 2 Writeup
=============
My name: Catfood
My SUNet ID: 998244353
I collaborated with: An orange cat
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]
- Optional: I think you could make this lab better by: [describe]
- Optional: I was surprised by: [describe]
- Optional: I'm not sure about: [在注释里面给出了关于unwrap的时候一种特殊情况的思考]