当前位置:网站首页>[Stanford Jiwang cs144 project] lab4: tcpconnection
[Stanford Jiwang cs144 project] lab4: tcpconnection
2022-07-07 07:43:00 【Altair_ alpha】
At the receiving end TCPReceiver Class and sender TCPSender After the class , In this section, the experimental implementation takes charge of these two classes , Provide users with a complete TCP Connect Abstract TCPConnection class . As the title of the handout says , After completing the experiment in this section , We really climbed a peak (summit), It is also the most important essence of this course .
Advance warning , The amount of testing in this section is very large , It will use yours TCP Realization and Linux Of TCP Realize the interaction of various conditions , Previous Sender and Receiver If there are potential problems in the implementation of classes, they will also be exposed . therefore , If you're trying to do it yourself , Please be patient Debug To prepare . Although look directly at others blog It may feel that the logic is very natural , But doing it yourself is totally different . I also spent 2 It took about a whole day to pass all the tests .
TCP It's full duplex communication , That is, both parties can send / Receiving information . As shown in the figure ,TCPConnection Class should be built on TCPSender and TCPReceiver Above . When Sender When you need to send a packet , Send queue from it _segments_out
Take out the data packet and actually send it out ; When a packet is received , After necessary treatment, hand it over to Receiver Handle . in addition , We haven't paid attention to it before TCP A very important logo in Baotou RST, This is also TCPConnection Responsible , That is, the handling of abnormal states . Last ,TCPConnection You should also handle the termination of the connection , Including normal termination and abnormal termination . Let's discuss these problems and implementation ideas .
notes : The implementation of sending here is actually to send packets from Sender Take out and transfer to TCPConnection In a send queue of , Later, the higher-level owner will actually be responsible for sending
Receive packets
The corresponding function :void segment_received(const TCPSegment &seg)
.
- If RST Identification exists , Immediately set the incoming and outgoing data streams to the error state , And end the connection . You can refine the end connection into a
_shutdown(bool)
function , Parameter represents normal or abnormal end , Here is the abnormal end . otherwise : - Give the packet to Receiver Handle , That is to call Receiver Of
segment_received
. - If ACK Identification exists , notice Sender The information it focuses on (ackno and window size), That is to call Sender Of
ack_received
. - If the packet has a serial number , Ensure that at least one reply packet is replied , That is, you should check Sender Whether the send queue is empty , If it is empty, create an empty bag .
- “keep-alive” Reply of package : The other party may send a packet containing an invalid serial number to detect whether the connection is still valid , At this time, an empty package should be replied . The implementation method handout has been given .
Send packet
- Sender The constructed packet to be sent is not complete ,ackno and window size Information should be provided by Receiver give ( If there is ackno, Also set ACK identification ).
- Any time Sender Send to the queue push I bought a bag ,TCPConnection Should be sent immediately . therefore ,TCPConnection An emptying should be realized Sender queue , fill Receiver Information and send function ( My implementation is named
_clear_sendbuf
), In any possible way Sender This function is called after the statement that sends the packet .
Perception of time
And Sender identical ,TCPConnection Also through its tick
The function is called and passively perceives the passage of time . When tick
When called :
- send Sender
tick
. - If Sender The number of retransmissions exceeds a certain threshold , Terminate the connection and send a tape RST Empty package identified . Terminate the connection and receive the other party above RST Package processing is the same , That is to call
_shutdown(false)
. - If the time is right , End the connection normally ( See the next section ).
The termination of the connection
Two cases of abnormal connection termination have been discussed above , That is, active detection of too many retransmissions or passive receipt of the other party RST package , The main discussion here is the normal termination of the connection .
In theory , The two parties communicating through an untrusted connection cannot absolutely ensure a consensus ( Reference resources : The issue of the two armies ), however TCP A scheme with high reliability is designed . On one side (local Fang ) From the point of view of , There are at least four things that make it possible to properly terminate the connection :
- Inflow (inbound) The data of has been completely received and reorganized .
- Outward flow (outbound) The data of has been completely sent with FIN The identified package has also been sent .
- The outgoing flow is fully confirmed by the other party .
- local Fang believes that remote Can meet the third . This is the most difficult problem to solve , because TCP It won't be right ack Information do ack, Otherwise there will be no end . So there are two options :
- Delayed closure (lingering). The current three articles are established and after a certain period of time local Fang didn't receive remote We retransmit any data , be local We can make sure that all the data of both sides has been transmitted correctly and close the connection . say concretely , This time is set to Initial retransmission timeout 10 times .
- Passive closure . If the end of the incoming flow is earlier than that of the outgoing flow FIN Identify the sending of packets , be local Fang closes the connection immediately after the outgoing flow ends . The reasons are explained in the handout , It's not going to unfold here .
test
In addition to running automated tests , After the completion of this section, you can use two of your own TCP End to end communication , And use your own TCP Instead of Lab0 Medium TCPSocket Communicate with real servers , You can also test yourself TCP The performance of the implementation , The operation method is described in the handout .
Full code link :
tcp_connection.hh
tcp_connection.cc
Screenshot of customs clearance
边栏推荐
- 考研失败,卷不进大厂,感觉没戏了
- Tencent's one-day life
- ROS2规划系统plansys2简单的例子
- [performance pressure test] how to do a good job of performance pressure test?
- KBU1510-ASEMI电源专用15A整流桥KBU1510
- Convolutional neural network -- understanding of pooling
- JSON introduction and JS parsing JSON
- JS get all date or time stamps between two time stamps
- Detailed explanation of neo4j installation process
- How to * * labelimg
猜你喜欢
4、 High performance go language release optimization and landing practice youth training camp notes
Stockage et pratique des données en langage C (haut niveau)
URP - shaders and materials - simple lit
身边35岁程序员如何建立起技术护城河?
Convolutional neural network -- understanding of pooling
1090: integer power (multi instance test)
Example of Pushlet using handle of Pushlet
nacos
聊聊异步编程的 7 种实现方式
leetcode:105. 从前序与中序遍历序列构造二叉树
随机推荐
1、 Go knowledge check and remedy + practical course notes youth training camp notes
MobaXterm
3、 High quality programming and performance tuning practical youth training camp notes
C language (high-level) data storage + Practice
Dynamics CRM server deployment - restore database prompt: the database is in use
Blue Bridge Cup Birthday candles (violence)
Redis data migration
抽丝剥茧C语言(高阶)指针进阶练习
Rxjs - observable doesn't complete when an error occurs - rxjs - observable doesn't complete when an error occurs
JSON introduction and JS parsing JSON
Convolutional neural network -- understanding of pooling
Iterable、Collection、List 的常见方法签名以及含义
【webrtc】m98 screen和window采集
Summary of customer value model (RFM) technology for data analysis
Wx is used in wechat applet Showtoast() for interface interaction
2、 Concurrent and test notes youth training camp notes
07_ Handout on the essence and practical skills of text measurement and geometric transformation
JS get all date or time stamps between two time stamps
Write CPU yourself -- Chapter 9 -- learning notes
聊聊异步编程的 7 种实现方式