forked from KNEMC/KLALB
再次优化调度性能
This commit is contained in:
@@ -10,6 +10,7 @@ import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -17,6 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
public class KLALBClient {
|
||||
private List<Tunnel> tls=new ArrayList<>();
|
||||
private TCPListener tcpl;
|
||||
private ServiceElement sel;
|
||||
public KLALBClient(int port) throws IOException {
|
||||
tcpl=new TCPListener(port);
|
||||
tcpl.setCon((s)->{
|
||||
@@ -43,6 +45,11 @@ public class KLALBClient {
|
||||
TCPConnection tc=new TCPConnection(tll);
|
||||
tc.getDout().writeShort(59649);
|
||||
tc.getDout().write(1);
|
||||
|
||||
tc.getDout().writeUTF(sel.ipport.getIp().getHostAddress());
|
||||
tc.getDout().writeInt(sel.ipport.getPort());
|
||||
tc.getDout().writeUTF(sel.proc);
|
||||
|
||||
tc.getDout().writeUTF(tll.getName());
|
||||
tc.getDout().writeUTF(tll.getIp());
|
||||
tc.getDout().writeInt(tll.getPort());
|
||||
@@ -50,15 +57,15 @@ public class KLALBClient {
|
||||
tc.getDout().writeLong(uid.getLeastSignificantBits());
|
||||
tc.getDout().flush();
|
||||
aig.incrementAndGet();
|
||||
System.out.println("隧道"+tll+"已连接,可用线路数量:"+ (kcp.getTcps().size()+1));
|
||||
//System.out.println("隧道"+tll+"已连接,可用线路数量:"+ (kcp.getTcps().size()+1));
|
||||
kcp.handleSocket(tc);
|
||||
|
||||
tc.close();
|
||||
int n=kcp.getTcps().size();
|
||||
System.out.println("隧道"+tll+"已断开,可用线路数量:"+ n);
|
||||
//System.out.println("隧道"+tll+"已断开,可用线路数量:"+ n);
|
||||
if(n<=0) {
|
||||
kcp.closeRemote();
|
||||
kcp.closeLocal();
|
||||
System.out.println("连接已断开");
|
||||
//System.out.println("连接已断开");
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -66,7 +73,7 @@ public class KLALBClient {
|
||||
kcp.closeRemote();
|
||||
kcp.closeLocal();
|
||||
if(b.get()) {
|
||||
System.out.println("连接失败");
|
||||
System.out.println("隧道连接失败");
|
||||
b.set(false);
|
||||
}
|
||||
return;
|
||||
@@ -92,8 +99,11 @@ public class KLALBClient {
|
||||
public List<Tunnel> getTls() {
|
||||
return tls;
|
||||
}
|
||||
public static List<ServiceElement> services=new ArrayList<ServiceElement>();
|
||||
public List<ServiceElement> services=new ArrayList<ServiceElement>();
|
||||
|
||||
public List<ServiceElement> getServices() {
|
||||
return services;
|
||||
}
|
||||
public void searchTunnels(String ipport) throws IOException {
|
||||
IPPort u=new IPPort(ipport);
|
||||
TCPConnection tcpc=null;
|
||||
@@ -108,47 +118,63 @@ public class KLALBClient {
|
||||
}
|
||||
int s2=tcpc.getDin().readInt();
|
||||
for (int i = 0; i < s2; i++) {
|
||||
tls.add(new Tunnel(tcpc.getDin().readUTF()));
|
||||
tls.add(Tunnel.newTunnel(tcpc.getDin().readUTF()));
|
||||
}
|
||||
System.out.println(services);
|
||||
System.out.println(tls);
|
||||
//System.out.println(services);
|
||||
//System.out.println(tls);
|
||||
}finally {
|
||||
if(tcpc!=null) {
|
||||
tcpc.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceElement getSel() {
|
||||
return sel;
|
||||
}
|
||||
public void setSel(ServiceElement sel) {
|
||||
this.sel = sel;
|
||||
}
|
||||
public static void main(String[] args) throws IOException {
|
||||
Scanner scn=new Scanner(System.in);
|
||||
KLALBClient kc=new KLALBClient(4568);
|
||||
kc.searchTunnels("153.36.240.12:65529");
|
||||
//Tunnel t= new Tunnel("Test1", "127.0.0.1", 4569);
|
||||
/*Tunnel t= new Tunnel("Test1", "cn-hz-bgp-1.openfrp.top", 65529);
|
||||
tls.add(t);
|
||||
Tunnel t2=new Tunnel("Test2","cn-bj-bgp-3.openfrp.top",65529);
|
||||
tls.add(t2);
|
||||
Tunnel t3=new Tunnel("Test3","180.76.147.250",65529);
|
||||
tls.add(t3);
|
||||
Tunnel t4=new Tunnel("Test4","cn-sx-xa-bgp-1.openfrp.top",65529);
|
||||
tls.add(t4);
|
||||
*/
|
||||
/* List<Tunnel> tls=kc.getTls();
|
||||
Tunnel t5=new Tunnel("Test5","la.afrps.cn",49966);
|
||||
tls.add(t5);
|
||||
Tunnel t6=new Tunnel("Test6","sg.afrps.cn",49966);
|
||||
tls.add(t6);
|
||||
Tunnel t7=new Tunnel("Test7","ch.afrps.cn",49966);
|
||||
tls.add(t7);
|
||||
Tunnel t8=new Tunnel("Test8","sj.afrps.cn",49966);
|
||||
tls.add(t8);
|
||||
Tunnel t9=new Tunnel("Test9","frp.104300.xyz",49965);
|
||||
tls.add(t9);
|
||||
|
||||
Tunnel t11=new Tunnel("Test11","153.36.240.12",65529);
|
||||
tls.add(t11);
|
||||
Tunnel t12=new Tunnel("Test12","frp.freefrps.com",49965);
|
||||
tls.add(t12);*/
|
||||
kc.setSel(kc.getServices().get(0));
|
||||
kc.open();
|
||||
while(true) {
|
||||
String s=scn.next();
|
||||
switch(s) {
|
||||
case "states":
|
||||
Tunnel.states();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Tunnel t= new Tunnel("Test1", "127.0.0.1", 4569);
|
||||
/*Tunnel t= new Tunnel("Test1", "cn-hz-bgp-1.openfrp.top", 65529);
|
||||
tls.add(t);
|
||||
Tunnel t2=new Tunnel("Test2","cn-bj-bgp-3.openfrp.top",65529);
|
||||
tls.add(t2);
|
||||
Tunnel t3=new Tunnel("Test3","180.76.147.250",65529);
|
||||
tls.add(t3);
|
||||
Tunnel t4=new Tunnel("Test4","cn-sx-xa-bgp-1.openfrp.top",65529);
|
||||
tls.add(t4);
|
||||
*/
|
||||
/* List<Tunnel> tls=kc.getTls();
|
||||
Tunnel t5=new Tunnel("Test5","la.afrps.cn",49966);
|
||||
tls.add(t5);
|
||||
Tunnel t6=new Tunnel("Test6","sg.afrps.cn",49966);
|
||||
tls.add(t6);
|
||||
Tunnel t7=new Tunnel("Test7","ch.afrps.cn",49966);
|
||||
tls.add(t7);
|
||||
Tunnel t8=new Tunnel("Test8","sj.afrps.cn",49966);
|
||||
tls.add(t8);
|
||||
Tunnel t9=new Tunnel("Test9","frp.104300.xyz",49965);
|
||||
tls.add(t9);
|
||||
|
||||
Tunnel t11=new Tunnel("Test11","153.36.240.12",65529);
|
||||
tls.add(t11);
|
||||
Tunnel t12=new Tunnel("Test12","frp.freefrps.com",49965);
|
||||
tls.add(t12);*/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user