自动获得节点地址功能

This commit is contained in:
Administrator
2022-11-28 15:47:42 +08:00
parent 913313b2a8
commit 05d4117ef3
8 changed files with 344 additions and 23 deletions
@@ -3,6 +3,11 @@ package org.kne.cloud.network.klalb;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -37,6 +42,10 @@ public class KLALBClient {
try {
TCPConnection tc=new TCPConnection(tll);
tc.getDout().writeShort(59649);
tc.getDout().write(1);
tc.getDout().writeUTF(tll.getName());
tc.getDout().writeUTF(tll.getIp());
tc.getDout().writeInt(tll.getPort());
tc.getDout().writeLong(uid.getMostSignificantBits());
tc.getDout().writeLong(uid.getLeastSignificantBits());
tc.getDout().flush();
@@ -83,8 +92,35 @@ public class KLALBClient {
public List<Tunnel> getTls() {
return tls;
}
public static List<ServiceElement> services=new ArrayList<ServiceElement>();
public void searchTunnels(String ipport) throws IOException {
IPPort u=new IPPort(ipport);
TCPConnection tcpc=null;
try {
tcpc=new TCPConnection(null, new Socket(u.getIp(),u.getPort()));
tcpc.getDout().writeShort(59649);
tcpc.getDout().write(0);
tcpc.getDout().flush();
int s=tcpc.getDin().readInt();
for (int i = 0; i < s; i++) {
services.add(new ServiceElement(tcpc.getDin().readUTF()));
}
int s2=tcpc.getDin().readInt();
for (int i = 0; i < s2; i++) {
tls.add(new Tunnel(tcpc.getDin().readUTF()));
}
System.out.println(services);
System.out.println(tls);
}finally {
if(tcpc!=null) {
tcpc.close();
}
}
}
public static void main(String[] args) throws IOException {
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);
@@ -95,7 +131,7 @@ public class KLALBClient {
Tunnel t4=new Tunnel("Test4","cn-sx-xa-bgp-1.openfrp.top",65529);
tls.add(t4);
*/
List<Tunnel> tls=kc.getTls();
/* 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);
@@ -110,7 +146,7 @@ public class KLALBClient {
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);
tls.add(t12);*/
kc.open();
}