Changeset 5d06de8 for apps


Ignore:
Timestamp:
Dec 14, 2018 4:54:10 PM (19 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3054a24
Parents:
468871f
Message:

Sybil: Class for persisting results, related refactoring

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

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java

    r468871f r5d06de8  
    3131import net.i2p.router.peermanager.DBHistory;
    3232import net.i2p.router.peermanager.PeerProfile;
     33import net.i2p.router.sybil.Points;
    3334import net.i2p.router.tunnel.pool.TunnelPool;
    3435import net.i2p.router.util.HashDistance;
     
    5152 *
    5253 */
    53 class SybilRenderer {
     54public class SybilRenderer {
    5455
    5556    private final RouterContext _context;
     
    103104    }
    104105
    105     /**
    106      *  A total score and a List of reason Strings
    107      */
    108     public static class Points implements Comparable<Points> {
    109          private double points;
    110          private final List<String> reasons;
    111 
    112          public Points(double points, String reason) {
    113              this.points = points;
    114              reasons = new ArrayList<String>(4);
    115              reasons.add(reason);
    116          }
    117          public int compareTo(Points r) {
    118              return Double.compare(points, r.points);
    119         }
    120     }
    121 
    122106    private static class PointsComparator implements Comparator<Hash>, Serializable {
    123107         private final Map<Hash, Points> _points;
     
    160144     *  points1 is unmodified.
    161145     */
     146/****
    162147    private void mergePoints(Map<Hash, Points> points1, Map<Hash, Points> points2) {
    163148        for (Map.Entry<Hash, Points> e : points1.entrySet()) {
     
    173158        }
    174159    }
    175 
     160****/
     161
     162    /** */
    176163    private void addPoints(Map<Hash, Points> points, Hash h, double d, String reason) {
    177         String rsn = fmt.format(d) + ": " + reason;
    178164        Points dd = points.get(h);
    179165        if (dd != null) {
    180             dd.points += d;
    181             dd.reasons.add(rsn);
     166            dd.addPoints(d, reason);
    182167        } else {
    183             points.put(h, new Points(d, rsn));
     168            points.put(h, new Points(d, reason));
    184169        }
    185170    }
     
    324309                    continue;
    325310                Points pp = points.get(h);
    326                 double p = pp.points;
     311                double p = pp.getPoints();
    327312                if (p < MIN_DISPLAY_POINTS)
    328313                    break;  // sorted
    329314                buf.append("<p class=\"threatpoints\"><b>Threat Points: " + fmt.format(p) + "</b></p><ul>");
    330                 if (pp.reasons.size() > 1)
    331                     Collections.sort(pp.reasons, new ReasonComparator());
    332                 for (String s : pp.reasons) {
     315                List<String> reasons = pp.getReasons();
     316                if (reasons.size() > 1)
     317                    Collections.sort(reasons, new ReasonComparator());
     318                for (String s : reasons) {
    333319                    int c = s.indexOf(':');
    334320                    if (c <= 0)
Note: See TracChangeset for help on using the changeset viewer.