Changeset 67e7e45 for apps


Ignore:
Timestamp:
May 20, 2019 6:27:29 PM (11 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a8f11d1
Parents:
cafdca9
Message:

Sybil: Skip comment lines in stored files
Escape % in stored reasons
Improve error handling when loading files

Location:
apps/routerconsole/java/src/net/i2p/router
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/sybil/PersistSybil.java

    rcafdca9 r67e7e45  
    6565        try {
    6666            out = new OutputStreamWriter(new GZIPOutputStream(new SecureFileOutputStream(file)));
     67            out.write("# Format (one per line)\n");
     68            out.write("# Base64 router hash:total points%points:reason%points:reason ...\n");
    6769            for (Map.Entry<Hash, Points> entry : entries.entrySet()) {
    6870                Hash h = entry.getKey();
     
    115117            String line;
    116118            while ((line = in.readLine()) != null) {
     119                if (line.startsWith("#"))
     120                    continue;
    117121                int colon = line.indexOf(':');
    118122                if (colon != 44)
     
    193197                    if (file.delete())
    194198                        deleted++;
     199                    else if (_log.shouldWarn())
     200                        _log.warn("Failed to delete: " + file);
    195201                }
    196202            } catch (NumberFormatException nfe) {}
  • apps/routerconsole/java/src/net/i2p/router/sybil/Points.java

    rcafdca9 r67e7e45  
    8282        buf.append(points);
    8383        for (String r : reasons) {
    84             buf.append('%').append(r);
     84            buf.append('%').append(r.replace("%", "&#x25;"));
    8585        }
    8686    }
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java

    rcafdca9 r67e7e45  
    6363
    6464    private final RouterContext _context;
     65    private final Log _log;
    6566    private final DecimalFormat fmt = new DecimalFormat("#0.00");
    6667    private final DateFormat dfmt;
     
    7576    public SybilRenderer(RouterContext ctx) {
    7677        _context = ctx;
     78        _log = ctx.logManager().getLog(SybilRenderer.class);
    7779        dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    7880        dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
     
    207209                points = ps.load(date);
    208210            } catch (IOException ioe) {
    209                 out.write("<b>No analysis found for " + new Date(date) + "</b>");
     211                _log.error("loading stored analysis for date: " + date, ioe);
     212                out.write("<b>Failed to load analysis for " + dfmt.format(new Date(date)) + "</b>: " +
     213                          DataHelper.escapeHTML(ioe.toString()));
    210214                return;
    211215            }
    212216            if (points.isEmpty()) {
    213                 out.write("<b>No analysis found for " + new Date(date) + "</b>");
     217                _log.error("empty stored analysis or bad file format for date: " + date);
     218                out.write("<b>Corrupt analysis file for " + dfmt.format(new Date(date)) + "</b>");
    214219            } else {
    215220                renderThreatsHTML(out, buf, date, points);
Note: See TracChangeset for help on using the changeset viewer.