优化代码,性能暴涨
This commit is contained in:
@@ -0,0 +1,575 @@
|
||||
package org.kne.cloud.network.srv6;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.BindException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.Neighbor;
|
||||
import org.kne.cloud.network.monitor.DelayMonitorData;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficMonitorData;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficMonitorDataImpl;
|
||||
import org.kne.cloud.network.scanner.InetAddressRange;
|
||||
|
||||
public class KLALBRoutingProtocol extends Thread{
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
private Map<Inet6Address, RouterInfo> netmap=new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private volatile Map<Inet6Address,Long>addresses;
|
||||
|
||||
private volatile Map<Inet6Address, Set<LinkDirection>> paths;
|
||||
|
||||
public static final int DEFAULT_PORT=1001;
|
||||
|
||||
public static final long HOTSOPT_TIMEOUT = 1000000000;
|
||||
|
||||
public static final int HOTSOPT_REPORT_INTERVAL = 100000000;
|
||||
private SRv6Router router;
|
||||
public SRv6Router getRouter() {
|
||||
return router;
|
||||
}
|
||||
public KLALBRoutingProtocol(SRv6Router router) {
|
||||
this.router=router;
|
||||
}
|
||||
|
||||
private ReentrantLock sendlock=new ReentrantLock();
|
||||
|
||||
private long floodTimer=System.nanoTime();
|
||||
private long floodTimer2=System.nanoTime();
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("KLALB路由协议接收线程");
|
||||
getSelfRouterInfo();
|
||||
DatagramSocket ds = null;
|
||||
try{
|
||||
ds=new DatagramSocket(new InetSocketAddress(router.getLocator().getAddress(), DEFAULT_PORT) );
|
||||
DatagramSocket ds2=ds;
|
||||
new Thread(()->{
|
||||
Thread.currentThread().setName("KLALB路由协议接收线程");
|
||||
|
||||
while(true) {
|
||||
try {
|
||||
/*List<NetworkLink>links=router.getLinkTabel();
|
||||
Object[] nls=links.toArray();
|
||||
byte[]to=createLinkStatePacket(nls);
|
||||
DatagramPacket dgp=new DatagramPacket(to,to.length);
|
||||
|
||||
for(int i=0;i<nls.length;i++) {
|
||||
NetworkLink nl=(NetworkLink) nls[i];
|
||||
if(!nl.isLoopBack()) {
|
||||
Set<Inet6Address>neis=nl.discoverNeighbors();
|
||||
for (Iterator<Inet6Address> iteratorx = neis.iterator(); iteratorx.hasNext();) {
|
||||
Inet6Address addresses = (Inet6Address) iteratorx.next();
|
||||
dgp.setAddress(addresses);
|
||||
dgp.setPort(DEFAULT_PORT);
|
||||
ds2.send(dgp);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
RouterInfo slf= getSelfRouterInfo();
|
||||
RouterInfo oslf=netmap.put(slf.getLocator().getAddress(), slf);
|
||||
noticeUpdate();
|
||||
if(oslf==null||(!slf.equals(oslf))) {
|
||||
//System.out.println("change:"+oslf+"\n"+slf);
|
||||
long cur=System.nanoTime();
|
||||
if(cur-floodTimer2>5000000000L) {
|
||||
//System.out.println("update10");
|
||||
floodTimer2=cur;
|
||||
floodPacket(ds2, null, new RouterInfoPacket(slf,true));
|
||||
}
|
||||
}else {
|
||||
long cur=System.nanoTime();
|
||||
if(cur-floodTimer>60000000000L) {
|
||||
//System.out.println("update60");
|
||||
floodTimer=cur;
|
||||
floodPacket(ds2, null, new RouterInfoPacket(slf,true));
|
||||
}
|
||||
}
|
||||
Set<Inet6Address> requestSet=new HashSet<>();
|
||||
for (Iterator<Entry<Inet6Address, RouterInfo>> iterator = netmap.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, RouterInfo> type = (Entry<Inet6Address, RouterInfo>) iterator.next();
|
||||
RouterInfo val=type.getValue();
|
||||
if(val.checkTimeOut()) {
|
||||
iterator.remove();
|
||||
noticeUpdate();
|
||||
}
|
||||
Set<NeighborInfo> ads=val.getNeighborAddresses();
|
||||
for (Iterator<NeighborInfo> iterator2 = ads.iterator(); iterator2.hasNext();) {
|
||||
Inet6Address address=iterator2.next().getLocator().getAddress();
|
||||
//System.out.println(address);
|
||||
if(!netmap.containsKey(address)) {
|
||||
requestSet.add(address);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
computeShortestPathIfUpdated();
|
||||
|
||||
for (Iterator<Inet6Address> iterator = requestSet.iterator(); iterator.hasNext();) {
|
||||
Inet6Address inet6Address = (Inet6Address) iterator.next();
|
||||
byte[]to=new byte[] {0};
|
||||
DatagramPacket dgp=new DatagramPacket(to,to.length);
|
||||
dgp.setAddress(inet6Address);
|
||||
dgp.setPort(DEFAULT_PORT);
|
||||
if(debug)
|
||||
System.out.println("Request:"+inet6Address);
|
||||
sendlock.lock();
|
||||
try {
|
||||
ds2.send(dgp);
|
||||
}catch(SocketException e) {
|
||||
System.out.println("Send failed:"+dgp.getAddress());
|
||||
}finally {
|
||||
sendlock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Iterator<Entry<Inet6Address, HotspotAddressTimer>> iterator = hotspots.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, HotspotAddressTimer> type = (Entry<Inet6Address, HotspotAddressTimer>) iterator.next();
|
||||
if(type.getValue().checkReportTime()) {
|
||||
//System.out.println("hotspot address:"+type.getKey());
|
||||
writePacket(ds2, new RouterInfoPacket( netmap.get(router.getLocator().getAddress()),false), new InetSocketAddress(type.getKey(), DEFAULT_PORT));
|
||||
}
|
||||
if(type.getValue().checkTimeOut()) {
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Thread.sleep(1);
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}catch (IOException e1) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
while(true) {
|
||||
|
||||
try {
|
||||
byte[]ca=new byte[65535];
|
||||
DatagramPacket dgp=new DatagramPacket(ca, ca.length);
|
||||
ds.receive(dgp);
|
||||
//System.out.println(Arrays.toString( Arrays.copyOf( dgp.getData(),dgp.getLength())));
|
||||
ByteArrayInputStream bi=new ByteArrayInputStream(dgp.getData(),0,dgp.getLength());
|
||||
KLALBRoutingProtocolPacket kp=KLALBRoutingProtocolPacket.readKLALBPacketFromChannel(Channels.newChannel(bi));
|
||||
|
||||
//System.out.println(kp);
|
||||
switch(kp.getType()) {
|
||||
case KLALBRoutingProtocolPacket.RINFO_REQ:
|
||||
RouterInfo rifr=netmap.get(router.getLocator().getAddress());
|
||||
if(rifr!=null)
|
||||
writePacket(ds, new RouterInfoPacket( rifr,false), dgp.getSocketAddress());
|
||||
break;
|
||||
case KLALBRoutingProtocolPacket.RINFO:
|
||||
|
||||
RouterInfoPacket rifp=(RouterInfoPacket) kp;
|
||||
RouterInfo rif=rifp.getRinfo();
|
||||
RouterInfo oldrif=netmap.get(rif.getLocator().getAddress());
|
||||
|
||||
if(debug)
|
||||
System.out.println(rif);
|
||||
if(oldrif==null||oldrif.getCreateTime()<rif.getCreateTime()) {
|
||||
if(debug)
|
||||
System.out.println("update RouterInfo");
|
||||
netmap.put(rif.getLocator().getAddress(), rif);
|
||||
noticeUpdate();
|
||||
if(rifp.isFlood()) {
|
||||
floodPacket(ds, dgp.getSocketAddress(), rifp);
|
||||
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
if(debug)
|
||||
System.out.println("dispose RouterInfo");
|
||||
}
|
||||
computeShortestPathIfUpdated();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (SocketException e2) {
|
||||
e2.printStackTrace();
|
||||
}finally {
|
||||
if(ds!=null) {
|
||||
ds.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void floodPacket(DatagramSocket ds,SocketAddress except,KLALBRoutingProtocolPacket rifp) throws IOException {
|
||||
List<IPv6NetworkLink>links=router.getLinkTabel();
|
||||
Object[] nls=links.toArray();
|
||||
for(int i=0;i<nls.length;i++) {
|
||||
IPv6NetworkLink nl=(IPv6NetworkLink) nls[i];
|
||||
if(!nl.isLoopBack()) {
|
||||
List<Neighbor>neis=nl.getNeighborsInfo();
|
||||
for (Iterator<Neighbor> iteratorx = neis.iterator(); iteratorx.hasNext();) {
|
||||
Neighbor addresses = (Neighbor) iteratorx.next();
|
||||
InetSocketAddress isa=new InetSocketAddress(addresses.getLocator().getAddress(),DEFAULT_PORT);
|
||||
if(!isa.equals(except)) {
|
||||
writePacket(ds, rifp, isa);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writePacket(DatagramSocket ds,KLALBRoutingProtocolPacket pkt,SocketAddress dest) throws IOException {
|
||||
ByteArrayOutputStream bos=new ByteArrayOutputStream(65535);
|
||||
KLALBRoutingProtocolPacket.writeKLALBPacketToChannel(Channels.newChannel(bos),pkt);
|
||||
byte[]to=bos.toByteArray();
|
||||
DatagramPacket dgpx=new DatagramPacket(to,to.length);
|
||||
dgpx.setSocketAddress(dest);
|
||||
sendlock.lock();
|
||||
try {
|
||||
ds.send(dgpx);
|
||||
}catch(BindException e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Cannot assign:"+dest);
|
||||
}finally {
|
||||
sendlock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private DijkstraAlgorithm algorithm=new SingleDijkstraAlgorithm();
|
||||
|
||||
private ReentrantLock directionLock=new ReentrantLock();
|
||||
|
||||
private volatile NetmapDirections directions;
|
||||
|
||||
private static class NetmapDirections{
|
||||
|
||||
public NetmapDirections(long[] direction, List<Inet6Address> rias,
|
||||
Map<Inet6Address, Long> direction_airs) {
|
||||
super();
|
||||
this.direction = direction;
|
||||
this.direction_rias = rias;
|
||||
this.direction_airs = direction_airs;
|
||||
}
|
||||
|
||||
private long[] direction;
|
||||
|
||||
private List<Inet6Address> direction_rias;
|
||||
|
||||
private Map<Inet6Address, Long> direction_airs;
|
||||
|
||||
public long[] getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public List<Inet6Address> getDirection_rias() {
|
||||
return direction_rias;
|
||||
}
|
||||
|
||||
public Map<Inet6Address, Long> getDirection_airs() {
|
||||
return direction_airs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private volatile boolean updated=false;
|
||||
public void noticeUpdate() {
|
||||
updated=true;
|
||||
}
|
||||
private void computeShortestPathIfUpdated() {
|
||||
if(updated) {
|
||||
computeShortestPath();
|
||||
updated=false;
|
||||
}
|
||||
}
|
||||
|
||||
private void computeShortestPath() {
|
||||
|
||||
directionLock.lock();
|
||||
try {
|
||||
if(netmap.get(router.getLocator().getAddress())==null) {
|
||||
return;
|
||||
}
|
||||
Set<Entry<Inet6Address, RouterInfo>> s=netmap.entrySet();
|
||||
Map<Inet6Address,Long>airs=new HashMap<>();
|
||||
|
||||
List<Inet6Address>rias=new ArrayList<>();
|
||||
|
||||
Map<Inet6Address,Set< LinkDirection>>paths=new HashMap<>();
|
||||
long number=0;
|
||||
for (Iterator<Entry<Inet6Address, RouterInfo>> iterator = s.iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, RouterInfo> entry = (Entry<Inet6Address, RouterInfo>) iterator.next();
|
||||
if(!airs.containsKey(entry.getKey())) {
|
||||
airs.put(entry.getKey(),number);
|
||||
rias.add( entry.getKey());
|
||||
number++;
|
||||
}
|
||||
Set<NeighborInfo> ni= entry.getValue().getNeighborAddresses();
|
||||
for (Iterator<NeighborInfo> iterator2 = ni.iterator(); iterator2.hasNext();) {
|
||||
NeighborInfo neighborInfo = (NeighborInfo) iterator2.next();
|
||||
Inet6Address ias2=neighborInfo.getLocator().getAddress();
|
||||
if(!airs.containsKey(ias2)) {
|
||||
airs.put(ias2,number);
|
||||
rias.add( ias2);
|
||||
number++;
|
||||
}
|
||||
Set<LinkDirection>lp1=paths.get(entry.getKey());
|
||||
if(lp1==null) {
|
||||
paths.put(entry.getKey(), lp1=new HashSet<>());
|
||||
}
|
||||
lp1.add(new LinkDirection(neighborInfo.getLocal(),neighborInfo.getNeighbor(),entry.getKey(), ias2, neighborInfo.getUploadDelay(),neighborInfo.getUploadSpeed(),neighborInfo.getUploadSpeedMax()));
|
||||
|
||||
Set<LinkDirection>lp2=paths.get(ias2);
|
||||
if(lp2==null) {
|
||||
paths.put(ias2, lp2=new HashSet<>());
|
||||
}
|
||||
lp2.add( new LinkDirection(neighborInfo.getNeighbor(),neighborInfo.getLocal(),ias2,entry.getKey() , neighborInfo.getDownloadDelay(),neighborInfo.getDownloadSpeed(),neighborInfo.getDownloadSpeedMax()));
|
||||
}
|
||||
}
|
||||
|
||||
long[][]pointers=new long[(int) airs.size()][2];
|
||||
long heappos=0;
|
||||
long linknumber=0;
|
||||
for (Iterator<Entry<Inet6Address, Set<LinkDirection>>> iterator = paths.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, Set<LinkDirection>> entry = (Entry<Inet6Address, Set<LinkDirection>>) iterator.next();
|
||||
linknumber+=entry.getValue().size();
|
||||
}
|
||||
long[][]heap=new long[(int) (linknumber)][2];
|
||||
for (long i = 0; i < number; i++) {
|
||||
long heapindex=0;
|
||||
pointers[(int) i][0]=heappos;
|
||||
InetAddress ia=rias.get((int) i);
|
||||
Set<LinkDirection>lks=paths.get(ia);
|
||||
if(lks!=null)
|
||||
for (Iterator<LinkDirection> iterator = lks.iterator(); iterator.hasNext();) {
|
||||
LinkDirection linkPath=iterator.next();
|
||||
heap[(int)(heappos+ heapindex)][0]=airs.get(linkPath.getToLocator());
|
||||
heap[(int) (heappos+heapindex)][1]=linkPath.getWeight();
|
||||
heapindex++;
|
||||
|
||||
}
|
||||
|
||||
heappos+=heapindex;
|
||||
pointers[(int) i][1]=heapindex;
|
||||
}
|
||||
|
||||
algorithm.setGraph(pointers,heap,airs.get(router.getLocator().getAddress()));
|
||||
algorithm.run();
|
||||
directions=new NetmapDirections(algorithm.getDirection(), rias, airs);
|
||||
addresses=airs;
|
||||
this.paths=paths;
|
||||
}finally {
|
||||
directionLock.unlock();
|
||||
}
|
||||
//System.out.println(Arrays.toString( algorithm.getDirection()));
|
||||
}
|
||||
public static class LinkDirection{
|
||||
private Inet6AddressGroup fromAddress;
|
||||
private Inet6AddressGroup toAddress;
|
||||
private Inet6Address fromLocator;
|
||||
private Inet6Address toLocator;
|
||||
private long delay;
|
||||
private long speed;
|
||||
public long getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
private long bandwidth;
|
||||
private long usedBandwidth=0;
|
||||
public Inet6AddressGroup getFromAddress() {
|
||||
return fromAddress;
|
||||
}
|
||||
public Inet6AddressGroup getToAddress() {
|
||||
return toAddress;
|
||||
}
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
}
|
||||
public long getBandwidth() {
|
||||
return bandwidth;
|
||||
}
|
||||
public LinkDirection(Inet6AddressGroup fromAddress, Inet6AddressGroup toAddress, Inet6Address fromLocator,
|
||||
Inet6Address toLocator,long delay,long speed, long bandwidth) {
|
||||
super();
|
||||
this.fromAddress = fromAddress;
|
||||
this.toAddress = toAddress;
|
||||
this.fromLocator = fromLocator;
|
||||
this.toLocator = toLocator;
|
||||
this.delay = delay;
|
||||
this.speed=speed;
|
||||
this.bandwidth = bandwidth;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LinkDirection [fromAddress=" + fromAddress + ", toAddress=" + toAddress + ", fromLocator="
|
||||
+ fromLocator + ", toLocator=" + toLocator + ", delay=" + delay + ", speed=" + speed
|
||||
+ ", bandwidth=" + bandwidth + ", usedBandwidth=" + usedBandwidth + "]";
|
||||
}
|
||||
public Inet6Address getFromLocator() {
|
||||
return fromLocator;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(fromAddress, toAddress);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
LinkDirection other = (LinkDirection) obj;
|
||||
return Objects.equals(fromAddress, other.fromAddress) && Objects.equals(toAddress, other.toAddress);
|
||||
}
|
||||
public Inet6Address getToLocator() {
|
||||
return toLocator;
|
||||
}
|
||||
public long getWeight() {
|
||||
return delay;
|
||||
}
|
||||
}
|
||||
private RouterInfo getSelfRouterInfo() {
|
||||
List<IPv6NetworkLink>links=router.getLinkTabel();
|
||||
Object[] nls=links.toArray();
|
||||
RouterInfo ri=new RouterInfo(System.currentTimeMillis());
|
||||
ri.setLocator(router.getLocator());
|
||||
for(int i=0;i<nls.length;i++) {
|
||||
IPv6NetworkLink nl=(IPv6NetworkLink) nls[i];
|
||||
if((!nl.isLoopBack())&&nl.isUp()) {
|
||||
List<Neighbor>neis=nl.getNeighborsInfo();
|
||||
for (Iterator<Neighbor> iteratorx = neis.iterator(); iteratorx.hasNext();) {
|
||||
Neighbor addresses = (Neighbor) iteratorx.next();
|
||||
long updelay=10000000000L;
|
||||
long downdelay=10000000000L;
|
||||
long uploadspeed=1024L*1024;
|
||||
long downloadspeed=1024L*1024;
|
||||
long uploadspeedmax=1024L*1024;
|
||||
long downloadspeedmax=1024L*1024;
|
||||
MonitorData md=addresses.getMonitor();
|
||||
if(md!=null) {
|
||||
if(md instanceof DelayMonitorData) {
|
||||
updelay=((DelayMonitorData) md).getOutDelay();
|
||||
downdelay=((DelayMonitorData) md).getInDelay();
|
||||
}
|
||||
if(md instanceof SpeedAndTrafficMonitorData) {
|
||||
uploadspeed=((SpeedAndTrafficMonitorData) md).getOutSpeed();
|
||||
downloadspeed=((SpeedAndTrafficMonitorData) md).getInSpeed();
|
||||
if(md instanceof SpeedAndTrafficMonitorDataImpl) {
|
||||
SpeedAndTrafficMonitorDataImpl smd=(SpeedAndTrafficMonitorDataImpl) md;
|
||||
uploadspeedmax=smd.getOutSpeedMax2();
|
||||
downloadspeedmax=smd.getInSpeedMax2();
|
||||
}
|
||||
}
|
||||
}
|
||||
ri.getNeighborAddresses().add(new NeighborInfo(nl.getAddressGroup(),addresses.getAddress(),addresses.getLocator(),updelay ,downdelay ,uploadspeed ,downloadspeed,uploadspeedmax ,downloadspeedmax));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//if(debug)
|
||||
//System.out.println(ri);
|
||||
return ri;
|
||||
}
|
||||
|
||||
public Map<Inet6Address, Long> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
public Map<Inet6Address, Set<LinkDirection>> getPaths() {
|
||||
return paths;
|
||||
}
|
||||
public List<Inet6Address> createSegmentList(Inet6Address dest) {
|
||||
NetmapDirections directionsx=directions;
|
||||
if(directionsx==null) {
|
||||
return null;
|
||||
}
|
||||
Long dn=directionsx.getDirection_airs().get(dest);
|
||||
if(dn==null) {
|
||||
return null;
|
||||
}
|
||||
List<Inet6Address>segments=new ArrayList<>();
|
||||
while(true) {
|
||||
long idx=directionsx.getDirection()[(int) dn.longValue()];
|
||||
if(idx==-1) {
|
||||
return null;
|
||||
}
|
||||
if(idx==dn) {
|
||||
return segments;
|
||||
}
|
||||
segments.add(directionsx.getDirection_rias().get(dn.intValue()));
|
||||
dn=idx;
|
||||
}
|
||||
}
|
||||
public long getDevicesFound() {
|
||||
return netmap.size();
|
||||
}
|
||||
|
||||
private static class HotspotAddressTimer{
|
||||
private long putTime=System.nanoTime();
|
||||
private long reportTime =System.nanoTime();
|
||||
public boolean checkTimeOut() {
|
||||
return System.nanoTime()-putTime>HOTSOPT_TIMEOUT;
|
||||
}
|
||||
public boolean checkReportTime() {
|
||||
long cu = System.nanoTime();
|
||||
if (cu - reportTime > HOTSOPT_REPORT_INTERVAL) {
|
||||
reportTime = cu;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void refreshTimeout() {
|
||||
putTime=System.nanoTime();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Inet6Address, HotspotAddressTimer> hotspots=new ConcurrentHashMap<>();
|
||||
public void putHotspotAddress(Inet6Address sourceAddress) {
|
||||
HotspotAddressTimer hat=hotspots.get(sourceAddress);
|
||||
if(hat==null) {
|
||||
hotspots.put(sourceAddress, new HotspotAddressTimer());
|
||||
}else {
|
||||
hat.refreshTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user