优化调度算法,避免路由震荡
This commit is contained in:
@@ -10,9 +10,13 @@ import java.io.OutputStream;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
@@ -54,10 +58,15 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
}
|
||||
|
||||
|
||||
dout = new DataOutputStream(new AddOutputStream(new BufferedOutputStream(outm)) );
|
||||
din = new DataInputStream(new AddInputStream(new BufferedInputStream(inm)));
|
||||
dout = new DataOutputStream(new BufferedOutputStream(outm,Consts.BLOCKSIZE*2+1) );
|
||||
din = new DataInputStream(new BufferedInputStream(inm,Consts.BLOCKSIZE*2+1));
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RemoteTCPConnection [tunnel=" + tunnel + "]";
|
||||
}
|
||||
|
||||
public RemoteTCPConnection(Tunnel t, Socket s) throws UnknownHostException, IOException {
|
||||
super(s);
|
||||
tunnel=t;
|
||||
@@ -87,7 +96,17 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
long odelay=Long.MAX_VALUE;
|
||||
public void setDelayAvg(long delay) {
|
||||
if(odelay==Long.MAX_VALUE) {
|
||||
odelay=delay;
|
||||
setDelay(odelay);
|
||||
}else {
|
||||
odelay=(delay+odelay*100)/101;
|
||||
setDelay(odelay);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (tunnel != null) {
|
||||
@@ -103,20 +122,27 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
public void sendBlock(KLALBBlock data) throws IOException {
|
||||
dout.writeLong(data.sn);
|
||||
dout.writeLong(data.cuid);
|
||||
sendBlock(data,true);
|
||||
}
|
||||
public void sendBlock(KLALBBlock data,boolean isflush) throws IOException {
|
||||
|
||||
dout.writeInt(data.cuid);
|
||||
dout.writeLong(data.number);
|
||||
if (data.number > 0) {
|
||||
if (data.data == null) {
|
||||
dout.writeInt(-1);
|
||||
dout.writeShort(-1);
|
||||
} else {
|
||||
dout.writeInt(data.data.length);
|
||||
dout.writeShort(data.data.length);
|
||||
dout.write(data.data);
|
||||
}
|
||||
} else if (data.number == 0) {
|
||||
dout.write(data.command);
|
||||
if(data.command!=0&&data.command!=1) {
|
||||
dout.writeLong(data.sn);
|
||||
}else {
|
||||
|
||||
}
|
||||
switch (data.command) {
|
||||
case 0:
|
||||
case 1:
|
||||
@@ -126,11 +152,14 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
dout.writeUTF(data.lservice);
|
||||
dout.writeUTF(data.lipport.toString());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
dout.writeInt(data.cacheused);
|
||||
}
|
||||
|
||||
if(isflush)
|
||||
dout.flush();
|
||||
|
||||
//System.out.println("SEND:" + data);
|
||||
@@ -138,11 +167,10 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
|
||||
public KLALBBlock receiveBlock() throws IOException {
|
||||
KLALBBlock klb = new KLALBBlock();
|
||||
klb.sn = din.readLong();
|
||||
klb.cuid = din.readLong();
|
||||
klb.cuid = din.readInt();
|
||||
klb.number = din.readLong();
|
||||
if (klb.number > 0) {
|
||||
int size = din.readInt();
|
||||
int size = din.readShort();
|
||||
if (size == -1) {
|
||||
klb.data = null;
|
||||
} else {
|
||||
@@ -152,6 +180,11 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
}
|
||||
} else if (klb.number == 0) {
|
||||
klb.command = din.read();
|
||||
if(klb.command!=0&&klb.command!=1) {
|
||||
klb.sn = din.readLong();
|
||||
}else {
|
||||
klb.sn=0;
|
||||
}
|
||||
switch (klb.command) {
|
||||
case 0:
|
||||
case 1:
|
||||
@@ -160,6 +193,9 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
case 2:
|
||||
klb.lservice = din.readUTF();
|
||||
klb.lipport = new IPPort(din.readUTF());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
klb.cacheused = din.readInt();
|
||||
@@ -180,10 +216,16 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Queue<KLALBBlock> NDsendDeque = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private BlockingDeque<KLALBBlock> sendDeque = new LinkedBlockingDeque<>();
|
||||
public Queue<KLALBBlock> getNDSendDeque() {
|
||||
return NDsendDeque;
|
||||
}
|
||||
|
||||
private Queue<KLALBBlock> sendDeque = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public BlockingDeque<KLALBBlock> getSendDeque() {
|
||||
public Queue<KLALBBlock> getSendDeque() {
|
||||
return sendDeque;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user