1. 模式有client/server mode(客户端,服务器端模式) and the rendezvous mode(会合模式,可同时向对方发送请求)
2. client发送的握手信息,信息有:
1) UDT version: udt版本,主要用作兼容性处理
2) Socket Type: STREAM (0) or DGRAM (1).
3) Initial Sequence Number: 第一包的序号,是个随机值
4) Packet Size: the maximum size of a data packet (including all
headers). This is usually the value of MTU.
5) Maximum Flow Window Size
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].
9) Peer IP address: B's IP address.
//initial handshake for connect protected void sendInitialHandShake()throws IOException{ ConnectionHandshake handshake = new ConnectionHandshake(); handshake.setConnectionType(ConnectionHandshake.CONNECTION_TYPE_REGULAR); handshake.setSocketType(ConnectionHandshake.SOCKET_TYPE_DGRAM); long initialSequenceNo=SequenceNumber.random(); setInitialSequenceNumber(initialSequenceNo); handshake.setInitialSeqNo(initialSequenceNo); handshake.setPacketSize(getDatagramSize()); handshake.setSocketID(mySocketID); handshake.setMaxFlowWndSize(flowWindowSize); handshake.setSession(this); handshake.setAddress(endPoint.getLocalAddress()); logger.info("Sending "+handshake); // 没有设置destinationID endPoint.doSend(handshake); }
client的状态之后设置位handshaking
3. server端对握手信息的处理
接收到握手信息后,产生cookie返回,client端需要返回相同的cookie到server
/* * response after the initial connection handshake received: * compute cookie */ protected void ackInitialHandshake(ConnectionHandshake handshake)throws IOException{ ConnectionHandshake responseHandshake = new ConnectionHandshake(); //compare the packet size and choose minimun long clientBufferSize=handshake.getPacketSize(); long myBufferSize=getDatagramSize(); long bufferSize=Math.min(clientBufferSize, myBufferSize); long initialSequenceNumber=handshake.getInitialSeqNo(); setInitialSequenceNumber(initialSequenceNumber); setDatagramSize((int)bufferSize); responseHandshake.setPacketSize(bufferSize); responseHandshake.setUdtVersion(4); responseHandshake.setInitialSeqNo(initialSequenceNumber); responseHandshake.setConnectionType(-1); responseHandshake.setMaxFlowWndSize(handshake.getMaxFlowWndSize()); //tell peer what the socket ID on this side is responseHandshake.setSocketID(mySocketID); responseHandshake.setDestinationID(this.getDestination().getSocketID()); responseHandshake.setSession(this); // 产生cookie sessionCookie=SequenceNumber.random(); responseHandshake.setCookie(sessionCookie); responseHandshake.setAddress(endPoint.getLocalAddress()); logger.info("Sending reply "+responseHandshake); endPoint.doSend(responseHandshake); }
server端的状态为n_handshake=1(第一次握手)
4. client端收到server端的返回
// 第一次握手的响应 if (getState()==handshaking) { logger.info("Received initial handshake response from "+peer+"\n"+hs); if(hs.getConnectionType()==ConnectionHandshake.CONNECTION_SERVER_ACK){ try{ //TODO validate parameters sent by peer long peerSocketID=hs.getSocketID(); sessionCookie=hs.getCookie(); destination.setSocketID(peerSocketID); setState(handshaking+1); }catch(Exception ex){ logger.log(Level.WARNING,"Error creating socket",ex); setState(invalid); } return; } else{ logger.info("Unexpected type of handshake packet received"); setState(invalid); } }
client的状态设置为handshaking+1
同时发送二次握手信息
//2nd handshake for connect protected void sendSecondHandshake()throws IOException{ ConnectionHandshake handshake = new ConnectionHandshake(); handshake.setConnectionType(ConnectionHandshake.CONNECTION_TYPE_REGULAR); handshake.setSocketType(ConnectionHandshake.SOCKET_TYPE_DGRAM); handshake.setInitialSeqNo(initialSequenceNo); handshake.setPacketSize(getDatagramSize()); handshake.setSocketID(mySocketID); handshake.setMaxFlowWndSize(flowWindowSize); handshake.setSession(this); handshake.setCookie(sessionCookie); handshake.setAddress(endPoint.getLocalAddress()); handshake.setDestinationID(getDestination().getSocketID()); logger.info("Sending confirmation "+handshake); endPoint.doSend(handshake); }
5. server端接收到client的二次握手
protected void sendFinalHandShake(ConnectionHandshake handshake)throws IOException{ if(finalConnectionHandshake==null){ finalConnectionHandshake= new ConnectionHandshake(); //compare the packet size and choose minimun long clientBufferSize=handshake.getPacketSize(); long myBufferSize=getDatagramSize(); long bufferSize=Math.min(clientBufferSize, myBufferSize); long initialSequenceNumber=handshake.getInitialSeqNo(); setInitialSequenceNumber(initialSequenceNumber); setDatagramSize((int)bufferSize); finalConnectionHandshake.setPacketSize(bufferSize); finalConnectionHandshake.setUdtVersion(4); finalConnectionHandshake.setInitialSeqNo(initialSequenceNumber); finalConnectionHandshake.setConnectionType(-1); finalConnectionHandshake.setMaxFlowWndSize(handshake.getMaxFlowWndSize()); //tell peer what the socket ID on this side is finalConnectionHandshake.setSocketID(mySocketID); finalConnectionHandshake.setDestinationID(this.getDestination().getSocketID()); finalConnectionHandshake.setSession(this); finalConnectionHandshake.setCookie(sessionCookie); finalConnectionHandshake.setAddress(endPoint.getLocalAddress()); } logger.info("Sending final handshake ack "+finalConnectionHandshake); endPoint.doSend(finalConnectionHandshake); }
server端的状态位ready,链接建立完毕
6. client端收到二次握手的确认
if(getState()==handshaking+1){ // 第二次握手的响应 try{ logger.info("Received confirmation handshake response from "+peer+"\n"+hs); //TODO validate parameters sent by peer setState(ready); socket=new UDTSocket(endPoint,this); }catch(Exception ex){ logger.log(Level.WARNING,"Error creating socket",ex); setState(invalid); }
client端状态为ready, 链接建立完毕
7. 关闭,接收到Shutdown包,直接设置状态为关闭
8. 一些类的梳理:
(1)一个链接,可以理解为一个session
client端对应一个ClientSession
server端对应一个ServerSession
(2) Server对应UDTServerSocket,Client对应UDTClient
(3) 底层的udp的传输和多个Session的维护使用UDPEndPoint
(4) 每个session的数据操作实际对应一个UDTSocket和CongestionControl
(5)每个UDTSocket对应一个UDTReceiver和UDTSender,对应一个UDTInputStream和UDTOutputStream
(6)CongestionControl用于拥塞控制
相关推荐
UDT协议-基于UDP的可靠数据传输协议
UDT协议-基于UDP的可靠数据传输协议.pdfUDT协议-基于UDP的可靠数据传输协议.pdf
UDT协议-基于UDP的可靠数据传输协议.docxUDT协议-基于UDP的可靠数据传输协议.docx
UDT协议-基于UDP的可靠数据传输协议 (2).pdfUDT协议-基于UDP的可靠数据传输协议 (2).pdf
UDT协议-基于UDP的可靠数据传输协议 (2).docxUDT协议-基于UDP的可靠数据传输协议 (2).docx
另一个重要的应用场景是,允许网络研究人员、学生和应用程序开发人员在UDT框架下轻松地实现和部署新的数据传输算法和协议。此外,UDT也可用于更好地支持防火墙穿透。 UDT完全构建在UDP之上。但是,UDT是有连接的,...
UDT协议基于UDP的可靠数据传输协议.pdfUDT协议基于UDP的可靠数据传输协议.pdf
基于UDP的高速传输协议UDT,介绍UDT的来历,拥塞控制算法,开发使用方法等。
udt-java 可靠UDP传输 源码
UDT网络传输协议开源包,是基于UDP的可靠传输协议,UDP访TCP
UDT协议UDP可靠数据传输协议.pdfUDT协议UDP可靠数据传输协议.pdf
UDT协议UDP可靠数据传输协议.docxUDT协议UDP可靠数据传输协议.docx
Python UDP实现可靠传输 停等协议
基于UDP的高速传输协议--UDT.pdf
udt 基于udp的可靠连接 udt 基于udp的可靠连接
分析了基于UDP的改进高速网络传输协议的基本原理, 详细阐述了近年来提出的一些典型的基于UDP改进传输协议的主要设计思想。通过建立端到端的高速网络试验床, 评价了RTT及丢包率对RUBDP、Tsunami、 UDT、PA-UDP四种...
udt,一种基于udp协议的可靠文件传输协议
UDP 可靠传输协议 UDT ,实现原理
udt 是基于udp的可靠数据收发程序。之前有很多版本,这个是目前官网最新的。
基于UDT协议-通过libudt-http://udt.sourceforge.net/ UDT是一种可靠的基于UDP的应用程序级数据传输协议。 UDT是为超高速网络设计的,已用于支持TB级数据集的全局数据传输。 Ne Plus Ultra的构建具有极低的依赖性...