1 19 20 package com.sslexplorer.agent.client.tunneling; 21 22 import java.util.Enumeration ; 23 import java.util.Hashtable ; 24 25 import com.sslexplorer.agent.client.Agent; 26 27 37 public class TunnelInactivityMonitor extends Thread { 38 39 private Agent vpnClient; 41 42 static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(TunnelInactivityMonitor.class); 44 45 47 52 public TunnelInactivityMonitor(Agent vpnClient) { 53 this.vpnClient = vpnClient; 54 setDaemon(true); 55 56 } 57 58 63 public void run() { 64 log.info("Starting tunnel inactivity monitor (tunnels " + new Integer (vpnClient.getConfiguration().getTunnelInactivity()) 66 + "ms, web forwards " 67 + new Integer (vpnClient.getConfiguration().getWebForwardInactivity()) 68 + "ms)"); 69 while (true) { 71 try { 72 Thread.sleep(30000); 73 if (vpnClient.getState() == Agent.STATE_DISCONNECTED) { 74 break; 75 } 76 log.info("Checking for tunnel inactivity"); 80 Hashtable activeListeners = vpnClient.getTunnelManager().getActiveLocalTunnels(); 82 83 synchronized (activeListeners) { 84 long now = System.currentTimeMillis(); 85 for (Enumeration e = activeListeners.keys(); e.hasMoreElements();) { 86 Integer id = (Integer ) e.nextElement(); 87 LocalTunnelServer l = (LocalTunnelServer) activeListeners.get(id); 88 try { 89 if (l.isListening()) { 90 if (vpnClient.getConfiguration().getTunnelInactivity() != 0 && (l.getTunnel().isPermanent() || (!l.getTunnel() 93 .isPermanent() && l.getTunnel().isTemporarySingleConnect()))) { 94 if (now > (l.getDataLastTransferredTime() + vpnClient.getConfiguration().getTunnelInactivity())) { 95 log.info("Permanent / Temporary Single Connect tunnel " + id + " is out of date, closing."); vpnClient.getTunnelManager().stopLocalTunnel(l.getId()); 99 } 100 101 } 102 else if (vpnClient.getConfiguration().getWebForwardInactivity() != 0 && (!l.getTunnel() 106 .isPermanent() && !l.getTunnel().isTemporarySingleConnect())) { 107 if (now > (l.getDataLastTransferredTime() + vpnClient.getConfiguration() 108 .getWebForwardInactivity())) { 109 log.info("Temporary Multiple Connection (Webforward) tunnel " + id + " is out of date, closing."); vpnClient.getTunnelManager().stopLocalTunnel(l.getId()); 113 } 114 } 115 } 116 } catch (Throwable t) { 117 log.error("Failed to check state of tunnel " + id, t); } 121 } 122 } 123 124 } catch (Throwable t) { 125 log.error("Failed to check state of tunnels", t); } 129 } 130 log.error("Disconnected, so stopping tunnel inactivity monitor."); } 134 } | Popular Tags |