当前位置:网站首页>Network: friends interview TCP / IP, go back and wait for notice

Network: friends interview TCP / IP, go back and wait for notice

2021-06-23 22:26:18 cscw

Preface

Recently, I chatted with a classmate , He wants to change his job , Then I went to a big factory . at that time , He wrote on his resume that he was proficient in TCP/IP, In line with the right TCP The agreement has a little understanding , The interviewer won't ask deeply about the idea , I wrote to master two words . little does one think , It's careless

github Address , thank star

Official account , Communicate together , Search on wechat : Sneak forward

start

My friend has an appointment for an interview at half past ten , Arrived ten minutes ahead of time , Then sit quietly on the sofa and wait , By the way, I'll recall what I saw before . It's almost half past ten , One is tall and thin , The man in the plaid shirt opened the door and entered , Said a sentence “ Hello , Let's start the interview !”, My friend replied politely with a smile “ That's ok ”

interviewer : Read your resume and say you are proficient in TCP and IP, Let's talk about the network model and TCP、IP agreement , Talk about your understanding first

  • friend ( How to ask as soon as you come up TCP, Don't play according to the routine , You shouldn't ask java Basic ? But regular questions , I'm ok )
  • friend : The network model is generally divided into seven layers : application layer 、 The presentation layer 、 The session layer 、 Transport layer 、 The network layer 、 Data link layer 、 The physical layer . Application layer protocols include HTTP、FTP、SMTP, and TCP Belongs to the transport layer ,IP The protocol belongs to the network layer
  • friend :TCP/IP The network model is hierarchical from top to bottom , Layers of packaging , Each layer corresponds to a different protocol resolution , Let me draw a picture

interviewer : Look at the picture you drew ,TCP It has its own head structure , What fields are there , It's better to talk about their role

  • friend ( What the hell? ! When I baidu dictionary , How can you remember ? wait , I think I saw it last night , Have an impression )
  • friend : Continue to draw a picture , Intuitive point
  • friend :TCP The first structure is 16 Bit source port number and destination port number 、 Next is 32 Bit sequence number and confirmation number . Next is 4bit Head length and 6 individual bit The reserved bits of and 6bit The mark of a
  • friend :16 Bit attributes have window size ( Control the send window ), Inspection and ( Verify that the data segment has not been modified ) And the emergency pointer . Finally, the options , Its length is determined by the length of the head
  • friend : In detail, the serial number , It is TCP A numeric number of a message segment , To guarantee TCP Reliable connection , Each data segment to be sent should be added with a sequence number . When establishing a connection , Both ends will randomly generate an initial sequence number . The confirmation number is used in conjunction with the serial number , In response to a request , A confirmation number is returned , Its value is equal to the request sequence number plus 1
  • friend : and 6 The flag bits are ,URG: This is an urgent message ,ACK: Reply message ,PSH: The buffer is not full ,RST: Reset connection ,SYN: Establish connection message flag ,FIN: Notification of closing the connection
  • friend : Window size is the sliding window size used by the receiver to control the sender

interviewer : that TCP and UDP What's the difference?

  • friend ( A sigh of relief )
  • friend :1) Connection aspect :TCP Connection oriented .UDP It's disconnected , There is no need to establish a connection before sending data
  • friend :2) security :TCP Provide reliable service , Guaranteed data transfer , No mistakes , No loss , No repetition , And arrive in order .UDP It's about doing your best to deliver , There is no guarantee of reliable delivery
  • friend :3) transmission efficiency :TCP Transmission efficiency is relatively low ,UDP High transmission efficiency

interviewer : Just now you said TCP It's a reliable connection , How did it come true

  • friend :TCP The connection is based on three handshakes , And disconnection is four waves
  • friend : In order to protect data from loss and error ( reliability ), It has message checking 、ACK The reply 、 Over time retransmission ( The sender )、 Out of order data retransmission ( The receiving party )、 Discard duplicate data 、 flow control ( The sliding window ) And congestion control

interviewer : To be specific, say three handshakes and four waves

  • friend ( It's a regular question again , Sun water )
  • friend :TCP It's a reliable two-way channel , So it takes three handshakes and four waves , Let me draw a picture
  • Three handshakes
  • Four waves
  • friend : Answer in advance , It takes four waves to close the connection , One more time than when it was set up , It's because the passive shutdown may still have data that hasn't been sent out , It can't be like shaking hands , The second handshake is both an initiation handshake and a response handshake

interviewer : What's wrong if you don't shake hands three times

  • friend : If there are only two handshakes ,client After sending the connection request, it will not be ACK Server side SYN
  • friend : At this time, if the client determines that the connection failed due to its own reasons , It may be repeated TCP Connect , The server will think that those who are client Discarded TCP Still effective , It's a waste of resources

interviewer :TIME_WAIT and CLOSE_WAIT What's the difference between

  • friend :CLOSE_WAIT It's passive closure ; When the other side close socket And send FIN When the message comes , Respond ACK After entering CLOSE_WAIT state . Then check for untransmitted data , If not, make a third wave , send out FIN Message to the other party , Get into LAST_ACK State and wait for each other ACK The message arrived
  • friend :TIME_WAIT It's formed by actively closing the connection ; be in FIN_WAIT_2 In the state of , Received from the other side FIN Enter after message TIME_WAIT state ; Then wait for two more MSL(Maximum Segment Lifetime: Maximum message lifetime )

interviewer :TIME_WAIT What's the role of , There are also reasons to keep two state times MSL

  • friend ( It's too deep to ask , my dear friend . Fortunately, I made up a lesson secretly yesterday )
  • friend :1)TIME_WAIT The purpose of this is to ensure the last wave ACK The message can be delivered to the other party , If ACK The loss of , The other party will retransmit over time FIN, The active shutdown will respond again ACK In the past ; without TIME_WAIT state , Direct closure , It's retransmitted by the other side FIN The message is responded with a RST message , this RST Will be passively closed end resolved as an error
  • friend :2) There are two connections , The first connection is normally closed , Second, the same connection follows ; If the lost message of the first connection arrives , Will interfere with the second connection , Wait for two MSL Then the data of the last connected message will disappear behind the network

interviewer : You also mentioned congestion control ,TCP In what way does the protocol solve congestion

  • friend : The first is slow start and congestion avoidance
  • friend :1) Slow start ,TCP The sender maintains a congestion window (congestionwindow), Referred to as cwnd. The initial congestion window is 1 Message segments , Every time RTT( When the data is completely sent to the confirmation time ), Double the size of the window ( Exponential growth , It's just slow in the early days )
  • friend :2) Congestion avoidance , The idea is to make congestion windows cwnd Increase slowly , The sender's cwnd Reach the threshold ssthresh( The initial value is determined by the system ) after , Every time I pass by RTT Just add one more congestion window , Not double ( Received two or four confirmations , All are cwnd+1),cwnd It increases linearly ( Add more )
  • friend :( Draw a picture to analyze )
  • friend : If you encounter network congestion , Congestion window threshold ssthresh halve ,cwnd Set to 1, Re entering the slow start phase

interviewer : What other ways of congestion control

  • friend : Fast retransmission and fast recovery
  • friend :1) Fast retransmission is when the receiver receives an out of order message , Report to the sender immediately , I'm going to repeat it
  • friend : If the receiver M1 received ,M2 Have not received , After that M3、M4、M5 Sent again , At this time, the receiver continuously gives feedback to the sender 3 individual M1 Confirmation message . So fast repeat the rules , As long as the sender receives 3 Double check , Retransmit it immediately M2( The next message of a repeat acknowledgement message )
  • friend :2) Fast recovery
  • friend : When the sender receives three consecutive acknowledgments ,ssthresh halve ; Because the sender may think that the network is not congested now , So unlike a slow start , hold cwnd Value is set to ssthresh Half the value , Then the congestion avoidance algorithm ,cwnd Linear increase
  • friend :( Another picture )

interviewer : Know that sliding windows don't , How does the client and server control the sliding window

  • friend : The receiver puts the size of the buffer it can receive into TCP In the first part “ Window size ” Field , adopt ACK A message to inform the sender , The sliding window is used by the receiver to control the size of the data sent by the sender , So as to achieve flow control
  • friend : In fact, the upper limit of the sender's window , Is the minimum value of congestion window and sliding window

interviewer : Do you know the difference between a sliding window and a congested window

  • friend : The same thing is to control packet loss , The implementation mechanism is to make the sender send more slowly
  • friend : The difference is that the object of control is different
  • friend :1) The object of flow control is the receiver , I'm afraid the sender is sending too fast , So that the receiver has no time to process
  • friend :2) The object of congestion control is network , I'm afraid the sender is sending too fast , Causing network congestion , Make the network too late to handle

interviewer :TCP The problem of sticking and unpacking , What do you think

  • friend : The size of data the program needs to send and TCP Message segments can be sent MSS(Maximum Segment Size, Maximum message length ) It's different
  • friend : Greater than MSS when , The program data needs to be split into multiple TCP Message segment , It's called unpacking ; Less than when , Consider merging multiple program data into one TCP Message segment , It's a sticky bag ; among MSS = TCP Segment length -TCP The length of the first
  • friend : stay IP Protocol layer or link layer 、 The physical layer , There's unpacking 、 Sticking phenomenon

interviewer : What are the solutions to sticking and unpacking ?

  • friend :1) Add special characters to the end of the data for segmentation
  • friend :2) Set the data to a fixed size
  • friend :3) Divide the data into two parts , Part of it is the head , Part of it is the body of content ; The size of the head structure is fixed , And there is a field to declare the size of the content body

interviewer :SYN Flood Understand?

  • friend :SYN Flood forge SYN The message initiates a connection to the server , After receiving the message, the server uses SYN_ACK The reply , When this response is sent out , Will not receive ACK message , Make a half connection
  • friend : If the attacker sends a large number of such messages , There will be a large number of semi connections on the attacked host , Depleting its resources , Make normal users inaccessible , Until the half connection times out

interviewer : Yes TCP I have a good command of , Let's ask HTTP Knowledge . You know once HTTP request , How many steps does the program go through ?

  • friend :1) Domain name resolution -> 2) launch TCP Three handshakes , Establishing a connection -> 3) be based on TCP launch HTTP request -> 4) Server response HTTP request , And return the data -> 5) The client parses the returned data

interviewer :HTTP What are the response status codes , List a few that you are familiar with

  • friend : There are about the following

    *    200: Successful normal request 
    *    400: Semantically incorrect , Generally, the request format is not correct 
    *    401: User authentication permission is required , It's usually a certificate token Not certified 
    *    403: Denial of service 
    *    404: Resource does not exist 
    *    500: Server error 
    *    503: Temporary server maintenance , overload ; recoverable 
    

interviewer : Pretty good , I'll test you again ,session and cookie What's the difference?

  • friend :1) Different storage locations ,cookie It's data stored on the client side ;session On the server
  • friend :2) Different storage capacity , Single cookie The data saved is small , A site can save at most 20 individual Cookie; about session There is no upper limit
  • friend :3) Different storage methods ,cookie You can only keep ASCII character string ;session Can store any type of data
  • friend :4) Different privacy policies ,cookie Visible to clients ;session Store on the server , It's transparent to the client
  • friend :5) The validity period is different ,cookie It can exist for a long time ;session Depends on the name JSESSIONID Of cookie, Expiration time defaults to -1, Just close the window session It will fail.
  • friend :6) Cross domain support is different ,cookie Support cross domain access ;session Cross domain access is not supported

interviewer : Pretty good , So you know what HTTP Block transmission

  • friend : Block transmission is HTTP A transmission mechanism of , Allows the data sent by the server to the client to be divided into multiple parts , The agreement is HTTP/1.1 Provide

interviewer :HTTP What's the benefit of block transfer

  • friend :HTTP Block transfer coding allows the server to maintain... For dynamically generated content HTTP Persistent connection
  • friend : Block transfer encoding allows the server to send the header field at the end of the message . It's important for those cases where the header field value cannot be known before the content is generated , For example, the content of a message should be signed with a hash
  • friend :HTTP Servers sometimes use compression (gzip or deflate) To shorten the transmission time . Block transfer coding can be used to separate multiple parts of a compressed object . under these circumstances , Blocks are not compressed separately , Instead, the entire load is compressed . Block coding is beneficial to transmit data while compressing

    interviewer :HTTP How do you understand

  • friend : Long connection refers to the establishment of client and service TCP After connection , The connection between them will continue , Not for once HTTP Close after request , Subsequent requests also use this connection
  • friend : Long connection can be omitted TCP Set up and close operations of , For clients with frequent requests, it is suitable to use long connection , But be aware that malicious long connections cause service damage ( It is recommended to use )

interviewer :HTTP Is it safe ? How to be safe HTTP Protocol transfer

  • friend : It's not safe ,HTTP The data transmitted is plaintext , Easily intercepted by third parties ; To do secure data transmission , have access to HTTP Upgraded version HTTPS agreement

interviewer :HTTPS and HTTP The difference between , How do you understand

  • friend :1)http Protocol connections are stateless , Plaintext transmission
  • friend :2)HTTPS It is from SSL/TLS+HTTP The protocol is built with encrypted transmission 、 Network protocol for identity authentication

interviewer :SSL/TLS What is it? ,HTTPS How is the security of ?

  • friend :SSL(Secure Socket Layer Secure socket layer ) Is based on HTTPS The next protocol encryption layer , Protect data privacy .TLS(Transport Layer Security) The upgraded version is SSL
  • friend :https stay http The foundation adds a layer of security authentication and encryption layer TLS perhaps SSL, It goes through the security layer first ca Certification , Get the server's public key correctly
  • friend : Then the client will confirm an encryption algorithm through the public key and the server , The latter data can be encrypted with the encryption algorithm

interviewer : Can you elaborate on TLS/SSL The certification process for is not ...( At this time, the interviewer's mobile phone on the desk vibrated , He looked at his cell phone subconsciously , Pause )

My friend's interview has come to an end ( Go on next time )

Welcome refers to a mistake in the text

Reference article

版权声明
本文为[cscw]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/06/20210623222519728w.html