2005-07-04 jrandom
* Within the tunnel, use xor(IV, msg[0:16]) as the flag to detect dups, rather than the IV by itself, preventing an attack that would let colluding internal adversaries tag a message to determine that they are in the same tunnel. Thanks dvorak for the catch! * Drop long inactive profiles on startup and shutdown * /configstats.jsp: web interface to pick what stats to log * Deliver more session tags to account for wider window sizes * Cache some intermediate values in our HMACSHA256 and BC's HMAC * Track the client send rate (stream.sendBps and client.sendBpsRaw) * UrlLauncher: adjust the browser selection order * I2PAppContext: hooks for dummy HMACSHA256 and a weak PRNG * StreamSinkClient: add support for sending an unlimited amount of data * Migrate the tests out of the default build jars 2005-06-22 Comwiz * Migrate the core tests to junit
This commit is contained in:
@ -0,0 +1,94 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.i2p.stat.StatManager;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the stats config form and act
|
||||
* upon the values.
|
||||
*
|
||||
*/
|
||||
public class ConfigStatsHandler extends FormHandler {
|
||||
private String _filename;
|
||||
private List _stats;
|
||||
private boolean _explicitFilter;
|
||||
private String _explicitFilterValue;
|
||||
|
||||
public ConfigStatsHandler() {
|
||||
super();
|
||||
_stats = new ArrayList();
|
||||
}
|
||||
|
||||
protected void processForm() {
|
||||
saveChanges();
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
_filename = (filename != null ? filename.trim() : null);
|
||||
}
|
||||
|
||||
public void setStatList(String stat) {
|
||||
if (stat != null) {
|
||||
if (stat.indexOf(',') != -1) {
|
||||
StringTokenizer tok = new StringTokenizer(stat, ",");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String cur = tok.nextToken().trim();
|
||||
if ( (cur.length() > 0) && (!_stats.contains(cur)) )
|
||||
_stats.add(cur);
|
||||
}
|
||||
} else {
|
||||
stat = stat.trim();
|
||||
if ( (stat.length() > 0) && (!_stats.contains(stat)) )
|
||||
_stats.add(stat);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setStatList(String stats[]) {
|
||||
if (stats != null) {
|
||||
for (int i = 0; i < stats.length; i++) {
|
||||
String cur = stats[i].trim();
|
||||
if ( (cur.length() > 0) && (!_stats.contains(cur)) )
|
||||
_stats.add(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setExplicitFilter(String foo) { _explicitFilter = true; }
|
||||
public void setExplicitFilterValue(String filter) { _explicitFilterValue = filter; }
|
||||
|
||||
/**
|
||||
* The user made changes to the config and wants to save them, so
|
||||
* lets go ahead and do so.
|
||||
*
|
||||
*/
|
||||
private void saveChanges() {
|
||||
if (_filename == null)
|
||||
_filename = StatManager.DEFAULT_STAT_FILE;
|
||||
_context.router().setConfigSetting(StatManager.PROP_STAT_FILE, _filename);
|
||||
|
||||
if (_explicitFilter) {
|
||||
_stats.clear();
|
||||
setStatList(_explicitFilterValue);
|
||||
}
|
||||
|
||||
StringBuffer stats = new StringBuffer();
|
||||
for (int i = 0; i < _stats.size(); i++) {
|
||||
stats.append((String)_stats.get(i));
|
||||
if (i + 1 < _stats.size())
|
||||
stats.append(',');
|
||||
}
|
||||
|
||||
_context.router().setConfigSetting(StatManager.PROP_STAT_FILTER, stats.toString());
|
||||
boolean ok = _context.router().saveConfig();
|
||||
if (ok)
|
||||
addFormNotice("Stat filter and location updated successfully to: " + stats.toString());
|
||||
else
|
||||
addFormError("Failed to update the stat filter and location");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import net.i2p.stat.RateStat;
|
||||
import net.i2p.stat.FrequencyStat;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
public class ConfigStatsHelper {
|
||||
private RouterContext _context;
|
||||
private Log _log;
|
||||
private String _filter;
|
||||
private Set _filters;
|
||||
/** list of names of stats which are remaining, ordered by nested groups */
|
||||
private List _stats;
|
||||
private String _currentStatName;
|
||||
private String _currentStatDescription;
|
||||
private String _currentGroup;
|
||||
/** true if the current stat is the first in the group */
|
||||
private boolean _currentIsFirstInGroup;
|
||||
/** true if the stat is being logged */
|
||||
private boolean _currentIsLogged;
|
||||
|
||||
/**
|
||||
* Configure this bean to query a particular router context
|
||||
*
|
||||
* @param contextId begging few characters of the routerHash, or null to pick
|
||||
* the first one we come across.
|
||||
*/
|
||||
public void setContextId(String contextId) {
|
||||
try {
|
||||
_context = ContextHelper.getContext(contextId);
|
||||
_log = _context.logManager().getLog(ConfigStatsHelper.class);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
_stats = new ArrayList();
|
||||
Map groups = _context.statManager().getStatsByGroup();
|
||||
for (Iterator iter = groups.values().iterator(); iter.hasNext(); ) {
|
||||
Set stats = (Set)iter.next();
|
||||
for (Iterator statIter = stats.iterator(); statIter.hasNext(); )
|
||||
_stats.add(statIter.next());
|
||||
}
|
||||
_filter = _context.statManager().getStatFilter();
|
||||
if (_filter == null)
|
||||
_filter = "";
|
||||
|
||||
_filters = new HashSet();
|
||||
StringTokenizer tok = new StringTokenizer(_filter, ",");
|
||||
while (tok.hasMoreTokens())
|
||||
_filters.add(tok.nextToken().trim());
|
||||
}
|
||||
|
||||
public ConfigStatsHelper() {}
|
||||
|
||||
public String getFilename() { return _context.statManager().getStatFile(); }
|
||||
|
||||
/**
|
||||
* move the cursor to the next known stat, returning true if a valid
|
||||
* stat is available.
|
||||
*
|
||||
* @return true if a valid stat is available, otherwise false
|
||||
*/
|
||||
public boolean hasMoreStats() {
|
||||
if (_stats.size() <= 0)
|
||||
return false;
|
||||
_currentStatName = (String)_stats.remove(0);
|
||||
RateStat rs = _context.statManager().getRate(_currentStatName);
|
||||
if (rs != null) {
|
||||
_currentStatDescription = rs.getDescription();
|
||||
if (_currentGroup == null)
|
||||
_currentIsFirstInGroup = true;
|
||||
else if (!rs.getGroupName().equals(_currentGroup))
|
||||
_currentIsFirstInGroup = true;
|
||||
else
|
||||
_currentIsFirstInGroup = false;
|
||||
_currentGroup = rs.getGroupName();
|
||||
} else {
|
||||
FrequencyStat fs = _context.statManager().getFrequency(_currentStatName);
|
||||
if (fs != null) {
|
||||
_currentStatDescription = fs.getDescription();
|
||||
if (_currentGroup == null)
|
||||
_currentIsFirstInGroup = true;
|
||||
else if (!fs.getGroupName().equals(_currentGroup))
|
||||
_currentIsFirstInGroup = true;
|
||||
else
|
||||
_currentIsFirstInGroup = false;
|
||||
_currentGroup = fs.getGroupName();
|
||||
} else {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Stat does not exist?! [" + _currentStatName + "]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (_filters.contains("*") || _filters.contains(_currentStatName))
|
||||
_currentIsLogged = true;
|
||||
else
|
||||
_currentIsLogged = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Is the current stat the first in the group? */
|
||||
public boolean groupRequired() {
|
||||
if (_currentIsFirstInGroup) {
|
||||
_currentIsFirstInGroup = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/** What group is the current stat in */
|
||||
public String getCurrentGroupName() { return _currentGroup; }
|
||||
public String getCurrentStatName() { return _currentStatName; }
|
||||
public String getCurrentStatDescription() { return _currentStatDescription; }
|
||||
public boolean getCurrentIsLogged() { return _currentIsLogged; }
|
||||
public String getExplicitFilter() { return _filter; }
|
||||
}
|
Reference in New Issue
Block a user