Changeset a8f11d1


Ignore:
Timestamp:
May 21, 2019 5:24:18 PM (11 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a6434fb
Parents:
67e7e45
Message:

Profiles: Omit comments from stored profiles

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/stat/PersistenceHelper.java

    r67e7e45 ra8f11d1  
    1616    private final static String NL = System.getProperty("line.separator");
    1717
    18     public final static void add(StringBuilder buf, String prefix, String name, String description, double value) {
    19         buf.append("# ").append(prefix).append(name).append(NL);
    20         buf.append("# ").append(description).append(NL);
    21         buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL);
     18    public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, double value) {
     19        if (addComments) {
     20            buf.append("# ").append(prefix).append(name).append(NL);
     21            buf.append("# ").append(description).append(NL);
     22        }
     23        buf.append(prefix).append(name).append('=').append(value).append(NL);
     24        if (addComments)
     25           buf.append(NL);
    2226    }
    2327
    2428    /** @since 0.8.5 */
    25     public final static void addDate(StringBuilder buf, String prefix, String name, String description, long value) {
    26         String when = value > 0 ? (new Date(value)).toString() : "Never";
    27         add(buf, prefix, name, description + ' ' + when, value);
     29    public final static void addDate(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
     30        if (addComments) {
     31            String when = value > 0 ? (new Date(value)).toString() : "Never";
     32            add(buf, true, prefix, name, description + ' ' + when, value);
     33       } else {
     34            add(buf, false, prefix, name, description, value);
     35       }
    2836    }
    2937
    3038    /** @since 0.8.5 */
    31     public final static void addTime(StringBuilder buf, String prefix, String name, String description, long value) {
    32         String when = DataHelper.formatDuration(value);
    33         add(buf, prefix, name, description + ' ' + when, value);
    34     }
     39    public final static void addTime(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
     40        if (addComments) {
     41            String when = DataHelper.formatDuration(value);
     42            add(buf, true, prefix, name, description + ' ' + when, value);
     43       } else {
     44            add(buf, false, prefix, name, description, value);
     45       }
     46   }
    3547
    3648    /** @param value non-negative */
    37     public final static void add(StringBuilder buf, String prefix, String name, String description, long value) {
    38         buf.append("# ").append(prefix).append(name).append(NL);
    39         buf.append("# ").append(description).append(NL);
    40         buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL);
     49    public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
     50        if (addComments) {
     51            buf.append("# ").append(prefix).append(name).append(NL);
     52            buf.append("# ").append(description).append(NL);
     53        }
     54        buf.append(prefix).append(name).append('=').append(value).append(NL);
     55        if (addComments)
     56           buf.append(NL);
    4157    }
    4258
  • core/java/src/net/i2p/stat/Rate.java

    r67e7e45 ra8f11d1  
    453453    }
    454454
     455    /**
     456     * Includes comment lines
     457     */
    455458    public synchronized void store(String prefix, StringBuilder buf) throws IOException {
    456         PersistenceHelper.addTime(buf, prefix, ".period", "Length of the period:", _period);
    457         PersistenceHelper.addDate(buf, prefix, ".creationDate",
     459        store(prefix, buf, true);
     460    }
     461
     462    /**
     463     * @param addComments add comment lines to the output
     464     * @since 0.9.41
     465     */
     466    public synchronized void store(String prefix, StringBuilder buf, boolean addComments) throws IOException {
     467        PersistenceHelper.addTime(buf, addComments, prefix, ".period", "Length of the period:", _period);
     468        PersistenceHelper.addDate(buf, addComments, prefix, ".creationDate",
    458469                              "When was this rate created?", _creationDate);
    459         PersistenceHelper.addDate(buf, prefix, ".lastCoalesceDate",
     470        PersistenceHelper.addDate(buf, addComments, prefix, ".lastCoalesceDate",
    460471                              "When did we last coalesce this rate?",
    461472                              _lastCoalesceDate);
    462         PersistenceHelper.addDate(buf, prefix, ".currentDate",
     473        PersistenceHelper.addDate(buf, addComments, prefix, ".currentDate",
    463474                              "When was this data written?", now());
    464         PersistenceHelper.add(buf, prefix, ".currentTotalValue",
     475        PersistenceHelper.add(buf, addComments, prefix, ".currentTotalValue",
    465476                              "Total value of data points in the current (uncoalesced) period", _currentTotalValue);
    466         PersistenceHelper.add(buf, prefix, ".currentEventCount",
     477        PersistenceHelper.add(buf, addComments, prefix, ".currentEventCount",
    467478                              "How many events have occurred in the current (uncoalesced) period?", _currentEventCount);
    468         PersistenceHelper.addTime(buf, prefix, ".currentTotalEventTime",
     479        PersistenceHelper.addTime(buf, addComments, prefix, ".currentTotalEventTime",
    469480                              "How much time have the events in the current (uncoalesced) period consumed?",
    470481                              _currentTotalEventTime);
    471         PersistenceHelper.add(buf, prefix, ".lastTotalValue",
     482        PersistenceHelper.add(buf, addComments, prefix, ".lastTotalValue",
    472483                              "Total value of data points in the most recent (coalesced) period", _lastTotalValue);
    473         PersistenceHelper.add(buf, prefix, ".lastEventCount",
     484        PersistenceHelper.add(buf, addComments, prefix, ".lastEventCount",
    474485                              "How many events have occurred in the most recent (coalesced) period?", _lastEventCount);
    475         PersistenceHelper.addTime(buf, prefix, ".lastTotalEventTime",
     486        PersistenceHelper.addTime(buf, addComments, prefix, ".lastTotalEventTime",
    476487                              "How much time have the events in the most recent (coalesced) period consumed?",
    477488                              _lastTotalEventTime);
    478         PersistenceHelper.add(buf, prefix, ".extremeTotalValue",
     489        PersistenceHelper.add(buf, addComments, prefix, ".extremeTotalValue",
    479490                              "Total value of data points in the most extreme period", _extremeTotalValue);
    480         PersistenceHelper.add(buf, prefix, ".extremeEventCount",
     491        PersistenceHelper.add(buf, addComments, prefix, ".extremeEventCount",
    481492                              "How many events have occurred in the most extreme period?", _extremeEventCount);
    482         PersistenceHelper.addTime(buf, prefix, ".extremeTotalEventTime",
     493        PersistenceHelper.addTime(buf, addComments, prefix, ".extremeTotalEventTime",
    483494                              "How much time have the events in the most extreme period consumed?",
    484495                              _extremeTotalEventTime);
    485         PersistenceHelper.add(buf, prefix, ".lifetimeTotalValue",
     496        PersistenceHelper.add(buf, addComments, prefix, ".lifetimeTotalValue",
    486497                              "Total value of data points since this stat was created", _lifetimeTotalValue);
    487         PersistenceHelper.add(buf, prefix, ".lifetimeEventCount",
     498        PersistenceHelper.add(buf, addComments, prefix, ".lifetimeEventCount",
    488499                              "How many events have occurred since this stat was created?", _lifetimeEventCount);
    489         PersistenceHelper.addTime(buf, prefix, ".lifetimeTotalEventTime",
     500        PersistenceHelper.addTime(buf, addComments, prefix, ".lifetimeTotalEventTime",
    490501                              "How much total time was consumed by the events since this stat was created?",
    491502                              _lifetimeTotalEventTime);
  • core/java/src/net/i2p/stat/RateStat.java

    r67e7e45 ra8f11d1  
    178178    }
    179179
     180    /**
     181     * Includes comment lines
     182     */
    180183    public void store(OutputStream out, String prefix) throws IOException {
     184        store(out, prefix, true);
     185    }
     186
     187    /**
     188     * @param addComments add comment lines to the output
     189     * @since 0.9.41
     190     */
     191    public void store(OutputStream out, String prefix, boolean addComments) throws IOException {
    181192        StringBuilder buf = new StringBuilder(1024);
    182         buf.append(NL);
    183         buf.append("################################################################################").append(NL);
    184         buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
    185         buf.append("# ").append(_description).append(NL);
    186         buf.append("# ").append(NL).append(NL);
    187         out.write(buf.toString().getBytes("UTF-8"));
    188         buf.setLength(0);
     193        if (addComments) {
     194            buf.append(NL);
     195            buf.append("################################################################################").append(NL);
     196            buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
     197            buf.append("# ").append(_description).append(NL);
     198            buf.append("# ").append(NL).append(NL);
     199            out.write(buf.toString().getBytes("UTF-8"));
     200            buf.setLength(0);
     201        }
    189202        for (Rate r: _rates){
    190             buf.append("#######").append(NL);
    191             buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
    192                 .append(_groupName).append(" - ").append(_statName).append(NL);
    193             buf.append(NL);
     203            if (addComments) {
     204                buf.append("#######").append(NL);
     205                buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
     206                    .append(_groupName).append(" - ").append(_statName).append(NL);
     207                buf.append(NL);
     208            }
    194209            String curPrefix = prefix + "." + DataHelper.formatDuration(r.getPeriod());
    195             r.store(curPrefix, buf);
     210            r.store(curPrefix, buf, addComments);
    196211            out.write(buf.toString().getBytes("UTF-8"));
    197212            buf.setLength(0);
  • history.txt

    r67e7e45 ra8f11d1  
     12019-05-21 zzz
     2 * Profiles: Omit comments from stored profiles
     3
     42019-05-20 zzz
     5 * Console: Hide some columns on /peers SSU tab unless advanced
     6 * Installer:
     7   - Fix -console install for Izpack 5 (ticket #2492)
     8   - Switch to Izpack 5 for non-windows release installer
     9 * Sybil:
     10   - Escape % in stored reasons
     11   - Improve error handling when loading files
     12   - Skip comment lines in stored files
     13 * Tunnels: Increase tunnel reuse probability
     14
    1152019-05-19 zzz
    2  * Sybil: Run IP and family tests on all routers
     16 * Build: Remove dependencies on Nashorn (ticket #2367)
     17 * Sybil:
     18   - Run IP and family tests on all routers
     19   - Delete old stored analysis if configured
    320
    4212019-05-18 zzz
  • router/java/src/net/i2p/router/RouterVersion.java

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

    r67e7e45 ra8f11d1  
    238238    private final static String NL = System.getProperty("line.separator");
    239239   
     240    /**
     241     * write out the data from the profile to the stream
     242     * includes comments
     243     */
    240244    public void store(OutputStream out) throws IOException {
     245        store(out, true);
     246    }
     247
     248    /**
     249     * write out the data from the profile to the stream
     250     * @param addComments add comment lines to the output
     251     * @since 0.9.41
     252     */
     253    public void store(OutputStream out, boolean addComments) throws IOException {
    241254        StringBuilder buf = new StringBuilder(512);
    242         buf.append(NL);
    243         buf.append("#################").append(NL);
    244         buf.append("# DB history").append(NL);
    245         buf.append("###").append(NL);
     255        if (addComments) {
     256            buf.append(NL);
     257            buf.append("#################").append(NL);
     258            buf.append("# DB history").append(NL);
     259            buf.append("###").append(NL);
     260        }
    246261        //add(buf, "successfulLookups", _successfulLookups, "How many times have they successfully given us what we wanted when looking for it?");
    247262        //add(buf, "failedLookups", _failedLookups, "How many times have we sent them a db lookup and they didn't reply?");
     
    251266        //add(buf, "lookupReplyNew", _lookupReplyNew, "How many of their reply values to our lookups were brand new to us?");
    252267        //add(buf, "lookupReplyOld", _lookupReplyOld, "How many of their reply values to our lookups were something we had seen before?");
    253         add(buf, "unpromptedDbStoreNew", _unpromptedDbStoreNew, "How times have they sent us something we didn't ask for and hadn't seen before?");
    254         add(buf, "unpromptedDbStoreOld", _unpromptedDbStoreOld, "How times have they sent us something we didn't ask for but have seen before?");
     268        add(buf, addComments, "unpromptedDbStoreNew", _unpromptedDbStoreNew, "How times have they sent us something we didn't ask for and hadn't seen before?");
     269        add(buf, addComments, "unpromptedDbStoreOld", _unpromptedDbStoreOld, "How times have they sent us something we didn't ask for but have seen before?");
    255270        //add(buf, "lastLookupReceived", _lastLookupReceived, "When was the last time they send us a lookup?  (milliseconds since the epoch)");
    256271        //add(buf, "avgDelayBetweenLookupsReceived", _avgDelayBetweenLookupsReceived, "How long is it typically between each db lookup they send us?  (in milliseconds)");
    257272        // 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)");
     273        add(buf, addComments, "lastLookupSuccessful", _lastLookupSuccessful, "When was the last time a lookup from them succeeded?  (milliseconds since the epoch)");
     274        add(buf, addComments, "lastLookupFailed", _lastLookupFailed, "When was the last time a lookup from them failed?  (milliseconds since the epoch)");
     275        add(buf, addComments, "lastStoreSuccessful", _lastStoreSuccessful, "When was the last time a store to them succeeded?  (milliseconds since the epoch)");
     276        add(buf, addComments, "lastStoreFailed", _lastStoreFailed, "When was the last time a store to them failed?  (milliseconds since the epoch)");
    262277        out.write(buf.toString().getBytes("UTF-8"));
    263         _failedLookupRate.store(out, "dbHistory.failedLookupRate");
    264         _invalidReplyRate.store(out, "dbHistory.invalidReplyRate");
    265     }
    266    
    267     private static void add(StringBuilder buf, String name, long val, String description) {
    268         buf.append("# ").append(name.toUpperCase(Locale.US)).append(NL).append("# ").append(description).append(NL);
    269         buf.append("dbHistory.").append(name).append('=').append(val).append(NL).append(NL);
     278        _failedLookupRate.store(out, "dbHistory.failedLookupRate", addComments);
     279        _invalidReplyRate.store(out, "dbHistory.invalidReplyRate", addComments);
     280    }
     281   
     282    private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) {
     283        if (addComments)
     284            buf.append("# ").append(name.toUpperCase(Locale.US)).append(NL).append("# ").append(description).append(NL);
     285        buf.append("dbHistory.").append(name).append('=').append(val).append(NL);
     286        if (addComments)
     287            buf.append(NL);
    270288    }
    271289   
  • router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java

    r67e7e45 ra8f11d1  
    7676    public void setUs(Hash routerIdentHash) { _us = routerIdentHash; }
    7777   
    78     /** write out the data from the profile to the stream */
     78    /**
     79     * write out the data from the profile to the file
     80     */
    7981    public void writeProfile(PeerProfile profile) {
    8082        if (isExpired(profile.getLastSendSuccessful()))
     
    8688        try {
    8789            fos = new BufferedOutputStream(new GZIPOutputStream(new SecureFileOutputStream(f)));
    88             writeProfile(profile, fos);
     90            writeProfile(profile, fos, false);
    8991        } catch (IOException ioe) {
    9092            _log.error("Error writing profile to " + f);
     
    9799    }
    98100
    99     /** write out the data from the profile to the stream */
     101    /**
     102     * write out the data from the profile to the stream
     103     * includes comments
     104     */
    100105    public void writeProfile(PeerProfile profile, OutputStream out) throws IOException {
     106        writeProfile(profile, out, true);
     107    }
     108
     109    /**
     110     * write out the data from the profile to the stream
     111     * @param addComments add comment lines to the output
     112     * @since 0.9.41
     113     */
     114    public void writeProfile(PeerProfile profile, OutputStream out, boolean addComments) throws IOException {
    101115        String groups = null;
    102116        if (_context.profileOrganizer().isFailing(profile.getPeer())) {
     
    115129       
    116130        StringBuilder buf = new StringBuilder(512);
    117         buf.append("########################################################################").append(NL);
    118         buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL);
    119         if (_us != null)
    120             buf.append("# as calculated by ").append(_us.toBase64()).append(NL);
    121         buf.append("#").append(NL);
    122         buf.append("# Speed: ").append(profile.getSpeedValue()).append(NL);
    123         buf.append("# Capacity: ").append(profile.getCapacityValue()).append(NL);
    124         buf.append("# Integration: ").append(profile.getIntegrationValue()).append(NL);
    125         buf.append("# Groups: ").append(groups).append(NL);
    126         buf.append("#").append(NL);
    127         buf.append("########################################################################").append(NL);
    128         buf.append("##").append(NL);
    129         add(buf, "speedBonus", profile.getSpeedBonus(), "Manual adjustment to the speed score");
    130         add(buf, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score");
    131         add(buf, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score");
    132         addDate(buf, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first get a reference to this peer?");
    133         addDate(buf, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?");
    134         addDate(buf, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?");
    135         addDate(buf, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?");
    136         addDate(buf, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to the peer?");
    137         add(buf, "tunnelTestTimeAverage", profile.getTunnelTestTimeAverage(), "Moving average as to how fast the peer replies");
    138         add(buf, "tunnelPeakThroughput", profile.getPeakThroughputKBps(), "KBytes/sec");
    139         add(buf, "tunnelPeakTunnelThroughput", profile.getPeakTunnelThroughputKBps(), "KBytes/sec");
    140         add(buf, "tunnelPeakTunnel1mThroughput", profile.getPeakTunnel1mThroughputKBps(), "KBytes/sec");
    141         buf.append(NL);
     131        if (addComments) {
     132            buf.append("########################################################################").append(NL);
     133            buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL);
     134            if (_us != null)
     135                buf.append("# as calculated by ").append(_us.toBase64()).append(NL);
     136            buf.append("#").append(NL);
     137            buf.append("# Speed: ").append(profile.getSpeedValue()).append(NL);
     138            buf.append("# Capacity: ").append(profile.getCapacityValue()).append(NL);
     139            buf.append("# Integration: ").append(profile.getIntegrationValue()).append(NL);
     140            buf.append("# Groups: ").append(groups).append(NL);
     141            buf.append("#").append(NL);
     142            buf.append("########################################################################").append(NL);
     143            buf.append("##").append(NL);
     144        }
     145        add(buf, addComments, "speedBonus", profile.getSpeedBonus(), "Manual adjustment to the speed score");
     146        add(buf, addComments, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score");
     147        add(buf, addComments, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score");
     148        addDate(buf, addComments, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first get a reference to this peer?");
     149        addDate(buf, addComments, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?");
     150        addDate(buf, addComments, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?");
     151        addDate(buf, addComments, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?");
     152        addDate(buf, addComments, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to the peer?");
     153        add(buf, addComments, "tunnelTestTimeAverage", profile.getTunnelTestTimeAverage(), "Moving average as to how fast the peer replies");
     154        add(buf, addComments, "tunnelPeakThroughput", profile.getPeakThroughputKBps(), "KBytes/sec");
     155        add(buf, addComments, "tunnelPeakTunnelThroughput", profile.getPeakTunnelThroughputKBps(), "KBytes/sec");
     156        add(buf, addComments, "tunnelPeakTunnel1mThroughput", profile.getPeakTunnel1mThroughputKBps(), "KBytes/sec");
     157        if (addComments)
     158            buf.append(NL);
    142159       
    143160        out.write(buf.toString().getBytes("UTF-8"));
     
    145162        if (profile.getIsExpanded()) {
    146163            // only write out expanded data if, uh, we've got it
    147             profile.getTunnelHistory().store(out);
     164            profile.getTunnelHistory().store(out, addComments);
    148165            //profile.getReceiveSize().store(out, "receiveSize");
    149166            //profile.getSendSuccessSize().store(out, "sendSuccessSize");
    150             profile.getTunnelCreateResponseTime().store(out, "tunnelCreateResponseTime");
    151             profile.getTunnelTestResponseTime().store(out, "tunnelTestResponseTime");
     167            profile.getTunnelCreateResponseTime().store(out, "tunnelCreateResponseTime", addComments);
     168            profile.getTunnelTestResponseTime().store(out, "tunnelTestResponseTime", addComments);
    152169        }
    153170
    154171        if (profile.getIsExpandedDB()) {
    155             profile.getDBHistory().store(out);
    156             profile.getDbIntroduction().store(out, "dbIntroduction");
    157             profile.getDbResponseTime().store(out, "dbResponseTime");
     172            profile.getDBHistory().store(out, addComments);
     173            profile.getDbIntroduction().store(out, "dbIntroduction", addComments);
     174            profile.getDbResponseTime().store(out, "dbResponseTime", addComments);
    158175        }
    159176    }
    160177   
    161178    /** @since 0.8.5 */
    162     private static void addDate(StringBuilder buf, String name, long val, String description) {
    163         String when = val > 0 ? (new Date(val)).toString() : "Never";
    164         add(buf, name, val, description + ' ' + when);
     179    private static void addDate(StringBuilder buf, boolean addComments, String name, long val, String description) {
     180        if (addComments) {
     181            String when = val > 0 ? (new Date(val)).toString() : "Never";
     182            add(buf, true, name, val, description + ' ' + when);
     183        } else {
     184            add(buf, false, name, val, description);
     185        }
    165186    }
    166187   
    167188    /** @since 0.8.5 */
    168     private static void add(StringBuilder buf, String name, long val, String description) {
    169         buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
    170         buf.append(name).append('=').append(val).append(NL).append(NL);
     189    private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) {
     190        if (addComments)
     191            buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
     192        buf.append(name).append('=').append(val).append(NL);
     193        if (addComments)
     194            buf.append(NL);
    171195    }
    172196   
    173197    /** @since 0.8.5 */
    174     private static void add(StringBuilder buf, String name, float val, String description) {
    175         buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
    176         buf.append(name).append('=').append(val).append(NL).append(NL);
     198    private static void add(StringBuilder buf, boolean addComments, String name, float val, String description) {
     199        if (addComments)
     200            buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
     201        buf.append(name).append('=').append(val).append(NL);
     202        if (addComments)
     203            buf.append(NL);
    177204    }
    178205   
  • router/java/src/net/i2p/router/peermanager/TunnelHistory.java

    r67e7e45 ra8f11d1  
    138138   
    139139    public void store(OutputStream out) throws IOException {
     140        store(out, true);
     141    }
     142
     143    /**
     144     * write out the data from the profile to the stream
     145     * @param addComments add comment lines to the output
     146     * @since 0.9.41
     147     */
     148    public void store(OutputStream out, boolean addComments) throws IOException {
    140149        StringBuilder buf = new StringBuilder(512);
    141         buf.append(NL);
    142         buf.append("#################").append(NL);
    143         buf.append("# Tunnel history").append(NL);
    144         buf.append("###").append(NL);
    145         addDate(buf, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel?");
    146         addDate(buf, "lastFailed", _lastFailed, "When was the last time a tunnel that the peer agreed to participate failed?");
    147         addDate(buf, "lastRejectedCritical", _lastRejectedCritical, "When was the last time the peer refused to participate in a tunnel (Critical response code)?");
    148         addDate(buf, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel (Bandwidth response code)?");
    149         addDate(buf, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel (Transient load response code)?");
    150         addDate(buf, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel (Probabalistic response code)?");
    151         add(buf, "lifetimeAgreedTo", _lifetimeAgreedTo.get(), "How many tunnels has the peer ever agreed to participate in?");
    152         add(buf, "lifetimeFailed", _lifetimeFailed.get(), "How many tunnels has the peer ever agreed to participate in that failed prematurely?");
    153         add(buf, "lifetimeRejected", _lifetimeRejected.get(), "How many tunnels has the peer ever refused to participate in?");
     150        if (addComments) {
     151            buf.append(NL);
     152            buf.append("#################").append(NL);
     153            buf.append("# Tunnel history").append(NL);
     154            buf.append("###").append(NL);
     155        }
     156        addDate(buf, addComments, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel?");
     157        addDate(buf, addComments, "lastFailed", _lastFailed, "When was the last time a tunnel that the peer agreed to participate failed?");
     158        addDate(buf, addComments, "lastRejectedCritical", _lastRejectedCritical, "When was the last time the peer refused to participate in a tunnel (Critical response code)?");
     159        addDate(buf, addComments, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel (Bandwidth response code)?");
     160        addDate(buf, addComments, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel (Transient load response code)?");
     161        addDate(buf, addComments, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel (Probabalistic response code)?");
     162        add(buf, addComments, "lifetimeAgreedTo", _lifetimeAgreedTo.get(), "How many tunnels has the peer ever agreed to participate in?");
     163        add(buf, addComments, "lifetimeFailed", _lifetimeFailed.get(), "How many tunnels has the peer ever agreed to participate in that failed prematurely?");
     164        add(buf, addComments, "lifetimeRejected", _lifetimeRejected.get(), "How many tunnels has the peer ever refused to participate in?");
    154165        out.write(buf.toString().getBytes("UTF-8"));
    155         _rejectRate.store(out, "tunnelHistory.rejectRate");
    156         _failRate.store(out, "tunnelHistory.failRate");
    157     }
    158    
    159     private static void addDate(StringBuilder buf, String name, long val, String description) {
    160         String when = val > 0 ? (new Date(val)).toString() : "Never";
    161         add(buf, name, val, description + ' ' + when);
    162     }
    163    
    164     private static void add(StringBuilder buf, String name, long val, String description) {
    165         buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
    166         buf.append("tunnels.").append(name).append('=').append(val).append(NL).append(NL);
     166        _rejectRate.store(out, "tunnelHistory.rejectRate", addComments);
     167        _failRate.store(out, "tunnelHistory.failRate", addComments);
     168    }
     169   
     170    private static void addDate(StringBuilder buf, boolean addComments, String name, long val, String description) {
     171        if (addComments) {
     172            String when = val > 0 ? (new Date(val)).toString() : "Never";
     173            add(buf, true, name, val, description + ' ' + when);
     174        } else {
     175            add(buf, false, name, val, description);
     176        }
     177    }
     178   
     179    private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) {
     180        if (addComments)
     181            buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
     182        buf.append("tunnels.").append(name).append('=').append(val).append(NL);
     183        if (addComments)
     184            buf.append(NL);
    167185    }
    168186   
Note: See TracChangeset for help on using the changeset viewer.