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

3.0 KiB
Raw Blame History

Lab 0 Writeup

My name: Catfood

My SUNet ID: 998244353

I collaborated with: An orange cat

This lab took me about 2 hours to do.

My secret code from section 2.1 was: 294080

  • Optional: I had unexpected difficulty with: [打字的手速太慢telnet会超时]

  • Optional: I think you could make this lab better by: [describe]

  • Optional: I was surprised by: [describe]

  • Optional: I'm not sure about: [describe]

实现细节描述

2.1.2

➜  sponge git:(lab0-startercode) ✗ telnet cs144.keithw.org http
Trying 104.196.238.229...
Connected to cs144.keithw.org.
Escape character is '^]'.
GET /hello HTTP/1.1
Host: cs144.keithw.org
Connection: close

HTTP/1.1 200 OK
Date: Tue, 14 Feb 2023 14:17:29 GMT
Server: Apache
Last-Modified: Thu, 13 Dec 2018 15:45:29 GMT
ETag: "e-57ce93446cb64"
Accept-Ranges: bytes
Content-Length: 14
Connection: close
Content-Type: text/plain

Hello, CS144!
Connection closed by foreign host.

2.1.3:

➜  sponge git:(lab0-startercode) ✗ telnet cs144.keithw.org http
Trying 104.196.238.229...
Connected to cs144.keithw.org.
Escape character is '^]'.
GET /lab0/998244353 HTTP/1.1
Host: cs144.keithw.org
Connection: close

HTTP/1.1 200 OK
Date: Tue, 14 Feb 2023 14:18:54 GMT
Server: Apache
X-You-Said-Your-SunetID-Was: 998244353
X-Your-Code-Is: 294080
Content-length: 113
Vary: Accept-Encoding
Connection: close
Content-Type: text/plain

Hello! You told us that your SUNet ID was "998244353". Please see the HTTP headers (above) for your secret code.
Connection closed by foreign host.

2.2:

学校的邮件系统比较智障,做不了

2.3:

➜  sponge git:(lab0-startercode) ✗ telnet localhost 9090   
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
fuck
lalal
Connection closed by foreign host.

➜  sponge git:(lab0-startercode) ✗ netcat -v -l -p 9090
Listening on 0.0.0.0 9090
Connection received on localhost 33706
fuck
lalal

3.4:

他的提示没啥用但是doxygen里面有个例子可以直接看那个例子。 地址可以直接放域名,Address(host, protocol)这个重载是可以DNS查询的因此直接用就行然后TCP socketconnect->write->loop read就好了。

4:

Buffer开了一个STL的deque感觉是最适合做这种buffer的容器了能够前后插入删除、常数级随机访问、动态调整空间非常棒的性质。数据类型用的是charbyte方便调整。

write接口没啥东西控制一下不要超出空间就行。 read接口比较智障需要这样一个组合但是实际上好像测试的时候都没用到。。。

    std::string data_read = peek_output(len);
    pop_output(len);
    return data_read;

最智障的是它的peek_outputpop_output这两个的设计peek只能读啥也不能动因为是个const函数pop需要再把东西删掉然后read就是他们的组合。需要注意一下,更新bytes_read是在pop里面而不是read因为大概率在上层的实现中可能需要把直接调用peek和pop而不是read。