Changeset a8f11d1 for router


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

Profiles: Omit comments from stored profiles

Location:
router/java/src/net/i2p/router
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.