private void updateActive() { manager.updateSRPState(); if (active && SRP_VERIFIER != null) { start(); } else { synchronized (tunnels) { for (PairManagerTunnel t : new ArrayList<PairManagerTunnel>(tunnels.values())) { t.destroy(); } } synchronized (local_server_map) { local_server_map.clear(); } } List<DHTNATPuncher> punchers = new ArrayList<DHTNATPuncher>(); punchers.addAll(nat_punchers_ipv4); punchers.addAll(nat_punchers_ipv6); for (DHTNATPuncher p : punchers) { p.forceActive(active); } }
private boolean createTunnel( InetAddress originator, long session, String sid, SecretKeySpec secret, String tunnel_url, String endpoint_url) { PairedServiceImpl ps = manager.getService(sid); if (ps == null) { Debug.out("Service '" + sid + "' not registered"); return (false); } PairedServiceRequestHandler handler = ps.getHandler(); if (handler == null) { Debug.out("Service '" + sid + "' has no handler registered"); return (false); } String key = originator.getHostAddress() + ":" + session + ":" + sid; synchronized (tunnels) { PairManagerTunnel existing = tunnels.get(key); if (existing != null) { return (true); } if (tunnels.size() > MAX_TUNNELS) { long oldest_active = Long.MAX_VALUE; PairManagerTunnel oldest_tunnel = null; for (PairManagerTunnel t : tunnels.values()) { long at = t.getLastActive(); if (at < oldest_active) { oldest_active = at; oldest_tunnel = t; } } oldest_tunnel.destroy(); tunnels.remove(oldest_tunnel.getKey()); } PairManagerTunnel tunnel = new PairManagerTunnel( this, key, originator, sid, handler, secret, tunnel_url, endpoint_url); tunnels.put(key, tunnel); System.out.println("Created pair manager tunnel: " + tunnel.getString()); } return (true); }