public class PeerProfile extends Object
| Constructor and Description |
|---|
PeerProfile(RouterContext context,
Hash peer)Caller should call setLastHeardAbout() and setFirstHeardAbout() |
| Modifier and Type | Method and Description |
|---|---|
void | clearLossy()Clear the loss demotion flag after the peer has been re-admitted. |
(package private) void | coalesceOnly(boolean shouldDecay)Caller must next call updateValues(). |
void | coalesceStats()Coalesce all stats and update values |
(package private) void | dataPushed(int size)Record data pushed through this peer. |
(package private) void | dataPushed1m(int size)The tunnel pushed that much data in a 1 minute period. |
boolean | equals(Object obj) |
void | expandDBProfile()For floodfills |
void | expandProfile()When the given peer is performing well enough that we want to keep detailed
stats on them again, call this to set up the info we dropped during shrinkProfile. |
int | getCapacityBonus()Extra factor added to the capacity ranking - this can be updated in the profile
written to disk to affect how the algorithm ranks capacity. |
(package private) long | getCapacityBonusLastUpdate()The timestamp of the last capacity bonus update. |
(package private) int | getCapacityBonusRaw()The raw capacity bonus value. |
float | getCapacityValue()How many tunnels do we think this peer can handle over the next hour? |
(package private) RouterContext | getContext()Helper for calculators. |
DBHistory | getDBHistory()History of DB activity with the peer. |
RateStat | getDbIntroduction()How many new peers we get from dbSearchReplyMessages or dbStore messages. |
RateStat | getDbResponseTime()How long it takes to get a DB response from the peer (in milliseconds). |
long | getFirstHeardAbout()When did we first hear about this peer? |
int | getIntegrationBonus()Extra factor added to the integration ranking - this can be updated in the profile
written to disk to affect how the algorithm ranks integration. |
float | getIntegrationValue()How well integrated into the network is this peer (as measured by how much they've
told us that we didn't already know). |
boolean | getIsActive()Is this peer active at the moment (sending/receiving messages within the last
10 minutes) |
boolean | getIsActive(long now)Is this peer active at the moment (sending/receiving messages within the last 10 minutes) |
boolean | getIsActive(long period,
long now)Is this peer active at the moment (sending/receiving messages within the
given period?)
Also mark active if it is connected, as this will tend to encourage use
of already-connected peers. |
boolean | getIsExpanded()Whether the tunnel profile data has been allocated (RateStats, TunnelHistory). |
boolean | getIsExpandedDB()Whether the DB profile data has been allocated. |
long | getLastHeardAbout()When did we last hear about this peer? |
long | getLastHeardFrom()When did we last hear from the peer? |
long | getLastSendFailed()When did we last have a problem sending to this peer? |
long | getLastSendSuccessful()When did we last send to this peer successfully? |
long | getLastTestedSuccessfully()When the peer last passed a tunnel test successfully. |
long | getLastTestStarted()The timestamp of the last test start. |
(package private) long | getLastThroughputUpdate()The timestamp of the last throughput update. |
float | getLossRatio()Packet-loss (retransmit) ratio reported by the transport, 0.0 = unknown/healthy. |
long | getLossRatioLastUpdate()When the loss ratio was last reported by the transport. |
float | getLossScore(long now)Decayed loss score, the maximum of all loss ratios reported within the
last few hours, with time-based decay (50% per hour since the last
report, capped at 4 hours). |
long | getLossySince()When the peer was last demoted from the fast/high-cap tiers for packet
loss, or 0 if it was never demoted. |
float | getPeakThroughputKBps()The peak throughput in KBps. |
float | getPeakTunnel1mThroughputKBps()This is the speed value |
float | getPeakTunnelThroughputKBps()The peak tunnel throughput in KBps. |
Hash | getPeer()What peer is being profiled |
float | getPeerTestTimeAverage()The average peer test time. |
int | getSpeedBonus()Retained for backward compatibility with stored profile data. |
(package private) long | getSpeedBonusLastUpdate()Last update time of the speed bonus, for the 4-hour expiry. |
float | getSpeedValue()How fast is the peer, taking into consideration both throughput and latency. |
double | getTunnelAcceptanceRatio()Tunnel acceptance ratio from tunnel history. |
RateStat | getTunnelCreateResponseTime()How long it takes to get a tunnel create response from the peer (in milliseconds). |
TunnelHistory | getTunnelHistory()History of tunnel activity with the peer. |
float | getTunnelTestTimeAverage()EWMA average of the tunnel test response time. |
(package private) long | getTunnelTestTimeAvgLastUpdate()Timestamp when the EWMA was last updated. |
(package private) int | getXORDistance()For now, just a one-byte comparison |
int | hashCode() |
boolean | hasTunnelHistory()Whether the peer has accepted or rejected at least one of our tunnel
build requests. |
(package private) boolean | isEstablished()Is this peer established? |
boolean | isLossy()Whether the peer is currently in loss probation. |
boolean | isLowLatency()Low latency flag, set when this peer has been observed to respond quickly
to tunnel build requests. |
(package private) boolean | isSameCountry()Is the peer in the same country as us? |
(package private) void | recalculateLowLatency()Recalculate the low-latency flag from the accumulated peer test time average. |
void | setCapacityBonus(int bonus)The capacity bonus. |
(package private) void | setCapacityBonusLastUpdate(long ts)The timestamp of the last capacity bonus update. |
void | setDBHistory(DBHistory hist)The DB history. |
(package private) void | setFirstHeardAbout(long when)Remember when we first heard about this peer, only if older. |
void | setIntegrationBonus(int bonus)The integration bonus. |
void | setLastHeardAbout(long when)Remember when we last heard about this peer, only if unset or newer. |
void | setLastHeardFrom(long when)When we last heard from the peer. |
void | setLastSendFailed(long when)When we last had a problem sending to this peer. |
void | setLastSendSuccessful(long when)When we last sent to this peer successfully. |
(package private) void | setLastTestStarted(long ts)Store the timestamp of the last test start. |
(package private) void | setLastThroughputUpdate(long ts)Store the timestamp of the last throughput update. |
void | setLossRatio(float ratio,
long now)Record the packet-loss ratio reported by the transport. |
void | setLossySince(long when)Set when the peer is demoted from the fast/high-cap tiers for packet
loss. |
void | setLowLatency(boolean low)The low latency flag. |
(package private) void | setPeakThroughputKBps(float kBps)Only for restoration from persisted profile. |
(package private) void | setPeakTunnel1mThroughputKBps(float kBps)Only for restoration from persisted profile. |
(package private) void | setPeakTunnelThroughputKBps(float kBps)Only for restoration from persisted profile. |
(package private) void | setPeerTestTimeAverage(float testAvg)Store the average peer test time. |
void | setSpeedBonus(int bonus)Retained for backward compatibility with stored profile data. |
(package private) void | setSpeedBonusLastUpdate(long ts)Last update time of the speed bonus, for the 4-hour expiry. |
void | setTunnelHistory(TunnelHistory history)The tunnel history. |
(package private) void | setTunnelTestTimeAverage(float avg)The tunnel test time average. |
(package private) void | setTunnelTestTimeAvgLastUpdate(long ts)The timestamp of the last tunnel test time average update. |
void | shrinkDBProfile()Shrink the DB-specific part of the profile. |
void | shrinkProfile()Shrink the profile by dropping the RateStat objects. |
String | toString() |
(package private) void | tunnelDataTransferred(long tunnelByteLifetime)The tunnel pushed that much data in its lifetime. |
(package private) void | updatePeerTestTimeAverage(float ms)Update peer test time average. |
(package private) void | updateTunnelTestTimeAverage(float ms)Update the tunnel test time average with a new measurement. |
void | updateValues()Update the speed, capacity, and integration values from the new values. |
boolean | wasUnreachable()Was the peer previously unreachable? |
public PeerProfile(RouterContext context, Hash peer)
context - the router contextpeer - non-nullpublic void clearLossy()
void coalesceOnly(boolean shouldDecay)
shouldDecay - whether to decay peak throughput valuespublic void coalesceStats()
void dataPushed(int size)
size - the number of bytes pushedvoid dataPushed1m(int size)
size - the number of bytes in that minutepublic void expandDBProfile()
public void expandProfile()
public int getCapacityBonus()
long getCapacityBonusLastUpdate()
int getCapacityBonusRaw()
public float getCapacityValue()
RouterContext getContext()
public DBHistory getDBHistory()
public RateStat getDbIntroduction()
public RateStat getDbResponseTime()
public long getFirstHeardAbout()
public int getIntegrationBonus()
public float getIntegrationValue()
public boolean getIsActive()
public boolean getIsActive(long now)
now - current timepublic boolean getIsActive(long period,
long now)period - must be one of the periods in the RateStat constructors below
(5*60*1000 or 60*60*1000)now - current timepublic boolean getIsExpanded()
public boolean getIsExpandedDB()
public long getLastHeardAbout()
public long getLastHeardFrom()
public long getLastSendFailed()
public long getLastSendSuccessful()
public long getLastTestedSuccessfully()
public long getLastTestStarted()
long getLastThroughputUpdate()
public float getLossRatio()
public long getLossRatioLastUpdate()
public float getLossScore(long now)
getLossRatio() this retains
loss memory when the transport stops reporting, so a demoted peer does
not look clean again merely because its last sample went stale.now - current time in mspublic long getLossySince()
public float getPeakThroughputKBps()
public float getPeakTunnel1mThroughputKBps()
public float getPeakTunnelThroughputKBps()
public Hash getPeer()
public float getPeerTestTimeAverage()
public int getSpeedBonus()
long getSpeedBonusLastUpdate()
public float getSpeedValue()
public double getTunnelAcceptanceRatio()
public RateStat getTunnelCreateResponseTime()
public TunnelHistory getTunnelHistory()
public float getTunnelTestTimeAverage()
long getTunnelTestTimeAvgLastUpdate()
int getXORDistance()
public boolean hasTunnelHistory()
boolean isEstablished()
public boolean isLossy()
public boolean isLowLatency()
boolean isSameCountry()
void recalculateLowLatency()
public void setCapacityBonus(int bonus)
bonus - the capacity bonusvoid setCapacityBonusLastUpdate(long ts)
ts - the timestamppublic void setDBHistory(DBHistory hist)
hist - the DBHistoryvoid setFirstHeardAbout(long when)
when - the time to setpublic void setIntegrationBonus(int bonus)
bonus - the integration bonuspublic void setLastHeardAbout(long when)
when - the time to setpublic void setLastHeardFrom(long when)
when - the timestamppublic void setLastSendFailed(long when)
when - the timestamppublic void setLastSendSuccessful(long when)
when - the timestampvoid setLastTestStarted(long ts)
ts - the timestampvoid setLastThroughputUpdate(long ts)
ts - the timestamppublic void setLossRatio(float ratio,
long now)The reported ratio is folded into the decayed loss score (see
getLossScore(long)) so a single clean report does not erase
recent loss history — the score only declines with time.
ratio - retransmitted / transmitted packets, 0.0 = healthynow - time in mspublic void setLossySince(long when)
when - demotion time in mspublic void setLowLatency(boolean low)
low - true for low latencyvoid setPeakThroughputKBps(float kBps)
kBps - the peak throughput in KBpsvoid setPeakTunnel1mThroughputKBps(float kBps)
kBps - the peak 1-minute throughput in KBpsvoid setPeakTunnelThroughputKBps(float kBps)
kBps - the peak tunnel throughput in KBpsvoid setPeerTestTimeAverage(float testAvg)
testAvg - the peer test time averagepublic void setSpeedBonus(int bonus)
bonus - the speed bonusvoid setSpeedBonusLastUpdate(long ts)
ts - the last update timepublic void setTunnelHistory(TunnelHistory history)
history - the TunnelHistoryvoid setTunnelTestTimeAverage(float avg)
avg - the average in msvoid setTunnelTestTimeAvgLastUpdate(long ts)
ts - the timestamppublic void shrinkDBProfile()
public void shrinkProfile()
void tunnelDataTransferred(long tunnelByteLifetime)
tunnelByteLifetime - total bytes transferredvoid updatePeerTestTimeAverage(float ms)
ms - the new measurement in msvoid updateTunnelTestTimeAverage(float ms)
ms - the new measurement in mspublic void updateValues()
public boolean wasUnreachable()