Search in sources :

Example 6 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class ExploratoryPeerSelector method getEvents.

/**
 * Use current + last to get more recent and smoother data
 */
private int getEvents(String stat, long period) {
    RateStat rs = ctx.statManager().getRate(stat);
    if (rs == null)
        return 0;
    Rate r = rs.getRate(period);
    if (r == null)
        return 0;
    return (int) (r.computeAverages().getTotalEventCount());
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 7 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class StatisticsManager method includeAverageThroughput.

/* report the same data for tx and rx, for enhanced anonymity */
private void includeAverageThroughput(Properties stats) {
    RateStat sendRate = _context.statManager().getRate("bw.sendRate");
    RateStat recvRate = _context.statManager().getRate("bw.recvRate");
    if (sendRate == null || recvRate == null)
        return;
    Rate s = sendRate.getRate(60 * 60 * 1000);
    Rate r = recvRate.getRate(60 * 60 * 1000);
    if (s == null || r == null)
        return;
    double speed = (s.getAverageValue() + r.getAverageValue()) / 2;
    double max = Math.max(s.getExtremeAverageValue(), r.getExtremeAverageValue());
    String str = num(speed) + ';' + num(max) + ";0;0;";
    stats.setProperty("stat_bandwidthSendBps.60m", str);
    stats.setProperty("stat_bandwidthReceiveBps.60m", str);
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 8 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class Router method get5mRate.

/**
 *  When outboundOnly is false, outbound rate in bytes per second.
 *  When true, max of inbound and outbound rate in bytes per second.
 */
public int get5mRate(boolean outboundOnly) {
    int send = 0;
    RateStat rs = _context.statManager().getRate("bw.sendRate");
    if (rs != null)
        send = (int) rs.getRate(5 * 60 * 1000).getAverageValue();
    if (outboundOnly)
        return send;
    int recv = 0;
    rs = _context.statManager().getRate("bw.recvRate");
    if (rs != null)
        recv = (int) rs.getRate(5 * 60 * 1000).getAverageValue();
    return Math.max(send, recv);
}
Also used : RateStat(net.i2p.stat.RateStat)

Example 9 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class ProfileOrganizer method peerSendsBadReplies.

/**
 * Does the given peer send us bad replies - either invalid store messages
 * (expired, corrupt, etc) or unreachable replies (pointing towards routers
 * that don't exist).
 */
public boolean peerSendsBadReplies(Hash peer) {
    PeerProfile profile = getProfile(peer);
    if (profile != null && profile.getIsExpandedDB()) {
        RateStat invalidReplyRateStat = profile.getDBHistory().getInvalidReplyRate();
        Rate invalidReplyRate = invalidReplyRateStat.getRate(30 * 60 * 1000l);
        if ((invalidReplyRate.getCurrentTotalValue() > MAX_BAD_REPLIES_PER_HOUR) || (invalidReplyRate.getLastTotalValue() > MAX_BAD_REPLIES_PER_HOUR)) {
            return true;
        }
    }
    return false;
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 10 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class CapacityCalculator method calc.

public static double calc(PeerProfile profile) {
    double capacity;
    if (tooOld(profile)) {
        capacity = 1;
    } else {
        RateStat acceptStat = profile.getTunnelCreateResponseTime();
        RateStat rejectStat = profile.getTunnelHistory().getRejectionRate();
        RateStat failedStat = profile.getTunnelHistory().getFailedRate();
        double capacity10m = estimateCapacity(acceptStat, rejectStat, failedStat, 10 * 60 * 1000);
        // if we actively know they're bad, who cares if they used to be good?
        if (capacity10m <= 0) {
            capacity = 0;
        } else {
            double capacity30m = estimateCapacity(acceptStat, rejectStat, failedStat, 30 * 60 * 1000);
            double capacity60m = estimateCapacity(acceptStat, rejectStat, failedStat, 60 * 60 * 1000);
            double capacity1d = estimateCapacity(acceptStat, rejectStat, failedStat, 24 * 60 * 60 * 1000);
            capacity = capacity10m * periodWeight(10 * 60 * 1000) + capacity30m * periodWeight(30 * 60 * 1000) + capacity60m * periodWeight(60 * 60 * 1000) + capacity1d * periodWeight(24 * 60 * 60 * 1000);
        }
    }
    // now take into account non-rejection tunnel rejections (which haven't
    // incremented the rejection counter, since they were only temporary)
    RouterContext context = profile.getContext();
    long now = context.clock().now();
    if (profile.getTunnelHistory().getLastRejectedTransient() > now - 5 * 60 * 1000)
        capacity = 1;
    else if (profile.getTunnelHistory().getLastRejectedProbabalistic() > now - 5 * 60 * 1000)
        capacity -= context.random().nextInt(5);
    // boost new profiles
    if (now - profile.getFirstHeardAbout() < 45 * 60 * 1000)
        capacity += BONUS_NEW;
    // boost connected peers
    if (profile.isEstablished())
        capacity += BONUS_ESTABLISHED;
    // boost same country
    if (profile.isSameCountry()) {
        double bonus = BONUS_SAME_COUNTRY;
        String b = context.getProperty(PROP_COUNTRY_BONUS);
        if (b != null) {
            try {
                bonus = Double.parseDouble(b);
            } catch (NumberFormatException nfe) {
            }
        }
        capacity += bonus;
    }
    // penalize unreachable peers
    if (profile.wasUnreachable())
        capacity -= PENALTY_UNREACHABLE;
    // credit non-floodfill to reduce conn limit issues at floodfills
    // TODO only if we aren't floodfill ourselves?
    RouterInfo ri = context.netDb().lookupRouterInfoLocally(profile.getPeer());
    if (!FloodfillNetworkDatabaseFacade.isFloodfill(ri))
        capacity += BONUS_NON_FLOODFILL;
    // a tiny tweak to break ties and encourage closeness, -.25 to +.25
    capacity -= profile.getXORDistance() * (BONUS_XOR / 128);
    capacity += profile.getCapacityBonus();
    if (capacity < 0)
        capacity = 0;
    return capacity;
}
Also used : RateStat(net.i2p.stat.RateStat) RouterInfo(net.i2p.data.router.RouterInfo) RouterContext(net.i2p.router.RouterContext)

Aggregations

RateStat (net.i2p.stat.RateStat)33 Rate (net.i2p.stat.Rate)24 Hash (net.i2p.data.Hash)5 RouterInfo (net.i2p.data.router.RouterInfo)5 RateAverages (net.i2p.stat.RateAverages)4 PeerProfile (net.i2p.router.peermanager.PeerProfile)3 ArrayList (java.util.ArrayList)2 RouterContext (net.i2p.router.RouterContext)2 StatManager (net.i2p.stat.StatManager)2 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1 RouterAddress (net.i2p.data.router.RouterAddress)1 CommSystemFacade (net.i2p.router.CommSystemFacade)1 TunnelInfo (net.i2p.router.TunnelInfo)1 DBHistory (net.i2p.router.peermanager.DBHistory)1 HopConfig (net.i2p.router.tunnel.HopConfig)1 TunnelPool (net.i2p.router.tunnel.pool.TunnelPool)1