forked from KNEMC/KLALB
优化调度算法,避免路由震荡
This commit is contained in:
+31
-13
@@ -14,6 +14,12 @@
|
|||||||
"localaddress" : "127.0.0.1:3389"
|
"localaddress" : "127.0.0.1:3389"
|
||||||
} ],
|
} ],
|
||||||
"tunnels" : [ {
|
"tunnels" : [ {
|
||||||
|
"name" : "Openfrp-直连线路",
|
||||||
|
"remoteaddress" : "127.0.0.1:4566"
|
||||||
|
}, {
|
||||||
|
"name" : "Openfrp-直连线路",
|
||||||
|
"remoteaddress" : "127.0.0.1:4566"
|
||||||
|
},{
|
||||||
"name" : "NULL-宿迁联通",
|
"name" : "NULL-宿迁联通",
|
||||||
"remoteaddress" : "153.36.240.12:65529"
|
"remoteaddress" : "153.36.240.12:65529"
|
||||||
}, {
|
}, {
|
||||||
@@ -29,8 +35,26 @@
|
|||||||
"name" : "Openfrp-美国-8「BGP」",
|
"name" : "Openfrp-美国-8「BGP」",
|
||||||
"remoteaddress" : "us-los-bgp-8.openfrp.top:65529"
|
"remoteaddress" : "us-los-bgp-8.openfrp.top:65529"
|
||||||
}, {
|
}, {
|
||||||
"name" : "Openfrp-新加坡-1「BGP」",
|
"name" : "Sakurafrp-安徽电信-1",
|
||||||
"remoteaddress" : "singa-bgp-2.openfrp.top:65529"
|
"remoteaddress" : "cn-ah-dx-1.natfrp.cloud:65529"
|
||||||
|
}, {
|
||||||
|
"name" : "Sakurafrp-十堰电信-1",
|
||||||
|
"remoteaddress" : "cn-sy-dx-1.natfrp.cloud:65529"
|
||||||
|
}, {
|
||||||
|
"name" : "Sakurafrp-武汉电信-1",
|
||||||
|
"remoteaddress" : "cn-wh-dx-1.natfrp.cloud:65529"
|
||||||
|
}, {
|
||||||
|
"name" : "Sakurafrp-枣庄BGP-10",
|
||||||
|
"remoteaddress" : "cn-zz-bgp-10.natfrp.cloud:23330"
|
||||||
|
}, {
|
||||||
|
"name" : "Sakurafrp-枣庄BGP-7",
|
||||||
|
"remoteaddress" : "cn-zz-bgp-7.natfrp.cloud:33336"
|
||||||
|
}, {
|
||||||
|
"name" : "HYHBX-深圳阿里-1",
|
||||||
|
"remoteaddress" : "119.23.238.91:12413"
|
||||||
|
}, {
|
||||||
|
"name" : "HYHBX-上海腾讯-2",
|
||||||
|
"remoteaddress" : "43.143.109.64:49965"
|
||||||
}, {
|
}, {
|
||||||
"name" : "XYZ-韩国首尔",
|
"name" : "XYZ-韩国首尔",
|
||||||
"remoteaddress" : "frp.104300.xyz:49965"
|
"remoteaddress" : "frp.104300.xyz:49965"
|
||||||
@@ -40,19 +64,13 @@
|
|||||||
}, {
|
}, {
|
||||||
"name" : "aFrps-新加坡",
|
"name" : "aFrps-新加坡",
|
||||||
"remoteaddress" : "sg.afrps.cn:49966"
|
"remoteaddress" : "sg.afrps.cn:49966"
|
||||||
|
}, {
|
||||||
|
"name" : "aFrps-美国芝加哥",
|
||||||
|
"remoteaddress" : "ch.afrps.cn:49966"
|
||||||
}, {
|
}, {
|
||||||
"name" : "aFrps-美国圣何塞",
|
"name" : "aFrps-美国圣何塞",
|
||||||
"remoteaddress" : "sj.afrps.cn:49966"
|
"remoteaddress" : "sj.afrps.cn:49966"
|
||||||
}, {
|
} , {
|
||||||
"name" : "Sakurafrp-安徽电信-1",
|
|
||||||
"remoteaddress" : "cn-ah-dx-1.natfrp.cloud:65529"
|
|
||||||
}, {
|
|
||||||
"name" : "Sakurafrp-十堰电信-1",
|
|
||||||
"remoteaddress" : "cn-sy-dx-1.natfrp.cloud:65529"
|
|
||||||
}, {
|
|
||||||
"name" : "Sakurafrp-武汉电信-1",
|
|
||||||
"remoteaddress" : "cn-wh-dx-1.natfrp.cloud:65529"
|
|
||||||
}, {
|
|
||||||
"name" : "Freefrp-韩国首尔-0",
|
"name" : "Freefrp-韩国首尔-0",
|
||||||
"remoteaddress" : "frp.freefrp.net:49965"
|
"remoteaddress" : "frp.freefrp.net:49965"
|
||||||
}, {
|
}, {
|
||||||
@@ -64,5 +82,5 @@
|
|||||||
}, {
|
}, {
|
||||||
"name" : "Freefrp-韩国首尔-4",
|
"name" : "Freefrp-韩国首尔-4",
|
||||||
"remoteaddress" : "frp4.freefrp.net:49965"
|
"remoteaddress" : "frp4.freefrp.net:49965"
|
||||||
} ]
|
}]
|
||||||
}
|
}
|
||||||
+25
-19
@@ -16,6 +16,9 @@
|
|||||||
"tunnels" : [ {
|
"tunnels" : [ {
|
||||||
"name" : "Openfrp-直连线路",
|
"name" : "Openfrp-直连线路",
|
||||||
"remoteaddress" : "127.0.0.1:4566"
|
"remoteaddress" : "127.0.0.1:4566"
|
||||||
|
}, {
|
||||||
|
"name" : "Openfrp-直连线路",
|
||||||
|
"remoteaddress" : "127.0.0.1:4566"
|
||||||
},{
|
},{
|
||||||
"name" : "NULL-宿迁联通",
|
"name" : "NULL-宿迁联通",
|
||||||
"remoteaddress" : "153.36.240.12:65529"
|
"remoteaddress" : "153.36.240.12:65529"
|
||||||
@@ -31,18 +34,6 @@
|
|||||||
}, {
|
}, {
|
||||||
"name" : "Openfrp-美国-8「BGP」",
|
"name" : "Openfrp-美国-8「BGP」",
|
||||||
"remoteaddress" : "us-los-bgp-8.openfrp.top:65529"
|
"remoteaddress" : "us-los-bgp-8.openfrp.top:65529"
|
||||||
}, {
|
|
||||||
"name" : "XYZ-韩国首尔",
|
|
||||||
"remoteaddress" : "frp.104300.xyz:49965"
|
|
||||||
}, {
|
|
||||||
"name" : "aFrps-美国洛杉矶",
|
|
||||||
"remoteaddress" : "la.afrps.cn:49966"
|
|
||||||
}, {
|
|
||||||
"name" : "aFrps-新加坡",
|
|
||||||
"remoteaddress" : "sg.afrps.cn:49966"
|
|
||||||
}, {
|
|
||||||
"name" : "aFrps-美国圣何塞",
|
|
||||||
"remoteaddress" : "sj.afrps.cn:49966"
|
|
||||||
}, {
|
}, {
|
||||||
"name" : "Sakurafrp-安徽电信-1",
|
"name" : "Sakurafrp-安徽电信-1",
|
||||||
"remoteaddress" : "cn-ah-dx-1.natfrp.cloud:65529"
|
"remoteaddress" : "cn-ah-dx-1.natfrp.cloud:65529"
|
||||||
@@ -59,6 +50,27 @@
|
|||||||
"name" : "Sakurafrp-枣庄BGP-7",
|
"name" : "Sakurafrp-枣庄BGP-7",
|
||||||
"remoteaddress" : "cn-zz-bgp-7.natfrp.cloud:33336"
|
"remoteaddress" : "cn-zz-bgp-7.natfrp.cloud:33336"
|
||||||
}, {
|
}, {
|
||||||
|
"name" : "HYHBX-深圳阿里-1",
|
||||||
|
"remoteaddress" : "119.23.238.91:12413"
|
||||||
|
}, {
|
||||||
|
"name" : "HYHBX-上海腾讯-2",
|
||||||
|
"remoteaddress" : "43.143.109.64:49965"
|
||||||
|
}, {
|
||||||
|
"name" : "XYZ-韩国首尔",
|
||||||
|
"remoteaddress" : "frp.104300.xyz:49965"
|
||||||
|
}, {
|
||||||
|
"name" : "aFrps-美国洛杉矶",
|
||||||
|
"remoteaddress" : "la.afrps.cn:49966"
|
||||||
|
}, {
|
||||||
|
"name" : "aFrps-新加坡",
|
||||||
|
"remoteaddress" : "sg.afrps.cn:49966"
|
||||||
|
}, {
|
||||||
|
"name" : "aFrps-美国芝加哥",
|
||||||
|
"remoteaddress" : "ch.afrps.cn:49966"
|
||||||
|
}, {
|
||||||
|
"name" : "aFrps-美国圣何塞",
|
||||||
|
"remoteaddress" : "sj.afrps.cn:49966"
|
||||||
|
} , {
|
||||||
"name" : "Freefrp-韩国首尔-0",
|
"name" : "Freefrp-韩国首尔-0",
|
||||||
"remoteaddress" : "frp.freefrp.net:49965"
|
"remoteaddress" : "frp.freefrp.net:49965"
|
||||||
}, {
|
}, {
|
||||||
@@ -70,11 +82,5 @@
|
|||||||
}, {
|
}, {
|
||||||
"name" : "Freefrp-韩国首尔-4",
|
"name" : "Freefrp-韩国首尔-4",
|
||||||
"remoteaddress" : "frp4.freefrp.net:49965"
|
"remoteaddress" : "frp4.freefrp.net:49965"
|
||||||
}, {
|
}]
|
||||||
"name" : "HYHBX-深圳阿里-1",
|
|
||||||
"remoteaddress" : "119.23.238.91:49965"
|
|
||||||
}, {
|
|
||||||
"name" : "HYHBX-上海腾讯-2",
|
|
||||||
"remoteaddress" : "43.143.109.64:49965"
|
|
||||||
} ]
|
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
@@ -1,8 +1,8 @@
|
|||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
public class Consts {
|
public class Consts {
|
||||||
public static final int BLOCKSIZE=32768;
|
public static final int BLOCKSIZE=16384;
|
||||||
public static final long PINGTIMENS=2000000000L;
|
public static final long PINGTIMENS=1000000000L;
|
||||||
public static final double A = 0.125;
|
public static final double A = 0.125;
|
||||||
public static final int SO_TIMEOUT = 20000;
|
public static final int SO_TIMEOUT = 20000;
|
||||||
public static final long SN_KEEP = 60000000000L;
|
public static final long SN_KEEP = 60000000000L;
|
||||||
|
|||||||
@@ -9,9 +9,13 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.concurrent.BlockingDeque;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.kne.cloud.network.mport.ServiceElement;
|
import org.kne.cloud.network.mport.ServiceElement;
|
||||||
@@ -168,6 +172,15 @@ public class IOThreadManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
klc.getRemotetcps().remove(tc);
|
klc.getRemotetcps().remove(tc);
|
||||||
|
Queue<KLALBBlock> sq=tc.getSendDeque();
|
||||||
|
KLALBBlock tmp;
|
||||||
|
while((tmp=sq.poll())!=null) {
|
||||||
|
try {
|
||||||
|
klc.submitDataBlock(tmp);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class KLALBBlock implements Comparable<KLALBBlock>{
|
|||||||
private static AtomicLong sng=new AtomicLong(1);
|
private static AtomicLong sng=new AtomicLong(1);
|
||||||
|
|
||||||
public long sn;//每个数据包的唯一编号
|
public long sn;//每个数据包的唯一编号
|
||||||
public long cuid;//用于识别数据包的stream ID号
|
public int cuid;//用于识别数据包的stream ID号
|
||||||
public long number;//数据包的编号,用于排序
|
public long number;//数据包的编号,用于排序
|
||||||
public byte[]data;//数据内容
|
public byte[]data;//数据内容
|
||||||
public int command;//功能标记 0=PING 1=PONG 2=SYN 3=RST
|
public int command;//功能标记 0=PING 1=PONG 2=SYN 3=RST
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class KLALBClientGUI extends XFrame {
|
|||||||
for (Iterator<ServiceElement> iterator = lse.iterator(); iterator.hasNext();) {
|
for (Iterator<ServiceElement> iterator = lse.iterator(); iterator.hasNext();) {
|
||||||
ServiceElement serviceElement = (ServiceElement) iterator.next();
|
ServiceElement serviceElement = (ServiceElement) iterator.next();
|
||||||
ProxyIPPortProperties pippp = new ProxyIPPortProperties(pdis, serviceElement.name,
|
ProxyIPPortProperties pippp = new ProxyIPPortProperties(pdis, serviceElement.name,
|
||||||
"127.0.0.1", serviceElement.ipport.getPort());
|
"0.0.0.0", serviceElement.ipport.getPort());
|
||||||
try {
|
try {
|
||||||
kc.open(pippp.getBindPort(), serviceElement, pippp.getBindIP());
|
kc.open(pippp.getBindPort(), serviceElement, pippp.getBindIP());
|
||||||
} catch (BindException e) {
|
} catch (BindException e) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.util.concurrent.ArrayBlockingQueue;
|
|||||||
import java.util.concurrent.BlockingDeque;
|
import java.util.concurrent.BlockingDeque;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
@@ -37,7 +38,7 @@ import org.kne.cloud.network.mport.ThreadTool;
|
|||||||
public class KLALBCore {
|
public class KLALBCore {
|
||||||
private volatile int cacheblocks;
|
private volatile int cacheblocks;
|
||||||
|
|
||||||
private Map<Long,LocalTCPConnection> localtcps = new ConcurrentHashMap<>();
|
private Map<Integer, LocalTCPConnection> localtcps = new ConcurrentHashMap<>();
|
||||||
private List<RemoteTCPConnection> remotetcps = new Vector<>();
|
private List<RemoteTCPConnection> remotetcps = new Vector<>();
|
||||||
private Predicate<KLALBBlock>acceptSYN;
|
private Predicate<KLALBBlock>acceptSYN;
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ public class KLALBCore {
|
|||||||
this.acceptSYN = acceptSYN;
|
this.acceptSYN = acceptSYN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Long, LocalTCPConnection> getLocaltcps() {
|
public Map<Integer, LocalTCPConnection> getLocaltcps() {
|
||||||
return localtcps;
|
return localtcps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,21 +104,28 @@ public class KLALBCore {
|
|||||||
pdb.pingtime=System.nanoTime();
|
pdb.pingtime=System.nanoTime();
|
||||||
tc.sendBlock(pdb);
|
tc.sendBlock(pdb);
|
||||||
}
|
}
|
||||||
if(!tc.getSendDeque().isEmpty())
|
if(!tc.getNDSendDeque().isEmpty()||!tc.getSendDeque().isEmpty())
|
||||||
break;
|
break;
|
||||||
Thread.sleep(1);
|
synchronized (tc.getSendDeque()) {
|
||||||
|
tc.getSendDeque().wait(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
KLALBBlock k0=tc.getNDSendDeque().poll();
|
||||||
|
if(k0!=null) {
|
||||||
|
tc.sendBlock(k0,tc.getNDSendDeque().isEmpty());
|
||||||
|
}else {
|
||||||
KLALBBlock k=tc.getSendDeque().poll();
|
KLALBBlock k=tc.getSendDeque().poll();
|
||||||
if(k!=null) {
|
if(k!=null) {
|
||||||
//if(localtcps.containsKey(k.cuid)||k.cuid.equals(ZERO_UUID))
|
//if(localtcps.containsKey(k.cuid)||k.cuid.equals(ZERO_UUID))
|
||||||
tc.sendBlock(k);
|
tc.sendBlock(k,tc.getSendDeque().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void remoteReceive(RemoteTCPConnection tc) throws IOException {
|
public void remoteReceive(RemoteTCPConnection tc) throws IOException {
|
||||||
KLALBBlock brc=null;
|
KLALBBlock brc=null;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
brc=tc.receiveBlock();
|
brc=tc.receiveBlock();
|
||||||
if(brc.number!=0) {
|
if(brc.number!=0||brc.sn==0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SN s=new SN(brc.sn);
|
SN s=new SN(brc.sn);
|
||||||
@@ -148,11 +156,11 @@ public class KLALBCore {
|
|||||||
pdb.number=0;
|
pdb.number=0;
|
||||||
pdb.command=1;
|
pdb.command=1;
|
||||||
pdb.pingtime=brc.pingtime;
|
pdb.pingtime=brc.pingtime;
|
||||||
tc.getSendDeque().addFirst(pdb);
|
tc.getNDSendDeque().offer(pdb);
|
||||||
}else if(brc.command==1) {
|
}else if(brc.command==1) {
|
||||||
long cur=System.nanoTime();
|
long cur=System.nanoTime();
|
||||||
long delay=(cur-brc.pingtime)/2;
|
long delay=(cur-brc.pingtime)/2;
|
||||||
tc.setDelay(delay);
|
tc.setDelayAvg(delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
@@ -215,11 +223,15 @@ public class KLALBCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//System.out.println(remotetcps);
|
||||||
for (Iterator<RemoteTCPConnection> iterator = remotetcps.iterator(); iterator.hasNext();) {
|
for (Iterator<RemoteTCPConnection> iterator = remotetcps.iterator(); iterator.hasNext();) {
|
||||||
RemoteTCPConnection remoteTCPConnection = (RemoteTCPConnection) iterator.next();
|
RemoteTCPConnection remoteTCPConnection = (RemoteTCPConnection) iterator.next();
|
||||||
BlockingDeque<KLALBBlock> bdq=remoteTCPConnection.getSendDeque();
|
Queue<KLALBBlock> bdq=remoteTCPConnection.getSendDeque();
|
||||||
if(bdq.size()<2) {
|
if(bdq.size()<1) {
|
||||||
bdq.add(kb);
|
bdq.add(kb);
|
||||||
|
synchronized (bdq) {
|
||||||
|
bdq.notifyAll();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,7 +244,11 @@ public class KLALBCore {
|
|||||||
synchronized (remotetcps) {
|
synchronized (remotetcps) {
|
||||||
for (Iterator<RemoteTCPConnection> iterator = remotetcps.iterator(); iterator.hasNext();) {
|
for (Iterator<RemoteTCPConnection> iterator = remotetcps.iterator(); iterator.hasNext();) {
|
||||||
RemoteTCPConnection rmt = (RemoteTCPConnection) iterator.next();
|
RemoteTCPConnection rmt = (RemoteTCPConnection) iterator.next();
|
||||||
rmt.getSendDeque().addFirst(kb);
|
Queue<KLALBBlock> sq = rmt.getNDSendDeque();
|
||||||
|
sq.offer(kb);
|
||||||
|
synchronized (sq) {
|
||||||
|
sq.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,16 @@ import java.net.Socket;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.BlockingDeque;
|
import java.util.concurrent.BlockingDeque;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.kne.cloud.network.mport.ServiceElement;
|
import org.kne.cloud.network.mport.ServiceElement;
|
||||||
|
|
||||||
public class LocalTCPConnection extends TCPConnection {
|
public class LocalTCPConnection extends TCPConnection {
|
||||||
private static AtomicLong sng=new AtomicLong(1);
|
private static AtomicInteger sng=new AtomicInteger(1);
|
||||||
|
|
||||||
private long cuid;
|
private int cuid;
|
||||||
private ServiceElement serviceElement;
|
private ServiceElement serviceElement;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,14 +27,14 @@ private volatile long outputcount = 1;
|
|||||||
super(s);
|
super(s);
|
||||||
cuid=sng.getAndIncrement();
|
cuid=sng.getAndIncrement();
|
||||||
}
|
}
|
||||||
public LocalTCPConnection(Socket s,long uid) throws IOException {
|
public LocalTCPConnection(Socket s,int uid) throws IOException {
|
||||||
super(s);
|
super(s);
|
||||||
cuid=uid;
|
cuid=uid;
|
||||||
}
|
}
|
||||||
public long getCuid() {
|
public int getCuid() {
|
||||||
return cuid;
|
return cuid;
|
||||||
}
|
}
|
||||||
public void setCuid(long cuid) {
|
public void setCuid(int cuid) {
|
||||||
this.cuid = cuid;
|
this.cuid = cuid;
|
||||||
}
|
}
|
||||||
public ServiceElement getServiceElement() {
|
public ServiceElement getServiceElement() {
|
||||||
|
|||||||
@@ -10,9 +10,13 @@ import java.io.OutputStream;
|
|||||||
import java.io.StreamCorruptedException;
|
import java.io.StreamCorruptedException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.BlockingDeque;
|
import java.util.concurrent.BlockingDeque;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
@@ -54,10 +58,15 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dout = new DataOutputStream(new AddOutputStream(new BufferedOutputStream(outm)) );
|
dout = new DataOutputStream(new BufferedOutputStream(outm,Consts.BLOCKSIZE*2+1) );
|
||||||
din = new DataInputStream(new AddInputStream(new BufferedInputStream(inm)));
|
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 {
|
public RemoteTCPConnection(Tunnel t, Socket s) throws UnknownHostException, IOException {
|
||||||
super(s);
|
super(s);
|
||||||
tunnel=t;
|
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
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (tunnel != null) {
|
if (tunnel != null) {
|
||||||
@@ -103,20 +122,27 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
}
|
}
|
||||||
super.finalize();
|
super.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendBlock(KLALBBlock data) throws IOException {
|
public void sendBlock(KLALBBlock data) throws IOException {
|
||||||
dout.writeLong(data.sn);
|
sendBlock(data,true);
|
||||||
dout.writeLong(data.cuid);
|
}
|
||||||
|
public void sendBlock(KLALBBlock data,boolean isflush) throws IOException {
|
||||||
|
|
||||||
|
dout.writeInt(data.cuid);
|
||||||
dout.writeLong(data.number);
|
dout.writeLong(data.number);
|
||||||
if (data.number > 0) {
|
if (data.number > 0) {
|
||||||
if (data.data == null) {
|
if (data.data == null) {
|
||||||
dout.writeInt(-1);
|
dout.writeShort(-1);
|
||||||
} else {
|
} else {
|
||||||
dout.writeInt(data.data.length);
|
dout.writeShort(data.data.length);
|
||||||
dout.write(data.data);
|
dout.write(data.data);
|
||||||
}
|
}
|
||||||
} else if (data.number == 0) {
|
} else if (data.number == 0) {
|
||||||
dout.write(data.command);
|
dout.write(data.command);
|
||||||
|
if(data.command!=0&&data.command!=1) {
|
||||||
|
dout.writeLong(data.sn);
|
||||||
|
}else {
|
||||||
|
|
||||||
|
}
|
||||||
switch (data.command) {
|
switch (data.command) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
@@ -126,11 +152,14 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
dout.writeUTF(data.lservice);
|
dout.writeUTF(data.lservice);
|
||||||
dout.writeUTF(data.lipport.toString());
|
dout.writeUTF(data.lipport.toString());
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dout.writeInt(data.cacheused);
|
dout.writeInt(data.cacheused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isflush)
|
||||||
dout.flush();
|
dout.flush();
|
||||||
|
|
||||||
//System.out.println("SEND:" + data);
|
//System.out.println("SEND:" + data);
|
||||||
@@ -138,11 +167,10 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
|
|
||||||
public KLALBBlock receiveBlock() throws IOException {
|
public KLALBBlock receiveBlock() throws IOException {
|
||||||
KLALBBlock klb = new KLALBBlock();
|
KLALBBlock klb = new KLALBBlock();
|
||||||
klb.sn = din.readLong();
|
klb.cuid = din.readInt();
|
||||||
klb.cuid = din.readLong();
|
|
||||||
klb.number = din.readLong();
|
klb.number = din.readLong();
|
||||||
if (klb.number > 0) {
|
if (klb.number > 0) {
|
||||||
int size = din.readInt();
|
int size = din.readShort();
|
||||||
if (size == -1) {
|
if (size == -1) {
|
||||||
klb.data = null;
|
klb.data = null;
|
||||||
} else {
|
} else {
|
||||||
@@ -152,6 +180,11 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
}
|
}
|
||||||
} else if (klb.number == 0) {
|
} else if (klb.number == 0) {
|
||||||
klb.command = din.read();
|
klb.command = din.read();
|
||||||
|
if(klb.command!=0&&klb.command!=1) {
|
||||||
|
klb.sn = din.readLong();
|
||||||
|
}else {
|
||||||
|
klb.sn=0;
|
||||||
|
}
|
||||||
switch (klb.command) {
|
switch (klb.command) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
@@ -160,6 +193,9 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
case 2:
|
case 2:
|
||||||
klb.lservice = din.readUTF();
|
klb.lservice = din.readUTF();
|
||||||
klb.lipport = new IPPort(din.readUTF());
|
klb.lipport = new IPPort(din.readUTF());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
klb.cacheused = din.readInt();
|
klb.cacheused = din.readInt();
|
||||||
@@ -180,10 +216,16 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
return false;
|
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;
|
return sendDeque;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@@ -83,7 +85,7 @@ public class Tunnel{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getName()+"$"+getIpport();
|
return getName()+"$"+getIpport()+" "+delay/1000000;
|
||||||
}
|
}
|
||||||
public Socket connectClientSocket() throws UnknownHostException, IOException {
|
public Socket connectClientSocket() throws UnknownHostException, IOException {
|
||||||
Socket socket=new Socket();
|
Socket socket=new Socket();
|
||||||
@@ -138,8 +140,21 @@ public class Tunnel{
|
|||||||
public AtomicLong getIM() {
|
public AtomicLong getIM() {
|
||||||
return im;
|
return im;
|
||||||
}
|
}
|
||||||
|
PrintStream ndbg=null;
|
||||||
|
private void initcdbg() {
|
||||||
|
try {
|
||||||
|
ndbg=new PrintStream(name+".csv");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
public void updateTraffics(long timems) {
|
public void updateTraffics(long timems) {
|
||||||
tlr.setTraffic(om.get(), im.get(), om.get()-om1, im.get()-im1);
|
tlr.setTraffic(om.get(), im.get(), om.get()-om1, im.get()-im1);
|
||||||
|
|
||||||
|
if(ndbg==null)
|
||||||
|
initcdbg();
|
||||||
|
ndbg.println((om.get()-om1)+ (im.get()-im1)+","+delay);
|
||||||
|
|
||||||
om1=om.get();
|
om1=om.get();
|
||||||
im1=im.get();
|
im1=im.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,25 @@
|
|||||||
package org.kne.cloud.network.mport;
|
package org.kne.cloud.network.mport;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ThreadTool {
|
public class ThreadTool {
|
||||||
public static boolean first=true;
|
public static boolean first=true;
|
||||||
public static boolean forceD=false;
|
public static boolean forceD=false;
|
||||||
public static Thread makeVThreadIfSupport(String name,Runnable r) {
|
public static Thread makeVThreadIfSupport(String name,Runnable r) {
|
||||||
if(forceD)
|
if(forceD)
|
||||||
return new Thread(r, name);
|
return new Thread(r, name);
|
||||||
try { return new Thread(r, name);
|
try { //return new Thread(r, name);
|
||||||
|
Class<?> c=Class.forName("java.lang.Thread");
|
||||||
|
Method m= c.getDeclaredMethod("ofVirtual", null);
|
||||||
|
Object o=m.invoke(null, null);
|
||||||
|
Class<?> cb=Class.forName("java.lang.Thread$Builder");
|
||||||
|
Method mn= cb.getDeclaredMethod("name", String.class);
|
||||||
|
mn.invoke(o, name);
|
||||||
|
Method mu= cb.getDeclaredMethod("unstarted", Runnable.class);
|
||||||
|
return (Thread) mu.invoke(o, r);
|
||||||
//return Thread.ofVirtual().name(name).unstarted(r);
|
//return Thread.ofVirtual().name(name).unstarted(r);
|
||||||
}catch(Throwable e) {
|
}catch(Throwable e) {
|
||||||
|
//e.printStackTrace();
|
||||||
if(first) {
|
if(first) {
|
||||||
System.out.println("请使用java19以上版本以提高性能!");
|
System.out.println("请使用java19以上版本以提高性能!");
|
||||||
first=false;
|
first=false;
|
||||||
|
|||||||
@@ -568,5 +568,6 @@ public class XFrame extends JFrame {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import java.awt.event.ComponentEvent;
|
|||||||
import java.awt.event.ComponentListener;
|
import java.awt.event.ComponentListener;
|
||||||
import java.awt.event.ContainerEvent;
|
import java.awt.event.ContainerEvent;
|
||||||
import java.awt.event.ContainerListener;
|
import java.awt.event.ContainerListener;
|
||||||
|
import java.awt.event.MouseWheelEvent;
|
||||||
|
import java.awt.event.MouseWheelListener;
|
||||||
|
|
||||||
import javax.swing.JScrollBar;
|
import javax.swing.JScrollBar;
|
||||||
|
|
||||||
public class YScrollPane extends JPanel {
|
public class YScrollPane extends JPanel {
|
||||||
@@ -109,6 +112,14 @@ settings.addContainerListener(new ContainerListener() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
settings.addMouseWheelListener(new MouseWheelListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
|
int x=e.getWheelRotation()*20;
|
||||||
|
scrollBar.setValue(scrollBar.getValue()+x);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getView() {
|
public JPanel getView() {
|
||||||
|
|||||||
Reference in New Issue
Block a user