forked from KNEMC/KLALB
提高性能
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
public class Consts {
|
||||
public static final int BLOCKSIZE=32768;
|
||||
public static final long PINGTIMENS=1000000000;
|
||||
public static final int BLOCKSIZE=65536;
|
||||
public static final long PINGTIMENS=10000000000L;
|
||||
public static final double A = 0.125;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ import java.net.SocketException;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.kne.cloud.network.mport.ThreadTool;
|
||||
|
||||
public class IOThreadManager {
|
||||
private KLALBCore klc=new KLALBCore(200);
|
||||
private KLALBCore klc=new KLALBCore(10000);
|
||||
private List<TCPConnection>tcps=new Vector<>();
|
||||
|
||||
|
||||
@@ -48,7 +50,6 @@ public class IOThreadManager {
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
closeRemote();
|
||||
}
|
||||
});
|
||||
upo.start();
|
||||
@@ -60,11 +61,16 @@ public class IOThreadManager {
|
||||
Thread up=ThreadTool.makeVThreadIfSupport("远程发送线程",()->{
|
||||
try{
|
||||
while(true) {
|
||||
if(s.getTunnel().getName().contains("Openfrp")) {
|
||||
klc.sendDataBlockControlOnly(s);
|
||||
}else {
|
||||
klc.sendDataBlock(s);
|
||||
}
|
||||
}
|
||||
}catch(InterruptedException s1) {
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
Thread down=ThreadTool.makeVThreadIfSupport("远程接收线程",()->{
|
||||
@@ -76,6 +82,7 @@ public class IOThreadManager {
|
||||
|
||||
}catch(Exception e) {
|
||||
up.interrupt();
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class IPPort implements Serializable{
|
||||
private InetAddress ip;
|
||||
private int port;
|
||||
public IPPort(String ipport) throws UnknownHostException {
|
||||
int index =ipport.lastIndexOf(":");
|
||||
ip=InetAddress.getByName( ipport.substring(0,index));
|
||||
port=Integer.parseInt(ipport.substring(index+1));
|
||||
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(ip, port);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
IPPort other = (IPPort) obj;
|
||||
return Objects.equals(ip, other.ip) && port == other.port;
|
||||
}
|
||||
public IPPort(String ip2, int port2) throws UnknownHostException {
|
||||
ip=InetAddress.getByName(ip2);
|
||||
port=port2;
|
||||
}
|
||||
public IPPort(InetSocketAddress remoteSocketAddress) {
|
||||
ip=remoteSocketAddress.getAddress();
|
||||
port=remoteSocketAddress.getPort();
|
||||
}
|
||||
public InetAddress getIp() {
|
||||
return ip;
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
if(ip instanceof Inet6Address) {
|
||||
return "["+ip.getHostAddress()+"]:"+port;
|
||||
}
|
||||
return ip.getHostAddress()+":"+port;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class KLALBBlock {
|
||||
|
||||
|
||||
volatile long time=-1;
|
||||
volatile Thread thread;
|
||||
volatile TCPConnection connect;
|
||||
public KLALBBlock(byte[] b, int size,long number) {
|
||||
data=b;
|
||||
this.size=size;
|
||||
|
||||
@@ -16,7 +16,28 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.kne.cloud.network.mport.IPPort;
|
||||
import org.kne.cloud.network.mport.ServiceElement;
|
||||
import org.kne.cloud.network.mport.ThreadTool;
|
||||
|
||||
public class KLALBClient {
|
||||
private static Object olock=new Object();
|
||||
static {
|
||||
new Thread(()->{
|
||||
while(true) {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
synchronized(olock) {
|
||||
olock.notifyAll();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private List<Tunnel> tls=new ArrayList<>();
|
||||
private TCPListener tcpl;
|
||||
private ServiceElement sel;
|
||||
@@ -45,8 +66,14 @@ public class KLALBClient {
|
||||
tc.getDout().flush();
|
||||
aig.incrementAndGet();
|
||||
System.out.println("隧道"+tll+"已连接,可用线路数量:"+ (kcp.getTcps().size()+1));
|
||||
try {
|
||||
kcp.handleSocket(tc);
|
||||
tc.close();
|
||||
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
tc.close();
|
||||
}
|
||||
int n=kcp.getTcps().size();
|
||||
System.out.println("隧道"+tll+"已断开,可用线路数量:"+ n);
|
||||
if(n<=0) {
|
||||
@@ -67,10 +94,12 @@ public class KLALBClient {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
synchronized(olock) {
|
||||
try {
|
||||
olock.wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@@ -123,7 +152,7 @@ public class KLALBClient {
|
||||
}
|
||||
int s2=tcpc.getDin().readInt();
|
||||
System.out.println("隧道列表:");
|
||||
for (int i = 0; i < s2; i++) {
|
||||
for (int i = 0; i < s2; i++) {
|
||||
String str=tcpc.getDin().readUTF();
|
||||
System.out.println(str);
|
||||
tls.add(Tunnel.newTunnel(str));
|
||||
@@ -157,6 +186,7 @@ public class KLALBClient {
|
||||
kc.setSel(kc.getServices().get(scn.nextInt()));
|
||||
System.out.println("请输入你要映射的本地端口:");
|
||||
kc.open(scn.nextInt());
|
||||
System.out.println("服务已开启");
|
||||
while(true) {
|
||||
String s=scn.next();
|
||||
switch(s) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -25,13 +26,15 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.kne.cloud.network.mport.ThreadTool;
|
||||
|
||||
public class KLALBCore {
|
||||
private volatile long inputcount = 1;
|
||||
private volatile long outputcount = 1;
|
||||
private Set<KLALBBlock> inputcache = Collections.synchronizedSet(new HashSet<>());
|
||||
private List<KLALBBlock> outputcache = Collections.synchronizedList(new ArrayList<>());
|
||||
private List<KLALBBlock> outputcache = new Vector<>();
|
||||
|
||||
//private Map<TCPConnection, BlockingQueue<KLALBBlock>>acks=Collections.synchronizedMap(new WeakHashMap<>());
|
||||
private BlockingQueue<KLALBBlock> ackp=new LinkedBlockingQueue<>();
|
||||
private BlockingQueue<KLALBBlock> ackq=new LinkedBlockingQueue<>();
|
||||
private volatile boolean inlocal=true;
|
||||
|
||||
@@ -47,7 +50,7 @@ public class KLALBCore {
|
||||
|
||||
if (closelocal)
|
||||
throw new InterruptedException();
|
||||
while (outputcache.size() > cacheblocks) {
|
||||
while (!outputcache.isEmpty()&&(outputcount-outputcache.get(0).number>cacheblocks)) {
|
||||
if (closelocal)
|
||||
Thread.currentThread().interrupt();
|
||||
Thread.sleep(1);
|
||||
@@ -76,13 +79,14 @@ public class KLALBCore {
|
||||
}
|
||||
}
|
||||
if (b != null) {
|
||||
System.out.println("\tPROCESS:" + inputcache.size());
|
||||
System.out.println("\tSORT:"+inputcount+" " + inputcache.size());
|
||||
inputcount++;
|
||||
return b;
|
||||
}
|
||||
if (closelocal)
|
||||
Thread.currentThread().interrupt();
|
||||
Thread.sleep(1);
|
||||
//System.err.println(inputcount);
|
||||
|
||||
}
|
||||
}finally {
|
||||
@@ -90,6 +94,17 @@ public class KLALBCore {
|
||||
}
|
||||
}
|
||||
|
||||
private void makeAck(KLALBBlock klalbBlock) {
|
||||
KLALBBlock klb1=new KLALBBlock(null, 0, -klalbBlock.number);
|
||||
klb1.time=klalbBlock.time;
|
||||
ackq.add(klb1);
|
||||
if(ackp.size()<100) {
|
||||
KLALBBlock klb2=new KLALBBlock(null, 0, -klalbBlock.number);
|
||||
klb2.time=klalbBlock.time;
|
||||
ackp.add(klb2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendDataBlock(TCPConnection out) throws IOException, InterruptedException {
|
||||
if (closeremote)
|
||||
@@ -112,24 +127,24 @@ public class KLALBCore {
|
||||
for (int i = 0; i < outputcache.size(); i++) {
|
||||
|
||||
KLALBBlock kd = outputcache.get(i);
|
||||
if (kd.thread == null) {
|
||||
if (kd.connect == null) {
|
||||
kd.time = System.nanoTime();
|
||||
kd.thread = Thread.currentThread();
|
||||
kd.connect = out;
|
||||
ks = kd;
|
||||
} else {
|
||||
if (kd.thread.isAlive()) {
|
||||
if (kd.connect.isOpen()) {
|
||||
long timex = (System.nanoTime() - kd.time) / 1000000;
|
||||
if (timex > 200000) {
|
||||
System.out.println("³¬Ê±ÖØ´«£º"+kd);
|
||||
if (timex > 100+1000*i) {
|
||||
kd.time = System.nanoTime();
|
||||
kd.thread = Thread.currentThread();
|
||||
kd.connect = out;
|
||||
ks = kd;
|
||||
System.out.println("³¬Ê±ÖØ´«£º"+kd);
|
||||
}
|
||||
} else {
|
||||
System.out.println("µôÏßÖØ´«£º"+kd);
|
||||
kd.time = System.nanoTime();
|
||||
kd.thread = Thread.currentThread();
|
||||
kd.connect = out;
|
||||
ks = kd;
|
||||
System.out.println("µôÏßÖØ´«£º"+kd);
|
||||
}
|
||||
}
|
||||
if (ks != null) {
|
||||
@@ -139,7 +154,7 @@ public class KLALBCore {
|
||||
}
|
||||
if (ks != null) {
|
||||
send0(out, ks);
|
||||
// System.out.println(outputcache.size());
|
||||
ks.time = System.nanoTime();
|
||||
}else {
|
||||
Thread.sleep(1);
|
||||
}
|
||||
@@ -149,19 +164,36 @@ public class KLALBCore {
|
||||
send0(out, new KLALBBlock(null,0 , 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendDataBlockControlOnly(TCPConnection out) throws IOException, InterruptedException {
|
||||
if (closeremote)
|
||||
throw new InterruptedException();
|
||||
//BlockingQueue<KLALBBlock> bqk=acks.get(out);
|
||||
while (ackp.isEmpty()) {
|
||||
if (closeremote)
|
||||
Thread.currentThread().interrupt();
|
||||
Thread.sleep(1);
|
||||
if(out.checkPingTime()) {
|
||||
send0(out, new KLALBBlock(null,0 , 0));
|
||||
}
|
||||
}
|
||||
KLALBBlock klb=ackp.poll();
|
||||
if(klb!=null) {
|
||||
send0(out, klb);
|
||||
//System.out.println(klb+" "+ackp.size());
|
||||
}
|
||||
if(out.checkPingTime()) {
|
||||
send0(out, new KLALBBlock(null,0 , 0));
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveDataBlock(TCPConnection in) throws IOException, InterruptedException {
|
||||
if (closeremote)
|
||||
throw new InterruptedException();
|
||||
KLALBBlock x = receive0(in);
|
||||
long rect=System.nanoTime();
|
||||
if (x.number > 0) {
|
||||
|
||||
KLALBBlock klb=new KLALBBlock(null, 0, -x.number);
|
||||
ackq.add(klb);
|
||||
|
||||
klb=new KLALBBlock(null, 0, -x.number);
|
||||
ackq.add(klb);
|
||||
|
||||
/*BlockingQueue<KLALBBlock> bq=acks.get(in);
|
||||
if(bq==null) {
|
||||
BlockingQueue<KLALBBlock> bqt=new LinkedBlockingQueue<>();
|
||||
@@ -171,7 +203,6 @@ public class KLALBCore {
|
||||
acks.get(in).add(klb);
|
||||
}*/
|
||||
|
||||
|
||||
if (x.number >= inputcount) {
|
||||
|
||||
while(inputcache.size()>(2*cacheblocks)&&inlocal) {
|
||||
@@ -181,7 +212,8 @@ public class KLALBCore {
|
||||
}
|
||||
|
||||
inputcache.add(x);
|
||||
}
|
||||
}
|
||||
makeAck(x);
|
||||
|
||||
} else if(x.number==0) {
|
||||
ThreadTool.makeVThreadIfSupport("TACK", ()->{
|
||||
@@ -192,7 +224,6 @@ public class KLALBCore {
|
||||
klk.time=x.time+tw;
|
||||
send0(in, klk);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
}
|
||||
}).start();
|
||||
@@ -211,14 +242,18 @@ public class KLALBCore {
|
||||
private void send0(TCPConnection tcp, KLALBBlock kd) throws IOException {
|
||||
DataOutputStream out=tcp.getDout();
|
||||
synchronized (out) {
|
||||
|
||||
out.writeLong(kd.number);
|
||||
if (kd.number > 0) {
|
||||
out.writeLong(System.nanoTime());
|
||||
out.writeInt(kd.size);
|
||||
out.write(kd.data, 0, kd.size);
|
||||
}else if(kd.number==0){
|
||||
out.writeLong(System.nanoTime());
|
||||
}else if(kd.number==Long.MIN_VALUE) {
|
||||
out.writeLong(kd.time);
|
||||
}else {
|
||||
out.writeLong(kd.time);
|
||||
}
|
||||
out.flush();
|
||||
|
||||
@@ -230,15 +265,23 @@ public class KLALBCore {
|
||||
KLALBBlock kb = new KLALBBlock();
|
||||
DataInputStream in=tcp.getDin();
|
||||
synchronized (in) {
|
||||
|
||||
kb.number = in.readLong();
|
||||
if (kb.number > 0) {
|
||||
kb.time=in.readLong();
|
||||
kb.size = in.readInt();
|
||||
if(kb.size<0||kb.size>65536) {
|
||||
throw new StreamCorruptedException(tcp+"block size error:"+kb.size);
|
||||
}
|
||||
kb.data = new byte[kb.size];
|
||||
in.readFully(kb.data);
|
||||
}else if(kb.number==0){
|
||||
kb.time=in.readLong();
|
||||
}else if(kb.number==Long.MIN_VALUE) {
|
||||
kb.time=in.readLong();
|
||||
}else {
|
||||
kb.time=in.readLong();
|
||||
//tcp.nextRTT(System.nanoTime()-kb.time);
|
||||
}
|
||||
}
|
||||
System.out.println(tcp.getTunnel().getName()+" RECEIVE:" + kb);
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.kne.cloud.network.mport.ServiceElement;
|
||||
|
||||
public class KLALBSM {
|
||||
public static Map<String, ServiceElement> services=new HashMap<String, ServiceElement>();
|
||||
|
||||
|
||||
@@ -14,14 +14,18 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.kne.cloud.network.mport.IPPort;
|
||||
import org.kne.cloud.network.mport.ServiceElement;
|
||||
|
||||
public class KLALBServer {
|
||||
WeakHashMap<UUID, IOThreadManager> whm=new WeakHashMap<>();
|
||||
public KLALBServer(int port, Map<String,ServiceElement> services,List<Tunnel> tunnels) throws IOException {
|
||||
TCPListener tcpl=new TCPListener(port);
|
||||
tcpl.setCon((s)->{
|
||||
TCPConnection tcc=null;
|
||||
try {
|
||||
//s.setSoTimeout(10000);
|
||||
TCPConnection tcc=new TCPConnection(null,s);
|
||||
tcc=new TCPConnection(null,s);
|
||||
DataInputStream din=tcc.getDin();
|
||||
int val=din.readShort()&0xffff;
|
||||
if(val!=59649) {
|
||||
@@ -80,6 +84,7 @@ public class KLALBServer {
|
||||
}
|
||||
nx.handleSocket(tcc);
|
||||
int n=nx.getTcps().size();
|
||||
System.out.println(nx.getTcps());
|
||||
if(n<=0) {
|
||||
nx.closeLocal();
|
||||
System.out.println("连接已关闭");
|
||||
@@ -89,11 +94,8 @@ public class KLALBServer {
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
s.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(tcc!=null)
|
||||
tcc.close();
|
||||
}
|
||||
});
|
||||
tcpl.open();
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ServiceElement {
|
||||
public static final Map<Integer,String> procs=new HashMap<Integer,String>();
|
||||
static {
|
||||
procs.put(768,"RDP");
|
||||
procs.put(5635,"HTTPS");
|
||||
procs.put(59649, "KLALB");
|
||||
procs.put(21331, "SSH");
|
||||
|
||||
procs.put(18245, "HTTP");
|
||||
procs.put(20559, "HTTP");
|
||||
procs.put(18501, "HTTP");
|
||||
procs.put(20565, "HTTP");
|
||||
procs.put(17477, "HTTP");
|
||||
procs.put(17231, "HTTP");
|
||||
procs.put(20304, "HTTP");
|
||||
procs.put(21586, "HTTP");
|
||||
procs.put(20545, "HTTP");
|
||||
}
|
||||
public String proc;
|
||||
public IPPort ipport;
|
||||
public ServiceElement(String ini) throws UnknownHostException {
|
||||
String[]t=ini.split("\\$");
|
||||
if(t.length==1) {
|
||||
proc="";
|
||||
ipport=new IPPort(t[0]);
|
||||
}else {
|
||||
proc=t[0];
|
||||
ipport=new IPPort(t[1]);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
if(proc.isEmpty())
|
||||
return ipport.toString();
|
||||
return proc+"$"+ipport;
|
||||
}
|
||||
public static ServiceElement getbyproc(List<ServiceElement> services, int n) {
|
||||
String proc=procs.get(n);
|
||||
synchronized (services) {
|
||||
|
||||
Iterator<ServiceElement>sei=services.iterator();
|
||||
while (sei.hasNext()) {
|
||||
ServiceElement serviceElement = (ServiceElement) sei.next();
|
||||
if(serviceElement.proc.isEmpty()||serviceElement.proc.equals(proc))
|
||||
return serviceElement;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,11 @@ import java.net.UnknownHostException;
|
||||
|
||||
public class TCPConnection {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TCPConnection [tunnel=" + tunnel + ", connect=" + connect + ", delay=" + delay + "]";
|
||||
}
|
||||
|
||||
private Tunnel tunnel;
|
||||
private Socket connect;
|
||||
private DataInputStream din;
|
||||
@@ -70,13 +75,13 @@ public class TCPConnection {
|
||||
if(tunnel!=null) {
|
||||
tunnel.setDelay(delay);
|
||||
}
|
||||
/*if(connect!=null) {
|
||||
if(connect!=null) {
|
||||
try {
|
||||
connect.setSoTimeout((int) (delay/100000));
|
||||
connect.setSoTimeout(10000);
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public void setTunnel(Tunnel tunnel) {
|
||||
@@ -92,9 +97,8 @@ public class TCPConnection {
|
||||
if(t!=null) {
|
||||
t.getCCount().incrementAndGet();
|
||||
}
|
||||
// connect.setSoTimeout(10000);
|
||||
din = new DataInputStream(new BufferedInputStream(connect.getInputStream(), 65536));
|
||||
dout = new DataOutputStream(new BufferedOutputStream(connect.getOutputStream(), 65536));
|
||||
din = new DataInputStream(connect.getInputStream());
|
||||
dout = new DataOutputStream(connect.getOutputStream());
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
@@ -115,6 +119,11 @@ public class TCPConnection {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private volatile long RTT=10000000;
|
||||
public void nextRTT(long NRTT) {
|
||||
RTT=(long) ((1.0-Consts.A)*RTT+Consts.A*NRTT);
|
||||
System.out.println(RTT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.network.mport.ThreadTool;
|
||||
|
||||
public class TCPListener {
|
||||
private int port;
|
||||
private ServerSocket servers;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
public class ThreadTool {
|
||||
public static boolean first=true;
|
||||
public static boolean forceD=false;
|
||||
public static Thread makeVThreadIfSupport(String name,Runnable r) {
|
||||
if(forceD)
|
||||
return new Thread(r, name);
|
||||
try { return new Thread(r, name);
|
||||
//return Thread.ofVirtual().name(name).unstarted(r);
|
||||
}catch(Throwable e) {
|
||||
if(first) {
|
||||
System.out.println("请使用java19以上版本以提高性能!");
|
||||
first=false;
|
||||
}
|
||||
return new Thread(r, name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,8 @@ import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.kne.cloud.network.mport.IPPort;
|
||||
|
||||
public class Tunnel {
|
||||
private String name;
|
||||
private IPPort ipport;
|
||||
@@ -73,7 +75,9 @@ public class Tunnel {
|
||||
return name+"$"+ipport;
|
||||
}
|
||||
public Socket connectClientSocket() throws UnknownHostException, IOException {
|
||||
return new Socket(ipport.getIp(), ipport.getPort());
|
||||
Socket socket=new Socket();
|
||||
socket.connect(ipport.getSocketAddress(), 5000);
|
||||
return socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user