@Override public void setUp() throws Exception { Expand.expandFile( TestUtils.getResourceFile("com/limegroup/gnutella/xml/xml.war"), CommonUtils.getUserSettingsDir()); Injector injector = LimeTestUtils.createInjector(); limeXMLSchemaRepository = injector.getInstance(LimeXMLSchemaRepository.class); }
/** Constructs an IPFilter that automatically loads the content. */ @Inject public LocalIPFilter( @Named("hostileFilter") IPFilter hostileNetworkFilter, @Named("backgroundExecutor") ScheduledExecutorService ipLoader) { this.hostileNetworkFilter = hostileNetworkFilter; this.ipLoader = ipLoader; File hostiles = new File(CommonUtils.getUserSettingsDir(), "hostiles.txt"); shouldLoadHostiles = hostiles.exists(); hostileNetworkFilter.refreshHosts(); refreshHosts(); }
/** Does the work of setting new good & bad hosts. */ private void refreshHostsImpl() { LOG.debug("refreshing hosts"); // Load the local blacklist, stripping out invalid entries IPList newBad = new IPList(); String[] allHosts = FilterSettings.BLACK_LISTED_IP_ADDRESSES.get(); ArrayList<String> valid = new ArrayList<String>(allHosts.length); for (int i = 0; i < allHosts.length; i++) { if (newBad.add(allHosts[i])) valid.add(allHosts[i]); } if (valid.size() != allHosts.length) { allHosts = valid.toArray(new String[0]); FilterSettings.BLACK_LISTED_IP_ADDRESSES.set(allHosts); } // Load the local whitelist, stripping out invalid entries IPList newGood = new IPList(); allHosts = FilterSettings.WHITE_LISTED_IP_ADDRESSES.get(); valid = new ArrayList<String>(allHosts.length); for (int i = 0; i < allHosts.length; i++) { if (newGood.add(allHosts[i])) valid.add(allHosts[i]); } if (valid.size() != allHosts.length) { allHosts = valid.toArray(new String[0]); FilterSettings.WHITE_LISTED_IP_ADDRESSES.set(allHosts); } // Load data from hostiles.txt (if it wasn't already loaded!)... if (shouldLoadHostiles) { shouldLoadHostiles = false; LOG.debug("loading hostiles"); File hostiles = new File(CommonUtils.getUserSettingsDir(), "hostiles.txt"); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(hostiles)); String read = null; while ((read = reader.readLine()) != null) { hostilesTXTHosts.add(read); } } catch (IOException ignored) { LOG.debug("iox loading hostiles", ignored); } finally { IOUtils.close(reader); } } badHosts = new MultiIPList(newBad, hostilesTXTHosts); goodHosts = newGood; }
private void storeAndUpdate(byte[] data, SimppParser parser, UpdateType updateType) { if (LOG.isTraceEnabled()) LOG.trace("Retrieved new data from: " + updateType + ", storing & updating"); if (parser.getVersion() == IGNORE_ID && updateType == UpdateType.FROM_NETWORK) throw new IllegalStateException("shouldn't be here!"); if (updateType == UpdateType.FROM_NETWORK && httpRequestControl.isRequestPending()) return; _lastId = parser.getVersion(); _lastBytes = data; if (updateType != UpdateType.FROM_DISK) { FileUtils.verySafeSave(CommonUtils.getUserSettingsDir(), FILENAME, data); } for (SimppSettingsManager ssm : simppSettingsManagers) ssm.updateSimppSettings(parser.getPropsData()); for (SimppListener listener : listeners) listener.simppUpdated(_lastId); }
private File getPropertiesFile() { return new File(CommonUtils.getUserSettingsDir(), "intent.props"); }
/** Simple accessor for the stored file. */ private File getStoredFile() { return new File(CommonUtils.getUserSettingsDir(), FILENAME); }
/** * Stores the given data to disk & posts an update to neighboring connections. Starts the download * of any updates */ private void storeAndUpdate(byte[] data, UpdateCollection uc, UpdateType updateType) { if (LOG.isTraceEnabled()) LOG.trace("Retrieved new data from: " + updateType + ", storing & updating."); if (uc.getId() == IGNORE_ID && updateType == UpdateType.FROM_NETWORK) throw new IllegalStateException("shouldn't be here!"); // If an http max request is pending, don't even bother with this stuff. // We want to get it straight from the source... if (updateType == UpdateType.FROM_NETWORK && httpRequestControl.isRequestPending() && httpRequestControl.getRequestReason() == HttpRequestControl.RequestReason.MAX) return; _lastId = uc.getId(); _lastTimestamp = uc.getTimestamp(); UpdateSettings.LAST_UPDATE_TIMESTAMP.setValue(_lastTimestamp); long delay = UpdateSettings.UPDATE_DOWNLOAD_DELAY.getValue(); long random = Math.abs(RANDOM.nextLong() % delay); _nextDownloadTime = _lastTimestamp + random; _lastBytes = data; if (updateType != UpdateType.FROM_DISK) { // cancel any http and pretend we just updated. if (httpRequestControl.getRequestReason() == HttpRequestControl.RequestReason.TIMEOUT) httpRequestControl.cancelRequest(); UpdateSettings.LAST_HTTP_FAILOVER.setValue(clock.now()); FileUtils.verySafeSave(CommonUtils.getUserSettingsDir(), FILENAME, data); capabilitiesVMFactory.updateCapabilities(); connectionManager.get().sendUpdatedCapabilities(); } Version limeV; try { limeV = new Version(LimeWireUtils.getLimeWireVersion()); } catch (VersionFormatException vfe) { LOG.warn("Invalid LimeWire version", vfe); return; } Version javaV = null; try { javaV = new Version(VersionUtils.getJavaVersion()); } catch (VersionFormatException vfe) { LOG.warn("Invalid java version", vfe); } // don't allow someone to set the style to be above major. int style = Math.min(UpdateStyle.STYLE_MAJOR, UpdateSettings.UPDATE_STYLE.getValue()); UpdateData updateInfo = uc.getUpdateDataFor( limeV, ApplicationSettings.getLanguage(), LimeWireUtils.isPro(), style, javaV); List<DownloadInformation> updatesToDownload = uc.getUpdatesWithDownloadInformation(); _killingObsoleteNecessary = true; // if we have an update for our machine, prepare the command line // and move our update to the front of the list of updates if (updateInfo != null && updateInfo.getUpdateURN() != null) { prepareUpdateCommand(updateInfo); updatesToDownload = new LinkedList<DownloadInformation>(updatesToDownload); updatesToDownload.add(0, updateInfo); } _updateInfo = updateInfo; _updatesToDownload = updatesToDownload; downloadUpdates(updatesToDownload, null); if (updateInfo == null) { LOG.warn("No relevant update info to notify about."); return; } else if (updateInfo.getUpdateURN() == null || isHopeless(updateInfo)) { if (LOG.isDebugEnabled()) LOG.debug( "we have an update, but it doesn't need a download. " + "or all our updates are hopeles. Scheduling URL notification..."); updateInfo.setUpdateCommand(null); backgroundExecutor.schedule( new NotificationFailover(_lastId), delay(clock.now(), uc.getTimestamp()), TimeUnit.MILLISECONDS); } else if (isMyUpdateDownloaded(updateInfo)) { LOG.debug("there is an update for me, but I happen to have it on disk"); fireUpdate(updateInfo); } else LOG.debug("we have an update, it needs a download. Rely on callbacks"); }