Networking and the Internet, from First Principles

Networking and the Internet, from First Principles

网络与互联网:从第一性原理出发

Have you ever wondered what happens when we text, call, or video chat with a friend or a colleague on another continent, and their reply arrives in a fraction of a second, as though they were in the same room? 你是否曾好奇过,当我们与身处另一大洲的朋友或同事发短信、通话或视频聊天时,对方的回复能在不到一秒的时间内送达,仿佛他们就在同一个房间里,这背后究竟发生了什么?

Behind the scenes, a chain of invisible conversions takes place: your voice, video, or message is translated into radio waves crossing the room to your Wi-Fi router, then electrical pulses in copper (or light, if you have a fiber connection), and then flashes of light inside a glass strand thinner than a hair lying deep on the ocean floor, only for the entire sequence to play in reverse at the other end. 在幕后,一系列隐形的转换正在发生:你的语音、视频或消息被转化为无线电波,穿过房间到达 Wi-Fi 路由器,随后变成铜线中的电脉冲(如果你使用光纤,则是光脉冲),接着变成深埋海底、比头发丝还细的玻璃纤维中的闪烁光信号,最后在另一端将整个过程反向重演。

I find it mind-boggling that we can communicate instantly with anyone in the world by doing nothing more than creating controlled, patterned disturbances of electricity, light, and radio. 我感到不可思议的是,我们仅仅通过制造受控的、有规律的电、光和无线电扰动,就能与世界上的任何人即时沟通。

The message passes through equipment owned by dozens of independent companies in different countries. None of them coordinated with the others specifically for this message transfer, and none of them knows the full path your data took, they just hand it off to the next closest route. 这些信息会经过由不同国家数十家独立公司拥有的设备。它们之间并没有为了这次信息传输进行专门的协调,也没有任何一家公司知道你的数据所经过的完整路径,它们只是将数据传递给下一个最近的路由。

There is no central computer directing the traffic, and no single company owns the internet infrastructure. Yet it works, billions of times every second, so reliably that we only notice it when a call stutters or video buffers. 没有中央计算机在指挥流量,也没有任何一家公司拥有整个互联网基础设施。然而它却能每秒运行数十亿次,且极其可靠,以至于我们只有在通话卡顿或视频缓冲时才会注意到它的存在。

The software article followed the story of a single machine, from electrons in silicon up to the software you run. This article follows the story of the connections between those machines. 之前的软件文章讲述了单台机器的故事,从硅片中的电子一直到你运行的软件。而本文将讲述这些机器之间连接的故事。

Like the layers of computing, the internet was not designed in one stroke; it accumulated over decades, and each protocol makes sense only once you see the concrete limitation it was invented to fix. 就像计算的分层一样,互联网并非一蹴而就;它是经过数十年积累而成的,只有当你了解了每种协议旨在解决的具体局限性时,你才能理解它的意义。

It is easy to mistake the result for something engineered to a finished blueprint, because failures are rare enough to feel like the system was always this reliable. In reality, every mechanism in this article, packet switching, TCP, DNS, and TLS, was a patch for a specific problem, deployed decades after the internet already “worked”. 人们很容易误以为互联网是按照一份完整的蓝图设计出来的,因为故障太少见,以至于让人觉得系统一直都如此可靠。实际上,本文提到的每一个机制——分组交换、TCP、DNS 和 TLS——都是针对特定问题的补丁,它们是在互联网已经“能用”之后数十年才部署的。

My aim is to build this understanding from first principles. By the end, many of the everyday mysteries of using the internet will make intuitive sense under a single, coherent mental model. 我的目标是从第一性原理出发建立这种理解。读完本文后,许多使用互联网时的日常谜题,都将在一个统一、连贯的思维模型下变得直观易懂。

Networking is much older than computing, and older than electricity too. The word network itself originally meant exactly what it sounds like, a net-like fabric of threads or cords crossing at regular intervals. 网络(Networking)的历史比计算久远得多,甚至比电力还要古老。“网络”(network)这个词本身最初的意思就如其字面所示:一种由线绳在规则间隔处交叉而成的网状织物。

In the early 19th century, engineers borrowed the term to describe interconnected transit routes like canals and railways. When the electrical telegraph arrived in the 1840s, the word drifted naturally to describe the systems of wires and stations that carried its signals. 19 世纪初,工程师们借用这个词来描述运河和铁路等相互连接的交通路线。当 1840 年代电报出现时,这个词自然而然地被用来描述承载其信号的电线和站点系统。

Yet the basic physical principle of a network link remains the same as the simplest mechanical connection. Knot a string tight between two tin cans, speak into one, and the string carries the vibration of your voice to the other as mechanical motion with no amplifier or relay, just a wave losing energy to friction and slack with every meter it crosses. 然而,网络链路的基本物理原理与最简单的机械连接并无二致。在两个罐头之间系紧一根绳子,对着其中一个说话,绳子就会将你声音的振动作为机械运动传导到另一个罐头,无需放大器或中继器,只是波在传播的每一米中因摩擦和松弛而损失能量。

That is already the whole principle behind every link built since, vary a physical quantity at one end and measure it at the other. 这正是此后建立的每一个链路背后的全部原理:在一端改变一个物理量,并在另一端测量它。

The telegraph’s true breakthrough wasn’t just replacing string with electrical wire, but overcoming this physical limit of distance. In 1844, Samuel Morse sent the message “What hath God wrought” from Washington to Baltimore over a copper wire, using Morse code, a system of short and long electrical pulses. 电报真正的突破不仅仅是用电线代替了绳子,而是克服了距离的物理限制。1844 年,塞缪尔·莫尔斯通过铜线从华盛顿向巴尔的摩发送了“上帝创造了什么”(What hath God wrought)这条信息,使用的是莫尔斯电码——一种由长短电脉冲组成的系统。

Notice what the telegraph actually was, a digital network. It did not transmit the sound of a voice; it transmitted discrete symbols from a fixed alphabet. That choice had an advantage the Victorians understood well. 请注意电报的本质:它是一个数字网络。它传输的不是声音,而是来自固定字母表的离散符号。维多利亚时代的人们很清楚这种选择的优势。

An electromechanical relay along the line didn’t need to pass the wave itself; it only needed to detect whether a pulse was present, and then recreate a brand new, clean copy of that pulse to send down the next segment of wire. Discrete symbols plus regeneration meant a message could cross a continent without degrading, something no analog signal could do. 线路上的机电继电器不需要传输波本身;它只需要检测是否存在脉冲,然后重新生成一个全新的、干净的脉冲副本,发送到下一段电线上。离散符号加上再生,意味着信息可以跨越整个大陆而不发生衰减,这是任何模拟信号都无法做到的。

Notice also what had to exist before the wire could carry anything, an agreement between sender and receiver. The telegraph only worked because both ends held the same table in advance, which pulses stood for which letters, and how operators signaled “received” or “repeat.” This shared rulebook is a protocol. 还要注意在电线传输任何东西之前必须存在的前提:发送方和接收方之间的协议。电报之所以能工作,是因为双方预先掌握了相同的对照表,即哪些脉冲代表哪些字母,以及操作员如何发出“已收到”或“重发”的信号。这套共享的规则手册就是协议(protocol)。