Update 计算机网络 - 应用层.md
重新绘制配图,补充 DNS 解析和输入 URL 之后的过程。
|
After Width: | Height: | Size: 156 KiB |
|
After Width: | Height: | Size: 226 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 129 KiB |
@@ -15,6 +15,7 @@
|
||||
* [2. ARP 解析 MAC 地址](#2-arp-解析-mac-地址)
|
||||
* [3. DNS 解析域名](#3-dns-解析域名)
|
||||
* [4. HTTP 请求页面](#4-http-请求页面)
|
||||
* [参考资料](#参考资料)
|
||||
<!-- GFM-TOC -->
|
||||
|
||||
|
||||
@@ -24,7 +25,11 @@ DNS 是一个分布式数据库,提供了主机名和 IP 地址之间相互转
|
||||
|
||||
域名具有层次结构,从上到下依次为:根域名、顶级域名、二级域名。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/b54eeb16-0b0e-484c-be62-306f57c40d77.jpg"/> </div><br>
|
||||
以解析 www.example.com 为例:主机先查浏览器缓存、操作系统缓存和 hosts 文件,没有命中就向本地 DNS 服务器查询。本地 DNS 服务器依次询问根服务器、com 顶级域服务器和 example.com 的权威服务器,前两者只返回下一级服务器的地址,权威服务器返回最终的 IP 地址。
|
||||
|
||||
<div align="center"> <img src="pics/dns-resolve.png" width="760px"/> </div><br>
|
||||
|
||||
主机到本地 DNS 服务器是递归查询,主机只等最终结果;本地 DNS 服务器到其它服务器是迭代查询,由它自己一步步问下去。每一级的结果都按 TTL 缓存,所以大多数查询在本地 DNS 服务器甚至主机上就能得到结果。
|
||||
|
||||
DNS 可以使用 UDP 或者 TCP 进行传输,使用的端口号都为 53。大多数情况下 DNS 使用 UDP 进行传输,这就要求域名解析器和域名服务器都必须自己处理超时和重传从而保证可靠性。在两种情况下会使用 TCP 进行传输:
|
||||
|
||||
@@ -42,11 +47,9 @@ FTP 使用 TCP 进行连接,它需要两个连接来传送一个文件:
|
||||
|
||||
- 主动模式:服务器端主动建立数据连接,其中服务器端的端口号为 20,客户端的端口号随机,但是必须大于 1024,因为 0\~1023 是熟知端口号。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/03f47940-3843-4b51-9e42-5dcaff44858b.jpg"/> </div><br>
|
||||
|
||||
- 被动模式:客户端主动建立数据连接,其中客户端的端口号由客户端自己指定,服务器端的端口号随机。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/be5c2c61-86d2-4dba-a289-b48ea23219de.jpg"/> </div><br>
|
||||
<div align="center"> <img src="pics/ftp-modes.png" width="760px"/> </div><br>
|
||||
|
||||
主动模式要求客户端开放端口号给服务器端,需要去配置客户端的防火墙。被动模式只需要服务器端开放端口号即可,无需客户端配置防火墙。但是被动模式会导致服务器端的安全性减弱,因为开放了过多的端口号。
|
||||
|
||||
@@ -63,7 +66,7 @@ DHCP 工作过程如下:
|
||||
3. 如果客户端选择了某个 DHCP 服务器提供的信息,那么就发送 Request 报文给该 DHCP 服务器。
|
||||
4. DHCP 服务器发送 Ack 报文,表示客户端此时可以使用提供给它的信息。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/23219e4c-9fc0-4051-b33a-2bd95bf054ab.jpg"/> </div><br>
|
||||
<div align="center"> <img src="pics/dhcp.png" width="780px"/> </div><br>
|
||||
|
||||
## 远程登录协议
|
||||
|
||||
@@ -77,13 +80,13 @@ TELNET 可以适应许多计算机和操作系统的差异,例如不同操作
|
||||
|
||||
邮件协议包含发送协议和读取协议,发送协议常用 SMTP,读取协议常用 POP3 和 IMAP。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/7b3efa99-d306-4982-8cfb-e7153c33aab4.png" width="700"/> </div><br>
|
||||
<div align="center"> <img src="pics/email-flow.png" width="760px"/> </div><br>
|
||||
|
||||
### 1. SMTP
|
||||
|
||||
SMTP 只能发送 ASCII 码,而互联网邮件扩充 MIME 可以发送二进制文件。MIME 并没有改动或者取代 SMTP,而是增加邮件主体的结构,定义了非 ASCII 码的编码规则。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ed5522bb-3a60-481c-8654-43e7195a48fe.png" width=""/> </div><br>
|
||||
<div align="center"> <img src="pics/mime.png" width="720px"/> </div><br>
|
||||
|
||||
### 2. POP3
|
||||
|
||||
@@ -101,14 +104,31 @@ IMAP 协议中客户端和服务器上的邮件保持同步,如果不手动删
|
||||
| 动态主机配置协议 | DHCP | 67/68 | UDP | |
|
||||
| 简单网络管理协议 | SNMP | 161/162 | UDP | |
|
||||
| 文件传送协议 | FTP | 20/21 | TCP | 控制连接 21,数据连接 20 |
|
||||
| 安全外壳协议 | SSH | 22 | TCP | |
|
||||
| 远程终端协议 | TELNET | 23 | TCP | |
|
||||
| 超文本传送协议 | HTTP | 80 | TCP | |
|
||||
| 超文本传送安全协议 | HTTPS | 443 | TCP | HTTP/3 使用 UDP |
|
||||
| 简单邮件传送协议 | SMTP | 25 | TCP | |
|
||||
| 邮件读取协议 | POP3 | 110 | TCP | |
|
||||
| 网际报文存取协议 | IMAP | 143 | TCP | |
|
||||
|
||||
## Web 页面请求过程
|
||||
|
||||
在浏览器中输入 https://www.example.com/ 并回车后,主要经过以下步骤:
|
||||
|
||||
1. 浏览器解析 URL,检查缓存,有未过期的缓存时直接使用;
|
||||
2. DNS 解析域名,得到 IP 地址;
|
||||
3. 与服务器进行 TCP 三次握手,HTTPS 还要进行 TLS 握手;
|
||||
4. 发送 HTTP 请求,服务器处理后返回响应;
|
||||
5. 浏览器解析 HTML,再请求其中引用的 CSS、JavaScript、图片等资源,最后渲染出页面;
|
||||
6. 连接保持一段时间供后续请求复用,空闲后关闭。
|
||||
|
||||
以下是本机访问该网址时各阶段的耗时:
|
||||
|
||||
<div align="center"> <img src="pics/url-timeline.png" width="760px"/> </div><br>
|
||||
|
||||
下面从网络各层的角度,看一台刚接入网络的主机发出这个请求的完整过程。
|
||||
|
||||
### 1. DHCP 配置主机信息
|
||||
|
||||
- 假设主机最开始没有 IP 地址以及其它信息,那么就需要先使用 DHCP 来获取。
|
||||
@@ -166,3 +186,8 @@ IMAP 协议中客户端和服务器上的邮件保持同步,如果不手动删
|
||||
- HTTP 服务器从 TCP 套接字读取 HTTP GET 报文,生成一个 HTTP 响应报文,将 Web 页面内容放入报文主体中,发回给主机。
|
||||
|
||||
- 浏览器收到 HTTP 响应报文后,抽取出 Web 页面内容,之后进行渲染,显示 Web 页面。
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [RFC 1035: Domain Names - Implementation and Specification](https://www.rfc-editor.org/rfc/rfc1035)
|
||||
- [RFC 2131: Dynamic Host Configuration Protocol](https://www.rfc-editor.org/rfc/rfc2131)
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="780" height="340" viewBox="0 0 780 340">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="390" y="28" class="title">DHCP:新接入的主机获取 IP 地址</text>
|
||||
<rect x="150" y="44" width="180" height="32" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="240" y="64.5" class="c sub b">客户端(还没有 IP)</text>
|
||||
<line x1="240" y1="78" x2="240" y2="300" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<rect x="470" y="44" width="180" height="32" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="560" y="64.5" class="c sub b">DHCP 服务器 192.168.1.1</text>
|
||||
<line x1="560" y1="78" x2="560" y2="300" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<line x1="240" y1="100" x2="560" y2="114" class="arrow "/>
|
||||
<text x="400" y="96" class="c sub" style="fill:#444">① Discover 0.0.0.0:68 → 255.255.255.255:67</text>
|
||||
<text x="576" y="116" class="sub">广播:有没有 DHCP 服务器?</text>
|
||||
<line x1="560" y1="150" x2="240" y2="164" class="arrow dash"/>
|
||||
<text x="400" y="146" class="c sub" style="fill:#444">② Offer 可以用 192.168.1.100,租期 1 天</text>
|
||||
<text x="228" y="166" class="sub e">附带子网掩码、网关、DNS 服务器</text>
|
||||
<line x1="240" y1="200" x2="560" y2="214" class="arrow "/>
|
||||
<text x="400" y="196" class="c sub" style="fill:#444">③ Request 我要 192.168.1.1 提供的这个地址</text>
|
||||
<text x="576" y="216" class="sub">仍是广播,其它服务器收回提议</text>
|
||||
<line x1="560" y1="250" x2="240" y2="264" class="arrow dash"/>
|
||||
<text x="400" y="246" class="c sub" style="fill:#444">④ Ack 确认,从现在起租期 1 天</text>
|
||||
<text x="228" y="266" class="sub e">客户端开始使用这个地址</text>
|
||||
<text x="30" y="316" class="sub">前两步用广播是因为客户端还没有地址,也不知道服务器在哪;租期过半时客户端会向同一台服务器申请续租。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,97 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="400" viewBox="0 0 760 400">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">DNS 解析 www.example.com</text>
|
||||
<rect x="38" y="150" width="44" height="29.92" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<rect x="42" y="154" width="36" height="21.92" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
|
||||
<path d="M56,179.92 v5 M64,179.92 v5" stroke="#7FB2D6" stroke-width="1.4"/>
|
||||
<rect x="48" y="184.92" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
|
||||
<text x="60" y="204" class="c b">主机</text>
|
||||
<text x="60" y="222" class="c sub">先查浏览器缓存、</text>
|
||||
<text x="60" y="238" class="c sub">系统缓存和 hosts</text>
|
||||
<rect x="235" y="150" width="50" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="242" cy="156.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="249" y1="156.5" x2="278" y2="156.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="235" y="166" width="50" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="242" cy="172.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="249" y1="172.5" x2="278" y2="172.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="235" y="182" width="50" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="242" cy="188.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="249" y1="188.5" x2="278" y2="188.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="260" y="214" class="c b">本地 DNS 服务器</text>
|
||||
<text x="260" y="230" class="c sub">运营商或公司提供</text>
|
||||
<rect x="507" y="60" width="46" height="13" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<circle cx="514" cy="66.5" r="2" fill="#7DBCB7"/>
|
||||
<line x1="521" y1="66.5" x2="546" y2="66.5" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<rect x="507" y="76" width="46" height="13" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<circle cx="514" cy="82.5" r="2" fill="#7DBCB7"/>
|
||||
<line x1="521" y1="82.5" x2="546" y2="82.5" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<text x="566" y="72" class="b">根服务器</text>
|
||||
<text x="566" y="88" class="sub mono">a.root-servers.net</text>
|
||||
<line x1="290" y1="156" x2="502" y2="68" class="arrow "/>
|
||||
<line x1="502" y1="86" x2="292" y2="166" class="arrow dash"/>
|
||||
<text x="566" y="106" class="sub" style="fill:#444">去问 com 的服务器</text>
|
||||
<text x="566" y="122" class="sub mono">a.gtld-servers.net 等</text>
|
||||
<rect x="507" y="160" width="46" height="13" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<circle cx="514" cy="166.5" r="2" fill="#7DBCB7"/>
|
||||
<line x1="521" y1="166.5" x2="546" y2="166.5" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<rect x="507" y="176" width="46" height="13" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<circle cx="514" cy="182.5" r="2" fill="#7DBCB7"/>
|
||||
<line x1="521" y1="182.5" x2="546" y2="182.5" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<text x="566" y="172" class="b">com 顶级域服务器</text>
|
||||
<text x="566" y="188" class="sub mono">a.gtld-servers.net</text>
|
||||
<line x1="290" y1="162" x2="502" y2="168" class="arrow "/>
|
||||
<line x1="502" y1="186" x2="292" y2="172" class="arrow dash"/>
|
||||
<text x="566" y="206" class="sub" style="fill:#444">去问 example.com 的服务器</text>
|
||||
<text x="566" y="222" class="sub mono">hera.ns.cloudflare.com 等</text>
|
||||
<rect x="507" y="260" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="514" cy="266.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="521" y1="266.5" x2="546" y2="266.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="507" y="276" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="514" cy="282.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="521" y1="282.5" x2="546" y2="282.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="566" y="272" class="b">权威服务器</text>
|
||||
<text x="566" y="288" class="sub mono">hera.ns.cloudflare.com</text>
|
||||
<line x1="290" y1="168" x2="502" y2="268" class="arrow "/>
|
||||
<line x1="502" y1="286" x2="292" y2="178" class="arrow dash"/>
|
||||
<text x="566" y="306" class="sub" style="fill:#444">www.example.com 的 A 记录</text>
|
||||
<text x="566" y="322" class="sub mono">104.20.23.154,TTL 300</text>
|
||||
<line x1="86" y1="160" x2="228" y2="160" class="arrow "/>
|
||||
<text x="157" y="150" class="c sub">① 递归查询</text>
|
||||
<line x1="228" y1="176" x2="86" y2="176" class="arrow dash"/>
|
||||
<text x="157" y="192" class="c sub">④ 返回结果</text>
|
||||
<text x="260" y="262" class="c sub" style="fill:#296898">② 迭代查询:每台服务器</text>
|
||||
<text x="260" y="278" class="c sub" style="fill:#296898">只告诉下一步去问谁</text>
|
||||
<text x="260" y="302" class="c sub" style="fill:#207773">③ 按 TTL 缓存 300 秒</text>
|
||||
<text x="30" y="352" class="sub">图中的服务器和 TTL 是本机用 dig 逐级查询的结果:根服务器和 com 服务器返回的是下一级的 NS 记录(缓存 2 天),</text>
|
||||
<text x="30" y="370" class="sub">只有权威服务器的回答带有 aa(权威回答)标志。缓存命中时,前面任何一级都可以直接返回,不必走完全程。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.6 KiB |
@@ -0,0 +1,76 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="260" viewBox="0 0 760 260">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">电子邮件:alice@a.com 发信给 bob@b.com</text>
|
||||
<circle cx="50" cy="79" r="9" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
|
||||
<path d="M33,110 q0,-19 17,-19 q17,0 17,19 z" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
|
||||
<text x="50" y="130" class="c sub b">alice</text>
|
||||
<text x="50" y="146" class="c sub">用户代理</text>
|
||||
<rect x="227" y="74" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="234" cy="80.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="241" y1="80.5" x2="266" y2="80.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="227" y="90" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="234" cy="96.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="241" y1="96.5" x2="266" y2="96.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="227" y="106" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="234" cy="112.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="241" y1="112.5" x2="266" y2="112.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="250" y="138" class="c sub b">a.com 邮件服务器</text>
|
||||
<rect x="477" y="74" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="484" cy="80.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="491" y1="80.5" x2="516" y2="80.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="477" y="90" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="484" cy="96.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="491" y1="96.5" x2="516" y2="96.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="477" y="106" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="484" cy="112.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="491" y1="112.5" x2="516" y2="112.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="500" y="138" class="c sub b">b.com 邮件服务器</text>
|
||||
<circle cx="700" cy="79" r="9" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
|
||||
<path d="M683,110 q0,-19 17,-19 q17,0 17,19 z" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
|
||||
<text x="700" y="130" class="c sub b">bob</text>
|
||||
<text x="700" y="146" class="c sub">用户代理</text>
|
||||
<rect x="96" y="74" width="110" height="28" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<path d="M96,75 L110,85 L124,75" fill="none" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="130" y="92" class="sub b">SMTP</text>
|
||||
<line x1="80" y1="108" x2="222" y2="108" class="arrow "/>
|
||||
<line x1="278" y1="98" x2="472" y2="98" class="arrow "/>
|
||||
<text x="375" y="88" class="c sub b">SMTP(端口 25)</text>
|
||||
<text x="375" y="120" class="c sub">先查 b.com 的 MX 记录</text>
|
||||
<text x="375" y="136" class="c sub">找到对方的邮件服务器</text>
|
||||
<line x1="672" y1="98" x2="528" y2="98" class="arrow dash"/>
|
||||
<text x="600" y="88" class="c sub b">POP3 或 IMAP</text>
|
||||
<text x="600" y="120" class="c sub">bob 主动来取</text>
|
||||
<text x="30" y="196" class="sub">发送和服务器之间的转发用 SMTP,是“推”;收件人读取用 POP3 或 IMAP,是“拉”。</text>
|
||||
<text x="30" y="214" class="sub">邮件先存放在收件方的服务器上,bob 不在线也不影响 alice 发信。</text>
|
||||
<text x="30" y="238" class="sub">(用户代理到发件服务器之间通常使用端口 587 并要求登录。)</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,82 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="300" viewBox="0 0 760 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">FTP 的主动模式与被动模式</text>
|
||||
<text x="190" y="56" class="c b">主动模式</text>
|
||||
<rect x="48" y="90" width="44" height="29.92" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<rect x="52" y="94" width="36" height="21.92" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
|
||||
<path d="M66,119.92 v5 M74,119.92 v5" stroke="#7FB2D6" stroke-width="1.4"/>
|
||||
<rect x="58" y="124.92" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
|
||||
<text x="70" y="146" class="c sub b">客户端</text>
|
||||
<rect x="297" y="86" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="304" cy="92.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="311" y1="92.5" x2="336" y2="92.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="297" y="102" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="304" cy="108.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="311" y1="108.5" x2="336" y2="108.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="297" y="118" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="304" cy="124.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="311" y1="124.5" x2="336" y2="124.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="320" y="146" class="c sub b">服务器</text>
|
||||
<line x1="100" y1="100" x2="292" y2="100" class="arrow "/>
|
||||
<text x="196" y="92" class="c sub mono">控制连接 → 21</text>
|
||||
<text x="196" y="118" class="c sub mono" style="fill:#296898">PORT 192,168,1,10,195,81</text>
|
||||
<line x1="292" y1="132" x2="100" y2="132" class="arrow red"/>
|
||||
<text x="196" y="152" class="c sub mono" style="fill:#C0605A">数据连接 20 → 50001</text>
|
||||
<text x="196" y="184" class="c sub">服务器主动连接客户端的 50001,</text>
|
||||
<text x="196" y="200" class="c sub">客户端的防火墙要放行</text>
|
||||
<text x="560" y="56" class="c b">被动模式</text>
|
||||
<rect x="418" y="90" width="44" height="29.92" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<rect x="422" y="94" width="36" height="21.92" rx="1.5" fill="#FFFFFF" stroke="#7FB2D6" stroke-width="0.8"/>
|
||||
<path d="M436,119.92 v5 M444,119.92 v5" stroke="#7FB2D6" stroke-width="1.4"/>
|
||||
<rect x="428" y="124.92" width="24" height="3.5" rx="1.5" fill="#7FB2D6"/>
|
||||
<text x="440" y="146" class="c sub b">客户端</text>
|
||||
<rect x="667" y="86" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="674" cy="92.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="681" y1="92.5" x2="706" y2="92.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="667" y="102" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="674" cy="108.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="681" y1="108.5" x2="706" y2="108.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="667" y="118" width="46" height="13" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<circle cx="674" cy="124.5" r="2" fill="#7FB2D6"/>
|
||||
<line x1="681" y1="124.5" x2="706" y2="124.5" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="690" y="146" class="c sub b">服务器</text>
|
||||
<line x1="470" y1="100" x2="662" y2="100" class="arrow "/>
|
||||
<text x="566" y="92" class="c sub mono">控制连接 → 21</text>
|
||||
<text x="566" y="118" class="c sub mono" style="fill:#296898">PASV → 227 (…,195,82)</text>
|
||||
<line x1="470" y1="132" x2="662" y2="132" class="arrow green"/>
|
||||
<text x="566" y="152" class="c sub mono" style="fill:#6A9F68">数据连接 → 50002</text>
|
||||
<text x="566" y="184" class="c sub">客户端主动连接服务器的 50002,</text>
|
||||
<text x="566" y="200" class="c sub">服务器要开放一段端口</text>
|
||||
<text x="30" y="252" class="sub">PORT 和 PASV 的回复中,最后两个数字表示端口:195 × 256 + 81 = 50001,195 × 256 + 82 = 50002。</text>
|
||||
<text x="30" y="272" class="sub">客户端通常在 NAT 和防火墙之后,服务器连不进来,所以现在多用被动模式。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 5.5 KiB |
@@ -0,0 +1,52 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="220" viewBox="0 0 720 220">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="360" y="28" class="title">MIME:把非 ASCII 内容编码成 ASCII 字符</text>
|
||||
<text x="90" y="62" class="c sub b" style="fill:#444">邮件主题</text>
|
||||
<rect x="30" y="72" width="120" height="36" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="90" y="94" class="c b" style="fill:#444">你好</text>
|
||||
<line x1="152" y1="90" x2="188" y2="90" class="arrow "/>
|
||||
<text x="265" y="62" class="c sub b" style="fill:#444">UTF-8 编码</text>
|
||||
<rect x="190" y="72" width="150" height="36" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="265" y="94" class="c sub mono" style="fill:#444">e4 bd a0 e5 a5 bd</text>
|
||||
<line x1="342" y1="90" x2="378" y2="90" class="arrow "/>
|
||||
<text x="435" y="62" class="c sub b" style="fill:#444">Base64</text>
|
||||
<rect x="380" y="72" width="110" height="36" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="435" y="94" class="c sub mono" style="fill:#444">5L2g5aW9</text>
|
||||
<line x1="492" y1="90" x2="528" y2="90" class="arrow "/>
|
||||
<text x="615" y="62" class="c sub b" style="fill:#444">邮件首部</text>
|
||||
<rect x="530" y="72" width="170" height="36" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<text x="615" y="94" class="c sub mono" style="fill:#444">=?utf-8?b?5L2g5aW9?=</text>
|
||||
<text x="30" y="150" class="sub">SMTP 最初只能传送 7 位 ASCII 文本。MIME 不改变 SMTP,只规定如何把中文、图片、附件等内容编码成 ASCII:</text>
|
||||
<text x="30" y="168" class="sub">Base64 把每 3 个字节变成 4 个可打印字符,6 个字节的“你好”编码后是 8 个字符;收件方按首部中注明的</text>
|
||||
<text x="30" y="186" class="sub">字符集和编码方式还原。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,63 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="330" viewBox="0 0 760 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">访问 https://www.example.com/ 的耗时(本机一次实测,RTT 约 200 ms)</text>
|
||||
<text x="148" y="82" class="sub b e" style="fill:#444">DNS 解析</text>
|
||||
<rect x="160" y="64" width="6.15385" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="174.154" y="82" class="sub">10 ms,命中缓存</text>
|
||||
<text x="148" y="128" class="sub b e" style="fill:#444">TCP 三次握手</text>
|
||||
<rect x="166.154" y="110" width="123.077" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="297.231" y="128" class="sub">1 个 RTT</text>
|
||||
<text x="148" y="174" class="sub b e" style="fill:#444">TLS 1.3 握手</text>
|
||||
<rect x="289.231" y="156" width="131.077" height="26" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<text x="428.308" y="174" class="sub">1 个 RTT</text>
|
||||
<text x="148" y="220" class="sub b e" style="fill:#444">请求到首字节</text>
|
||||
<rect x="420.308" y="202" width="126.769" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="555.077" y="220" class="sub">1 个 RTT + 服务器处理</text>
|
||||
<line x1="160" y1="250" x2="160" y2="255" stroke="#999"/>
|
||||
<text x="160" y="270" class="c sub mono">0 ms</text>
|
||||
<line x1="221.538" y1="250" x2="221.538" y2="255" stroke="#999"/>
|
||||
<text x="221.538" y="270" class="c sub mono">100 ms</text>
|
||||
<line x1="283.077" y1="250" x2="283.077" y2="255" stroke="#999"/>
|
||||
<text x="283.077" y="270" class="c sub mono">200 ms</text>
|
||||
<line x1="344.615" y1="250" x2="344.615" y2="255" stroke="#999"/>
|
||||
<text x="344.615" y="270" class="c sub mono">300 ms</text>
|
||||
<line x1="406.154" y1="250" x2="406.154" y2="255" stroke="#999"/>
|
||||
<text x="406.154" y="270" class="c sub mono">400 ms</text>
|
||||
<line x1="467.692" y1="250" x2="467.692" y2="255" stroke="#999"/>
|
||||
<text x="467.692" y="270" class="c sub mono">500 ms</text>
|
||||
<line x1="529.231" y1="250" x2="529.231" y2="255" stroke="#999"/>
|
||||
<text x="529.231" y="270" class="c sub mono">600 ms</text>
|
||||
<line x1="160" y1="250" x2="560" y2="250" class="line"/>
|
||||
<text x="30" y="300" class="sub">curl -w 测得:time_connect 0.210 s、time_appconnect 0.423 s、time_starttransfer 0.629 s。</text>
|
||||
<text x="30" y="318" class="sub">HTTPS 首次请求至少要 3 个 RTT 才能收到响应,这也是连接复用、TLS 会话恢复和 HTTP/3 要解决的问题。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.9 KiB |