Changeset 68c3121


Ignore:
Timestamp:
Dec 4, 2015 8:35:38 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ff4d575
Parents:
cab69f65
Message:

Console: Fix NPE on /profiles
Profiles:

  • Fix first heard about to be earliest, undeprecate
  • Fixup first heard about at profile readin
  • Persist good/bad lookup/store DBHistory stats added in 0.7.8
  • Remove unused DBHistory methods and fields to save memory
  • Change bonus longs to ints to save memory
  • Extend profile expiration time from 3 days to 15
  • Consolidate getLong()
  • Synch fixes

Sybil tool: Tweaks and enhancements

Files:
10 edited

Legend:

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

    rcab69f65 r68c3121  
    4343                if (prof != null) {
    4444                    try {
    45                         prof.setSpeedBonus(Long.parseLong(_speed));
     45                        prof.setSpeedBonus(Integer.parseInt(_speed));
    4646                    } catch (NumberFormatException nfe) {
    4747                        addFormError(_t("Bad speed value"));
    4848                    }
    4949                    try {
    50                         prof.setCapacityBonus(Long.parseLong(_capacity));
     50                        prof.setCapacityBonus(Integer.parseInt(_capacity));
    5151                    } catch (NumberFormatException nfe) {
    5252                        addFormError(_t("Bad capacity value"));
  • apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java

    rcab69f65 r68c3121  
    4949            if (_organizer.getUs().equals(peer)) continue;
    5050            PeerProfile prof = _organizer.getProfile(peer);
     51            if (prof == null)
     52                continue;
    5153            if (mode == 2) {
    5254                RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
  • apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java

    rcab69f65 r68c3121  
    4646    private static final int PAIRMAX = 10;
    4747    private static final int MAX = 10;
     48    // multiplied by size - 1, will also get POINTS24 added
     49    private static final double POINTS32 = 10.0;
     50    // multiplied by size - 1, will also get POINTS16 added
     51    private static final double POINTS24 = 10.0;
    4852    // multiplied by size - 1
    49     private static final double POINTS32 = 15.0;
    50     // multiplied by size - 1
    51     private static final double POINTS24 = 2.0;
     53    private static final double POINTS16 = 0.25;
    5254    private static final double MIN_CLOSE = 242.0;
    5355    private static final double MIN_DISPLAY_POINTS = 3.0;
     
    7678    }
    7779
     80    /**
     81     *  A total score and a List of reason Strings
     82     */
    7883    private static class Points implements Comparable<Points> {
    7984         private double points;
     
    107112
    108113    private static void addPoints(Map<Hash, Points> points, Hash h, double d, String reason) {
     114        DecimalFormat fmt = new DecimalFormat("#0.00");
    109115        Points dd = points.get(h);
    110116        if (dd != null) {
    111117            dd.points += d;
    112             dd.reasons.add(reason);
     118            dd.reasons.add("<b>" + fmt.format(d) + ":</b> " + reason);
    113119        } else {
    114             points.put(h, new Points(d, reason));
     120            points.put(h, new Points(d, "<b>" + fmt.format(d) + ":</b> " + reason));
    115121        }
    116122    }
     
    164170
    165171        Map<Hash, Points> points = new HashMap<Hash, Points>(64);
     172
     173        // IP analysis
    166174        renderIPGroups32(out, buf, ris, points);
    167175        renderIPGroups24(out, buf, ris, points);
    168         renderIPGroups16(out, buf, ris);
    169 
     176        renderIPGroups16(out, buf, ris, points);
     177
     178        // Pairwise distance analysis
    170179        renderPairDistance(out, buf, ris, points);
    171180
     181        // Distance to our router analysis
    172182        buf.append("<h3>Closest Floodfills to Our Routing Key (Where we Store our RI)</h3>");
    173183        renderRouterInfoHTML(out, buf, ourRKey, avgMinDist, ris, points);
     
    176186        renderRouterInfoHTML(out, buf, us, avgMinDist, ris, points);
    177187
     188        // Distance to our published destinations analysis
    178189        Map<Hash, TunnelPool> clientInboundPools = _context.tunnelManager().getInboundClientPools();
    179190        List<Hash> destinations = new ArrayList<Hash>(clientInboundPools.keySet());
     
    194205            renderRouterInfoHTML(out, buf, rkey, avgMinDist, ris, points);
    195206        }
     207
     208        // TODO Profile analysis
    196209
    197210        if (!points.isEmpty()) {
     
    261274            double point = MIN_CLOSE - distance;
    262275            if (point > 0) {
    263                 addPoints(points, p.r1.getHash(), point, fmt.format(point) + ": Too close to other floodfill " + p.r2.getHash().toBase64());
    264                 addPoints(points, p.r2.getHash(), point, fmt.format(point) + ": Too close to other floodfill " + p.r1.getHash().toBase64());
     276                addPoints(points, p.r1.getHash(), point, "Very close (" + fmt.format(distance) +
     277                          ") to other floodfill " + p.r2.getHash().toBase64());
     278                addPoints(points, p.r2.getHash(), point, "Very close (" + fmt.format(distance) +
     279                          ") to other floodfill " + p.r1.getHash().toBase64());
    265280            }
    266281        }
     
    348363                renderRouterInfo(buf, info, null, false, false);
    349364                double point = POINTS32 * (count - 1);
    350                 addPoints(points, info.getHash(), point, fmt.format(point) + ": Same IP with " + (count - 1) + " other");
     365                addPoints(points, info.getHash(), point, "Same IP with " + (count - 1) + " other");
    351366            }
    352367        }
     
    397412                renderRouterInfo(buf, info, null, false, false);
    398413                double point = POINTS24 * (count - 1);
    399                 addPoints(points, info.getHash(), point, fmt.format(point) + ": Same /24 IP with " + (count - 1) + " other");
     414                addPoints(points, info.getHash(), point, "Same /24 IP with " + (count - 1) + " other");
    400415            }
    401416        }
     
    405420    }
    406421
    407     /** no points */
    408     private void renderIPGroups16(Writer out, StringBuilder buf, List<RouterInfo> ris) throws IOException {
     422    private void renderIPGroups16(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
    409423        buf.append("<h3>Floodfills in the Same /16 (4 minimum)</h3>");
    410424        int sz = ris.size();
     
    424438        }
    425439        Collections.sort(foo, new FooComparator(oc));
     440        DecimalFormat fmt = new DecimalFormat("#0.00");
    426441        for (Integer ii : foo) {
    427442            int count = oc.count(ii);
     
    440455                    continue;
    441456                renderRouterInfo(buf, info, null, false, false);
     457                double point = POINTS16 * (count - 1);
     458                addPoints(points, info.getHash(), point, "Same /16 IP with " + (count - 1) + " other");
    442459            }
    443460        }
     
    485502            if (point > 0) {
    486503                point *= 2.0;
    487                 addPoints(points, ri.getHash(), point, fmt.format(point) + ": Too close to our key " + us.toBase64());
     504                addPoints(points, ri.getHash(), point, "Very close (" + fmt.format(dist) + ") to our key " + us.toBase64());
    488505            }
    489506            if (i >= MAX - 1)
     
    531548            buf.append("<a name=\"our-info\" ></a><b>" + _t("Our info") + ": ").append(hash).append("</b></th></tr><tr><td>\n");
    532549        } else {
    533             buf.append("<b>" + _t("Peer info for") + ":</b> ").append(hash).append("\n");
     550            buf.append("<b>" + _t("Router") + ":</b> ").append(hash).append("\n");
    534551            if (!full) {
    535552                buf.append("[<a href=\"netdb?r=").append(hash.substring(0, 6)).append("\" >").append(_t("Full entry")).append("</a>]");
     
    559576                long heard = prof.getFirstHeardAbout();
    560577                if (heard > 0) {
    561                     long age = now - heard;
    562                     if (age > 0) {
    563                        buf.append("<b>First heard about:</b> ")
    564                           .append(_t("{0} ago", DataHelper.formatDuration2(age))).append("<br>\n");
    565                     } else {
    566                             // shouldnt happen
    567                        buf.append("<b>First heard about:</b> in ").append(DataHelper.formatDuration2(0-age)).append("???<br>\n");
    568                     }
     578                    long age = Math.max(now - heard, 1);
     579                    buf.append("<b>First heard about:</b> ")
     580                       .append(_t("{0} ago", DataHelper.formatDuration2(age))).append("<br>\n");
     581                }
     582                heard = prof.getLastHeardAbout();
     583                if (heard > 0) {
     584                    long age = Math.max(now - heard, 1);
     585                    buf.append("<b>Last heard about:</b> ")
     586                       .append(_t("{0} ago", DataHelper.formatDuration2(age))).append("<br>\n");
     587                }
     588                heard = prof.getLastHeardFrom();
     589                if (heard > 0) {
     590                    long age = Math.max(now - heard, 1);
     591                    buf.append("<b>Last heard from:</b> ")
     592                       .append(_t("{0} ago", DataHelper.formatDuration2(age))).append("<br>\n");
    569593                }
    570594                // any other profile stuff?
     
    597621            for (Map.Entry<Object, Object> e : p.entrySet()) {
    598622                String name = (String) e.getKey();
    599                 if (name.equals("key") || name.startsWith("ikey") || name.startsWith("itag") || name.startsWith("iport"))
     623                if (name.equals("key") || name.startsWith("ikey") || name.startsWith("itag") ||
     624                    name.startsWith("iport") || name.equals("mtu"))
    600625                    continue;
    601626                String val = (String) e.getValue();
  • history.txt

    rcab69f65 r68c3121  
     12015-12-04 zzz
     2 * Console: Fix NPE on /profiles
     3 * Profiles:
     4   - Fix first heard about to be earliest, undeprecate
     5   - Fixup first heard about at profile readin
     6   - Persist good/bad lookup/store DBHistory stats added in 0.7.8
     7   - Remove unused DBHistory methods and fields to save memory
     8   - Change bonus longs to ints to save memory
     9   - Extend profile expiration time from 3 days to 15
     10   - Consolidate getLong()
     11   - Synch fixes
     12 * Sybil tool: Tweaks and enhancements
     13
    1142015-12-03 zzz
    215 * Console: Add experimental Sybil analysis tool
  • router/java/src/net/i2p/router/RouterVersion.java

    rcab69f65 r68c3121  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 8;
     21    public final static long BUILD = 9;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/peermanager/DBHistory.java

    rcab69f65 r68c3121  
    1717    private final Log _log;
    1818    private final RouterContext _context;
    19     private long _successfulLookups;
    20     private long _failedLookups;
     19    //private long _successfulLookups;
     20    //private long _failedLookups;
    2121    private RateStat _failedLookupRate;
    2222    private RateStat _invalidReplyRate;
    23     private long _lookupReplyNew;
    24     private long _lookupReplyOld;
    25     private long _lookupReplyDuplicate;
    26     private long _lookupReplyInvalid;
    27     private long _lookupsReceived;
    28     private long _avgDelayBetweenLookupsReceived;
    29     private long _lastLookupReceived;
     23    //private long _lookupReplyNew;
     24    //private long _lookupReplyOld;
     25    //private long _lookupReplyDuplicate;
     26    //private long _lookupReplyInvalid;
     27    //private long _lookupsReceived;
     28    //private long _avgDelayBetweenLookupsReceived;
     29    //private long _lastLookupReceived;
    3030    private long _lastLookupSuccessful;
    3131    private long _lastLookupFailed;
     
    4040        _log = context.logManager().getLog(DBHistory.class);
    4141        _statGroup = statGroup;
    42         _lastLookupReceived = -1;
     42        //_lastLookupReceived = -1;
    4343        createRates(statGroup);
    4444    }
    4545   
    4646    /** how many times we have sent them a db lookup and received the value back from them
    47      *  @deprecated unused
    48      */
    49     public long getSuccessfulLookups() { return _successfulLookups; }
     47     */
     48    //public long getSuccessfulLookups() { return _successfulLookups; }
     49
    5050    /** how many times we have sent them a db lookup and not received the value or a lookup reply
    51      *  @deprecated unused
    52      */
    53     public long getFailedLookups() { return _failedLookups; }
     51     */
     52    //public long getFailedLookups() { return _failedLookups; }
     53
    5454    /** how many peers that we have never seen before did lookups provide us with?
    55      *  @deprecated unused
    56      */
    57     public long getLookupReplyNew() { return _lookupReplyNew; }
     55     */
     56    //public long getLookupReplyNew() { return _lookupReplyNew; }
     57
    5858    /** how many peers that we have already seen did lookups provide us with?
    59      *  @deprecated unused
    60      */
    61     public long getLookupReplyOld() { return _lookupReplyOld; }
     59     */
     60    //public long getLookupReplyOld() { return _lookupReplyOld; }
     61
    6262    /** how many peers that we explicitly asked the peer not to send us did they reply with?
    63      *  @deprecated unused
    64      */
    65     public long getLookupReplyDuplicate() { return _lookupReplyDuplicate; }
     63     */
     64    //public long getLookupReplyDuplicate() { return _lookupReplyDuplicate; }
     65
    6666    /** how many peers that were incorrectly formatted / expired / otherwise illegal did lookups provide us with?
    67      *  @deprecated unused
    68      */
    69     public long getLookupReplyInvalid() { return _lookupReplyInvalid; }
     67     */
     68    //public long getLookupReplyInvalid() { return _lookupReplyInvalid; }
     69
    7070    /** how many lookups this peer has sent us?
    71      *  @deprecated unused
    72      */
    73     public long getLookupsReceived() { return _lookupsReceived; }
     71     */
     72    //public long getLookupsReceived() { return _lookupsReceived; }
     73
    7474    /** how frequently do they send us lookup requests?
    75      *  @deprecated unused
    76      */
    77     public long getAvgDelayBetweenLookupsReceived() { return _avgDelayBetweenLookupsReceived; }
     75     */
     76    //public long getAvgDelayBetweenLookupsReceived() { return _avgDelayBetweenLookupsReceived; }
     77
    7878    /** when did they last send us a request?
    79      *  @deprecated unused
    80      */
    81     public long getLastLookupReceived() { return _lastLookupReceived; }
     79     */
     80   // public long getLastLookupReceived() { return _lastLookupReceived; }
     81
     82    /**
     83     *  Not persisted until 0.9.24
     84     *  @since 0.7.8
     85     */
    8286    public long getLastLookupSuccessful() { return _lastLookupSuccessful; }
     87
     88    /**
     89     *  Not persisted until 0.9.24
     90     *  @since 0.7.8
     91     */
    8392    public long getLastLookupFailed() { return _lastLookupFailed; }
     93
     94    /**
     95     *  Not persisted until 0.9.24
     96     *  @since 0.7.8
     97     */
    8498    public long getLastStoreSuccessful() { return _lastStoreSuccessful; }
     99
     100    /**
     101     *  Not persisted until 0.9.24
     102     *  @since 0.7.8
     103     */
    85104    public long getLastStoreFailed() { return _lastStoreFailed; }
    86105
     
    104123     */
    105124    public void lookupSuccessful() {
    106         _successfulLookups++;
    107         _failedLookupRate.addData(0, 0);
     125        //_successfulLookups++;
     126        _failedLookupRate.addData(0);
    108127        _context.statManager().addRateData("peer.failedLookupRate", 0);
    109128        _lastLookupSuccessful = _context.clock().now();
     
    114133     */
    115134    public void lookupFailed() {
    116         _failedLookups++;
    117         _failedLookupRate.addData(1, 0);
     135        //_failedLookups++;
     136        _failedLookupRate.addData(1);
    118137        _context.statManager().addRateData("peer.failedLookupRate", 1);
    119138        _lastLookupFailed = _context.clock().now();
     
    124143     * by asking another floodfill peer
    125144     *
     145     *  @since 0.7.8
    126146     */
    127147    public void storeSuccessful() {
    128148        // Fixme, redefined this to include both lookup and store fails,
    129149        // need to fix the javadocs
    130         _failedLookupRate.addData(0, 0);
     150        _failedLookupRate.addData(0);
    131151        _context.statManager().addRateData("peer.failedLookupRate", 0);
    132152        _lastStoreSuccessful = _context.clock().now();
     
    135155    /**
    136156     * Note that floodfill verify failed
     157     *
     158     *  @since 0.7.8
    137159     */
    138160    public void storeFailed() {
    139161        // Fixme, redefined this to include both lookup and store fails,
    140162        // need to fix the javadocs
    141         _failedLookupRate.addData(1, 0);
     163        _failedLookupRate.addData(1);
    142164        _lastStoreFailed = _context.clock().now();
    143165    }
     
    153175     */
    154176    public void lookupReply(int newPeers, int oldPeers, int invalid, int duplicate) {
    155         _lookupReplyNew += newPeers;
    156         _lookupReplyOld += oldPeers;
    157         _lookupReplyInvalid += invalid;
    158         _lookupReplyDuplicate += duplicate;
     177        //_lookupReplyNew += newPeers;
     178        //_lookupReplyOld += oldPeers;
     179        //_lookupReplyInvalid += invalid;
     180        //_lookupReplyDuplicate += duplicate;
    159181       
    160182        if (invalid > 0) {
    161             _invalidReplyRate.addData(invalid, 0);
     183            _invalidReplyRate.addData(invalid);
    162184        }
    163185    }
     186
    164187    /**
    165188     * Note that the peer sent us a lookup
    166189     *
    167190     */
     191/****
    168192    public void lookupReceived() {
    169193        long now = _context.clock().now();
     
    180204        }
    181205    }
     206****/
     207
    182208    /**
    183209     * Note that the peer sent us a data point without us asking for it
     
    191217    }
    192218   
    193     public void setSuccessfulLookups(long num) { _successfulLookups = num; }
    194     public void setFailedLookups(long num) { _failedLookups = num; }
    195     public void setLookupReplyNew(long num) { _lookupReplyNew = num; }
    196     public void setLookupReplyOld(long num) { _lookupReplyOld = num; }
    197     public void setLookupReplyInvalid(long num) { _lookupReplyInvalid = num; }
    198     public void setLookupReplyDuplicate(long num) { _lookupReplyDuplicate = num; }
    199     public void setLookupsReceived(long num) { _lookupsReceived = num; }
    200     public void setAvgDelayBetweenLookupsReceived(long ms) { _avgDelayBetweenLookupsReceived = ms; }
    201     public void setLastLookupReceived(long when) { _lastLookupReceived = when; }
     219    //public void setSuccessfulLookups(long num) { _successfulLookups = num; }
     220    //public void setFailedLookups(long num) { _failedLookups = num; }
     221    //public void setLookupReplyNew(long num) { _lookupReplyNew = num; }
     222    //public void setLookupReplyOld(long num) { _lookupReplyOld = num; }
     223    //public void setLookupReplyInvalid(long num) { _lookupReplyInvalid = num; }
     224    //public void setLookupReplyDuplicate(long num) { _lookupReplyDuplicate = num; }
     225    //public void setLookupsReceived(long num) { _lookupsReceived = num; }
     226    //public void setAvgDelayBetweenLookupsReceived(long ms) { _avgDelayBetweenLookupsReceived = ms; }
     227    //public void setLastLookupReceived(long when) { _lastLookupReceived = when; }
    202228    public void setUnpromptedDbStoreNew(long num) { _unpromptedDbStoreNew = num; }
    203229    public void setUnpromptedDbStoreOld(long num) { _unpromptedDbStoreOld = num; }
     
    218244        buf.append("# DB history").append(NL);
    219245        buf.append("###").append(NL);
    220         add(buf, "successfulLookups", _successfulLookups, "How many times have they successfully given us what we wanted when looking for it?");
    221         add(buf, "failedLookups", _failedLookups, "How many times have we sent them a db lookup and they didn't reply?");
    222         add(buf, "lookupsReceived", _lookupsReceived, "How many lookups have they sent us?");
    223         add(buf, "lookupReplyDuplicate", _lookupReplyDuplicate, "How many of their reply values to our lookups were something we asked them not to send us?");
    224         add(buf, "lookupReplyInvalid", _lookupReplyInvalid, "How many of their reply values to our lookups were invalid (expired, forged, corrupted)?");
    225         add(buf, "lookupReplyNew", _lookupReplyNew, "How many of their reply values to our lookups were brand new to us?");
    226         add(buf, "lookupReplyOld", _lookupReplyOld, "How many of their reply values to our lookups were something we had seen before?");
     246        //add(buf, "successfulLookups", _successfulLookups, "How many times have they successfully given us what we wanted when looking for it?");
     247        //add(buf, "failedLookups", _failedLookups, "How many times have we sent them a db lookup and they didn't reply?");
     248        //add(buf, "lookupsReceived", _lookupsReceived, "How many lookups have they sent us?");
     249        //add(buf, "lookupReplyDuplicate", _lookupReplyDuplicate, "How many of their reply values to our lookups were something we asked them not to send us?");
     250        //add(buf, "lookupReplyInvalid", _lookupReplyInvalid, "How many of their reply values to our lookups were invalid (expired, forged, corrupted)?");
     251        //add(buf, "lookupReplyNew", _lookupReplyNew, "How many of their reply values to our lookups were brand new to us?");
     252        //add(buf, "lookupReplyOld", _lookupReplyOld, "How many of their reply values to our lookups were something we had seen before?");
    227253        add(buf, "unpromptedDbStoreNew", _unpromptedDbStoreNew, "How times have they sent us something we didn't ask for and hadn't seen before?");
    228254        add(buf, "unpromptedDbStoreOld", _unpromptedDbStoreOld, "How times have they sent us something we didn't ask for but have seen before?");
    229         add(buf, "lastLookupReceived", _lastLookupReceived, "When was the last time they send us a lookup?  (milliseconds since the epoch)");
    230         add(buf, "avgDelayBetweenLookupsReceived", _avgDelayBetweenLookupsReceived, "How long is it typically between each db lookup they send us?  (in milliseconds)");
     255        //add(buf, "lastLookupReceived", _lastLookupReceived, "When was the last time they send us a lookup?  (milliseconds since the epoch)");
     256        //add(buf, "avgDelayBetweenLookupsReceived", _avgDelayBetweenLookupsReceived, "How long is it typically between each db lookup they send us?  (in milliseconds)");
     257        // following 4 weren't persisted until 0.9.24
     258        add(buf, "lastLookupSuccessful", _lastLookupSuccessful, "When was the last time a lookup from them succeeded?  (milliseconds since the epoch)");
     259        add(buf, "lastLookupFailed", _lastLookupFailed, "When was the last time a lookup from them failed?  (milliseconds since the epoch)");
     260        add(buf, "lastStoreSuccessful", _lastStoreSuccessful, "When was the last time a store to them succeeded?  (milliseconds since the epoch)");
     261        add(buf, "lastStoreFailed", _lastStoreFailed, "When was the last time a store to them failed?  (milliseconds since the epoch)");
    231262        out.write(buf.toString().getBytes("UTF-8"));
    232263        _failedLookupRate.store(out, "dbHistory.failedLookupRate");
     
    241272   
    242273    public void load(Properties props) {
    243         _successfulLookups = getLong(props, "dbHistory.successfulLookups");
    244         _failedLookups = getLong(props, "dbHistory.failedLookups");
    245         _lookupsReceived = getLong(props, "dbHistory.lookupsReceived");
    246         _lookupReplyDuplicate = getLong(props, "dbHistory.lookupReplyDuplicate");
    247         _lookupReplyInvalid = getLong(props, "dbHistory.lookupReplyInvalid");
    248         _lookupReplyNew = getLong(props, "dbHistory.lookupReplyNew");
    249         _lookupReplyOld = getLong(props, "dbHistory.lookupReplyOld");
     274        //_successfulLookups = getLong(props, "dbHistory.successfulLookups");
     275        //_failedLookups = getLong(props, "dbHistory.failedLookups");
     276        //_lookupsReceived = getLong(props, "dbHistory.lookupsReceived");
     277        //_lookupReplyDuplicate = getLong(props, "dbHistory.lookupReplyDuplicate");
     278        //_lookupReplyInvalid = getLong(props, "dbHistory.lookupReplyInvalid");
     279        //_lookupReplyNew = getLong(props, "dbHistory.lookupReplyNew");
     280        //_lookupReplyOld = getLong(props, "dbHistory.lookupReplyOld");
    250281        _unpromptedDbStoreNew = getLong(props, "dbHistory.unpromptedDbStoreNew");
    251282        _unpromptedDbStoreOld = getLong(props, "dbHistory.unpromptedDbStoreOld");
    252         _lastLookupReceived = getLong(props, "dbHistory.lastLookupReceived");
    253         _avgDelayBetweenLookupsReceived = getLong(props, "dbHistory.avgDelayBetweenLookupsReceived");
     283        //_lastLookupReceived = getLong(props, "dbHistory.lastLookupReceived");
     284        //_avgDelayBetweenLookupsReceived = getLong(props, "dbHistory.avgDelayBetweenLookupsReceived");
     285        // following 4 weren't persisted until 0.9.24
     286        _lastLookupSuccessful = getLong(props, "dbHistory.lastLookupSuccessful");
     287        _lastLookupFailed = getLong(props, "dbHistory.lastLookupFailed");
     288        _lastStoreSuccessful = getLong(props, "dbHistory.lastStoreSuccessful");
     289        _lastStoreFailed = getLong(props, "dbHistory.lastStoreFailed");
    254290        try {
    255291            _failedLookupRate.load(props, "dbHistory.failedLookupRate", true);
     
    267303    }
    268304   
    269     private void createRates(String statGroup) {
     305    private synchronized void createRates(String statGroup) {
    270306        if (_failedLookupRate == null)
    271307            _failedLookupRate = new RateStat("dbHistory.failedLookupRate", "How often does this peer to respond to a lookup?", statGroup, new long[] { 10*60*1000l, 60*60*1000l, 24*60*60*1000l });
     
    277313   
    278314    private final static long getLong(Properties props, String key) {
    279         String val = props.getProperty(key);
    280         if (val != null) {
    281             try {
    282                 return Long.parseLong(val);
    283             } catch (NumberFormatException nfe) {
    284                 return 0;
    285             }
    286         }
    287         return 0;
     315        return ProfilePersistenceHelper.getLong(props, key);
    288316    }
    289317}
  • router/java/src/net/i2p/router/peermanager/PeerProfile.java

    rcab69f65 r68c3121  
    2525 * (keeping only the most basic data) and maintain hundreds of thousands of profiles
    2626 * in memory. Beyond that size, we can simply eject the peers (e.g. keeping the best 100,000).
     27 *
     28 * TODO most of the methods should be synchronized.
     29 *
    2730 */
    2831
     
    4750    private RateStat _dbIntroduction;
    4851    // calculation bonuses
    49     private long _speedBonus;
    50     private long _capacityBonus;
    51     private long _integrationBonus;
     52    // ints to save some space
     53    private int _speedBonus;
     54    private int _capacityBonus;
     55    private int _integrationBonus;
    5256    // calculation values
    5357    private double _speedValue;
     
    8286
    8387    /**
     88     *  Caller should call setLastHeardAbout() and setFirstHeardAbout()
     89     *
    8490     *  @param peer non-null
    8591     */
     
    8995
    9096    /**
     97     *  Caller should call setLastHeardAbout() and setFirstHeardAbout()
     98     *
    9199     *  @param peer non-null
    92100     *  @param expand must be true (see below)
    93101     */
    94102    private PeerProfile(RouterContext context, Hash peer, boolean expand) {
     103        if (peer == null)
     104            throw new NullPointerException();
    95105        _context = context;
    96106        _log = context.logManager().getLog(PeerProfile.class);
    97         if (peer == null)
    98             throw new NullPointerException();
    99107        _peer = peer;
     108        _firstHeardAbout = _context.clock().now();
    100109        // this is always true, and there are several places in the router that will NPE
    101110        // if it is false, so all need to be fixed before we can have non-expanded profiles
     
    192201    /**
    193202     *  When did we first hear about this peer?
    194      *  Currently unused, candidate for removal.
    195      */
    196     public long getFirstHeardAbout() { return _firstHeardAbout; }
    197     public void setFirstHeardAbout(long when) { _firstHeardAbout = when; }
    198    
    199     /** when did we last hear about this peer? */
    200     public long getLastHeardAbout() { return _lastHeardAbout; }
    201     public void setLastHeardAbout(long when) { _lastHeardAbout = when; }
     203     *  @return greater than zero, set to now in consturctor
     204     */
     205    public synchronized long getFirstHeardAbout() { return _firstHeardAbout; }
     206
     207    /**
     208     *  Set when did we first heard about this peer, only if older.
     209     *  Package private, only set by profile management subsystem.
     210     */
     211    synchronized void setFirstHeardAbout(long when) {
     212        if (when < _firstHeardAbout)
     213            _firstHeardAbout = when;
     214    }
     215   
     216    /**
     217     *  when did we last hear about this peer?
     218     *  @return 0 if unset
     219     */
     220    public synchronized long getLastHeardAbout() { return _lastHeardAbout; }
     221
     222    /**
     223     *  Set when did we last hear about this peer, only if unset or newer
     224     *  Also sets FirstHeardAbout if earlier
     225     */
     226    public synchronized void setLastHeardAbout(long when) {
     227        if (_lastHeardAbout <= 0 || when > _lastHeardAbout)
     228            _lastHeardAbout = when;
     229        // this is called by netdb PersistentDataStore, so fixup first heard
     230        if (when < _firstHeardAbout)
     231            _firstHeardAbout = when;
     232    }
    202233   
    203234    /** when did we last send to this peer successfully? */
     
    245276     * penalties
    246277     */
    247     public long getSpeedBonus() { return _speedBonus; }
    248     public void setSpeedBonus(long bonus) { _speedBonus = bonus; }
     278    public int getSpeedBonus() { return _speedBonus; }
     279    public void setSpeedBonus(int bonus) { _speedBonus = bonus; }
    249280   
    250281    /**
     
    253284     * penalties
    254285     */
    255     public long getCapacityBonus() { return _capacityBonus; }
    256     public void setCapacityBonus(long bonus) { _capacityBonus = bonus; }
     286    public int getCapacityBonus() { return _capacityBonus; }
     287    public void setCapacityBonus(int bonus) { _capacityBonus = bonus; }
    257288   
    258289    /**
     
    261292     * penalties
    262293     */
    263     public long getIntegrationBonus() { return _integrationBonus; }
    264     public void setIntegrationBonus(long bonus) { _integrationBonus = bonus; }
     294    public int getIntegrationBonus() { return _integrationBonus; }
     295    public void setIntegrationBonus(int bonus) { _integrationBonus = bonus; }
    265296   
    266297    /**
     
    430461     *
    431462     */
    432     public void expandProfile() {
     463    public synchronized void expandProfile() {
    433464        String group = (null == _peer ? "profileUnknown" : _peer.toBase64().substring(0,6));
    434465        //if (_sendSuccessSize == null)
  • router/java/src/net/i2p/router/peermanager/ProfileManagerImpl.java

    rcab69f65 r68c3121  
    223223        if (!data.getIsExpandedDB())
    224224            return;
    225         DBHistory hist = data.getDBHistory();
    226         hist.lookupReceived();
     225        //DBHistory hist = data.getDBHistory();
     226        //hist.lookupReceived();
    227227    }
    228228   
     
    314314        PeerProfile data = getProfile(peer);
    315315        //if (data == null) return;
    316         if (when > data.getLastHeardAbout())
    317             data.setLastHeardAbout(when);
     316        data.setLastHeardAbout(when);
    318317    }
    319318   
     
    341340        if (prof == null) {
    342341            prof = new PeerProfile(_context, peer);
    343             prof.setFirstHeardAbout(_context.clock().now());
    344342            _context.profileOrganizer().addProfile(prof);
    345343        }
  • router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java

    rcab69f65 r68c3121  
    4949   
    5050    /**
    51      * If we haven't been able to get a message through to the peer in 3 days,
     51     * If we haven't been able to get a message through to the peer in this much time,
    5252     * drop the profile.  They may reappear, but if they do, their config may
    5353     * have changed (etc).
    5454     *
    5555     */
    56     private static final long EXPIRE_AGE = 3*24*60*60*1000;
     56    private static final long EXPIRE_AGE = 15*24*60*60*1000;
    5757   
    5858    private final File _profileDir;
     
    264264            }
    265265           
    266             profile.setCapacityBonus(getLong(props, "capacityBonus"));
    267             profile.setIntegrationBonus(getLong(props, "integrationBonus"));
    268             profile.setSpeedBonus(getLong(props, "speedBonus"));
     266            profile.setCapacityBonus((int) getLong(props, "capacityBonus"));
     267            profile.setIntegrationBonus((int) getLong(props, "integrationBonus"));
     268            profile.setSpeedBonus((int) getLong(props, "speedBonus"));
    269269           
    270270            profile.setLastHeardAbout(getLong(props, "lastHeardAbout"));
     
    283283            // don't load the DB info at all unless there is something interesting there
    284284            // (i.e. floodfills)
    285             // It seems like we do one or two lookups as a part of handshaking?
    286             // Not sure, to be researched.
    287             if (getLong(props, "dbHistory.successfulLookups") > 1 ||
    288                 getLong(props, "dbHistory.failedlLokups") > 1) {
     285            if (getLong(props, "dbHistory.lastLookupSuccessful") > 0 ||
     286                getLong(props, "dbHistory.lastLookupFailed") > 0 ||
     287                getLong(props, "dbHistory.lastStoreSuccessful") > 0 ||
     288                getLong(props, "dbHistory.lastStoreFailed") > 0) {
    289289                profile.expandDBProfile();
    290290                profile.getDBHistory().load(props);
     
    301301                _log.debug("Loaded the profile for " + peer.toBase64() + " from " + file.getName());
    302302           
     303            fixupFirstHeardAbout(profile);
    303304            return profile;
    304305        } catch (IOException e) {
     
    309310        }
    310311    }
    311    
    312     private final static long getLong(Properties props, String key) {
     312
     313    /**
     314     *  First heard about wasn't always set correctly before,
     315     *  set it to the minimum of all recorded timestamps.
     316     *
     317     *  @since 0.9.24
     318     */
     319    private void fixupFirstHeardAbout(PeerProfile p) {
     320        long min = Long.MAX_VALUE;
     321        long t = p.getLastHeardAbout();
     322        if (t > 0 && t < min) min = t;
     323        t = p.getLastSendSuccessful();
     324        if (t > 0 && t < min) min = t;
     325        t = p.getLastSendFailed();
     326        if (t > 0 && t < min) min = t;
     327        t = p.getLastHeardFrom();
     328        if (t > 0 && t < min) min = t;
     329        // the first was never used and the last 4 were never persisted
     330        //DBHistory dh = p.getDBHistory();
     331        //if (dh != null) {
     332        //    t = dh.getLastLookupReceived();
     333        //    if (t > 0 && t < min) min = t;
     334        //    t = dh.getLastLookupSuccessful();
     335        //    if (t > 0 && t < min) min = t;
     336        //    t = dh.getLastLookupFailed();
     337        //    if (t > 0 && t < min) min = t;
     338        //    t = dh.getLastStoreSuccessful();
     339        //    if (t > 0 && t < min) min = t;
     340        //    t = dh.getLastStoreFailed();
     341        //    if (t > 0 && t < min) min = t;
     342        //}
     343        TunnelHistory th = p.getTunnelHistory();
     344        if (th != null) {
     345            t = th.getLastAgreedTo();
     346            if (t > 0 && t < min) min = t;
     347            t = th.getLastRejectedCritical();
     348            if (t > 0 && t < min) min = t;
     349            t = th.getLastRejectedBandwidth();
     350            if (t > 0 && t < min) min = t;
     351            t = th.getLastRejectedTransient();
     352            if (t > 0 && t < min) min = t;
     353            t = th.getLastRejectedProbabalistic();
     354            if (t > 0 && t < min) min = t;
     355            t = th.getLastFailed();
     356            if (t > 0 && t < min) min = t;
     357        }
     358        long fha = p.getFirstHeardAbout();
     359        if (min > 0 && min < Long.MAX_VALUE && (fha <= 0 || min < fha)) {
     360            p.setFirstHeardAbout(min);
     361            if (_log.shouldDebug())
     362                _log.debug("Fixed up the FHA time for " + p.getPeer().toBase64() + " to " + (new Date(min)));
     363        }
     364    }
     365   
     366    static long getLong(Properties props, String key) {
    313367        String val = props.getProperty(key);
    314368        if (val != null) {
  • router/java/src/net/i2p/router/peermanager/TunnelHistory.java

    rcab69f65 r68c3121  
    9090        if (severity >= TUNNEL_REJECT_CRIT) {
    9191            _lastRejectedCritical = _context.clock().now();
    92             _rejectRate.addData(1, 1);
     92            _rejectRate.addData(1);
    9393        } else if (severity >= TUNNEL_REJECT_BANDWIDTH) {
    9494            _lastRejectedBandwidth = _context.clock().now();
    95             _rejectRate.addData(1, 1);
     95            _rejectRate.addData(1);
    9696        } else if (severity >= TUNNEL_REJECT_TRANSIENT_OVERLOAD) {
    9797            _lastRejectedTransient = _context.clock().now();
     
    109109    public void incrementFailed(int pct) {
    110110        _lifetimeFailed.incrementAndGet();
    111         _failRate.addData(pct, 1);
     111        _failRate.addData(pct);
    112112        _lastFailed = _context.clock().now();
    113113    }
     
    191191   
    192192    private final static long getLong(Properties props, String key) {
    193         String val = props.getProperty(key);
    194         if (val != null) {
    195             try {
    196                 return Long.parseLong(val);
    197             } catch (NumberFormatException nfe) {
    198                 return 0;
    199             }
    200         }
    201         return 0;
     193        return ProfilePersistenceHelper.getLong(props, key);
    202194    }
    203195}
Note: See TracChangeset for help on using the changeset viewer.