public void testUDPPingRequest() { PingRequest pr = pingRequestFactory.createUDPPing(); assertTrue(pr.supportsCachedPongs()); // Test +UP +TLS UltrapeerSettings.MIN_CONNECT_TIME.setValue(0); UltrapeerSettings.FORCE_ULTRAPEER_MODE.setValue(true); ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true); ConnectionSettings.LOCAL_IS_PRIVATE.setValue(false); UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.setValue(true); UltrapeerSettings.NEED_MIN_CONNECT_TIME.setValue(false); tlsManager.setIncomingTLSEnabled(true); assertTrue(connectionServices.isSupernode()); pr = pingRequestFactory.createUDPPing(); assertFalse(pr.requestsIP()); byte[] data = pr.getSupportsCachedPongData(); assertEquals(0x1, data[0] & 0x1); assertEquals(0x2, data[0] & 0x2); // +UP -TLS tlsManager.setIncomingTLSEnabled(false); assertTrue(connectionServices.isSupernode()); pr = pingRequestFactory.createUDPPing(); assertFalse(pr.requestsIP()); data = pr.getSupportsCachedPongData(); assertEquals(0x1, data[0] & 0x1); assertEquals(0x0, data[0] & 0x2); // Test -UP +TLS UltrapeerSettings.DISABLE_ULTRAPEER_MODE.setValue(true); UltrapeerSettings.FORCE_ULTRAPEER_MODE.setValue(false); tlsManager.setIncomingTLSEnabled(true); assertFalse(connectionServices.isSupernode()); pr = pingRequestFactory.createUDPPing(); assertFalse(pr.requestsIP()); data = pr.getSupportsCachedPongData(); assertEquals(0x0, data[0] & 0x1); assertEquals(0x2, data[0] & 0x2); // Test -UP -TLS tlsManager.setIncomingTLSEnabled(false); assertFalse(connectionServices.isSupernode()); pr = pingRequestFactory.createUDPPing(); assertFalse(pr.requestsIP()); data = pr.getSupportsCachedPongData(); assertEquals(0x0, data[0] & 0x1); assertEquals(0x0, data[0] & 0x2); ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(false); pr = pingRequestFactory.createUDPPing(); assertTrue(pr.requestsIP()); }
/** begins an http failover. */ private void checkForStaleUpdateAndMaybeDoHttpFailover() { LOG.debug("checking for timeout http failover"); long monthAgo = clock.now() - ONE_MONTH; if (UpdateSettings.LAST_UPDATE_TIMESTAMP.getValue() < monthAgo && // more than a month ago UpdateSettings.LAST_HTTP_FAILOVER.getValue() < monthAgo && // and last failover too !httpRequestControl.requestQueued( HttpRequestControl.RequestReason.TIMEOUT)) { // and we're not already doing a failover long when = (connectionServices.isConnected() ? 1 : 5) * 60 * 1000; if (LOG.isDebugEnabled()) LOG.debug("scheduling http failover in " + when); backgroundExecutor.schedule( new Runnable() { public void run() { try { launchHTTPUpdate(timeoutUpdateLocation); } catch (URISyntaxException e) { httpRequestControl.requestFinished(); httpRequestControl.cancelRequest(); LOG.warn(e.toString(), e); } } }, when, TimeUnit.MILLISECONDS); } }
byte[] getSCPData() { byte[] data = new byte[1]; if (connectionServices.isSupernode()) data[0] = PingRequest.SCP_ULTRAPEER; else data[0] = PingRequest.SCP_LEAF; if (networkManager.isIncomingTLSEnabled()) data[0] |= PingRequest.SCP_TLS; // add our support for TLS. return data; }