forked from KNEMC/KLALB
V1.0
This commit is contained in:
+15
-3
@@ -14,6 +14,9 @@
|
|||||||
"localaddress" : "127.0.0.1:3389"
|
"localaddress" : "127.0.0.1:3389"
|
||||||
} ],
|
} ],
|
||||||
"tunnels" : [ {
|
"tunnels" : [ {
|
||||||
|
"name" : "Openfrp-直连线路",
|
||||||
|
"remoteaddress" : "127.0.0.1:4566"
|
||||||
|
},{
|
||||||
"name" : "NULL-宿迁联通",
|
"name" : "NULL-宿迁联通",
|
||||||
"remoteaddress" : "153.36.240.12:65529"
|
"remoteaddress" : "153.36.240.12:65529"
|
||||||
}, {
|
}, {
|
||||||
@@ -28,9 +31,6 @@
|
|||||||
}, {
|
}, {
|
||||||
"name" : "Openfrp-美国-8「BGP」",
|
"name" : "Openfrp-美国-8「BGP」",
|
||||||
"remoteaddress" : "us-los-bgp-8.openfrp.top:65529"
|
"remoteaddress" : "us-los-bgp-8.openfrp.top:65529"
|
||||||
}, {
|
|
||||||
"name" : "Openfrp-新加坡-1「BGP」",
|
|
||||||
"remoteaddress" : "singa-bgp-2.openfrp.top:65529"
|
|
||||||
}, {
|
}, {
|
||||||
"name" : "XYZ-韩国首尔",
|
"name" : "XYZ-韩国首尔",
|
||||||
"remoteaddress" : "frp.104300.xyz:49965"
|
"remoteaddress" : "frp.104300.xyz:49965"
|
||||||
@@ -52,6 +52,12 @@
|
|||||||
}, {
|
}, {
|
||||||
"name" : "Sakurafrp-武汉电信-1",
|
"name" : "Sakurafrp-武汉电信-1",
|
||||||
"remoteaddress" : "cn-wh-dx-1.natfrp.cloud:65529"
|
"remoteaddress" : "cn-wh-dx-1.natfrp.cloud:65529"
|
||||||
|
}, {
|
||||||
|
"name" : "Sakurafrp-枣庄BGP-10",
|
||||||
|
"remoteaddress" : "cn-zz-bgp-10.natfrp.cloud:23330"
|
||||||
|
}, {
|
||||||
|
"name" : "Sakurafrp-枣庄BGP-7",
|
||||||
|
"remoteaddress" : "cn-zz-bgp-7.natfrp.cloud:33336"
|
||||||
}, {
|
}, {
|
||||||
"name" : "Freefrp-韩国首尔-0",
|
"name" : "Freefrp-韩国首尔-0",
|
||||||
"remoteaddress" : "frp.freefrp.net:49965"
|
"remoteaddress" : "frp.freefrp.net:49965"
|
||||||
@@ -64,5 +70,11 @@
|
|||||||
}, {
|
}, {
|
||||||
"name" : "Freefrp-韩国首尔-4",
|
"name" : "Freefrp-韩国首尔-4",
|
||||||
"remoteaddress" : "frp4.freefrp.net:49965"
|
"remoteaddress" : "frp4.freefrp.net:49965"
|
||||||
|
}, {
|
||||||
|
"name" : "HYHBX-深圳阿里-1",
|
||||||
|
"remoteaddress" : "119.23.238.91:49965"
|
||||||
|
}, {
|
||||||
|
"name" : "HYHBX-上海腾讯-2",
|
||||||
|
"remoteaddress" : "43.143.109.64:49965"
|
||||||
} ]
|
} ]
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
public class Consts {
|
public class Consts {
|
||||||
public static final int BLOCKSIZE=16384;
|
public static final int BLOCKSIZE=32768;
|
||||||
public static final long PINGTIMENS=2000000000L;
|
public static final long PINGTIMENS=2000000000L;
|
||||||
public static final double A = 0.125;
|
public static final double A = 0.125;
|
||||||
public static final int SO_TIMEOUT = 20000;
|
public static final int SO_TIMEOUT = 20000;
|
||||||
public static final long SN_KEEP = 60000000000L;
|
public static final long SN_KEEP = 60000000000L;
|
||||||
public static final int MAX_RESEND = 20;
|
public static final int MAX_RESEND = 100;
|
||||||
public static final long UACK_TIME = 10000000000L;
|
public static final long UACK_TIME = 10000000000L;
|
||||||
|
public static final int CONNECT_TIMEOUT=10000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -17,13 +19,16 @@ import org.kne.cloud.network.mport.ThreadTool;
|
|||||||
|
|
||||||
public class IOThreadManager {
|
public class IOThreadManager {
|
||||||
private KLALBCore klc = new KLALBCore(2000);
|
private KLALBCore klc = new KLALBCore(2000);
|
||||||
private boolean isopen = true;
|
private volatile boolean isopen = true;
|
||||||
|
|
||||||
public IOThreadManager() {
|
public IOThreadManager() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleLocal(LocalTCPConnection tc, boolean syn) {
|
public void handleLocal(LocalTCPConnection tc, boolean syn) {
|
||||||
|
if(!isopen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
klc.getLocaltcps().put(tc.getCuid(), tc);
|
klc.getLocaltcps().put(tc.getCuid(), tc);
|
||||||
AtomicBoolean AB=new AtomicBoolean(true);
|
AtomicBoolean AB=new AtomicBoolean(true);
|
||||||
try {
|
try {
|
||||||
@@ -129,6 +134,9 @@ public class IOThreadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleRemote(RemoteTCPConnection tc) {
|
public void handleRemote(RemoteTCPConnection tc) {
|
||||||
|
if(!isopen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
klc.getRemotetcps().add(tc);
|
klc.getRemotetcps().add(tc);
|
||||||
try {
|
try {
|
||||||
Thread rs = ThreadTool.makeVThreadIfSupport("远程发送线程", () -> {
|
Thread rs = ThreadTool.makeVThreadIfSupport("远程发送线程", () -> {
|
||||||
@@ -165,7 +173,22 @@ public class IOThreadManager {
|
|||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
isopen = false;
|
isopen = false;
|
||||||
//klc.get
|
Collection<LocalTCPConnection>ltcc= klc.getLocaltcps().values();
|
||||||
|
synchronized ( klc.getLocaltcps()) {
|
||||||
|
|
||||||
|
for (Iterator iterator = ltcc.iterator(); iterator.hasNext();) {
|
||||||
|
LocalTCPConnection localTCPConnection = (LocalTCPConnection) iterator.next();
|
||||||
|
localTCPConnection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<RemoteTCPConnection>rtcc= klc.getRemotetcps();
|
||||||
|
synchronized (rtcc) {
|
||||||
|
|
||||||
|
for (Iterator iterator = rtcc.iterator(); iterator.hasNext();) {
|
||||||
|
RemoteTCPConnection remoteTCPConnection = (RemoteTCPConnection) iterator.next();
|
||||||
|
remoteTCPConnection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
public class InputMetre extends InputStream {
|
public class InputMetre extends InputStream {
|
||||||
|
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
private AtomicLong total=new AtomicLong(0);
|
private AtomicLong total;
|
||||||
public InputMetre(InputStream inputStream) {
|
public InputMetre(InputStream inputStream,AtomicLong v) {
|
||||||
this.in=inputStream;
|
this.in=inputStream;
|
||||||
|
this.total=v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -69,4 +70,5 @@ public class InputMetre extends InputStream {
|
|||||||
return in.markSupported();
|
return in.markSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import java.nio.file.Paths;
|
|||||||
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.Random;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@@ -71,7 +72,6 @@ public class KLALBClient {
|
|||||||
try {
|
try {
|
||||||
re++;
|
re++;
|
||||||
tc=new RemoteTCPConnection(tll);
|
tc=new RemoteTCPConnection(tll);
|
||||||
tc.getDout().writeShort(59649);
|
|
||||||
tc.getDout().write(1);
|
tc.getDout().write(1);
|
||||||
tc.getDout().writeUTF(tll.getName());
|
tc.getDout().writeUTF(tll.getName());
|
||||||
tc.getDout().writeUTF(tll.getIp());
|
tc.getDout().writeUTF(tll.getIp());
|
||||||
@@ -101,7 +101,7 @@ public class KLALBClient {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
//System.out.println(re);
|
//System.out.println(re);
|
||||||
Thread.sleep(500*(1<<Math.min(re,8)));
|
Thread.sleep(1000*(1<<Math.min(re,7)));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,6 +193,13 @@ public class KLALBClientGUI extends XFrame {
|
|||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTraffic(long up, long down, long ups, long downs) {
|
||||||
|
tp.setTraffic(up,down,ups,downs);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ysp.updateUI();
|
ysp.updateUI();
|
||||||
@@ -217,6 +224,13 @@ public class KLALBClientGUI extends XFrame {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
Thread.sleep(999);
|
Thread.sleep(999);
|
||||||
|
List<Tunnel>ts=kc.getTls();
|
||||||
|
synchronized(ts) {
|
||||||
|
for(int i=0;i<ts.size();i++) {
|
||||||
|
Tunnel t=ts.get(i) ;
|
||||||
|
t.updateTraffics(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ConnectException e) {
|
} catch (ConnectException e) {
|
||||||
@@ -228,6 +242,7 @@ public class KLALBClientGUI extends XFrame {
|
|||||||
if(kc!=null) {
|
if(kc!=null) {
|
||||||
kc.close();
|
kc.close();
|
||||||
}
|
}
|
||||||
|
wv.removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ public class KLALBCore {
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
if(tc.checkPingTime()) {
|
if(tc.checkPingTime()) {
|
||||||
KLALBBlock pdb=new KLALBBlock();
|
KLALBBlock pdb=new KLALBBlock();
|
||||||
pdb.sn=0;
|
|
||||||
pdb.cuid=0;
|
pdb.cuid=0;
|
||||||
pdb.number=0;
|
pdb.number=0;
|
||||||
pdb.command=0;
|
pdb.command=0;
|
||||||
@@ -118,7 +117,7 @@ public class KLALBCore {
|
|||||||
KLALBBlock brc=null;
|
KLALBBlock brc=null;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
brc=tc.receiveBlock();
|
brc=tc.receiveBlock();
|
||||||
if(brc.sn==0||brc.number!=0) {
|
if(brc.number!=0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SN s=new SN(brc.sn);
|
SN s=new SN(brc.sn);
|
||||||
@@ -145,7 +144,6 @@ public class KLALBCore {
|
|||||||
if(brc.number==0) {
|
if(brc.number==0) {
|
||||||
if(brc.command==0) {
|
if(brc.command==0) {
|
||||||
KLALBBlock pdb=new KLALBBlock();
|
KLALBBlock pdb=new KLALBBlock();
|
||||||
pdb.sn=0;
|
|
||||||
pdb.cuid=0;
|
pdb.cuid=0;
|
||||||
pdb.number=0;
|
pdb.number=0;
|
||||||
pdb.command=1;
|
pdb.command=1;
|
||||||
@@ -220,7 +218,7 @@ public class KLALBCore {
|
|||||||
for (Iterator<RemoteTCPConnection> iterator = remotetcps.iterator(); iterator.hasNext();) {
|
for (Iterator<RemoteTCPConnection> iterator = remotetcps.iterator(); iterator.hasNext();) {
|
||||||
RemoteTCPConnection remoteTCPConnection = (RemoteTCPConnection) iterator.next();
|
RemoteTCPConnection remoteTCPConnection = (RemoteTCPConnection) iterator.next();
|
||||||
BlockingDeque<KLALBBlock> bdq=remoteTCPConnection.getSendDeque();
|
BlockingDeque<KLALBBlock> bdq=remoteTCPConnection.getSendDeque();
|
||||||
if(bdq.size()<1) {
|
if(bdq.size()<2) {
|
||||||
bdq.add(kb);
|
bdq.add(kb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -17,8 +19,9 @@ public class KLALBIPList {
|
|||||||
IPPort u=new IPPort(ipport);
|
IPPort u=new IPPort(ipport);
|
||||||
TCPConnection tcpc=null;
|
TCPConnection tcpc=null;
|
||||||
try {
|
try {
|
||||||
tcpc=new RemoteTCPConnection(null, new Socket(u.getIp(),u.getPort()));
|
Socket soc=new Socket();
|
||||||
tcpc.getDout().writeShort(59649);
|
soc.connect(new InetSocketAddress(u.getIp(),u.getPort()), Consts.CONNECT_TIMEOUT);
|
||||||
|
tcpc=new RemoteTCPConnection(null, soc);
|
||||||
tcpc.getDout().write(0);
|
tcpc.getDout().write(0);
|
||||||
tcpc.getDout().flush();
|
tcpc.getDout().flush();
|
||||||
String json=tcpc.getDin().readUTF();
|
String json=tcpc.getDin().readUTF();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.kne.cloud.network.mport.IPPort;
|
import org.kne.cloud.network.mport.IPPort;
|
||||||
@@ -21,7 +22,7 @@ import org.kne.cloud.network.mport.ThreadTool;
|
|||||||
|
|
||||||
public class KLALBServer {
|
public class KLALBServer {
|
||||||
|
|
||||||
WeakHashMap<UUID, IOThreadManager> whm=new WeakHashMap<>();
|
Map<UUID, IOThreadManager> whm=new WeakHashMap<UUID, IOThreadManager>();
|
||||||
public KLALBServer(int port,Supplier<String> gjso) throws IOException {
|
public KLALBServer(int port,Supplier<String> gjso) throws IOException {
|
||||||
TCPListener tcpl=new TCPListener(port);
|
TCPListener tcpl=new TCPListener(port);
|
||||||
tcpl.setCon((s)->{
|
tcpl.setCon((s)->{
|
||||||
@@ -30,10 +31,7 @@ public class KLALBServer {
|
|||||||
//s.setSoTimeout(10000);
|
//s.setSoTimeout(10000);
|
||||||
tcc=new RemoteTCPConnection(null,s);
|
tcc=new RemoteTCPConnection(null,s);
|
||||||
DataInputStream din=tcc.getDin();
|
DataInputStream din=tcc.getDin();
|
||||||
int val=din.readShort()&0xffff;
|
|
||||||
if(val!=59649) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int x=din.read();
|
int x=din.read();
|
||||||
if(x==0) {
|
if(x==0) {
|
||||||
String sj=gjso.get();
|
String sj=gjso.get();
|
||||||
@@ -49,6 +47,7 @@ public class KLALBServer {
|
|||||||
tcc.setTunnel(tll);
|
tcc.setTunnel(tll);
|
||||||
|
|
||||||
UUID uid=new UUID(din.readLong(),din.readLong());
|
UUID uid=new UUID(din.readLong(),din.readLong());
|
||||||
|
System.out.println(uid);
|
||||||
IOThreadManager nx = null;
|
IOThreadManager nx = null;
|
||||||
synchronized (tcpl) {
|
synchronized (tcpl) {
|
||||||
if(whm.containsKey(uid)) {
|
if(whm.containsKey(uid)) {
|
||||||
@@ -64,7 +63,7 @@ public class KLALBServer {
|
|||||||
try {
|
try {
|
||||||
n1.handleLocal(ltc, false);
|
n1.handleLocal(ltc, false);
|
||||||
}finally {
|
}finally {
|
||||||
n1.close();
|
ltc.close();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
public class OutputMetre extends OutputStream {
|
public class OutputMetre extends OutputStream {
|
||||||
|
|
||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
private AtomicLong total=new AtomicLong(0);
|
private AtomicLong total;
|
||||||
public OutputMetre(OutputStream outputStream) {
|
public OutputMetre(OutputStream outputStream,AtomicLong v) {
|
||||||
this.out=outputStream;
|
this.out=outputStream;
|
||||||
|
this.total=v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,4 +41,6 @@ public class OutputMetre extends OutputStream {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,67 @@
|
|||||||
package org.kne.cloud.network.klalb;
|
package org.kne.cloud.network.klalb;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.StreamCorruptedException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.BlockingDeque;
|
import java.util.concurrent.BlockingDeque;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import org.kne.cloud.network.mport.IPPort;
|
import org.kne.cloud.network.mport.IPPort;
|
||||||
|
import org.kne.io.AddInputStream;
|
||||||
|
import org.kne.io.AddOutputStream;
|
||||||
|
|
||||||
public class RemoteTCPConnection extends TCPConnection {
|
public class RemoteTCPConnection extends TCPConnection {
|
||||||
|
|
||||||
public RemoteTCPConnection(Tunnel t) throws UnknownHostException, IOException {
|
public RemoteTCPConnection(Tunnel t) throws UnknownHostException, IOException {
|
||||||
this(t, t.connectClientSocket());
|
this(t, t.connectClientSocket());
|
||||||
|
if (tunnel != null) {
|
||||||
|
t.getRtcs().add(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initIO() throws IOException {
|
protected void initIO() throws IOException {
|
||||||
dout = new DataOutputStream(new OutputMetre( connect.getOutputStream()));
|
|
||||||
din = new DataInputStream(new InputMetre(connect.getInputStream()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
protected void initIOs() throws IOException {
|
||||||
|
OutputStream outm=null;
|
||||||
|
InputStream inm=null;
|
||||||
|
if(tunnel!=null) {
|
||||||
|
outm = new OutputMetre( connect.getOutputStream(),tunnel.getOM());
|
||||||
|
inm = new InputMetre(connect.getInputStream(),tunnel.getIM());
|
||||||
|
}else {
|
||||||
|
outm=connect.getOutputStream();
|
||||||
|
inm=connect.getInputStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
new DataOutputStream(outm).writeShort(59649);//59649
|
||||||
|
outm.flush();
|
||||||
|
int val=new DataInputStream(inm).readShort()&0xffff;
|
||||||
|
if(val!=59649) {
|
||||||
|
throw new StreamCorruptedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dout = new DataOutputStream(new AddOutputStream(new BufferedOutputStream(outm)) );
|
||||||
|
din = new DataInputStream(new AddInputStream(new BufferedInputStream(inm)));
|
||||||
|
|
||||||
|
}
|
||||||
public RemoteTCPConnection(Tunnel t, Socket s) throws UnknownHostException, IOException {
|
public RemoteTCPConnection(Tunnel t, Socket s) throws UnknownHostException, IOException {
|
||||||
super(s);
|
super(s);
|
||||||
this.tunnel = t;
|
tunnel=t;
|
||||||
|
initIOs();
|
||||||
s.setSoTimeout(Consts.SO_TIMEOUT);
|
s.setSoTimeout(Consts.SO_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,11 +88,25 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (tunnel != null) {
|
||||||
|
tunnel.getRtcs().remove(this);
|
||||||
|
}
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
if (tunnel != null) {
|
||||||
|
tunnel.getRtcs().remove(this);
|
||||||
|
}
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
public void sendBlock(KLALBBlock data) throws IOException {
|
public void sendBlock(KLALBBlock data) throws IOException {
|
||||||
dout.writeLong(data.sn);
|
dout.writeLong(data.sn);
|
||||||
if(data.sn!=0) {
|
|
||||||
dout.writeLong(data.cuid);
|
dout.writeLong(data.cuid);
|
||||||
}
|
|
||||||
dout.writeLong(data.number);
|
dout.writeLong(data.number);
|
||||||
if (data.number > 0) {
|
if (data.number > 0) {
|
||||||
if (data.data == null) {
|
if (data.data == null) {
|
||||||
@@ -83,17 +133,13 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
|
|
||||||
dout.flush();
|
dout.flush();
|
||||||
|
|
||||||
System.out.println("SEND:" + data);
|
//System.out.println("SEND:" + data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLALBBlock receiveBlock() throws IOException {
|
public KLALBBlock receiveBlock() throws IOException {
|
||||||
KLALBBlock klb = new KLALBBlock();
|
KLALBBlock klb = new KLALBBlock();
|
||||||
klb.sn = din.readLong();
|
klb.sn = din.readLong();
|
||||||
if(klb.sn!=0) {
|
|
||||||
klb.cuid = din.readLong();
|
klb.cuid = din.readLong();
|
||||||
}else {
|
|
||||||
klb.cuid=0;
|
|
||||||
}
|
|
||||||
klb.number = din.readLong();
|
klb.number = din.readLong();
|
||||||
if (klb.number > 0) {
|
if (klb.number > 0) {
|
||||||
int size = din.readInt();
|
int size = din.readInt();
|
||||||
@@ -119,7 +165,7 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
klb.cacheused = din.readInt();
|
klb.cacheused = din.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("RECEIVE:" + klb);
|
//System.out.println("RECEIVE:" + klb);
|
||||||
return klb;
|
return klb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,4 +186,5 @@ public class RemoteTCPConnection extends TCPConnection {
|
|||||||
public BlockingDeque<KLALBBlock> getSendDeque() {
|
public BlockingDeque<KLALBBlock> getSendDeque() {
|
||||||
return sendDeque;
|
return sendDeque;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ public interface TListener {
|
|||||||
void setDelay(long delay);
|
void setDelay(long delay);
|
||||||
|
|
||||||
void setState(boolean state);
|
void setState(boolean state);
|
||||||
|
void setTraffic(long up,long down,long ups,long downs) ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class TPanel extends JPanel{
|
|||||||
add(tname, BorderLayout.WEST);
|
add(tname, BorderLayout.WEST);
|
||||||
|
|
||||||
targ = new JLabel();
|
targ = new JLabel();
|
||||||
targ.setFont(new Font("ËÎÌå", Font.PLAIN, 14));
|
targ.setFont(new Font("ËÎÌå", Font.PLAIN, 13));
|
||||||
targ.setHorizontalAlignment(SwingConstants.TRAILING);
|
targ.setHorizontalAlignment(SwingConstants.TRAILING);
|
||||||
targ.setForeground(Color.YELLOW);
|
targ.setForeground(Color.YELLOW);
|
||||||
add(targ, BorderLayout.CENTER);
|
add(targ, BorderLayout.CENTER);
|
||||||
@@ -45,28 +45,39 @@ public class TPanel extends JPanel{
|
|||||||
setSize(570, 30);
|
setSize(570, 30);
|
||||||
setPreferredSize(getSize());
|
setPreferredSize(getSize());
|
||||||
}
|
}
|
||||||
private long up,down,delay;
|
private long up,down,ups,downs,delay;
|
||||||
|
|
||||||
public long getUp() {
|
|
||||||
return up;
|
|
||||||
}
|
|
||||||
public void setUp(long up) {
|
|
||||||
this.up = up;
|
|
||||||
targ.setText(up+"\u2191 "+down+"\u2193 "+delay/1000000+"ms");
|
|
||||||
}
|
|
||||||
public long getDown() {
|
|
||||||
return down;
|
|
||||||
}
|
|
||||||
public void setDown(long down) {
|
|
||||||
this.down = down;
|
|
||||||
targ.setText(up+"\u2191 "+down+"\u2193 "+delay/1000000+"ms");
|
|
||||||
}
|
|
||||||
public long getDelay() {
|
public long getDelay() {
|
||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
public void setDelay(long delay) {
|
public void setDelay(long delay) {
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
targ.setText(up+"\u2191 "+down+"\u2193 "+delay/1000000+"ms");
|
updateText();
|
||||||
|
}
|
||||||
|
private void updateText() {
|
||||||
|
targ.setText(bytesUnit(up)+"\u2191 "+bytesUnit(down)+"\u2193 "+bytesUnit(ups)+"/s\u2191 "+bytesUnit(downs)+"/s\u2193 "+delay/1000000+"ms");
|
||||||
|
}
|
||||||
|
private String bytesUnit(long v) {
|
||||||
|
if(v>=1024L*1024*1024*1024*1024) {
|
||||||
|
return String.format("%.1f", v/(1024.0*1024.0*1024.0*1024.0*1024.0))+"PB";
|
||||||
|
}else if(v>=1024L*1024*1024*1024) {
|
||||||
|
return String.format("%.1f", v/(1024.0*1024.0*1024.0*1024.0))+"TB";
|
||||||
|
}else if(v>=1024L*1024*1024) {
|
||||||
|
return String.format("%.1f", v/(1024.0*1024.0*1024.0))+"GB";
|
||||||
|
}else if(v>=1024L*1024) {
|
||||||
|
return String.format("%.1f", v/(1024.0*1024.0))+"MB";
|
||||||
|
}else if(v>=1024L) {
|
||||||
|
return String.format("%.1f", v/(1024.0))+"KB";
|
||||||
|
}else {
|
||||||
|
return v+"B";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setTraffic(long up2, long down2, long ups, long downs) {
|
||||||
|
up=up2;
|
||||||
|
down=down2;
|
||||||
|
this.ups=ups;
|
||||||
|
this.downs=downs;
|
||||||
|
updateText();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,20 @@ import java.io.BufferedOutputStream;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Vector;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import javax.naming.spi.Resolver;
|
import javax.naming.spi.Resolver;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@@ -71,7 +75,7 @@ public class Tunnel{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getIp() {
|
public String getIp() {
|
||||||
return getIpport().getIp().getHostAddress();
|
return getIpport().getIp();
|
||||||
}
|
}
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return getIpport().getPort();
|
return getIpport().getPort();
|
||||||
@@ -83,7 +87,8 @@ public class Tunnel{
|
|||||||
}
|
}
|
||||||
public Socket connectClientSocket() throws UnknownHostException, IOException {
|
public Socket connectClientSocket() throws UnknownHostException, IOException {
|
||||||
Socket socket=new Socket();
|
Socket socket=new Socket();
|
||||||
socket.connect(getIpport().getSocketAddress(), 10000);
|
// socket.bind(new InetSocketAddress(new Random().nextInt(65535)+1));
|
||||||
|
socket.connect(getIpport().getSocketAddress(), Consts.CONNECT_TIMEOUT);
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,5 +119,28 @@ public class Tunnel{
|
|||||||
this.ipport = ipport;
|
this.ipport = ipport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Vector<RemoteTCPConnection >rtcs=new Vector<>();
|
||||||
|
|
||||||
|
public Vector<RemoteTCPConnection> getRtcs() {
|
||||||
|
return rtcs;
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicLong om=new AtomicLong(0);
|
||||||
|
AtomicLong im=new AtomicLong(0);
|
||||||
|
|
||||||
|
long om1=0;
|
||||||
|
long im1=0;
|
||||||
|
|
||||||
|
|
||||||
|
public AtomicLong getOM() {
|
||||||
|
return om;
|
||||||
|
}
|
||||||
|
public AtomicLong getIM() {
|
||||||
|
return im;
|
||||||
|
}
|
||||||
|
public void updateTraffics(long timems) {
|
||||||
|
tlr.setTraffic(om.get(), im.get(), om.get()-om1, im.get()-im1);
|
||||||
|
om1=om.get();
|
||||||
|
im1=im.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import java.net.UnknownHostException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class IPPort implements Serializable{
|
public class IPPort implements Serializable{
|
||||||
private InetAddress ip;
|
private String ip;
|
||||||
private int port;
|
private int port;
|
||||||
public IPPort(String ipport) throws UnknownHostException {
|
public IPPort(String ipport) throws UnknownHostException {
|
||||||
int index =ipport.lastIndexOf(":");
|
int index =ipport.lastIndexOf(":");
|
||||||
ip=InetAddress.getByName( ipport.substring(0,index));
|
ip=ipport.substring(0,index);
|
||||||
port=Integer.parseInt(ipport.substring(index+1));
|
port=Integer.parseInt(ipport.substring(index+1));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -33,14 +33,14 @@ public class IPPort implements Serializable{
|
|||||||
return Objects.equals(ip, other.ip) && port == other.port;
|
return Objects.equals(ip, other.ip) && port == other.port;
|
||||||
}
|
}
|
||||||
public IPPort(String ip2, int port2) throws UnknownHostException {
|
public IPPort(String ip2, int port2) throws UnknownHostException {
|
||||||
ip=InetAddress.getByName(ip2);
|
ip=ip2;
|
||||||
port=port2;
|
port=port2;
|
||||||
}
|
}
|
||||||
public IPPort(InetSocketAddress remoteSocketAddress) {
|
public IPPort(InetSocketAddress remoteSocketAddress) {
|
||||||
ip=remoteSocketAddress.getAddress();
|
ip=remoteSocketAddress.getAddress().getHostAddress();
|
||||||
port=remoteSocketAddress.getPort();
|
port=remoteSocketAddress.getPort();
|
||||||
}
|
}
|
||||||
public InetAddress getIp() {
|
public String getIp() {
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
@@ -48,10 +48,10 @@ public class IPPort implements Serializable{
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if(ip instanceof Inet6Address) {
|
if(ip.contains(":")) {
|
||||||
return "["+ip.getHostAddress()+"]:"+port;
|
return "["+ip+"]:"+port;
|
||||||
}
|
}
|
||||||
return ip.getHostAddress()+":"+port;
|
return ip+":"+port;
|
||||||
}
|
}
|
||||||
public SocketAddress getSocketAddress() {
|
public SocketAddress getSocketAddress() {
|
||||||
return new InetSocketAddress(ip, port);
|
return new InetSocketAddress(ip, port);
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ public class PortRelay {
|
|||||||
se = ServiceElement.getbyproc(services, n);
|
se = ServiceElement.getbyproc(services, n);
|
||||||
InetSocketAddress sa=(InetSocketAddress) s.getRemoteSocketAddress();
|
InetSocketAddress sa=(InetSocketAddress) s.getRemoteSocketAddress();
|
||||||
System.out.println(sa.getAddress().getHostAddress() + ":" + port
|
System.out.println(sa.getAddress().getHostAddress() + ":" + port
|
||||||
+ "-" + se.protocol + "(" + n + ")->" + se.ipport.getIp().getHostAddress() + ":" + se.ipport.getPort());
|
+ "-" + se.protocol + "(" + n + ")->" + se.ipport.getIp() + ":" + se.ipport.getPort());
|
||||||
sl.connect(new InetSocketAddress(se.ipport.getIp().getHostAddress(), se.ipport.getPort()));
|
sl.connect(new InetSocketAddress(se.ipport.getIp(), se.ipport.getPort()));
|
||||||
final DataInputStream xdinl=new DataInputStream(sl.getInputStream());
|
final DataInputStream xdinl=new DataInputStream(sl.getInputStream());
|
||||||
dinl=xdinl;
|
dinl=xdinl;
|
||||||
final DataOutputStream xdoutl =new DataOutputStream(sl.getOutputStream());
|
final DataOutputStream xdoutl =new DataOutputStream(sl.getOutputStream());
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.kne.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public final class AddInputStream extends InputStream {
|
||||||
|
|
||||||
|
volatile byte out = 0;
|
||||||
|
private InputStream in;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
|
int read = in.read();
|
||||||
|
if (read==-1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
out = (byte) (out+(byte) read);
|
||||||
|
return out&0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddInputStream(InputStream in) {
|
||||||
|
super();
|
||||||
|
this.in = in;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(byte[][] e) throws IOException {
|
||||||
|
for (int y = 0; y<e.length; y++) {
|
||||||
|
byte tmp[] = e[y];
|
||||||
|
|
||||||
|
for (int x = 0; x<tmp.length; x++) {
|
||||||
|
tmp[x] = (byte) read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package org.kne.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class AddOutputStream extends OutputStream {
|
||||||
|
volatile byte out=0;
|
||||||
|
private OutputStream o;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
o.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() throws IOException {
|
||||||
|
|
||||||
|
o.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddOutputStream(OutputStream o) {
|
||||||
|
super();
|
||||||
|
this.o = o;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
o.write((((byte)b)-out)&0xff);
|
||||||
|
out=(byte) b;
|
||||||
|
}
|
||||||
|
public void write(byte[][]e) throws IOException{
|
||||||
|
for (int y = 0; y < e.length; y++) {
|
||||||
|
byte tmp[]=e[y];
|
||||||
|
//System.out.println(Arrays.toString(tmp));
|
||||||
|
for (int x = 0; x < tmp.length; x++) {
|
||||||
|
write(tmp[x]&0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user