# Network Programming With Go ![rw-book-cover](https://m.media-amazon.com/images/I/81fKZR728yL._SY160.jpg) ## Metadata - Author: [[Adam Woodbeck]] - Full Title: Network Programming With Go - Category: #computer-networking #golang ## Highlights - Google created the Go programming language in 2007 to increase the productivity of developers working with large code bases. ([Location 894](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=894)) - A computer network is a connection between two or more devices, or nodes, that allows each node to share data. These connections aren’t inherently reliable or secure. ([Location 965](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=965)) - The organization of nodes in a network is called its topology. A network’s topology can be as simple as a single connection between two nodes or as complex as a layout of nodes that don’t share a direct connection but are nonetheless able to exchange data. ([Location 970](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=970)) - Topology types fall into six basic categories: point-to-point, daisy chain, bus, ring, star, and mesh. ([Location 973](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=973)) - In the simplest network, point-to-point, two nodes share a single connection (Figure 1-1). This type of network connection is uncommon, though it is useful when direct communication is required between two nodes. ([Location 974](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=974)) - A series of point-to-point connections creates a daisy chain. ([Location 979](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=979)) - Bus topology nodes share a common network link. Wired bus networks aren’t common, but this type of topology drives wireless networks. ([Location 985](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=985)) - Although wireless clients can see each other’s traffic, traffic is usually encrypted. ([Location 989](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=989)) - A ring topology, which was used in some fiber-optic network deployments, is a closed loop in which data travels in a single direction. ([Location 992](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=992)) - In a star topology, a central node has individual point-to-point connections to all other nodes. You will likely encounter this network topology in wired networks. The central node, as shown in Figure 1-5, is often a network switch, which is a device that accepts data from the origin nodes and retransmits data to the destination nodes, like a postal service. ([Location 1001](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1001)) - Every node in a fully connected mesh network has a direct connection to every other node (Figure 1-6). This topology eliminates single points of failure because the failure of a single node doesn’t affect traffic between any other nodes on the network. On the other hand, costs and complexity increase as the number of nodes increases, making this topology untenable for large-scale networks. This is another topology you may encounter only in larger wireless networks. ([Location 1008](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1008)) - You can also create a hybrid network topology by combining two or more basic topologies. Real-world networks are rarely composed of just one network topology. ([Location 1014](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1014)) - Hybrid topologies are meant to improve reliability, scalability, and flexibility by taking advantage of each topology’s strengths and by limiting the disadvantages of each topology to individual network segments. ([Location 1021](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1021)) - Network bandwidth is the amount of data we can send over a network connection in an interval of time. ([Location 1028](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1028)) - Network latency is a measure of the time that passes between sending a network resource request and receiving a response. ([Location 1034](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1034)) - You can address the most common sources of latency in several ways. First, you can reduce both the distance and the number of hops between users and your service by using a content delivery network (CDN) or cloud infrastructure to locate your service near your users. Optimizing the request and response sizes will further reduce latency. Incorporating a caching strategy in your network applications can have dramatic effects on performance. Finally, taking advantage of Go’s concurrency to minimize server-side blocking of the response can help. ([Location 1047](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1047)) - Protocols are rules and procedures that determine the format and order of data sent over a network. ([Location 1054](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1054)) - Layer 7—application layer Your network applications and libraries most often interact with the application layer, which is responsible for identifying hosts and retrieving resources. Web browsers, Skype, and bit torrent clients are examples of Layer 7 applications. ([Location 1068](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1068)) - Layer 6—presentation layer The presentation layer prepares data for the network layer when that data is moving down the stack, and it presents data to the application layer when that data moves up the stack. Encryption, decryption, and data encoding are examples of Layer 6 functions. ([Location 1071](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1071)) - Layer 5—session layer The session layer manages the connection life cycle between nodes on a network. It’s responsible for establishing the connection, managing connection time-outs, coordinating the mode of operation, and terminating the connection. Some Layer 7 protocols rely on services provided by Layer 5. ([Location 1073](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1073)) - Layer 4—transport layer The transport layer controls and coordinates the transfer of data between two nodes while maintaining the reliability of the transfer. Maintaining the reliability of the transfer includes correcting errors, controlling the speed of data transfer, chunking or segmenting the data, retransmitting missing data, and acknowledging received data. Often protocols in this layer might retransmit data if the recipient doesn’t acknowledge receipt of the data. ([Location 1076](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1076)) - Layer 3—network layer The network layer is responsible for transmitting data between nodes. It allows you to send data to a network address without having a direct point-to-point connection to the remote node. OSI does not require protocols in this layer to provide reliable transport or report transmission errors to the sender. The network layer is home to network management protocols involved in routing, addressing, multicasting, and traffic control. ([Location 1079](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1079)) - Layer 2—data link layer The data link layer handles data transfers between two directly connected nodes. ([Location 1083](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1083)) - For example, Ethernet does not retransmit incorrect data, whereas wireless does. This is because bit errors on Ethernet networks are infrequent, whereas they’re common over wireless. ([Location 1086](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1086)) - Layer 1—physical layer The physical layer converts bits from the network stack to electrical, optic, or radio signals suitable for the underlying physical medium and from the physical medium back into bits. ([Location 1089](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1089)) - We count the number of zeros and ones, or bits, we can transfer per second. Therefore, network transmission rates are measured in bits per second. We use bytes per second when discussing the amount of data transferred. ([Location 1093](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1093)) - Encapsulation is a method of hiding implementation details or making only relevant details available to the recipient. ([Location 1099](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1099)) - As data travels down the stack, it’s encapsulated by the layer below. We typically call the data traveling down the stack a payload, although you might see it referred to as a message body. The literature uses the term service data unit(SDU). ([Location 1103](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1103)) - Generally, a payload travels down the client’s network stack, over physical media to the server, and up the server’s network stack to its corresponding layer. The result is that data sent from one layer at the origin node arrives at the same layer on the destination node. ([Location 1117](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1117)) - The Internet Protocol(IP) at Layer 3 receives the TCP segment and encapsulates it with a header to create Layer 3’s payload, which is known as a packet. ([Location 1128](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1128)) - Layer 2’s header translates the recipient’s IP address into a media access control(MAC) address, which is a unique identifier assigned to the node’s network interface. ([Location 1131](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1131)) - TCP/IP—named for the Transmission Control Protocol and the Internet Protocol—facilitated networks designed using the end-to-end principle, whereby each network segment includes only enough functionality to properly transmit and route bits; all other functionality belongs to the endpoints, or the sender and receiver’s network stacks. ([Location 1142](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1142)) - Like the OSI reference model, TCP/IP relies on layer encapsulation to abstract functionality. It consists of four named layers: the application, transport, internet, and link layers. ([Location 1148](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1148)) - Like OSI’s application layer, the TCP/IP model’s application layer interacts directly with software applications. ([Location 1161](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1161)) - Common TCP/IP application layer protocols include HTTP, the File Transfer Protocol(FTP) for file transfers between nodes, and the Simple Mail Transfer Protocol(SMTP) for sending email to mail servers. The Dynamic Host Configuration Protocol(DHCP) and the Domain Name System(DNS) also function in the application layer. ([Location 1167](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1167)) - DHCP and DNS provide the addressing and name resolution services, respectively, that allow other application layer protocols to operate. HTTP, FTP, and SMTP are examples of protocol implementations that provide the presentation or session functionality in TCP/IP’s application layer. ([Location 1170](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1170)) - Transport layer protocols handle the transfer of data between two nodes, like OSI’s Layer 4. These protocols can help ensure data integrity by making sure that all data sent from the origin completely and correctly makes its way to the destination. ([Location 1174](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1174)) - Most of our network applications rely on the transport layer protocols to handle the error correction, flow control, retransmission, and transport acknowledgment of each segment. ([Location 1186](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1186)) - The internet layer is responsible for routing packets of data from the upper layers between the origin node and the destination node, often over multiple networks with heterogeneous physical media. ([Location 1190](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1190)) - Internet Protocol version 4 (IPv4), Internet Protocol version 6 (IPv6), Border Gateway Protocol(BGP), Internet Control Message Protocol(ICMP), Internet Group Management Protocol (IGMP), and the Internet Protocol Security(IPsec) suite, among others, provide host identification and routing to TCP/IP’s internet layer. ([Location 1193](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1193)) - The link layer, which corresponds to Layers 1 and 2 of the OSI reference model, is the interface between the core TCP/IP protocols and the physical media. ([Location 1199](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1199)) - The link layer’s Address Resolution Protocol(ARP) translates a node’s IP address to the MAC address of its network interface. ([Location 1201](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1201)) - Then we’ll discuss routing, or sending traffic between network hosts that aren’t directly connected, and cover some common routing protocols. ([Location 1240](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1240)) - domain name resolution (the process of translating human-readable names to IP addresses), potential privacy implications of DNS, and the solutions to overcome those privacy concerns. ([Location 1242](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1242)) - The Internet Protocol (IP) is a set of rules that dictate the format of data sent over a network—specifically, the internet. IP addresses identify nodes on a network at the internet layer of the TCP/IP stack, and you use them to facilitate communication between nodes. ([Location 1250](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1250)) - The 32 bits that compose an IPv4 address represent two components: a network ID and a host ID. ([Location 1273](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1273)) - The network ID informs the network devices responsible for shuttling packets toward their destination about the next appropriate hop in the transmission. These devices are called routers. ([Location 1274](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1274)) - Once the data reaches the destination network, the router uses the host ID to deliver the data to the specific recipient. ([Location 1277](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1277)) - IPv4’s network and host IDs allow you to subdivide, or partition, the more than four billion IPv4 addresses into smaller groups to keep the network secure and easier to manage. All IP addresses in these smaller networks, called subnets, share the same network ID but have unique host IDs. ([Location 1298](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1298)) - You allocate networks using a method known as Classless Inter-Domain Routing(CIDR). In CIDR, you indicate the number of bits in the network ID by appending a network prefix to each IP address, consisting of a forward slash and an integer. ([Location 1308](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1308)) - For example, you’d write the IP address 192.168.156.97 from Figure 2-4 as 192.168.156.97/16 in CIDR notation, indicating that it belongs to a 16-bit network and that the network ID is the first 16 bits of the IP address. ([Location 1312](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1312)) - The first IP address in the network is the network address, and the last IP address is the broadcast address. ([Location 1362](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1362)) - Take 192.168.0.0/16, for example. The first IP address in the network is 192.168.0.0. This is the network address. The last IP address in the network is 192.168.255.255, which is the broadcast address. ([Location 1363](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1363)) - each host has the 127.0.0.0/8 subnet designated as its local subnet. Addresses in this subnet are local to the host and simply called localhost. Even if your computer is not on a network, it should still have an address on the 127.0.0.0/8 subnet, most likely 127.0.0.1. ([Location 1387](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1387)) - TCP and UDP allow us to multiplex data transmissions by using ports. ([Location 1392](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1392)) - The combination of an IP address and a port number is a socket address, typically written in the format address:port. ([Location 1395](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1395)) - Ports are 16-bit unsigned integers. Port numbers 0 to 1023 are well-known ports assigned to common services by the Internet Assigned Numbers Authority(IANA). ([Location 1396](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1396)) - One way to address the IPv4 shortage is by using network address translation (NAT), a process that allows numerous nodes to share the same public IPv4 address. It requires a device, such as a firewall, load balancer, or router that can keep track of incoming and outgoing traffic and properly route incoming traffic to the correct node. ([Location 1415](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1415)) - Hosts outside the NAT device’s private network cannot establish incoming connections. ([Location 1431](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1431)) - Sending packets from one IP address to another IP address is known as unicast addressing. But TCP/IP’s internet layer supports IP multicasting, or sending a single message to a group of nodes. You can think of it as an opt-in mailing list, such as a newspaper subscription. ([Location 1434](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1434)) - Broadcasting is the ability to concurrently deliver a message to all IP addresses in a network. To do this, nodes on a network send packets to the broadcast address of a subnet. A network switch or router then propagates the packets out to all IPv4 addresses in the subnet ([Location 1442](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1442)) - Unlike multicasting, the nodes in the subnet don’t first need to opt in to receiving broadcast messages. ([Location 1448](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1448)) - Like IPv4 addresses, IPv6 addresses have a network address and a host address. IPv6’s host address is commonly known as the interface ID. ([Location 1489](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1489)) - The first 48 bits of the network address are known as the global routing prefix(GRP), and the last 16 bits of the network address are called the subnet ID. ([Location 1491](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1491)) - IPv6 addresses are divided into three categories: anycast, multicast, and unicast. ([Location 1520](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1520)) - A unicast IPv6 address uniquely identifies a node. If an originating node sends a message to a unicast address, only the node with that address will receive the message, ([Location 1522](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1522)) - Multicast addresses represent a group of nodes. ([Location 1528](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1528)) - An anycast address represents a group of nodes listening to the same address. ([Location 1536](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1536)) - The IPv6 header is an improvement over the IPv4 header. The IPv4 header contains mandatory yet rarely used fields. IPv6 makes these fields optional. ([Location 1552](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1552)) - IPv6 also lessens the loads on routers and other hops by ensuring that headers require minimal processing, eliminating the need for checksum calculation at every hop. ([Location 1555](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1555)) - Nodes using IPv6 can automatically configure or derive their IPv6 addresses through stateless address autoconfiguration(SLAAC) to reduce administrative overhead. ([Location 1558](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1558)) - Router advertisement packets contain information clients need to automatically configure their IPv6 address, including the 64-bit network address. ([Location 1567](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1567)) - If you value your privacy, the method SLAAC uses to derive a unique interface ID should concern you. No matter which network your device is on, SLAAC will make sure the host portion of your IPv6 address contains your NIC’s MAC address. The MAC address is a unique fingerprint that betrays the hardware you use and allows anyone to track your online activity. ([Location 1571](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1571)) - IPv6 has native support for IPsec, a technology that allows multiple nodes to dynamically create secure connections between each other, ensuring that traffic is encrypted. ([Location 1578](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1578)) - The Internet Protocol relies on the Internet Control Message Protocol(ICMP) to give it feedback about the local network. ICMP can inform you of network problems, unreachable nodes or networks, local network configuration, proper traffic routes, and network time-outs. ([Location 1583](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1583)) - You can determine whether a node is online and reachable by using an ICMP echo request (also called a ping). ([Location 1594](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1594)) - nodes won’t have a direct connection, so they’ll have to make use of intermediate nodes to transfer data. ([Location 1605](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1605)) - The intermediate nodes (Nodes 1 and 2 in Figure 2-15) are typically routers or firewalls that control the path data takes from one node to the other. ([Location 1607](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1607)) - Firewalls control the flow of traffic in and out of a network, primarily to secure networks behind the firewall. ([Location 1609](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1609)) - Routing protocols have their own criteria for determining the best path between nodes. Some protocols determine a route’s efficiency based on hop count. Some may use bandwidth. Others may use more complicated means to determine which route is the most efficient. ([Location 1628](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1628)) - An autonomous system is an organization that manages one or more networks. An ISP is an example of an autonomous system. ([Location 1631](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1631)) - An external routing protocol routes data between autonomous systems. ([Location 1634](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1634)) - The Border Gateway Protocol (BGP) allows ASN-assigned ISPs to exchange routing information. BGP relies on trust between ISPs. That is, if an ISP says it manages a specific network and all traffic destined for that network should be sent to it, the other ISPs trust this claim and send traffic accordingly. ([Location 1638](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1638)) - The Domain Name System(DNS) is a way of matching IP addresses to domain names, which are the names we enter in an address bar when we want to visit websites. ([Location 1655](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1655)) - domain name resolver, a server that knows how to retrieve the answer to your query. ([Location 1669](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1669)) - Domain name servers maintain resource records for the domains they serve. Resource records contain domain-specific information, used to satisfy domain name queries, like IP addresses, mail server hostnames, mail-handling rules, and authentication tokens. ([Location 1678](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1678)) - The root zone is the top DNS namespace. ([Location 1691](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1691)) - The Address (A) record is the most common record you’ll query. An A record will resolve to one or more IPv4 addresses. ([Location 1695](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1695)) - The Start of Authority (SOA) record contains authoritative and administrative details about the domain, ([Location 1717](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1717)) - The Name Server (NS) record returns the authoritative name servers for the domain name. Authoritative name servers are the name servers able to provide answers for the domain name. ([Location 1730](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1730)) - Canonical Name (CNAME) record points one domain at another. ([Location 1741](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1741)) - The Mail Exchange (MX) record specifies the mail server hostnames that should be contacted when sending email to recipients at the domain. ([Location 1757](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1757)) - The Pointer (PTR) record allows you to perform a reverse lookup by accepting an IP address and returning its corresponding domain name. ([Location 1770](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1770)) - The Text (TXT) record allows the domain owner to return arbitrary text. ([Location 1787](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1787)) - Multicast DNS(mDNS) is a protocol that facilitates name resolution over a local area network (LAN) in the absence of a DNS server. ([Location 1806](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1806)) - DNS traffic is typically unencrypted when it traverses the internet. A potential exception occurs if you’re connected to a virtual private network (VPN) and are careful to make sure all DNS traffic passes through its encrypted tunnel. Because of DNS’s unencrypted transport, unscrupulous ISPs or intermediate providers may glean sensitive information in your DNS queries and share those details with third parties. You can make a point of visiting HTTPS-only websites, but your DNS queries may betray your otherwise secure browsing habits and allow the DNS server’s administrators to glean the sites you visit. ([Location 1811](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1811)) - Domain Name System Security Extensions(DNSSEC) is a method to prevent the covert modification of DNS responses in transit by using digital signatures to authenticate the response. DNSSEC ensures the authenticity of data by authenticating the content. ([Location 1822](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1822)) - DNS over TLS (DoT), detailed in RFC 7858 (https://tools.ietf.org/html/rfc7858/), addresses both security and privacy concerns by using Transport Layer Security(TLS) to establish an encrypted connection between the client and its DNS server. ([Location 1828](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1828)) - DNS over HTTPS (DoH), detailed in RFC 8484 (https://tools.ietf.org/html/rfc8484/) aims to address DNS security and privacy concerns while using a heavily used TCP port. ([Location 1836](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1836)) - TCP allows you to reliably stream data between nodes on a network. ([Location 1851](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1851)) - TCP is reliable because it overcomes the effects of packet loss or receiving packets out of order. ([Location 1860](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1860)) - Packet loss occurs when data fails to reach its destination—typically because of data transmission errors (such as wireless network interference) or network congestion. ([Location 1861](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1861)) - Network congestion happens when nodes attempt to send more data over a network connection than the connection can handle, causing the nodes to discard the excess packets. ([Location 1862](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1862)) - A TCP session allows you to deliver a stream of data of any size to a recipient and receive confirmation that the recipient received the data. ([Location 1876](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1876)) - A TCP connection uses a three-way handshake to introduce the client to the server and the server to the client. ([Location 1886](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1886)) - As the first step of the handshake, the client sends a packet with the synchronize (SYN) flag to the server. ([Location 1894](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1894)) - the server responds with its own packet, with both the acknowledgment (ACK) and SYN flags set. ([Location 1896](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1896)) - Unmanaged and lengthy idle TCP sessions may result in wasteful consumption of memory. ([Location 1901](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1901)) - Each TCP packet contains a sequence number, which the receiver uses to acknowledge receipt of each packet and properly order the packets for presentation to your Go application ([Location 1905](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1905)) - While writing and debugging network programs, it’s often necessary to view the traffic your code sends and receives. To capture and inspect TCP packets, I strongly recommend you familiarize yourself with Wireshark (https://www.wireshark.org/). ([Location 1919](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1919)) - If you view your application’s network traffic in Wireshark, you may notice selective acknowledgments (SACKs). These are ACK packets used to acknowledge the receipt of a subset of sent packets. ([Location 1923](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1923)) - A receive buffer is a block of memory reserved for incoming data on a network connection. ([Location 1930](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1930)) - ACK packets include a particularly important piece of information: the window size, which is the number of bytes the sender can transmit to the receiver without requiring an acknowledgment. ([Location 1934](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1934)) - This method—of receiving the window size in an ACK packet, sending data, receiving an updated window size in the next ACK, and then sending more data—is known as a sliding window, ([Location 1939](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1939)) - The maximum segment lifetime is the duration a TCP segment can remain in transit before the sender considers it abandoned. Upon receiving the client’s last ACK packet, the server immediately changes its connection state to CLOSED, fully terminating the TCP session. ([Location 1964](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1964)) - Binding means that the operating system has exclusively assigned the port on the given IP address to the listener. ([Location 1993](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=1993)) - Unless you want to accept only a single incoming connection, you need to use a for loop 1 so your server will accept each incoming connection, handle it in a goroutine, and loop back around, ready to accept the next connection. Serially accepting connections is perfectly acceptable and efficient, but beyond that point, you should use a goroutine to handle each connection. ([Location 2015](https://readwise.io/to_kindle?action=open&asin=B085BVTB5M&location=2015))