Basic computer problems

Recently read some articles micro letter, the contents of the article generally summarized below, continuously updated.

1. Computer Network

1. How a computer to send data to another computer?

Reference Source

Five model based on network communication to answer:

  1. Physical Layer: The physical layer is responsible for up to two computers connected between the computer frequency electrical signal transmitted through the high and low 0,1

  2. : Data link layer of the actual meaning of the rules to transfer 0,1, 0,1 recognized by the computer so that electrical signals representative of the

    • Ethernet protocol: data packets a set of electrical signals is referred to as a frame, composed of the header and data. Header length is fixed to 18 bytes, a data portion length is not necessarily, the size of a frame is typically 64-1518 bytes, too large to be divided into a plurality of transmission frames. How to distinguish between the computer and the computer before it? Next introducing a concept unique MAC identifier

    • MAC Address: Each card has a unique address, called a MAC address. It consists of 48 bytes, unique identification

    • Broadcast and ARP protocol:

      • ARP: Address Revolution Protocol, ARP
      • Only broadcast in the same subnet, a data packet which contains the MAC address of the recipient host in the subnet received broadcast message, the MAC address of the packet and the MAC out their contrast, if, as described sender I was looking for, then receives the packet, otherwise discarded.
  3. Network layer: If within a subnet, broadcast transmission of data in the form of, if not a subnet, then the data will be sent to the gateway, so that the gateway forwards

    1. IP protocol:
    2. ~ 255.255.255.255 0.0.0.0
      2. network and host portions
      3. two judges whether the IP address is a subnet, but also need to know the subnet mask, the host bits are all 1
    3. ARP protocol:
      1. MAC address can be obtained by other hosts ARP protocol
      2. ARP protocol to send a packet to all other hosts in the form of a subnet broadcasts, including the IP address obtained in the MAC address corresponding to want to. After the other party received the packet, and the IP address out its own IP address, and if the same, put his IP address to reply to that party wants to obtain otherwise discarded.
    4. DNS server:
      1. Usually we want to visit a Web site, enter the site's domain name, rather than directly enter the IP address of the site.
      2. DNS server is able to access our Web site domain name resolution for the corresponding IP address
    5. Network layer: Let us be able to find a computer in the network where, to determine whether we belong to the same subnet.
  4. Transport Layer: establishing a port to port connection. For a specific program for receiving process.

    1. Common TCP and UDP protocols
  5. Application layer:

    1. Specified data format, rules, receive good go Interpretation rendering.

2. Computer ip is how come?

Reference Source

  1. DHCP (Dynamic Host Configuration Protocol) Dynamic Host Configuration Protocol
  2. IP client requests
    1. The client sends a broadcast, the destination IP broadcast is 255.255.255.255, the destination port is 67, in order to let others know that he is to request an IP address, the client's source IP is set to 0.0.0.0, the source port is 68. The request for the IP packet called discover packet (UDP)
  3. DHCP response
    1. DHCP packets with a source IP 0.0.0.0, it will provide him an IP, including IP address, subnet mask, gateway, IP is valid , the client initiated the request by the end of the MAC address, DHCP server will send this information past. Also in the form of broadcast, in which case the source IP broadcast packets to the DHCP server IP, destination IP address is 255.255.255.255
    2. DHCP provides IP packet called the offer message .
  4. Client IP address selection
    1. May be more than one DHCP server received IP requests for clients, generally choose offer packet first received, and then to the corresponding DHCP server sends a request message indicating that the IP has received his offer.
  5. If a DHCP server is not located in the local area network, you need a gateway for delivery, middle involve NAT address translation protocol

3. talk about NAT

Reference Source

  1. NAT(Network Address Translation)
  2. To reduce the consumption of IP addresses, a company can have one of their own network (LAN), the LAN is assigned an IP address can be used as the entire local area network gateway, network communications with the outside world;
  3. Hosts in the LAN and external networks want to communicate, you need to go through the gateway, in order to identify the local area outside the internal Which is the host wants to communicate with the outside world, the gateway maintains an address conversion table is stored in an internal IP host: after mapping the port number and IP: port number table;
  4. Through this address conversion table, that is, the host NAT protocol, internal LAN and the outside world will be able to communicate the
  5. IP LAN network called IP
  6. Gateway IP, Baidu and other so called global IP IP

4. The three-way handshake

Reference Source

  1. effect:

    1. Confirmation of both receiving and sending capability is normal
    2. To prevent erroneous connection to the server will allow Open Server connection error
    3. Specify your own initialization sequence number, to prepare for the reliable delivery back
    4. If the HTTPS protocol, then the three-way handshake process, will conduct verification of digital certificates and encryption keys are generated
  2. Three-way handshake process

    At first, the client is in the closed state, the server in listen state

    1. The first handshake: a client to the server sends a SYN packet, the client and specify initialization sequence number ISN (c). At this stage the client is SYN_SENT
    2. The second handshake: server received SYN packet from the client later, will own SYN packet in reply, and also specify your own initialization sequence number ISN (s). ISN while the client (c) + 1 as the value of the ACK, indicating that they have received the client SYN, while the server is SYN_REVD state
    3. Third handshake: the client receives the SYN packet, sends an ACK packet, of course, it is the server's ISN (s) + 1 as the value of the ACK, he has received a SYN server, in which case the client in the ESTABLISHED state
    4. After the server receives the ACK packet, it is in the ESTABLISHED state, the two sides set up the connection.
  3. schematic diagram

TCP three-way handshake

  1. common problem

    1. ISN (Initial Sequence Number) is fixed it?

    The two sides exchanged ISN communication to let each other know next time how to accept data reassembling data in accordance with the serial number. If it is fixed, it is easy for an attacker to guess the subsequent acknowledgment number, therefore, ISN is dynamically generated .

    1. What is the half-connection queue?

    When the server receives the first SYN, SYN_RECD is in a state, in this state the connection request in a queue inside, the queue is semi-connection queue . After completing the three-way handshake, the connection will be established on a fully connected queue in. If the queue is full, packet loss may occur.

    1. SYN-ACK retransmission mechanism

    The server has finished sending SYN - ACK packet, if no acknowledgment message client server for the first retransmission, wait some time yet to receive a confirmation packet, a second retransmission, if the retransmission count exceeds the system requirements maximum number of retransmissions, then the connection information is deleted from the half-connection queue. Latency exponential growth: 1248 .. .

    1. Three-way handshake may carry data?

    The first handshake can not carry secondary, third handshake, in fact, the client is already in the state to establish a connection, so the third handshake can carry data.

    The first handshake can not carry data to avoid malicious server receives the client information in the first handshake carry large amounts of data, and repeatedly resend SYN packets, resulting in a waste of server time and space.

    1. Why not shake hands twice?

    If the request sent by the client stay in the network, will be connected across a long time to receive confirmation server sends back. The client waits for a retransmission timeout after time, the request will be re-connected, but retained the connection request will eventually arrive at the server. If you do not shake hands for the third time, then Server opens two connections. If 3-way handshake, then the client will ignore Server stranded request sent connection confirmation.

5. Four waving

At first, the two sides are in the ESTABLISHED state, if the client is first launched shutdown request:

  1. The first wave: the client sends a FIN packet, the packet will assign a serial number. At this time, the client is FIN_WAIT1 state;
  2. The second wave: the server receives a FIN packet, the ACK packet is sent, and the client's sequence number + 1 as the sequence number ACK packet, indicating that the client has received the FIN message, and this when the server is CLOSE_WAIT state.
  3. Third wave: If the server also want to disconnect, and the same to send a FIN packet to the client, and specify a serial number. At this time, the server is LAST_ACK state
  4. The fourth wave: The client receives the FIN, ACK sent as a reply, then the client is in the TIME_WAIT state. After a while the need to ensure that their server received ACK packet enters the CLOSED state.
  5. After the server receives the ACK packet, it is in a closed state.
  6. schematic diagram

TCP four wave

1. Points to note:

  1. 每一次报文交换后,客户端与服务器端的状态是什么样的。
  2. Client 发送了 FIN 报文后,Server 一收到这个报文就进入 Close-Wait 状态,这个状态是为了让 Server 发送还未发送完成的数据,传送完后,Server 也发送 FIN 来结束连接。
  3. Client 接收到 Server 的 FIN 后,需要进入一个 Time-Wait 状态,时间为 2MSL(最大报文存活时间),再进入 Closed 状态,原因?
    1. 确保最后一个确认报文能够到达,若 Server 没有收到 Client 的 ACK,就会重新发送 FIN 报文,Client 等待一段时间就是为此;
    2. 等待一段时间是为了让本地连接持续时间内产生的所有报文从网络中消失,使得下一个新的连接不会出现旧的连接请求报文。

6. TCP流量控制机制

参考来源

  1. 为什么要进行流量控制?

接收方缓存满后,再接受数据包会出现丢包的问题,为了避免丢包问题,控制发送方发送速率,让接收方、发送方处于动态平衡的策略叫做流量控制

  1. 如何控制

接收方每次接收到数据后,在发送确认报文的时候可以将自己**缓冲区还剩下多少空间(接收窗口 win)**告诉发送方。

发送方收到这个接收窗口的信息后,便调整自己的发送速率,即调整发送窗口的大小,当发送窗口变为0,则停止发送数据,避免出现丢包的情况。

  1. 发送方什么时候再继续发送数据?
    1. 当发送方收到 win = 0 的消息后,就停止发送报文,同时打开一个定时器,每隔一段时间就发送一个测试报文去询问接收方,“你准备好了吗?”,如果接收方回复可以继续发送,则继续发送;若 win 还是等于 0 ,则刷新启动定时器,准备下一次询问。

4.注意事项

  1. TCP/IP 全双工传输,因此通信双方都有两个滑动窗口,一个用于接受数据,接收窗口;一个用于发送数据,发送窗口(拥塞窗口)。指出窗口大小的通知称为 “窗口通告”。
  2. 接收窗口的大小固定吗?
    1. 现在的TCP协议中,大小是动态调整的
  3. 接收窗口越大越好吗?
    1. 太小,丢包率上升;太大,消耗内存。
    2. 根据网络环境以及发送方的拥塞窗口来进行动态调整。
  4. 一般情况下:接收窗口 >= 发送窗口

7. 拥塞控制机制

参考来源

1.为什么要进行拥塞控制?

​ 假设主机A和主机B通信

​ 当主机A给主机B发送报文后,由于某些原因,迟迟没有收到主机B的ACK确认报文,那么主机A会认为报文被丢失了,那么主机A将继续给主机B发送报文。但是现实情况可能是因为网络中有太多主机占用信道资源,导致网络拥塞,主机A第一次给主机B发送的报文还是可以到达主机B的,但是A再次给主机B发送了一个报文,不仅造成网络进一步拥塞,还浪费了信道资源。所以我们需要进行拥塞控制。

2.如何知道网络的拥塞情况?

​ 将A一次性连续发送的数据包个数称之为“拥塞窗口”,用N表示吧。那么A怎么知道网络的拥塞情况呢?

开始阶段,发送数据包试探,其中 N 指数增长,到达一个阈值 ssthresh 后,再线性增长。

3.到了瓶颈值后怎么办?

  1. 将达到瓶颈值的 N 称为 Max;
  2. 到达 Max 后,我们就回到最原始的状态,1 2 4 8 。。。这样开始,同时, 设置阈值 ssthresh​ = Max / 2

4.超时事件一定是网络拥塞吗?

​ 还有可能是某个数据包出现了丢失或者损害,导致这个数据包超时时间发生。

通过冗余 ACK 防止这种情况。当 A 连续收到三个确认 M2 的 ACK 且M3超时事件还没发生。A就知道 M3 可能丢失了,这个时候A就不必等待 M3 设置的计时器到期了,而是快速重传M3 。 并且把 ssthresh 设置为 Max 的一半,即 ssthresh = Max / 2 , 但是这个时候并非把控制窗口 N 设置为1,而是让N = ssthresh,N 在一个一个增长。 这种情况也叫做 快速恢复。

8.在浏览器地址栏输入一个URL后回车,背后会进行哪些技术步骤?

参考来源

1.格式验证与协议选择

  1. 浏览器对用户输入的网址做初步的格式化检查,只有通过格式化检查,才会进入下一步
  2. 浏览器使用 http 还是 https 访问服务器?
    1. 没有明确告知浏览器用哪个协议,浏览器采用默认的 http 协议

2.DNS 查询

  1. 拥有想要访问的网站的域名还是不够的,TCP/IP 协议传送消息需要知道对方的 IP 地址
  2. 于是,浏览器使用 DNS(域名系统)查询域名对应的 IP 地址
  3. DNS 先查询自己内存里面的 DNS Cache,没有 -》接着再看本地硬盘里面的 host 文件,还是没有
  4. 于是,DNS 请求 DNS 服务器,请求过程使用 UDP 协议,请求报文中还携带有网关的 MAC 地址,通过 ARP(地址解析协议)获取;
  5. After the request arrived at the DNS server, the DNS server cache inside look at their IP address corresponding to the domain name is not requested, if it is returned, otherwise, DNS server requesting DNS root servers ran. "." . "" Is the root servers, the global total of 13 root name servers, each DNS server knows the IP address of the 13 root servers
  6. Root server receives "zhihu.com." (Domain name requested), knowing that his grandson server, but do not know his IP, but know "com" IP address, DNS server and then went to the "com", obtaining from him to "zhihu.com." IP address, the IP address will be immediately conveyed to wait for the browser.

3. The three-way handshake

Using the TCP protocol.

  1. After a successful three-way handshake to establish a reliable virtual channel. Browser ready to http request message to just get to the IP address (zhihu.com domain name), this time to get a redirected message, because zhihu.com use https protocol, so back to the request;
  2. Http requests and substantially similar. But the difference is that the https protocol is encrypted, secure, need to go through the certificate validation step, the default port 443 .
  3. After a series of encryption, decryption, certificate validation operation, browser-initiated request finally got a response, https zhihu.com will return home and ultimately to the browser.

If you have questions, please correct me!

Published 16 original articles · won praise 2 · Views 1279

Guess you like

Origin blog.csdn.net/yx185/article/details/103281570