UDT4之握手分析

本文详细介绍了UDT的两种连接设置方法:传统的客户端/服务器模式和汇合模式,重点关注握手协议的过程。在汇合模式中,双方同时发起连接请求。UDT客户端发送包含版本信息、Socket类型、初始序列号、包大小、最大流窗口大小、连接类型、Socket ID、Cookie和对端IP地址的手握请求。文章还深入解析了UDT::connect及accept的源代码。
摘要由CSDN通过智能技术生成

1握手协议分析

UDT supports two different connection setup methods, the traditional client/server mode and the rendezvous mode. In the latter mode, both UDT sockets connect to each other at (approximately) the same time. 

UDT支持两种连接模式:传统模式(c/s)和汇合模式。其中,汇合模式中,需要两端同时调用udt::connect。

The UDT client (in rendezvous mode, both peer are clients) sends a handshake request (type 0 control packet) to the server or the peer side. The handshake packet has the following information (suppose UDT socket A sends this handshake to B): 

UDT client(在汇合模式中,两端均为客户端)发送一个握手消息(type为0的控制报文)给server或者peer。握手报文所携带的信息如下(加入UDT socket A发送握手信息给UDT socket B):

1) UDT version: this value is for compatibility purpose. The current version is 4. 
2) Socket Type: STREAM (0) or DGRAM (1). 
3) Initial Sequence Number: It is the sequence number for the first data packet that A will send out. This should be a random value. 随机序列号
4) Packet Size: the maximum size of a data packet (including all headers). This is usually the value of MTU. 一般为MTU值的大小
5) Maximum Flow Window Size: This value may not be necessary; however, it is needed in the current reference implementation. 
6) Connection Type. This information is used to differential the connection setup modes and request/response. 
7) Socket ID. The client UDT socket ID. 
8) Cookie. This is a cookie value used to avoid SYN flooding attack [RFC4987]. 避免SYN flooding 攻击
9) Peer IP address: B's IP address. 

1.1传统模式(c/s) Client/Server Connection Setup(四次握手)

One UDT entity starts first as the server (listener). The server accepts and processes incoming connection request, and creates new UDT socket for each new connection. 
一个UDT实体开始作为server(listener)。server接收和处理连接请求, 并为每一个新的连接创建一个new UDT socket

A client that wants to connect to the server will send a handshake packet first. The client should keep on sending the handshake packet every constant interval until it receives a response handshake from the server or a timeout timer expires. 
当一个client要跟server建立连接的时候,首先会发送一个握手报文给server。client会每隔一个固定的间隔interbal发送一个握手报文(这个固定间隔在代码中是250ms),当遇到如下两种情况之一的时候才停止发送:1、收到server反馈回来的握手的报文;2、连接超时。

When the server first receives the connection request from a client, it generates a cookie value according to the client address and a secret key and sends it back to the client. The client must then send back the same cookie to the server. 
server第一次接收到来自client握手请求的时候,它会根据client的address和一个secret key产生一个cookie值,然后反馈给client。然后,client必须把收到的cookie反馈给server。

The server, when receiving a handshake packet and the correct cookie, compares the packet size and maximum window size with its own values and set its own values as the smaller ones. The result values are also sent back to the client by a response handshake packet,together with the server's version and initial sequence number. T he server is ready for sending/receiving data right after this step is finished. However, it must send back response packet as long as it receives any further handshakes from the same client. 
当server接收到一个握手报文和正确的cookie时,将握手报文中的packet size 和maximum window size信息提取出来,并同server端自己的packet size 和maximum window size信息相比较,将较小的packet size 和maximum window size信息赋值给自己。把这个结果反馈给client端,并携带上server的版本号和初始序列号。当完成这个步骤之后,server端就开始准备发送/接收数据。然后,如果收到来自same client端的其它handshakes的时候,server端仍要回复response packet。(这是为了防止server反馈回去的包丢失)

The client can start sending/receiving data once it gets a response handshake packet from the server. Further response handshake messages, if received any, should be omitted.
一旦
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值