\documentclass[全部作业]{subfiles}
\input{mysubpreamble}
\setcounter{chapter}{1}
\begin{document}
    \chapter{应用层}
    \begin{enumerate}
        \cnitem[2] Consider an HTTP client that wants to retrieve a Web document at a given URL.
        The IP address of the HTTP server is initially unknown. What transport and
        application-layer protocols besides HTTP are needed in this scenario?

        \begin{zhongwen}
            首先，客户端需要根据URL中的域名找到IP地址，这需要DNS协议（这是应用层协议），而DNS协议是基于UDP协议的（这是传输层协议）。之后的HTTP协议如果不是HTTP3.0，则是基于TCP协议的（这是传输层协议），如果是HTTP3.0，则是基于UDP协议的（这是传输层协议）。

            总结：如果是HTTP3.0，则还需要应用层协议DNS，传输层协议UDP；
                如果不是HTTP3.0，则还需要应用层协议DNS，传输层协议UDP、TCP。
        \end{zhongwen}

        \cnitem[8] Suppose within your Web browser you click on a link to obtain a Web page. The
        IP address for the associated URL is not cached in your local host, so a DNS lookup is
        necessary to obtain the IP address. Suppose that $n$ DNS servers are visited before your
        host receives the IP address from DNS; the successive visits incur an RTT of
        RTT$_1$, $\cdots$, RTT$_n$. Further suppose that the Web page associated with the link contains
        exactly one object, consisting of a small amount of HTML text. Let RTT$_0$ denote the
        RTT between the local host and the server containing the object. Assuming zero
        transmission time of the object, how much time elapses from when the client clicks on
        the link until the client receives the object?
        
            \begin{zhongwen}
                首先，需要查询DNS，由于DNS基于UDP，因此需要$\sum_{i=1}^{n}RTT_i$的时间完成DNS查询。之后的网页应该是通过HTTP协议传输，假定这里使用的不是HTTP 3.0，那么这里是基于TCP协议的HTTP协议，因此需要$RTT_0$的时间建立TCP连接，之后请求和响应还需要一个$RTT_0$的时间。

                因此总的时间为：
                $$
                \sum_{i=1}^{n}RTT_{i} + 2RTT_0
                $$
            \end{zhongwen}
        
        \cnitem[9] Referring to Problem P8, suppose the HTML file references three very small
        objects on the same server. Neglecting transmission times, how much time elapses
        with
        \begin{enumerate}
            \item Non-persistent HTTP with parallel connections?
            
                \begin{zhongwen}
                    每次请求和响应都需要开启一个新的TCP连接，但这些连接可以同时进行，因此需要的时间为：
                    $$
                    \sum_{i=1}^{n}RTT_{i}+2RTT_0+2RTT_0=\sum_{i=1}^{n}RTT_i+4RTT_0
                    $$
                \end{zhongwen}

            \item Non-persistent HTTP with no parallel TCP connections?
            
                \begin{zhongwen}
                    每次请求和响应都需要开启一个新的TCP连接，而且这些连接不能同时进行，因此需要的时间为：
                    $$
                    \sum_{i=1}^{n}RTT_{i}+2RTT_0+3\times 2RTT_0=\sum_{i=1}^{n}RTT_i+8RTT_0
                    $$
                \end{zhongwen}

            \item Persistent HTTP?
            
                \begin{zhongwen}
                    只开启一个TCP连接，并且在这个TCP连接中，HTTP请求互相不阻塞，也就是说不需要等到前一个HTTP请求收到响应后再发送后一个HTTP请求，由于忽略传输时间，因此可以认为这三个请求同时发出，同时得到响应。但这三个请求还是会依赖于HTML文件的响应，因此在DNS查询后，需要建立一次TCP连接，之后在这个连接上进行两批HTTP的请求和响应，因此总的时间为：
                    $$
                    \sum_{i=1}^{n}RTT_{i}+RTT_0+2RTT_0=\sum_{i=1}^{n}RTT_{i}+3RTT_0
                    $$
                \end{zhongwen}

        \end{enumerate}
        
        \cnitem[11] What is the difference between \textit{MAIL FROM}: in SMTP and \textit{From}: in the mail
        message itself?

            \begin{zhongwen}
                SMTP中的\textit{MAIL FROM}表示发信的SMTP服务器的地址与发信的用户名，而邮件信息中的\textit{From}是用户自己填写的内容。

                也就是说，一封邮件可能经过很多次转发，而SMTP中的\textit{MAIL FROM}就是每次转发时直接发信的服务器和用户名，而邮件信息中的\textit{From}是写信的人。

                当然，由于\textit{From}是可以由用户自己编辑的，所以用户也可以填写一个虚假的发信的邮箱地址，而用户就无法在\textit{MAIL FROM}上造假了（除非用户用自己的SMTP服务器）。
            \end{zhongwen}

        \cnitem[15] Consider accessing your e-mail with POP3.
        \begin{enumerate}
            \item Suppose you have configured your POP mail client to operate in the
            \textit{download-and-keep} mode. Complete the following transaction:

            % 这种需要分栏的情况可以用minipage也可以用multicol，具体哪个更好呢？
            
            \begin{minipage}[H]{0.3\linewidth}
                \begin{minted}{text}
C: list
S: 1 498
S: 2 912
S: .
C: retr 1
S: blah blah ...
S: ..........blah
S: .
?
?
                \end{minted}
            \end{minipage}
            {\Huge$\longrightarrow$}
            \begin{minipage}[H]{0.3\linewidth}
                \begin{minted}{text}
    C: list
    S: 1 498
    S: 2 912
    S: .
    C: retr 1
    S: blah blah ...
    S: ..........blah
    S: .
    C: retr 2
    S: blah blah ...
    S: ..........blah
    S: .
    C: quit
    S: +OK POP3 server signing off
                \end{minted}
            \end{minipage}
        
            \item Suppose you have configured your POP mail client to operate in the
            \textit{download-and-delete} mode. Complete the following transaction:

            \begin{minipage}[H]{0.3\linewidth}
                \begin{minted}{text}
S: ..........blah
S: .
?
?
                \end{minted}
            \end{minipage}
            {\Huge$\longrightarrow$}
            \begin{minipage}[H]{0.3\linewidth}
                \begin{minted}{text}
    S: ..........blah
    S: .
    C: dele 1
    C: retr 2
    S: blah blah ...
    S: ..........blah
    S: .
    C: dele 2
    C: quit
    S: +OK POP3 server signing off
                \end{minted}
            \end{minipage}

            \item Suppose you have configured your POP mail client to operate in the
            \textit{download-and-keep} mode. Using your transcript in part (b), suppose you retrieve
            messages 1 and 2, exit POP, and then five minutes later you again access POP to
            retrieve new e-mail. Suppose that in the five-minute interval no new messages have
            been sent to you. Provide a transcript of this second POP session.


            \begin{minted}{text}
                C: list
                S: 1 498
                S: 2 912
                S: .
                C: retr 1
                S: blah blah ...
                S: ..........blah
                S: .
                C: retr 2
                S: blah blah ...
                S: ..........blah
                S: .
                C: quit
                S: +OK POP3 server signing off
            \end{minted}
        \end{enumerate}
        \item Consider query flooding, as discussed in Section 2.6. Suppose that each peer is
        connected to at most $N$ neighbors in the overlay network. Also suppose that the
        node-count field is initially set to $K$. Suppose Alice makes a query. Find an upper
        bound on the number of query messages that are sent into the overlay network.

        \begin{zhongwen}
            每个节点最多向$N$个邻居节点发送查询信息，但是不应向给自己发送查询信息的服务器发送查询信息，因此除了Alice外，每个邻居最多向$N-1$个邻居节点发送查询信息。而Alice因为是查询的发起者，所以最多向$N$个邻居节点发送查询信息。
            
            因此，设Alice发起的查询为第$0$次查询，邻居发送给邻居的邻居为第$1$次查询，依此类推。设$a_i$ $(i\in \mathbb{N})$表示第$i$次查询时新收到查询的邻居数，则$a_{i+1}=a_i\times (N-1)$，且$a_0=N$。这样的查询最多执行$K$轮，那么最多发送的查询信息数也就是所有收到查询的邻居数的总和，因此只需要将每次查询时新收到查询的邻居数求和即可。

            因此最多发送的查询信息数为：
            $$
            \underbrace{a_0+a_1+a_2+ \cdots}_{K个}=\underbrace{N+N(N-1)+N(N-1)^{2}+ \cdots }_{K个}
            $$

            可以看到$\{ a_n \}_{n=1}^{\infty}$构成等比数列，所求的值为它的前$K$项求和，因此上式可化为：
            $$
            \frac{N(1-(N-1)^{K})}{1-(N-1)}=\frac{N(1-(N-1)^{K})}{2-N}
            $$
        \end{zhongwen}
    \end{enumerate}
\end{document}