UDP is unreliable, why does I2P (garlic routing, an alternative to Tor) use UDP instead of reliable alternative: TCP? Won't I2P become unreliable due to UDP?
-
3Likely off-topic here, since you are asking about an application layer protocol. But in short: technologies which provide virtual networks (as I2P does) are commonly build on unreliable transport to provide a similar experience to IP. Applications build the reliability requirements (which not all have) on top of this. Have a look at Wireguard, OpenVPN, ... - all use UDP as underlying layer.– Steffen UllrichApr 21 at 9:15
2 Answers
As well as Zac I can't speak for the developers of I2C, but here are some general thoughts.
(1) UDP adds a header that contains port numbers and checksum. You will need a port number to identify the socket. Otherwise it offers the same type of service as sending raw IP packets. Yes, it is best effort/unreliable.
(2) One can build a reliable service on top of unreliable service. This is basically what TCP does. TCP however has a very specific way of achieving this reliability, that may be unnecessary and/or unsuitable for some application. Besides reliability TCP has a number of other mechanisms that may or may not be suited for application in question, most notably congestion control.
(3) Most usages of UDP actually involve implementing another protocol on top of UDP, that is better suited to the task in question. As Zac67 said, having another protocol on top of UDP is easier due to Firewalls and NAT boxes and also due to the fact that transport protocols are usually part of OS kernel. A very famous example of such a scenario is QUIC. Another example would be RTP (for VoIP traffic).
(4) Finally, if you consider the task of building tunnels to tunnel web traffic. Web traffic is TCP which is designed to run on top of an unreliable IP service. Having reliable tunnel is not necessary (since TCP will handle it anyways), and under some circumstances, may create more problems then it solves (two instances of TCP in the stack can adversely interact with each other).
General answer: If you need/want more control over the transmission and are willing to put up with delivery tracking and out-of-order resorting, then you use UDP.
TCP ensures reliable delivery but introduces additional overhead and latencies that you might want to avoid.
Reliable UDP is a thing, but due to the ubiquity of IPv4 NAT and the near impossibility to use other protocols than TCP and UDP on the open Internet, you're mostly left with the choice between those two.
As to exactly why xyz uses UDP instead of TCP you'd need to use the developers. Also note that protocols above the transport layer are explicitly off topic here.