3 ms·
Why TCP needs 3 handshakes
- deathanatos 2y agoI've always considered it one handshake, with 3 packets, which are for some reason then called "3 way". But it's one 3-way-handshake.
- sedatk 2y ago"3 shake handshake"? :)
- butterfly42069 2y agoYou, the server and the NSA Collection.
- nasretdinov 2y ago3 hands handshake, nothing unusual here
- beng-nl 2y agoNext TCP: Zaphod
- AStonesThrow 2y agoIt all started when Jon Postel obtained the Holy Hand Grenade of Antioch and reverse-engineered it...
- qwertox 2y agoIt is only one handshake, with 3 packets. The author made a mistake in the title, but the content is mostly correct (fails at "First Handshake", "Second Handshake" and "Third Handshake"). He should call them stages, phases or something like that.
- AStonesThrow 2y agoTo be really specific, they are not "packets" but at the TCP protocol level, they are "segments" TFA appears to use both terms sort of interchangeably, which is uncool when describing a formalized protocol standard! Segments are encapsulated in IP datagrams, or packets, which are, in turn, encapsulated in other PDU types, such as Ethernet frames.
- Ekaros 2y agoAnd one could ask are segments without well data segment a segments? As mostly 2 first PDUs in exchange do not contain data...
- AStonesThrow 2y agoYes they are. I don't know what "well data segment" is, but perhaps you mean a payload. TCP streams consist of segments, and the fragmentation or collection of those logical segments into packets is a function of the lower-layer protocols which are not TCP. https://www.rfc-editor.org/rfc/rfc9293.html https://www.rfc-editor.org/rfc/rfc9293.html
- tsimionescu 2y agoI think one important mention here is that fragmentation happens at two levels: most commonly, an upper layer protocol message (such as an HTTP request) is fragmented into several TCP segments, each with one TCP header. Those TCP segments themselves can sometimes be fragmented into multiple IP packets if the TCP MSS (maximum segment size) is larger than the Ethernet MTU (maximum transmission unit). IP fragmentation is typically avoided, and in IPv6 it is only allowed at the originator of a packet - if a router is trying to route an IPv6 packet larger than the MTU of the outgoing link's MTU, it must drop the packet and send a signal about the MTU back. An IPv4 router may fragment the packet, but this rarely works well in practice.
- AStonesThrow 2y ago
- ddfs123 2y agoI've consider it to be 4 handshakes but the middle 2 are merged.
- ay 2y agoThere is a scenario called “simultaneous open”, which has 4 packets handshake and is a wonderful source of corner cases and debugging. Mostly doesn’t happen these days, but is possible by standard and is explicitly described.
- winternewt 2y agoIt has been used for NAT traversal when both parties are behind NAT, but sadly it doesn't work with all routers.
- Uptrenda 2y agoIts just 1 packet: an RST with a data field containing a swear word.
- evilc00kie 2y agoJokes like that make me realize I understand the matter more than I want to :'D
- odo1242 2y agoI did not know RST packets had a data field lol
- odo1242 2y agoThe reason it’s considered a “3-way” handshake is mostly latency related. If the delay sending a packet between the client and server is k, there are 3 hops involved in establishing a connection so the time is 3k. Confusingly, this has nothing to do with how many devices are involved.
- jabiko 2y ago> The reason it’s considered a “3-way” handshake is mostly latency relate Its not latency related. Its because there 3 packets involved in completing the handshake. > If the delay sending a packet between the client and server is k, there are 3 hops involved in establishing a connection so the time is 3k. Also I think calling it "hops" is not correct. A hop occurs when a packet passes through a router. > Confusingly, this has nothing to do with how many devices are involved. In a TCP handshake there are only two devices involved (disregarding any middleboxes that meddle with the connection).
- deleted 2y ago[deleted]
- foobiekr 2y agoit's called 3-way because from the point of view of a network message diagram, there are three arrows which change direction at each step. what it really amounts to is a three phase transaction.
- krackers 2y agoThere's this interesting comment by "John Day" on that page, does anyone have more context/detail?
- Joel_Mckay 2y agoThere were several competing standards on the early networks, and almost every ambitious commercial entity wanted to embed their licensed IP into the webs core transport layer or lower on the OSI stack. We take for granted the inter-connectivity of most modern equipment, but to this day companies still try to create synthetic technology monopolies to cash-in. i.e. to sustain a tenuous service commodity out of something that has essentially been free since the mid 1990s. https://xkcd.com/927/ https://xkcd.com/927/ Philosophically it doesn't matter TCP is imperfect, but rather that the inter-connectivity is compatible with the inertia of the installed infrastructure. One can indeed optimistically ignore the TCP connection drop and syn part of standards to tunnel/reverse-proxy though certain censorship firewalls... but it still does not make it safe for the people that live under such regimes. Does this make it more or less clear? =3
- Bluecobra 2y ago> We take for granted the inter-connectivity of most modern equipment, but to this day companies still try to create synthetic technology monopolies to cash-in. i.e. to sustain a tenuous service commodity out of something that has essentially been free since the mid 1990s. This is why as a network engineer I always advocate for open standards everywhere I can to avoid vendor lock-in. The classic one is using OSPF instead of EIGRP on Cisco routers (or their other proprietary protocols). Nowadays this is much tricker with cloud computing and black box stuff like SDN/SDWAN.
- Joel_Mckay 2y agoMost good engineers I've met follow the same open standards prioritization recommendation. The drama that goes on inside Cisco could fill a soap opera season. =3
- 2y ago
- sedatk 2y agoTL;DR: "Because if TCP handshake were 2-way only, the receiver couldn't confirm if it could send packets successfully or sender could receive them". And that sounds bogus to me. Connection initiation isn't about testing if packets can reach or not. It's about acknowledgement, building a two peer consensus about how to handle upcoming packets from a peer, not reliability checks. In that sense, I don't even think the third step is necessary, but apparently, it's needed to handle the case of both endpoints going into a timeout loop, this article explains it perfectly: https://www.baeldung.com/cs/handshakes https://www.baeldung.com/cs/handshakes
- toast0 2y agoYou can only reach consensus if the peers can each receive packets that the other sent. So reaching consensus and testing for reachability in both directions are the same. In a client/server scenario, the client knows the connection is good when it receives the SYN+ACK, but the server doesn't know until it receives the resulting ACK. So the third packet is necessary to communicate consensus to the server; it doesn't need to be a pure ACK though, it can have data, if the client's stack makes it possible to queue outgoing data before the SYN+ACK is received.
- sedatk 2y ago> You can only reach consensus if the peers can each receive packets that the other sent. So reaching consensus and testing for reachability in both directions are the same. No, that's not the intent of a handshake. Assume a hypothetical Internet where every node has guaranteed connectivity to every other node that never fails. Do we suddenly lose the need to do a 3-way handshake? No. It's not about testing connectivity, that's semantically wrong. And what's the meaning of testing connectivity for a connection of an arbitrary length and with a quality of unknown degree throughout? It doesn't make any sense. There is no "knowing the connection is good", there is a process of building up consensus. The peers are only interested in an answer to this question: "Does the other party assume a connection?". If we knew the answer to that question beforehand, we wouldn't need a handshake at all. Reachability, transmissibility are all irrelevant. And, UDP actually works like that. Both endpoints assume willingness to connect. That's why you don't need a handshake with UDP. TCP-FO worked liked that too, removing the need for a TCP handshake completely, because it could persist the consensus information.
- teleforce 2y agoI think the more important question is why TCP only using positive acknowledgement (ACK) but not negative acknowledgement (NACK)?
- toast0 2y agoSelective acknowledgement (SACK) effectively indicates which sequence numbers are missing when there's packet loss. It's optional, but afaik, used by nearly everything on today's internet.
- keeperofdakeys 2y agoWhat would a NACK add? TCP can already send an ACK for the last successful sequence number, telling the sender to retransmit packets after that sequence number. Due to latency and large window sizes, it's far more efficient to just resend all the data than NACK individual packets.
- retSava 2y agoPerhaps GP considers a NACK more semantically easier to understand on an intuitive level, instead of the implicit NACK with "I know you sent 8, but we're really at 4 so resume from that". But I do agree that it's more efficient for the remote host to just immediately establish "4 was the last point we are ok at".
- ay 2y agoIt is not possible to distinguish between the absence of negative ACK and the loss of it.
- ggm 2y ago1RTT FTW!
- Avamander 2y agoTFO has unfortunately been ruined by middleboxes meddling. Maybe once IPv6 becomes more popular and NATs (that also mangle) fall out of favor we'll have more luck enabling it.
- geon 2y agoGreat conclusion: > Theoretically, even more than three handshakes would not guarantee a "completely reliable" TCP connection. However, through three handshakes, it can at least be confirmed that the connection is "basically usable." Increasing the number of handshakes would merely increase the confidence level in the "connection availability." 3 is an arbitrary number, but one that works well in practice.
- Pikamander2 2y ago> Theoretically, even more than three handshakes would not guarantee a "completely reliable" TCP connection. However, through three handshakes, it can at least be confirmed that the connection is "basically usable." Increasing the number of handshakes would merely increase the confidence level in the "connection availability." This sounds like a variation of the Two Generals' Problem: https://en.wikipedia.org/wiki/Two_Generals%27_Problem https://en.wikipedia.org/wiki/Two_Generals%27_Problem
- stavros 2y agoKind of, but not exactly. The article treats the channels as immutable, ie you can tell whether a channel is working or not by sending one packet. In this assumption, you'd have to send three packets for both sides to discover if all four ways work (server send, server receive, client send, client receive), but after that you'd need no more assurance. In the two generals problem, the channel can fail at any time (which is what happens in real life), so no amount of handshakes can assure you. Because of the above, I don't agree with their conclusion that more handshakes is better. Either you assume immutable channels, so you only need three, or mutable channels that can fail any time, so you need infinite.
- im3w1l 2y agoWell it's quite common to assume a channel has failed if its inactive too long, with periodic keep-alive messages to ensure it doesn't go inactive in the case where there is nothing to say.
- cortesoft 2y ago> Either you assume immutable channels, so you only need three, or mutable channels that can fail any time, so you need infinite. This is true if you only care about having 100% confidence. Sending more handshakes allows you to do statistical analysis to give you more confidence that the connection is reliable.
- ali_piccioni 2y agoThe information can be compressed into a table that shows what knowledge (columns) each party gain (rows) at each stage (cells) of the connection. Can Can Transmit | Receive Client SYN-ACK SYN—ACK Server ACK SYN
- ninkendo 2y agoIs your bottom row backwards? Surely the server learns that the client can transmit when it receives a SYN and that it must have received the SYN-ACK when the ACK comes back.
- deleted 2y ago[deleted]
- ingen0s 2y agoThat’s commitment
- aiava 2y ago[flagged]
- deleted 2y ago[deleted]
- gorfian_robot 2y agoback in the day we had some chats with Vint Cerf during the development of Delay-tolerant networking (DTN) for primarily for use in space scenarios (though there are other scenarios). no way SYN, SYN-ACK, ACK type was gonna cut it. I found a light overview here: https://www.quantamagazine.org/vint-cerfs-plan-for-building-an-internet-in-space-20201021/ https://www.quantamagazine.org/vint-cerfs-plan-for-building-...
- veblen 2y agoImagine two blind people who want to have a conversation. Before they start, each person needs to ensure that the other can both speak and hear. Typically, one person begins by asking, 'Can you hear me?' to check if the other can hear them. The second person responds with 'Yes,' confirming that they can hear. Then, the second person asks, 'Can you hear me?' and the first person replies, 'Yes,' completing the process. In total, there are four exchanges (two questions and two answers). However, if you look closely, the second person's reply of 'Yes' already confirms that they can both hear and speak. Therefore, the second 'Can you hear me?' is unnecessary. With just three exchanges (one question and two answers), both people know that they can send and receive messages.
- blamarvt 2y agoWhat if the first blind person was also deaf and just trolling the other blind person so wouldn't the second "Can you hear me?" be needed?
- deleted 2y ago[deleted]
- kbmr 2y agoTroll Control Protocol
- colejohnson66 2y agoThen you set the “evil” bit
- tsimionescu 2y agoActually, the second answer is also unnecessary. The conversation can go like this: A: Can you hear me? B: Yes A: What time is it? B: 5 o'clock A: Thank you, goodbye! B: Goobye! Nothing is lost compared to: A: Can you hear me? B: Yes A: Yes A: What time is it? [...]
- stiglitz 2y agoTCP Fast Open does you one better: A: If you can hear me, what time is it? B: Yeah I can hear you; it’s 5.
- userbinator 2y agoI've always found the bitfields in the TCP header to be either too loosely defined or the standard insufficiently lax, since there are many combinations that make theoretical sense but don't work well or at all in practice. E.g. SYN+ACK+FIN+DATA would be perfect for a very short-lived connection that transfers a single segment. IMHO they should've either just used a "state" field that enumerates all possible states a packet is intended to have, or usefully defined all the possible combinations of the flags.
- stevecalifornia 2y agoPilots also do a 3 handshake exchange when handing over control to the other pilot. Pilot: "You have the plane." Co-Pilot: "I have the plane." Pilot: "You have the plane." The third statement is the pilot acknowledging that the transfer of control has completed. Without it, the co-pilot doesn't positively know that the pilot knows that control has been handed over. As an aside, Air France 447 was a crash where the co-pilot was pulling back on the stick without the captain knowing. The captain couldn't understand why his controls weren't having the intended effect. Both pilots were making inputs, unaware of each other.
- deleted 2y ago[deleted]