Author: hackett
Wechat official account: Overtime Ape

Computer network

1 How does TCP ensure reliability and briefly describe the process of establishing and disconnecting TCP connections

TCP ensures reliability:

(1) Serial number, confirmation reply, timeout retransmission

When the data arrives at the receiver, the receiver needs to send an acknowledgement that it has received the data segment, and the acknowledgement sequence number specifies the serial number of the data it needs to receive next. If the sender does not receive the confirmation reply after a while, the sent data may be lost or the confirmation reply may be lost. In this case, the sender retransmits data after waiting for a certain period of time. The time is usually 2 x RTT(round-trip time of a packet segment) plus one offset.

(2) Window control and high-speed retransmission control/fast retransmission (repeated confirmation response)

TCP uses window control to speed up transmission, meaning that you don’t have to wait for a reply to send the next piece of data within a window size, which is the maximum that can continue to send data without waiting for confirmation. If you do not use window control, every data that does not receive an acknowledgement is retransmitted.

Use window control, if the data segment 1001-2000 lost, behind each data transmission, confirm the answer will keep sending serial number 1001 response, said I want to receive 1001 data, sending end if received 3 times the same response, will immediately resend; But there are cases where the data may have been received, but some of the response is lost, this situation will not be resend, because the sender knows that if the data segment is lost, the receiver will not let it go, will be crazy to remind it……

(3) Congestion control

If the window is set too large, the sender will send a large amount of data continuously, which may cause network congestion (everyone is using the network, you are here, the throughput is so large, of course, will cause congestion), or even cause network breakdown. So TCP implements congestion control to prevent this.

Slow start: Define congestion window, set the size of the window to 1 at the beginning, and then increase the size of the congestion window to 2 each time you receive an acknowledgement (after one RTT).

Congestion avoidance: Set the slow start threshold to 65536. Congestion avoidance means that when the size of the congestion window reaches this threshold, the value of the congestion window does not increase exponentially, but increases by addition (+1 for each acknowledgement/RTT) to avoid congestion.

The timeout retransmission of the packet segment is regarded as congestion. Once the timeout retransmission occurs, we need to set the threshold value to half of the current window size and the initial window size to 1, and then restart the slow start process.

Fast retransmission: In the case of three repeated acknowledgments (high-speed retransmission control), three message segments are received, but the previous one is lost, and it is immediately retransmitted.

Then, first set the threshold to half the current window size, and then set the congested window size to the size of the slow start threshold +3.

This can be achieved: during TCP communication, the network throughput shows a gradual increase, and with congestion to reduce the throughput, and then enter a slow increase process, the network will not easily break down.

TCP establishes and disconnects a connection:

img

Three handshakes:

\1. The Client sets the SYN flag bit to 1, randomly generates a value seq=J, and sends the packet to the Server. The Client enters the SYN_SENT state and waits for the Server to confirm the packet.

\2. After receiving the packet, the Server uses flag bit SYN=1 to know that the Client requests to establish a connection. The Server sets flag bit SYN and ACK to 1, ACK =J+1, randomly generates a value seq=K, and sends the packet to the Client to confirm the connection request. The Server enters the SYN_RCVD state.

\3. After receiving the acknowledgement, the Client checks whether the ACK is J+1 and ack is 1. If the ack is correct, the Client sets the flag ACK bit to 1 and ack=K+1 and sends the packet to the Server. The Client and Server enter the ESTABLISHED state and complete the three-way handshake. Data can be transmitted between the Client and Server.

Four waves:

The TCP connection is in full duplex, so each direction must be closed separately. This principle is that when a party finishes sending data, it sends a FIN to terminate the connection in this direction. Receiving a FIN only means that no data flows in this direction, that is, no more data is received. However, data can still be sent on this TCP connection until a FIN is also sent in that direction. The party that closes first performs an active shutdown, while the other party performs a passive shutdown.

1. After the data transfer is complete, the application process of the client sends a connection release packet and stops sending data. The client enters the FIN_WAIT_1 state.

2. After receiving the FIN, the server sends an ACK to the client and confirms that the sequence number is +1. The server enters CLOSE_WAIT state. The client enters the FIN_WAIT_2 state.

3. When no data is to be sent, the server sends a FIN packet to the LAST_ACK state and waits for confirmation from the client

4. After receiving the FIN packet from the server, the client sends an ACK packet to the server to confirm that the sequence number is +1. At this point, the client enters the TIME_WAIT state, waits for 2MSL (MSL: maximum lifetime of packet segments), and then closes the connection.

2 Please describe the TCP model

The four-layer TCP/IP model is as follows:

img

3 please answer the difference between HTTP and HTTPS, and what are the disadvantages of HTTPS?

The differences between HTTP and HTTPS are as follows:

1) HTTP transmits data in plaintext over the network, while HTTPS transmits data encrypted by TLS. Therefore, HTTPS has higher security

2) HTTPS In the TCP three-way handshake phase, SSL handshake is required to negotiate the symmetric encryption key for encryption

3) The HTTPS protocol requires the server to apply for a certificate and the browser to install the corresponding root certificate

4) HTTP port 80, HTTPS port 443

HTTPS advantages:

HTTPS uses keys to encrypt data during data transmission, ensuring higher security

The HTTPS protocol authenticates users and servers to ensure that data is sent to the correct users and servers

HTTPS faults:

High DELAY in HTTPS handshake: The SSL handshake is required before the HTTP session. Therefore, the DELAY in HTTPS handshake is increased

HTTPS deployment costs are high. On the one hand, HTTPS requires a certificate to verify its security, so you need to purchase a CA certificate. On the other hand, HTTPS requires computing for encryption and decryption, which consumes a lot of CPU resources and requires a large number of servers

4 Please say HTTP return code

The HTTP response packet consists of a status line, a response header, and a response packet. The general description of the response status code is as follows:

1XX: Indicating message – indicating that the request has been received and processing continues.

2xx: Success: The request is successfully received, understood, or accepted.

3xx: Redirect – Further action must be taken to complete the request.

4XX: Client error – The request has a syntax error or the request cannot be implemented.

5xx: Server side error — the server failed to fulfill a valid request.

The following describes common status codes and status descriptions.

200 OK: The client request is successful.

206 Partial Content The partial Content server has correctly handled some OF the GET requests for breakpoint continuation or simultaneous shard download. The request must contain the Range request header to indicate the Range the client expects

300 Multiple Choices: The requested resource has a list of feedback options, one of which is selected by the browser/user.

301 Moved PERMANENTLY permanently: The resource has been permanently moved to a new location, and any future access to that resource will use one of the urIs returned by this response.

Temporarily: The requested resource is now temporarily available from a different URI.

304: Not Modified: If the client sends a conditional GET request and the request is allowed, but the document content is not changed, 304 is returned. The response does not contain the package body (the cache can be used directly).

403 Forbidden: The server receives requests but refuses to provide services.

404 not Found: The requested resource does not exist, for example: an incorrect URL was entered.

5 What are the functions of IP addresses and MAC addresses

A MAC address is a hardware address used to define the location of network devices. The MAC address is mainly responsible for the data link layer. The IP address is a unified address format provided by the IP protocol. It allocates a logical address to each network and each host on the Internet to shield physical address differences.

6 Please answer the OSI seven-layer model and TCP/IP four-layer model. List two protocols for each layer

The OSI seven-layer model and its protocols are as follows:

Application layer: a method that allows access to the OSI environment. The transfer unit is APDU and the protocol is FTP, HTTP and DNS

Presentation layer: data translation, encryption and compression, transmission unit is PPDU, mainly including the protocol JPEG ASII

Session layer: establishes, manages, and terminates sessions. The transfer unit is SPDU and the protocol is RPC NFS

Transport layer: provides end-to-end reliable packet transmission and error recovery. The transmission unit is packet and the protocol is TCP UDP

Network layer: the network layer is responsible for the transmission of data packets from source to destination and the Internet interconnection. The transmission unit is packet. The protocol mainly includes IP ARP and ICMP

Data link layer: Assembs bits into frames and point-to-point transmission. The transmission unit is frame. The protocol mainly includes MAC VLAN PPP

Physical layer: transmits bits through media to determine mechanical and electrical specifications. The transmission unit is bit. The protocol mainly includes: IEE802.3 CLOCK RJ45

The TCP/IP layer 4 model includes:

Application layer :HTTP DNS SMTP

Network interface layer: MAC VLAN

Network layer :IP ARP ICMP

Transport layer :TCP UDP

7 Why three handshakes? Not twice, not four times?

The reasons for the three-way handshake will be analyzed in three aspects:

1) Three-way handshake can prevent network congestion of initialization (main cause) packets with repeated historical connections

2) Only three handshakes can synchronize the initial serial number of both parties

3) Three handshakes to avoid resource waste

8 What if the client suddenly fails after a connection has been established?

First, the peer program is working. When a TCP keepalive probe packet is sent to the peer end, the peer end responds normally. In this case, the TCP keepalive time is reset and the TCP keepalive time is waiting for the next TCP keepalive time. In the second case, the peer program crashes and restarts. After a TCP probe packet is sent to the peer end, the peer end can respond. However, the peer end generates an RST packet because there is no valid information about the connection. In this case, the peer end quickly discovers that the TCP connection has been reset. Third, the peer program crashes or the packet is unreachable due to other reasons. After the TCP keepalive probe packet is sent to the peer end, no response is received. When the keepalive probe number reaches several times, TCP reports that the TCP connection is dead.

If you think it’s good, “Like” it.

Follow my wechat official account [Overtime Ape] to get more content