UI改进
This commit is contained in:
@@ -5,7 +5,13 @@
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/graalvm-jdk-23.0.1+11.1">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="add-exports" value="java.base/jdk.internal.misc=ALL-UNNAMED"/>
|
||||
<attribute name="add-opens" value="java.base/jdk.internal.misc=ALL-UNNAMED"/>
|
||||
</attributes>
|
||||
<accessrules>
|
||||
<accessrule kind="accessible" pattern="**"/>
|
||||
<accessrule kind="accessible" pattern="jdk/internal/misc/*"/>
|
||||
</accessrules>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="lib/gson-2.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/javassist.jar" sourcepath="C:/Users/ADMINI~1/AppData/Local/Temp/1/.org.sf.feeling.decompiler1686963856070/source/javassist-3.29.2-GA-sources.jar"/>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[{"language":"ZH_CN","nogui":false,"VirtualAddress":"2486:1:0:0:0:0:0:8888","DNS":["2486:1:0:0:0:0:0:8888"],"TCPListen":"0.0.0.0:4565","UDPListen":"{UDP}0.0.0.0:4572","VirtualSocketName":"KLALB_Stream","LineTable":["07f4acdef99b.ofalias.net:4565"],"ConnectLineTable":[],"Type":"KLALBController"},{"Listen":"0.0.0.0:4572","Bridge":{"KLALB":"SocketBridge","RDP":"SocketBridge","HTTP":"SocketBridge","HTTPS":"SocketBridge","DEFAULT":"MinecraftSocketBridge23332"},"Connect":{"KLALB":"127.0.0.1:4565","RDP":"127.0.0.1:3389","HTTP":"127.0.0.1:5212","HTTPS":"192.168.1.235:443","DEFAULT":"127.0.0.1:36555"},"Type":"SocketBridge"},{"Listen":"{KLALB_Stream}[::0]:23332","Bridge":{"DEFAULT":"MinecraftSocketBridge23332"},"Connect":{"DEFAULT":"127.0.0.1:36555"},"Type":"SocketBridge"},{"Listen":"{KLALB_Stream}[::0]:23333","Bridge":{"DEFAULT":"SocketBridge"},"Connect":{"DEFAULT":"127.0.0.1:5212"},"Type":"SocketBridge"},{"Listen":"0.0.0.0:25561","Bridge":{"KLALB":"SocketBridge","DEFAULT":"MinecraftSocketBridge23330"},"Connect":{"KLALB":"127.0.0.1:4565","DEFAULT":"127.0.0.1:25562"},"Type":"SocketBridge"},{"Listen":"{KLALB_Stream}[::0]:23330","Bridge":{"DEFAULT":"MinecraftSocketBridge23330"},"Connect":{"DEFAULT":"127.0.0.1:25562"},"Type":"SocketBridge"}]
|
||||
@@ -1,56 +0,0 @@
|
||||
[
|
||||
{"Type":"KLALBController" ,"VirtualAddress":"2486:1:34de:4abd:98c1:abd1:fc7a:401",
|
||||
"TCPListen" : "0.0.0.0:4565",
|
||||
"UDPListen" : "{UDP}0.0.0.0:4572",
|
||||
"VirtualSocketName" : "KLALB_Stream",
|
||||
"LineTable":["07f4acdef99b.ofalias.net:4572","{UDP}07f4acdef99b.ofalias.net:4572"]
|
||||
},
|
||||
{"Type":"SocketBridge" ,
|
||||
"Listen" : "0.0.0.0:4572",
|
||||
"Bridge":{
|
||||
"KLALB" : "SocketBridge",
|
||||
"RDP":"SocketBridge",
|
||||
"HTTP":"SocketBridge",
|
||||
"HTTPS":"SocketBridge",
|
||||
"DEFAULT":"MinecraftSocketBridge23332"
|
||||
} ,
|
||||
"Connect" : {
|
||||
"KLALB" : "127.0.0.1:4565",
|
||||
"RDP":"127.0.0.1:3389",
|
||||
"HTTP":"127.0.0.1:5212",
|
||||
"HTTPS":"192.168.1.235:443",
|
||||
"DEFAULT":"127.0.0.1:36555"
|
||||
}
|
||||
},
|
||||
{"Type":"SocketBridge" ,
|
||||
"Listen" : "{KLALB_Stream}[::0]:23332",
|
||||
"Bridge":"MinecraftSocketBridge23332",
|
||||
"Connect" : "127.0.0.1:36555"
|
||||
},
|
||||
{ "Type":"SocketBridge" ,
|
||||
"Listen" : "{KLALB_Stream}[::0]:23333",
|
||||
"Bridge":"SocketBridge",
|
||||
"Connect" : "127.0.0.1:5212"
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{"Type":"SocketBridge" ,
|
||||
"Listen" : "0.0.0.0:25561",
|
||||
"Bridge":{
|
||||
"KLALB" : "SocketBridge",
|
||||
"DEFAULT":"MinecraftSocketBridge23330"
|
||||
} ,
|
||||
"Connect" : {
|
||||
"KLALB" : "127.0.0.1:4565",
|
||||
"DEFAULT":"127.0.0.1:25562"
|
||||
}
|
||||
},
|
||||
{"Type":"SocketBridge" ,
|
||||
"Listen" : "{KLALB_Stream}[::0]:23330",
|
||||
"Bridge":"MinecraftSocketBridge23330",
|
||||
"Connect" : "127.0.0.1:25562"
|
||||
}
|
||||
]
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
@@ -0,0 +1,47 @@
|
||||
srv6acc=SRv6 network accelerator system
|
||||
networkgraph=Network graph
|
||||
language=Language
|
||||
basicsettings=Basic settings
|
||||
ipv6addr=IPv6 address
|
||||
dnsserver=DNS server
|
||||
asnumber=AS number
|
||||
tcplistening=TCP listening
|
||||
udplistening=UDP listening
|
||||
openlinetable=Open line table
|
||||
autoconnectlinetable=Auto connect line table
|
||||
advancedsettings=Advanced settings
|
||||
congresscontrolalgorithm=Congress control algorithm
|
||||
savesettings=Save settings
|
||||
locate=Locate
|
||||
find=Find
|
||||
home=Home
|
||||
uploadspeed=Upload speed
|
||||
downloadspeed=Download speed
|
||||
uploadpps=Upload PPS
|
||||
downloadpps=Download PPS
|
||||
copy=Copy
|
||||
onlinedevices=Online devices
|
||||
monitor=Monitor
|
||||
showofflines=Show offline remotelines
|
||||
lineaddressport=Line address:port
|
||||
addline=Add line
|
||||
reconnectall=Reconnect All
|
||||
remotelines=Remote lines
|
||||
settings=Settings
|
||||
saveconfigsuccess=Save config success
|
||||
warning=Warning
|
||||
invaildipv6addr=IPv6 address:Invaild Input
|
||||
invailddnsserver=DNS server:Invaild Input
|
||||
invaildasnumber=AS number:Invaild Input
|
||||
invaildtcplisten=TCP listen:Invaild Input
|
||||
invaildudplisten=UDP listen:Invaild Input
|
||||
invaildopenlinetable=Open line table:Invaild Input
|
||||
invaildconnectlinetable=Connect line table:Invaild Input
|
||||
unknown=Unknown
|
||||
viewlinemonitor=View line monitor
|
||||
copylineaddress=Copy line address
|
||||
copyvirtualaddress=Copy virtual address
|
||||
tryreconnect=Try reconnect
|
||||
forcedisconnect=Force disconnect
|
||||
removeline=Remove line
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
srv6acc=SRv6 网络加速系统
|
||||
networkgraph=网络拓扑图
|
||||
language=语言
|
||||
basicsettings=基本设置
|
||||
ipv6addr=IPv6地址
|
||||
dnsserver=DNS服务器
|
||||
asnumber=AS号码
|
||||
tcplistening=TCP监听端口
|
||||
udplistening=UDP监听端口
|
||||
openlinetable=开放线路列表
|
||||
autoconnectlinetable=自动连接线路列表
|
||||
advancedsettings=高级设置
|
||||
congresscontrolalgorithm=拥塞控制算法
|
||||
savesettings=保存设置
|
||||
locate=定位
|
||||
find=查找
|
||||
home=本机
|
||||
uploadspeed=上传速度
|
||||
downloadspeed=下载速度
|
||||
uploadpps=上传包转发率
|
||||
downloadpps=下载包转发率
|
||||
copy=复制
|
||||
onlinedevices=在线设备
|
||||
monitor=监视器
|
||||
showofflines=显示离线远程链路
|
||||
lineaddressport=链路地址:端口
|
||||
addline=添加链路
|
||||
reconnectall=全部重连
|
||||
remotelines=远程链路
|
||||
settings=设置
|
||||
saveconfigsuccess=保存配置成功
|
||||
warning=警告
|
||||
invaildipv6addr=IPv6地址:非法输入
|
||||
invailddnsserver=DNS服务器:非法输入
|
||||
invaildasnumber=AS号码:非法输入
|
||||
invaildtcplisten=TCP监听端口:非法输入
|
||||
invaildudplisten=UDP监听端口:非法输入
|
||||
invaildopenlinetable=开放线路列表:非法输入
|
||||
invaildconnectlinetable=自动连接线路列表:非法输入
|
||||
unknown=未知
|
||||
viewlinemonitor=打开链路监视器
|
||||
copylineaddress=复制链路地址
|
||||
copyvirtualaddress=复制虚拟地址
|
||||
tryreconnect=立即尝试重连
|
||||
forcedisconnect=强制断开连接
|
||||
removeline=强制断开连接并移除
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.lang.ref.PhantomReference;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,6 +15,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.kne.debug.TimeDebugger;
|
||||
|
||||
import jdk.internal.misc.Unsafe;
|
||||
public class ByteBufferAllocator {
|
||||
private List<ByteBufferPool> bbfps=new ArrayList<>();
|
||||
|
||||
@@ -75,9 +79,38 @@ public class ByteBufferAllocator {
|
||||
new ByteBufferPhantomReference(bbfs,refq,bbf,bbfp);
|
||||
return bbfs;
|
||||
}
|
||||
private static ByteBuffer allocateHeap(int capacity) {
|
||||
return ByteBuffer.wrap(new byte[capacity]);
|
||||
private static jdk.internal.misc.Unsafe usf;
|
||||
private static Method meth;
|
||||
static {
|
||||
Class<?> name;
|
||||
try {
|
||||
name = Class.forName("jdk.internal.misc.Unsafe");
|
||||
Field field = name.getDeclaredField("theUnsafe");
|
||||
field.setAccessible(true);
|
||||
usf= (Unsafe) field.get(null);
|
||||
meth=name.getMethod("allocateUninitializedArray", Class.class,int.class);
|
||||
|
||||
} catch (java.lang.reflect.InaccessibleObjectException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteBuffer allocateHeap(int capacity) {
|
||||
//return ByteBuffer.wrap((byte[]) usf.allocateUninitializedArray(byte.class, capacity));
|
||||
if(usf!=null&&meth!=null) {
|
||||
try {
|
||||
return ByteBuffer.wrap((byte[]) usf.allocateUninitializedArray(byte.class, capacity));
|
||||
} catch (Exception e) {
|
||||
return ByteBuffer.wrap(new byte[capacity]);
|
||||
}
|
||||
}else {
|
||||
return ByteBuffer.wrap(new byte[capacity]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ByteBufferPool getByteBufferPool(int capacity) {
|
||||
int elen=0;
|
||||
for (int i = 0; i < bbfps.size(); i++) {
|
||||
|
||||
@@ -81,6 +81,7 @@ public class IPMulticastDiscovery extends Thread implements Closeable, AutoClose
|
||||
try {
|
||||
while (!closed) {
|
||||
HashSet<MultipurposeSocketAddress> s = new HashSet<MultipurposeSocketAddress>();
|
||||
synchronized (msas) {
|
||||
for (Iterator<MultipurposeSocketAddress> iterator = msas.iterator(); iterator.hasNext();) {
|
||||
MultipurposeSocketAddress multipurposeSocketAddress = (MultipurposeSocketAddress) iterator
|
||||
.next();
|
||||
@@ -114,6 +115,7 @@ public class IPMulticastDiscovery extends Thread implements Closeable, AutoClose
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Thread.sleep(timeInterval);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.kne.cloud.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
@@ -17,6 +18,16 @@ import java.util.*;
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
public class MultipurposeSocketAddress implements Serializable{
|
||||
/**
|
||||
*
|
||||
@@ -141,8 +152,14 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("Socket Unsupported");
|
||||
}
|
||||
Socket s=sf.createSocket();
|
||||
try {
|
||||
s.bind(new InetSocketAddress(bindip, bindport));
|
||||
s.connect(new InetSocketAddress(host, port),timeout);
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
public Socket connectSocket(InetAddress bindip,int bindport) throws UnknownHostException, IOException {
|
||||
@@ -151,8 +168,14 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("Socket Unsupported");
|
||||
}
|
||||
Socket s=sf.createSocket();
|
||||
try {
|
||||
s.bind(new InetSocketAddress(bindip, bindport));
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
public Socket connectSocket() throws UnknownHostException, IOException {
|
||||
@@ -161,7 +184,13 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("Socket Unsupported");
|
||||
}
|
||||
Socket s=sf.createSocket();
|
||||
try {
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
public Socket connectSocket(int timeout) throws UnknownHostException, IOException {
|
||||
@@ -170,7 +199,13 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("Socket Unsupported");
|
||||
}
|
||||
Socket s=sf.createSocket();
|
||||
try {
|
||||
s.connect(new InetSocketAddress(host, port),timeout);
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -186,10 +221,16 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("Socket Unsupported");
|
||||
}
|
||||
SocketChannel s=sf.createSocketChannel();
|
||||
s.bind(new InetSocketAddress(bindip, bindport));
|
||||
TimerTask tt=tmoTimer.createTimeOutTask(s, timeout);
|
||||
TimerTask tt=null;
|
||||
try {
|
||||
s.bind(new InetSocketAddress(bindip, bindport));
|
||||
tt=tmoTimer.createTimeOutTask(s, timeout);
|
||||
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}finally {
|
||||
if(tt!=null)
|
||||
tt.cancel();
|
||||
@@ -202,8 +243,14 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("Socket Unsupported");
|
||||
}
|
||||
SocketChannel s=sf.createSocketChannel();
|
||||
try {
|
||||
s.bind(new InetSocketAddress(bindip, bindport));
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
public SocketChannel connectSocketChannel() throws UnknownHostException, IOException {
|
||||
@@ -212,7 +259,13 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("Socket Unsupported");
|
||||
}
|
||||
SocketChannel s=sf.createSocketChannel();
|
||||
try {
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
public SocketChannel connectSocketChannel(int timeout) throws UnknownHostException, IOException {
|
||||
@@ -225,6 +278,10 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
TimerTask tt=tmoTimer.createTimeOutTask(s, timeout);
|
||||
try {
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
s.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}finally {
|
||||
if(tt!=null)
|
||||
tt.cancel();
|
||||
@@ -285,8 +342,14 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
||||
}
|
||||
DatagramSocket dgd=dgs.createSocket();
|
||||
try {
|
||||
dgd.bind(new InetSocketAddress(bindip, bindport));
|
||||
dgd.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
dgd.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return dgd;
|
||||
}
|
||||
public DatagramSocket connectDatagramSocket() throws IOException {
|
||||
@@ -295,7 +358,13 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
||||
}
|
||||
DatagramSocket dgd=dgs.createSocket();
|
||||
try {
|
||||
dgd.connect(new InetSocketAddress(host, port));
|
||||
}catch(Exception e) {
|
||||
dgd.close();
|
||||
System.gc();
|
||||
throw e;
|
||||
}
|
||||
return dgd;
|
||||
}
|
||||
public DatagramServerSocket listenDatagramServerSocket() throws UnknownHostException, IOException {
|
||||
@@ -330,4 +399,35 @@ public class MultipurposeSocketAddress implements Serializable{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonDeserializer<MultipurposeSocketAddress>getDefaultJsonDeserializer(){
|
||||
return new JsonDeserializer<MultipurposeSocketAddress>() {
|
||||
|
||||
@Override
|
||||
public MultipurposeSocketAddress deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
|
||||
throws JsonParseException {
|
||||
if(arg0.isJsonPrimitive()) {
|
||||
JsonPrimitive jp=(JsonPrimitive) arg0;
|
||||
if(jp.isString()) {
|
||||
return new MultipurposeSocketAddress(jp.getAsString());
|
||||
}
|
||||
}
|
||||
throw new JsonParseException("not a string:"+arg0);
|
||||
}
|
||||
};
|
||||
}
|
||||
public static JsonSerializer<MultipurposeSocketAddress>getDefaultJsonSerializer(){
|
||||
return new JsonSerializer<MultipurposeSocketAddress>() {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(MultipurposeSocketAddress arg0, Type arg1, JsonSerializationContext arg2) {
|
||||
return new JsonPrimitive(arg0.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void registerToGsonBuilder(GsonBuilder gsonBuilder) {
|
||||
gsonBuilder.registerTypeAdapter(MultipurposeSocketAddress.class, getDefaultJsonDeserializer());
|
||||
gsonBuilder.registerTypeAdapter(MultipurposeSocketAddress.class, getDefaultJsonSerializer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ public class PortRelay {
|
||||
+ "-" + "(" + nx + ")->" + hp.getHost() + ":" + hp.getPort());
|
||||
try {
|
||||
sl=hp.connectSocket();
|
||||
|
||||
s.setSoTimeout(120*60*1000);
|
||||
sl.setSoTimeout(120*60*1000);
|
||||
new SocketBridge(s, sl).run();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -20,6 +20,15 @@ public class SocketToSocketProxy extends Proxy {
|
||||
private SocketBridgeFactory defaultFactory;
|
||||
private SocketChannelBridgeFactory defaultChannelFactory;
|
||||
private Map<String, SocketBridgeFactory> detectedFactory;
|
||||
private int defaultSoTimeout=120*60*1000;
|
||||
|
||||
public int getDefaultSoTimeout() {
|
||||
return defaultSoTimeout;
|
||||
}
|
||||
|
||||
public void setDefaultSoTimeout(int defaultSoTimeout) {
|
||||
this.defaultSoTimeout = defaultSoTimeout;
|
||||
}
|
||||
|
||||
public SocketToSocketProxy(MultipurposeSocketAddress listen, MultipurposeSocketAddress connect) throws IOException {
|
||||
this(listen, new MultipurposeSocketAddress(new InetSocketAddress(0)), connect);
|
||||
@@ -152,6 +161,8 @@ public class SocketToSocketProxy extends Proxy {
|
||||
|
||||
protected void runBridge(SocketBridgeFactory sbf,Socket sk, Socket sox) throws IOException {
|
||||
|
||||
sk.setSoTimeout(defaultSoTimeout);
|
||||
sox.setSoTimeout(defaultSoTimeout);
|
||||
sk.setTcpNoDelay(true);
|
||||
sox.setTcpNoDelay(true);
|
||||
SocketBridge sb = sbf.createBridge(sk, sox);
|
||||
@@ -159,6 +170,8 @@ public class SocketToSocketProxy extends Proxy {
|
||||
}
|
||||
|
||||
protected void runChannelBridge(SocketChannelBridgeFactory sbf,SocketChannel sk, SocketChannel sox) throws IOException {
|
||||
//sk.setSoTimeout(defaultSoTimeout);
|
||||
//sox.setSoTimeout(defaultSoTimeout);
|
||||
sk.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
||||
sox.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
||||
SocketChannelBridge sb = sbf.createBridge(sk, sox);
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.kne.cloud.network.ByteBufferAllocator;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet.IPv6ExtHeader;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet.IPv6SegmentRoutingHeader;
|
||||
@@ -718,7 +719,7 @@ public class IPv6Packet extends NetworkPacket {
|
||||
|
||||
//System.out.println("SR length:"+(laste+1));
|
||||
addresses.clear();
|
||||
ByteBuffer bfr=ByteBuffer.allocate(16);
|
||||
ByteBuffer bfr=NetworkPacket.bufferAllocator.allocate(16);
|
||||
for (int i = 0; i < (laste+1); i++) {
|
||||
bfr.clear();
|
||||
while (bfr.hasRemaining()) {
|
||||
|
||||
@@ -141,7 +141,7 @@ public class IPv6TUNLoopbackNetworkLink implements IPv6NetworkLink, Closeable, A
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
LockSupport.parkNanos(1000000L);
|
||||
LockSupport.parkNanos(10000000L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,15 @@ import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.io.KNEChannels;
|
||||
|
||||
public abstract class AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||
private static int defaultSoTimeout=60*1000;
|
||||
|
||||
public static int getDefaultSoTimeout() {
|
||||
return defaultSoTimeout;
|
||||
}
|
||||
|
||||
public static void setDefaultSoTimeout(int defaultSoTimeout) {
|
||||
AbstractKLALBPacketLink.defaultSoTimeout = defaultSoTimeout;
|
||||
}
|
||||
|
||||
private AtomicLong[] inputTrafficCounters;
|
||||
private AtomicLong[] outputTrafficCounters;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.JavaFileManager.Location;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class KLALBConfig extends ArrayList<KLALBConfigItem>{
|
||||
public static void main(String[] args) throws UnknownHostException, JsonSyntaxException, JsonIOException, FileNotFoundException {
|
||||
GsonBuilder gb=new GsonBuilder();
|
||||
MultipurposeSocketAddress.registerToGsonBuilder(gb);
|
||||
KLALBConfigItem.registerToGsonBuilder(gb);
|
||||
Gson gson=gb.create();
|
||||
KLALBConfig kc=gson.fromJson(new FileReader(new File("klalb-config.json")),KLALBConfig.class);
|
||||
System.out.println(kc);
|
||||
String s=gson.toJson(kc);
|
||||
System.out.println(s);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
public class KLALBConfigItem {
|
||||
private String Type;
|
||||
|
||||
public String getType() {
|
||||
return Type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
Type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KLALBConfigItem [Type=" + Type + "]";
|
||||
}
|
||||
|
||||
public KLALBConfigItem(String type) {
|
||||
super();
|
||||
Type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(Type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
KLALBConfigItem other = (KLALBConfigItem) obj;
|
||||
return Objects.equals(Type, other.Type);
|
||||
}
|
||||
public static JsonDeserializer<KLALBConfigItem>getDefaultJsonDeserializer(){
|
||||
return new JsonDeserializer<KLALBConfigItem>() {
|
||||
|
||||
@Override
|
||||
public KLALBConfigItem deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
|
||||
throws JsonParseException {
|
||||
if(arg0.isJsonObject()) {
|
||||
JsonObject jobj=(JsonObject) arg0;
|
||||
String s=jobj.get("Type").getAsString();
|
||||
switch(s) {
|
||||
case "KLALBController":
|
||||
return arg2.deserialize(arg0, new TypeToken<KLALBControllerConfigItem>() {}.getType());
|
||||
case "SocketBridge":
|
||||
return arg2.deserialize(arg0, new TypeToken<SocketBridgeConfigItem>() {}.getType());
|
||||
default:
|
||||
return arg2.deserialize(arg0, new TypeToken<UnknownKLALBConfigItem>() {}.getType());
|
||||
}
|
||||
}
|
||||
throw new JsonParseException("not a object:"+arg0);
|
||||
}
|
||||
};
|
||||
}
|
||||
public static JsonSerializer<KLALBConfigItem>getDefaultJsonSerializer(){
|
||||
return new JsonSerializer<KLALBConfigItem>() {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(KLALBConfigItem arg0, Type arg1, JsonSerializationContext arg2) {
|
||||
if(arg0 instanceof KLALBControllerConfigItem) {
|
||||
return arg2.serialize(arg0, new TypeToken<KLALBControllerConfigItem>() {}.getType());
|
||||
}
|
||||
if(arg0 instanceof SocketBridgeConfigItem) {
|
||||
return arg2.serialize(arg0, new TypeToken<SocketBridgeConfigItem>() {}.getType());
|
||||
}
|
||||
return arg2.serialize(arg0, new TypeToken<UnknownKLALBConfigItem>() {}.getType());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void registerToGsonBuilder(GsonBuilder gsonBuilder) {
|
||||
gsonBuilder.registerTypeAdapter(KLALBConfigItem.class, getDefaultJsonDeserializer());
|
||||
gsonBuilder.registerTypeAdapter(KLALBConfigItem.class, getDefaultJsonSerializer());
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class KLALBController {
|
||||
|
||||
private static final boolean showpacket = false;
|
||||
|
||||
private static final int PREFIX = 112;
|
||||
private static final int PREFIX = 128;//112
|
||||
private static final int DISCOVERY_PORT=4569;
|
||||
|
||||
private static List<IPMulticastDiscovery> ipmd=new ArrayList<>();
|
||||
@@ -168,25 +168,33 @@ public class KLALBController {
|
||||
|
||||
|
||||
for (Iterator<MultipurposeSocketAddress> iterator = st.iterator(); iterator.hasNext();) {
|
||||
MultipurposeSocketAddress multipurposeSocketAddress = (MultipurposeSocketAddress) iterator
|
||||
MultipurposeSocketAddress target = (MultipurposeSocketAddress) iterator
|
||||
.next();
|
||||
for (Iterator<MultipurposeSocketAddress> iterator2 = localaddress.iterator(); iterator2.hasNext();) {
|
||||
addRemoteLines(target);
|
||||
/*for (Iterator<MultipurposeSocketAddress> iterator2 = localaddress.iterator(); iterator2.hasNext();) {
|
||||
MultipurposeSocketAddress bind = (MultipurposeSocketAddress) iterator2
|
||||
.next();
|
||||
try {
|
||||
if(multipurposeSocketAddress.getInetAddress()instanceof Inet4Address&&bind.getInetAddress() instanceof Inet6Address) {
|
||||
if(target.getInetAddress().isLoopbackAddress() &&(!bind.getInetAddress().isLoopbackAddress())) {
|
||||
continue;
|
||||
}
|
||||
if(multipurposeSocketAddress.getInetAddress() instanceof Inet6Address &&bind.getInetAddress() instanceof Inet4Address) {
|
||||
if((!target.getInetAddress().isLoopbackAddress()) &&bind.getInetAddress().isLoopbackAddress()) {
|
||||
continue;
|
||||
}
|
||||
if(target.getInetAddress()instanceof Inet4Address&&bind.getInetAddress() instanceof Inet6Address) {
|
||||
continue;
|
||||
}
|
||||
if(target.getInetAddress() instanceof Inet6Address &&bind.getInetAddress() instanceof Inet4Address) {
|
||||
continue;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
if(e.getMessage().toLowerCase().contains("no scope_id found"))
|
||||
}
|
||||
if(!checkContainsTargetAndBind(multipurposeSocketAddress,bind)) {
|
||||
if(!checkContainsTargetAndBind(target,bind)) {
|
||||
//System.out.println(target+" "+bind);
|
||||
addRemoteLine( new KLALBRemoteLine(multipurposeSocketAddress,bind));
|
||||
addRemoteLine( new KLALBRemoteLine(target,bind));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
for (Iterator<KLALBRemoteLine> iterator = lines.iterator(); iterator.hasNext();) {
|
||||
@@ -404,7 +412,8 @@ public class KLALBController {
|
||||
|
||||
}
|
||||
|
||||
public List<KLALBRemoteLine> addRemoteLines(MultipurposeSocketAddress target) {lineslock.writeLock().lock();
|
||||
public List<KLALBRemoteLine> addRemoteLines(MultipurposeSocketAddress target) {
|
||||
lineslock.writeLock().lock();
|
||||
try {
|
||||
List<KLALBRemoteLine>added=new ArrayList<>();
|
||||
try {
|
||||
@@ -416,21 +425,36 @@ public class KLALBController {
|
||||
Enumeration<InetAddress>ei= networkInterface.getInetAddresses();
|
||||
while (ei.hasMoreElements()) {
|
||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||
try {
|
||||
MultipurposeSocketAddress bind=new MultipurposeSocketAddress(inetAddress.getHostAddress(),0);
|
||||
try {
|
||||
if(target.getInetAddress().isLoopbackAddress() &&(!bind.getInetAddress().isLoopbackAddress())) {
|
||||
continue;
|
||||
}
|
||||
if((!target.getInetAddress().isLoopbackAddress()) &&bind.getInetAddress().isLoopbackAddress()) {
|
||||
continue;
|
||||
}
|
||||
if(target.getInetAddress()instanceof Inet4Address&&bind.getInetAddress() instanceof Inet6Address) {
|
||||
continue;
|
||||
}
|
||||
if(target.getInetAddress() instanceof Inet6Address &&bind.getInetAddress() instanceof Inet4Address) {
|
||||
continue;
|
||||
}
|
||||
//System.out.println(target+"->"+bind);
|
||||
} catch (UnknownHostException e) {
|
||||
if(e.getMessage().trim().toLowerCase().contains("no scope_id found")) {
|
||||
throw e;
|
||||
}
|
||||
//e.printStackTrace();
|
||||
}
|
||||
if(!checkContainsTargetAndBind(target,bind)) {
|
||||
KLALBRemoteLine line=new KLALBRemoteLine(target,bind);
|
||||
addRemoteLine(line );
|
||||
added.add(line);
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
public class KLALBControllerConfigItem extends KLALBConfigItem {
|
||||
private String language;
|
||||
private boolean nogui;
|
||||
private String VirtualAddress;
|
||||
private Long VirtualASN;
|
||||
private List<InetAddress> DNS;
|
||||
private MultipurposeSocketAddress TCPListen;
|
||||
private MultipurposeSocketAddress UDPListen;
|
||||
private String VirtualSocketName;
|
||||
private List<MultipurposeSocketAddress>LineTable=new ArrayList<>();
|
||||
private List<MultipurposeSocketAddress>ConnectLineTable=new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
|
||||
public KLALBControllerConfigItem(String type, boolean nogui, String virtualAddress, Long virtualASN,
|
||||
List<InetAddress> dNS, MultipurposeSocketAddress tCPListen, MultipurposeSocketAddress uDPListen,
|
||||
String virtualSocketName, List<MultipurposeSocketAddress> lineTable,
|
||||
List<MultipurposeSocketAddress> connectLineTable) {
|
||||
super(type);
|
||||
this.nogui = nogui;
|
||||
VirtualAddress = virtualAddress;
|
||||
VirtualASN = virtualASN;
|
||||
DNS = dNS;
|
||||
TCPListen = tCPListen;
|
||||
UDPListen = uDPListen;
|
||||
VirtualSocketName = virtualSocketName;
|
||||
LineTable = lineTable;
|
||||
ConnectLineTable = connectLineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public KLALBControllerConfigItem(String type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getVirtualSocketName() {
|
||||
return VirtualSocketName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setVirtualSocketName(String virtualSocketName) {
|
||||
VirtualSocketName = virtualSocketName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isNogui() {
|
||||
return nogui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setNogui(boolean nogui) {
|
||||
this.nogui = nogui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getVirtualAddress() {
|
||||
return VirtualAddress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setVirtualAddress(String virtualAddress) {
|
||||
VirtualAddress = virtualAddress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Long getVirtualASN() {
|
||||
return VirtualASN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setVirtualASN(Long virtualASN) {
|
||||
VirtualASN = virtualASN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<InetAddress> getDNS() {
|
||||
return DNS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setDNS(List<InetAddress> dNS) {
|
||||
DNS = dNS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MultipurposeSocketAddress getTCPListen() {
|
||||
return TCPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setTCPListen(MultipurposeSocketAddress tCPListen) {
|
||||
TCPListen = tCPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MultipurposeSocketAddress getUDPListen() {
|
||||
return UDPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setUDPListen(MultipurposeSocketAddress uDPListen) {
|
||||
UDPListen = uDPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MultipurposeSocketAddress> getLineTable() {
|
||||
return LineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLineTable(List<MultipurposeSocketAddress> lineTable) {
|
||||
LineTable = lineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MultipurposeSocketAddress> getConnectLineTable() {
|
||||
return ConnectLineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setConnectLineTable(List<MultipurposeSocketAddress> connectLineTable) {
|
||||
ConnectLineTable = connectLineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KLALBControllerConfigItem [language=" + language + ", nogui=" + nogui + ", VirtualAddress="
|
||||
+ VirtualAddress + ", VirtualASN=" + VirtualASN + ", DNS=" + DNS + ", TCPListen=" + TCPListen
|
||||
+ ", UDPListen=" + UDPListen + ", VirtualSocketName=" + VirtualSocketName + ", LineTable=" + LineTable
|
||||
+ ", ConnectLineTable=" + ConnectLineTable + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + Objects.hash(ConnectLineTable, DNS, LineTable, TCPListen, UDPListen, VirtualASN,
|
||||
VirtualAddress, VirtualSocketName, language, nogui);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
KLALBControllerConfigItem other = (KLALBControllerConfigItem) obj;
|
||||
return Objects.equals(ConnectLineTable, other.ConnectLineTable) && Objects.equals(DNS, other.DNS)
|
||||
&& Objects.equals(LineTable, other.LineTable) && Objects.equals(TCPListen, other.TCPListen)
|
||||
&& Objects.equals(UDPListen, other.UDPListen) && Objects.equals(VirtualASN, other.VirtualASN)
|
||||
&& Objects.equals(VirtualAddress, other.VirtualAddress)
|
||||
&& Objects.equals(VirtualSocketName, other.VirtualSocketName)
|
||||
&& Objects.equals(language, other.language) && nogui == other.nogui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
@@ -18,6 +19,7 @@ import org.kne.cloud.network.SocketChannelListener;
|
||||
import org.kne.cloud.network.SocketListener;
|
||||
import org.kne.cloud.network.ipv6.RouteItem;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI2;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI3;
|
||||
import org.kne.cloud.network.klalb.ui.UIEnv;
|
||||
import org.kne.cloud.network.perf.Kperf;
|
||||
import org.kne.cloud.network.perf.MemcpyBenchmark;
|
||||
@@ -25,7 +27,7 @@ import org.kne.cloud.network.perf.NodeBenchmark;
|
||||
import org.kne.debug.Debuger;
|
||||
|
||||
public class KLALBMain {
|
||||
public static KLALBStateGUI2 ksg;
|
||||
public static KLALBStateGUI3 ksg;
|
||||
public static void main(String[] args) throws IOException {
|
||||
try {
|
||||
UIEnv.inituie();
|
||||
@@ -35,14 +37,15 @@ public class KLALBMain {
|
||||
System.out.println(CONST.klalb+" V"+CONST.klalbver);
|
||||
Scanner scn=new Scanner(System.in);
|
||||
|
||||
File configJson=new File("klalbconfig.json");
|
||||
File configJson=new File("klalb-config.json");
|
||||
|
||||
KLALBProxySystem kpcje=new KLALBProxySystem();
|
||||
kpcje.loadConfigJson(configJson);
|
||||
System.out.println("SRv6地址:"+kpcje.getKlalbController().getSelf().getAddress().getHostAddress());
|
||||
try {
|
||||
if(!kpcje.getControllerConfig().isNogui())
|
||||
openGUI(kpcje);
|
||||
}catch(RuntimeException e) {
|
||||
}catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*MultipurposeSocketAddress mpa=new MultipurposeSocketAddress("127.9.9.9", 49573);
|
||||
@@ -79,7 +82,11 @@ public class KLALBMain {
|
||||
break;
|
||||
|
||||
case "monitor":
|
||||
try {
|
||||
openGUI(kpcje);
|
||||
}catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case "lines-state":
|
||||
System.out.println("线路状态:");
|
||||
@@ -191,6 +198,9 @@ public class KLALBMain {
|
||||
default:
|
||||
System.out.println("未知命令,请输入help以查询命令说明");
|
||||
}
|
||||
}catch (NoSuchElementException err) {
|
||||
System.out.println("已退出程序");
|
||||
System.exit(0);
|
||||
}catch(RuntimeException e) {
|
||||
System.out.println("错误!");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.Inet6Address;
|
||||
@@ -23,10 +24,15 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.kne.cloud.network.*;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI2;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI3;
|
||||
import org.kne.cloud.network.klalb.ui.Language;
|
||||
import org.kne.cloud.network.klalb.ui.UIEnv;
|
||||
import org.kne.cloud.network.minecraft.MinecraftSocketBridge;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -37,6 +43,15 @@ public class KLALBProxySystem {
|
||||
private Set<Proxy> proxys=new HashSet<>();
|
||||
private KLALBController klalbController;
|
||||
private KLALBRemoteManagement krm;
|
||||
private KLALBConfig config;
|
||||
private Gson gson;
|
||||
private File jsonFile;
|
||||
{
|
||||
GsonBuilder gb=new GsonBuilder();
|
||||
MultipurposeSocketAddress.registerToGsonBuilder(gb);
|
||||
KLALBConfigItem.registerToGsonBuilder(gb);
|
||||
gson=gb.create();
|
||||
}
|
||||
public Set<Proxy> getProxys() {
|
||||
return proxys;
|
||||
}
|
||||
@@ -87,6 +102,7 @@ public class KLALBProxySystem {
|
||||
}
|
||||
|
||||
public void loadConfigJson(File jsonFile) throws IOException {
|
||||
this.jsonFile=jsonFile;
|
||||
FileReader fr = null;
|
||||
try {
|
||||
fr=new FileReader(jsonFile);
|
||||
@@ -104,229 +120,165 @@ public class KLALBProxySystem {
|
||||
loadConfigJson(new JsonParser().parse(json));
|
||||
}
|
||||
public void loadConfigJson(JsonElement json) {
|
||||
JsonArray jobj=(JsonArray) json;
|
||||
jobj.forEach((val)->{
|
||||
solveEntry((JsonObject) val);
|
||||
});
|
||||
KLALBConfig config= gson.fromJson(json, KLALBConfig.class);
|
||||
System.out.println(config);
|
||||
loadConfig(config);
|
||||
}
|
||||
protected void solveEntry(JsonObject entry){
|
||||
switch (entry.get("Type").getAsString()) {
|
||||
case "KLALBController":
|
||||
JsonElement vase= entry.get("VirtualAddress");
|
||||
//System.out.println(vase);
|
||||
List<InetAddress>daddr=new ArrayList<InetAddress>();
|
||||
JsonElement vdns= entry.get("DNS");
|
||||
if(vdns!=null) {
|
||||
if(vdns instanceof JsonArray) {
|
||||
JsonArray arr=(JsonArray) vdns;
|
||||
for(JsonElement str:arr) {
|
||||
public void loadConfig(KLALBConfig config) {
|
||||
this.config=config;
|
||||
for(KLALBConfigItem item:config) {
|
||||
if(item instanceof KLALBControllerConfigItem) {
|
||||
KLALBControllerConfigItem kcci=(KLALBControllerConfigItem) item;
|
||||
String lstr=kcci.getLanguage();
|
||||
if(lstr!=null) {
|
||||
Language lang=Language.valueOf(lstr);
|
||||
if(lang!=null) {
|
||||
try {
|
||||
daddr.add((Inet6Address) InetAddress.getByName(str.getAsString()));
|
||||
} catch (UnknownHostException e) {
|
||||
UIEnv.setRsb(lang.getFileName());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
String vase= kcci.getVirtualAddress();
|
||||
//System.out.println(vase);
|
||||
List<InetAddress>daddr=new ArrayList<InetAddress>();
|
||||
List<InetAddress> vdns= kcci.getDNS();
|
||||
if(vdns!=null) {
|
||||
for(InetAddress dnsaddr:vdns) {
|
||||
daddr.add(dnsaddr);
|
||||
}
|
||||
|
||||
}
|
||||
if(vase!=null) {
|
||||
try {
|
||||
klalbController=new KLALBController((Inet6Address) InetAddress.getByName(vase),daddr);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
klalbController=new KLALBController(daddr);
|
||||
}
|
||||
|
||||
|
||||
Long vasn= kcci.getVirtualASN();
|
||||
if(vasn!=null) {
|
||||
klalbController.getIpv6Router().setASN (vasn);
|
||||
}
|
||||
|
||||
|
||||
String vsne=kcci.getVirtualSocketName();
|
||||
//if(vsne!=null) {
|
||||
MultipurposeSocketAddress.getSocketTypeRegister().put(vsne, klalbController.getSocketType());
|
||||
//}
|
||||
MultipurposeSocketAddress tcple=kcci.getTCPListen();
|
||||
if(tcple!=null) {
|
||||
|
||||
SocketChannelListener tcpl = null;
|
||||
try {
|
||||
daddr.add((Inet6Address) InetAddress.getByName(vdns.getAsString()));
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
tcpl = new SocketChannelListener(tcple);
|
||||
|
||||
tcpl.setCon((soc)->{
|
||||
|
||||
KLALBRemoteLine krs=null;
|
||||
try {
|
||||
krs = new KLALBRemoteLine(new StreamChannelKLALBPacketLink(soc));
|
||||
klalbController.addRemoteLine(krs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
MultipurposeSocketAddress mpsa2=new MultipurposeSocketAddress(tcple.getType(), tcple.getHost(),((InetSocketAddress)tcpl.getServerSocketChannel().getLocalAddress()).getPort());
|
||||
klalbController.getListenSocketAddress().add(mpsa2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(vase!=null) {
|
||||
try {
|
||||
klalbController=new KLALBController((Inet6Address) InetAddress.getByName(vase.getAsString()),daddr);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
klalbController=new KLALBController(daddr);
|
||||
}
|
||||
MultipurposeSocketAddress udple=kcci.getUDPListen();
|
||||
if(udple!=null) {
|
||||
DatagramSocketListener udpl = null;
|
||||
try {
|
||||
udpl = new DatagramSocketListener(udple);
|
||||
|
||||
udpl.setCon((soc)->{
|
||||
|
||||
JsonElement vasn= entry.get("VirtualASN");
|
||||
if(vasn!=null) {
|
||||
klalbController.getIpv6Router().setASN (Long.parseLong( vasn.getAsString()));
|
||||
}
|
||||
KLALBRemoteLine krs=null;
|
||||
try {
|
||||
krs = new KLALBRemoteLine(new SplitedDatagramKLALBPacketLink(soc));
|
||||
klalbController.addRemoteLine(krs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
MultipurposeSocketAddress mpsau2=new MultipurposeSocketAddress(udple.getType(), udple.getHost(),((InetSocketAddress)(udpl.getDatagramServerSocket().getLocalSocketAddress())).getPort());
|
||||
//klalbController.getListenSocketAddress().add(mpsau2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
List<MultipurposeSocketAddress> linele=kcci.getLineTable();
|
||||
if(linele!=null) {
|
||||
linele.forEach((aline)->{
|
||||
klalbController.getSelflineTable().add(aline);
|
||||
});
|
||||
|
||||
JsonElement vsne=entry.get("VirtualSocketName");
|
||||
//if(vsne!=null) {
|
||||
MultipurposeSocketAddress.getSocketTypeRegister().put(vsne.getAsString(), klalbController.getSocketType());
|
||||
//}
|
||||
JsonElement tcple=entry.get("TCPListen");
|
||||
if(tcple!=null) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(tcple.getAsString());
|
||||
|
||||
SocketChannelListener tcpl = null;
|
||||
}
|
||||
List<MultipurposeSocketAddress> linetoc=kcci.getConnectLineTable();
|
||||
if(linetoc!=null) {
|
||||
linetoc.forEach((aline)->{
|
||||
klalbController.addRemoteLines(aline);
|
||||
});
|
||||
}
|
||||
}else if(item instanceof SocketBridgeConfigItem) {
|
||||
SocketBridgeConfigItem scci=(SocketBridgeConfigItem) item;
|
||||
try {
|
||||
tcpl = new SocketChannelListener(mpsa);
|
||||
|
||||
tcpl.setCon((soc)->{
|
||||
|
||||
KLALBRemoteLine krs=null;
|
||||
try {
|
||||
krs = new KLALBRemoteLine(new StreamChannelKLALBPacketLink(soc));
|
||||
klalbController.addRemoteLine(krs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
MultipurposeSocketAddress mpsa2=new MultipurposeSocketAddress(mpsa.getType(), mpsa.getHost(),((InetSocketAddress)tcpl.getServerSocketChannel().getLocalAddress()).getPort());
|
||||
klalbController.getListenSocketAddress().add(mpsa2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
proxys.add(scci.createProxy(klalbController));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
JsonElement udple=entry.get("UDPListen");
|
||||
if(udple!=null) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(udple.getAsString());
|
||||
DatagramSocketListener udpl = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private KLALBStateGUI3 kgui;
|
||||
public KLALBStateGUI3 getKLALBGUI() {
|
||||
if(kgui==null) {
|
||||
kgui=new KLALBStateGUI3(klalbController);
|
||||
kgui.loadConfig(config);
|
||||
kgui.setSaveComsumer((cfg)->{
|
||||
String json=gson.toJson(cfg);
|
||||
if(jsonFile!=null) {
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
udpl = new DatagramSocketListener(mpsa);
|
||||
|
||||
udpl.setCon((soc)->{
|
||||
|
||||
KLALBRemoteLine krs=null;
|
||||
try {
|
||||
krs = new KLALBRemoteLine(new SplitedDatagramKLALBPacketLink(soc));
|
||||
klalbController.addRemoteLine(krs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
MultipurposeSocketAddress mpsau2=new MultipurposeSocketAddress(mpsa.getType(), mpsa.getHost(),((InetSocketAddress)(udpl.getDatagramServerSocket().getLocalSocketAddress())).getPort());
|
||||
//klalbController.getListenSocketAddress().add(mpsau2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
fw=new FileWriter(jsonFile);
|
||||
fw.write(json);
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(fw!=null)
|
||||
try {
|
||||
fw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
JsonElement linele=entry.get("LineTable");
|
||||
if(linele!=null) {
|
||||
JsonArray jary=(JsonArray)linele;
|
||||
jary.forEach((aline)->{
|
||||
klalbController.getSelflineTable().add(new MultipurposeSocketAddress(aline.getAsString()));
|
||||
});
|
||||
|
||||
}
|
||||
JsonElement linetoc=entry.get("ConnectLineTable");
|
||||
if(linetoc!=null) {
|
||||
JsonArray jary=(JsonArray)linetoc;
|
||||
jary.forEach((aline)->{
|
||||
klalbController.addRemoteLines(new MultipurposeSocketAddress(aline.getAsString()));
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "SocketBridge":
|
||||
|
||||
try {
|
||||
proxys.add(createProxyByJson(entry));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
});
|
||||
}
|
||||
}
|
||||
public Proxy createProxyByJson(JsonObject entry) throws IOException {
|
||||
HostPortMap mapp=new HostPortMap();
|
||||
LinkedHashMap<String, SocketBridgeFactory>mapb=new LinkedHashMap<>();
|
||||
MultipurposeSocketAddress l=new MultipurposeSocketAddress(entry.get("Listen").getAsString());
|
||||
SocketBridgeFactory bdg=getDefaultBridgeFactory(entry.get("Bridge"),mapb);
|
||||
MultipurposeSocketAddress r=getDefaultConnect(entry.get("Connect"),mapp);
|
||||
return new SocketToSocketProxy(l ,new MultipurposeSocketAddress("0.0.0.0:0"), r,mapp,bdg,mapb);
|
||||
}
|
||||
public JsonObject createJsonObjectByProxy(Proxy p) {
|
||||
if(p instanceof SocketToSocketProxy) {
|
||||
SocketToSocketProxy stsp=(SocketToSocketProxy) p;
|
||||
JsonObject jobj=new JsonObject();
|
||||
jobj.addProperty("Listen", stsp.getListen().toString());
|
||||
jobj.add("Bridge", getJsonElementByBridges(stsp));
|
||||
jobj.add("Connect", getJsonElementByConnects(stsp));
|
||||
return jobj;
|
||||
}else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private JsonElement getJsonElementByConnects(SocketToSocketProxy stsp) {
|
||||
if(stsp.getDetectedConnect()==null||stsp.getDetectedConnect().isEmpty()) {
|
||||
return new JsonPrimitive(stsp.getDefaultConnect().toString());
|
||||
}else {
|
||||
JsonObject jo=new JsonObject();
|
||||
for (Iterator<Entry<String, MultipurposeSocketAddress>> iterator = stsp.getDetectedConnect().entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<String, MultipurposeSocketAddress> proxy = (Entry<String, MultipurposeSocketAddress>) iterator.next();
|
||||
if(!proxy.getKey().equals("DEFAULT")) {
|
||||
jo.addProperty(proxy.getKey(), proxy.getValue().toString());
|
||||
}
|
||||
}
|
||||
jo.addProperty("DEFAULT", stsp.getDefaultConnect().toString());
|
||||
return jo;
|
||||
}
|
||||
}
|
||||
private JsonElement getJsonElementByBridges(SocketToSocketProxy stsp) {
|
||||
if(stsp.getDetectedFactory()==null||stsp.getDetectedFactory().isEmpty()) {
|
||||
return new JsonPrimitive(getJobjByFActory(stsp.getDefaultFactory()));
|
||||
}else {
|
||||
JsonObject jo=new JsonObject();
|
||||
for (Iterator<Entry<String, SocketBridgeFactory>> iterator = stsp.getDetectedFactory().entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<String, SocketBridgeFactory> proxy = (Entry<String, SocketBridgeFactory>) iterator.next();
|
||||
if(!proxy.getKey().equals("DEFAULT")) {
|
||||
jo.addProperty(proxy.getKey(), getJobjByFActory(proxy.getValue()));
|
||||
}
|
||||
}
|
||||
jo.addProperty("DEFAULT",getJobjByFActory( stsp.getDefaultFactory()));
|
||||
return jo;
|
||||
}
|
||||
}
|
||||
private MultipurposeSocketAddress getDefaultConnect(JsonElement jsonElement, LinkedHashMap<String, MultipurposeSocketAddress> mapp) {
|
||||
if(jsonElement instanceof JsonObject) {
|
||||
JsonObject jobj=(JsonObject) jsonElement;
|
||||
jobj.entrySet().forEach((en)->{
|
||||
mapp.put(en.getKey(), new MultipurposeSocketAddress( en.getValue().getAsString()));
|
||||
});
|
||||
return mapp.get("DEFAULT");
|
||||
}else {
|
||||
return new MultipurposeSocketAddress(jsonElement.getAsString());
|
||||
}
|
||||
}
|
||||
private SocketBridgeFactory getDefaultBridgeFactory(JsonElement jsonElement, LinkedHashMap<String, SocketBridgeFactory> mapp) {
|
||||
if(jsonElement instanceof JsonObject) {
|
||||
JsonObject jobj=(JsonObject) jsonElement;
|
||||
jobj.entrySet().forEach((en)->{
|
||||
mapp.put(en.getKey(), getFactoryByJobj(en.getValue().getAsString()));
|
||||
});
|
||||
return mapp.get("DEFAULT");
|
||||
}else {
|
||||
return getFactoryByJobj(jsonElement.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
private SocketBridgeFactory getFactoryByJobj(String string) {
|
||||
if(string.startsWith("SocketBridge")) {
|
||||
return new DefaultSocketBridgeFactory();
|
||||
}else if(string.startsWith("MinecraftSocketBridge")) {
|
||||
return new DefaultMinecraftSocketBridgeFactory(klalbController.getSelf().getAddress(), Integer.parseInt(string.substring(21)));
|
||||
}
|
||||
throw new IllegalArgumentException("unknown SocketBridge type:"+string);
|
||||
}
|
||||
private String getJobjByFActory(SocketBridgeFactory sbf) {
|
||||
if(sbf instanceof DefaultSocketBridgeFactory) {
|
||||
return "SocketBridge";
|
||||
}else if(sbf instanceof DefaultMinecraftSocketBridgeFactory) {
|
||||
return "MinecraftSocketBridge"+((DefaultMinecraftSocketBridgeFactory)sbf).getVport();
|
||||
}else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
private KLALBStateGUI2 kgui;
|
||||
public KLALBStateGUI2 getKLALBGUI() {
|
||||
if(kgui==null)
|
||||
kgui=new KLALBStateGUI2(klalbController);
|
||||
return kgui;
|
||||
}
|
||||
public KLALBConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
public KLALBControllerConfigItem getControllerConfig() {
|
||||
for(KLALBConfigItem item:config) {
|
||||
if(item instanceof KLALBControllerConfigItem)
|
||||
return (KLALBControllerConfigItem) item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,7 +369,8 @@ public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteL
|
||||
writeKLALBPacketToKPL(new VADDRPacket(localVaddrSupplier.get()));
|
||||
writeKLALBPacketToKPL(new VADDRPacket(localVaddrSupplier.get()));
|
||||
flushKPL();
|
||||
ByteBuffer[] kpp = null;
|
||||
ByteBuffer[] kpp = new ByteBuffer[10];
|
||||
boolean haskpp=false;
|
||||
int kppslen=0;
|
||||
while ((!kplink.isClosed()) && (!closed)) {
|
||||
// TimeDebugger tdb=new TimeDebugger();
|
||||
@@ -393,12 +394,12 @@ public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteL
|
||||
|
||||
// tdb.putTime("Isend");
|
||||
|
||||
if (kpp == null) {
|
||||
if (haskpp == false) {
|
||||
ByteBuffer tkpp = sendDequeList.poll();
|
||||
if(tkpp==null) {
|
||||
monitor.setQueueingDelay(0);
|
||||
}else {
|
||||
kpp=new ByteBuffer[10];
|
||||
haskpp=true;
|
||||
kpp[0]=tkpp;
|
||||
int i=1;
|
||||
for(;i<kpp.length;i++) {
|
||||
@@ -411,7 +412,7 @@ public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteL
|
||||
}
|
||||
}
|
||||
// System.out.println(sendDequeList.size());
|
||||
if (kpp != null) {
|
||||
if (haskpp) {
|
||||
// TimeDebugger tdb=new TimeDebugger();
|
||||
//tdb.putTime("start");
|
||||
|
||||
@@ -426,7 +427,7 @@ public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteL
|
||||
/*if (kpp instanceof DATATPacket||kpp instanceof IPv6OverKLALBPacket) {
|
||||
resetSleepTimer();
|
||||
}*/
|
||||
kpp = null;
|
||||
haskpp = false;
|
||||
|
||||
//}
|
||||
|
||||
@@ -679,12 +680,10 @@ public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteL
|
||||
//iv6.dispose();
|
||||
}else {
|
||||
if(val!=null) {
|
||||
Long l=recvedUIDMap.putIfAbsent(val.getUuid(), System.nanoTime());
|
||||
if(l==null) {
|
||||
/*Long l=recvedUIDMap.putIfAbsent(val.getUuid(), System.nanoTime());
|
||||
if(l==null) {*/
|
||||
ipv6con.accept(iv6);
|
||||
}else {
|
||||
//System.out.println("虚假重传:"+val.getUuid());
|
||||
}
|
||||
//}
|
||||
}else {
|
||||
ipv6con.accept(iv6);
|
||||
}
|
||||
@@ -730,7 +729,9 @@ public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteL
|
||||
}
|
||||
// Thread.sleep(monitor.getCoolingTime());
|
||||
lthd = Thread.currentThread();
|
||||
//LockSupport.parkNanos(1000000000L);
|
||||
LockSupport.parkNanos(coll.getCoolingTime(monitor.getReliability()));
|
||||
//System.out.println("waitend");
|
||||
// coll.incCoolingTime();
|
||||
|
||||
}
|
||||
@@ -1021,9 +1022,9 @@ public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteL
|
||||
|
||||
|
||||
|
||||
private Map<IPSequence,SendItem> sendMap= new ConcurrentHashMap<>();
|
||||
private Map<IPSequence,SendItem> sendMap= new ConcurrentHashMap<>(1024,0.2f);
|
||||
private AtomicInteger sendmapWindowUsed=new AtomicInteger(0);
|
||||
private Map<UUID,Long>recvedUIDMap=new ConcurrentHashMap<UUID, Long>();
|
||||
private Map<UUID,Long>recvedUIDMap=new ConcurrentHashMap<UUID, Long>(1024,0.2f);
|
||||
|
||||
private volatile int inputchachesize = 8192 * 4000;
|
||||
private volatile int outputchachesize = 8192 * 240;//500
|
||||
|
||||
@@ -144,7 +144,7 @@ public class KLALBRemoteManagement {
|
||||
case "OPENMONITORUI":
|
||||
klalbProxySystem.getKLALBGUI().setVisible(true);
|
||||
break;
|
||||
case "GETSOCKETBRIDGE":
|
||||
/*case "GETSOCKETBRIDGE":
|
||||
JsonArray bridges=new JsonArray();
|
||||
Set<Proxy> pxy=klalbProxySystem.getProxys();
|
||||
synchronized (pxy) {
|
||||
@@ -165,7 +165,7 @@ public class KLALBRemoteManagement {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;*/
|
||||
default:
|
||||
System.out.println("未知请求类型:"+reqt);
|
||||
break;
|
||||
|
||||
@@ -94,9 +94,9 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
|
||||
|
||||
//60000 30 30
|
||||
private final int MTU=10000;
|
||||
private final int MTU=60000;
|
||||
private final long MIN_RTTVAR=100000000L;
|
||||
private final long MIN_LIMIT_SPEED=128*1024L;
|
||||
private final long MIN_LIMIT_SPEED=64*1024L;
|
||||
private final long REACK_INTERVAL = 100000000L;
|
||||
|
||||
|
||||
@@ -115,12 +115,12 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
private ReentrantLock backlogQueuelock=new ReentrantLock();
|
||||
|
||||
private ThreadParker sendDequeLock=new ThreadParker();
|
||||
private Map<Long,DATATPacket> recvMap = new ConcurrentHashMap<Long,DATATPacket>(100000);
|
||||
private Map<Long,DATATPacket> recvMap = new ConcurrentHashMap<Long,DATATPacket>(1024,0.2f);
|
||||
private AtomicInteger recvWindowUsed=new AtomicInteger(0);
|
||||
//private AtomicInteger recvCounter=new AtomicInteger(0);
|
||||
|
||||
|
||||
private Map<Long,DATATPacket> sendmap=new ConcurrentHashMap<Long, DATATPacket>(100000);
|
||||
private Map<Long,DATATPacket> sendmap=new ConcurrentHashMap<Long, DATATPacket>(1024,0.5f);
|
||||
private AtomicInteger sendmapWindowUsed=new AtomicInteger(0);
|
||||
//private ReentrantReadWriteLock sendmaplock=new ReentrantReadWriteLock();
|
||||
|
||||
|
||||
@@ -34,11 +34,11 @@ public class PortBinder {
|
||||
this.controller = controller;
|
||||
}
|
||||
private ReentrantReadWriteLock bindMaplock=new ReentrantReadWriteLock();
|
||||
private Map<InetSocketAddress,BindableKLALBPacketConsumer>bindMap=new ConcurrentHashMap<>(65536*16);
|
||||
private Map<InetSocketAddress,BindableKLALBPacketConsumer>bindMap=new ConcurrentHashMap<>(1024,0.2f);
|
||||
private ReentrantReadWriteLock listenMaplock=new ReentrantReadWriteLock();
|
||||
private Map<InetSocketAddress,BindableKLALBPacketConsumer>listenMap=new ConcurrentHashMap<>(65536*16);
|
||||
private Map<InetSocketAddress,BindableKLALBPacketConsumer>listenMap=new ConcurrentHashMap<>(1024,0.2f);
|
||||
private ReentrantReadWriteLock connectMaplock=new ReentrantReadWriteLock();
|
||||
private Map<Pair<InetSocketAddress,InetSocketAddress>,BindableKLALBPacketConsumer>connectMap=new ConcurrentHashMap<>(65536*16);
|
||||
private Map<Pair<InetSocketAddress,InetSocketAddress>,BindableKLALBPacketConsumer>connectMap=new ConcurrentHashMap<>(1024,0.2f);
|
||||
private volatile int portn=65535;
|
||||
public void bind(BindableKLALBPacketConsumer ks) throws BindException {
|
||||
bindMaplock.writeLock().lock();
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.channels.MulticastChannel;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.kne.cloud.network.DefaultMinecraftSocketBridgeFactory;
|
||||
import org.kne.cloud.network.DefaultSocketBridgeFactory;
|
||||
import org.kne.cloud.network.HostPortMap;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.Proxy;
|
||||
import org.kne.cloud.network.SocketBridgeFactory;
|
||||
import org.kne.cloud.network.SocketToSocketProxy;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
public class SocketBridgeConfigItem extends KLALBConfigItem {
|
||||
private MultipurposeSocketAddress Listen;
|
||||
|
||||
private LinkedHashMap<String, String>Bridge=new LinkedHashMap<>();
|
||||
private HostPortMap Connect=new HostPortMap();
|
||||
|
||||
public SocketBridgeConfigItem( MultipurposeSocketAddress listen,
|
||||
LinkedHashMap<String, String> bridge, HostPortMap connect) {
|
||||
super("SocketBridge");
|
||||
Listen = listen;
|
||||
Bridge = bridge;
|
||||
Connect = connect;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SocketBridgeConfigItem [Listen=" + Listen + ", Bridge=" + Bridge + ", Connect=" + Connect + "]";
|
||||
}
|
||||
|
||||
|
||||
/*public static JsonDeserializer<SocketBridgeConfigItem> getSocketBridgeConfigItemJsonDeserializer(){
|
||||
return new JsonDeserializer<SocketBridgeConfigItem>() {
|
||||
|
||||
@Override
|
||||
public SocketBridgeConfigItem deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
|
||||
throws JsonParseException {
|
||||
if(arg0.isJsonObject()) {
|
||||
HostPortMap mapp=new HostPortMap();
|
||||
LinkedHashMap<String, SocketBridgeFactory>mapb=new LinkedHashMap<>();
|
||||
MultipurposeSocketAddress l=new MultipurposeSocketAddress(((JsonObject) arg0).get("Listen").getAsString());
|
||||
SocketBridgeFactory bdg=getDefaultBridgeFactory(((JsonObject)arg0).get("Bridge"),mapb);
|
||||
MultipurposeSocketAddress r=getDefaultConnect(((JsonObject)arg0).get("Connect"),mapp);
|
||||
return new SocketBridgeConfigItem(l,mapb,mapp);
|
||||
}else {
|
||||
throw new JsonParseException("not a object:"+arg0);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
public static JsonSerializer<SocketBridgeConfigItem> getSocketBridgeConfigItemJsonSerializer(){
|
||||
return new JsonSerializer<SocketBridgeConfigItem>() {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(SocketBridgeConfigItem arg0, Type arg1, JsonSerializationContext arg2) {
|
||||
return null;
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
public static void registerToGsonBuilder(GsonBuilder gsonBuilder) {
|
||||
gsonBuilder.registerTypeAdapter(SocketBridgeConfigItem.class, getSocketBridgeConfigItemJsonDeserializer());
|
||||
gsonBuilder.registerTypeAdapter(SocketBridgeConfigItem.class, getSocketBridgeConfigItemJsonSerializer());
|
||||
}*/
|
||||
public Proxy createProxy(KLALBController controller) throws IOException {
|
||||
HostPortMap mapp=new HostPortMap();
|
||||
LinkedHashMap<String, SocketBridgeFactory>mapb=new LinkedHashMap<>();
|
||||
MultipurposeSocketAddress l=Listen;
|
||||
SocketBridgeFactory bdg=getDefaultBridgeFactory(Bridge,mapb,controller);
|
||||
MultipurposeSocketAddress r=getDefaultConnect(Connect,mapp);
|
||||
return new SocketToSocketProxy(l ,new MultipurposeSocketAddress("0.0.0.0:0"), r,mapp,bdg,mapb);
|
||||
}
|
||||
private MultipurposeSocketAddress getDefaultConnect(HostPortMap connect2, LinkedHashMap<String, MultipurposeSocketAddress> mapp) {
|
||||
connect2.entrySet().forEach((en)->{
|
||||
mapp.put(en.getKey(), en.getValue());
|
||||
});
|
||||
return mapp.get("DEFAULT");
|
||||
}
|
||||
private SocketBridgeFactory getDefaultBridgeFactory(LinkedHashMap<String, String> bridge2, LinkedHashMap<String, SocketBridgeFactory> mapp, KLALBController controller) {
|
||||
bridge2.entrySet().forEach((en)->{
|
||||
mapp.put(en.getKey(), getFactoryByJobj(en.getValue(), controller));
|
||||
});
|
||||
return mapp.get("DEFAULT");
|
||||
}private SocketBridgeFactory getFactoryByJobj(String string,KLALBController controller) {
|
||||
if(string.startsWith("SocketBridge")) {
|
||||
return new DefaultSocketBridgeFactory();
|
||||
}else if(string.startsWith("MinecraftSocketBridge")) {
|
||||
return new DefaultMinecraftSocketBridgeFactory(controller.getSelf().getAddress(), Integer.parseInt(string.substring(21)));
|
||||
}
|
||||
throw new IllegalArgumentException("unknown SocketBridge type:"+string);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
}
|
||||
|
||||
private SocketChannel connectSocket;
|
||||
private int sotimeout;
|
||||
private int sotimeout=getDefaultSoTimeout();
|
||||
public StreamChannelKLALBPacketLink(SocketChannel connectSocket) throws IOException {
|
||||
this.connectSocket=connectSocket;
|
||||
connectSocket.setOption(StandardSocketOptions.TCP_NODELAY,true);
|
||||
@@ -140,10 +140,15 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ByteBuffer[] bbfwx=new ByteBuffer[100<<1];
|
||||
{
|
||||
for(int i=0;i<100;i++) {
|
||||
bbfwx[i<<1]=NetworkPacket.bufferAllocator.allocate(4);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void writePackets(ByteBuffer[] kpp,int off,int len) throws IOException {
|
||||
if(len>100) {
|
||||
ByteBuffer[] bbfw=new ByteBuffer[len<<1];
|
||||
for(int i=0;i<len;i++) {
|
||||
ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
@@ -153,22 +158,33 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
szeWrite.putInt(kpp[off+i].limit());
|
||||
szeWrite.flip();
|
||||
KLALBVirtualSocketChannel obj = null;
|
||||
bbfw[i*2]=szeWrite;
|
||||
bbfw[i*2+1]=kpp[i];
|
||||
bbfw[i<<1]=szeWrite;
|
||||
bbfw[(i<<1)+1]=kpp[off+i];
|
||||
}
|
||||
connectSocket.write(bbfw);
|
||||
}else {
|
||||
for(int i=0;i<len;i++) {
|
||||
bbfwx[i<<1].clear();
|
||||
bbfwx[i<<1].limit(4);
|
||||
incOutput(kpp[off+i].limit());
|
||||
bbfwx[i<<1].putInt(kpp[off+i].limit());
|
||||
bbfwx[i<<1].flip();
|
||||
bbfwx[(i<<1)+1]=kpp[off+i];
|
||||
}
|
||||
connectSocket.write(bbfwx,0,len<<1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ByteBuffer szeRead=NetworkPacket.bufferAllocator.allocate(4);
|
||||
|
||||
@Override
|
||||
public ByteBuffer readPacket() throws IOException {
|
||||
timeoutTimer=System.nanoTime();
|
||||
timerenabled=true;
|
||||
ByteBuffer kp;
|
||||
|
||||
ByteBuffer szeRead=NetworkPacket.bufferAllocator.allocate(4);
|
||||
szeRead.clear();
|
||||
szeRead.limit(4);
|
||||
//szeRead.clear();
|
||||
try {
|
||||
|
||||
@@ -24,6 +24,7 @@ public class StreamKLALBPacketLink extends AbstractKLALBPacketLink implements KL
|
||||
public StreamKLALBPacketLink(Socket connectSocket) throws IOException {
|
||||
this.connectSocket=connectSocket;
|
||||
connectSocket.setTcpNoDelay(true);
|
||||
setSoTimeout(getDefaultSoTimeout());
|
||||
out=new KLALBOutputStream(connectSocket.getOutputStream());
|
||||
out.flush();
|
||||
in=new KLALBInputStream( connectSocket.getInputStream());
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
public class UnknownKLALBConfigItem extends KLALBConfigItem {
|
||||
|
||||
public UnknownKLALBConfigItem(String type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -15,6 +17,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||
@@ -44,6 +47,21 @@ public class GraphPanel extends JPanel {
|
||||
private double translateX,translateY;
|
||||
|
||||
private double scale=1;
|
||||
public Image defaultimage;
|
||||
public Image defaultimage2;
|
||||
{
|
||||
|
||||
try {
|
||||
defaultimage=ImageIO.read(GraphPanel.class.getResourceAsStream("/assets/ipv6router1.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
defaultimage2=ImageIO.read(GraphPanel.class.getResourceAsStream("/assets/ipv6router2.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public double getTranslateX() {
|
||||
return translateX;
|
||||
@@ -95,11 +113,13 @@ public class GraphPanel extends JPanel {
|
||||
public class GraphNode{
|
||||
private String text;
|
||||
private Color color;
|
||||
private double nodesize=40;
|
||||
private double nodesize=110;
|
||||
private double x;
|
||||
private double y;
|
||||
private boolean ismarked;
|
||||
private Vector2 delta=new Vector2(0, 0);
|
||||
private Image image=defaultimage;
|
||||
private Image image2=defaultimage2;
|
||||
public GraphNode(String text, Color color, double x, double y,boolean ismarked) {
|
||||
super();
|
||||
this.text = text;
|
||||
@@ -133,6 +153,24 @@ public class GraphPanel extends JPanel {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(Image image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public Image getImage2() {
|
||||
return image2;
|
||||
}
|
||||
|
||||
public void setImage2(Image image2) {
|
||||
this.image2 = image2;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
@@ -164,20 +202,29 @@ public class GraphPanel extends JPanel {
|
||||
public void paint(Graphics2D g) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.setStroke(new BasicStroke(2.0f));
|
||||
if(image!=null) {
|
||||
if(ismarked) {
|
||||
g.drawImage(image2,(int)(x-image.getWidth(null)/2),(int)(y-image.getHeight(null)/2) ,null);
|
||||
}else {
|
||||
g.drawImage(image,(int)(x-image.getWidth(null)/2),(int)(y-image.getHeight(null)/2) ,null);
|
||||
}
|
||||
}else {
|
||||
g.drawOval((int)(x-nodesize/2), (int)(y-nodesize/2), (int)(nodesize), (int)(nodesize));
|
||||
if(ismarked) {
|
||||
Vector2 pos=new Vector2(x, y);
|
||||
Vector2 v2a=new Vector2(0, -1).multi(nodesize/4);
|
||||
Vector2 v2b=new Vector2(Math.sqrt(3)/2.0, 0.5).multi(nodesize/4);
|
||||
Vector2 v2c=new Vector2(-Math.sqrt(3)/2.0, 0.5).multi(nodesize/4);
|
||||
v2a=v2a.add(pos);
|
||||
v2b=v2b.add(pos);
|
||||
v2c=v2c.add(pos);
|
||||
g.drawPolygon(new int[] {(int) v2a.x,(int) v2b.x,(int) v2c.x}, new int[] {(int) v2a.y,(int) v2b.y,(int) v2c.y}, 3);
|
||||
}
|
||||
}
|
||||
g.setFont(UIEnv.getFont().deriveFont(10.0f));
|
||||
|
||||
g.drawString(text, (int)(x+nodesize/2), (int)(y-nodesize/3));
|
||||
if(ismarked) {
|
||||
Vector2 pos=new Vector2(x, y);
|
||||
Vector2 v2a=new Vector2(0, -1).multi(nodesize/4);
|
||||
Vector2 v2b=new Vector2(Math.sqrt(3)/2.0, 0.5).multi(nodesize/4);
|
||||
Vector2 v2c=new Vector2(-Math.sqrt(3)/2.0, 0.5).multi(nodesize/4);
|
||||
v2a=v2a.add(pos);
|
||||
v2b=v2b.add(pos);
|
||||
v2c=v2c.add(pos);
|
||||
g.drawPolygon(new int[] {(int) v2a.x,(int) v2b.x,(int) v2c.x}, new int[] {(int) v2a.y,(int) v2b.y,(int) v2c.y}, 3);
|
||||
}
|
||||
//g.drawString(text, (int)(x+nodesize/2), (int)(y-nodesize/3));
|
||||
g.drawString(text, (int)(x-image.getWidth(null)/2-10), (int)(y+image.getHeight(null)/2+10));
|
||||
}
|
||||
|
||||
public Vector2 getPositionVec2() {
|
||||
@@ -478,7 +525,7 @@ public class GraphPanel extends JPanel {
|
||||
|
||||
//System.out.println(length);
|
||||
if(distance>length) {
|
||||
Vector2 dicb=sub.normalize().multi((distance-length)/3);
|
||||
Vector2 dicb=sub.normalize().multi((distance-length)/4);
|
||||
Vector2 dica=dicb.opposite();
|
||||
na.delta=na.delta.add(dica);
|
||||
nb.delta=nb.delta.add(dicb);
|
||||
@@ -497,15 +544,15 @@ public class GraphPanel extends JPanel {
|
||||
private Random r=new Random();
|
||||
public Vector2 getRandomPos() {
|
||||
double x,y;
|
||||
if(xmin>=xmax) {
|
||||
x=r.nextDouble();
|
||||
}else {
|
||||
if(xmin<xmax) {
|
||||
x=r.nextDouble(xmin, xmax);
|
||||
}
|
||||
if(ymin>=ymax) {
|
||||
y=r.nextDouble();
|
||||
}else {
|
||||
x=r.nextDouble();
|
||||
}
|
||||
if(ymin<ymax) {
|
||||
y=r.nextDouble(ymin, ymax);
|
||||
}else {
|
||||
y=r.nextDouble();
|
||||
}
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
@@ -1164,7 +1164,9 @@ textFieldLocate.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void run() {
|
||||
graph.loadNodes();
|
||||
for(int i=0;i<5;i++) {
|
||||
graph.runPhy();
|
||||
}
|
||||
if(graph.isVisible()) {
|
||||
graph.repaint();
|
||||
graph.revalidate();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum Language {
|
||||
ZH_CN("简体中文","zh_CN"),EN_US("English","en_US");
|
||||
private String string,filename;
|
||||
private Language(String string, String filename) {
|
||||
this.string=string;
|
||||
this.filename=filename;
|
||||
}
|
||||
public String toString() {
|
||||
return string;
|
||||
}
|
||||
public String getFileName() {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class TPanel2 extends JPanel {
|
||||
panel.setLayout(new BorderLayout(0, 0));
|
||||
panel.add(tname);
|
||||
|
||||
vaddr = new JLabel("unknown");
|
||||
vaddr = new JLabel(UIEnv.getRsb().getString("unknown"));
|
||||
panel.add(vaddr, BorderLayout.SOUTH);
|
||||
vaddr.setForeground(Color.DARK_GRAY);
|
||||
|
||||
@@ -157,7 +157,7 @@ public class TPanel2 extends JPanel {
|
||||
|
||||
popupMenu = new JPopupMenu();
|
||||
|
||||
mntmNewMenuItem = new JMenuItem("View line monitor");
|
||||
mntmNewMenuItem = new JMenuItem(UIEnv.getRsb().getString("viewlinemonitor"));
|
||||
popupMenu.add(mntmNewMenuItem);
|
||||
mntmNewMenuItem.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -168,7 +168,7 @@ public class TPanel2 extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem mntmNewMenuItemz = new JMenuItem("Copy line address");
|
||||
JMenuItem mntmNewMenuItemz = new JMenuItem(UIEnv.getRsb().getString("copylineaddress"));
|
||||
popupMenu.add(mntmNewMenuItemz);
|
||||
mntmNewMenuItemz.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -178,7 +178,7 @@ public class TPanel2 extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem mntmNewMenuItemx = new JMenuItem("Copy virtual address");
|
||||
JMenuItem mntmNewMenuItemx = new JMenuItem(UIEnv.getRsb().getString("copyvirtualaddress"));
|
||||
popupMenu.add(mntmNewMenuItemx);
|
||||
mntmNewMenuItemx.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -191,7 +191,7 @@ public class TPanel2 extends JPanel {
|
||||
|
||||
|
||||
|
||||
mntmNewMenuItem3 = new JMenuItem("Try reconnect");
|
||||
mntmNewMenuItem3 = new JMenuItem(UIEnv.getRsb().getString("tryreconnect"));
|
||||
popupMenu.add(mntmNewMenuItem3);
|
||||
mntmNewMenuItem3.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -202,7 +202,7 @@ public class TPanel2 extends JPanel {
|
||||
}
|
||||
});
|
||||
mntmNewMenuItem3.setForeground(Color.GREEN);
|
||||
mntmNewMenuItem2 = new JMenuItem("Force disconnect");
|
||||
mntmNewMenuItem2 = new JMenuItem(UIEnv.getRsb().getString("forcedisconnect"));
|
||||
popupMenu.add(mntmNewMenuItem2);
|
||||
mntmNewMenuItem2.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -213,7 +213,7 @@ public class TPanel2 extends JPanel {
|
||||
});
|
||||
mntmNewMenuItem2.setForeground(Color.RED);
|
||||
|
||||
JMenuItem mi=new JMenuItem("Remove line");
|
||||
JMenuItem mi=new JMenuItem(UIEnv.getRsb().getString("removeline"));
|
||||
popupMenu.add(mi);
|
||||
mi.addActionListener(new ActionListener() {
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class UIEnv {
|
||||
|
||||
private static ResourceBundle rsb;
|
||||
public static void setRsb(String xrsb) throws IOException {
|
||||
rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/knemcl_"+xrsb+".properties"));
|
||||
rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/klalb_"+xrsb+".properties"));
|
||||
}
|
||||
|
||||
public static void setRsb(ResourceBundle xrsb) {
|
||||
@@ -38,7 +38,7 @@ public class UIEnv {
|
||||
public static ResourceBundle getRsb() {
|
||||
if(rsb==null) {
|
||||
try {
|
||||
rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/knemcl_en_US.properties"));
|
||||
rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/klalb_en_US.properties"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.kne.cloud.network.nathole;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
public class Experiment {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Socket soc=new Socket();
|
||||
soc.bind(new InetSocketAddress("kne02.yoyo250.fun", 1234));
|
||||
soc.connect(new InetSocketAddress("kne04.yoyo250.fun", 1234));
|
||||
System.out.println("连接成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
|
||||
public static final long HOTSOPT_TIMEOUT = 1000000000;
|
||||
|
||||
public static final int HOTSOPT_REPORT_INTERVAL = 100000000;
|
||||
public static final int HOTSOPT_REPORT_INTERVAL = 50000000;
|
||||
private SRv6Router router;
|
||||
public SRv6Router getRouter() {
|
||||
return router;
|
||||
@@ -83,14 +83,13 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
private long floodTimer=System.nanoTime();
|
||||
private long floodTimer2=System.nanoTime();
|
||||
private long requestTimer=System.nanoTime();
|
||||
KLALBVirtualRawSocket ds = null;
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("KLALB路由协议接收线程");
|
||||
getSelfRouterInfo();
|
||||
KLALBVirtualRawSocket ds = null;
|
||||
try{
|
||||
ds=new KLALBVirtualRawSocket(router,router.getLocator().getAddress(), DEFAULT_PROTOCOL_NUMBER);
|
||||
KLALBVirtualRawSocket ds2=ds;
|
||||
new Thread(()->{
|
||||
Thread.currentThread().setName("KLALB路由协议接收线程");
|
||||
|
||||
@@ -120,14 +119,14 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
if(debug)
|
||||
System.out.println("update60");
|
||||
floodTimer=cur;
|
||||
floodPacket(ds2, null, new RouterInfoPacket(selfRouterInfo,true,-1));
|
||||
floodPacket(ds, null, new RouterInfoPacket(selfRouterInfo,true,-1));
|
||||
}
|
||||
|
||||
if(cur-floodTimer2>1000000000L) {
|
||||
if(debug)
|
||||
System.out.println("update1");
|
||||
floodTimer2=cur;
|
||||
floodPacket(ds2, null, new RouterInfoPacket(selfRouterInfo,true,router.getASN()));
|
||||
floodPacket(ds, null, new RouterInfoPacket(selfRouterInfo,true,router.getASN()));
|
||||
}
|
||||
|
||||
//Set<Inet6Address> requestSet=new HashSet<>();
|
||||
@@ -174,10 +173,10 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
|
||||
for (Iterator<Entry<Inet6Address, HotspotAddressTimer>> iterator = hotspots.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, HotspotAddressTimer> type = (Entry<Inet6Address, HotspotAddressTimer>) iterator.next();
|
||||
if(type.getValue().checkReportTime()) {
|
||||
//if(type.getValue().checkReportTime()) {
|
||||
//System.out.println("hotspot address:"+type.getKey());
|
||||
writePacket(ds2, new RouterInfoPacket( netmap.get(router.getLocator().getAddress()),false,-1), new InetSocketAddress(type.getKey(), DEFAULT_PORT));
|
||||
}
|
||||
//writePacket(ds2, new RouterInfoPacket( netmap.get(router.getLocator().getAddress()),false,-1), new InetSocketAddress(type.getKey(), DEFAULT_PORT));
|
||||
//}
|
||||
if(type.getValue().checkTimeOut()) {
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -358,7 +357,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
return;
|
||||
}
|
||||
Set<Entry<Inet6Address, RouterInfo>> s=netmap.entrySet();
|
||||
Map<Inet6Address,Long>airs=new HashMap<>(netmap.size()+1);
|
||||
Map<Inet6Address,Long>airs=new HashMap<>(netmap.size()*2,0.4f);
|
||||
|
||||
List<Inet6Address>rias=new ArrayList<>(netmap.size()+1);
|
||||
|
||||
@@ -620,10 +619,18 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
if(true) {
|
||||
HotspotAddressTimer hat=hotspots.get(sourceAddress);
|
||||
if(hat==null) {
|
||||
hotspots.put(sourceAddress, new HotspotAddressTimer());
|
||||
hotspots.put(sourceAddress,hat= new HotspotAddressTimer());
|
||||
}else {
|
||||
hat.refreshTimeout();
|
||||
}
|
||||
if(hat.checkReportTime()) {
|
||||
System.out.println("hotspot address:"+sourceAddress);
|
||||
try {
|
||||
writePacket(ds, new RouterInfoPacket( netmap.get(router.getLocator().getAddress()),false,-1), new InetSocketAddress(sourceAddress, DEFAULT_PORT));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private Map<Inet6Address,Long> toIpBandwidth=new ConcurrentHashMap<Inet6Address,Long>();
|
||||
@@ -646,7 +653,10 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
NetmapDirections directionsx=directions;
|
||||
if(directionsx==null)
|
||||
return null;
|
||||
long number= directionsx.getDirection_airs().get(text);
|
||||
Long l=directionsx.getDirection_airs().get(text);
|
||||
if(l==null)
|
||||
return null;
|
||||
long number= l;
|
||||
long prev= directionsx.getDirection()[(int)number];
|
||||
if(prev==-1) {
|
||||
return null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.kne.cloud.network.srv6;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -17,9 +18,23 @@ public class SRv6PacketReorder {
|
||||
this.packetConsumer=packetConsumer;
|
||||
}
|
||||
|
||||
private long jumpTime=500000000L;
|
||||
private long jumpTime=400000000L;
|
||||
|
||||
private Map<Long,IPv6Packet>map=new ConcurrentHashMap<>();
|
||||
|
||||
private long maxCacheingTime=5000000000L;
|
||||
|
||||
private class PacketTimeEntry{
|
||||
private IPv6Packet packet;
|
||||
private long addTime;
|
||||
public PacketTimeEntry(IPv6Packet packet) {
|
||||
super();
|
||||
this.packet = packet;
|
||||
this.addTime = System.nanoTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<Long,PacketTimeEntry>map=new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private long orderTime=System.nanoTime();
|
||||
@@ -27,7 +42,7 @@ public class SRv6PacketReorder {
|
||||
|
||||
public void put(IPv6Packet pack, long sequence) throws IOException {
|
||||
//System.out.println(pack.getFlowLabel()+" "+sequence);
|
||||
map.put(sequence,pack);
|
||||
map.put(sequence,new PacketTimeEntry(pack));
|
||||
runOrdering();
|
||||
}
|
||||
private ReentrantLock orderLock=new ReentrantLock();
|
||||
@@ -39,13 +54,13 @@ public class SRv6PacketReorder {
|
||||
whi=false;
|
||||
|
||||
while(true) {
|
||||
IPv6Packet i6p=map.remove(seqptr.get());
|
||||
PacketTimeEntry i6p=map.remove(seqptr.get());
|
||||
if(i6p!=null) {
|
||||
//System.out.println("Ord:"+i6p.getFlowLabel()+" "+seqptr.get());
|
||||
seqptr.getAndIncrement();
|
||||
orderTime=System.nanoTime();
|
||||
if(packetConsumer!=null) {
|
||||
packetConsumer.accept(i6p);
|
||||
packetConsumer.accept(i6p.packet);
|
||||
}
|
||||
}else {
|
||||
break;
|
||||
@@ -69,6 +84,12 @@ public class SRv6PacketReorder {
|
||||
}finally {
|
||||
orderLock.unlock();
|
||||
}
|
||||
for (Iterator<PacketTimeEntry> iterator = map.values().iterator(); iterator.hasNext();) {
|
||||
PacketTimeEntry type = (PacketTimeEntry) iterator.next();
|
||||
if(System.nanoTime()-type.addTime>maxCacheingTime) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ import com.google.gson.internal.Pair;
|
||||
public class SRv6Router {
|
||||
private static final boolean debug = false;
|
||||
|
||||
public static final int MTU = 8192;
|
||||
public static final int MTU = 16384;
|
||||
|
||||
public static final int MAX_REROUTE_COUNT=2;//1
|
||||
|
||||
@@ -417,7 +417,7 @@ public class SRv6Router {
|
||||
segmentsLeft--;
|
||||
}
|
||||
List<Inet6Address> repairSegments= klalbRouteProtol.createSegmentList(srh.getAddresses().get(segmentsLeft));
|
||||
if(repairSegments ==null) {
|
||||
if(repairSegments ==null||repairSegments.isEmpty()) {
|
||||
System.out.println("FRR保护失败");
|
||||
return;
|
||||
}
|
||||
@@ -589,15 +589,15 @@ public class SRv6Router {
|
||||
|
||||
}
|
||||
if(retry) {
|
||||
if(System.nanoTime()-start>200000000L) {
|
||||
if(System.nanoTime()-start>1000000L) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
/*try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Thread.yield();
|
||||
}*/
|
||||
Thread.yield();
|
||||
//短暂挂起当前线程,待链路速度未超限时重试发送数据包
|
||||
}
|
||||
}while((!routes.isEmpty())&&retry);
|
||||
@@ -713,6 +713,7 @@ public class SRv6Router {
|
||||
srhh.setSegmentsLeft(newSL);
|
||||
iPv6Packet.setDestinationAddress(srhh.getAddresses().get(newSL));
|
||||
}
|
||||
if(iPv6Packet.getPayload().getProtocolNumber()!=KLALBRoutingProtocol.DEFAULT_PROTOCOL_NUMBER)
|
||||
klalbRouteProtol.putHotspotAddress(iPv6Packet.getSourceAddress());
|
||||
routePacket(iPv6Packet,reroute);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user