当前位置:网站首页>[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
边栏推荐
- Initial experience of teambiion network disk (Alibaba cloud network disk)
- 身边35岁程序员如何建立起技术护城河?
- 《动手学深度学习》(四) -- 卷积神经网络 CNN
- The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
- 【数学笔记】弧度
- BGP experiment (1)
- Six methods of flattening arrays with JS
- 外包干了三年,废了...
- 3、 High quality programming and performance tuning practical youth training camp notes
- 1090: integer power (multi instance test)
猜你喜欢
外包幹了三年,廢了...
Summary of customer value model (RFM) technology for data analysis
Calculus key and difficult points record part integral + trigonometric function integral
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
Flutter riverpod is comprehensively and deeply analyzed. Why is it officially recommended?
《动手学深度学习》(四) -- 卷积神经网络 CNN
Iterable、Collection、List 的常见方法签名以及含义
Leetcode-226. Invert Binary Tree
【斯坦福计网CS144项目】Lab3: TCPSender
07_ Handout on the essence and practical skills of text measurement and geometric transformation
随机推荐
微信小程序中的路由跳转
Example of Pushlet using handle of Pushlet
How to * * labelimg
nacos
Solve could not find or load the QT platform plugin "xcb" in "
外包干了四年,废了...
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
2022-07-06:以下go语言代码是否会panic?A:会;B:不会。 package main import “C“ func main() { var ch chan struct
Detailed explanation of neo4j installation process
MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding
[UTCTF2020]file header
为什么要了解现货黄金走势?
2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct
Is the test cycle compressed? Teach you 9 ways to deal with it
Outlier detection technology of time series data
gatk4中的interval是什么??
JS plot flot application - simple curve
IO流 file
聊聊异步编程的 7 种实现方式
Solution: could not find kf5 (missing: coreaddons dbusaddons doctools xmlgui)