147 lines
3.2 KiB
Java
147 lines
3.2 KiB
Java
package org.kne.cloud.network.klalb;
|
|
|
|
import java.io.BufferedInputStream;
|
|
import java.io.BufferedOutputStream;
|
|
import java.io.DataInputStream;
|
|
import java.io.DataOutputStream;
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.Socket;
|
|
import java.net.UnknownHostException;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
import java.util.Objects;
|
|
import java.util.Random;
|
|
import java.util.Set;
|
|
import java.util.Vector;
|
|
import java.util.WeakHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
import javax.naming.spi.Resolver;
|
|
import javax.swing.JPanel;
|
|
|
|
import org.kne.cloud.network.mport.IPPort;
|
|
|
|
public class Tunnel{
|
|
private String name;
|
|
private IPPort ipport;
|
|
private boolean state=false;
|
|
|
|
private TListener tlr;
|
|
|
|
public boolean isState() {
|
|
return state;
|
|
}
|
|
public void setState(boolean state) {
|
|
this.state = state;
|
|
if(tlr!=null) {
|
|
tlr.setState(state);
|
|
}
|
|
}
|
|
public IPPort getIpport() {
|
|
return ipport;
|
|
}
|
|
private long delay=Long.MAX_VALUE;
|
|
public TListener getTlr() {
|
|
return tlr;
|
|
}
|
|
public void setTlr(TListener tlr) {
|
|
this.tlr = tlr;
|
|
}
|
|
public long getDelay() {
|
|
return delay;
|
|
}
|
|
public void setDelay(long delay) {
|
|
this.delay = delay;
|
|
if(tlr!=null)
|
|
tlr.setDelay(delay);
|
|
}
|
|
|
|
public Tunnel() {
|
|
|
|
}
|
|
|
|
|
|
public Tunnel(String name, IPPort ipport) {
|
|
super();
|
|
this.name = name;
|
|
this.ipport = ipport;
|
|
}
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public String getIp() {
|
|
return getIpport().getIp();
|
|
}
|
|
public int getPort() {
|
|
return getIpport().getPort();
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return getName()+"$"+getIpport();
|
|
}
|
|
public Socket connectClientSocket() throws UnknownHostException, IOException {
|
|
Socket socket=new Socket();
|
|
// socket.bind(new InetSocketAddress(new Random().nextInt(65535)+1));
|
|
socket.connect(getIpport().getSocketAddress(), Consts.CONNECT_TIMEOUT);
|
|
return socket;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(getIpport(), getName());
|
|
}
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj)
|
|
return true;
|
|
if (obj == null)
|
|
return false;
|
|
if (getClass() != obj.getClass())
|
|
return false;
|
|
Tunnel other = (Tunnel) obj;
|
|
return Objects.equals(getIpport(), other.getIpport()) && Objects.equals(getName(), other.getName());
|
|
}
|
|
|
|
private AtomicInteger ati=new AtomicInteger(0);
|
|
public AtomicInteger getCCount() {
|
|
return ati;
|
|
}
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
public void setIpport(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();
|
|
}
|
|
}
|