forked from KNEMC/KLALB
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
455139dfe9
|
||
|
|
f0efa6d041 | ||
|
|
314f90b5f3 | ||
|
|
053450429c | ||
|
|
8dcdb08755 | ||
|
|
ba61d3b5ae | ||
|
|
74e4360d71 |
+1
-1
@@ -24,7 +24,7 @@
|
|||||||
<classpathentry kind="lib" path="lib/jctools-core-4.0.6.jar"/>
|
<classpathentry kind="lib" path="lib/jctools-core-4.0.6.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jctools-core-4.0.6-javadoc.jar"/>
|
<classpathentry kind="lib" path="lib/jctools-core-4.0.6-javadoc.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jctools-core-4.0.6-sources.jar"/>
|
<classpathentry kind="lib" path="lib/jctools-core-4.0.6-sources.jar"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-26.0.1">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-25">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
|||||||
@@ -14,4 +14,15 @@
|
|||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1787317094049</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
Vendored
+27
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "KLALBMain (VS Code 自动构建)",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "org.kne.cloud.network.klalb.KLALBMain",
|
||||||
|
"projectName": "KLALB",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"vmArgs": "--enable-native-access=ALL-UNNAMED --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "KLALBMain (直接用 bin 目录)",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "org.kne.cloud.network.klalb.KLALBMain",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"classPaths": [
|
||||||
|
"${workspaceFolder}/bin",
|
||||||
|
"${workspaceFolder}/src",
|
||||||
|
"${workspaceFolder}/lib/*"
|
||||||
|
],
|
||||||
|
"vmArgs": "--enable-native-access=ALL-UNNAMED --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"java.configuration.runtimes": [
|
||||||
|
{
|
||||||
|
"name": "JavaSE-25",
|
||||||
|
"path": "C:\\Program Files\\Eclipse Adoptium\\jdk-25.0.4.7-hotspot",
|
||||||
|
"default": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# AGENTS.md
|
||||||
|
|
||||||
|
KLALB ("KLALB Decentralized SRv6 Network") — Java load-balancing/tunnel system that merges multiple WAN links into one virtual IPv6/SRv6 network. Version constant lives in `src/org/kne/cloud/network/klalb/CONST.java`. Protocol specs and manuals are the Chinese `.docx` files in the repo root.
|
||||||
|
|
||||||
|
## Build & run
|
||||||
|
|
||||||
|
No Maven/Gradle. Plain Eclipse/IntelliJ project: dependencies are vendored jars in `lib/`, output goes to `bin/` (gitignored). When adding a jar, update **both** `.classpath` and `KLALB.iml`.
|
||||||
|
|
||||||
|
Compile (verified; `-encoding UTF-8` is mandatory — sources contain Chinese text):
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
& javac -encoding UTF-8 -cp "lib/*" -d bin (Get-ChildItem -Recurse src -Filter *.java | ForEach-Object FullName)
|
||||||
|
```
|
||||||
|
|
||||||
|
Run from the repo root — CWD matters:
|
||||||
|
- reads `klalb-config.json` from CWD
|
||||||
|
- loads native libs from CWD: `tuntap4j.dll/.so/.dylib`, `wintun.dll`, `fastcopy.dll` (TUN device support)
|
||||||
|
- classpath must include `src` as well as `bin`: i18n bundles (`/klalb_*.properties`) and images (`/assets/*`) are classpath resources that Eclipse copies to `bin` but manual `javac` does not
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
java --enable-native-access=ALL-UNNAMED "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED" -cp "bin;src;lib/*" org.kne.cloud.network.klalb.KLALBMain
|
||||||
|
```
|
||||||
|
|
||||||
|
IDE metadata targets JDK 26 (`jdk-26.0.1`); the tree also compiles cleanly on JDK 25. `.classpath` now references the standard container `JavaSE-25` — an execution-environment spec that any JDK ≥25 satisfies, so it works unchanged on JDK 26 machines too (the original named `jdk-26.0.1` VM broke VS Code import on machines without it). `.vscode/settings.json` maps `JavaSE-25` to the locally installed Adoptium JDK; register every installed JDK there when adding another one. Keep compiler compliance ≤25 (`.settings` pins 19) so both JDKs stay usable.
|
||||||
|
|
||||||
|
Runtime gotchas (all verified):
|
||||||
|
- On JDK 25, `KNEOptimize.jar`'s `FastLib` reflects into `jdk.internal.misc.Unsafe`; without the two JVM flags above it throws `InaccessibleObjectException` at startup (app still runs).
|
||||||
|
- Creating the SRv6 TUN adapter (`WintunCreateAdapter`) requires an elevated shell; without admin rights it logs "创建虚拟网卡失败" and continues with only the `inLoopBack` interface — links/bridges still work.
|
||||||
|
- To disable TUN creation completely (e.g. for non-admin UI/routing testing), set `"TUNName": null` in `klalb-config.json` or leave the TUN Name empty in GUI settings. If omitted, it defaults to `"KLALB_SRv6"`.
|
||||||
|
- Routing broadcast (`RouterInfo`) transmits `deviceName` across the network, which topology and node overview panels display. `deviceDescription` and `ExtraRoutes` remain local controller configs.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
No test suite, no CI. Classes named `*Test*` (`nathole/`, `ntp/`) are manual `main()` harnesses requiring real network peers. Practical check = compile succeeds + app launches.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
- Entrypoint `org.kne.cloud.network.klalb.KLALBMain`: load config → build `KLALBProxySystem` → open Swing GUI (`KLALBStateGUI3`) unless `"nogui": true` → interactive console (`help`, `links-state`, `route`, `kperf`, ...).
|
||||||
|
- `org.kne.cloud.network` — generic socket framework: `VirtualSocket*` hierarchy, `SocketBridge` port-forwarding proxies, `ProtocolDetector` (multi-protocol mux on one port), `MultiProtocolSocketAddress` = URI-style addresses (`tcp://`, `udp://`, `kltp://`, `ntp://`) dispatched through the `SocketType` registry.
|
||||||
|
- `...network.klalb` — app core: `KLALBController` (the virtual SRv6 network), `KLALBRemoteLink` (WAN lines), `*Packet` wire-format classes, virtual socket implementations.
|
||||||
|
- `...network.congestion` — pluggable congestion control (BBR, Vegas2, DCTCP...), chosen via `"congestionAlgorithm"` in config.
|
||||||
|
- `...network.kltp` — custom reliable transport protocol (packets/streams).
|
||||||
|
- `...network.ipv6`, `...network.srv6` — packet codecs, route table, Dijkstra path computation.
|
||||||
|
- `...network.frpc` — frp client integration.
|
||||||
|
- `...klalb.ui` — all Swing UI code.
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
`klalb-config.json` is an array of items discriminated by their `"Type"` field. Adding a new item type requires a `KLALBConfigItem` subclass **plus** new cases in both `KLALBConfigItem.getDefaultJsonDeserializer()` and `getDefaultJsonSerializer()`; unknown types are preserved as `UnknownKLALBConfigItem`. Any Gson instance handling config must register these adapters via `registerToGsonBuilder` (see `KLALBProxySystem`).
|
||||||
|
|
||||||
|
## Conventions
|
||||||
|
|
||||||
|
- Sources are UTF-8; comments, log/UI strings, and commit messages are largely Chinese.
|
||||||
|
- UI strings go through `UIEnv.getRsb().getString(...)`; add keys to **both** `src/klalb_zh_CN.properties` and `src/klalb_en_US.properties`.
|
||||||
|
- `client.cfg`, `server.cfg`, `linetable.txt` at the root are example line-table/port-rule files loaded via the GUI file picker — not hardwired paths.
|
||||||
+55
-71
@@ -2,121 +2,105 @@
|
|||||||
{
|
{
|
||||||
"language": "ZH_CN",
|
"language": "ZH_CN",
|
||||||
"nogui": false,
|
"nogui": false,
|
||||||
"VirtualAddress": "2486:1:0:0:0:0:0:8888",
|
"VirtualAddress": "2486:1:0:0:0:0:0:8889",
|
||||||
"VirtualASN": 2142606939373348329,
|
"VirtualASN": 2142606939373348329,
|
||||||
"DNS": [
|
"DNS": [
|
||||||
"2486:1:0:0:0:0:0:8888"
|
"2486:1:0:0:0:0:0:8888"
|
||||||
],
|
],
|
||||||
"TCPListen": "0.0.0.0:4565",
|
"TCPListen": "tcp://0.0.0.0:4565",
|
||||||
"UDPListen": "{UDP}0.0.0.0:4572",
|
"UDPListen": "udp://0.0.0.0:4572",
|
||||||
"VirtualSocketName": "KLALB_Stream",
|
"VirtualSocketName": "kltp",
|
||||||
"LineTable": [
|
"LineTable": [
|
||||||
"07f4acdef99b.ofalias.net:4565"
|
"tcp://kne03.yoyo250.fun:4565",
|
||||||
|
"tcp://kne04.yoyo250.fun:4565"
|
||||||
],
|
],
|
||||||
"ConnectLineTable": [
|
"ConnectLineTable": [
|
||||||
"home-ipv6.sliveridc1.cn:4565",
|
"tcp://07f4acdef99b.ofalias.net:4565",
|
||||||
"home-ltipv6.sliveridc1.cn:4565",
|
"tcp://kne01.yoyo250.fun:4565",
|
||||||
"cn-gd-gz.sliveridc1.cn:4565"
|
"tcp://kne02.yoyo250.fun:4565"
|
||||||
],
|
],
|
||||||
"ntpServerTable": [
|
"ntpServerTable": [
|
||||||
"{UDP}ntp1.aliyun.com:123",
|
"ntp://ntp1.aliyun.com",
|
||||||
"{UDP}ntp2.aliyun.com:123",
|
"ntp://ntp2.aliyun.com",
|
||||||
"{UDP}ntp3.aliyun.com:123",
|
"ntp://ntp3.aliyun.com",
|
||||||
"{UDP}ntp4.aliyun.com:123",
|
"ntp://ntp4.aliyun.com",
|
||||||
"{UDP}ntp5.aliyun.com:123",
|
"ntp://ntp5.aliyun.com",
|
||||||
"{UDP}ntp6.aliyun.com:123",
|
"ntp://ntp6.aliyun.com",
|
||||||
"{UDP}ntp7.aliyun.com:123",
|
"ntp://ntp7.aliyun.com",
|
||||||
"{UDP}ntp1.tencent.com:123",
|
"ntp://ntp1.tencent.com",
|
||||||
"{UDP}ntp2.tencent.com:123",
|
"ntp://ntp2.tencent.com",
|
||||||
"{UDP}ntp3.tencent.com:123",
|
"ntp://ntp4.tencent.com",
|
||||||
"{UDP}ntp4.tencent.com:123",
|
"ntp://ntp5.tencent.com",
|
||||||
"{UDP}ntp5.tencent.com:123",
|
"ntp://time.google.com",
|
||||||
"{UDP}time.google.com:123",
|
"ntp://time.apple.com",
|
||||||
"{UDP}time.apple.com:123",
|
"ntp://pool.ntp.org",
|
||||||
"{UDP}pool.ntp.org:123",
|
"ntp://ntp.ntsc.ac.cn",
|
||||||
"{UDP}ntp.ntsc.ac.cn:123",
|
"ntp://us.ntp.org.cn"
|
||||||
"{UDP}us.ntp.org.cn:123"
|
|
||||||
],
|
],
|
||||||
"denyLineTableQuery": true,
|
"ExtraRoutes": [],
|
||||||
"denyLineTableBroadcast": true,
|
"denyLineTableQuery": false,
|
||||||
|
"denyLineTableBroadcast": false,
|
||||||
"congestionAlgorithm": "BBR",
|
"congestionAlgorithm": "BBR",
|
||||||
"burstLimit": 1.5,
|
"burstLimit": 2.0,
|
||||||
"delayUpperBound": 1.3,
|
"delayUpperBound": 1.2,
|
||||||
"delayLowerBound": 1.3,
|
"delayLowerBound": 1.1,
|
||||||
"nagleDelayTime": 1000000,
|
"nagleDelayTime": 1000000,
|
||||||
"linkNagleDelayTime": 0,
|
"linkNagleDelayTime": 0,
|
||||||
"linkConnectionsCount": 1,
|
"linkConnectionsCount": 1,
|
||||||
"TUNName": "KLALB_SRv6",
|
"TUNName": null,
|
||||||
|
"performanceStrategy": "multiscatter",
|
||||||
|
"DeviceName": "SerinaNya PC",
|
||||||
|
"DeviceDescription": "desc",
|
||||||
"NetworkInterfaceExcepts": [],
|
"NetworkInterfaceExcepts": [],
|
||||||
"Type": "KLALBController"
|
"Type": "KLALBController"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Listen": "0.0.0.0:4572",
|
"Listen": "kltp://[::0]:5201",
|
||||||
"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": {
|
"Bridge": {
|
||||||
"DEFAULT": "SocketBridge"
|
"DEFAULT": "SocketBridge"
|
||||||
},
|
},
|
||||||
"Connect": {
|
"Connect": {
|
||||||
"DEFAULT": "127.0.0.1:5212"
|
"DEFAULT": "tcp://127.0.0.1:5201"
|
||||||
},
|
},
|
||||||
"Type": "SocketBridge"
|
"Type": "SocketBridge"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Listen": "{KLALB_Stream}[::0]:25565",
|
"Listen": "tcp://[::1]:5202",
|
||||||
"Bridge": {
|
"Bridge": {
|
||||||
"DEFAULT": "SocketBridge"
|
"DEFAULT": "SocketBridge"
|
||||||
},
|
},
|
||||||
"Connect": {
|
"Connect": {
|
||||||
"DEFAULT": "127.0.0.1:25566"
|
"DEFAULT": "kltp://[2486:5acd:e339:4837:a6d9:3aed:4de2:30fd]:5201"
|
||||||
},
|
},
|
||||||
"Type": "SocketBridge"
|
"Type": "SocketBridge"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Listen": "0.0.0.0:25561",
|
"Listen": "tcp://127.0.0.1:35000",
|
||||||
"Bridge": {
|
"Bridge": {
|
||||||
"KLALB": "SocketBridge",
|
"DEFAULT": "SocketBridge"
|
||||||
"DEFAULT": "MinecraftSocketBridge23330"
|
|
||||||
},
|
},
|
||||||
"Connect": {
|
"Connect": {
|
||||||
"KLALB": "127.0.0.1:4565",
|
"DEFAULT": "kltp://[2486:1::8888]:23333"
|
||||||
"DEFAULT": "127.0.0.1:25562"
|
|
||||||
},
|
},
|
||||||
"Type": "SocketBridge"
|
"Type": "SocketBridge"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Listen": "{KLALB_Stream}[::0]:23330",
|
"Listen": "kltp://[::0]:25565",
|
||||||
"Bridge": {
|
"Bridge": {
|
||||||
"DEFAULT": "MinecraftSocketBridge23330"
|
"DEFAULT": "SocketBridge"
|
||||||
},
|
},
|
||||||
"Connect": {
|
"Connect": {
|
||||||
"DEFAULT": "127.0.0.1:25562"
|
"DEFAULT": "tcp://127.0.0.1:25566"
|
||||||
|
},
|
||||||
|
"Type": "SocketBridge"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Listen": "tcp://127.0.0.1:35565",
|
||||||
|
"Bridge": {
|
||||||
|
"DEFAULT": "SocketBridge"
|
||||||
|
},
|
||||||
|
"Connect": {
|
||||||
|
"DEFAULT": "kltp://[2486:1::8888]:25565"
|
||||||
},
|
},
|
||||||
"Type": "SocketBridge"
|
"Type": "SocketBridge"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
virtualip=cefe:49b8:f837:4b00:b9cd:dbdd:c299:349
|
|
||||||
bind=0.0.0.0:4569
|
|
||||||
local=127.0.0.1:5212
|
|
||||||
@@ -3,7 +3,10 @@ networkgraph=Network graph
|
|||||||
language=Language
|
language=Language
|
||||||
basicsettings=Basic settings
|
basicsettings=Basic settings
|
||||||
ipv6addr=IPv6 address
|
ipv6addr=IPv6 address
|
||||||
|
devicename=Device name
|
||||||
|
devicedescription=Device description
|
||||||
dnsserver=DNS server
|
dnsserver=DNS server
|
||||||
|
extraroutes=Extra routes
|
||||||
asnumber=AS number
|
asnumber=AS number
|
||||||
tcplistening=TCP listening
|
tcplistening=TCP listening
|
||||||
udplistening=UDP listening
|
udplistening=UDP listening
|
||||||
@@ -34,6 +37,7 @@ saveconfigsuccess=Save config success
|
|||||||
warning=Warning
|
warning=Warning
|
||||||
invaildipv6addr=IPv6 address:Invaild Input
|
invaildipv6addr=IPv6 address:Invaild Input
|
||||||
invailddnsserver=DNS server:Invaild Input
|
invailddnsserver=DNS server:Invaild Input
|
||||||
|
invaildextraroutes=Extra routes:Invaild Input
|
||||||
invaildasnumber=AS number:Invaild Input
|
invaildasnumber=AS number:Invaild Input
|
||||||
invaildtcplisten=TCP listen:Invaild Input
|
invaildtcplisten=TCP listen:Invaild Input
|
||||||
invaildudplisten=UDP listen:Invaild Input
|
invaildudplisten=UDP listen:Invaild Input
|
||||||
@@ -105,3 +109,6 @@ uploadbasedelay=Upload Base
|
|||||||
burstlimit=Burst limit
|
burstlimit=Burst limit
|
||||||
performancesettings=Performance settings
|
performancesettings=Performance settings
|
||||||
performancestrategy=Performance strategy
|
performancestrategy=Performance strategy
|
||||||
|
singlecore=Single-Core - Cache Affinity First (Best energy/performance ratio, for low-power & cloud)
|
||||||
|
multifill=Multi-Core - Fill Cores Sequentially (Recommended for general-purpose physical servers)
|
||||||
|
multiscatter=Multi-Core - Spread Load Evenly (Optimized for multi-socket NUMA architectures)
|
||||||
@@ -3,7 +3,10 @@ networkgraph=网络拓扑图
|
|||||||
language=语言
|
language=语言
|
||||||
basicsettings=基本设置
|
basicsettings=基本设置
|
||||||
ipv6addr=IPv6地址
|
ipv6addr=IPv6地址
|
||||||
|
devicename=设备名称
|
||||||
|
devicedescription=设备描述
|
||||||
dnsserver=DNS服务器
|
dnsserver=DNS服务器
|
||||||
|
extraroutes=额外路由
|
||||||
asnumber=AS号码
|
asnumber=AS号码
|
||||||
tcplistening=TCP监听端口
|
tcplistening=TCP监听端口
|
||||||
udplistening=UDP监听端口
|
udplistening=UDP监听端口
|
||||||
@@ -34,6 +37,7 @@ saveconfigsuccess=保存配置成功
|
|||||||
warning=警告
|
warning=警告
|
||||||
invaildipv6addr=IPv6地址:非法输入
|
invaildipv6addr=IPv6地址:非法输入
|
||||||
invailddnsserver=DNS服务器:非法输入
|
invailddnsserver=DNS服务器:非法输入
|
||||||
|
invaildextraroutes=额外路由:非法输入
|
||||||
invaildasnumber=AS号码:非法输入
|
invaildasnumber=AS号码:非法输入
|
||||||
invaildtcplisten=TCP监听端口:非法输入
|
invaildtcplisten=TCP监听端口:非法输入
|
||||||
invaildudplisten=UDP监听端口:非法输入
|
invaildudplisten=UDP监听端口:非法输入
|
||||||
@@ -105,3 +109,6 @@ uploadbasedelay=上传延迟基线
|
|||||||
burstlimit=突发限制
|
burstlimit=突发限制
|
||||||
performancesettings=性能设置
|
performancesettings=性能设置
|
||||||
performancestrategy=性能策略
|
performancestrategy=性能策略
|
||||||
|
singlecore=单核-缓存命中率优先(高能耗比,适合低功耗设备、云机)
|
||||||
|
multifill=多核-负载按顺序填充(适合大多数物理服务器、电脑)
|
||||||
|
multiscatter=多核-负载均匀打散分配(适合特殊的多路NUMA服务器)
|
||||||
@@ -3,14 +3,9 @@ package org.kne.cloud.network;
|
|||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import javax.net.ServerSocketFactory;
|
|
||||||
|
|
||||||
public class DatagramSocketListener implements Closeable,AutoCloseable{
|
public class DatagramSocketListener implements Closeable,AutoCloseable{
|
||||||
private DatagramServerSocket serverSocket;
|
private DatagramServerSocket serverSocket;
|
||||||
public DatagramServerSocket getDatagramServerSocket() {
|
public DatagramServerSocket getDatagramServerSocket() {
|
||||||
@@ -36,10 +31,10 @@ public class DatagramSocketListener implements Closeable,AutoCloseable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private MultipurposeSocketAddress multipurposeSocketAddress;
|
private MultiProtocolSocketAddress multiProtocolSocketAddress;
|
||||||
|
|
||||||
public DatagramSocketListener(MultipurposeSocketAddress multipurposeSocketAddress) throws IOException {
|
public DatagramSocketListener(MultiProtocolSocketAddress multiProtocolSocketAddress) throws IOException {
|
||||||
this.multipurposeSocketAddress=multipurposeSocketAddress;
|
this.multiProtocolSocketAddress = multiProtocolSocketAddress;
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
public DatagramSocketListener(DatagramServerSocket tserverSocket) throws IOException {
|
public DatagramSocketListener(DatagramServerSocket tserverSocket) throws IOException {
|
||||||
@@ -49,7 +44,7 @@ public class DatagramSocketListener implements Closeable,AutoCloseable{
|
|||||||
|
|
||||||
private void open() throws IOException {
|
private void open() throws IOException {
|
||||||
if(serverSocket==null)
|
if(serverSocket==null)
|
||||||
serverSocket=multipurposeSocketAddress.listenDatagramServerSocket();
|
serverSocket= multiProtocolSocketAddress.listenDatagramServerSocket();
|
||||||
//new Thread(r).start();
|
//new Thread(r).start();
|
||||||
ThreadTool.makePThreadIfSupport("端口监听线程",r).start();
|
ThreadTool.makePThreadIfSupport("端口监听线程",r).start();
|
||||||
}
|
}
|
||||||
@@ -63,8 +58,8 @@ public class DatagramSocketListener implements Closeable,AutoCloseable{
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MultipurposeSocketAddress getMultipurposeSocketAddress() {
|
public MultiProtocolSocketAddress getMultipurposeSocketAddress() {
|
||||||
return multipurposeSocketAddress;
|
return multiProtocolSocketAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Consumer<DatagramSocket> getCon() {
|
public Consumer<DatagramSocket> getCon() {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package org.kne.cloud.network;
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class HostPortMap extends LinkedHashMap<String, MultipurposeSocketAddress> {
|
public class HostPortMap extends LinkedHashMap<String, MultiProtocolSocketAddress> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -11,9 +10,9 @@ public class HostPortMap extends LinkedHashMap<String, MultipurposeSocketAddress
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
public MultipurposeSocketAddress putN$H(String str) {
|
public MultiProtocolSocketAddress putN$H(String str) {
|
||||||
String[] strx=str.split("\\$");
|
String[] strx=str.split("\\$");
|
||||||
return super.put(strx[0], new MultipurposeSocketAddress( strx[1]));
|
return super.put(strx[0], new MultiProtocolSocketAddress( strx[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,8 @@ import java.io.DataInputStream;
|
|||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.*;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.MulticastSocket;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.NoRouteToHostException;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -29,12 +21,11 @@ public class IPMulticastDiscovery implements Closeable, AutoCloseable {
|
|||||||
private NetworkInterface ninterface;
|
private NetworkInterface ninterface;
|
||||||
private volatile boolean closed = false;
|
private volatile boolean closed = false;
|
||||||
private InetSocketAddress group;
|
private InetSocketAddress group;
|
||||||
private InetSocketAddress bind;
|
|
||||||
private int type;
|
private int type;
|
||||||
private List<MultipurposeSocketAddress> msas;
|
private List<MultiProtocolSocketAddress> msas;
|
||||||
private UUID selfUUID;
|
private UUID selfUUID;
|
||||||
|
|
||||||
private volatile Consumer<MultipurposeSocketAddress> con;
|
private volatile Consumer<MultiProtocolSocketAddress> con;
|
||||||
private long timeInterval;
|
private long timeInterval;
|
||||||
|
|
||||||
public long getTimeInterval() {
|
public long getTimeInterval() {
|
||||||
@@ -45,7 +36,7 @@ public class IPMulticastDiscovery implements Closeable, AutoCloseable {
|
|||||||
this.timeInterval = timeInterval;
|
this.timeInterval = timeInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkInterface getNinterface() {
|
public NetworkInterface getInterface() {
|
||||||
return ninterface;
|
return ninterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,22 +45,24 @@ public class IPMulticastDiscovery implements Closeable, AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InetSocketAddress getBind() {
|
public InetSocketAddress getBind() {
|
||||||
return bind;
|
return (InetSocketAddress) soc.getLocalSocketAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Consumer<MultipurposeSocketAddress> getCon() {
|
public Consumer<MultiProtocolSocketAddress> getCon() {
|
||||||
return con;
|
return con;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCon(Consumer<MultipurposeSocketAddress> con) {
|
public void setCon(Consumer<MultiProtocolSocketAddress> con) {
|
||||||
this.con = con;
|
this.con = con;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPMulticastDiscovery(InetSocketAddress bind, InetSocketAddress group, NetworkInterface ninterface,
|
public IPMulticastDiscovery(InetSocketAddress bind, InetSocketAddress group, NetworkInterface ninterface,
|
||||||
List<MultipurposeSocketAddress> msas,UUID node,long timeInterval) throws IOException {
|
List<MultiProtocolSocketAddress> msas, UUID node, long timeInterval) throws IOException {
|
||||||
soc = new MulticastSocket(bind);
|
soc = new MulticastSocket(null);
|
||||||
|
soc.setReuseAddress(true);
|
||||||
|
soc.bind(bind);
|
||||||
|
soc.setNetworkInterface(ninterface);
|
||||||
soc.joinGroup(group, ninterface);
|
soc.joinGroup(group, ninterface);
|
||||||
this.bind = bind;
|
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.ninterface = ninterface;
|
this.ninterface = ninterface;
|
||||||
this.msas = msas;
|
this.msas = msas;
|
||||||
@@ -82,46 +75,22 @@ public class IPMulticastDiscovery implements Closeable, AutoCloseable {
|
|||||||
ThreadTool.makeVDaemonThreadIfSupport("线路通知线程", () -> {
|
ThreadTool.makeVDaemonThreadIfSupport("线路通知线程", () -> {
|
||||||
try {
|
try {
|
||||||
while (!closed) {
|
while (!closed) {
|
||||||
HashSet<MultipurposeSocketAddress> s = new HashSet<MultipurposeSocketAddress>();
|
/*MultipurposeSocketAddress mpsa = new MultipurposeSocketAddress(
|
||||||
|
multipurposeSocketAddress.getType(), "::0", multipurposeSocketAddress.getPort());*/
|
||||||
|
if(msas!=null) {
|
||||||
synchronized (msas) {
|
synchronized (msas) {
|
||||||
for (Iterator<MultipurposeSocketAddress> iterator = msas.iterator(); iterator.hasNext();) {
|
for (Iterator<MultiProtocolSocketAddress> iterator = msas.iterator(); iterator.hasNext(); ) {
|
||||||
MultipurposeSocketAddress multipurposeSocketAddress = (MultipurposeSocketAddress) iterator
|
MultiProtocolSocketAddress multiProtocolSocketAddress = (MultiProtocolSocketAddress) iterator
|
||||||
.next();
|
.next();
|
||||||
|
|
||||||
MultipurposeSocketAddress mpsa = new MultipurposeSocketAddress(
|
|
||||||
multipurposeSocketAddress.getType(), "::0", multipurposeSocketAddress.getPort());
|
|
||||||
try {
|
try {
|
||||||
if (s.add(mpsa)) {
|
send(multiProtocolSocketAddress);
|
||||||
boolean bf = true;
|
} catch (NoRouteToHostException | UnknownHostException e) {
|
||||||
Enumeration<InetAddress> ei = ninterface.getInetAddresses();
|
|
||||||
while (ei.hasMoreElements()) {
|
|
||||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
|
||||||
if (inetAddress.equals(multipurposeSocketAddress.getInetAddress())) {
|
|
||||||
bf = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bf) {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dops = new DataOutputStream(baos);
|
|
||||||
dops.writeInt(multipurposeSocketAddress.getPort());
|
|
||||||
dops.writeUTF(multipurposeSocketAddress.getType());
|
|
||||||
dops.writeLong(selfUUID.getMostSignificantBits());
|
|
||||||
dops.writeLong(selfUUID.getLeastSignificantBits());
|
|
||||||
dops.close();
|
|
||||||
byte[] b = baos.toByteArray();
|
|
||||||
DatagramPacket dp = new DatagramPacket(b, b.length, group);
|
|
||||||
soc.send(dp);
|
|
||||||
if(debug)
|
|
||||||
System.out.println("发送广播:"+multipurposeSocketAddress+" "+group+" "+selfUUID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NoRouteToHostException|UnknownHostException e) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Thread.sleep(timeInterval);
|
Thread.sleep(timeInterval);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -143,27 +112,8 @@ public class IPMulticastDiscovery implements Closeable, AutoCloseable {
|
|||||||
try {
|
try {
|
||||||
loop:while (!closed) {
|
loop:while (!closed) {
|
||||||
try {
|
try {
|
||||||
byte[] b = new byte[65535];
|
MultiProtocolSocketAddress mpsa = receive();
|
||||||
DatagramPacket dp = new DatagramPacket(b, b.length);
|
if (mpsa == null) continue;
|
||||||
soc.receive(dp);
|
|
||||||
ByteArrayInputStream bis = new ByteArrayInputStream(b, 0, dp.getLength());
|
|
||||||
DataInputStream dis = new DataInputStream(bis);
|
|
||||||
int port = dis.readInt();
|
|
||||||
String type = dis.readUTF();
|
|
||||||
long h=dis.readLong();
|
|
||||||
long l=dis.readLong();
|
|
||||||
UUID uid=new UUID(h, l);
|
|
||||||
dis.close();
|
|
||||||
MultipurposeSocketAddress mpsa = new MultipurposeSocketAddress(type, dp.getAddress().getHostAddress(),
|
|
||||||
port);
|
|
||||||
if(debug) {
|
|
||||||
if(uid.equals(selfUUID)) {
|
|
||||||
System.out.println("丢弃广播:"+mpsa+" "+dp.getSocketAddress()+" "+uid);
|
|
||||||
continue;
|
|
||||||
}else {
|
|
||||||
System.out.println("接收广播:"+mpsa+" "+dp.getSocketAddress()+" "+uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
InetAddress mpsai=mpsa.getInetAddress();
|
InetAddress mpsai=mpsa.getInetAddress();
|
||||||
Enumeration<InetAddress> ei = ninterface.getInetAddresses();
|
Enumeration<InetAddress> ei = ninterface.getInetAddresses();
|
||||||
while (ei.hasMoreElements()) {
|
while (ei.hasMoreElements()) {
|
||||||
@@ -186,7 +136,7 @@ public class IPMulticastDiscovery implements Closeable, AutoCloseable {
|
|||||||
if(!isClosed())
|
if(!isClosed())
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}catch (IOException e) {
|
}catch (IOException e) {
|
||||||
System.out.println(bind + " " + group + " " + ninterface);
|
System.out.println(getBind() + " " + group + " " + ninterface);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
@@ -196,7 +146,48 @@ public class IPMulticastDiscovery implements Closeable, AutoCloseable {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MultiProtocolSocketAddress receive() throws IOException {
|
||||||
|
byte[] b = new byte[65535];
|
||||||
|
DatagramPacket dp = new DatagramPacket(b, b.length);
|
||||||
|
soc.receive(dp);
|
||||||
|
ByteArrayInputStream bis = new ByteArrayInputStream(b, 0, dp.getLength());
|
||||||
|
DataInputStream dis = new DataInputStream(bis);
|
||||||
|
String val = dis.readUTF();
|
||||||
|
long h=dis.readLong();
|
||||||
|
long l=dis.readLong();
|
||||||
|
UUID uid=new UUID(h, l);
|
||||||
|
dis.close();
|
||||||
|
MultiProtocolSocketAddress mpsa = new MultiProtocolSocketAddress(val);
|
||||||
|
if(mpsa.getInetAddress().isAnyLocalAddress()){
|
||||||
|
mpsa=new MultiProtocolSocketAddress(mpsa.getProtocol(),dp.getAddress().getHostAddress(),mpsa.getPort());
|
||||||
|
}
|
||||||
|
if(debug) {
|
||||||
|
if(uid.equals(selfUUID)) {
|
||||||
|
System.out.println(ninterface.getDisplayName()+" 丢弃广播:"+mpsa+" "+dp.getSocketAddress()+" "+uid);
|
||||||
|
return null;
|
||||||
|
}else {
|
||||||
|
System.out.println(ninterface.getDisplayName()+ " 接收广播:"+mpsa+" "+dp.getSocketAddress()+" "+uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mpsa;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void send(MultiProtocolSocketAddress multiProtocolSocketAddress) throws IOException {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream dops = new DataOutputStream(baos);
|
||||||
|
dops.writeUTF(multiProtocolSocketAddress.toString());
|
||||||
|
dops.writeLong(selfUUID.getMostSignificantBits());
|
||||||
|
dops.writeLong(selfUUID.getLeastSignificantBits());
|
||||||
|
dops.close();
|
||||||
|
byte[] b = baos.toByteArray();
|
||||||
|
DatagramPacket dp = new DatagramPacket(b, b.length, group);
|
||||||
|
soc.send(dp);
|
||||||
|
if(debug)
|
||||||
|
System.out.println(ninterface.getDisplayName()+" 发送广播:"+ multiProtocolSocketAddress +" "+group+" "+selfUUID);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+101
-95
@@ -3,14 +3,7 @@ package org.kne.cloud.network;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.net.DatagramSocket;
|
import java.net.*;
|
||||||
import java.net.Inet6Address;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -18,7 +11,6 @@ import java.util.*;
|
|||||||
import javax.net.ServerSocketFactory;
|
import javax.net.ServerSocketFactory;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
@@ -27,17 +19,18 @@ import com.google.gson.JsonParseException;
|
|||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializationContext;
|
||||||
import com.google.gson.JsonSerializer;
|
import com.google.gson.JsonSerializer;
|
||||||
|
import org.kne.cloud.network.ntp.NTPSocketType;
|
||||||
|
|
||||||
public class MultipurposeSocketAddress implements Serializable{
|
public class MultiProtocolSocketAddress implements Serializable{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final Map<String,SocketType> socketTypeRegister=new HashMap<>();
|
private static final Map<String,SocketType> socketTypeRegister=new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
socketTypeRegister.put("TCP", new SocketType(new DefaultSocketFactory(), new DefaultServerSocketFactory(),new DefaultSocketChannelFactory(),new DefaultServerSocketChannelFactory()));
|
socketTypeRegister.put("tcp", TCPSocketType.getInstance());
|
||||||
socketTypeRegister.put("UDP", new SocketType(new DefaultDatagramSocketFactory(),new DefaultDatagramServerSocketFactory()));
|
socketTypeRegister.put("udp", UDPSocketType.getInstance());
|
||||||
|
socketTypeRegister.put("ntp", NTPSocketType.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -46,46 +39,59 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return socketTypeRegister;
|
return socketTypeRegister;
|
||||||
}
|
}
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private String type;
|
private String protocol;
|
||||||
private String host;
|
private String host;
|
||||||
private ProtocolStack ps=new ProtocolStack();
|
private ProtocolStack ps=new ProtocolStack();
|
||||||
|
|
||||||
|
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
public MultipurposeSocketAddress(String hostport) {
|
public MultiProtocolSocketAddress(String hostport) {
|
||||||
this(hostport,"TCP");
|
this(hostport,"tcp");
|
||||||
}
|
}
|
||||||
public MultipurposeSocketAddress(String hostport,String defaulttype) {
|
public MultiProtocolSocketAddress(String hostport, String defaultprotocol) {
|
||||||
hostport=hostport.trim();
|
try {
|
||||||
if (hostport.startsWith("{")) {
|
if (!hostport.contains("://")) {
|
||||||
int i=hostport.indexOf("}");
|
hostport = defaultprotocol.toLowerCase() + "://" + hostport;
|
||||||
if(i==-1) {
|
|
||||||
throw new IllegalArgumentException("missing }");
|
|
||||||
}
|
}
|
||||||
type=hostport.substring(1, i);
|
URI uri = new URI(hostport);
|
||||||
hostport=hostport.substring(i+1);
|
|
||||||
}else {
|
this.protocol = uri.getScheme().toLowerCase();
|
||||||
type=defaulttype;
|
this.host = uri.getHost();
|
||||||
|
if (this.host == null) {
|
||||||
|
throw new IllegalArgumentException("无效的主机地址: " + hostport);
|
||||||
}
|
}
|
||||||
int index =hostport.lastIndexOf(":");
|
this.port = resolvePort(uri, this.protocol);
|
||||||
host=hostport.substring(0,index);
|
|
||||||
host=host.replace("[", "");
|
// 可选:处理查询参数
|
||||||
host=host.replace("]", "");
|
String query = uri.getQuery();
|
||||||
String tps=hostport.substring(index+1);
|
if (query != null && !query.isEmpty()) {
|
||||||
int v=tps.indexOf("(");
|
// 解析查询参数作为扩展信息
|
||||||
if(v!=-1) {
|
|
||||||
ps.add(new Protocol(tps.substring(v+1,tps.lastIndexOf(")") )));
|
|
||||||
tps=tps.substring(0, v);
|
|
||||||
}
|
}
|
||||||
port=Integer.parseInt(tps);
|
} catch (URISyntaxException e) {
|
||||||
if(port<0) {
|
throw new IllegalArgumentException("无效的地址格式: " + hostport, e);
|
||||||
throw new IllegalArgumentException("port < 0");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int resolvePort(URI uri, String protocol) {
|
||||||
|
int port = uri.getPort();
|
||||||
|
if (port != -1) {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
SocketType socketType = socketTypeRegister.get(protocol);
|
||||||
|
if (socketType != null) {
|
||||||
|
int defaultPort = socketType.getDefaultPort();
|
||||||
|
if (defaultPort != -1) {
|
||||||
|
return defaultPort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"未指定端口号,且协议 " + protocol + " 没有默认端口: " + uri
|
||||||
|
);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(host, port, ps, type);
|
return Objects.hash(host, port, ps, protocol);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
@@ -95,9 +101,9 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
MultipurposeSocketAddress other = (MultipurposeSocketAddress) obj;
|
MultiProtocolSocketAddress other = (MultiProtocolSocketAddress) obj;
|
||||||
return Objects.equals(host, other.host) && port == other.port && Objects.equals(ps, other.ps)
|
return Objects.equals(host, other.host) && port == other.port && Objects.equals(ps, other.ps)
|
||||||
&& Objects.equals(type, other.type);
|
&& Objects.equals(protocol, other.protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals2(Object obj) {
|
public boolean equals2(Object obj) {
|
||||||
@@ -107,7 +113,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
MultipurposeSocketAddress other = (MultipurposeSocketAddress) obj;
|
MultiProtocolSocketAddress other = (MultiProtocolSocketAddress) obj;
|
||||||
InetAddress addra=null;
|
InetAddress addra=null;
|
||||||
try {
|
try {
|
||||||
addra = InetAddress.getByName(host);
|
addra = InetAddress.getByName(host);
|
||||||
@@ -121,25 +127,25 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
boolean hostequals=Objects.equals(addra, addrb);
|
boolean hostequals=Objects.equals(addra, addrb);
|
||||||
|
|
||||||
return hostequals && port == other.port && Objects.equals(ps, other.ps)
|
return hostequals && port == other.port && Objects.equals(ps, other.ps)
|
||||||
&& Objects.equals(type, other.type);
|
&& Objects.equals(protocol, other.protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress(String host2, int port2) {
|
public MultiProtocolSocketAddress(String host2, int port2) {
|
||||||
this("TCP", host2, port2);
|
this("tcp", host2, port2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress(String type,String host2, int port2) {
|
public MultiProtocolSocketAddress(String protocol, String host2, int port2) {
|
||||||
host=host2;
|
host=host2;
|
||||||
port=port2;
|
port=port2;
|
||||||
this.type=type;
|
this.protocol = protocol;
|
||||||
}
|
}
|
||||||
public MultipurposeSocketAddress(InetSocketAddress remoteSocketAddress) {
|
public MultiProtocolSocketAddress(InetSocketAddress remoteSocketAddress) {
|
||||||
this("TCP",remoteSocketAddress);
|
this("tcp",remoteSocketAddress);
|
||||||
}
|
}
|
||||||
public MultipurposeSocketAddress(String type,InetSocketAddress remoteSocketAddress) {
|
public MultiProtocolSocketAddress(String protocol, InetSocketAddress remoteSocketAddress) {
|
||||||
host=remoteSocketAddress.getAddress().getHostAddress();
|
host=remoteSocketAddress.getAddress().getHostAddress();
|
||||||
port=remoteSocketAddress.getPort();
|
port=remoteSocketAddress.getPort();
|
||||||
this.type=type;
|
this.protocol = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -149,8 +155,8 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
public String getType() {
|
public String getProtocol() {
|
||||||
return type;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetSocketAddress getSocketAddress() {
|
public InetSocketAddress getSocketAddress() {
|
||||||
@@ -159,27 +165,25 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb=new StringBuilder();
|
try {
|
||||||
if(!"TCP".equals(type)) {
|
// 获取协议的默认端口
|
||||||
sb.append('{').append(type).append('}');
|
SocketType socketType = socketTypeRegister.get(protocol);
|
||||||
}
|
int defaultPort = (socketType != null) ? socketType.getDefaultPort() : -1;
|
||||||
if(host.contains(":")) {
|
|
||||||
sb.append('[').append( host).append( "]:").append( port);
|
|
||||||
}else {
|
|
||||||
sb.append( host).append( ':').append( port);
|
|
||||||
}
|
|
||||||
if(!ps.isEmpty()) {
|
|
||||||
sb.append('(').append(ps.pop().getName()).append(')');
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 如果当前端口等于默认端口,则隐去端口号
|
||||||
|
int portToUse = (defaultPort != -1 && this.port == defaultPort) ? -1 : this.port;
|
||||||
|
|
||||||
|
URI uri = new URI(protocol, null, host, portToUse, null, null, null);
|
||||||
|
return uri.toString();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
return protocol + "://" + host + ":" + port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Socket connectSocket(InetAddress bindip,int bindport,int timeout) throws UnknownHostException, IOException {
|
public Socket connectSocket(InetAddress bindip,int bindport,int timeout) throws UnknownHostException, IOException {
|
||||||
SocketFactory sf=socketTypeRegister.get(type).getSocketFactory();
|
SocketFactory sf=socketTypeRegister.get(protocol).getSocketFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -194,7 +198,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
public Socket connectSocket(InetAddress bindip,int bindport) throws UnknownHostException, IOException {
|
public Socket connectSocket(InetAddress bindip,int bindport) throws UnknownHostException, IOException {
|
||||||
SocketFactory sf=socketTypeRegister.get(type).getSocketFactory();
|
SocketFactory sf=socketTypeRegister.get(protocol).getSocketFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -209,7 +213,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
public Socket connectSocket() throws UnknownHostException, IOException {
|
public Socket connectSocket() throws UnknownHostException, IOException {
|
||||||
SocketFactory sf=socketTypeRegister.get(type).getSocketFactory();
|
SocketFactory sf=socketTypeRegister.get(protocol).getSocketFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -223,7 +227,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
public Socket connectSocket(int timeout) throws UnknownHostException, IOException {
|
public Socket connectSocket(int timeout) throws UnknownHostException, IOException {
|
||||||
SocketFactory sf=socketTypeRegister.get(type).getSocketFactory();
|
SocketFactory sf=socketTypeRegister.get(protocol).getSocketFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -244,7 +248,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
|
|
||||||
|
|
||||||
public SocketChannel connectSocketChannel(InetAddress bindip,int bindport,int timeout) throws UnknownHostException, IOException {
|
public SocketChannel connectSocketChannel(InetAddress bindip,int bindport,int timeout) throws UnknownHostException, IOException {
|
||||||
SocketChannelFactory sf=socketTypeRegister.get(type).getSocketChannelFactory();
|
SocketChannelFactory sf=socketTypeRegister.get(protocol).getSocketChannelFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -265,7 +269,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
public SocketChannel connectSocketChannel(InetAddress bindip,int bindport) throws UnknownHostException, IOException {
|
public SocketChannel connectSocketChannel(InetAddress bindip,int bindport) throws UnknownHostException, IOException {
|
||||||
SocketChannelFactory sf=socketTypeRegister.get(type).getSocketChannelFactory();
|
SocketChannelFactory sf=socketTypeRegister.get(protocol).getSocketChannelFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -280,7 +284,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
public SocketChannel connectSocketChannel() throws UnknownHostException, IOException {
|
public SocketChannel connectSocketChannel() throws UnknownHostException, IOException {
|
||||||
SocketChannelFactory sf=socketTypeRegister.get(type).getSocketChannelFactory();
|
SocketChannelFactory sf=socketTypeRegister.get(protocol).getSocketChannelFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -294,7 +298,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
public SocketChannel connectSocketChannel(int timeout) throws UnknownHostException, IOException {
|
public SocketChannel connectSocketChannel(int timeout) throws UnknownHostException, IOException {
|
||||||
SocketChannelFactory sf=socketTypeRegister.get(type).getSocketChannelFactory();
|
SocketChannelFactory sf=socketTypeRegister.get(protocol).getSocketChannelFactory();
|
||||||
if(sf==null) {
|
if(sf==null) {
|
||||||
throw new UnsupportedOperationException("Socket Unsupported");
|
throw new UnsupportedOperationException("Socket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -319,7 +323,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
|
|
||||||
|
|
||||||
public ServerSocket listenServerSocket() throws UnknownHostException, IOException {
|
public ServerSocket listenServerSocket() throws UnknownHostException, IOException {
|
||||||
ServerSocketFactory srf=socketTypeRegister.get(type).getServerSocketFactory();
|
ServerSocketFactory srf=socketTypeRegister.get(protocol).getServerSocketFactory();
|
||||||
if(srf==null) {
|
if(srf==null) {
|
||||||
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -327,7 +331,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return sk;
|
return sk;
|
||||||
}
|
}
|
||||||
public ServerSocket listenServerSocket(int backlog) throws UnknownHostException, IOException {
|
public ServerSocket listenServerSocket(int backlog) throws UnknownHostException, IOException {
|
||||||
ServerSocketFactory srf=socketTypeRegister.get(type).getServerSocketFactory();
|
ServerSocketFactory srf=socketTypeRegister.get(protocol).getServerSocketFactory();
|
||||||
if(srf==null) {
|
if(srf==null) {
|
||||||
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -337,7 +341,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
|
|
||||||
|
|
||||||
public ServerSocketChannel listenServerSocketChannel() throws UnknownHostException, IOException {
|
public ServerSocketChannel listenServerSocketChannel() throws UnknownHostException, IOException {
|
||||||
ServerSocketChannelFactory srf=socketTypeRegister.get(type).getServerSocketChannelFactory();
|
ServerSocketChannelFactory srf=socketTypeRegister.get(protocol).getServerSocketChannelFactory();
|
||||||
if(srf==null) {
|
if(srf==null) {
|
||||||
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -345,7 +349,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return sk;
|
return sk;
|
||||||
}
|
}
|
||||||
public ServerSocketChannel listenServerSocketChannel(int backlog) throws UnknownHostException, IOException {
|
public ServerSocketChannel listenServerSocketChannel(int backlog) throws UnknownHostException, IOException {
|
||||||
ServerSocketChannelFactory srf=socketTypeRegister.get(type).getServerSocketChannelFactory();
|
ServerSocketChannelFactory srf=socketTypeRegister.get(protocol).getServerSocketChannelFactory();
|
||||||
if(srf==null) {
|
if(srf==null) {
|
||||||
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
throw new UnsupportedOperationException("ServerSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -355,13 +359,13 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
|
|
||||||
|
|
||||||
public boolean isStream() {
|
public boolean isStream() {
|
||||||
return checkIsStream(type);
|
return checkIsStream(protocol);
|
||||||
}
|
}
|
||||||
public static boolean checkIsStream(String type2) {
|
public static boolean checkIsStream(String type2) {
|
||||||
return socketTypeRegister.get(type2).isStream();
|
return socketTypeRegister.get(type2).isStream();
|
||||||
}
|
}
|
||||||
public DatagramSocket connectDatagramSocket(InetAddress bindip,int bindport) throws IOException {
|
public DatagramSocket connectDatagramSocket(InetAddress bindip,int bindport) throws IOException {
|
||||||
DatagramSocketFactory dgs=socketTypeRegister.get(type).getDatagramSocketFactory();
|
DatagramSocketFactory dgs=socketTypeRegister.get(protocol).getDatagramSocketFactory();
|
||||||
if(dgs==null) {
|
if(dgs==null) {
|
||||||
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -376,7 +380,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return dgd;
|
return dgd;
|
||||||
}
|
}
|
||||||
public DatagramSocket connectDatagramSocket() throws IOException {
|
public DatagramSocket connectDatagramSocket() throws IOException {
|
||||||
DatagramSocketFactory dgs=socketTypeRegister.get(type).getDatagramSocketFactory();
|
DatagramSocketFactory dgs=socketTypeRegister.get(protocol).getDatagramSocketFactory();
|
||||||
if(dgs==null) {
|
if(dgs==null) {
|
||||||
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -390,7 +394,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return dgd;
|
return dgd;
|
||||||
}
|
}
|
||||||
public DatagramSocket listenDatagramSocket() throws UnknownHostException, IOException {
|
public DatagramSocket listenDatagramSocket() throws UnknownHostException, IOException {
|
||||||
DatagramSocketFactory dgs=socketTypeRegister.get(type).getDatagramSocketFactory();
|
DatagramSocketFactory dgs=socketTypeRegister.get(protocol).getDatagramSocketFactory();
|
||||||
if(dgs==null) {
|
if(dgs==null) {
|
||||||
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
throw new UnsupportedOperationException("DatagramSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -405,7 +409,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DatagramServerSocket listenDatagramServerSocket() throws UnknownHostException, IOException {
|
public DatagramServerSocket listenDatagramServerSocket() throws UnknownHostException, IOException {
|
||||||
DatagramServerSocketFactory srf=socketTypeRegister.get(type).getDatagramServerSocketFactory();
|
DatagramServerSocketFactory srf=socketTypeRegister.get(protocol).getDatagramServerSocketFactory();
|
||||||
if(srf==null) {
|
if(srf==null) {
|
||||||
throw new UnsupportedOperationException("DatagramServerSocket Unsupported");
|
throw new UnsupportedOperationException("DatagramServerSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -413,7 +417,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return sk;
|
return sk;
|
||||||
}
|
}
|
||||||
public DatagramServerSocket listenDatagramServerSocket(int backlog) throws UnknownHostException, IOException {
|
public DatagramServerSocket listenDatagramServerSocket(int backlog) throws UnknownHostException, IOException {
|
||||||
DatagramServerSocketFactory srf=socketTypeRegister.get(type).getDatagramServerSocketFactory();
|
DatagramServerSocketFactory srf=socketTypeRegister.get(protocol).getDatagramServerSocketFactory();
|
||||||
if(srf==null) {
|
if(srf==null) {
|
||||||
throw new UnsupportedOperationException("DatagramServerSocket Unsupported");
|
throw new UnsupportedOperationException("DatagramServerSocket Unsupported");
|
||||||
}
|
}
|
||||||
@@ -427,7 +431,7 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
return InetAddress.getAllByName(host);
|
return InetAddress.getAllByName(host);
|
||||||
}
|
}
|
||||||
public boolean supportNIO() {
|
public boolean supportNIO() {
|
||||||
SocketType stp= socketTypeRegister.get(getType());
|
SocketType stp= socketTypeRegister.get(getProtocol());
|
||||||
if(stp==null)
|
if(stp==null)
|
||||||
return false;
|
return false;
|
||||||
if(stp.getSocketChannelFactory()==null) {
|
if(stp.getSocketChannelFactory()==null) {
|
||||||
@@ -437,35 +441,37 @@ public class MultipurposeSocketAddress implements Serializable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonDeserializer<MultipurposeSocketAddress>getDefaultJsonDeserializer(){
|
public static JsonDeserializer<MultiProtocolSocketAddress>getDefaultJsonDeserializer(){
|
||||||
return new JsonDeserializer<MultipurposeSocketAddress>() {
|
return new JsonDeserializer<MultiProtocolSocketAddress>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultipurposeSocketAddress deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
|
public MultiProtocolSocketAddress deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
if(arg0.isJsonPrimitive()) {
|
if(arg0.isJsonPrimitive()) {
|
||||||
JsonPrimitive jp=(JsonPrimitive) arg0;
|
JsonPrimitive jp=(JsonPrimitive) arg0;
|
||||||
if(jp.isString()) {
|
if(jp.isString()) {
|
||||||
return new MultipurposeSocketAddress(jp.getAsString());
|
MultiProtocolSocketAddress msa=new MultiProtocolSocketAddress(jp.getAsString());
|
||||||
|
// System.out.println(msa);
|
||||||
|
return msa;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new JsonParseException("not a string:"+arg0);
|
throw new JsonParseException("not a string:"+arg0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static JsonSerializer<MultipurposeSocketAddress>getDefaultJsonSerializer(){
|
public static JsonSerializer<MultiProtocolSocketAddress>getDefaultJsonSerializer(){
|
||||||
return new JsonSerializer<MultipurposeSocketAddress>() {
|
return new JsonSerializer<MultiProtocolSocketAddress>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement serialize(MultipurposeSocketAddress arg0, Type arg1, JsonSerializationContext arg2) {
|
public JsonElement serialize(MultiProtocolSocketAddress arg0, Type arg1, JsonSerializationContext arg2) {
|
||||||
return new JsonPrimitive(arg0.toString());
|
return new JsonPrimitive(arg0.toString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerToGsonBuilder(GsonBuilder gsonBuilder) {
|
public static void registerToGsonBuilder(GsonBuilder gsonBuilder) {
|
||||||
gsonBuilder.registerTypeAdapter(MultipurposeSocketAddress.class, getDefaultJsonDeserializer());
|
gsonBuilder.registerTypeAdapter(MultiProtocolSocketAddress.class, getDefaultJsonDeserializer());
|
||||||
gsonBuilder.registerTypeAdapter(MultipurposeSocketAddress.class, getDefaultJsonSerializer());
|
gsonBuilder.registerTypeAdapter(MultiProtocolSocketAddress.class, getDefaultJsonSerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package org.kne.cloud.network;
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
public interface NetworkService {
|
public interface NetworkService {
|
||||||
public void listen(MultipurposeSocketAddress msa);
|
public void listen(MultiProtocolSocketAddress msa);
|
||||||
public void unlisten(MultipurposeSocketAddress msc);
|
public void unlisten(MultiProtocolSocketAddress msc);
|
||||||
|
|
||||||
public void connect(MultipurposeSocketAddress msa);
|
public void connect(MultiProtocolSocketAddress msa);
|
||||||
public void unconnect(MultipurposeSocketAddress msc);
|
public void unconnect(MultiProtocolSocketAddress msc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
package org.kne.cloud.network;
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.channels.*;
|
|
||||||
import java.nio.channels.spi.AbstractInterruptibleChannel;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class PortRelay {
|
public class PortRelay {
|
||||||
private int port;
|
private int port;
|
||||||
@@ -16,8 +10,8 @@ public class PortRelay {
|
|||||||
public PortRelay(int port, HostPortMap services) throws IOException {
|
public PortRelay(int port, HostPortMap services) throws IOException {
|
||||||
this.services = services;
|
this.services = services;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
MultipurposeSocketAddress.getSocketTypeRegister().put("ProtocolDetectorServerSocket",new SocketType(null, new ProtocolDetectorServerSocketFactory()) );
|
MultiProtocolSocketAddress.getSocketTypeRegister().put("ProtocolDetectorServerSocket",new SocketType(null, new ProtocolDetectorServerSocketFactory()) );
|
||||||
ssc=new SocketListener(new MultipurposeSocketAddress("ProtocolDetectorServerSocket", "0.0.0.0", port));
|
ssc=new SocketListener(new MultiProtocolSocketAddress("ProtocolDetectorServerSocket", "0.0.0.0", port));
|
||||||
}
|
}
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
ssc.setCon((s)->{
|
ssc.setCon((s)->{
|
||||||
@@ -30,7 +24,7 @@ public class PortRelay {
|
|||||||
}else {
|
}else {
|
||||||
nx=pds.getProtocolStack().pop().getName();
|
nx=pds.getProtocolStack().pop().getName();
|
||||||
}
|
}
|
||||||
MultipurposeSocketAddress hp=services.get(nx);
|
MultiProtocolSocketAddress hp=services.get(nx);
|
||||||
InetSocketAddress sa=(InetSocketAddress) s.getRemoteSocketAddress();
|
InetSocketAddress sa=(InetSocketAddress) s.getRemoteSocketAddress();
|
||||||
System.out.println(sa.getAddress().getHostAddress() + ":" + port
|
System.out.println(sa.getAddress().getHostAddress() + ":" + port
|
||||||
+ "-" + "(" + nx + ")->" + hp.getHost() + ":" + hp.getPort());
|
+ "-" + "(" + nx + ")->" + hp.getHost() + ":" + hp.getPort());
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
package org.kne.cloud.network;
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ServiceElement {
|
public class ServiceElement {
|
||||||
public String name;
|
public String name;
|
||||||
public String protocol;
|
public String protocol;
|
||||||
public MultipurposeSocketAddress ipport;
|
public MultiProtocolSocketAddress ipport;
|
||||||
public ServiceElement(String ini) throws UnknownHostException {
|
public ServiceElement(String ini) throws UnknownHostException {
|
||||||
String[]t=ini.split("\\$");
|
String[]t=ini.split("\\$");
|
||||||
if(t.length==1) {
|
if(t.length==1) {
|
||||||
protocol="";
|
protocol="";
|
||||||
ipport=new MultipurposeSocketAddress(t[0]);
|
ipport=new MultiProtocolSocketAddress(t[0]);
|
||||||
}else {
|
}else {
|
||||||
protocol=t[0];
|
protocol=t[0];
|
||||||
ipport=new MultipurposeSocketAddress(t[1]);
|
ipport=new MultiProtocolSocketAddress(t[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public ServiceElement() {
|
public ServiceElement() {
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
package org.kne.cloud.network;
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class ServiceToSocketProxy extends Proxy{
|
public class ServiceToSocketProxy extends Proxy{
|
||||||
public NetworkService getSrc() {
|
public NetworkService getSrc() {
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
public MultipurposeSocketAddress getDes() {
|
public MultiProtocolSocketAddress getDes() {
|
||||||
return des;
|
return des;
|
||||||
}
|
}
|
||||||
public ServiceToSocketProxy(String l, String r) {
|
public ServiceToSocketProxy(String l, String r) {
|
||||||
src=getRegister().get(l.substring(1, l.length()-1));
|
src=getRegister().get(l.substring(1, l.length()-1));
|
||||||
des=new MultipurposeSocketAddress(r);
|
des=new MultiProtocolSocketAddress(r);
|
||||||
}
|
}
|
||||||
private NetworkService src;
|
private NetworkService src;
|
||||||
private MultipurposeSocketAddress des;
|
private MultiProtocolSocketAddress des;
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
// TODO 自动生成的方法存根
|
// TODO 自动生成的方法存根
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ public class SocketChannelListener implements Closeable,AutoCloseable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private MultipurposeSocketAddress multipurposeSocketAddress;
|
private MultiProtocolSocketAddress multiProtocolSocketAddress;
|
||||||
|
|
||||||
public SocketChannelListener(MultipurposeSocketAddress multipurposeSocketAddress) throws IOException {
|
public SocketChannelListener(MultiProtocolSocketAddress multiProtocolSocketAddress) throws IOException {
|
||||||
this.multipurposeSocketAddress=multipurposeSocketAddress;
|
this.multiProtocolSocketAddress = multiProtocolSocketAddress;
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
public SocketChannelListener(ServerSocketChannel tserverSocket) throws IOException {
|
public SocketChannelListener(ServerSocketChannel tserverSocket) throws IOException {
|
||||||
@@ -62,9 +62,9 @@ public class SocketChannelListener implements Closeable,AutoCloseable{
|
|||||||
}
|
}
|
||||||
protected void open() throws UnknownHostException, IOException {
|
protected void open() throws UnknownHostException, IOException {
|
||||||
if(serverSocketChannel==null)
|
if(serverSocketChannel==null)
|
||||||
serverSocketChannel=multipurposeSocketAddress.listenServerSocketChannel();
|
serverSocketChannel= multiProtocolSocketAddress.listenServerSocketChannel();
|
||||||
if(serverSocketChannel==null) {
|
if(serverSocketChannel==null) {
|
||||||
throw new IOException(multipurposeSocketAddress.getType()+" unsupport SocketChannel");
|
throw new IOException(multiProtocolSocketAddress.getProtocol()+" unsupport SocketChannel");
|
||||||
}
|
}
|
||||||
ThreadTool.makeVThread("端口监听线程", r).start();
|
ThreadTool.makeVThread("端口监听线程", r).start();
|
||||||
}
|
}
|
||||||
@@ -82,8 +82,8 @@ public class SocketChannelListener implements Closeable,AutoCloseable{
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MultipurposeSocketAddress getMultipurposeSocketAddress() {
|
public MultiProtocolSocketAddress getMultipurposeSocketAddress() {
|
||||||
return multipurposeSocketAddress;
|
return multiProtocolSocketAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Consumer<SocketChannel> getCon() {
|
public Consumer<SocketChannel> getCon() {
|
||||||
|
|||||||
@@ -2,15 +2,12 @@ package org.kne.cloud.network;
|
|||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import javax.net.ServerSocketFactory;
|
|
||||||
|
|
||||||
public class SocketListener implements Closeable,AutoCloseable{
|
public class SocketListener implements Closeable,AutoCloseable{
|
||||||
protected ServerSocket serverSocket;
|
protected ServerSocket serverSocket;
|
||||||
public ServerSocket getServerSocket() {
|
public ServerSocket getServerSocket() {
|
||||||
@@ -53,10 +50,10 @@ public class SocketListener implements Closeable,AutoCloseable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private MultipurposeSocketAddress multipurposeSocketAddress;
|
private MultiProtocolSocketAddress multiProtocolSocketAddress;
|
||||||
|
|
||||||
public SocketListener(MultipurposeSocketAddress multipurposeSocketAddress) throws IOException {
|
public SocketListener(MultiProtocolSocketAddress multiProtocolSocketAddress) throws IOException {
|
||||||
this.multipurposeSocketAddress=multipurposeSocketAddress;
|
this.multiProtocolSocketAddress = multiProtocolSocketAddress;
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
public SocketListener(ServerSocket tserverSocket) throws IOException {
|
public SocketListener(ServerSocket tserverSocket) throws IOException {
|
||||||
@@ -65,7 +62,7 @@ public class SocketListener implements Closeable,AutoCloseable{
|
|||||||
}
|
}
|
||||||
protected void open() throws UnknownHostException, IOException {
|
protected void open() throws UnknownHostException, IOException {
|
||||||
if(serverSocket==null)
|
if(serverSocket==null)
|
||||||
serverSocket=multipurposeSocketAddress.listenServerSocket();
|
serverSocket= multiProtocolSocketAddress.listenServerSocket();
|
||||||
ThreadTool.makeVThread("端口监听线程", r).start();
|
ThreadTool.makeVThread("端口监听线程", r).start();
|
||||||
}
|
}
|
||||||
public void close() {
|
public void close() {
|
||||||
@@ -82,8 +79,8 @@ public class SocketListener implements Closeable,AutoCloseable{
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MultipurposeSocketAddress getMultipurposeSocketAddress() {
|
public MultiProtocolSocketAddress getMultipurposeSocketAddress() {
|
||||||
return multipurposeSocketAddress;
|
return multiProtocolSocketAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Consumer<Socket> getCon() {
|
public Consumer<Socket> getCon() {
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
package org.kne.cloud.network;
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class SocketToServiceProxy extends Proxy {
|
public class SocketToServiceProxy extends Proxy {
|
||||||
public SocketToServiceProxy(String l, String r) {
|
public SocketToServiceProxy(String l, String r) {
|
||||||
src=new MultipurposeSocketAddress(l);
|
src=new MultiProtocolSocketAddress(l);
|
||||||
des=getRegister().get(r.substring(1, r.length()-1)) ;
|
des=getRegister().get(r.substring(1, r.length()-1)) ;
|
||||||
}
|
}
|
||||||
public MultipurposeSocketAddress getSrc() {
|
public MultiProtocolSocketAddress getSrc() {
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
public NetworkService getDes() {
|
public NetworkService getDes() {
|
||||||
return des;
|
return des;
|
||||||
}
|
}
|
||||||
private MultipurposeSocketAddress src;
|
private MultiProtocolSocketAddress src;
|
||||||
private NetworkService des;
|
private NetworkService des;
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import java.io.IOException;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketOption;
|
|
||||||
import java.net.SocketOptions;
|
|
||||||
import java.net.StandardSocketOptions;
|
import java.net.StandardSocketOptions;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -15,8 +12,8 @@ public class SocketToSocketProxy extends Proxy {
|
|||||||
private SocketListener sl;
|
private SocketListener sl;
|
||||||
private SocketChannelListener scl;
|
private SocketChannelListener scl;
|
||||||
private DatagramSocketListener dsl;
|
private DatagramSocketListener dsl;
|
||||||
private MultipurposeSocketAddress listen, cbind, defaultConnect;
|
private MultiProtocolSocketAddress listen, cbind, defaultConnect;
|
||||||
private Map<String, MultipurposeSocketAddress> detectedConnect;
|
private Map<String, MultiProtocolSocketAddress> detectedConnect;
|
||||||
private SocketBridgeFactory defaultFactory;
|
private SocketBridgeFactory defaultFactory;
|
||||||
private SocketChannelBridgeFactory defaultChannelFactory;
|
private SocketChannelBridgeFactory defaultChannelFactory;
|
||||||
private Map<String, SocketBridgeFactory> detectedFactory;
|
private Map<String, SocketBridgeFactory> detectedFactory;
|
||||||
@@ -30,28 +27,28 @@ public class SocketToSocketProxy extends Proxy {
|
|||||||
this.defaultSoTimeout = defaultSoTimeout;
|
this.defaultSoTimeout = defaultSoTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketToSocketProxy(MultipurposeSocketAddress listen, MultipurposeSocketAddress connect) throws IOException {
|
public SocketToSocketProxy(MultiProtocolSocketAddress listen, MultiProtocolSocketAddress connect) throws IOException {
|
||||||
this(listen, new MultipurposeSocketAddress(new InetSocketAddress(0)), connect);
|
this(listen, new MultiProtocolSocketAddress(new InetSocketAddress(0)), connect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketToSocketProxy(String l, String r) throws IOException {
|
public SocketToSocketProxy(String l, String r) throws IOException {
|
||||||
this(new MultipurposeSocketAddress(l), new MultipurposeSocketAddress(r));
|
this(new MultiProtocolSocketAddress(l), new MultiProtocolSocketAddress(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketToSocketProxy(MultipurposeSocketAddress listen, MultipurposeSocketAddress cbind,
|
public SocketToSocketProxy(MultiProtocolSocketAddress listen, MultiProtocolSocketAddress cbind,
|
||||||
MultipurposeSocketAddress defaultConnect, Map<String, MultipurposeSocketAddress> detectedConnect)
|
MultiProtocolSocketAddress defaultConnect, Map<String, MultiProtocolSocketAddress> detectedConnect)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this(listen,cbind,defaultConnect,detectedConnect,new DefaultSocketBridgeFactory(),null);
|
this(listen,cbind,defaultConnect,detectedConnect,new DefaultSocketBridgeFactory(),null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketToSocketProxy(MultipurposeSocketAddress listen, MultipurposeSocketAddress cbind,
|
public SocketToSocketProxy(MultiProtocolSocketAddress listen, MultiProtocolSocketAddress cbind,
|
||||||
MultipurposeSocketAddress defaultConnect, Map<String, MultipurposeSocketAddress> detectedConnect,SocketBridgeFactory defaultFactory,Map<String, SocketBridgeFactory> detectedFactory)
|
MultiProtocolSocketAddress defaultConnect, Map<String, MultiProtocolSocketAddress> detectedConnect, SocketBridgeFactory defaultFactory, Map<String, SocketBridgeFactory> detectedFactory)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this(listen, cbind, defaultConnect, detectedConnect, defaultFactory, detectedFactory, new DefaultSocketChannelBridgeFactory());
|
this(listen, cbind, defaultConnect, detectedConnect, defaultFactory, detectedFactory, new DefaultSocketChannelBridgeFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketToSocketProxy(MultipurposeSocketAddress listen, MultipurposeSocketAddress cbind,
|
public SocketToSocketProxy(MultiProtocolSocketAddress listen, MultiProtocolSocketAddress cbind,
|
||||||
MultipurposeSocketAddress defaultConnect, Map<String, MultipurposeSocketAddress> detectedConnect,SocketBridgeFactory defaultFactory,Map<String, SocketBridgeFactory> detectedFactory,SocketChannelBridgeFactory defaultChannelFactory)
|
MultiProtocolSocketAddress defaultConnect, Map<String, MultiProtocolSocketAddress> detectedConnect, SocketBridgeFactory defaultFactory, Map<String, SocketBridgeFactory> detectedFactory, SocketChannelBridgeFactory defaultChannelFactory)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this.listen = listen;
|
this.listen = listen;
|
||||||
this.cbind = cbind;
|
this.cbind = cbind;
|
||||||
@@ -66,8 +63,8 @@ public class SocketToSocketProxy extends Proxy {
|
|||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketToSocketProxy(MultipurposeSocketAddress listen, MultipurposeSocketAddress cbind,
|
public SocketToSocketProxy(MultiProtocolSocketAddress listen, MultiProtocolSocketAddress cbind,
|
||||||
MultipurposeSocketAddress defaultConnect) throws IOException {
|
MultiProtocolSocketAddress defaultConnect) throws IOException {
|
||||||
this(listen, cbind, defaultConnect,null);
|
this(listen, cbind, defaultConnect,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +109,7 @@ public class SocketToSocketProxy extends Proxy {
|
|||||||
ProtocolStack ps = ((ProtocolDetectorSocket) sox).getProtocolStack();
|
ProtocolStack ps = ((ProtocolDetectorSocket) sox).getProtocolStack();
|
||||||
if (!ps.isEmpty()) {
|
if (!ps.isEmpty()) {
|
||||||
String pname=ps.pop().getName();
|
String pname=ps.pop().getName();
|
||||||
MultipurposeSocketAddress pmsa = detectedConnect.get(pname);
|
MultiProtocolSocketAddress pmsa = detectedConnect.get(pname);
|
||||||
if(pmsa!=null) {
|
if(pmsa!=null) {
|
||||||
sk = pmsa.connectSocket(InetAddress.getByName(cbind.getHost()), cbind.getPort());
|
sk = pmsa.connectSocket(InetAddress.getByName(cbind.getHost()), cbind.getPort());
|
||||||
}else {
|
}else {
|
||||||
@@ -178,19 +175,19 @@ public class SocketToSocketProxy extends Proxy {
|
|||||||
sb.run();
|
sb.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getListen() {
|
public MultiProtocolSocketAddress getListen() {
|
||||||
return listen;
|
return listen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getCbind() {
|
public MultiProtocolSocketAddress getCbind() {
|
||||||
return cbind;
|
return cbind;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getDefaultConnect() {
|
public MultiProtocolSocketAddress getDefaultConnect() {
|
||||||
return defaultConnect;
|
return defaultConnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, MultipurposeSocketAddress> getDetectedConnect() {
|
public Map<String, MultiProtocolSocketAddress> getDetectedConnect() {
|
||||||
return detectedConnect;
|
return detectedConnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class SocketType {
|
|||||||
private DatagramSocketFactory datagramSocketFactory;
|
private DatagramSocketFactory datagramSocketFactory;
|
||||||
private DatagramServerSocketFactory datagramServerSocketFactory;
|
private DatagramServerSocketFactory datagramServerSocketFactory;
|
||||||
private boolean stream;
|
private boolean stream;
|
||||||
|
private int defaultPort=-1;
|
||||||
|
|
||||||
public SocketFactory Channel() {
|
public SocketFactory Channel() {
|
||||||
return socketFactory;
|
return socketFactory;
|
||||||
@@ -74,5 +75,7 @@ public class SocketType {
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDefaultPort(){
|
||||||
|
return defaultPort;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
|
public class TCPSocketType extends SocketType {
|
||||||
|
private static final TCPSocketType INSTANCE = new TCPSocketType();
|
||||||
|
|
||||||
|
private TCPSocketType() {
|
||||||
|
super(
|
||||||
|
new DefaultSocketFactory(),
|
||||||
|
new DefaultServerSocketFactory(),
|
||||||
|
new DefaultSocketChannelFactory(),
|
||||||
|
new DefaultServerSocketChannelFactory()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TCPSocketType getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStream() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.kne.cloud.network;
|
||||||
|
|
||||||
|
public class UDPSocketType extends SocketType {
|
||||||
|
private static final UDPSocketType INSTANCE = new UDPSocketType();
|
||||||
|
|
||||||
|
protected UDPSocketType() {
|
||||||
|
super(
|
||||||
|
new DefaultDatagramSocketFactory(),
|
||||||
|
new DefaultDatagramServerSocketFactory()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UDPSocketType getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStream() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,16 +4,13 @@ import java.io.IOException;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.SocketImpl;
|
import java.net.SocketImpl;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.ini4j.Profile.Section;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
|
||||||
|
|
||||||
public class FrpcServerSocket extends ServerSocket {
|
public class FrpcServerSocket extends ServerSocket {
|
||||||
private FrpcProcess frpc;
|
private FrpcProcess frpc;
|
||||||
@@ -76,10 +73,10 @@ public class FrpcServerSocket extends ServerSocket {
|
|||||||
return frpcini.getRemotePort(tunnel);
|
return frpcini.getRemotePort(tunnel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getTunnelSocketAddress() {
|
public MultiProtocolSocketAddress getTunnelSocketAddress() {
|
||||||
if (!isBound())
|
if (!isBound())
|
||||||
return null;
|
return null;
|
||||||
return new MultipurposeSocketAddress(frpcini.getType(tunnel).toUpperCase(),getTunnelHost(), getTunnelPort());
|
return new MultiProtocolSocketAddress(frpcini.getType(tunnel).toUpperCase(),getTunnelHost(), getTunnelPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -116,9 +116,7 @@ public class DatagramKLALBPacketLink implements KLALBPacketLink {
|
|||||||
}*/
|
}*/
|
||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
@@ -128,15 +126,14 @@ import java.net.SocketException;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.kne.cloud.network.DatagramServerSocket;
|
import org.kne.cloud.network.DatagramServerSocket;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.NetworkPacket;
|
import org.kne.cloud.network.NetworkPacket;
|
||||||
import org.kne.cloud.network.SpeedLimiter;
|
|
||||||
|
|
||||||
public class DatagramKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
public class DatagramKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
return new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
private DatagramSocket ds;
|
private DatagramSocket ds;
|
||||||
|
|||||||
@@ -1,39 +1,31 @@
|
|||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.annotation.processing.Filer;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
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.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
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.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 com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
public class KLALBConfig extends ArrayList<KLALBConfigItem>{
|
public class KLALBConfig extends ArrayList<KLALBConfigItem>{
|
||||||
|
|
||||||
|
public KLALBConfig(){
|
||||||
|
}
|
||||||
|
public static KLALBConfig getDefault(){
|
||||||
|
KLALBConfig config=new KLALBConfig();
|
||||||
|
config.add(new KLALBControllerConfigItem());
|
||||||
|
return config;
|
||||||
|
}
|
||||||
public static void main(String[] args) throws UnknownHostException, JsonSyntaxException, JsonIOException, FileNotFoundException {
|
public static void main(String[] args) throws UnknownHostException, JsonSyntaxException, JsonIOException, FileNotFoundException {
|
||||||
GsonBuilder gb=new GsonBuilder().setPrettyPrinting();
|
GsonBuilder gb=new GsonBuilder().setPrettyPrinting();
|
||||||
MultipurposeSocketAddress.registerToGsonBuilder(gb);
|
MultiProtocolSocketAddress.registerToGsonBuilder(gb);
|
||||||
KLALBConfigItem.registerToGsonBuilder(gb);
|
KLALBConfigItem.registerToGsonBuilder(gb);
|
||||||
Gson gson=gb.create();
|
Gson gson=gb.create();
|
||||||
KLALBConfig kc=gson.fromJson(new FileReader(new File("klalb-config.json")),KLALBConfig.class);
|
KLALBConfig kc=gson.fromJson(new FileReader(new File("klalb-config.json")),KLALBConfig.class);
|
||||||
|
|||||||
@@ -1,22 +1,14 @@
|
|||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
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 java.util.Objects;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializationContext;
|
||||||
import com.google.gson.JsonSerializer;
|
import com.google.gson.JsonSerializer;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.network.IPMulticastDiscovery;
|
import org.kne.cloud.network.IPMulticastDiscovery;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.PortPair;
|
import org.kne.cloud.network.PortPair;
|
||||||
import org.kne.cloud.network.SocketType;
|
import org.kne.cloud.network.SocketType;
|
||||||
import org.kne.cloud.network.ThreadTool;
|
import org.kne.cloud.network.ThreadTool;
|
||||||
@@ -67,7 +67,7 @@ public class KLALBController {
|
|||||||
public HighAccuracyClock getClock() {
|
public HighAccuracyClock getClock() {
|
||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
private final long TIME_WINDOW=5000000000L;
|
private final long TIME_WINDOW=2000000000L;
|
||||||
private SpeedAndTrafficMonitorDataImpl linkMonitor = new SpeedAndTrafficMonitorDataImpl(
|
private SpeedAndTrafficMonitorDataImpl linkMonitor = new SpeedAndTrafficMonitorDataImpl(
|
||||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100,TIME_WINDOW ),
|
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100,TIME_WINDOW ),
|
||||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, TIME_WINDOW));
|
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, TIME_WINDOW));
|
||||||
@@ -76,8 +76,13 @@ public class KLALBController {
|
|||||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100, TIME_WINDOW),
|
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100, TIME_WINDOW),
|
||||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, TIME_WINDOW));
|
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, TIME_WINDOW));
|
||||||
|
|
||||||
private List<MultipurposeSocketAddress> selflineTable = new ArrayList<>();
|
private List<MultiProtocolSocketAddress> selflineTable = new ArrayList<>();
|
||||||
|
|
||||||
|
private List<MultiProtocolSocketAddress> listensSocketAddress = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
public List<MultiProtocolSocketAddress> getListenSocketAddress() {
|
||||||
|
return listensSocketAddress;
|
||||||
|
}
|
||||||
private static final boolean debug=false;
|
private static final boolean debug=false;
|
||||||
private static final boolean showpacket = false;
|
private static final boolean showpacket = false;
|
||||||
|
|
||||||
@@ -86,10 +91,12 @@ public class KLALBController {
|
|||||||
|
|
||||||
private static List<IPMulticastDiscovery> ipmd = new ArrayList<>();
|
private static List<IPMulticastDiscovery> ipmd = new ArrayList<>();
|
||||||
|
|
||||||
private List<NetworkInterface> networkInterfaceExcept = new ArrayList<>();
|
private NetworkInterfaceManager networkInterfaceManager=new NetworkInterfaceManager();
|
||||||
|
public NetworkInterfaceManager getNetworkInterfaceManager() {
|
||||||
|
return networkInterfaceManager;
|
||||||
|
}
|
||||||
public List<NetworkInterface> getNetworkInterfaceExcept() {
|
public List<NetworkInterface> getNetworkInterfaceExcept() {
|
||||||
return networkInterfaceExcept;
|
return networkInterfaceManager.getNetworkInterfaceExcept();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<InetAddress> dnsAddresses = new ArrayList<>();
|
private List<InetAddress> dnsAddresses = new ArrayList<>();
|
||||||
@@ -111,50 +118,23 @@ public class KLALBController {
|
|||||||
|
|
||||||
private Timer twk = new Timer("网卡检测扫描计时器", true);
|
private Timer twk = new Timer("网卡检测扫描计时器", true);
|
||||||
|
|
||||||
private List<InetAddress> getAllNetworkInterfaceAddress() throws SocketException {
|
|
||||||
List<InetAddress> addresses = new ArrayList<InetAddress>();
|
|
||||||
Enumeration<NetworkInterface> eu = NetworkInterface.getNetworkInterfaces();
|
|
||||||
while (eu.hasMoreElements()) {
|
|
||||||
NetworkInterface networkInterface = (NetworkInterface) eu.nextElement();
|
|
||||||
|
|
||||||
if (networkInterface.getDisplayName()
|
|
||||||
.startsWith(CONST.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (networkInterfaceExcept.contains(networkInterface)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (networkInterface.isUp()) {
|
|
||||||
// System.out.println(networkInterface+" "+networkInterface.isUp());
|
|
||||||
Enumeration<InetAddress> ei = networkInterface.getInetAddresses();
|
|
||||||
while (ei.hasMoreElements()) {
|
|
||||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
|
||||||
if (checkIsSelfLocator(inetAddress)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
addresses.add(inetAddress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return addresses;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TimerTask tsk1 = new TimerTask() {
|
private TimerTask tsk1 = new TimerTask() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
List<InetAddress> localaddress = getAllNetworkInterfaceAddress();
|
List<InetAddress> localaddress = networkInterfaceManager.getAllNetworkInterfaceAddress();
|
||||||
|
|
||||||
for (InetAddress inetAddress : localaddress) {
|
for (InetAddress inetAddress : localaddress) {
|
||||||
if (!inetAddress.isLoopbackAddress())
|
for (Iterator<MultiProtocolSocketAddress> iterator = listensSocketAddress.iterator(); iterator.hasNext();) {
|
||||||
for (Iterator<MultipurposeSocketAddress> iterator = listens.iterator(); iterator.hasNext();) {
|
MultiProtocolSocketAddress tcpl = (MultiProtocolSocketAddress) iterator.next();
|
||||||
MultipurposeSocketAddress tcpl = (MultipurposeSocketAddress) iterator.next();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (tcpl.getInetAddress().isAnyLocalAddress()
|
if (tcpl.getInetAddress().isAnyLocalAddress()
|
||||||
|| tcpl.getInetAddress().equals(inetAddress)) {
|
|| tcpl.getInetAddress().equals(inetAddress)) {
|
||||||
MultipurposeSocketAddress bind = new MultipurposeSocketAddress(tcpl.getType(),
|
MultiProtocolSocketAddress bind = new MultiProtocolSocketAddress(tcpl.getProtocol(),
|
||||||
inetAddress.getHostAddress(), tcpl.getPort());
|
inetAddress.getHostAddress(), tcpl.getPort());
|
||||||
// System.out.println(bind);
|
// System.out.println(bind);
|
||||||
synchronized (selflineTable) {
|
synchronized (selflineTable) {
|
||||||
@@ -175,9 +155,8 @@ public class KLALBController {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
Set<MultipurposeSocketAddress> st = new HashSet<>();
|
Set<MultiProtocolSocketAddress> st = new HashSet<>();
|
||||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
for (IPv6NetworkLink link : srv6Router.getLinkTabel()) {
|
||||||
IPv6NetworkLink link = iterator.next();
|
|
||||||
if (link instanceof KLALBRemoteLink) {
|
if (link instanceof KLALBRemoteLink) {
|
||||||
KLALBRemoteLink multipurposeSocketAddress = (KLALBRemoteLink) link;
|
KLALBRemoteLink multipurposeSocketAddress = (KLALBRemoteLink) link;
|
||||||
if (multipurposeSocketAddress.getSocketAddress() != null)
|
if (multipurposeSocketAddress.getSocketAddress() != null)
|
||||||
@@ -185,24 +164,24 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator<MultipurposeSocketAddress> iterator = st.iterator(); iterator.hasNext();) {
|
for (MultiProtocolSocketAddress target : st) {
|
||||||
MultipurposeSocketAddress target = (MultipurposeSocketAddress) iterator.next();
|
|
||||||
addRemoteLines(target);
|
addRemoteLines(target);
|
||||||
}
|
}
|
||||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
|
||||||
IPv6NetworkLink link = iterator.next();
|
/*
|
||||||
|
for (IPv6NetworkLink link : srv6Router.getLinkTabel()) {
|
||||||
if (link instanceof KLALBRemoteLink) {
|
if (link instanceof KLALBRemoteLink) {
|
||||||
KLALBRemoteLink reml = (KLALBRemoteLink) link;
|
KLALBRemoteLink reml = (KLALBRemoteLink) link;
|
||||||
if (reml.getSocketAddress() != null) {
|
if (reml.getSocketAddress() != null) {
|
||||||
if (reml.getBindAddress() != null || reml.getRemoteVaddr() != null)
|
if (reml.getBindAddress() != null || reml.getRemoteVaddr() != null)
|
||||||
try {
|
try {
|
||||||
MultipurposeSocketAddress iadr=reml.getBindAddress();
|
MultipurposeSocketAddress iadr = reml.getBindAddress();
|
||||||
if(iadr!=null) {
|
if (iadr != null) {
|
||||||
if (!localaddress.contains(iadr.getInetAddress())) {
|
if (!localaddress.contains(iadr.getInetAddress())) {
|
||||||
reml.close();
|
reml.close();
|
||||||
srv6Router.getLinkTabel().remove(reml);
|
srv6Router.getLinkTabel().remove(reml);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
|
|
||||||
reml.close();
|
reml.close();
|
||||||
}
|
}
|
||||||
@@ -214,7 +193,7 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
} finally {
|
} finally {
|
||||||
lineslock.writeLock().unlock();
|
lineslock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
@@ -228,9 +207,9 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateBroadcastNetworkInterface() throws SocketException {
|
private void updateBroadcastNetworkInterface() throws SocketException {
|
||||||
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext();) {
|
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext(); ) {
|
||||||
IPMulticastDiscovery ipMulticastDiscovery = (IPMulticastDiscovery) iterator.next();
|
IPMulticastDiscovery ipMulticastDiscovery = (IPMulticastDiscovery) iterator.next();
|
||||||
if (ipMulticastDiscovery.isClosed() || (!ipMulticastDiscovery.getNinterface().isUp())
|
if (ipMulticastDiscovery.isClosed() || (!ipMulticastDiscovery.getInterface().isUp())
|
||||||
|| (configItem != null && configItem.isDenyLineTableBroadcast())) {
|
|| (configItem != null && configItem.isDenyLineTableBroadcast())) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
try {
|
try {
|
||||||
@@ -238,37 +217,21 @@ public class KLALBController {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if(debug)
|
if (debug)
|
||||||
System.out.println("关闭网卡地址广播:" + ipMulticastDiscovery.getNinterface());
|
System.out.println("关闭网卡地址广播:" + ipMulticastDiscovery.getInterface());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configItem != null && configItem.isDenyLineTableBroadcast()) {
|
if (configItem != null && configItem.isDenyLineTableBroadcast()) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Enumeration<NetworkInterface> eu2 = NetworkInterface.getNetworkInterfaces();
|
List<NetworkInterface> interfaceList = networkInterfaceManager.getAllAvaliableNetworkInterface();
|
||||||
while (eu2.hasMoreElements()) {
|
for(NetworkInterface networkInterface:interfaceList){
|
||||||
NetworkInterface networkInterface = (NetworkInterface) eu2.nextElement();
|
List<InetAddress> addressList= networkInterfaceManager.getNetworkInterfaceAddress(networkInterface);
|
||||||
if (networkInterface.getDisplayName()
|
loop:for (InetAddress bidr:addressList) {
|
||||||
.startsWith(CONST.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (networkInterfaceExcept.contains(networkInterface)) {
|
for (IPMulticastDiscovery ipMulticastDiscovery : ipmd) {
|
||||||
continue;
|
if (networkInterface.equals(ipMulticastDiscovery.getInterface())
|
||||||
}
|
|
||||||
|
|
||||||
if (networkInterface.isUp()) {
|
|
||||||
|
|
||||||
Enumeration<InetAddress> ei = networkInterface.getInetAddresses();
|
|
||||||
loop: while (ei.hasMoreElements()) {
|
|
||||||
InetAddress bidr = (InetAddress) ei.nextElement();
|
|
||||||
if (checkIsSelfLocator(bidr)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext();) {
|
|
||||||
IPMulticastDiscovery ipMulticastDiscovery = (IPMulticastDiscovery) iterator.next();
|
|
||||||
if (networkInterface.equals(ipMulticastDiscovery.getNinterface())
|
|
||||||
&& bidr.equals(ipMulticastDiscovery.getBind().getAddress())) {
|
&& bidr.equals(ipMulticastDiscovery.getBind().getAddress())) {
|
||||||
continue loop;
|
continue loop;
|
||||||
}
|
}
|
||||||
@@ -278,13 +241,13 @@ public class KLALBController {
|
|||||||
// InetAddress bidr=InetAddress.getByName("::0");
|
// InetAddress bidr=InetAddress.getByName("::0");
|
||||||
|
|
||||||
if (bidr instanceof Inet6Address) {
|
if (bidr instanceof Inet6Address) {
|
||||||
IPMulticastDiscovery ipd = new IPMulticastDiscovery(
|
IPMulticastDiscovery ipd = new IPMulticastDiscovery(new InetSocketAddress(bidr,DISCOVERY_PORT),
|
||||||
new InetSocketAddress(bidr, DISCOVERY_PORT),
|
|
||||||
new InetSocketAddress(InetAddress.getByName("ff02::2486"),
|
new InetSocketAddress(InetAddress.getByName("ff02::2486"),
|
||||||
DISCOVERY_PORT),
|
DISCOVERY_PORT),
|
||||||
networkInterface, selflineTable, nodeuuid,10000L);
|
networkInterface, listensSocketAddress, nodeuuid, 10000L);
|
||||||
ipd.setCon((mpa) -> {
|
ipd.setCon((mpa) -> {
|
||||||
// System.out.println("添加本地IPv6链路:"+mpa);
|
if (debug)
|
||||||
|
System.out.println("添加本地IPv6链路:" + mpa);
|
||||||
try {
|
try {
|
||||||
if (!checkIsSelf(mpa))
|
if (!checkIsSelf(mpa))
|
||||||
addRemoteLines(mpa);
|
addRemoteLines(mpa);
|
||||||
@@ -295,13 +258,13 @@ public class KLALBController {
|
|||||||
ipmd.add(ipd);
|
ipmd.add(ipd);
|
||||||
} else if (bidr instanceof Inet4Address) {
|
} else if (bidr instanceof Inet4Address) {
|
||||||
// bidr=InetAddress.getByName("0.0.0.0");
|
// bidr=InetAddress.getByName("0.0.0.0");
|
||||||
IPMulticastDiscovery ipd2 = new IPMulticastDiscovery(
|
IPMulticastDiscovery ipd2 = new IPMulticastDiscovery(new InetSocketAddress(bidr,DISCOVERY_PORT),
|
||||||
new InetSocketAddress(bidr, DISCOVERY_PORT),
|
|
||||||
new InetSocketAddress(InetAddress.getByName("224.0.0.86"),
|
new InetSocketAddress(InetAddress.getByName("224.0.0.86"),
|
||||||
DISCOVERY_PORT),
|
DISCOVERY_PORT),
|
||||||
networkInterface, selflineTable,nodeuuid, 10000L);
|
networkInterface, listensSocketAddress, nodeuuid, 10000L);
|
||||||
ipd2.setCon((mpa) -> {
|
ipd2.setCon((mpa) -> {
|
||||||
// System.out.println("添加本地IPv4链路:"+mpa);
|
if (debug)
|
||||||
|
System.out.println("添加本地IPv4链路:" + mpa);
|
||||||
try {
|
try {
|
||||||
if (!checkIsSelf(mpa))
|
if (!checkIsSelf(mpa))
|
||||||
addRemoteLines(mpa);
|
addRemoteLines(mpa);
|
||||||
@@ -311,7 +274,7 @@ public class KLALBController {
|
|||||||
ipd2.start();
|
ipd2.start();
|
||||||
ipmd.add(ipd2);
|
ipmd.add(ipd2);
|
||||||
}
|
}
|
||||||
if(debug)
|
if (debug)
|
||||||
System.out.println("开启网卡地址广播:" + networkInterface);
|
System.out.println("开启网卡地址广播:" + networkInterface);
|
||||||
} catch (BindException e) {
|
} catch (BindException e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
@@ -321,16 +284,19 @@ public class KLALBController {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private boolean checkIsSelf(MultipurposeSocketAddress inetAddress) throws UnknownHostException {
|
private boolean checkIsSelf(MultiProtocolSocketAddress inetAddress) throws UnknownHostException {
|
||||||
|
|
||||||
return inetAddress.getInetAddress().isAnyLocalAddress() || inetAddress.getInetAddress().isLoopbackAddress()
|
return inetAddress.getInetAddress().isAnyLocalAddress() || inetAddress.getInetAddress().isLoopbackAddress()
|
||||||
|| selflineTable.contains(inetAddress);
|
|| selflineTable.contains(inetAddress);
|
||||||
@@ -345,16 +311,16 @@ public class KLALBController {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
List<MultipurposeSocketAddress> nt = ntptable;
|
List<MultiProtocolSocketAddress> nt = ntptable;
|
||||||
// System.out.println("srv6 ip"+nb);
|
// System.out.println("srv6 ip"+nb);
|
||||||
if (nvc2 != null) {
|
if (nvc2 != null) {
|
||||||
Set<NTPPeer> sp = nvc2.getPeers();
|
Set<NTPPeer> sp = nvc2.getPeers();
|
||||||
for (MultipurposeSocketAddress server : nt) {
|
for (MultiProtocolSocketAddress server : nt) {
|
||||||
sp.add(new NTPPeer(server, NTPv4Packet.NTP_CLIENT));
|
sp.add(new NTPPeer(server, NTPv4Packet.NTP_CLIENT));
|
||||||
|
|
||||||
}
|
}
|
||||||
sp.removeIf((p) -> {
|
sp.removeIf((p) -> {
|
||||||
for (MultipurposeSocketAddress server : nt) {
|
for (MultiProtocolSocketAddress server : nt) {
|
||||||
if (server.equals(p.getAddress())) {
|
if (server.equals(p.getAddress())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -365,10 +331,7 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private TimerTask tsk3 = new TimerTask() {
|
public void tryConnectMore(){
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (srv6Router != null && routingProtocol != null) {
|
if (srv6Router != null && routingProtocol != null) {
|
||||||
Set<IPv6AddressGroup> nb = srv6Router.getLocators();
|
Set<IPv6AddressGroup> nb = srv6Router.getLocators();
|
||||||
for (Iterator<IPv6AddressGroup> iterator = nb.iterator(); iterator.hasNext();) {
|
for (Iterator<IPv6AddressGroup> iterator = nb.iterator(); iterator.hasNext();) {
|
||||||
@@ -378,7 +341,7 @@ public class KLALBController {
|
|||||||
KLALBRoutingProtocol.DEFAULT_PORT);
|
KLALBRoutingProtocol.DEFAULT_PORT);
|
||||||
apiClient.requestOpenLines(iaddr, (v) -> {
|
apiClient.requestOpenLines(iaddr, (v) -> {
|
||||||
ThreadTool.makeVDaemonThreadIfSupport("线路添加任务", () -> {
|
ThreadTool.makeVDaemonThreadIfSupport("线路添加任务", () -> {
|
||||||
for (MultipurposeSocketAddress msa : v) {
|
for (MultiProtocolSocketAddress msa : v) {
|
||||||
// System.out.print(msa);
|
// System.out.print(msa);
|
||||||
addRemoteLines(msa);
|
addRemoteLines(msa);
|
||||||
}
|
}
|
||||||
@@ -391,7 +354,7 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
public SpeedAndTrafficMonitorDataImpl getLinkMonitor() {
|
public SpeedAndTrafficMonitorDataImpl getLinkMonitor() {
|
||||||
return linkMonitor;
|
return linkMonitor;
|
||||||
@@ -403,6 +366,8 @@ public class KLALBController {
|
|||||||
|
|
||||||
private SocketType streamSocketType = new KLALBStreamSocketType();
|
private SocketType streamSocketType = new KLALBStreamSocketType();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class KLALBStreamSocketType extends SocketType {
|
public class KLALBStreamSocketType extends SocketType {
|
||||||
|
|
||||||
public KLALBStreamSocketType() {
|
public KLALBStreamSocketType() {
|
||||||
@@ -436,7 +401,7 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<MultipurposeSocketAddress> getSelflineTable() {
|
public List<MultiProtocolSocketAddress> getSelflineTable() {
|
||||||
return selflineTable;
|
return selflineTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,13 +437,13 @@ public class KLALBController {
|
|||||||
|
|
||||||
private KLALBControllerConfigItem configItem;
|
private KLALBControllerConfigItem configItem;
|
||||||
|
|
||||||
public void addRemoteLines(List<MultipurposeSocketAddress> select) {
|
public void addRemoteLines(List<MultiProtocolSocketAddress> select) {
|
||||||
for (MultipurposeSocketAddress target : select) {
|
for (MultiProtocolSocketAddress target : select) {
|
||||||
addRemoteLines(target);
|
addRemoteLines(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<KLALBRemoteLink> addRemoteLines(MultipurposeSocketAddress target) {
|
public List<KLALBRemoteLink> addRemoteLines(MultiProtocolSocketAddress target) {
|
||||||
lineslock.writeLock().lock();
|
lineslock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
List<KLALBRemoteLink> added = new ArrayList<>();
|
List<KLALBRemoteLink> added = new ArrayList<>();
|
||||||
@@ -492,7 +457,7 @@ public class KLALBController {
|
|||||||
while (ei.hasMoreElements()) {
|
while (ei.hasMoreElements()) {
|
||||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||||
try {
|
try {
|
||||||
MultipurposeSocketAddress bind = new MultipurposeSocketAddress(
|
MultiProtocolSocketAddress bind = new MultiProtocolSocketAddress(
|
||||||
inetAddress.getHostAddress(), 0);
|
inetAddress.getHostAddress(), 0);
|
||||||
try {
|
try {
|
||||||
if (target.getInetAddress().isLoopbackAddress()
|
if (target.getInetAddress().isLoopbackAddress()
|
||||||
@@ -553,7 +518,7 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<KLALBRemoteLink> removeRemoteLines(MultipurposeSocketAddress mpsa) {
|
public List<KLALBRemoteLink> removeRemoteLines(MultiProtocolSocketAddress mpsa) {
|
||||||
|
|
||||||
List<KLALBRemoteLink> rmved = new ArrayList<>();
|
List<KLALBRemoteLink> rmved = new ArrayList<>();
|
||||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||||
@@ -569,7 +534,7 @@ public class KLALBController {
|
|||||||
return rmved;
|
return rmved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inet6Address getRemoteVaddrBySocketAddress(MultipurposeSocketAddress target) throws SocketTimeoutException {
|
public Inet6Address getRemoteVaddrBySocketAddress(MultiProtocolSocketAddress target) throws SocketTimeoutException {
|
||||||
KLALBRemoteLink kr = null;
|
KLALBRemoteLink kr = null;
|
||||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||||
IPv6NetworkLink link = iterator.next();
|
IPv6NetworkLink link = iterator.next();
|
||||||
@@ -593,7 +558,7 @@ public class KLALBController {
|
|||||||
return kr.getRemoteVaddr().getAddress().toInet6Address();
|
return kr.getRemoteVaddr().getAddress().toInet6Address();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkContainsTargetAndBind(MultipurposeSocketAddress target, MultipurposeSocketAddress bind) {
|
private boolean checkContainsTargetAndBind(MultiProtocolSocketAddress target, MultiProtocolSocketAddress bind) {
|
||||||
boolean b = false;
|
boolean b = false;
|
||||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||||
IPv6NetworkLink link = iterator.next();
|
IPv6NetworkLink link = iterator.next();
|
||||||
@@ -609,7 +574,7 @@ public class KLALBController {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkContainsTarget(MultipurposeSocketAddress target) {
|
private boolean checkContainsTarget(MultiProtocolSocketAddress target) {
|
||||||
boolean b = false;
|
boolean b = false;
|
||||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||||
IPv6NetworkLink link = iterator.next();
|
IPv6NetworkLink link = iterator.next();
|
||||||
@@ -639,8 +604,8 @@ public class KLALBController {
|
|||||||
|
|
||||||
private String generateSelfLineTable() {
|
private String generateSelfLineTable() {
|
||||||
StringBuilder sbd = new StringBuilder();
|
StringBuilder sbd = new StringBuilder();
|
||||||
for (Iterator<MultipurposeSocketAddress> iterator = selflineTable.iterator(); iterator.hasNext();) {
|
for (Iterator<MultiProtocolSocketAddress> iterator = selflineTable.iterator(); iterator.hasNext();) {
|
||||||
MultipurposeSocketAddress klalbRemoteLine = (MultipurposeSocketAddress) iterator.next();
|
MultiProtocolSocketAddress klalbRemoteLine = (MultiProtocolSocketAddress) iterator.next();
|
||||||
sbd.append(klalbRemoteLine.toString());
|
sbd.append(klalbRemoteLine.toString());
|
||||||
sbd.append('\n');
|
sbd.append('\n');
|
||||||
}
|
}
|
||||||
@@ -668,7 +633,12 @@ public class KLALBController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSRv6ProtocolStack(IPv6AddressGroup selfx, boolean enableVirtualAdapter) {
|
private void loadSRv6ProtocolStack(IPv6AddressGroup selfx, boolean enableVirtualAdapter) {
|
||||||
|
networkInterfaceManager.getInetAddressesExcept().add(selfx.getAddress().toInet6Address());
|
||||||
srv6Router = new SRv6Router(selfx, clock);
|
srv6Router = new SRv6Router(selfx, clock);
|
||||||
|
if(configItem!=null) {
|
||||||
|
srv6Router.setPerformanceStrategy(PerformanceStrategy.fromDescription(configItem.getPerformanceStrategy()));
|
||||||
|
srv6Router.setDeviceName(configItem.getDeviceName());
|
||||||
|
}
|
||||||
srv6Router.runKLALBRouteProtocol();
|
srv6Router.runKLALBRouteProtocol();
|
||||||
routingProtocol = srv6Router.getKlalbRouteProtol();
|
routingProtocol = srv6Router.getKlalbRouteProtol();
|
||||||
routingProtocol.addReceiver((addr, packet) -> {
|
routingProtocol.addReceiver((addr, packet) -> {
|
||||||
@@ -678,10 +648,11 @@ public class KLALBController {
|
|||||||
System.out.println(" Loaded: SRv6 Stack");
|
System.out.println(" Loaded: SRv6 Stack");
|
||||||
|
|
||||||
String name=(configItem!=null)?configItem.getTUNName():CONST.KLALB_S_RV6;
|
String name=(configItem!=null)?configItem.getTUNName():CONST.KLALB_S_RV6;
|
||||||
if (enableVirtualAdapter&&(name!=null)) {
|
boolean enableTUN = enableVirtualAdapter && (name != null) && !name.trim().isEmpty() && !name.trim().equalsIgnoreCase("null");
|
||||||
|
if (enableTUN) {
|
||||||
Thread t=new Thread(()->{
|
Thread t=new Thread(()->{
|
||||||
try {
|
try {
|
||||||
IPv6TUNLoopbackNetworkLink tunlink = new IPv6TUNLoopbackNetworkLink(name,
|
IPv6TUNLoopbackNetworkLink tunlink = new IPv6TUNLoopbackNetworkLink(name.trim(),
|
||||||
new IPv6AddressGroup(srv6Router.getLocator().getAddress(), 32), SRv6Router.MTU, dnsAddresses);
|
new IPv6AddressGroup(srv6Router.getLocator().getAddress(), 32), SRv6Router.MTU, dnsAddresses);
|
||||||
tunlink.setMonitor(datatMonitor);
|
tunlink.setMonitor(datatMonitor);
|
||||||
// srv6Router.getLinkTabel().add(tunlink);
|
// srv6Router.getLinkTabel().add(tunlink);
|
||||||
@@ -695,7 +666,7 @@ public class KLALBController {
|
|||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
}else {
|
}else {
|
||||||
System.out.println(" Tun Adapter Disbaled");
|
System.out.println(" Tun Adapter Disabled");
|
||||||
|
|
||||||
}
|
}
|
||||||
udpr=new UDPProtocolRegister(this);
|
udpr=new UDPProtocolRegister(this);
|
||||||
@@ -715,7 +686,7 @@ public class KLALBController {
|
|||||||
// System.out.println(context);
|
// System.out.println(context);
|
||||||
try {
|
try {
|
||||||
NTPv4Protocol nvc = new NTPv4Protocol(context,
|
NTPv4Protocol nvc = new NTPv4Protocol(context,
|
||||||
new MultipurposeSocketAddress("{" + iproxyname + "_Datagram}0.0.0.0:123"));
|
new MultiProtocolSocketAddress(iproxyname + "_Datagram","0.0.0.0",123));
|
||||||
srv6Router.addSRv6RouterListener(new SRv6RouterListener() {
|
srv6Router.addSRv6RouterListener(new SRv6RouterListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -726,7 +697,7 @@ public class KLALBController {
|
|||||||
for (Neighbor neighbor : nb) {
|
for (Neighbor neighbor : nb) {
|
||||||
if (neighbor.getLocator() != null)
|
if (neighbor.getLocator() != null)
|
||||||
sp.add(new NTPPeer(
|
sp.add(new NTPPeer(
|
||||||
new MultipurposeSocketAddress(iproxyname + "_Datagram",
|
new MultiProtocolSocketAddress(iproxyname + "_Datagram",
|
||||||
neighbor.getLocator().getAddress().toString(), 123),
|
neighbor.getLocator().getAddress().toString(), 123),
|
||||||
NTPv4Packet.NTP_SYMMETRIC_ACTIVE));
|
NTPv4Packet.NTP_SYMMETRIC_ACTIVE));
|
||||||
|
|
||||||
@@ -747,7 +718,7 @@ public class KLALBController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
nvc2 = new NTPv4Protocol(context, new MultipurposeSocketAddress("{UDP}0.0.0.0:0"));// 106.55.184.199
|
nvc2 = new NTPv4Protocol(context, new MultiProtocolSocketAddress("udp","0.0.0.0",0));
|
||||||
|
|
||||||
System.out.println(" Loaded: NTP Module");
|
System.out.println(" Loaded: NTP Module");
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
@@ -764,7 +735,6 @@ public class KLALBController {
|
|||||||
this.apiClient = new KLALBRoutingProtocolAPIClient(routingProtocol);
|
this.apiClient = new KLALBRoutingProtocolAPIClient(routingProtocol);
|
||||||
twk.schedule(tsk1, 5000, 5000);
|
twk.schedule(tsk1, 5000, 5000);
|
||||||
twk.schedule(tsk2, 5000, 5000);
|
twk.schedule(tsk2, 5000, 5000);
|
||||||
twk.schedule(tsk3, 5000, 5000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLALBController() {
|
public KLALBController() {
|
||||||
@@ -830,18 +800,18 @@ public class KLALBController {
|
|||||||
getIpv6Router().setASN(vasn);
|
getIpv6Router().setASN(vasn);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MultipurposeSocketAddress> linele = configItem.getLineTable();
|
List<MultiProtocolSocketAddress> linele = configItem.getLineTable();
|
||||||
if (linele != null) {
|
if (linele != null) {
|
||||||
getSelflineTable().addAll(linele);
|
getSelflineTable().addAll(linele);
|
||||||
}
|
}
|
||||||
List<MultipurposeSocketAddress> linetoc = configItem.getConnectLineTable();
|
List<MultiProtocolSocketAddress> linetoc = configItem.getConnectLineTable();
|
||||||
if (linetoc != null) {
|
if (linetoc != null) {
|
||||||
linetoc.forEach((aline) -> {
|
linetoc.forEach((aline) -> {
|
||||||
addRemoteLines(aline);
|
addRemoteLines(aline);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MultipurposeSocketAddress> ntps = configItem.getNtpServerTable();
|
List<MultiProtocolSocketAddress> ntps = configItem.getNtpServerTable();
|
||||||
if (ntps != null) {
|
if (ntps != null) {
|
||||||
getNTPTable().addAll(ntps);
|
getNTPTable().addAll(ntps);
|
||||||
}
|
}
|
||||||
@@ -1004,24 +974,19 @@ public class KLALBController {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<MultipurposeSocketAddress> listens = new CopyOnWriteArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
public void registerToProxyTypeAs(String proxyname) {
|
public void registerToProxyTypeAs(String proxyname) {
|
||||||
MultipurposeSocketAddress.getSocketTypeRegister().put(proxyname + "_Stream", streamSocketType);
|
MultiProtocolSocketAddress.getSocketTypeRegister().put(proxyname + "_Stream", streamSocketType);
|
||||||
MultipurposeSocketAddress.getSocketTypeRegister().put(proxyname + "_Datagram", datagramSocketType);
|
MultiProtocolSocketAddress.getSocketTypeRegister().put(proxyname + "_Datagram", datagramSocketType);
|
||||||
// ProxyProfileEntry.getRegister().put(proxyname, this);
|
// ProxyProfileEntry.getRegister().put(proxyname, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MultipurposeSocketAddress> getListenSocketAddress() {
|
private List<MultiProtocolSocketAddress> ntptable = new CopyOnWriteArrayList();
|
||||||
return listens;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MultipurposeSocketAddress> ntptable = new CopyOnWriteArrayList();
|
|
||||||
|
|
||||||
private KLALBRoutingProtocol routingProtocol;
|
private KLALBRoutingProtocol routingProtocol;
|
||||||
|
|
||||||
public List<MultipurposeSocketAddress> getNTPTable() {
|
public List<MultiProtocolSocketAddress> getNTPTable() {
|
||||||
return ntptable;
|
return ntptable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,31 +3,60 @@ package org.kne.cloud.network.klalb;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
|
|
||||||
public class KLALBControllerConfigItem extends KLALBConfigItem {
|
public class KLALBControllerConfigItem extends KLALBConfigItem {
|
||||||
private String language;
|
private String language;
|
||||||
private boolean nogui;
|
private boolean nogui;
|
||||||
private String VirtualAddress;
|
private String VirtualAddress=KLALBUtils.randomKLALBIPv6Address().toString();
|
||||||
private Long VirtualASN;
|
private Long VirtualASN;
|
||||||
private List<InetAddress> DNS;
|
private List<InetAddress> DNS;
|
||||||
private MultipurposeSocketAddress TCPListen;
|
private MultiProtocolSocketAddress TCPListen=new MultiProtocolSocketAddress("0.0.0.0",4565);
|
||||||
private MultipurposeSocketAddress UDPListen;
|
private MultiProtocolSocketAddress UDPListen=new MultiProtocolSocketAddress("udp","0.0.0.0",4565);
|
||||||
private String VirtualSocketName;
|
private String VirtualSocketName;
|
||||||
private List<MultipurposeSocketAddress>LineTable=new ArrayList<>();
|
private List<MultiProtocolSocketAddress>LineTable=new ArrayList<>();
|
||||||
private List<MultipurposeSocketAddress>ConnectLineTable=new ArrayList<>();
|
private List<MultiProtocolSocketAddress>ConnectLineTable=new ArrayList<>();
|
||||||
private List<MultipurposeSocketAddress>ntpServerTable=new ArrayList<>();
|
private List<MultiProtocolSocketAddress>ntpServerTable=new ArrayList<>();
|
||||||
|
private List<String>ExtraRoutes=new ArrayList<>();
|
||||||
private boolean denyLineTableQuery=false;
|
private boolean denyLineTableQuery=false;
|
||||||
private boolean denyLineTableBroadcast=false;
|
private boolean denyLineTableBroadcast=false;
|
||||||
private String congestionAlgorithm="BBR";
|
private String congestionAlgorithm="BBR";
|
||||||
private double burstLimit=1.20;
|
private double burstLimit=1.50;
|
||||||
private double delayUpperBound=1.20;
|
private double delayUpperBound=1.20;
|
||||||
private double delayLowerBound=1.15;
|
private double delayLowerBound=1.15;
|
||||||
private long nagleDelayTime=1000000L;
|
private long nagleDelayTime=1000000L;
|
||||||
private long linkNagleDelayTime=1000000L;
|
private long linkNagleDelayTime=1000000L;
|
||||||
private int linkConnectionsCount=1;
|
private int linkConnectionsCount=1;
|
||||||
private String TUNName=CONST.KLALB_S_RV6;
|
private String TUNName=CONST.KLALB_S_RV6;
|
||||||
|
private String performanceStrategy="multifill";
|
||||||
|
private String DeviceName;
|
||||||
|
private String DeviceDescription;
|
||||||
|
|
||||||
|
public String getPerformanceStrategy() {
|
||||||
|
return performanceStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPerformanceStrategy(String performanceStrategy) {
|
||||||
|
this.performanceStrategy = performanceStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceName() {
|
||||||
|
return DeviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceName(String deviceName) {
|
||||||
|
DeviceName = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceDescription() {
|
||||||
|
return DeviceDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceDescription(String deviceDescription) {
|
||||||
|
DeviceDescription = deviceDescription;
|
||||||
|
}
|
||||||
|
|
||||||
public void setNetworkInterfaceExcepts(List<String> networkInterfaceExcepts) {
|
public void setNetworkInterfaceExcepts(List<String> networkInterfaceExcepts) {
|
||||||
NetworkInterfaceExcepts = networkInterfaceExcepts;
|
NetworkInterfaceExcepts = networkInterfaceExcepts;
|
||||||
@@ -52,8 +81,8 @@ public class KLALBControllerConfigItem extends KLALBConfigItem {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public KLALBControllerConfigItem(String type) {
|
public KLALBControllerConfigItem() {
|
||||||
super(type);
|
super("KLALBController");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -124,65 +153,73 @@ public class KLALBControllerConfigItem extends KLALBConfigItem {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MultipurposeSocketAddress getTCPListen() {
|
public MultiProtocolSocketAddress getTCPListen() {
|
||||||
return TCPListen;
|
return TCPListen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setTCPListen(MultipurposeSocketAddress tCPListen) {
|
public void setTCPListen(MultiProtocolSocketAddress tCPListen) {
|
||||||
TCPListen = tCPListen;
|
TCPListen = tCPListen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MultipurposeSocketAddress getUDPListen() {
|
public MultiProtocolSocketAddress getUDPListen() {
|
||||||
return UDPListen;
|
return UDPListen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setUDPListen(MultipurposeSocketAddress uDPListen) {
|
public void setUDPListen(MultiProtocolSocketAddress uDPListen) {
|
||||||
UDPListen = uDPListen;
|
UDPListen = uDPListen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<MultipurposeSocketAddress> getLineTable() {
|
public List<MultiProtocolSocketAddress> getLineTable() {
|
||||||
return LineTable;
|
return LineTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setLineTable(List<MultipurposeSocketAddress> lineTable) {
|
public void setLineTable(List<MultiProtocolSocketAddress> lineTable) {
|
||||||
LineTable = lineTable;
|
LineTable = lineTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<MultipurposeSocketAddress> getConnectLineTable() {
|
public List<MultiProtocolSocketAddress> getConnectLineTable() {
|
||||||
return ConnectLineTable;
|
return ConnectLineTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setConnectLineTable(List<MultipurposeSocketAddress> connectLineTable) {
|
public void setConnectLineTable(List<MultiProtocolSocketAddress> connectLineTable) {
|
||||||
ConnectLineTable = connectLineTable;
|
ConnectLineTable = connectLineTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<MultipurposeSocketAddress> getNtpServerTable() {
|
public List<MultiProtocolSocketAddress> getNtpServerTable() {
|
||||||
return ntpServerTable;
|
return ntpServerTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setNtpServerTable(List<MultipurposeSocketAddress> ntpServerTable) {
|
public void setNtpServerTable(List<MultiProtocolSocketAddress> ntpServerTable) {
|
||||||
this.ntpServerTable = ntpServerTable;
|
this.ntpServerTable = ntpServerTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getExtraRoutes() {
|
||||||
|
return ExtraRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraRoutes(List<String> extraRoutes) {
|
||||||
|
ExtraRoutes = extraRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -306,146 +343,46 @@ public class KLALBControllerConfigItem extends KLALBConfigItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "KLALBControllerConfigItem [language=" + language + ", nogui=" + nogui + ", VirtualAddress="
|
return "KLALBControllerConfigItem{" +
|
||||||
+ VirtualAddress + ", VirtualASN=" + VirtualASN + ", DNS=" + DNS + ", TCPListen=" + TCPListen
|
"language='" + language + '\'' +
|
||||||
+ ", UDPListen=" + UDPListen + ", VirtualSocketName=" + VirtualSocketName + ", LineTable=" + LineTable
|
", nogui=" + nogui +
|
||||||
+ ", ConnectLineTable=" + ConnectLineTable + ", ntpServerTable=" + ntpServerTable
|
", VirtualAddress='" + VirtualAddress + '\'' +
|
||||||
+ ", denyLineTableQuery=" + denyLineTableQuery + ", denyLineTableBroadcast=" + denyLineTableBroadcast
|
", VirtualASN=" + VirtualASN +
|
||||||
+ ", congestionAlgorithm=" + congestionAlgorithm + ", delayUpperBound=" + delayUpperBound
|
", DNS=" + DNS +
|
||||||
+ ", delayLowerBound=" + delayLowerBound + ", nagleDelayTime=" + nagleDelayTime
|
", TCPListen=" + TCPListen +
|
||||||
+ ", linkNagleDelayTime=" + linkNagleDelayTime + ", linkConnectionsCount=" + linkConnectionsCount
|
", UDPListen=" + UDPListen +
|
||||||
+ ", TUNName=" + TUNName + ", NetworkInterfaceExcepts=" + NetworkInterfaceExcepts + "]";
|
", VirtualSocketName='" + VirtualSocketName + '\'' +
|
||||||
|
", LineTable=" + LineTable +
|
||||||
|
", ConnectLineTable=" + ConnectLineTable +
|
||||||
|
", ntpServerTable=" + ntpServerTable +
|
||||||
|
", ExtraRoutes=" + ExtraRoutes +
|
||||||
|
", denyLineTableQuery=" + denyLineTableQuery +
|
||||||
|
", denyLineTableBroadcast=" + denyLineTableBroadcast +
|
||||||
|
", congestionAlgorithm='" + congestionAlgorithm + '\'' +
|
||||||
|
", burstLimit=" + burstLimit +
|
||||||
|
", delayUpperBound=" + delayUpperBound +
|
||||||
|
", delayLowerBound=" + delayLowerBound +
|
||||||
|
", nagleDelayTime=" + nagleDelayTime +
|
||||||
|
", linkNagleDelayTime=" + linkNagleDelayTime +
|
||||||
|
", linkConnectionsCount=" + linkConnectionsCount +
|
||||||
|
", TUNName='" + TUNName + '\'' +
|
||||||
|
", performanceStrategy='" + performanceStrategy + '\'' +
|
||||||
|
", DeviceName='" + DeviceName + '\'' +
|
||||||
|
", DeviceDescription='" + DeviceDescription + '\'' +
|
||||||
|
", NetworkInterfaceExcepts=" + NetworkInterfaceExcepts +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
KLALBControllerConfigItem that = (KLALBControllerConfigItem) o;
|
||||||
|
return nogui == that.nogui && denyLineTableQuery == that.denyLineTableQuery && denyLineTableBroadcast == that.denyLineTableBroadcast && Double.compare(burstLimit, that.burstLimit) == 0 && Double.compare(delayUpperBound, that.delayUpperBound) == 0 && Double.compare(delayLowerBound, that.delayLowerBound) == 0 && nagleDelayTime == that.nagleDelayTime && linkNagleDelayTime == that.linkNagleDelayTime && linkConnectionsCount == that.linkConnectionsCount && Objects.equals(language, that.language) && Objects.equals(VirtualAddress, that.VirtualAddress) && Objects.equals(VirtualASN, that.VirtualASN) && Objects.equals(DNS, that.DNS) && Objects.equals(TCPListen, that.TCPListen) && Objects.equals(UDPListen, that.UDPListen) && Objects.equals(VirtualSocketName, that.VirtualSocketName) && Objects.equals(LineTable, that.LineTable) && Objects.equals(ConnectLineTable, that.ConnectLineTable) && Objects.equals(ntpServerTable, that.ntpServerTable) && Objects.equals(ExtraRoutes, that.ExtraRoutes) && Objects.equals(congestionAlgorithm, that.congestionAlgorithm) && Objects.equals(TUNName, that.TUNName) && Objects.equals(performanceStrategy, that.performanceStrategy) && Objects.equals(DeviceName, that.DeviceName) && Objects.equals(DeviceDescription, that.DeviceDescription) && Objects.equals(NetworkInterfaceExcepts, that.NetworkInterfaceExcepts);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hash(super.hashCode(), language, nogui, VirtualAddress, VirtualASN, DNS, TCPListen, UDPListen, VirtualSocketName, LineTable, ConnectLineTable, ntpServerTable, ExtraRoutes, denyLineTableQuery, denyLineTableBroadcast, congestionAlgorithm, burstLimit, delayUpperBound, delayLowerBound, nagleDelayTime, linkNagleDelayTime, linkConnectionsCount, TUNName, performanceStrategy, DeviceName, DeviceDescription, NetworkInterfaceExcepts);
|
||||||
int result = super.hashCode();
|
|
||||||
result = prime * result + ((ConnectLineTable == null) ? 0 : ConnectLineTable.hashCode());
|
|
||||||
result = prime * result + ((DNS == null) ? 0 : DNS.hashCode());
|
|
||||||
result = prime * result + ((LineTable == null) ? 0 : LineTable.hashCode());
|
|
||||||
result = prime * result + ((NetworkInterfaceExcepts == null) ? 0 : NetworkInterfaceExcepts.hashCode());
|
|
||||||
result = prime * result + ((TCPListen == null) ? 0 : TCPListen.hashCode());
|
|
||||||
result = prime * result + ((TUNName == null) ? 0 : TUNName.hashCode());
|
|
||||||
result = prime * result + ((UDPListen == null) ? 0 : UDPListen.hashCode());
|
|
||||||
result = prime * result + ((VirtualASN == null) ? 0 : VirtualASN.hashCode());
|
|
||||||
result = prime * result + ((VirtualAddress == null) ? 0 : VirtualAddress.hashCode());
|
|
||||||
result = prime * result + ((VirtualSocketName == null) ? 0 : VirtualSocketName.hashCode());
|
|
||||||
result = prime * result + ((congestionAlgorithm == null) ? 0 : congestionAlgorithm.hashCode());
|
|
||||||
long temp;
|
|
||||||
temp = Double.doubleToLongBits(delayLowerBound);
|
|
||||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
||||||
temp = Double.doubleToLongBits(delayUpperBound);
|
|
||||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
||||||
result = prime * result + (denyLineTableBroadcast ? 1231 : 1237);
|
|
||||||
result = prime * result + (denyLineTableQuery ? 1231 : 1237);
|
|
||||||
result = prime * result + ((language == null) ? 0 : language.hashCode());
|
|
||||||
result = prime * result + linkConnectionsCount;
|
|
||||||
result = prime * result + (int) (linkNagleDelayTime ^ (linkNagleDelayTime >>> 32));
|
|
||||||
result = prime * result + (int) (nagleDelayTime ^ (nagleDelayTime >>> 32));
|
|
||||||
result = prime * result + (nogui ? 1231 : 1237);
|
|
||||||
result = prime * result + ((ntpServerTable == null) ? 0 : ntpServerTable.hashCode());
|
|
||||||
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;
|
|
||||||
if (ConnectLineTable == null) {
|
|
||||||
if (other.ConnectLineTable != null)
|
|
||||||
return false;
|
|
||||||
} else if (!ConnectLineTable.equals(other.ConnectLineTable))
|
|
||||||
return false;
|
|
||||||
if (DNS == null) {
|
|
||||||
if (other.DNS != null)
|
|
||||||
return false;
|
|
||||||
} else if (!DNS.equals(other.DNS))
|
|
||||||
return false;
|
|
||||||
if (LineTable == null) {
|
|
||||||
if (other.LineTable != null)
|
|
||||||
return false;
|
|
||||||
} else if (!LineTable.equals(other.LineTable))
|
|
||||||
return false;
|
|
||||||
if (NetworkInterfaceExcepts == null) {
|
|
||||||
if (other.NetworkInterfaceExcepts != null)
|
|
||||||
return false;
|
|
||||||
} else if (!NetworkInterfaceExcepts.equals(other.NetworkInterfaceExcepts))
|
|
||||||
return false;
|
|
||||||
if (TCPListen == null) {
|
|
||||||
if (other.TCPListen != null)
|
|
||||||
return false;
|
|
||||||
} else if (!TCPListen.equals(other.TCPListen))
|
|
||||||
return false;
|
|
||||||
if (TUNName == null) {
|
|
||||||
if (other.TUNName != null)
|
|
||||||
return false;
|
|
||||||
} else if (!TUNName.equals(other.TUNName))
|
|
||||||
return false;
|
|
||||||
if (UDPListen == null) {
|
|
||||||
if (other.UDPListen != null)
|
|
||||||
return false;
|
|
||||||
} else if (!UDPListen.equals(other.UDPListen))
|
|
||||||
return false;
|
|
||||||
if (VirtualASN == null) {
|
|
||||||
if (other.VirtualASN != null)
|
|
||||||
return false;
|
|
||||||
} else if (!VirtualASN.equals(other.VirtualASN))
|
|
||||||
return false;
|
|
||||||
if (VirtualAddress == null) {
|
|
||||||
if (other.VirtualAddress != null)
|
|
||||||
return false;
|
|
||||||
} else if (!VirtualAddress.equals(other.VirtualAddress))
|
|
||||||
return false;
|
|
||||||
if (VirtualSocketName == null) {
|
|
||||||
if (other.VirtualSocketName != null)
|
|
||||||
return false;
|
|
||||||
} else if (!VirtualSocketName.equals(other.VirtualSocketName))
|
|
||||||
return false;
|
|
||||||
if (congestionAlgorithm == null) {
|
|
||||||
if (other.congestionAlgorithm != null)
|
|
||||||
return false;
|
|
||||||
} else if (!congestionAlgorithm.equals(other.congestionAlgorithm))
|
|
||||||
return false;
|
|
||||||
if (Double.doubleToLongBits(delayLowerBound) != Double.doubleToLongBits(other.delayLowerBound))
|
|
||||||
return false;
|
|
||||||
if (Double.doubleToLongBits(delayUpperBound) != Double.doubleToLongBits(other.delayUpperBound))
|
|
||||||
return false;
|
|
||||||
if (denyLineTableBroadcast != other.denyLineTableBroadcast)
|
|
||||||
return false;
|
|
||||||
if (denyLineTableQuery != other.denyLineTableQuery)
|
|
||||||
return false;
|
|
||||||
if (language == null) {
|
|
||||||
if (other.language != null)
|
|
||||||
return false;
|
|
||||||
} else if (!language.equals(other.language))
|
|
||||||
return false;
|
|
||||||
if (linkConnectionsCount != other.linkConnectionsCount)
|
|
||||||
return false;
|
|
||||||
if (linkNagleDelayTime != other.linkNagleDelayTime)
|
|
||||||
return false;
|
|
||||||
if (nagleDelayTime != other.nagleDelayTime)
|
|
||||||
return false;
|
|
||||||
if (nogui != other.nogui)
|
|
||||||
return false;
|
|
||||||
if (ntpServerTable == null) {
|
|
||||||
if (other.ntpServerTable != null)
|
|
||||||
return false;
|
|
||||||
} else if (!ntpServerTable.equals(other.ntpServerTable))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package org.kne.cloud.network.klalb;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -11,7 +13,7 @@ import java.util.List;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.SocketChannelListener;
|
import org.kne.cloud.network.SocketChannelListener;
|
||||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||||
import org.kne.cloud.network.ipv6.RouteItem;
|
import org.kne.cloud.network.ipv6.RouteItem;
|
||||||
@@ -87,6 +89,7 @@ public class KLALBMain {
|
|||||||
System.out.println(" links-remove <addr:port>: remove link");
|
System.out.println(" links-remove <addr:port>: remove link");
|
||||||
System.out.println(" links-reconnect: reconnect all link");
|
System.out.println(" links-reconnect: reconnect all link");
|
||||||
System.out.println(" kltp-state: query kltp states");
|
System.out.println(" kltp-state: query kltp states");
|
||||||
|
System.out.println(" interfaces: show all network interfaces");
|
||||||
System.out.println(" route: display internal route table");
|
System.out.println(" route: display internal route table");
|
||||||
System.out.println(" kperf <addr:port>: performance benchmark");
|
System.out.println(" kperf <addr:port>: performance benchmark");
|
||||||
System.out.println(" exit: Exit");
|
System.out.println(" exit: Exit");
|
||||||
@@ -115,7 +118,7 @@ public class KLALBMain {
|
|||||||
break;
|
break;
|
||||||
case "links-add":
|
case "links-add":
|
||||||
if(sc.length>=2) {
|
if(sc.length>=2) {
|
||||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress(sc[1]);
|
||||||
List<KLALBRemoteLink>addl=kpcje.getKlalbController().addRemoteLines(mpsa);
|
List<KLALBRemoteLink>addl=kpcje.getKlalbController().addRemoteLines(mpsa);
|
||||||
if(addl.isEmpty()) {
|
if(addl.isEmpty()) {
|
||||||
//System.out.println("添加失败,线路已存在!");
|
//System.out.println("添加失败,线路已存在!");
|
||||||
@@ -135,7 +138,7 @@ public class KLALBMain {
|
|||||||
break;
|
break;
|
||||||
case "links-remove":
|
case "links-remove":
|
||||||
if(sc.length>=2) {
|
if(sc.length>=2) {
|
||||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress(sc[1]);
|
||||||
List<KLALBRemoteLink>rmvl=kpcje.getKlalbController().removeRemoteLines(mpsa);
|
List<KLALBRemoteLink>rmvl=kpcje.getKlalbController().removeRemoteLines(mpsa);
|
||||||
if(rmvl.isEmpty()) {
|
if(rmvl.isEmpty()) {
|
||||||
System.out.println("No matched link has been found.");
|
System.out.println("No matched link has been found.");
|
||||||
@@ -161,6 +164,18 @@ public class KLALBMain {
|
|||||||
case "kltp-state":
|
case "kltp-state":
|
||||||
System.out.println(kpcje.getKlalbController().getKLTPregister().toString());
|
System.out.println(kpcje.getKlalbController().getKLTPregister().toString());
|
||||||
break;
|
break;
|
||||||
|
case "interfaces":
|
||||||
|
NetworkInterfaceManager networkInterfaceManager= kpcje.getKlalbController().getNetworkInterfaceManager();
|
||||||
|
List<NetworkInterface> interfaceList=networkInterfaceManager.getAllAvaliableNetworkInterface();
|
||||||
|
System.out.println("Network interface detected:");
|
||||||
|
for(NetworkInterface networkInterface:interfaceList){
|
||||||
|
System.out.println(networkInterface.getName()+"("+networkInterface.getDisplayName()+")");
|
||||||
|
List<InetAddress> lst= networkInterfaceManager.getNetworkInterfaceAddress(networkInterface);
|
||||||
|
for(InetAddress address :lst){
|
||||||
|
System.out.println(" "+address.getHostAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "route":
|
case "route":
|
||||||
List<RouteItem> lri=new ArrayList<>( kpcje.getKlalbController().getIpv6Router().getCurrentRouteTabel());
|
List<RouteItem> lri=new ArrayList<>( kpcje.getKlalbController().getIpv6Router().getCurrentRouteTabel());
|
||||||
Collections.sort(lri);
|
Collections.sort(lri);
|
||||||
@@ -174,7 +189,7 @@ public class KLALBMain {
|
|||||||
break;
|
break;
|
||||||
case "kperf":
|
case "kperf":
|
||||||
if(sc.length>=2) {
|
if(sc.length>=2) {
|
||||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress(sc[1]);
|
||||||
Kperf kp=new Kperf(mpsa);
|
Kperf kp=new Kperf(mpsa);
|
||||||
kp.startPerfing();
|
kp.startPerfing();
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -2,12 +2,6 @@ package org.kne.cloud.network.klalb;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.concurrent.atomic.LongAdder;
|
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
|
||||||
|
|
||||||
public interface KLALBPacketLink {
|
public interface KLALBPacketLink {
|
||||||
public void writeKLALBPacket(KLALBPacket kp) throws IOException;
|
public void writeKLALBPacket(KLALBPacket kp) throws IOException;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.net.UnknownHostException;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.kne.cloud.network.KLALBDetectorItem;
|
import org.kne.cloud.network.KLALBDetectorItem;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ProtocolDetector;
|
import org.kne.cloud.network.ProtocolDetector;
|
||||||
import org.kne.cloud.network.ProtocolDetectorServerSocket;
|
import org.kne.cloud.network.ProtocolDetectorServerSocket;
|
||||||
import org.kne.cloud.network.ProtocolDetectorSocket;
|
import org.kne.cloud.network.ProtocolDetectorSocket;
|
||||||
@@ -30,8 +30,8 @@ public class KLALBProtocolDetectSocketListener extends SocketListener {
|
|||||||
super.open();
|
super.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLALBProtocolDetectSocketListener(MultipurposeSocketAddress multipurposeSocketAddress,KLALBController klalbc) throws IOException {
|
public KLALBProtocolDetectSocketListener(MultiProtocolSocketAddress multiProtocolSocketAddress, KLALBController klalbc) throws IOException {
|
||||||
super(multipurposeSocketAddress);
|
super(multiProtocolSocketAddress);
|
||||||
this.klalbController=klalbc;
|
this.klalbController=klalbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class KLALBProxySystem {
|
|||||||
private File jsonFile;
|
private File jsonFile;
|
||||||
{
|
{
|
||||||
GsonBuilder gb=new GsonBuilder().setPrettyPrinting();
|
GsonBuilder gb=new GsonBuilder().setPrettyPrinting();
|
||||||
MultipurposeSocketAddress.registerToGsonBuilder(gb);
|
MultiProtocolSocketAddress.registerToGsonBuilder(gb);
|
||||||
KLALBConfigItem.registerToGsonBuilder(gb);
|
KLALBConfigItem.registerToGsonBuilder(gb);
|
||||||
gson=gb.create();
|
gson=gb.create();
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public class KLALBProxySystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableRemoteManagement(MultipurposeSocketAddress bind) throws IOException {
|
public void enableRemoteManagement(MultiProtocolSocketAddress bind) throws IOException {
|
||||||
if(krm==null) {
|
if(krm==null) {
|
||||||
krm=new KLALBRemoteManagement(this,bind);
|
krm=new KLALBRemoteManagement(this,bind);
|
||||||
}else {
|
}else {
|
||||||
@@ -84,14 +84,18 @@ public class KLALBProxySystem {
|
|||||||
|
|
||||||
public void loadConfigJson(File jsonFile) throws IOException {
|
public void loadConfigJson(File jsonFile) throws IOException {
|
||||||
this.jsonFile=jsonFile;
|
this.jsonFile=jsonFile;
|
||||||
|
if(jsonFile.exists()) {
|
||||||
FileReader fr = null;
|
FileReader fr = null;
|
||||||
try {
|
try {
|
||||||
fr=new FileReader(jsonFile);
|
fr = new FileReader(jsonFile);
|
||||||
loadConfigJson(fr);
|
loadConfigJson(fr);
|
||||||
}finally {
|
} finally {
|
||||||
if(fr!=null)
|
if (fr != null)
|
||||||
fr.close();
|
fr.close();
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
loadConfig(KLALBConfig.getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void loadConfigJson(String json) {
|
public void loadConfigJson(String json) {
|
||||||
@@ -128,9 +132,9 @@ public class KLALBProxySystem {
|
|||||||
|
|
||||||
String vsne=kcci.getVirtualSocketName();
|
String vsne=kcci.getVirtualSocketName();
|
||||||
//if(vsne!=null) {
|
//if(vsne!=null) {
|
||||||
MultipurposeSocketAddress.getSocketTypeRegister().put(vsne, klalbController.getStreamSocketType());
|
MultiProtocolSocketAddress.getSocketTypeRegister().put(vsne, klalbController.getStreamSocketType());
|
||||||
//}
|
//}
|
||||||
MultipurposeSocketAddress tcple=kcci.getTCPListen();
|
MultiProtocolSocketAddress tcple=kcci.getTCPListen();
|
||||||
if(tcple!=null) {
|
if(tcple!=null) {
|
||||||
|
|
||||||
SocketChannelListener tcpl = null;
|
SocketChannelListener tcpl = null;
|
||||||
@@ -148,13 +152,13 @@ public class KLALBProxySystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
MultipurposeSocketAddress mpsa2=new MultipurposeSocketAddress(tcple.getType(), tcple.getHost(),((InetSocketAddress)tcpl.getServerSocketChannel().getLocalAddress()).getPort());
|
MultiProtocolSocketAddress mpsa2=new MultiProtocolSocketAddress(tcple.getProtocol(), tcple.getHost(),((InetSocketAddress)tcpl.getServerSocketChannel().getLocalAddress()).getPort());
|
||||||
klalbController.getListenSocketAddress().add(mpsa2);
|
klalbController.getListenSocketAddress().add(mpsa2);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MultipurposeSocketAddress udple=kcci.getUDPListen();
|
MultiProtocolSocketAddress udple=kcci.getUDPListen();
|
||||||
if(udple!=null) {
|
if(udple!=null) {
|
||||||
DatagramSocketListener udpl = null;
|
DatagramSocketListener udpl = null;
|
||||||
try {
|
try {
|
||||||
@@ -171,7 +175,7 @@ public class KLALBProxySystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
MultipurposeSocketAddress mpsau2=new MultipurposeSocketAddress(udple.getType(), udple.getHost(),((InetSocketAddress)(udpl.getDatagramServerSocket().getLocalSocketAddress())).getPort());
|
MultiProtocolSocketAddress mpsau2=new MultiProtocolSocketAddress(udple.getProtocol(), udple.getHost(),((InetSocketAddress)(udpl.getDatagramServerSocket().getLocalSocketAddress())).getPort());
|
||||||
//klalbController.getListenSocketAddress().add(mpsau2);
|
//klalbController.getListenSocketAddress().add(mpsau2);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package org.kne.cloud.network.klalb;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StreamCorruptedException;
|
import java.io.StreamCorruptedException;
|
||||||
|
import java.net.BindException;
|
||||||
|
import java.net.NoRouteToHostException;
|
||||||
|
import java.net.SocketException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.channels.UnresolvedAddressException;
|
import java.nio.channels.UnresolvedAddressException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@@ -21,7 +24,7 @@ import org.kne.cloud.clock.HighAccuracyClock;
|
|||||||
import org.kne.cloud.clock.NTPTimestamps;
|
import org.kne.cloud.clock.NTPTimestamps;
|
||||||
import org.kne.cloud.clock.ReliabilityBackoffTimeClock;
|
import org.kne.cloud.clock.ReliabilityBackoffTimeClock;
|
||||||
import org.kne.cloud.clock.WatchDogTimer;
|
import org.kne.cloud.clock.WatchDogTimer;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ThreadTool;
|
import org.kne.cloud.network.ThreadTool;
|
||||||
import org.kne.cloud.network.congestion.BBRCongestionAlgorithm;
|
import org.kne.cloud.network.congestion.BBRCongestionAlgorithm;
|
||||||
import org.kne.cloud.network.congestion.CongestionAlgorithm;
|
import org.kne.cloud.network.congestion.CongestionAlgorithm;
|
||||||
@@ -100,8 +103,8 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
private LinkStatus status=new LinkStatus();
|
private LinkStatus status=new LinkStatus();
|
||||||
private SpeedAndTrafficAndDelayMonitorDataImpl monitor;
|
private SpeedAndTrafficAndDelayMonitorDataImpl monitor;
|
||||||
private volatile KLALBPacketLink kplink;
|
private volatile KLALBPacketLink kplink;
|
||||||
private MultipurposeSocketAddress bindAddress;
|
private MultiProtocolSocketAddress bindAddress;
|
||||||
private MultipurposeSocketAddress socketAddress;
|
private MultiProtocolSocketAddress socketAddress;
|
||||||
|
|
||||||
|
|
||||||
public void setKplink(KLALBPacketLink kplink) {
|
public void setKplink(KLALBPacketLink kplink) {
|
||||||
@@ -112,11 +115,11 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
return kplink;
|
return kplink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getSocketAddress() {
|
public MultiProtocolSocketAddress getSocketAddress() {
|
||||||
return socketAddress;
|
return socketAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getBindAddress() {
|
public MultiProtocolSocketAddress getBindAddress() {
|
||||||
return bindAddress;
|
return bindAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +137,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
return peerAddress;
|
return peerAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLALBRemoteLink(KLALBController controller, MultipurposeSocketAddress mpa, IPv6AddressGroup address) {
|
public KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa, IPv6AddressGroup address) {
|
||||||
this(controller,mpa, null,address);
|
this(controller,mpa, null,address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +150,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
name=kpl.toString();
|
name=kpl.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private KLALBRemoteLink(KLALBController controller,MultipurposeSocketAddress mpa, MultipurposeSocketAddress bindaddr, IPv6AddressGroup address) {
|
private KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa, MultiProtocolSocketAddress bindaddr, IPv6AddressGroup address) {
|
||||||
this.klalbController=controller;
|
this.klalbController=controller;
|
||||||
sysclk = klalbController.getClock();
|
sysclk = klalbController.getClock();
|
||||||
this.socketAddress = mpa;
|
this.socketAddress = mpa;
|
||||||
@@ -162,11 +165,11 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public KLALBRemoteLink(KLALBController controller,MultipurposeSocketAddress mpa, MultipurposeSocketAddress bind) {
|
public KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa, MultiProtocolSocketAddress bind) {
|
||||||
this(controller,mpa, bind, null);
|
this(controller,mpa, bind, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLALBRemoteLink(KLALBController controller,MultipurposeSocketAddress mpa) {
|
public KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa) {
|
||||||
this(controller,mpa, (IPv6AddressGroup) null);
|
this(controller,mpa, (IPv6AddressGroup) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +286,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
sendLock.unlock();
|
sendLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tlock.parkNanos(1000000L);
|
tlock.parkNanos(10000000L);
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (StreamCorruptedException sce) {
|
} catch (StreamCorruptedException sce) {
|
||||||
@@ -464,7 +467,9 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
break;
|
break;
|
||||||
case KLALBPacket.VADDR:
|
case KLALBPacket.VADDR:
|
||||||
IPv6AddressGroup vdr = ((VADDRPacket) kpp).getVaddr();
|
IPv6AddressGroup vdr = ((VADDRPacket) kpp).getVaddr();
|
||||||
|
if(vdr.getAddress().equals(klalbController.getSelf().getAddress())){
|
||||||
|
close();
|
||||||
|
}else {
|
||||||
remoteVaddr = vdr;
|
remoteVaddr = vdr;
|
||||||
sendPacket(new VADDRACKPacket());
|
sendPacket(new VADDRACKPacket());
|
||||||
if (fst.compareAndSet(true, false)) {
|
if (fst.compareAndSet(true, false)) {
|
||||||
@@ -473,7 +478,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
KLALBRemoteLink.this.onOnlineStateUpdate();
|
KLALBRemoteLink.this.onOnlineStateUpdate();
|
||||||
}
|
}
|
||||||
KLALBRemoteLink.this.onLocatorUpdate();
|
KLALBRemoteLink.this.onLocatorUpdate();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case KLALBPacket.VADDRACK:
|
case KLALBPacket.VADDRACK:
|
||||||
break;
|
break;
|
||||||
@@ -567,7 +572,9 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
public void run() {
|
public void run() {
|
||||||
while (!closed) {
|
while (!closed) {
|
||||||
status.updateReliability();
|
status.updateReliability();
|
||||||
|
if(status.getState()!=LinkStatus.DOWN) {
|
||||||
monitor.update();
|
monitor.update();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -672,7 +679,23 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
}
|
}
|
||||||
} catch (StreamCorruptedException sce) {
|
} catch (StreamCorruptedException sce) {
|
||||||
sce.printStackTrace();
|
sce.printStackTrace();
|
||||||
} catch (IOException | UnresolvedAddressException e) {
|
}catch(BindException e) {
|
||||||
|
close();
|
||||||
|
if (debug)
|
||||||
|
e.printStackTrace();
|
||||||
|
}catch(NoRouteToHostException e){
|
||||||
|
close();
|
||||||
|
if (debug)
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch(SocketException e) {
|
||||||
|
String massage = e.getMessage();
|
||||||
|
if (massage.toLowerCase().contains("unreachable")) {
|
||||||
|
close();
|
||||||
|
} else {
|
||||||
|
if (debug)
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}catch (IOException | UnresolvedAddressException e) {
|
||||||
if (debug)
|
if (debug)
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -927,23 +950,25 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
|||||||
public List<RouteItem> getRouteItems() {
|
public List<RouteItem> getRouteItems() {
|
||||||
List<RouteItem> rlist = new ArrayList<>();
|
List<RouteItem> rlist = new ArrayList<>();
|
||||||
|
|
||||||
|
if(isUp()) {
|
||||||
IPv6AddressGroup adg = addressGroup;
|
IPv6AddressGroup adg = addressGroup;
|
||||||
/*if (adg != null)
|
/*if (adg != null)
|
||||||
rlist.add(new RouteItem(new IPv6AddressGroup(adg.getAddress(), 128), adg.getAddress(), this, "Direct", 0, 0,
|
rlist.add(new RouteItem(new IPv6AddressGroup(adg.getAddress(), 128), adg.getAddress(), this, "Direct", 0, 0,
|
||||||
null, "D", true));*/
|
null, "D", true));*/
|
||||||
|
|
||||||
for (Iterator<Neighbor> iteratorx = getNeighborsInfo().iterator(); iteratorx.hasNext();) {
|
for (Iterator<Neighbor> iteratorx = getNeighborsInfo().iterator(); iteratorx.hasNext(); ) {
|
||||||
Neighbor addresses = (Neighbor) iteratorx.next();
|
Neighbor addresses = (Neighbor) iteratorx.next();
|
||||||
RouteItem ri = new RouteItem(new IPv6AddressGroup(addresses.getAddress().getAddress(), 128),
|
RouteItem ri = new RouteItem(new IPv6AddressGroup(addresses.getAddress().getAddress(), 128),
|
||||||
addresses.getAddress().getAddress(), this, "Direct", 0, 128,CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(),status,algorithm::getRTO), "D", false);
|
addresses.getAddress().getAddress(), this, "Direct", 0, 128, CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(), status, algorithm::getRTO), "D", false);
|
||||||
rlist.add(ri);
|
rlist.add(ri);
|
||||||
|
|
||||||
if (addresses.getLocator() != null) {
|
if (addresses.getLocator() != null) {
|
||||||
RouteItem ris = new RouteItem(addresses.getLocator(), addresses.getLocator().getAddress(), this,
|
RouteItem ris = new RouteItem(addresses.getLocator(), addresses.getLocator().getAddress(), this,
|
||||||
"KLALB SRv6", 13, 128,CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(),status,algorithm::getRTO), "D", false);
|
"KLALB SRv6", 13, 128, CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(), status, algorithm::getRTO), "D", false);
|
||||||
rlist.add(ris);
|
rlist.add(ris);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return rlist;
|
return rlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.SocketListener;
|
import org.kne.cloud.network.SocketListener;
|
||||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||||
import org.kne.cloud.network.monitor.LinkStatus;
|
import org.kne.cloud.network.monitor.LinkStatus;
|
||||||
@@ -20,9 +20,9 @@ public class KLALBRemoteManagement {
|
|||||||
SocketListener slr;
|
SocketListener slr;
|
||||||
private KLALBProxySystem klalbProxySystem;
|
private KLALBProxySystem klalbProxySystem;
|
||||||
public KLALBRemoteManagement(KLALBProxySystem klalbProxySystem) throws IOException {
|
public KLALBRemoteManagement(KLALBProxySystem klalbProxySystem) throws IOException {
|
||||||
this(klalbProxySystem,new MultipurposeSocketAddress("127.9.9.9", 49573));
|
this(klalbProxySystem,new MultiProtocolSocketAddress("127.9.9.9", 49573));
|
||||||
}
|
}
|
||||||
public KLALBRemoteManagement(KLALBProxySystem klalbProxySystem,MultipurposeSocketAddress listen) throws IOException {
|
public KLALBRemoteManagement(KLALBProxySystem klalbProxySystem, MultiProtocolSocketAddress listen) throws IOException {
|
||||||
this.klalbProxySystem=klalbProxySystem;
|
this.klalbProxySystem=klalbProxySystem;
|
||||||
slr=new SocketListener(listen);
|
slr=new SocketListener(listen);
|
||||||
slr.setCon((srcv)->{
|
slr.setCon((srcv)->{
|
||||||
@@ -97,18 +97,18 @@ public class KLALBRemoteManagement {
|
|||||||
String mip=jreq.getAsJsonPrimitive("ipport").getAsString();
|
String mip=jreq.getAsJsonPrimitive("ipport").getAsString();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
jrsp.addProperty ("Vaddr",klalbProxySystem.getKlalbController().getRemoteVaddrBySocketAddress(new MultipurposeSocketAddress(mip)).getHostAddress());
|
jrsp.addProperty ("Vaddr",klalbProxySystem.getKlalbController().getRemoteVaddrBySocketAddress(new MultiProtocolSocketAddress(mip)).getHostAddress());
|
||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "GETSELFLINES":
|
case "GETSELFLINES":
|
||||||
JsonArray lines2=new JsonArray();
|
JsonArray lines2=new JsonArray();
|
||||||
List<MultipurposeSocketAddress>selflineslist=klalbProxySystem.getKlalbController().getSelflineTable();
|
List<MultiProtocolSocketAddress>selflineslist=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||||
synchronized (selflineslist) {
|
synchronized (selflineslist) {
|
||||||
for (Iterator<MultipurposeSocketAddress> iterator = selflineslist.iterator(); iterator.hasNext();) {
|
for (Iterator<MultiProtocolSocketAddress> iterator = selflineslist.iterator(); iterator.hasNext();) {
|
||||||
MultipurposeSocketAddress multipurposeSocketAddress = (MultipurposeSocketAddress) iterator.next();
|
MultiProtocolSocketAddress multiProtocolSocketAddress = (MultiProtocolSocketAddress) iterator.next();
|
||||||
lines2.add(new JsonPrimitive(multipurposeSocketAddress.toString()));
|
lines2.add(new JsonPrimitive(multiProtocolSocketAddress.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jrsp.add("table", lines2);
|
jrsp.add("table", lines2);
|
||||||
@@ -116,16 +116,16 @@ public class KLALBRemoteManagement {
|
|||||||
break;
|
break;
|
||||||
case "ADDSELFLINE":
|
case "ADDSELFLINE":
|
||||||
String mips=jreq.getAsJsonPrimitive("ipport").getAsString();
|
String mips=jreq.getAsJsonPrimitive("ipport").getAsString();
|
||||||
List<MultipurposeSocketAddress>selflineslist2=klalbProxySystem.getKlalbController().getSelflineTable();
|
List<MultiProtocolSocketAddress>selflineslist2=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||||
synchronized (selflineslist2) {
|
synchronized (selflineslist2) {
|
||||||
selflineslist2.add(new MultipurposeSocketAddress(mips));
|
selflineslist2.add(new MultiProtocolSocketAddress(mips));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "REMOVESELFLINE":
|
case "REMOVESELFLINE":
|
||||||
String mipsr=jreq.getAsJsonPrimitive("ipport").getAsString();
|
String mipsr=jreq.getAsJsonPrimitive("ipport").getAsString();
|
||||||
List<MultipurposeSocketAddress>selflineslist21=klalbProxySystem.getKlalbController().getSelflineTable();
|
List<MultiProtocolSocketAddress>selflineslist21=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||||
synchronized (selflineslist21) {
|
synchronized (selflineslist21) {
|
||||||
selflineslist21.add(new MultipurposeSocketAddress(mipsr));
|
selflineslist21.add(new MultiProtocolSocketAddress(mipsr));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "GETLINKMONITOR":
|
case "GETLINKMONITOR":
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.jctools.counters.CountersFactory;
|
import org.jctools.counters.CountersFactory;
|
||||||
import org.jctools.counters.FixedSizeStripedLongCounter;
|
import org.jctools.counters.FixedSizeStripedLongCounter;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||||
|
|
||||||
public class KLALBUtils {
|
public class KLALBUtils {
|
||||||
@@ -51,6 +51,27 @@ public class KLALBUtils {
|
|||||||
v[3] = 0x01;
|
v[3] = 0x01;
|
||||||
return IPv6Address.valueOf(v);
|
return IPv6Address.valueOf(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String parseCidr(String cidr) {
|
||||||
|
int idx = cidr.indexOf('/');
|
||||||
|
if (idx <= 0 || idx == cidr.length() - 1)
|
||||||
|
throw new IllegalArgumentException("not a cidr: " + cidr);
|
||||||
|
int prefix;
|
||||||
|
try {
|
||||||
|
prefix = Integer.parseInt(cidr.substring(idx + 1));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new IllegalArgumentException("bad prefix: " + cidr);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
InetAddress addr = InetAddress.getByName(cidr.substring(0, idx));
|
||||||
|
int max = (addr instanceof Inet6Address) ? 128 : 32;
|
||||||
|
if (prefix < 0 || prefix > max)
|
||||||
|
throw new IllegalArgumentException("prefix out of range: " + cidr);
|
||||||
|
return addr.getHostAddress() + "/" + prefix;
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new IllegalArgumentException("bad address: " + cidr);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(uuidToIP(new UUID(-1,-1)));
|
System.out.println(uuidToIP(new UUID(-1,-1)));
|
||||||
}
|
}
|
||||||
@@ -208,7 +229,7 @@ public class KLALBUtils {
|
|||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KLALBPacketLink createKLALBPacketLink(MultipurposeSocketAddress bindAddress, MultipurposeSocketAddress targetAddress,boolean buffered)
|
public static KLALBPacketLink createKLALBPacketLink(MultiProtocolSocketAddress bindAddress, MultiProtocolSocketAddress targetAddress, boolean buffered)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (targetAddress.isStream()) {
|
if (targetAddress.isStream()) {
|
||||||
if (targetAddress.supportNIO()) {
|
if (targetAddress.supportNIO()) {
|
||||||
@@ -235,8 +256,8 @@ public class KLALBUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static KLALBPacketLink createKLALBPacketLink(MultipurposeSocketAddress bindAddress,
|
public static KLALBPacketLink createKLALBPacketLink(MultiProtocolSocketAddress bindAddress,
|
||||||
MultipurposeSocketAddress targetAddress,boolean buffered, int timeout) throws UnknownHostException, IOException {
|
MultiProtocolSocketAddress targetAddress, boolean buffered, int timeout) throws UnknownHostException, IOException {
|
||||||
if (targetAddress.isStream()) {
|
if (targetAddress.isStream()) {
|
||||||
if (targetAddress.supportNIO()) {
|
if (targetAddress.supportNIO()) {
|
||||||
if (bindAddress != null) {
|
if (bindAddress != null) {
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NetworkInterfaceManager {
|
||||||
|
private List<NetworkInterface> networkInterfaceExcept = new ArrayList<>();
|
||||||
|
private List<InetAddress> inetAddressesExcept = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<NetworkInterface> getNetworkInterfaceExcept() {
|
||||||
|
return networkInterfaceExcept;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<InetAddress> getInetAddressesExcept() {
|
||||||
|
return inetAddressesExcept;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<NetworkInterface> getAllAvaliableNetworkInterface() throws SocketException {
|
||||||
|
List<NetworkInterface> interfaces = new ArrayList<NetworkInterface>();
|
||||||
|
Enumeration<NetworkInterface> eu = NetworkInterface.getNetworkInterfaces();
|
||||||
|
while (eu.hasMoreElements()) {
|
||||||
|
NetworkInterface networkInterface = (NetworkInterface) eu.nextElement();
|
||||||
|
|
||||||
|
if (networkInterface.getDisplayName()
|
||||||
|
.startsWith(CONST.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (networkInterfaceExcept.contains(networkInterface)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (networkInterface.isUp()) {
|
||||||
|
interfaces.add(networkInterface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return interfaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<InetAddress> getAllNetworkInterfaceAddress() throws SocketException {
|
||||||
|
List<NetworkInterface> interfaces=getAllAvaliableNetworkInterface();
|
||||||
|
List<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||||
|
for (NetworkInterface nif:interfaces){
|
||||||
|
addresses.addAll( getNetworkInterfaceAddress(nif));
|
||||||
|
}
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<InetAddress> getNetworkInterfaceAddress(NetworkInterface networkInterface) throws SocketException {
|
||||||
|
List<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||||
|
// System.out.println(networkInterface+" "+networkInterface.isUp());
|
||||||
|
Enumeration<InetAddress> ei = networkInterface.getInetAddresses();
|
||||||
|
while (ei.hasMoreElements()) {
|
||||||
|
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||||
|
|
||||||
|
if (inetAddress.isLoopbackAddress()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (inetAddressesExcept.contains( inetAddress)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
addresses.add(inetAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
|
import org.kne.cloud.network.klalb.ui.UIEnv;
|
||||||
|
|
||||||
|
public enum PerformanceStrategy {
|
||||||
|
SINGLE_CORE("singlecore"),
|
||||||
|
MULTI_FILL("multifill"),
|
||||||
|
MULTI_SCATTER("multiscatter");
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private PerformanceStrategy(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 description 查找对应的枚举对象。
|
||||||
|
*
|
||||||
|
* @param description 描述文本(资源包key)
|
||||||
|
* @return 对应的枚举对象
|
||||||
|
*/
|
||||||
|
public static PerformanceStrategy fromDescription(String description) {
|
||||||
|
for (PerformanceStrategy strategy : values()) {
|
||||||
|
if (strategy.description.equals(description)) {
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +1,23 @@
|
|||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.LinkedHashMap;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.kne.cloud.network.DefaultMinecraftSocketBridgeFactory;
|
import org.kne.cloud.network.DefaultMinecraftSocketBridgeFactory;
|
||||||
import org.kne.cloud.network.DefaultSocketBridgeFactory;
|
import org.kne.cloud.network.DefaultSocketBridgeFactory;
|
||||||
import org.kne.cloud.network.HostPortMap;
|
import org.kne.cloud.network.HostPortMap;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.Proxy;
|
import org.kne.cloud.network.Proxy;
|
||||||
import org.kne.cloud.network.SocketBridgeFactory;
|
import org.kne.cloud.network.SocketBridgeFactory;
|
||||||
import org.kne.cloud.network.SocketToSocketProxy;
|
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 {
|
public class SocketBridgeConfigItem extends KLALBConfigItem {
|
||||||
private MultipurposeSocketAddress Listen;
|
private MultiProtocolSocketAddress Listen;
|
||||||
|
|
||||||
private LinkedHashMap<String, String>Bridge=new LinkedHashMap<>();
|
private LinkedHashMap<String, String>Bridge=new LinkedHashMap<>();
|
||||||
private HostPortMap Connect=new HostPortMap();
|
private HostPortMap Connect=new HostPortMap();
|
||||||
|
|
||||||
public SocketBridgeConfigItem( MultipurposeSocketAddress listen,
|
public SocketBridgeConfigItem( MultiProtocolSocketAddress listen,
|
||||||
LinkedHashMap<String, String> bridge, HostPortMap connect) {
|
LinkedHashMap<String, String> bridge, HostPortMap connect) {
|
||||||
super("SocketBridge");
|
super("SocketBridge");
|
||||||
Listen = listen;
|
Listen = listen;
|
||||||
@@ -85,12 +68,12 @@ public class SocketBridgeConfigItem extends KLALBConfigItem {
|
|||||||
public Proxy createProxy(KLALBController controller) throws IOException {
|
public Proxy createProxy(KLALBController controller) throws IOException {
|
||||||
HostPortMap mapp=new HostPortMap();
|
HostPortMap mapp=new HostPortMap();
|
||||||
LinkedHashMap<String, SocketBridgeFactory>mapb=new LinkedHashMap<>();
|
LinkedHashMap<String, SocketBridgeFactory>mapb=new LinkedHashMap<>();
|
||||||
MultipurposeSocketAddress l=Listen;
|
MultiProtocolSocketAddress l=Listen;
|
||||||
SocketBridgeFactory bdg=getDefaultBridgeFactory(Bridge,mapb,controller);
|
SocketBridgeFactory bdg=getDefaultBridgeFactory(Bridge,mapb,controller);
|
||||||
MultipurposeSocketAddress r=getDefaultConnect(Connect,mapp);
|
MultiProtocolSocketAddress r=getDefaultConnect(Connect,mapp);
|
||||||
return new SocketToSocketProxy(l ,new MultipurposeSocketAddress("0.0.0.0:0"), r,mapp,bdg,mapb);
|
return new SocketToSocketProxy(l ,new MultiProtocolSocketAddress("0.0.0.0:0"), r,mapp,bdg,mapb);
|
||||||
}
|
}
|
||||||
private MultipurposeSocketAddress getDefaultConnect(HostPortMap connect2, LinkedHashMap<String, MultipurposeSocketAddress> mapp) {
|
private MultiProtocolSocketAddress getDefaultConnect(HostPortMap connect2, LinkedHashMap<String, MultiProtocolSocketAddress> mapp) {
|
||||||
connect2.entrySet().forEach((en)->{
|
connect2.entrySet().forEach((en)->{
|
||||||
mapp.put(en.getKey(), en.getValue());
|
mapp.put(en.getKey(), en.getValue());
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -116,29 +116,20 @@ public class DatagramKLALBPacketLink implements KLALBPacketLink {
|
|||||||
}*/
|
}*/
|
||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.Channels;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
import org.kne.cloud.network.DatagramServerSocket;
|
|
||||||
import org.kne.cloud.network.DatagramServerSocket.SubDatagramSocket;
|
import org.kne.cloud.network.DatagramServerSocket.SubDatagramSocket;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.NetworkPacket;
|
import org.kne.cloud.network.NetworkPacket;
|
||||||
import org.kne.cloud.network.PacketRebuilder;
|
import org.kne.cloud.network.PacketRebuilder;
|
||||||
import org.kne.cloud.network.PacketSpliter;
|
import org.kne.cloud.network.PacketSpliter;
|
||||||
import org.kne.cloud.network.SpeedLimiter;
|
|
||||||
import org.kne.debug.TimeDebugger;
|
|
||||||
|
|
||||||
public class SplitedDatagramKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
public class SplitedDatagramKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||||
private PacketSpliter pslr;
|
private PacketSpliter pslr;
|
||||||
@@ -146,7 +137,7 @@ public class SplitedDatagramKLALBPacketLink extends AbstractKLALBPacketLink impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
return new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
private DatagramSocket ds;
|
private DatagramSocket ds;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.nio.channels.SocketChannel;
|
|||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.kne.cloud.network.BufferedChannel;
|
import org.kne.cloud.network.BufferedChannel;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.NetworkPacket;
|
import org.kne.cloud.network.NetworkPacket;
|
||||||
import org.kne.cloud.network.ThreadTool;
|
import org.kne.cloud.network.ThreadTool;
|
||||||
import org.kne.io.KNEChannels;
|
import org.kne.io.KNEChannels;
|
||||||
@@ -45,7 +45,7 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
try {
|
||||||
return new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getLocalAddress())+"←"+new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getRemoteAddress());
|
return new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getLocalAddress())+"←"+new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getRemoteAddress());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return "?←?";
|
return "?←?";
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.nio.Buffer;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
|
|
||||||
public class StreamKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
public class StreamKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getLocalSocketAddress())+"←"+new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getRemoteSocketAddress());
|
return new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getLocalSocketAddress())+"←"+new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getRemoteSocketAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Socket connectSocket;
|
private Socket connectSocket;
|
||||||
|
|||||||
@@ -346,7 +346,16 @@ public class GraphPanel extends JPanel {
|
|||||||
g.setFont(UIEnv.getFont().deriveFont(10.0f));
|
g.setFont(UIEnv.getFont().deriveFont(10.0f));
|
||||||
|
|
||||||
//g.drawString(text, (int)(x+nodesize/2), (int)(y-nodesize/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));
|
int imgw=(image!=null)?image.getWidth(null):(int)nodesize;
|
||||||
|
int imgh=(image!=null)?image.getHeight(null):(int)nodesize;
|
||||||
|
java.awt.FontMetrics fm=g.getFontMetrics();
|
||||||
|
int lineHeight=fm.getHeight()+2;
|
||||||
|
int textx=(int)(x-imgw/2-10);
|
||||||
|
int texty=(int)(y+imgh/2+10)+fm.getAscent();
|
||||||
|
String[] lines=text.split("\n");
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
g.drawString(lines[i], textx, texty+i*lineHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getPositionVec2() {
|
public Vector2 getPositionVec2() {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.jfree.chart.plot.dial.*;
|
|||||||
import org.jfree.data.general.DefaultValueDataset;
|
import org.jfree.data.general.DefaultValueDataset;
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.klalb.uitool.*;
|
import org.kne.cloud.klalb.uitool.*;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||||
import org.kne.cloud.network.klalb.*;
|
import org.kne.cloud.network.klalb.*;
|
||||||
@@ -80,7 +80,11 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
private JTextField textFieldLocate; // 定位地址输入框
|
private JTextField textFieldLocate; // 定位地址输入框
|
||||||
private JTextField asnField2; // ASN显示框
|
private JTextField asnField2; // ASN显示框
|
||||||
private JTextArea dnsAreaSet; // DNS服务器设置区域
|
private JTextArea dnsAreaSet; // DNS服务器设置区域
|
||||||
private JComboBox comboPerformance; // 性能策略选择框
|
private JTextArea extraRoutesSet; // 额外路由设置区域
|
||||||
|
private JTextField deviceNameSet; // 设备名称设置框
|
||||||
|
private JTextArea deviceDescriptionSet; // 设备描述设置区域
|
||||||
|
private KLALBController kcontroller; // 关联的控制器
|
||||||
|
private JComboBox<PerformanceStrategyItem> comboPerformance; // 性能策略选择框
|
||||||
private JComboBox comboCongestion; // 拥塞控制算法选择框
|
private JComboBox comboCongestion; // 拥塞控制算法选择框
|
||||||
private JTextField tcpListeningSet; // TCP监听设置
|
private JTextField tcpListeningSet; // TCP监听设置
|
||||||
private JTextField udpListeningSet; // UDP监听设置
|
private JTextField udpListeningSet; // UDP监听设置
|
||||||
@@ -138,6 +142,7 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
* 初始化UI界面
|
* 初始化UI界面
|
||||||
*/
|
*/
|
||||||
private void initUI(KLALBController kc, String title) {
|
private void initUI(KLALBController kc, String title) {
|
||||||
|
kcontroller = kc;
|
||||||
// 设置窗口基本属性
|
// 设置窗口基本属性
|
||||||
setIconImage(UIEnv.getIcon());
|
setIconImage(UIEnv.getIcon());
|
||||||
setTitleColor(UIEnv.getDefaultTitleColor());
|
setTitleColor(UIEnv.getDefaultTitleColor());
|
||||||
@@ -597,7 +602,11 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
JButton btnNewButton = new JButton(UIEnv.getRsb().getString("addline"));
|
JButton btnNewButton = new JButton(UIEnv.getRsb().getString("addline"));
|
||||||
btnNewButton.addActionListener(e -> {
|
btnNewButton.addActionListener(e -> {
|
||||||
try {
|
try {
|
||||||
kc.addRemoteLines(new MultipurposeSocketAddress(textField.getText()));
|
MultiProtocolSocketAddress mpsa= new MultiProtocolSocketAddress(textField.getText());
|
||||||
|
Thread t=new Thread(()->{
|
||||||
|
kc.addRemoteLines(mpsa);
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
JOptionPane.showMessageDialog(KLALBStateGUI3.this, "Input format error", "Error",
|
JOptionPane.showMessageDialog(KLALBStateGUI3.this, "Input format error", "Error",
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
@@ -781,12 +790,30 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
addressFieldSet = addr6.getTextField();
|
addressFieldSet = addr6.getTextField();
|
||||||
settings.getView().add(addr6);
|
settings.getView().add(addr6);
|
||||||
|
|
||||||
|
// 设备名称设置
|
||||||
|
TextSettingItem deviceName = new TextSettingItem(UIEnv.getRsb().getString("devicename"),
|
||||||
|
CONST.itemwidth, CONST.settingheight);
|
||||||
|
deviceNameSet = deviceName.getTextField();
|
||||||
|
settings.getView().add(deviceName);
|
||||||
|
|
||||||
|
// 设备描述设置
|
||||||
|
TextAreaSettingItem deviceDescription = new TextAreaSettingItem(UIEnv.getRsb().getString("devicedescription"),
|
||||||
|
CONST.itemwidth, CONST.settingheight * 5);
|
||||||
|
deviceDescriptionSet = deviceDescription.getTextArea();
|
||||||
|
settings.getView().add(deviceDescription);
|
||||||
|
|
||||||
// DNS服务器设置
|
// DNS服务器设置
|
||||||
TextAreaSettingItem dns = new TextAreaSettingItem(UIEnv.getRsb().getString("dnsserver"),
|
TextAreaSettingItem dns = new TextAreaSettingItem(UIEnv.getRsb().getString("dnsserver"),
|
||||||
CONST.itemwidth, CONST.settingheight * 5);
|
CONST.itemwidth, CONST.settingheight * 5);
|
||||||
dnsAreaSet = dns.getTextArea();
|
dnsAreaSet = dns.getTextArea();
|
||||||
settings.getView().add(dns);
|
settings.getView().add(dns);
|
||||||
|
|
||||||
|
// 额外路由设置
|
||||||
|
TextAreaSettingItem extraRoutes = new TextAreaSettingItem(UIEnv.getRsb().getString("extraroutes"),
|
||||||
|
CONST.itemwidth, CONST.settingheight * 5);
|
||||||
|
extraRoutesSet = extraRoutes.getTextArea();
|
||||||
|
settings.getView().add(extraRoutes);
|
||||||
|
|
||||||
// ASN设置
|
// ASN设置
|
||||||
TextSettingItem asn = new TextSettingItem(UIEnv.getRsb().getString("asnumber"),
|
TextSettingItem asn = new TextSettingItem(UIEnv.getRsb().getString("asnumber"),
|
||||||
CONST.itemwidth, CONST.settingheight);
|
CONST.itemwidth, CONST.settingheight);
|
||||||
@@ -888,8 +915,10 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
performanceStrategy = new ComboSettingItem(UIEnv.getRsb().getString("performancestrategy"),
|
performanceStrategy = new ComboSettingItem(UIEnv.getRsb().getString("performancestrategy"),
|
||||||
CONST.itemwidth, CONST.settingheight);
|
CONST.itemwidth, CONST.settingheight);
|
||||||
comboPerformance = performanceStrategy.getComboBox();
|
comboPerformance = performanceStrategy.getComboBox();
|
||||||
comboPerformance.addItem("BBR");
|
comboPerformance.addItem(new PerformanceStrategyItem(PerformanceStrategy.SINGLE_CORE));
|
||||||
comboPerformance.addItem("Vegas2");
|
comboPerformance.addItem(new PerformanceStrategyItem(PerformanceStrategy.MULTI_FILL));
|
||||||
|
comboPerformance.addItem(new PerformanceStrategyItem(PerformanceStrategy.MULTI_SCATTER));
|
||||||
|
comboPerformance.setSelectedIndex(1);
|
||||||
settings.getView().add(performanceStrategy);
|
settings.getView().add(performanceStrategy);
|
||||||
|
|
||||||
|
|
||||||
@@ -1004,7 +1033,7 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
private void saveConfig() {
|
private void saveConfig() {
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
config = new KLALBConfig();
|
config = new KLALBConfig();
|
||||||
config.add(new KLALBControllerConfigItem("KLALBController"));
|
config.add(new KLALBControllerConfigItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (KLALBConfigItem item : config) {
|
for (KLALBConfigItem item : config) {
|
||||||
@@ -1016,6 +1045,26 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
kck.setNogui(nogui.isSelected());
|
kck.setNogui(nogui.isSelected());
|
||||||
|
|
||||||
|
// 保存设备名称
|
||||||
|
String dnametext = deviceNameSet.getText().trim();
|
||||||
|
if (dnametext.equals("")) {
|
||||||
|
kck.setDeviceName(null);
|
||||||
|
} else {
|
||||||
|
kck.setDeviceName(dnametext);
|
||||||
|
}
|
||||||
|
if (kcontroller != null && kcontroller.getIpv6Router() != null) {
|
||||||
|
kcontroller.getIpv6Router().setDeviceName(kck.getDeviceName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存设备描述
|
||||||
|
String ddesctext = deviceDescriptionSet.getText().trim();
|
||||||
|
if (ddesctext.equals("")) {
|
||||||
|
kck.setDeviceDescription(null);
|
||||||
|
} else {
|
||||||
|
kck.setDeviceDescription(ddesctext);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 保存IPv6地址
|
// 保存IPv6地址
|
||||||
String ttext = addressFieldSet.getText().trim();
|
String ttext = addressFieldSet.getText().trim();
|
||||||
if (ttext.equals("")) {
|
if (ttext.equals("")) {
|
||||||
@@ -1052,6 +1101,24 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
}
|
}
|
||||||
kck.setDNS(iaddr);
|
kck.setDNS(iaddr);
|
||||||
|
|
||||||
|
// 保存额外路由列表
|
||||||
|
String[] spltEr = extraRoutesSet.getText().split("\n");
|
||||||
|
List<String> eroutes = new ArrayList<>();
|
||||||
|
for (String str : spltEr) {
|
||||||
|
str = str.trim();
|
||||||
|
if (!str.isEmpty()) {
|
||||||
|
try {
|
||||||
|
eroutes.add(KLALBUtils.parseCidr(str));
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
JOptionPane.showMessageDialog(this, UIEnv.getRsb().getString("invaildextraroutes"),
|
||||||
|
UIEnv.getRsb().getString("warning"), JOptionPane.WARNING_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kck.setExtraRoutes(eroutes);
|
||||||
|
|
||||||
// 保存ASN
|
// 保存ASN
|
||||||
String asntext = asnFieldSet.getText();
|
String asntext = asnFieldSet.getText();
|
||||||
if (asntext.equals("")) {
|
if (asntext.equals("")) {
|
||||||
@@ -1067,8 +1134,8 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String tunNameText=tunDeviceName.getText();
|
String tunNameText=tunDeviceName.getText().trim();
|
||||||
if(tunNameText.equals("")) {
|
if(tunNameText.equals("") || tunNameText.equalsIgnoreCase("null")) {
|
||||||
kck.setTUNName(null);
|
kck.setTUNName(null);
|
||||||
}else {
|
}else {
|
||||||
kck.setTUNName(tunNameText);
|
kck.setTUNName(tunNameText);
|
||||||
@@ -1080,7 +1147,7 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
kck.setTCPListen(null);
|
kck.setTCPListen(null);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
kck.setTCPListen(new MultipurposeSocketAddress(tcptext));
|
kck.setTCPListen(new MultiProtocolSocketAddress(tcptext));
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
JOptionPane.showMessageDialog(this, UIEnv.getRsb().getString("invaildtcplisten"),
|
JOptionPane.showMessageDialog(this, UIEnv.getRsb().getString("invaildtcplisten"),
|
||||||
@@ -1095,7 +1162,7 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
kck.setUDPListen(null);
|
kck.setUDPListen(null);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
kck.setUDPListen(new MultipurposeSocketAddress(udptext));
|
kck.setUDPListen(new MultiProtocolSocketAddress(udptext,"udp"));
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
JOptionPane.showMessageDialog(this, UIEnv.getRsb().getString("invaildudplisten"),
|
JOptionPane.showMessageDialog(this, UIEnv.getRsb().getString("invaildudplisten"),
|
||||||
@@ -1106,13 +1173,13 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
// 保存开放线路表
|
// 保存开放线路表
|
||||||
String[] splt1 = openLineTabelSet.getText().split("\n");
|
String[] splt1 = openLineTabelSet.getText().split("\n");
|
||||||
List<MultipurposeSocketAddress> iaddr1 = new ArrayList<>();
|
List<MultiProtocolSocketAddress> iaddr1 = new ArrayList<>();
|
||||||
boolean show1 = true;
|
boolean show1 = true;
|
||||||
for (String str : splt1) {
|
for (String str : splt1) {
|
||||||
try {
|
try {
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
if (!str.isEmpty())
|
if (!str.isEmpty())
|
||||||
iaddr1.add(new MultipurposeSocketAddress(str));
|
iaddr1.add(new MultiProtocolSocketAddress(str));
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (show1) {
|
if (show1) {
|
||||||
@@ -1127,13 +1194,13 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
// 保存自动连接线路表
|
// 保存自动连接线路表
|
||||||
String[] splt11 = connectLineTabelSet.getText().split("\n");
|
String[] splt11 = connectLineTabelSet.getText().split("\n");
|
||||||
List<MultipurposeSocketAddress> iaddr11 = new ArrayList<>();
|
List<MultiProtocolSocketAddress> iaddr11 = new ArrayList<>();
|
||||||
boolean show11 = true;
|
boolean show11 = true;
|
||||||
for (String str : splt11) {
|
for (String str : splt11) {
|
||||||
try {
|
try {
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
if (!str.isEmpty())
|
if (!str.isEmpty())
|
||||||
iaddr11.add(new MultipurposeSocketAddress(str));
|
iaddr11.add(new MultiProtocolSocketAddress(str));
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (show11) {
|
if (show11) {
|
||||||
@@ -1148,13 +1215,13 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
// 保存NTP服务器表
|
// 保存NTP服务器表
|
||||||
String[] splt111 = ntpServerSet.getText().split("\n");
|
String[] splt111 = ntpServerSet.getText().split("\n");
|
||||||
List<MultipurposeSocketAddress> iaddr111 = new ArrayList<>();
|
List<MultiProtocolSocketAddress> iaddr111 = new ArrayList<>();
|
||||||
boolean show111 = true;
|
boolean show111 = true;
|
||||||
for (String str : splt111) {
|
for (String str : splt111) {
|
||||||
try {
|
try {
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
if (!str.isEmpty())
|
if (!str.isEmpty())
|
||||||
iaddr111.add(new MultipurposeSocketAddress(str));
|
iaddr111.add(new MultiProtocolSocketAddress(str,"ntp"));
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (show111) {
|
if (show111) {
|
||||||
@@ -1180,6 +1247,11 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
kck.setDenyLineTableBroadcast(denyBroadcast.isSelected());
|
kck.setDenyLineTableBroadcast(denyBroadcast.isSelected());
|
||||||
|
|
||||||
|
PerformanceStrategyItem psi=((PerformanceStrategyItem)comboPerformance.getSelectedItem());
|
||||||
|
if(psi!=null) {
|
||||||
|
kck.setPerformanceStrategy(psi.getStrategy().toString());
|
||||||
|
}
|
||||||
|
|
||||||
kck.setCongestionAlgorithm((String) congestions.getComboBox().getSelectedItem());
|
kck.setCongestionAlgorithm((String) congestions.getComboBox().getSelectedItem());
|
||||||
|
|
||||||
kck.setBurstLimit(1.0+burstLimit.getSlider().getValue()/1000.0);
|
kck.setBurstLimit(1.0+burstLimit.getSlider().getValue()/1000.0);
|
||||||
@@ -1213,6 +1285,7 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
tsk = new TimerTask() {
|
tsk = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (isVisible()) {
|
||||||
Object[] kll = kc.getLines().toArray();
|
Object[] kll = kc.getLines().toArray();
|
||||||
|
|
||||||
// 遍历所有线路,更新或添加TPanel2
|
// 遍历所有线路,更新或添加TPanel2
|
||||||
@@ -1242,7 +1315,7 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
if (!found) {
|
if (!found) {
|
||||||
TPanel2 tp = new TPanel2(ent, kc);
|
TPanel2 tp = new TPanel2(ent, kc);
|
||||||
tp.setVisible(showoffline.isSelected() || (
|
tp.setVisible(showoffline.isSelected() || (
|
||||||
ent.getState()!= LinkStatus.DOWN));
|
ent.getState() != LinkStatus.DOWN));
|
||||||
ysp.getView().add(tp);
|
ysp.getView().add(tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1266,6 +1339,7 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
ysp.updateScrool();
|
ysp.updateScrool();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
t.scheduleAtFixedRate(tsk, 1000, 1000);
|
t.scheduleAtFixedRate(tsk, 1000, 1000);
|
||||||
|
|
||||||
@@ -1440,6 +1514,14 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
nogui.setSelected( kck.isNogui());
|
nogui.setSelected( kck.isNogui());
|
||||||
|
|
||||||
|
// 加载设备名称
|
||||||
|
String dname = kck.getDeviceName();
|
||||||
|
deviceNameSet.setText(dname != null ? dname : "");
|
||||||
|
|
||||||
|
// 加载设备描述
|
||||||
|
String ddesc = kck.getDeviceDescription();
|
||||||
|
deviceDescriptionSet.setText(ddesc != null ? ddesc : "");
|
||||||
|
|
||||||
// 加载IPv6地址
|
// 加载IPv6地址
|
||||||
String vaddr = kck.getVirtualAddress();
|
String vaddr = kck.getVirtualAddress();
|
||||||
addressFieldSet.setText(vaddr != null ? vaddr : "");
|
addressFieldSet.setText(vaddr != null ? vaddr : "");
|
||||||
@@ -1448,6 +1530,10 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
List<InetAddress> dns = kck.getDNS();
|
List<InetAddress> dns = kck.getDNS();
|
||||||
dnsAreaSet.setText(listToStr(dns));
|
dnsAreaSet.setText(listToStr(dns));
|
||||||
|
|
||||||
|
// 加载额外路由
|
||||||
|
List<String> ers = kck.getExtraRoutes();
|
||||||
|
extraRoutesSet.setText(listToStr2(ers));
|
||||||
|
|
||||||
// 加载ASN
|
// 加载ASN
|
||||||
Long vasn = kck.getVirtualASN();
|
Long vasn = kck.getVirtualASN();
|
||||||
asnFieldSet.setText(vasn != null ? vasn.toString() : "");
|
asnFieldSet.setText(vasn != null ? vasn.toString() : "");
|
||||||
@@ -1456,23 +1542,23 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
tunDeviceName.setText(tunname!=null?tunname:"");
|
tunDeviceName.setText(tunname!=null?tunname:"");
|
||||||
|
|
||||||
// 加载TCP监听
|
// 加载TCP监听
|
||||||
MultipurposeSocketAddress mpat = kck.getTCPListen();
|
MultiProtocolSocketAddress mpat = kck.getTCPListen();
|
||||||
tcpListeningSet.setText(mpat != null ? mpat.toString() : "");
|
tcpListeningSet.setText(mpat != null ? mpat.toString() : "");
|
||||||
|
|
||||||
// 加载UDP监听
|
// 加载UDP监听
|
||||||
MultipurposeSocketAddress mpau = kck.getUDPListen();
|
MultiProtocolSocketAddress mpau = kck.getUDPListen();
|
||||||
udpListeningSet.setText(mpau != null ? mpau.toString() : "");
|
udpListeningSet.setText(mpau != null ? mpau.toString() : "");
|
||||||
|
|
||||||
// 加载开放线路表
|
// 加载开放线路表
|
||||||
List<MultipurposeSocketAddress> linet = kck.getLineTable();
|
List<MultiProtocolSocketAddress> linet = kck.getLineTable();
|
||||||
openLineTabelSet.setText(listToStr2(linet));
|
openLineTabelSet.setText(listToStr2(linet));
|
||||||
|
|
||||||
// 加载自动连接线路表
|
// 加载自动连接线路表
|
||||||
List<MultipurposeSocketAddress> clinet = kck.getConnectLineTable();
|
List<MultiProtocolSocketAddress> clinet = kck.getConnectLineTable();
|
||||||
connectLineTabelSet.setText(listToStr2(clinet));
|
connectLineTabelSet.setText(listToStr2(clinet));
|
||||||
|
|
||||||
// 加载NTP服务器表
|
// 加载NTP服务器表
|
||||||
List<MultipurposeSocketAddress> ntps = kck.getNtpServerTable();
|
List<MultiProtocolSocketAddress> ntps = kck.getNtpServerTable();
|
||||||
ntpServerSet.setText(listToStr2(ntps));
|
ntpServerSet.setText(listToStr2(ntps));
|
||||||
|
|
||||||
// 加载网络接口排除列表
|
// 加载网络接口排除列表
|
||||||
@@ -1497,6 +1583,17 @@ public class KLALBStateGUI3 extends XFrame {
|
|||||||
|
|
||||||
denyBroadcast.setSelected( kck.isDenyLineTableBroadcast());
|
denyBroadcast.setSelected( kck.isDenyLineTableBroadcast());
|
||||||
|
|
||||||
|
String stategy= kck.getPerformanceStrategy();
|
||||||
|
PerformanceStrategy pfs=PerformanceStrategy.fromDescription(stategy);
|
||||||
|
if(pfs!=null) {
|
||||||
|
for (int i=0;i<comboPerformance.getItemCount();i++){
|
||||||
|
if(((PerformanceStrategyItem)comboPerformance.getModel().getElementAt(i)).getStrategy().equals(pfs)) {
|
||||||
|
comboPerformance.setSelectedIndex(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String con=kck.getCongestionAlgorithm();
|
String con=kck.getCongestionAlgorithm();
|
||||||
if(con==null) {
|
if(con==null) {
|
||||||
congestions.getComboBox().setSelectedItem("BBR");
|
congestions.getComboBox().setSelectedItem("BBR");
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import javax.swing.border.LineBorder;
|
|||||||
|
|
||||||
import org.jfree.chart.plot.dial.DialTextAnnotation;
|
import org.jfree.chart.plot.dial.DialTextAnnotation;
|
||||||
import org.jfree.data.general.DefaultValueDataset;
|
import org.jfree.data.general.DefaultValueDataset;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.klalb.CONST;
|
import org.kne.cloud.network.klalb.CONST;
|
||||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||||
@@ -143,9 +143,9 @@ public class KperfGUI extends XFrame{
|
|||||||
if(kperf==null) {
|
if(kperf==null) {
|
||||||
try {
|
try {
|
||||||
String tar=targetAddressField.getText();
|
String tar=targetAddressField.getText();
|
||||||
MultipurposeSocketAddress msa=new MultipurposeSocketAddress(tar);
|
MultiProtocolSocketAddress msa=new MultiProtocolSocketAddress(tar);
|
||||||
String sour=sourceAddressField.getText();
|
String sour=sourceAddressField.getText();
|
||||||
MultipurposeSocketAddress msas=new MultipurposeSocketAddress(sour);
|
MultiProtocolSocketAddress msas=new MultiProtocolSocketAddress(sour);
|
||||||
kperf=new Kperf(msa,msas);
|
kperf=new Kperf(msa,msas);
|
||||||
kperf.setReports(reports);
|
kperf.setReports(reports);
|
||||||
kperf.startPerfing();
|
kperf.startPerfing();
|
||||||
@@ -650,10 +650,10 @@ public class KperfGUI extends XFrame{
|
|||||||
startButton.setText(UIEnv.getRsb().getString("stoptest"));
|
startButton.setText(UIEnv.getRsb().getString("stoptest"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setTarget(MultipurposeSocketAddress target) {
|
public void setTarget(MultiProtocolSocketAddress target) {
|
||||||
targetAddressField.setText(target.toString());
|
targetAddressField.setText(target.toString());
|
||||||
}
|
}
|
||||||
public void setTarget(MultipurposeSocketAddress target,MultipurposeSocketAddress source) {
|
public void setTarget(MultiProtocolSocketAddress target, MultiProtocolSocketAddress source) {
|
||||||
targetAddressField.setText(target.toString());
|
targetAddressField.setText(target.toString());
|
||||||
sourceAddressField.setText(source.toString());
|
sourceAddressField.setText(source.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +1,25 @@
|
|||||||
package org.kne.cloud.network.klalb.ui;
|
package org.kne.cloud.network.klalb.ui;
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.FontMetrics;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.Shape;
|
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.datatransfer.StringSelection;
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.geom.Dimension2D;
|
|
||||||
import java.awt.geom.GeneralPath;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.image.ImageObserver;
|
|
||||||
import java.net.Inet6Address;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.text.AttributedCharacterIterator;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.border.LineBorder;
|
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||||
import org.kne.cloud.network.klalb.KLALBController;
|
import org.kne.cloud.network.klalb.KLALBController;
|
||||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
|
||||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocol;
|
|
||||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocol.LinkDirection;
|
import org.kne.cloud.network.srv6.KLALBRoutingProtocol.LinkDirection;
|
||||||
|
|
||||||
public class NetworkGraphPanel extends GraphPanel {
|
public class NetworkGraphPanel extends GraphPanel {
|
||||||
@@ -70,7 +47,7 @@ public class NetworkGraphPanel extends GraphPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InetGraphNode(IPv6Address address, Color color, double x, double y, boolean ismarked) {
|
public InetGraphNode(IPv6Address address, Color color, double x, double y, boolean ismarked) {
|
||||||
super(getText(address), color, x, y, ismarked);
|
super(getNodeText(address), color, x, y, ismarked);
|
||||||
this.address=address;
|
this.address=address;
|
||||||
initign();
|
initign();
|
||||||
}
|
}
|
||||||
@@ -105,8 +82,8 @@ public class NetworkGraphPanel extends GraphPanel {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
KperfGUI kpfg=new KperfGUI();
|
KperfGUI kpfg=new KperfGUI();
|
||||||
kpfg.setVisible(true);
|
kpfg.setVisible(true);
|
||||||
MultipurposeSocketAddress source=new MultipurposeSocketAddress("KLALB_Stream",controller.getIpv6Router().getLocator().getAddress().toString(),0);
|
MultiProtocolSocketAddress source=new MultiProtocolSocketAddress("KLALB_Stream",controller.getIpv6Router().getLocator().getAddress().toString(),0);
|
||||||
MultipurposeSocketAddress target=new MultipurposeSocketAddress("KLALB_Stream", address.toString(), 4564);
|
MultiProtocolSocketAddress target=new MultiProtocolSocketAddress("KLALB_Stream", address.toString(), 4564);
|
||||||
kpfg.setTarget(target,source);
|
kpfg.setTarget(target,source);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -160,17 +137,33 @@ public class NetworkGraphPanel extends GraphPanel {
|
|||||||
return address2.toCompressedString();
|
return address2.toCompressedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateLabel() {
|
||||||
|
setText(getNodeText(address));
|
||||||
|
}
|
||||||
|
|
||||||
public IPv6Address getAddress() {
|
public IPv6Address getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddress(IPv6Address address) {
|
public void setAddress(IPv6Address address) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
super.setText(getText(address));
|
super.setText(getNodeText(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点标签:显示广播得知的设备名称(若有)+IP地址
|
||||||
|
*/
|
||||||
|
private String getNodeText(IPv6Address address) {
|
||||||
|
StringBuilder sb=new StringBuilder();
|
||||||
|
String dname=controller.getIpv6Router().getKlalbRouteProtol().getDeviceName(address);
|
||||||
|
if(dname!=null)
|
||||||
|
sb.append(dname).append('\n');
|
||||||
|
sb.append(InetGraphNode.getText(address));
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private double nsPerPixel=1000L;
|
private double nsPerPixel=1000L;
|
||||||
private class InetGraphEdgeGroup extends GraphEdgeGroup{
|
private class InetGraphEdgeGroup extends GraphEdgeGroup{
|
||||||
public InetGraphEdgeGroup(GraphNode nodeA, GraphNode nodeB) {
|
public InetGraphEdgeGroup(GraphNode nodeA, GraphNode nodeB) {
|
||||||
@@ -201,6 +194,8 @@ public class NetworkGraphPanel extends GraphPanel {
|
|||||||
IPv6Address inet6Address = (IPv6Address) iterator.next();
|
IPv6Address inet6Address = (IPv6Address) iterator.next();
|
||||||
if(!addr.containsKey(inet6Address)) {
|
if(!addr.containsKey(inet6Address)) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
}else {
|
||||||
|
((InetGraphNode)getNodes().get(inet6Address)).updateLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//System.out.println("------------------------------------");
|
//System.out.println("------------------------------------");
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import java.awt.Image;
|
|||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.datatransfer.StringSelection;
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
@@ -22,7 +21,7 @@ import javax.swing.event.ListSelectionEvent;
|
|||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
import org.kne.cloud.klalb.uitool.XDefaultListModel;
|
import org.kne.cloud.klalb.uitool.XDefaultListModel;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||||
import org.kne.cloud.network.klalb.KLALBController;
|
import org.kne.cloud.network.klalb.KLALBController;
|
||||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocol;
|
import org.kne.cloud.network.srv6.KLALBRoutingProtocol;
|
||||||
@@ -30,7 +29,6 @@ import org.kne.cloud.network.srv6.KLALBRoutingProtocolAPIClient;
|
|||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -43,7 +41,7 @@ public class NodeInformationPanel extends JPanel {
|
|||||||
private KLALBController controller;
|
private KLALBController controller;
|
||||||
private Image image;
|
private Image image;
|
||||||
|
|
||||||
private XDefaultListModel<MultipurposeSocketAddress> listModel=new XDefaultListModel<>();
|
private XDefaultListModel<MultiProtocolSocketAddress> listModel=new XDefaultListModel<>();
|
||||||
public KLALBController getController() {
|
public KLALBController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
@@ -69,11 +67,32 @@ public class NodeInformationPanel extends JPanel {
|
|||||||
panel.setLayout(new BorderLayout(0, 0));
|
panel.setLayout(new BorderLayout(0, 0));
|
||||||
tabbedPane.addTab(UIEnv.getRsb().getString("overview"), null, panel, null);
|
tabbedPane.addTab(UIEnv.getRsb().getString("overview"), null, panel, null);
|
||||||
|
|
||||||
|
JTextArea overviewArea = new JTextArea();
|
||||||
|
overviewArea.setEditable(false);
|
||||||
|
overviewArea.setLineWrap(true);
|
||||||
|
overviewArea.setWrapStyleWord(true);
|
||||||
|
overviewArea.setFont(UIEnv.getFont().deriveFont(14.0f));
|
||||||
|
overviewArea.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||||
|
StringBuilder sb=new StringBuilder();
|
||||||
|
sb.append(UIEnv.getRsb().getString("ipv6addr")).append(": ").append(address.toCompressedString()).append('\n');
|
||||||
|
String dname=controller.getIpv6Router().getKlalbRouteProtol().getDeviceName(address);
|
||||||
|
if(dname!=null) {
|
||||||
|
sb.append('\n').append(UIEnv.getRsb().getString("devicename")).append(": ").append(dname).append('\n');
|
||||||
|
}
|
||||||
|
if(address.equals(controller.getIpv6Router().getLocator().getAddress())&&controller.getConfigItem()!=null) {
|
||||||
|
String ddesc=controller.getConfigItem().getDeviceDescription();
|
||||||
|
if(ddesc!=null&&!ddesc.isEmpty()) {
|
||||||
|
sb.append('\n').append(UIEnv.getRsb().getString("devicedescription")).append(":\n").append(ddesc).append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
overviewArea.setText(sb.toString());
|
||||||
|
panel.add(new JScrollPane(overviewArea), BorderLayout.CENTER);
|
||||||
|
|
||||||
JPanel panel_1 = new JPanel();
|
JPanel panel_1 = new JPanel();
|
||||||
panel_1.setLayout(new BorderLayout(0, 0));
|
panel_1.setLayout(new BorderLayout(0, 0));
|
||||||
panel_1.add(scrollPane);
|
panel_1.add(scrollPane);
|
||||||
|
|
||||||
JList<MultipurposeSocketAddress> list = new JList<MultipurposeSocketAddress>(listModel);
|
JList<MultiProtocolSocketAddress> list = new JList<MultiProtocolSocketAddress>(listModel);
|
||||||
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||||
scrollPane.setViewportView(list);
|
scrollPane.setViewportView(list);
|
||||||
tabbedPane.addTab(UIEnv.getRsb().getString("openlinetable"), null, panel_1, null);
|
tabbedPane.addTab(UIEnv.getRsb().getString("openlinetable"), null, panel_1, null);
|
||||||
@@ -81,7 +100,7 @@ public class NodeInformationPanel extends JPanel {
|
|||||||
JButton btnNewButton = new JButton(UIEnv.getRsb().getString("addline"));
|
JButton btnNewButton = new JButton(UIEnv.getRsb().getString("addline"));
|
||||||
btnNewButton.addActionListener(new ActionListener() {
|
btnNewButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
List<MultipurposeSocketAddress> select=list.getSelectedValuesList();
|
List<MultiProtocolSocketAddress> select=list.getSelectedValuesList();
|
||||||
controller.addRemoteLines(select);
|
controller.addRemoteLines(select);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -93,7 +112,7 @@ public class NodeInformationPanel extends JPanel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
List<MultipurposeSocketAddress> select=list.getSelectedValuesList();
|
List<MultiProtocolSocketAddress> select=list.getSelectedValuesList();
|
||||||
btnNewButton.setEnabled( !select.isEmpty()) ;
|
btnNewButton.setEnabled( !select.isEmpty()) ;
|
||||||
copy.setEnabled(!select.isEmpty());
|
copy.setEnabled(!select.isEmpty());
|
||||||
}
|
}
|
||||||
@@ -103,9 +122,9 @@ public class NodeInformationPanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
StringBuilder sb=new StringBuilder();
|
StringBuilder sb=new StringBuilder();
|
||||||
List<MultipurposeSocketAddress> select=list.getSelectedValuesList();
|
List<MultiProtocolSocketAddress> select=list.getSelectedValuesList();
|
||||||
for (MultipurposeSocketAddress multipurposeSocketAddress : select) {
|
for (MultiProtocolSocketAddress multiProtocolSocketAddress : select) {
|
||||||
sb.append(multipurposeSocketAddress);
|
sb.append(multiProtocolSocketAddress);
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(sb.toString()), null);
|
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(sb.toString()), null);
|
||||||
@@ -152,8 +171,8 @@ public class NodeInformationPanel extends JPanel {
|
|||||||
try {
|
try {
|
||||||
client.requestOpenLines(new InetSocketAddress( address.toInet6Address(), KLALBRoutingProtocol.DEFAULT_PORT), (result)->{
|
client.requestOpenLines(new InetSocketAddress( address.toInet6Address(), KLALBRoutingProtocol.DEFAULT_PORT), (result)->{
|
||||||
listModel.clear();
|
listModel.clear();
|
||||||
for (MultipurposeSocketAddress multipurposeSocketAddress : result) {
|
for (MultiProtocolSocketAddress multiProtocolSocketAddress : result) {
|
||||||
listModel.addElement(multipurposeSocketAddress);
|
listModel.addElement(multiProtocolSocketAddress);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.kne.cloud.network.klalb.ui;
|
||||||
|
|
||||||
|
import org.kne.cloud.network.klalb.PerformanceStrategy;
|
||||||
|
|
||||||
|
public class PerformanceStrategyItem {
|
||||||
|
private PerformanceStrategy strategy;
|
||||||
|
|
||||||
|
public PerformanceStrategyItem(PerformanceStrategy strategy) {
|
||||||
|
this.strategy = strategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PerformanceStrategy getStrategy() {
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return UIEnv.getRsb().getString(strategy.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import java.awt.Dimension;
|
|||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||||
import org.kne.cloud.network.klalb.CONST;
|
import org.kne.cloud.network.klalb.CONST;
|
||||||
import org.kne.cloud.network.klalb.KLALBController;
|
import org.kne.cloud.network.klalb.KLALBController;
|
||||||
@@ -219,7 +219,7 @@ public class TPanel2 extends JPanel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
MultipurposeSocketAddress mtar=tunnel.getSocketAddress();
|
MultiProtocolSocketAddress mtar=tunnel.getSocketAddress();
|
||||||
if(mtar!=null) {
|
if(mtar!=null) {
|
||||||
kc.removeRemoteLines(mtar);
|
kc.removeRemoteLines(mtar);
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ public class KLTPInputStream extends InputStream implements KLTPPacketConsumer,
|
|||||||
case KLTPPacket.KLTP_TYPE_DATA:
|
case KLTPPacket.KLTP_TYPE_DATA:
|
||||||
//ackSequenceBatcher.putMessage(kseq);
|
//ackSequenceBatcher.putMessage(kseq);
|
||||||
recvMap.put(kltp.getSequence(), kltp);
|
recvMap.put(kltp.getSequence(), kltp);
|
||||||
controller.getIpv6Router().runPacketSendTask(()->{
|
controller.getIpv6Router().enqueuePacketSendTask(()->{
|
||||||
KLTPPacket pack=new KLTPPacket(streamUUID,KLTPPacket.KLTP_TYPE_ACK,kltp.getSequence(),0);
|
KLTPPacket pack=new KLTPPacket(streamUUID,KLTPPacket.KLTP_TYPE_ACK,kltp.getSequence(),0);
|
||||||
pack.setCE(u.isCE());
|
pack.setCE(u.isCE());
|
||||||
return controller.createPacketToAddress(remoteaddr,0,pack);
|
return controller.createPacketToAddress(remoteaddr,0,pack);
|
||||||
@@ -267,7 +267,7 @@ public class KLTPInputStream extends InputStream implements KLTPPacketConsumer,
|
|||||||
case KLTPPacket.KLTP_TYPE_DATAFIN:
|
case KLTPPacket.KLTP_TYPE_DATAFIN:
|
||||||
//ackSequenceBatcher.putMessage(kseq2);
|
//ackSequenceBatcher.putMessage(kseq2);
|
||||||
recvMap.put(kltp.getSequence(), kltp);
|
recvMap.put(kltp.getSequence(), kltp);
|
||||||
controller.getIpv6Router().runPacketSendTask(()->{
|
controller.getIpv6Router().enqueuePacketSendTask(()->{
|
||||||
KLTPPacket pack=new KLTPPacket(streamUUID,KLTPPacket.KLTP_TYPE_ACK,kltp.getSequence(),0);
|
KLTPPacket pack=new KLTPPacket(streamUUID,KLTPPacket.KLTP_TYPE_ACK,kltp.getSequence(),0);
|
||||||
pack.setCE(u.isCE());
|
pack.setCE(u.isCE());
|
||||||
return controller.createPacketToAddress(remoteaddr,0,pack);
|
return controller.createPacketToAddress(remoteaddr,0,pack);
|
||||||
|
|||||||
@@ -1,23 +1,22 @@
|
|||||||
package org.kne.cloud.network.minecraft;
|
package org.kne.cloud.network.minecraft;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.scanner.InetAddressRange;
|
import org.kne.cloud.network.scanner.InetAddressRange;
|
||||||
import org.kne.cloud.network.scanner.PortRange;
|
import org.kne.cloud.network.scanner.PortRange;
|
||||||
import org.kne.cloud.network.scanner.ScanRange;
|
import org.kne.cloud.network.scanner.ScanRange;
|
||||||
import org.kne.cloud.network.scanner.TCPNetworkScanner;
|
import org.kne.cloud.network.scanner.TCPNetworkScanner;
|
||||||
|
|
||||||
public class MinecraftScanner extends TCPNetworkScanner{
|
public class MinecraftScanner extends TCPNetworkScanner{
|
||||||
private BiConsumer<MultipurposeSocketAddress, MinecraftServerPinger>minecraftConsumer;
|
private BiConsumer<MultiProtocolSocketAddress, MinecraftServerPinger>minecraftConsumer;
|
||||||
|
|
||||||
public BiConsumer<MultipurposeSocketAddress, MinecraftServerPinger> getMinecraftConsumer() {
|
public BiConsumer<MultiProtocolSocketAddress, MinecraftServerPinger> getMinecraftConsumer() {
|
||||||
return minecraftConsumer;
|
return minecraftConsumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinecraftConsumer(BiConsumer<MultipurposeSocketAddress, MinecraftServerPinger> minecraftConsumer) {
|
public void setMinecraftConsumer(BiConsumer<MultiProtocolSocketAddress, MinecraftServerPinger> minecraftConsumer) {
|
||||||
this.minecraftConsumer = minecraftConsumer;
|
this.minecraftConsumer = minecraftConsumer;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import javax.naming.directory.Attributes;
|
|||||||
import javax.naming.directory.DirContext;
|
import javax.naming.directory.DirContext;
|
||||||
import javax.naming.directory.InitialDirContext;
|
import javax.naming.directory.InitialDirContext;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
|
|
||||||
public class MinecraftServerAddress extends MultipurposeSocketAddress
|
public class MinecraftServerAddress extends MultiProtocolSocketAddress
|
||||||
{
|
{
|
||||||
|
|
||||||
private String originAddr;
|
private String originAddr;
|
||||||
|
|||||||
@@ -3,14 +3,8 @@ package org.kne.cloud.network.minecraft;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.Externalizable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.ObjectInput;
|
|
||||||
import java.io.ObjectOutput;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.StringReader;
|
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@@ -19,13 +13,11 @@ import java.util.Base64;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
import com.google.gson.stream.JsonToken;
|
|
||||||
|
|
||||||
public class MinecraftServerPinger implements Serializable{
|
public class MinecraftServerPinger implements Serializable{
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +26,7 @@ public class MinecraftServerPinger implements Serializable{
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private transient Socket socket;
|
private transient Socket socket;
|
||||||
private transient MinecraftProtocolContext mpc=new MinecraftProtocolContext();
|
private transient MinecraftProtocolContext mpc=new MinecraftProtocolContext();
|
||||||
private MultipurposeSocketAddress targetaddr;
|
private MultiProtocolSocketAddress targetaddr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -53,11 +45,11 @@ public class MinecraftServerPinger implements Serializable{
|
|||||||
private String icon;
|
private String icon;
|
||||||
private transient BufferedImage image;
|
private transient BufferedImage image;
|
||||||
|
|
||||||
public MinecraftServerPinger(MultipurposeSocketAddress target) throws UnknownHostException, IOException {
|
public MinecraftServerPinger(MultiProtocolSocketAddress target) throws UnknownHostException, IOException {
|
||||||
this(target,target.connectSocket());
|
this(target,target.connectSocket());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftServerPinger(MultipurposeSocketAddress target, Socket Asocket) throws UnknownHostException, IOException{
|
public MinecraftServerPinger(MultiProtocolSocketAddress target, Socket Asocket) throws UnknownHostException, IOException{
|
||||||
targetaddr=target;
|
targetaddr=target;
|
||||||
socket=Asocket;
|
socket=Asocket;
|
||||||
socket.setTcpNoDelay(true);
|
socket.setTcpNoDelay(true);
|
||||||
@@ -302,7 +294,7 @@ public class MinecraftServerPinger implements Serializable{
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getTargetaddr() {
|
public MultiProtocolSocketAddress getTargetaddr() {
|
||||||
return targetaddr;
|
return targetaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.kne.cloud.network.minecraft;
|
|||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.scanner.InetAddressRange;
|
import org.kne.cloud.network.scanner.InetAddressRange;
|
||||||
import org.kne.cloud.network.scanner.PortRange;
|
import org.kne.cloud.network.scanner.PortRange;
|
||||||
import org.kne.cloud.network.scanner.ScanRange;
|
import org.kne.cloud.network.scanner.ScanRange;
|
||||||
@@ -13,7 +13,7 @@ public class MinecraftServerScanRange extends ScanRange {
|
|||||||
super(addressRange, portRange);
|
super(addressRange, portRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftServerScanRange(MultipurposeSocketAddress begin, MultipurposeSocketAddress end)
|
public MinecraftServerScanRange(MultiProtocolSocketAddress begin, MultiProtocolSocketAddress end)
|
||||||
throws UnknownHostException {
|
throws UnknownHostException {
|
||||||
super(begin, end);
|
super(begin, end);
|
||||||
}
|
}
|
||||||
@@ -25,8 +25,8 @@ public class MinecraftServerScanRange extends ScanRange {
|
|||||||
@Override
|
@Override
|
||||||
protected void setMsaString(String range) throws UnknownHostException {
|
protected void setMsaString(String range) throws UnknownHostException {
|
||||||
String[]sp=range.split("~");
|
String[]sp=range.split("~");
|
||||||
MultipurposeSocketAddress begin=MinecraftServerAddress.findAddress (sp[0]);
|
MultiProtocolSocketAddress begin=MinecraftServerAddress.findAddress (sp[0]);
|
||||||
MultipurposeSocketAddress end;
|
MultiProtocolSocketAddress end;
|
||||||
if(sp.length>1) {
|
if(sp.length>1) {
|
||||||
end=MinecraftServerAddress.findAddress (sp[1]);
|
end=MinecraftServerAddress.findAddress (sp[1]);
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||||
|
import org.kne.concurrent.LazyEvaluator;
|
||||||
|
|
||||||
public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements SpeedAndTrafficMonitorData {
|
public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements SpeedAndTrafficMonitorData {
|
||||||
|
|
||||||
@@ -16,11 +17,12 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private final long TIME_WINDOW=2000000000L;
|
||||||
public SpeedAndTrafficMonitorDataImpl(HighAccuracyClock clock) {
|
public SpeedAndTrafficMonitorDataImpl(HighAccuracyClock clock) {
|
||||||
super();
|
super();
|
||||||
this.clock=clock;
|
this.clock=clock;
|
||||||
uploadBandwidth=new ArrayListTimestampMonitor<UUID>(clock,"UploadMonitor", 100, 5000000000L);
|
uploadBandwidth=new ArrayListTimestampMonitor<UUID>(clock,"UploadMonitor", 100, TIME_WINDOW);
|
||||||
downloadBandwidth=new ArrayListTimestampMonitor<UUID>(clock,"DownloadMonitor", 100, 5000000000L);
|
downloadBandwidth=new ArrayListTimestampMonitor<UUID>(clock,"DownloadMonitor", 100, TIME_WINDOW);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,12 +88,13 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private LazyEvaluator<Long> outSpeedEvaluator=new LazyEvaluator<Long>(()->{return uploadBandwidth.calculateBandwidth(timewindow);});
|
||||||
public long getOutSpeed() {
|
public long getOutSpeed() {
|
||||||
return uploadBandwidth.calculateBandwidth(timewindow);
|
return outSpeedEvaluator.get();
|
||||||
}
|
}
|
||||||
|
private LazyEvaluator<Long> inSpeedEvaluator=new LazyEvaluator<Long>(()->{return downloadBandwidth.calculateBandwidth(timewindow);});
|
||||||
public long getInSpeed() {
|
public long getInSpeed() {
|
||||||
return downloadBandwidth.calculateBandwidth(timewindow);
|
return inSpeedEvaluator.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -117,13 +120,15 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private LazyEvaluator<Long> outPPSEvaluator=new LazyEvaluator<Long>(()->{return uploadBandwidth.calculatePacketRate(timewindow);});
|
||||||
public long getOutPPS() {
|
public long getOutPPS() {
|
||||||
return uploadBandwidth.calculatePacketRate(timewindow);
|
return outPPSEvaluator.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LazyEvaluator<Long> inPPSEvaluator=new LazyEvaluator<Long>(()->{return downloadBandwidth.calculatePacketRate(timewindow);});
|
||||||
|
|
||||||
public long getInPPS() {
|
public long getInPPS() {
|
||||||
return downloadBandwidth.calculatePacketRate(timewindow);
|
return inPPSEvaluator.get();
|
||||||
}
|
}
|
||||||
private long inSpeed;
|
private long inSpeed;
|
||||||
private long outSpeed;
|
private long outSpeed;
|
||||||
@@ -159,9 +164,18 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
|||||||
public void update() {
|
public void update() {
|
||||||
upSampler.update();
|
upSampler.update();
|
||||||
downSampler.update();
|
downSampler.update();
|
||||||
uploadBandwidth.recordPacket(KLALBUtils.createGlobalUUID(),(int)upSampler.getPacketCountSinceLastSnapshot() ,(int)upSampler.getByteCountSinceLastSnapshot());
|
long uppacketcount=upSampler.getPacketCountSinceLastSnapshot();
|
||||||
downloadBandwidth.recordPacket(KLALBUtils.createGlobalUUID(),(int)downSampler.getPacketCountSinceLastSnapshot() ,(int) downSampler.getByteCountSinceLastSnapshot());
|
if(uppacketcount>0) {
|
||||||
|
uploadBandwidth.recordPacket(KLALBUtils.createGlobalUUID(), (int) uppacketcount, (int) upSampler.getByteCountSinceLastSnapshot());
|
||||||
|
outSpeedEvaluator.markDirty();
|
||||||
|
outPPSEvaluator.markDirty();
|
||||||
|
}
|
||||||
|
long downpacketcount=downSampler.getPacketCountSinceLastSnapshot();
|
||||||
|
if(downpacketcount>0) {
|
||||||
|
downloadBandwidth.recordPacket(KLALBUtils.createGlobalUUID(), (int) downpacketcount, (int) downSampler.getByteCountSinceLastSnapshot());
|
||||||
|
inSpeedEvaluator.markDirty();
|
||||||
|
inPPSEvaluator.markDirty();
|
||||||
|
}
|
||||||
long time=System.nanoTime();
|
long time=System.nanoTime();
|
||||||
if(time-stime>timewindowmax) {
|
if(time-stime>timewindowmax) {
|
||||||
stime=time;
|
stime=time;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.clock.NTPTimestamps;
|
import org.kne.cloud.clock.NTPTimestamps;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ntp.NTPv4Protocol.NTPPeer;
|
import org.kne.cloud.network.ntp.NTPv4Protocol.NTPPeer;
|
||||||
import org.kne.math.Long128;
|
import org.kne.math.Long128;
|
||||||
|
|
||||||
@@ -110,13 +110,13 @@ public class NTPContext implements Closeable, AutoCloseable {
|
|||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConcurrentHashMap<MultipurposeSocketAddress, List<NTPv4Packet>> recvmap = new ConcurrentHashMap<MultipurposeSocketAddress, List<NTPv4Packet>>();
|
private ConcurrentHashMap<MultiProtocolSocketAddress, List<NTPv4Packet>> recvmap = new ConcurrentHashMap<MultiProtocolSocketAddress, List<NTPv4Packet>>();
|
||||||
|
|
||||||
protected void clearPackets() {
|
protected void clearPackets() {
|
||||||
recvmap.clear();
|
recvmap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putPacket(NTPv4Packet nv4, MultipurposeSocketAddress inetSocketAddress) {
|
protected void putPacket(NTPv4Packet nv4, MultiProtocolSocketAddress inetSocketAddress) {
|
||||||
checkIP();
|
checkIP();
|
||||||
List<NTPv4Packet> newv = new Vector<NTPv4Packet>();
|
List<NTPv4Packet> newv = new Vector<NTPv4Packet>();
|
||||||
List<NTPv4Packet> oldv = recvmap.putIfAbsent(inetSocketAddress, newv);
|
List<NTPv4Packet> oldv = recvmap.putIfAbsent(inetSocketAddress, newv);
|
||||||
@@ -133,10 +133,10 @@ public class NTPContext implements Closeable, AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkIP() {
|
private void checkIP() {
|
||||||
Set<Entry<MultipurposeSocketAddress, List<NTPv4Packet>>> ens = recvmap.entrySet();
|
Set<Entry<MultiProtocolSocketAddress, List<NTPv4Packet>>> ens = recvmap.entrySet();
|
||||||
for (Iterator<Entry<MultipurposeSocketAddress, List<NTPv4Packet>>> iterator = ens.iterator(); iterator
|
for (Iterator<Entry<MultiProtocolSocketAddress, List<NTPv4Packet>>> iterator = ens.iterator(); iterator
|
||||||
.hasNext();) {
|
.hasNext();) {
|
||||||
Entry<MultipurposeSocketAddress, List<NTPv4Packet>> entry = (Entry<MultipurposeSocketAddress, List<NTPv4Packet>>) iterator
|
Entry<MultiProtocolSocketAddress, List<NTPv4Packet>> entry = (Entry<MultiProtocolSocketAddress, List<NTPv4Packet>>) iterator
|
||||||
.next();
|
.next();
|
||||||
AtomicBoolean ab = new AtomicBoolean(false);
|
AtomicBoolean ab = new AtomicBoolean(false);
|
||||||
ios.forEach((x) -> {
|
ios.forEach((x) -> {
|
||||||
@@ -153,7 +153,7 @@ public class NTPContext implements Closeable, AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class PeerInfo implements Comparable<PeerInfo> {
|
private class PeerInfo implements Comparable<PeerInfo> {
|
||||||
private MultipurposeSocketAddress address;
|
private MultiProtocolSocketAddress address;
|
||||||
private int leapIndicator = 3;
|
private int leapIndicator = 3;
|
||||||
private int stratum = 16;
|
private int stratum = 16;
|
||||||
private int referenceIdentifier;
|
private int referenceIdentifier;
|
||||||
@@ -265,10 +265,10 @@ public class NTPContext implements Closeable, AutoCloseable {
|
|||||||
|
|
||||||
private List<PeerInfo> mergeResponses() {
|
private List<PeerInfo> mergeResponses() {
|
||||||
List<PeerInfo> peerInfo = new ArrayList<PeerInfo>();
|
List<PeerInfo> peerInfo = new ArrayList<PeerInfo>();
|
||||||
Set<Entry<MultipurposeSocketAddress, List<NTPv4Packet>>> ens = recvmap.entrySet();
|
Set<Entry<MultiProtocolSocketAddress, List<NTPv4Packet>>> ens = recvmap.entrySet();
|
||||||
for (Iterator<Entry<MultipurposeSocketAddress, List<NTPv4Packet>>> iterator = ens.iterator(); iterator
|
for (Iterator<Entry<MultiProtocolSocketAddress, List<NTPv4Packet>>> iterator = ens.iterator(); iterator
|
||||||
.hasNext();) {
|
.hasNext();) {
|
||||||
Entry<MultipurposeSocketAddress, List<NTPv4Packet>> entry = (Entry<MultipurposeSocketAddress, List<NTPv4Packet>>) iterator
|
Entry<MultiProtocolSocketAddress, List<NTPv4Packet>> entry = (Entry<MultiProtocolSocketAddress, List<NTPv4Packet>>) iterator
|
||||||
.next();
|
.next();
|
||||||
|
|
||||||
List<NTPv4Packet> newv = entry.getValue();
|
List<NTPv4Packet> newv = entry.getValue();
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.kne.cloud.network.ntp;
|
||||||
|
|
||||||
|
import org.kne.cloud.network.UDPSocketType;
|
||||||
|
|
||||||
|
public class NTPSocketType extends UDPSocketType {
|
||||||
|
private static final NTPSocketType INSTANCE = new NTPSocketType();
|
||||||
|
|
||||||
|
private NTPSocketType() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NTPSocketType getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDefaultPort() {
|
||||||
|
return 123;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
|
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.clock.NTPTimestamps;
|
import org.kne.cloud.clock.NTPTimestamps;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
|
import org.kne.cloud.network.ThreadTool;
|
||||||
import org.kne.io.KNEChannels;
|
import org.kne.io.KNEChannels;
|
||||||
import org.kne.math.Long128;
|
import org.kne.math.Long128;
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
private static final long EPHEMERAL_TIMEOUT = 60000000000L;
|
private static final long EPHEMERAL_TIMEOUT = 60000000000L;
|
||||||
|
|
||||||
public static class NTPPeer {
|
public static class NTPPeer {
|
||||||
private MultipurposeSocketAddress address;
|
private MultiProtocolSocketAddress address;
|
||||||
private boolean isEphemeral;// ephemeral
|
private boolean isEphemeral;// ephemeral
|
||||||
private volatile long ephemeralUpdateTime = System.nanoTime();
|
private volatile long ephemeralUpdateTime = System.nanoTime();
|
||||||
private volatile long pollInterval = DEFAULT_POLL_INTERVAL;
|
private volatile long pollInterval = DEFAULT_POLL_INTERVAL;
|
||||||
@@ -70,11 +71,11 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
this.pollInterval = pollInterval;
|
this.pollInterval = pollInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NTPPeer(MultipurposeSocketAddress address, int requestMode) {
|
public NTPPeer(MultiProtocolSocketAddress address, int requestMode) {
|
||||||
this(address, requestMode, false);
|
this(address, requestMode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NTPPeer(MultipurposeSocketAddress address, int requestMode, boolean isEphemeral) {
|
protected NTPPeer(MultiProtocolSocketAddress address, int requestMode, boolean isEphemeral) {
|
||||||
super();
|
super();
|
||||||
checkRequestMode(requestMode);
|
checkRequestMode(requestMode);
|
||||||
this.address = address;
|
this.address = address;
|
||||||
@@ -90,10 +91,10 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public NTPPeer(String hostport, int requestMode) {
|
public NTPPeer(String hostport, int requestMode) {
|
||||||
this(new MultipurposeSocketAddress(hostport), requestMode);
|
this(new MultiProtocolSocketAddress(hostport), requestMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipurposeSocketAddress getAddress() {
|
public MultiProtocolSocketAddress getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,17 +154,28 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
|
|
||||||
private NTPContext context;
|
private NTPContext context;
|
||||||
private DatagramSocket dgs;
|
private DatagramSocket dgs;
|
||||||
private MultipurposeSocketAddress bind;
|
private MultiProtocolSocketAddress bind;
|
||||||
|
|
||||||
public NTPv4Protocol(NTPContext context) throws UnknownHostException, IOException {
|
public NTPv4Protocol(NTPContext context) throws UnknownHostException, IOException {
|
||||||
this(context, new MultipurposeSocketAddress("UDP", "::0", NTP_DEFAULT_PORT));
|
this(context, new MultiProtocolSocketAddress("UDP", "::0", NTP_DEFAULT_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public NTPv4Protocol(NTPContext context, MultipurposeSocketAddress bind) throws UnknownHostException, IOException {
|
public NTPv4Protocol(NTPContext context, MultiProtocolSocketAddress bind) throws UnknownHostException, IOException {
|
||||||
this.bind = bind;
|
this.bind = bind;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
dgs = bind.listenDatagramSocket();
|
dgs = bind.listenDatagramSocket();
|
||||||
context.registerIO(this);
|
context.registerIO(this);
|
||||||
|
Thread t4= ThreadTool.makeVThread("NTPv4 Packet Cleaner",()->{
|
||||||
|
while(isClosed()){
|
||||||
|
removeTimeoutTimestamp();
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t4.start();
|
||||||
Thread tr = new Thread(recv);
|
Thread tr = new Thread(recv);
|
||||||
tr.setName("NTPv4 Receive Thread");
|
tr.setName("NTPv4 Receive Thread");
|
||||||
tr.start();
|
tr.start();
|
||||||
@@ -219,7 +231,6 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
private void putOriginTimestamp(NTPv4Packet nv4, NTPPeer peer) {
|
private void putOriginTimestamp(NTPv4Packet nv4, NTPPeer peer) {
|
||||||
checkLock.lock();
|
checkLock.lock();
|
||||||
try {
|
try {
|
||||||
removeTimeoutTimestamp();
|
|
||||||
checkList.add(new CheckListItem(nv4.getTransmitTimestamp128(), peer));
|
checkList.add(new CheckListItem(nv4.getTransmitTimestamp128(), peer));
|
||||||
} finally {
|
} finally {
|
||||||
checkLock.unlock();
|
checkLock.unlock();
|
||||||
@@ -227,7 +238,9 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeTimeoutTimestamp() {
|
private void removeTimeoutTimestamp() {
|
||||||
for (Iterator<CheckListItem> iterator = checkList.iterator(); iterator.hasNext();) {
|
checkLock.lock();
|
||||||
|
try {
|
||||||
|
for (Iterator<CheckListItem> iterator = checkList.iterator(); iterator.hasNext(); ) {
|
||||||
CheckListItem bigInteger = (CheckListItem) iterator.next();
|
CheckListItem bigInteger = (CheckListItem) iterator.next();
|
||||||
if (bigInteger.checkTimeout()) {
|
if (bigInteger.checkTimeout()) {
|
||||||
if (showPacket)
|
if (showPacket)
|
||||||
@@ -235,6 +248,9 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}finally{
|
||||||
|
checkLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNTPPacket(NTPv4Packet nv4, SocketAddress target) throws IOException {
|
private void sendNTPPacket(NTPv4Packet nv4, SocketAddress target) throws IOException {
|
||||||
@@ -266,7 +282,7 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTPPeer findPeer(MultipurposeSocketAddress addr) {
|
NTPPeer findPeer(MultiProtocolSocketAddress addr) {
|
||||||
Object[] objs = peers.toArray();
|
Object[] objs = peers.toArray();
|
||||||
for (int i = 0; i < objs.length; i++) {
|
for (int i = 0; i < objs.length; i++) {
|
||||||
NTPPeer np = (NTPPeer) objs[i];
|
NTPPeer np = (NTPPeer) objs[i];
|
||||||
@@ -291,7 +307,7 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
while (!dgs.isClosed()) {
|
while (!dgs.isClosed()) {
|
||||||
AtomicReference<InetSocketAddress> isa = new AtomicReference<>();
|
AtomicReference<InetSocketAddress> isa = new AtomicReference<>();
|
||||||
NTPv4Packet nv4 = receiveNTPPacket(isa);
|
NTPv4Packet nv4 = receiveNTPPacket(isa);
|
||||||
MultipurposeSocketAddress mpsafrom = new MultipurposeSocketAddress(bind.getType(), isa.get());
|
MultiProtocolSocketAddress mpsafrom = new MultiProtocolSocketAddress(bind.getProtocol(), isa.get());
|
||||||
switch (nv4.getMode()) {
|
switch (nv4.getMode()) {
|
||||||
case NTPv4Packet.NTP_SYMMETRIC_ACTIVE:
|
case NTPv4Packet.NTP_SYMMETRIC_ACTIVE:
|
||||||
NTPv4Packet nv4r = new NTPv4Packet(context.getClock());
|
NTPv4Packet nv4r = new NTPv4Packet(context.getClock());
|
||||||
@@ -393,7 +409,7 @@ public class NTPv4Protocol implements Closeable, AutoCloseable {
|
|||||||
HighAccuracyClock hac = new HighAccuracyClock();
|
HighAccuracyClock hac = new HighAccuracyClock();
|
||||||
NTPContext context = new NTPContext(hac);
|
NTPContext context = new NTPContext(hac);
|
||||||
System.out.println(context);
|
System.out.println(context);
|
||||||
NTPv4Protocol nvc = new NTPv4Protocol(context, new MultipurposeSocketAddress("{UDP}0.0.0.0:123"));// 106.55.184.199
|
NTPv4Protocol nvc = new NTPv4Protocol(context, new MultiProtocolSocketAddress("{UDP}0.0.0.0:123"));// 106.55.184.199
|
||||||
nvc.getPeers().add(new NTPPeer("{UDP}106.55.184.199:123", NTPv4Packet.NTP_CLIENT));
|
nvc.getPeers().add(new NTPPeer("{UDP}106.55.184.199:123", NTPv4Packet.NTP_CLIENT));
|
||||||
nvc.getPeers().add(new NTPPeer("{UDP}time.windows.com:123", NTPv4Packet.NTP_CLIENT));
|
nvc.getPeers().add(new NTPPeer("{UDP}time.windows.com:123", NTPv4Packet.NTP_CLIENT));
|
||||||
nvc.getPeers().add(new NTPPeer("{UDP}127.0.0.1:123", NTPv4Packet.NTP_SYMMETRIC_ACTIVE));
|
nvc.getPeers().add(new NTPPeer("{UDP}127.0.0.1:123", NTPv4Packet.NTP_SYMMETRIC_ACTIVE));
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import java.io.IOException;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ntp.NTPv4Protocol.NTPPeer;
|
|
||||||
|
|
||||||
public class TestNTP1 {
|
public class TestNTP1 {
|
||||||
public static void main(String[] args) throws UnknownHostException, IOException {
|
public static void main(String[] args) throws UnknownHostException, IOException {
|
||||||
@@ -13,7 +12,7 @@ public class TestNTP1 {
|
|||||||
NTPContext context = new NTPContext(hac);
|
NTPContext context = new NTPContext(hac);
|
||||||
context.syncToSystem();
|
context.syncToSystem();
|
||||||
System.out.println(context);
|
System.out.println(context);
|
||||||
NTPv4Protocol nvc = new NTPv4Protocol(context, new MultipurposeSocketAddress("{UDP}0.0.0.0:123"));// 106.55.184.199
|
NTPv4Protocol nvc = new NTPv4Protocol(context, new MultiProtocolSocketAddress("{UDP}0.0.0.0:123"));// 106.55.184.199
|
||||||
//nvc.getPeers().add(new NTPPeer("{UDP}106.55.184.199:123", NTPv4Packet.NTP_CLIENT));
|
//nvc.getPeers().add(new NTPPeer("{UDP}106.55.184.199:123", NTPv4Packet.NTP_CLIENT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ntp.NTPv4Protocol.NTPPeer;
|
import org.kne.cloud.network.ntp.NTPv4Protocol.NTPPeer;
|
||||||
|
|
||||||
public class TestNTP2 {
|
public class TestNTP2 {
|
||||||
@@ -13,7 +13,7 @@ public class TestNTP2 {
|
|||||||
NTPContext context = new NTPContext(hac);
|
NTPContext context = new NTPContext(hac);
|
||||||
context.syncToSystem();
|
context.syncToSystem();
|
||||||
System.out.println(context);
|
System.out.println(context);
|
||||||
NTPv4Protocol nvc = new NTPv4Protocol(context, new MultipurposeSocketAddress("{UDP}0.0.0.0:0"));// 106.55.184.199
|
NTPv4Protocol nvc = new NTPv4Protocol(context, new MultiProtocolSocketAddress("{UDP}0.0.0.0:0"));// 106.55.184.199
|
||||||
nvc.getPeers().add(new NTPPeer("{UDP}127.0.0.1:123", NTPv4Packet.NTP_SYMMETRIC_ACTIVE));
|
nvc.getPeers().add(new NTPPeer("{UDP}127.0.0.1:123", NTPv4Packet.NTP_SYMMETRIC_ACTIVE));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||||||
|
|
||||||
import org.kne.cloud.clock.AdjustedNanoClock;
|
import org.kne.cloud.clock.AdjustedNanoClock;
|
||||||
import org.kne.cloud.clock.HighAccuracyClock;
|
import org.kne.cloud.clock.HighAccuracyClock;
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.SpeedLimiter;
|
import org.kne.cloud.network.SpeedLimiter;
|
||||||
import org.kne.cloud.network.ThreadTool;
|
import org.kne.cloud.network.ThreadTool;
|
||||||
import org.kne.cloud.network.klalb.KLALBPacket;
|
import org.kne.cloud.network.klalb.KLALBPacket;
|
||||||
@@ -32,8 +32,8 @@ public class Kperf implements Runnable{
|
|||||||
|
|
||||||
private static final boolean showpacket = false;
|
private static final boolean showpacket = false;
|
||||||
private volatile AdjustedNanoClock adjnc = new AdjustedNanoClock();
|
private volatile AdjustedNanoClock adjnc = new AdjustedNanoClock();
|
||||||
private MultipurposeSocketAddress targetAddress;
|
private MultiProtocolSocketAddress targetAddress;
|
||||||
private MultipurposeSocketAddress bindAddress;
|
private MultiProtocolSocketAddress bindAddress;
|
||||||
private volatile boolean connected=false;
|
private volatile boolean connected=false;
|
||||||
private volatile KLALBPacketLink link;
|
private volatile KLALBPacketLink link;
|
||||||
|
|
||||||
@@ -43,13 +43,13 @@ public class Kperf implements Runnable{
|
|||||||
private volatile boolean closed = false;
|
private volatile boolean closed = false;
|
||||||
|
|
||||||
private volatile ThreadParker tlock=new ThreadParker();
|
private volatile ThreadParker tlock=new ThreadParker();
|
||||||
public Kperf(MultipurposeSocketAddress targetAddress,MultipurposeSocketAddress bindAddress) {
|
public Kperf(MultiProtocolSocketAddress targetAddress, MultiProtocolSocketAddress bindAddress) {
|
||||||
Objects.requireNonNull(targetAddress);
|
Objects.requireNonNull(targetAddress);
|
||||||
this.targetAddress=targetAddress;
|
this.targetAddress=targetAddress;
|
||||||
this.bindAddress=bindAddress;
|
this.bindAddress=bindAddress;
|
||||||
}
|
}
|
||||||
public Kperf(MultipurposeSocketAddress targetAddress) {
|
public Kperf(MultiProtocolSocketAddress targetAddress) {
|
||||||
this(targetAddress,new MultipurposeSocketAddress("[::0]:0"));
|
this(targetAddress,new MultiProtocolSocketAddress("[::0]:0"));
|
||||||
}
|
}
|
||||||
public Kperf(KLALBPacketLink link) {
|
public Kperf(KLALBPacketLink link) {
|
||||||
Objects.requireNonNull(link);
|
Objects.requireNonNull(link);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.SocketChannelListener;
|
import org.kne.cloud.network.SocketChannelListener;
|
||||||
import org.kne.cloud.network.ThreadTool;
|
import org.kne.cloud.network.ThreadTool;
|
||||||
import org.kne.cloud.network.klalb.KLALBController;
|
import org.kne.cloud.network.klalb.KLALBController;
|
||||||
@@ -58,7 +58,7 @@ for (int i = 0; i < nodes; i++) {
|
|||||||
for (int j = 0; j < 1; j++) {
|
for (int j = 0; j < 1; j++) {
|
||||||
int ind=r.nextInt(size);
|
int ind=r.nextInt(size);
|
||||||
NodeEntry ne=nodeList.get(ind);
|
NodeEntry ne=nodeList.get(ind);
|
||||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress((InetSocketAddress) ne.getScl().getServerSocketChannel().getLocalAddress());
|
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress((InetSocketAddress) ne.getScl().getServerSocketChannel().getLocalAddress());
|
||||||
kct.addRemoteLines(mpsa);
|
kct.addRemoteLines(mpsa);
|
||||||
System.out.println("connect:" +ne.getKc().getSelf().getAddress());
|
System.out.println("connect:" +ne.getKc().getSelf().getAddress());
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ for (int i = 0; i < nodes; i++) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
NodeEntry ne=nodeList.get(0);
|
NodeEntry ne=nodeList.get(0);
|
||||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress((InetSocketAddress) ne.getScl().getServerSocketChannel().getLocalAddress());
|
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress((InetSocketAddress) ne.getScl().getServerSocketChannel().getLocalAddress());
|
||||||
klalbController.addRemoteLines(mpsa);
|
klalbController.addRemoteLines(mpsa);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.Serializable;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
|
|
||||||
public class ScanRange implements Serializable {
|
public class ScanRange implements Serializable {
|
||||||
public ScanRange(String range) throws UnknownHostException {
|
public ScanRange(String range) throws UnknownHostException {
|
||||||
@@ -12,21 +12,21 @@ public class ScanRange implements Serializable {
|
|||||||
}
|
}
|
||||||
protected void setMsaString(String range) throws UnknownHostException {
|
protected void setMsaString(String range) throws UnknownHostException {
|
||||||
String[]sp=range.split("~");
|
String[]sp=range.split("~");
|
||||||
MultipurposeSocketAddress begin=new MultipurposeSocketAddress(sp[0]);
|
MultiProtocolSocketAddress begin=new MultiProtocolSocketAddress(sp[0]);
|
||||||
MultipurposeSocketAddress end;
|
MultiProtocolSocketAddress end;
|
||||||
if(sp.length>1) {
|
if(sp.length>1) {
|
||||||
end=new MultipurposeSocketAddress(sp[1]);
|
end=new MultiProtocolSocketAddress(sp[1]);
|
||||||
}else {
|
}else {
|
||||||
end=new MultipurposeSocketAddress(sp[0]);
|
end=new MultiProtocolSocketAddress(sp[0]);
|
||||||
}
|
}
|
||||||
setMsa(begin, end);
|
setMsa(begin, end);
|
||||||
}
|
}
|
||||||
public ScanRange(MultipurposeSocketAddress begin,MultipurposeSocketAddress end) throws UnknownHostException {
|
public ScanRange(MultiProtocolSocketAddress begin, MultiProtocolSocketAddress end) throws UnknownHostException {
|
||||||
setMsa(begin,end);
|
setMsa(begin,end);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setMsa(MultipurposeSocketAddress begin, MultipurposeSocketAddress end) throws UnknownHostException {
|
protected void setMsa(MultiProtocolSocketAddress begin, MultiProtocolSocketAddress end) throws UnknownHostException {
|
||||||
this.addressRange=new InetAddressRange(begin.getHost(), end.getHost());
|
this.addressRange=new InetAddressRange(begin.getHost(), end.getHost());
|
||||||
this.portRange=new PortRange(begin.getPort(), end.getPort());
|
this.portRange=new PortRange(begin.getPort(), end.getPort());
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ public class ScanRange implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new MultipurposeSocketAddress(addressRange.getBeginHost(), portRange.getBegin())+"~"+new MultipurposeSocketAddress(addressRange.getEndHost(), portRange.getEnd());
|
return new MultiProtocolSocketAddress(addressRange.getBeginHost(), portRange.getBegin())+"~"+new MultiProtocolSocketAddress(addressRange.getEndHost(), portRange.getEnd());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.net.UnknownHostException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
@@ -20,11 +19,11 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.ThreadTool;
|
import org.kne.cloud.network.ThreadTool;
|
||||||
|
|
||||||
public class TCPNetworkScanner implements Runnable {
|
public class TCPNetworkScanner implements Runnable {
|
||||||
private BiConsumer<MultipurposeSocketAddress,Socket> consumer;
|
private BiConsumer<MultiProtocolSocketAddress,Socket> consumer;
|
||||||
private Consumer<Float>processConsumer;
|
private Consumer<Float>processConsumer;
|
||||||
|
|
||||||
public Consumer<Float> getProcessConsumer() {
|
public Consumer<Float> getProcessConsumer() {
|
||||||
@@ -44,11 +43,11 @@ public class TCPNetworkScanner implements Runnable {
|
|||||||
return ranges;
|
return ranges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BiConsumer<MultipurposeSocketAddress,Socket> getConsumer() {
|
public BiConsumer<MultiProtocolSocketAddress,Socket> getConsumer() {
|
||||||
return consumer;
|
return consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConsumer(BiConsumer<MultipurposeSocketAddress,Socket> consumer) {
|
public void setConsumer(BiConsumer<MultiProtocolSocketAddress,Socket> consumer) {
|
||||||
this.consumer = consumer;
|
this.consumer = consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,13 +127,13 @@ ThreadPoolExecutor excd=(ThreadPoolExecutor) Executors.newFixedThreadPool(8);
|
|||||||
exc.execute(()->{
|
exc.execute(()->{
|
||||||
|
|
||||||
|
|
||||||
MultipurposeSocketAddress mpsa;
|
MultiProtocolSocketAddress mpsa;
|
||||||
if (currAddress.equals(inetAddressRange.getBegin())) {
|
if (currAddress.equals(inetAddressRange.getBegin())) {
|
||||||
mpsa = new MultipurposeSocketAddress(inetAddressRange.getBeginHost(), curport0);
|
mpsa = new MultiProtocolSocketAddress(inetAddressRange.getBeginHost(), curport0);
|
||||||
}else if (currAddress.equals(inetAddressRange.getEnd())) {
|
}else if (currAddress.equals(inetAddressRange.getEnd())) {
|
||||||
mpsa = new MultipurposeSocketAddress(inetAddressRange.getEndHost(), curport0);
|
mpsa = new MultiProtocolSocketAddress(inetAddressRange.getEndHost(), curport0);
|
||||||
} else {
|
} else {
|
||||||
mpsa = new MultipurposeSocketAddress(currAddress.getHostAddress(),
|
mpsa = new MultiProtocolSocketAddress(currAddress.getHostAddress(),
|
||||||
curport0);
|
curport0);
|
||||||
}
|
}
|
||||||
Socket s = null;
|
Socket s = null;
|
||||||
@@ -228,7 +227,7 @@ ThreadPoolExecutor excd=(ThreadPoolExecutor) Executors.newFixedThreadPool(8);
|
|||||||
System.arraycopy( new BigInteger(curr).add(BigInteger.valueOf(1)).toByteArray(), 0, curr, 0, curr.length); ;
|
System.arraycopy( new BigInteger(curr).add(BigInteger.valueOf(1)).toByteArray(), 0, curr, 0, curr.length); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void acceptMultipurposeSocketAddress(MultipurposeSocketAddress scanned, Socket s) {
|
protected void acceptMultipurposeSocketAddress(MultiProtocolSocketAddress scanned, Socket s) {
|
||||||
|
|
||||||
consumer.accept(scanned,s);
|
consumer.accept(scanned,s);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,14 @@
|
|||||||
package org.kne.cloud.network.srv6;
|
package org.kne.cloud.network.srv6;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.Externalizable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInput;
|
|
||||||
import java.io.ObjectOutput;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.Inet6Address;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.Channels;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.NetworkPacket;
|
|
||||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
@@ -53,7 +38,7 @@ public class JsonDataPacket extends KLALBRoutingProtocolPacket implements Serial
|
|||||||
private static Gson gson;
|
private static Gson gson;
|
||||||
static{
|
static{
|
||||||
GsonBuilder gb=new GsonBuilder();
|
GsonBuilder gb=new GsonBuilder();
|
||||||
MultipurposeSocketAddress.registerToGsonBuilder(gb);
|
MultiProtocolSocketAddress.registerToGsonBuilder(gb);
|
||||||
gson=gb.create();
|
gson=gb.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -545,6 +545,7 @@ public class KLALBRoutingProtocol extends Thread{
|
|||||||
List<IPv6NetworkLink>links=router.getLinkTabel();
|
List<IPv6NetworkLink>links=router.getLinkTabel();
|
||||||
Object[] nls=links.toArray();
|
Object[] nls=links.toArray();
|
||||||
RouterInfo ri=new RouterInfo(System.currentTimeMillis(),router.getLocator(),router.getASN());
|
RouterInfo ri=new RouterInfo(System.currentTimeMillis(),router.getLocator(),router.getASN());
|
||||||
|
ri.setDeviceName(router.getDeviceName());
|
||||||
for(int i=0;i<nls.length;i++) {
|
for(int i=0;i<nls.length;i++) {
|
||||||
IPv6NetworkLink nl=(IPv6NetworkLink) nls[i];
|
IPv6NetworkLink nl=(IPv6NetworkLink) nls[i];
|
||||||
if((!nl.isLoopBack())&&nl.isUp()) {
|
if((!nl.isLoopBack())&&nl.isUp()) {
|
||||||
@@ -595,6 +596,19 @@ public class KLALBRoutingProtocol extends Thread{
|
|||||||
public Map<IPv6Address, Long> getAddresses() {
|
public Map<IPv6Address, Long> getAddresses() {
|
||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询某地址广播的设备名称(未知返回null)
|
||||||
|
*/
|
||||||
|
public String getDeviceName(IPv6Address address) {
|
||||||
|
RouterInfo ri=netmap.get(address);
|
||||||
|
if(ri!=null) {
|
||||||
|
String dn=ri.getDeviceName();
|
||||||
|
if(dn!=null&&!dn.isEmpty())
|
||||||
|
return dn;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public Map<IPv6Address, List<LinkDirection>> getPaths() {
|
public Map<IPv6Address, List<LinkDirection>> getPaths() {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.UUID;
|
|||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||||
import org.kne.cloud.network.congestion.NOCongestionAlgorithm;
|
import org.kne.cloud.network.congestion.NOCongestionAlgorithm;
|
||||||
import org.kne.cloud.network.congestion.SendPacketSlidingWindow;
|
import org.kne.cloud.network.congestion.SendPacketSlidingWindow;
|
||||||
import org.kne.opencl64.Releaser;
|
import org.kne.opencl64.Releaser;
|
||||||
@@ -33,16 +33,16 @@ public class KLALBRoutingProtocolAPIClient {
|
|||||||
|
|
||||||
if ((relate = window.ack(ruid)) != null) {
|
if ((relate = window.ack(ruid)) != null) {
|
||||||
List<?> connects = (List<?>) dataobj.getData();
|
List<?> connects = (List<?>) dataobj.getData();
|
||||||
List<MultipurposeSocketAddress> connectsm = new ArrayList<MultipurposeSocketAddress>(connects.size());
|
List<MultiProtocolSocketAddress> connectsm = new ArrayList<MultiProtocolSocketAddress>(connects.size());
|
||||||
for (Object open : connects) {
|
for (Object open : connects) {
|
||||||
if (open instanceof MultipurposeSocketAddress) {
|
if (open instanceof MultiProtocolSocketAddress) {
|
||||||
connectsm.add((MultipurposeSocketAddress) open);
|
connectsm.add((MultiProtocolSocketAddress) open);
|
||||||
} else {
|
} else {
|
||||||
connectsm.add(new MultipurposeSocketAddress((String) open));
|
connectsm.add(new MultiProtocolSocketAddress((String) open));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
((Consumer<List<MultipurposeSocketAddress>>) relate.getUserCallback()).accept(connectsm);
|
((Consumer<List<MultiProtocolSocketAddress>>) relate.getUserCallback()).accept(connectsm);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class KLALBRoutingProtocolAPIClient {
|
|||||||
clr.register(this, releaser);
|
clr.register(this, releaser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestOpenLines(SocketAddress addr, Consumer<List<MultipurposeSocketAddress>> callback)
|
public void requestOpenLines(SocketAddress addr, Consumer<List<MultiProtocolSocketAddress>> callback)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
UUID suid = UUID.randomUUID();
|
UUID suid = UUID.randomUUID();
|
||||||
KLALBRoutingProtocolJsonData json = new KLALBRoutingProtocolJsonData(
|
KLALBRoutingProtocolJsonData json = new KLALBRoutingProtocolJsonData(
|
||||||
|
|||||||
@@ -4,13 +4,8 @@ import java.io.IOException;
|
|||||||
import java.lang.ref.Cleaner;
|
import java.lang.ref.Cleaner;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
|
||||||
import org.kne.cloud.network.ThreadTool;
|
|
||||||
import org.kne.cloud.network.congestion.SendPacketSlidingWindow;
|
|
||||||
import org.kne.cloud.network.klalb.KLALBController;
|
import org.kne.cloud.network.klalb.KLALBController;
|
||||||
import org.kne.opencl64.Releaser;
|
import org.kne.opencl64.Releaser;
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class RouterInfo implements Serializable{
|
|||||||
return Objects.equals(locator, other.locator) && Objects.equals(neighborAddresses, other.neighborAddresses);
|
return Objects.equals(locator, other.locator) && Objects.equals(neighborAddresses, other.neighborAddresses);
|
||||||
}
|
}
|
||||||
private List<NeighborInfo> neighborAddresses=new ArrayList<>();
|
private List<NeighborInfo> neighborAddresses=new ArrayList<>();
|
||||||
|
private String deviceName=""; // 设备名称(广播时携带,描述不广播)
|
||||||
private long createTime;
|
private long createTime;
|
||||||
|
|
||||||
|
|
||||||
@@ -90,6 +91,14 @@ public class RouterInfo implements Serializable{
|
|||||||
return neighborAddresses;
|
return neighborAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDeviceName() {
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceName(String deviceName) {
|
||||||
|
this.deviceName = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
public RouterInfo( long createTime,IPv6AddressGroup locator,long asn) {
|
public RouterInfo( long createTime,IPv6AddressGroup locator,long asn) {
|
||||||
this.createTime = createTime;
|
this.createTime = createTime;
|
||||||
this.locator=locator;
|
this.locator=locator;
|
||||||
@@ -106,6 +115,7 @@ public class RouterInfo implements Serializable{
|
|||||||
for( NeighborInfo neighborInfo :neighborAddresses) {
|
for( NeighborInfo neighborInfo :neighborAddresses) {
|
||||||
neighborInfo.writeToStream(out);
|
neighborInfo.writeToStream(out);
|
||||||
}
|
}
|
||||||
|
out.writeUTF(deviceName==null?"":deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||||
@@ -126,6 +136,7 @@ public class RouterInfo implements Serializable{
|
|||||||
neighborAddresses.add(nif);
|
neighborAddresses.add(nif);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
deviceName=in.readUTF();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ import org.kne.cloud.network.ipv6.PostcardEntry;
|
|||||||
import org.kne.cloud.network.ipv6.RouteItem;
|
import org.kne.cloud.network.ipv6.RouteItem;
|
||||||
import org.kne.cloud.network.klalb.KLALBRemoteLink;
|
import org.kne.cloud.network.klalb.KLALBRemoteLink;
|
||||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||||
|
import org.kne.cloud.network.klalb.PerformanceStrategy;
|
||||||
|
import org.kne.cloud.network.klalb.ui.PerformanceStrategyItem;
|
||||||
import org.kne.concurrent.HighPerformanceExecutor2;
|
import org.kne.concurrent.HighPerformanceExecutor2;
|
||||||
import org.kne.concurrent.TimeoutConcurrentHashMap;
|
import org.kne.concurrent.TimeoutConcurrentHashMap;
|
||||||
import org.pcap4j.packet.IllegalRawDataException;
|
import org.pcap4j.packet.IllegalRawDataException;
|
||||||
@@ -62,6 +64,8 @@ public class SRv6Router {
|
|||||||
|
|
||||||
private static final int IPv6_BITS = 128; // IPv6地址位数
|
private static final int IPv6_BITS = 128; // IPv6地址位数
|
||||||
|
|
||||||
|
private PerformanceStrategy performanceStrategy=PerformanceStrategy.MULTI_FILL;
|
||||||
|
|
||||||
/*private TimeoutConcurrentHashMap<FlowSession, PacketIDGenerator> flowIDmap = new TimeoutConcurrentHashMap<FlowSession, PacketIDGenerator>(
|
/*private TimeoutConcurrentHashMap<FlowSession, PacketIDGenerator> flowIDmap = new TimeoutConcurrentHashMap<FlowSession, PacketIDGenerator>(
|
||||||
60000000000L);
|
60000000000L);
|
||||||
*/
|
*/
|
||||||
@@ -161,6 +165,14 @@ public class SRv6Router {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void setPerformanceStrategy(PerformanceStrategy performanceStrategy) {
|
||||||
|
this.performanceStrategy=performanceStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PerformanceStrategy getPerformanceStrategy(){
|
||||||
|
return performanceStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
// 链路状态监听器实现
|
// 链路状态监听器实现
|
||||||
private class LinkListener implements IPv6LinkStateListener {
|
private class LinkListener implements IPv6LinkStateListener {
|
||||||
|
|
||||||
@@ -282,6 +294,15 @@ public class SRv6Router {
|
|||||||
|
|
||||||
private IPv6AddressGroup locator; // SRv6定位器
|
private IPv6AddressGroup locator; // SRv6定位器
|
||||||
private long asn = new SecureRandom().nextLong(1, Long.MAX_VALUE); // 自治系统号
|
private long asn = new SecureRandom().nextLong(1, Long.MAX_VALUE); // 自治系统号
|
||||||
|
private volatile String deviceName; // 设备名称(随路由信息广播)
|
||||||
|
|
||||||
|
public String getDeviceName() {
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceName(String deviceName) {
|
||||||
|
this.deviceName = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
public IPv6AddressGroup getLocator() {
|
public IPv6AddressGroup getLocator() {
|
||||||
return locator;
|
return locator;
|
||||||
@@ -765,43 +786,43 @@ public class SRv6Router {
|
|||||||
|
|
||||||
//private static HighPerformanceExecutor2 defaultExecutor = new HighPerformanceExecutor2(4, Thread.ofVirtual().name("SRv6 Routing").factory());
|
//private static HighPerformanceExecutor2 defaultExecutor = new HighPerformanceExecutor2(4, Thread.ofVirtual().name("SRv6 Routing").factory());
|
||||||
|
|
||||||
public static HighPerformanceExecutor2 getDefaultExecutor() {
|
/*public static HighPerformanceExecutor2 getDefaultExecutor() {
|
||||||
return defaultExecutor;
|
return defaultExecutor;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// private ArrayBlockingQueue<Supplier<IPv6Packet>> packetQueue=new
|
// private ArrayBlockingQueue<Supplier<IPv6Packet>> packetQueue=new
|
||||||
// ArrayBlockingQueue<>(10000);
|
// ArrayBlockingQueue<>(10000);
|
||||||
public void enqueuePacketSendTask(Supplier<IPv6Packet> sendTask) {
|
public void enqueuePacketSendTask(Supplier<IPv6Packet> sendTask) {
|
||||||
// packetQueue.add(object);
|
// packetQueue.add(object);
|
||||||
|
switch(performanceStrategy) {
|
||||||
|
case SINGLE_CORE:
|
||||||
|
runPacketSendTask0(sendTask, false);
|
||||||
|
break;
|
||||||
|
case MULTI_FILL:
|
||||||
|
case MULTI_SCATTER:
|
||||||
defaultExecutor.executeWithCongestionReport((state) -> {
|
defaultExecutor.executeWithCongestionReport((state) -> {
|
||||||
|
runPacketSendTask0(sendTask, state);
|
||||||
|
}, 20,performanceStrategy);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void runPacketSendTask0(Supplier<IPv6Packet> sendTask,boolean ecn) {
|
||||||
try {
|
try {
|
||||||
long start=System.nanoTime();
|
long start=System.nanoTime();
|
||||||
IPv6Packet packet=sendTask.get();
|
IPv6Packet packet=sendTask.get();
|
||||||
if(state) {
|
if(ecn) {
|
||||||
packet.markCE();
|
packet.markCE();
|
||||||
}
|
}
|
||||||
insertSRHandRoutePacket(null, packet); // 插入SRH并路由
|
insertSRHandRoutePacket(null, packet); // 插入SRH并路由
|
||||||
long time=System.nanoTime()-start;
|
long time=System.nanoTime()-start;
|
||||||
backplaneCount(time,state);
|
backplaneCount(time,ecn);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
},20);
|
|
||||||
}
|
}
|
||||||
public void runPacketSendTask(Supplier<IPv6Packet> sendTask) {
|
public void runPacketSendTask(Supplier<IPv6Packet> sendTask) {
|
||||||
try {
|
runPacketSendTask0(sendTask,false);
|
||||||
boolean state=false;
|
|
||||||
long start=System.nanoTime();
|
|
||||||
IPv6Packet packet=sendTask.get();
|
|
||||||
if(state) {
|
|
||||||
packet.markCE();
|
|
||||||
}
|
|
||||||
insertSRHandRoutePacket(null, packet); // 插入SRH并路由
|
|
||||||
long time=System.nanoTime()-start;
|
|
||||||
backplaneCount(time,state);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReceive(IPv6NetworkLink link,IPv6Packet t){
|
public void onReceive(IPv6NetworkLink link,IPv6Packet t){
|
||||||
@@ -824,7 +845,7 @@ public class SRv6Router {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
},20);
|
},20,performanceStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enqueuePacket(IPv6Packet packet) {
|
public void enqueuePacket(IPv6Packet packet) {
|
||||||
|
|||||||
@@ -1,21 +1,13 @@
|
|||||||
package org.kne.concurrent;
|
package org.kne.concurrent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.concurrent.locks.LockSupport;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.jctools.queues.MpscArrayQueue;
|
import org.jctools.queues.MpscArrayQueue;
|
||||||
|
import org.kne.cloud.network.klalb.PerformanceStrategy;
|
||||||
|
|
||||||
public class HighPerformanceExecutor2 implements Executor {
|
public class HighPerformanceExecutor2 implements Executor {
|
||||||
|
|
||||||
@@ -33,6 +25,8 @@ public class HighPerformanceExecutor2 implements Executor {
|
|||||||
threads[i]=t;
|
threads[i]=t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class ThreadElement implements Runnable{
|
private static class ThreadElement implements Runnable{
|
||||||
private MpscArrayQueue<Runnable> queue=new MpscArrayQueue<Runnable>(2048);
|
private MpscArrayQueue<Runnable> queue=new MpscArrayQueue<Runnable>(2048);
|
||||||
private AtomicInteger size=new AtomicInteger();
|
private AtomicInteger size=new AtomicInteger();
|
||||||
@@ -80,7 +74,7 @@ public class HighPerformanceExecutor2 implements Executor {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable command) {
|
public void execute(Runnable command) {
|
||||||
if(execute0((x)->{command.run();},1000)) {
|
if(execute0((x)->{command.run();},1000, PerformanceStrategy.MULTI_FILL)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println("loss!");
|
System.out.println("loss!");
|
||||||
@@ -89,42 +83,47 @@ public class HighPerformanceExecutor2 implements Executor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private long vl=0;
|
private long vl=0;
|
||||||
private boolean execute0(Consumer<Boolean> command,int limit) {
|
|
||||||
|
private boolean execute0(Consumer<Boolean> command, int limit, PerformanceStrategy strategy) {
|
||||||
|
if(strategy.equals(PerformanceStrategy.MULTI_SCATTER)){
|
||||||
long ord=vl++;
|
long ord=vl++;
|
||||||
ThreadElement te= threads[(int) (ord%threads.length)];
|
ThreadElement te= threads[(int) (ord%threads.length)];
|
||||||
boolean b=te.size()>limit;
|
boolean b=te.size()>limit;
|
||||||
return te.putTask( ()->{command.accept(b);});
|
return te.putTask( ()->{command.accept(b);});
|
||||||
}*/
|
}else {
|
||||||
|
for (int i = 0; i < threads.length; i++) {
|
||||||
private boolean execute0(Consumer<Boolean> command,int limit) {
|
ThreadElement te = threads[i];
|
||||||
for(int i=0;i<threads.length;i++) {
|
boolean b = te.size() > limit;
|
||||||
ThreadElement te= threads[i];
|
if (!b) {
|
||||||
boolean b=te.size()>limit;
|
if (te.putTask(() -> {
|
||||||
if(!b) {
|
command.accept(false);
|
||||||
if(te.putTask( ()->{command.accept(false);})){
|
})) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0;i<threads.length;i++) {
|
for (int i = 0; i < threads.length; i++) {
|
||||||
ThreadElement te= threads[i];
|
ThreadElement te = threads[i];
|
||||||
if(te.putTask( ()->{command.accept(true);})){
|
if (te.putTask(() -> {
|
||||||
|
command.accept(true);
|
||||||
|
})) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void executeWithCongestionReport(Consumer<Boolean> command) {
|
public void executeWithCongestionReport(Consumer<Boolean> command) {
|
||||||
if(execute0(command,1000)) {
|
if(execute0(command,1000, PerformanceStrategy.MULTI_FILL)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println("loss!");
|
System.out.println("loss!");
|
||||||
}
|
}
|
||||||
public void executeWithCongestionReport(Consumer<Boolean> command,int limit) {
|
public void executeWithCongestionReport(Consumer<Boolean> command, int limit, PerformanceStrategy strategy) {
|
||||||
if(execute0(command,limit)) {
|
if(execute0(command,limit,strategy)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println("loss!");
|
System.out.println("loss!");
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package org.kne.concurrent;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 惰性计算器:只在输入变化且输出被需要时重算。
|
||||||
|
*
|
||||||
|
* 使用场景:路由表重算、统计信息聚合、UI 数据更新等
|
||||||
|
*
|
||||||
|
* @param <T> 输出类型
|
||||||
|
*/
|
||||||
|
public class LazyEvaluator<T> {
|
||||||
|
|
||||||
|
private final Supplier<T> recomputeFn; // 重算函数(可能较重)
|
||||||
|
private final AtomicBoolean dirty = new AtomicBoolean(true); // true表示需要重算
|
||||||
|
private volatile T cachedResult; // 缓存结果(volatile保证可见性)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param recomputeFn 当真正需要重算时,调用此函数生成新值
|
||||||
|
*/
|
||||||
|
public LazyEvaluator(Supplier<T> recomputeFn) {
|
||||||
|
this.recomputeFn = recomputeFn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记输入已变化(每次变化都调用)
|
||||||
|
* CAS 保证多线程下只有一个线程真正置脏,避免无谓的竞争
|
||||||
|
*/
|
||||||
|
public boolean markDirty() {
|
||||||
|
return dirty.compareAndSet(false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前值(如果 dirty 且被需要,则触发重算)
|
||||||
|
* 这个方法由需要输出的地方(如 UI 线程、路由引擎)调用
|
||||||
|
*/
|
||||||
|
public T get() {
|
||||||
|
if (dirty.get()) {
|
||||||
|
synchronized (this) {
|
||||||
|
// double-check:防止多个线程同时进入重算
|
||||||
|
if (dirty.get()) {
|
||||||
|
cachedResult = recomputeFn.get();
|
||||||
|
dirty.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cachedResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前缓存的值(不触发重算)
|
||||||
|
* 适合那些“如果已经算好就直接用,否则也不强求”的场景
|
||||||
|
*/
|
||||||
|
public T getCached() {
|
||||||
|
return cachedResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前是否需要重算
|
||||||
|
*/
|
||||||
|
public boolean isDirty() {
|
||||||
|
return dirty.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user