增加流量控制

增加自动按延迟选择线路
This commit is contained in:
Administrator
2022-12-14 17:27:04 +08:00
parent 5d7324db0e
commit e93a5815b4
10 changed files with 431 additions and 71 deletions
@@ -10,46 +10,55 @@ import java.util.concurrent.LinkedBlockingDeque;
import org.kne.cloud.network.mport.IPPort;
public class RemoteTCPConnection extends TCPConnection {
public RemoteTCPConnection(Tunnel t) throws UnknownHostException, IOException {
this(t,t.connectClientSocket());
this(t, t.connectClientSocket());
}
public RemoteTCPConnection(Tunnel t,Socket s) throws UnknownHostException, IOException {
public RemoteTCPConnection(Tunnel t, Socket s) throws UnknownHostException, IOException {
super(s);
this.tunnel=t;
this.tunnel = t;
s.setSoTimeout(Consts.SO_TIMEOUT);
}
private long delay=-1;
private long delay = Long.MAX_VALUE;
private Tunnel tunnel;
public Tunnel getTunnel() {
return tunnel;
}
public void setTunnel(Tunnel tunnel) {
this.tunnel = tunnel;
}
public long getDelay() {
return delay;
}
public void setDelay(long delay) {
this.delay = delay;
if(tunnel!=null) {
if (tunnel != null) {
tunnel.setDelay(delay);
}
}
public void sendBlock(KLALBBlock data) throws IOException {
dout.writeLong(data.sn);
dout.writeLong(data.cuid.getMostSignificantBits());
dout.writeLong(data.cuid.getLeastSignificantBits());
dout.writeLong(data.number);
if(data.number>0) {
dout.writeInt(data.data.length);
dout.write(data.data);
}else if(data.number==0) {
if (data.number > 0) {
if (data.data == null) {
dout.writeInt(-1);
} else {
dout.writeInt(data.data.length);
dout.write(data.data);
}
} else if (data.number == 0) {
dout.write(data.command);
switch(data.command) {
switch (data.command) {
case 0:
case 1:
dout.writeLong(data.pingtime);
@@ -59,51 +68,62 @@ public class RemoteTCPConnection extends TCPConnection {
dout.writeUTF(data.lipport.toString());
break;
}
} else {
dout.writeInt(data.cacheused);
}
dout.flush();
System.out.println("SEND:"+data);
System.out.println("SEND:" + data);
}
public KLALBBlock receiveBlock() throws IOException {
KLALBBlock klb=new KLALBBlock();
klb.sn=din.readLong();
klb.cuid=new UUID(din.readLong(), din.readLong());
klb.number=din.readLong();
if(klb.number>0) {
int size=din.readInt();
byte[]d=new byte[size];
din.readFully(d);
klb.data=d;
}else if(klb.number==0) {
klb.command=din.read();
switch(klb.command) {
KLALBBlock klb = new KLALBBlock();
klb.sn = din.readLong();
klb.cuid = new UUID(din.readLong(), din.readLong());
klb.number = din.readLong();
if (klb.number > 0) {
int size = din.readInt();
if (size == -1) {
klb.data = null;
} else {
byte[] d = new byte[size];
din.readFully(d);
klb.data = d;
}
} else if (klb.number == 0) {
klb.command = din.read();
switch (klb.command) {
case 0:
case 1:
klb.pingtime=din.readLong();
klb.pingtime = din.readLong();
break;
case 2:
klb.lservice=din.readUTF();
klb.lipport=new IPPort(din.readUTF());
klb.lservice = din.readUTF();
klb.lipport = new IPPort(din.readUTF());
}
} else {
klb.cacheused = din.readInt();
}
System.out.println("RECEIVE:"+klb);
System.out.println("RECEIVE:" + klb);
return klb;
}
private volatile long time=System.nanoTime();
private volatile long time = System.nanoTime();
public boolean checkPingTime() {
long cu=System.nanoTime();
if(cu-time>Consts.PINGTIMENS) {
time=cu;
long cu = System.nanoTime();
if (cu - time > Consts.PINGTIMENS) {
time = cu;
return true;
}else {
} else {
return false;
}
}
private BlockingDeque<KLALBBlock>sendDeque=new LinkedBlockingDeque<>();
private BlockingDeque<KLALBBlock> sendDeque = new LinkedBlockingDeque<>();
public BlockingDeque<KLALBBlock> getSendDeque() {
return sendDeque;
}