Skip to content

Commit

Permalink
清除冗余
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyuttt committed Jun 9, 2019
1 parent dba2731 commit 24dc9ed
Show file tree
Hide file tree
Showing 56 changed files with 6,013 additions and 124 deletions.
29 changes: 29 additions & 0 deletions .metadata/.log
Original file line number Diff line number Diff line change
Expand Up @@ -11247,3 +11247,32 @@ This warning can be switched off on the Team > Git > Confirmations and Warnings

!ENTRY org.eclipse.jdt.debug 2 0 2019-06-09 03:47:38.318
!MESSAGE Unable to find location of java.lang.Thread.setName() in debuggee JVM, for type java.lang.Thread
!SESSION 2019-06-09 10:41:50.744 -----------------------------------------------
eclipse.buildId=4.11.0.I20190307-0500
java.version=1.8.0_201
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

!ENTRY org.eclipse.egit.core 1 0 2019-06-09 10:44:38.604
!MESSAGE Using Apache MINA sshd as ssh client.

!ENTRY org.eclipse.jface.text 2 0 2019-06-09 10:46:26.427
!MESSAGE Duplicate template id: 'org.eclipse.wst.xslt.templates.xpath.boolean'

!ENTRY org.eclipse.egit.ui 2 0 2019-06-09 10:47:09.167
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
user global configuration and to define the default location to store repositories: 'C:\Users\jinyu'. If this is
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
EGit might behave differently since they see different configuration options.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.

!ENTRY org.eclipse.jface.text 2 0 2019-06-09 11:15:59.729
!MESSAGE Duplicate template id: 'org.eclipse.wst.xslt.templates.xpath.boolean'

!ENTRY org.eclipse.jdt.debug 2 0 2019-06-09 12:12:50.585
!MESSAGE Unable to find location of java.lang.Thread.setName() in debuggee JVM, for type java.lang.Thread

!ENTRY org.eclipse.jdt.debug 2 0 2019-06-09 12:13:50.480
!MESSAGE Unable to find location of java.lang.Thread.setName() in debuggee JVM, for type java.lang.Thread
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/*********************************************************************************
* Copyright (c) 2010 Forschungszentrum Juelich GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer at the end. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* (2) Neither the name of Forschungszentrum Juelich GmbH nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* DISCLAIMER
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************************/

package udt;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.DatagramPacket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;

import udt.packets.ConnectionHandshake;
import udt.packets.Destination;
import udt.packets.KeepAlive;
import udt.packets.Shutdown;
import udt.util.Tools;

/**
* server side session in client-server mode
*/
public class ServerSession extends UDTSession {

private static final Logger logger=Logger.getLogger(ServerSession.class.getName());

private final UDPEndPoint endPoint;

//last received packet (for testing purposes)
private UDTPacket lastPacket;

private long cookie=0;//cd 2018-08-28
private String key="judp";//��ǣ���ʱ�����ˣ���c++һ��
private String client="";
int n_handshake=0;
public ServerSession(DatagramPacket dp, UDPEndPoint endPoint)throws SocketException,UnknownHostException{
super("ServerSession localPort="+endPoint.getLocalPort()+" peer="+dp.getAddress()+":"+dp.getPort(),new Destination(dp.getAddress(),dp.getPort()));
this.endPoint=endPoint;
client=dp.getAddress()+":"+dp.getPort();
logger.info("Created "+toString()+" talking to "+dp.getAddress()+":"+dp.getPort());
}



@Override
public void received(UDTPacket packet, Destination peer){
lastPacket=packet;

if(packet instanceof ConnectionHandshake) {
ConnectionHandshake connectionHandshake=(ConnectionHandshake)packet;
logger.info("Received "+connectionHandshake);

if (getState()<=ready){
destination.setSocketID(connectionHandshake.getSocketID());
if(getState()<=handshaking){
setState(handshaking);
}
try{
handleHandShake(connectionHandshake);
n_handshake++;
try{
//������Ӧ���ȼ���cookie
setState(ready);
socket=new UDTSocket(endPoint, this);
cc.init();
}catch(Exception uhe){
//session is invalid
logger.log(Level.SEVERE,"",uhe);
setState(invalid);
}
}catch(IOException ex){
//session invalid
logger.log(Level.WARNING,"Error processing ConnectionHandshake",ex);
setState(invalid);
}
return;
}
else
{
//cd �ظ�
try {
handleHandShake(connectionHandshake);
} catch (IOException e) {
e.printStackTrace();
}
}

}else if(packet instanceof KeepAlive) {
socket.getReceiver().resetEXPTimer();
active = true;
return;
}

if(getState()== ready) {
active = true;

if (packet instanceof KeepAlive) {
//nothing to do here
return;
}else if (packet instanceof Shutdown) {
try{
socket.getReceiver().stop();
}catch(IOException ex){
logger.log(Level.WARNING,"",ex);
}
setState(shutdown);
System.out.println("SHUTDOWN ***");
active = false;
logger.info("Connection shutdown initiated by the other side.");
return;
}

else{
try{

if(packet.forSender()){
socket.getSender().receive(packet);
}else{
socket.getReceiver().receive(packet);
}
}catch(Exception ex){
//session invalid
logger.log(Level.SEVERE,"",ex);
setState(invalid);
}
}
return;

}


}

/**
* for testing use only
*/
UDTPacket getLastPacket(){
return lastPacket;
}

/**
* handle the connection handshake:<br/>
* <ul>
* <li>set initial sequence number</li>
* <li>send response handshake</li>
* </ul>
* @param handshake
* @param peer
* @throws IOException
*/
protected void handleHandShake(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());
//cd 2018-08-28
if(this.cookie==0)
{
this.cookie=createCookie();
}
responseHandshake.setcookie(cookie);

responseHandshake.setSession(this);
logger.info("Sending reply "+responseHandshake);
endPoint.doSend(responseHandshake);
}

/**
* cd
* @Title: createcCookie
* @Description: ����Cookie
* @param @return ����
* @return long ��������
*/
private long createCookie()
{
byte[] bytes=null;
byte[] result=new byte[4];
ByteBuffer buf=ByteBuffer.wrap(result);
//�޸�����c++һ��
String src=Tools.string2MD5(client+key);
try {
bytes=src.getBytes("utf-8");
} catch (UnsupportedEncodingException e)
{
bytes=src.getBytes();
}
if(bytes.length>4)
{
buf.put(bytes, 0, 4);
}
else
{
buf.put(bytes);
}
buf.flip();
return buf.getInt();
}

private String GetClientCookie()
{
long timespan=(System.currentTimeMillis()-startTime)/60000;//ת������
return client+":"+timespan;
}
}

Loading

0 comments on commit 24dc9ed

Please sign in to comment.