II · The Box You Don't Control · Chapter 3

You Can Reach Out but Not Be Reached

Timeouts

Mira’s new flat has internet. She opens Courtyard on her phone and, out of habit from the courtyard days, when your machine sometimes ran the chat, tells it to connect directly to yours. Nothing happens. The connection attempt times out. It is not refused, since Chapter 8’s nobody-home would have come back at once; there is only silence, as if your machine did not exist. You try connecting to hers and get the same silence.

Then you both open the feed, which is hosted on a rented machine somewhere, and it works at once. You can reach out. Neither of you can be reached. This is the clause of the contract that you were told to hold a place for.

Look at your machine’s address. It is 192.168.1.23. Now ask Mira for hers, and she reads it off: 192.168.1.23. Two machines ten kilometres apart have the same address. Chapter 5 said that an address names a location, and two machines cannot have one. And yet here they are, each reachable from inside its own building and invisible from outside. Something has happened to addresses between Part I and now, and what happened is that the world ran out of them.

Thirty-two bits gives about 4.3 billion addresses. That sounded like plenty in 1981. But hierarchy, Chapter 5’s own trick, wastes some of them: addresses are handed out in blocks, blocks are sized generously, and a building that needs two hundred gets two hundred and fifty-six. By the mid-1990s there were more devices wanting addresses than there were addresses, and the trend line was obvious to everyone.

Two fixes were possible. One was to make addresses wider, with a new format four times as long, which meant changing every box, every operating system, and every program that ever touched an address. The other required only one box to change, the one at the edge of your building. The second happened first, because it could.

It works like this. Your building gets one public address, say 203.0.113.9. Every machine inside gets a private address, from a range reserved for this purpose which the box promises never to forward: 192.168.x.x, 10.x.x.x, and one more. Those addresses mean something only inside the building. Mira’s building uses the same range, and there is no reason it should not, because the two sets of addresses never meet.

The router at your edge does the work. When your machine sends a piece from 192.168.1.23, port 51844, the router rewrites it before forwarding. The source becomes 203.0.113.9, port 40001, and the router writes the mapping down in a table:

inside                    outside
192.168.1.23 : 51844  ↔   203.0.113.9 : 40001
192.168.1.40 : 60122  ↔   203.0.113.9 : 40002
192.168.1.7  : 51844  ↔   203.0.113.9 : 40003

The piece goes out looking as though it came from the public address on port 40001. Courtyard’s server replies to 203.0.113.9:40001. The reply arrives at the router; the router looks up 40001, finds 192.168.1.23:51844, rewrites the destination back, and hands the piece inside. Your machine never knows. The server never knows. Twenty machines share one address, told apart by the port the router assigned to each conversation.

That is the whole mechanism, and it is called network address translation, or NAT. It is built out of the ports from Chapter 7, which were invented to tell programs apart on one machine; the router has repurposed them to tell machines apart behind one address. It works because a port number is sixteen bits and a building does not have sixty-five thousand simultaneous conversations. It also means that a box in the middle is reading and rewriting the transport header, which Chapter 22 told you it was not supposed to touch. That was the first place the layered model lied to you.

loading…

The router’s table. Machines inside open conversations, rows appear, and replies find their way back. A knock on the public address from outside, on a port with no row, goes nowhere. A conversation left idle shows its row’s timer running down.

Now knock. Mira’s phone sends a piece to 203.0.113.9, port 5222, which is your chat at your public address. It arrives at your router, and the router looks up 5222 in its table. There is no row. Nothing inside has sent anything from 5222 out through this router, so no mapping was ever created. The router has a piece, twenty machines behind it, and no idea which of them the piece is for, if any. It does the only thing it can do, which is to drop the piece, silently. Mira’s phone hears nothing and times out.

That is the silence you got. It was not a refusal, because a refusal would need the piece to reach a machine that could refuse. It was nothing, because the piece never got past the door.

So the contract’s hidden clause, in full, is that an unrequested piece cannot find you. You can start a conversation, because starting creates a row. You cannot receive one, because receiving needs a row that does not exist until you have started. Behind a shared address every machine is a client and none is a server. The address you share is a door that opens only from the inside.

None of this was designed as protection. It is a side effect of sharing; the router does not have the information it would need to deliver an inbound knock. But it acts as protection, and within a few years of NAT becoming universal, the assumption that a machine in a home could not be reached from outside was so complete that it became the default posture of the whole internet. Nothing gets in unless something inside asked for it.

The consequence of this is the reason a whole category of software is shaped the way it is. Two phones, in two buildings, behind two routers. Neither can knock on the other. Mira cannot reach you and you cannot reach Mira, and there is no arrangement of the two of you alone that produces a conversation.

But both of you can reach out. If there is a third machine, one with a public address that is not behind anyone’s shared door, you can both reach out to it. Mira’s phone connects to it, creating a row in her router. Your phone connects to it, creating a row in yours. Now the third machine has an open conversation with each of you, and when Mira sends it a message meant for you, it forwards the message down the conversation it already has with your phone. Your phone started that conversation, so your router has a row for it, so the piece gets in.

loading…

Two phones behind two boxes, each trying to knock on the other, each knock dying at the far door. Then a third machine with a public address appears. Both phones reach out to it and it relays between them. The idle timers on both routers’ rows count down, and the heartbeat resets them.

That third machine is Courtyard’s server, and it exists because of this clause. It does not exist because centralisation is neat, or because someone wanted to own the conversation, but because the box will not let Mira’s phone knock on yours, and the only thing the box permits is for both of you to knock on something that is not behind a door. The chat server is a workaround for NAT that became the architecture. When you build Part III’s version of Courtyard, remember that its very first design decision, that there is a server, was made for you by the shape of the box.

The feed, which was always request and response, has the same requirement for the same reason. Anything that must be reached needs a public address, which means it cannot be your laptop, which means it is hosted, rented, on a machine with a door that opens both ways. The word “server” in Part III means, more than anything else, a machine that can be knocked on.

There is one more consequence, and it is the one Chapter 13 promised you. The router’s table has a fixed size, and rows are cheap to create, one per outgoing conversation and thousands a day from a busy building. If rows lived forever the table would fill. So the router does the obvious thing and forgets rows that have gone quiet. When no pieces have passed in either direction for a few minutes, the row is deleted. The exact interval is the router’s choice, and it varies from thirty seconds to a few hours depending on the make and on the transport.

Now consider your phone’s connection to Courtyard’s server. You opened it this morning, and you have been reading rather than typing for twenty minutes. Nothing has crossed the router in either direction, and the row expires. Your phone’s operating system still has the connection, four-tuple, buffers and all. The server’s still has it too. Both ends believe they are connected. Then Mira sends you a message; the server forwards it down your connection; the piece arrives at your router; the router looks for the row; and there is none. The piece is dropped.

You have built Chapter 13’s half-open connection, except that neither end died. The middle forgot. And the middle will never tell either of you, since it owes you no such thing, so the server keeps sending into the void and your phone keeps waiting, and you do not see Mira’s message until your phone eventually tries to send something, gets no acknowledgement, times out, and reconnects.

The heartbeat is the fix, though not because it detects death this time. A heartbeat is a piece crossing the router, and every piece that crosses resets the row’s timer. Send something more often than the router forgets and the row never expires. That is the real reason chat applications pulse every thirty seconds or so, and it is why the operating system’s two-hour keepalive from Chapter 13 is useless here, since the row is long gone by two hours. The heartbeat interval, which in Part I was about detecting a dead peer, is in Part II about keeping a box you cannot see from forgetting that you exist. It is the same mechanism with a second reason.

The other fix, making addresses wider, did happen. The new format has 128 bits, enough to give every device that will ever exist its own public address, with room to spare by a factor that is hard to write down. With it the symmetry returns. Mira’s phone can have a real address, and so can yours, and either can knock on the other. It was standardised in 1998. A quarter of a century later it carries about half the world’s traffic.

The reason it took so long is the shape of the incentives. Widening addresses meant changing everything, every box, every operating system, every program that stored an address, and the benefit to any one party of changing was nearly zero until most of the others had. Meanwhile NAT, which needed only the edge router to change, removed the urgency, because the addresses had not really run out; they had only been shared. So the world took the cheap fix and deferred the correct one for twenty years, and is still deferring it, and every phone and laptop now runs both formats side by side and uses whichever the far end supports.

Even where the wider address is present, the door mostly stays closed. The router can now deliver an inbound knock, but a generation of engineers grew up assuming it could not, and built firewalls that refuse by default. The clause outlived its cause.

You now know why you cannot be reached, why Courtyard has a server, and why the heartbeat has to beat faster than a box you have never seen can forget. Those three facts shape every distributed system ever built, and all three come from one table in one router, and all three are a consequence of thirty-two bits not being enough.

You also know that Courtyard’s server needs a public address. That raises the question of how anyone finds it, because 203.0.113.50 is not a thing a person can remember, and it is going to change.

Coming up · II·4 — Nobody Remembers Numbers

Mira’s server moves to a new host and its address changes. Every client that had the number baked in stops working, and nobody remembers numbers anyway.

→