net.i2p.router.peermanager

## Class PeerProfile

- java.lang.Object
- - net.i2p.router.peermanager.PeerProfile

-     public class PeerProfile
      extends Object

  Copied from http://www.i2p2.i2p/how_peerselection.html See also main() below for additional commentary by zzz. Currently, there is no 'ejection' strategy to get rid of the profiles for peers that are no longer active (or when the network consists of thousands of peers, to get rid of peers that are performing poorly). However, the size of each profile is fairly small, and is unrelated to how much data is collected about the peer, so that a router can keep a few thousand active peer profiles before the overhead becomes a serious concern. Once it becomes necessary, we can simply compact the poorly performing profiles (keeping only the most basic data) and maintain hundreds of thousands of profiles in memory. Beyond that size, we can simply eject the peers (e.g. keeping the best 100,000).

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PeerProfile(RouterContext context, Hash peer)`
    `PeerProfile(RouterContext context, Hash peer, boolean expand)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `coalesceStats()` update the stats and rates (this should be called once a minute)
    `(package private) void` | `dataPushed(int size)`
    `(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.
    `long` | `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.
    `double` | `getCapacityValue()` How many tunnels do we think this peer can handle over the next hour?
    `DBHistory` | `getDBHistory()` history of db activity with the peer Warning - may return null if !getIsExpandedDB()
    `RateStat` | `getDbIntroduction()` how many new peers we get from dbSearchReplyMessages or dbStore messages, calculated over a 1 hour, 1 day, and 1 week period Warning - may return null if !getIsExpandedDB()
    `RateStat` | `getDbResponseTime()` how long it takes to get a db response from the peer (in milliseconds), calculated over a 1 minute, 1 hour, and 1 day period Warning - may return null if !getIsExpandedDB()
    `long` | `getFirstHeardAbout()` When did we first hear about this peer? Currently unused, candidate for removal.
    `long` | `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.
    `double` | `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 5 minutes)
    `boolean` | `getIsActive(long period)` 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()` are we keeping an expanded profile on the peer, or just the bare minimum.
    `boolean` | `getIsExpandedDB()`
    `boolean` | `getIsFailing()` is this peer actively failing (aka not worth touching)? deprecated - unused - always false
    `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?
    `double` | `getPeakThroughputKBps()`
    `double` | `getPeakTunnel1mThroughputKBps()`
    `double` | `getPeakTunnelThroughputKBps()`
    `Hash` | `getPeer()` what peer is being profiled
    `long` | `getSpeedBonus()` extra factor added to the speed ranking - this can be updated in the profile written to disk to affect how the algorithm ranks speed.
    `double` | `getSpeedValue()` How fast is the peer, taking into consideration both throughput and latency.
    `RateStat` | `getTunnelCreateResponseTime()` how long it takes to get a tunnel create response from the peer (in milliseconds), calculated over a 1 minute, 1 hour, and 1 day period Warning - may return null if !getIsExpanded()
    `TunnelHistory` | `getTunnelHistory()` history of tunnel activity with the peer Warning - may return null if !getIsExpanded()
    `RateStat` | `getTunnelTestResponseTime()` how long it takes to successfully test a tunnel this peer participates in (in milliseconds), calculated over a 10 minute, 1 hour, and 1 day period Warning - may return null if !getIsExpanded()
    `double` | `getTunnelTestTimeAverage()`
    `int` | `hashCode()`
    `int` | `incrementShitlists()`
    `static void` | `main(String[] args)` New measurement is 12KB per expanded profile.
    `static void` | `main2(String[] args)` Read in all of the profiles specified and print out their calculated values.
    `void` | `setCapacityBonus(long bonus)`
    `void` | `setDBHistory(DBHistory hist)`
    `void` | `setFirstHeardAbout(long when)`
    `void` | `setIntegrationBonus(long bonus)`
    `(package private) void` | `setIsFailing(boolean val)` deprecated - unused - always false
    `void` | `setLastHeardAbout(long when)`
    `void` | `setLastHeardFrom(long when)`
    `void` | `setLastSendFailed(long when)`
    `void` | `setLastSendSuccessful(long when)`
    `void` | `setPeakThroughputKBps(double kBps)`
    `void` | `setPeakTunnel1mThroughputKBps(double kBps)`
    `void` | `setPeakTunnelThroughputKBps(double kBps)`
    `void` | `setSpeedBonus(long bonus)`
    `void` | `setTunnelHistory(TunnelHistory history)`
    `(package private) void` | `setTunnelTestTimeAverage(double avg)`
    `String` | `toString()`
    `(package private) void` | `tunnelDataTransferred(long tunnelByteLifetime)` the tunnel pushed that much data in its lifetime
    `void` | `unshitlist()`
    `(package private) void` | `updateTunnelTestTimeAverage(long ms)`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### PeerProfile

          public PeerProfile(RouterContext context,
                     Hash peer)

    - #### PeerProfile

          public PeerProfile(RouterContext context,
                     Hash peer,
                     boolean expand)

      Parameters:
        `expand` - must be true (see below)

  - ### Method Detail

    - #### getPeer

          public Hash getPeer()

      what peer is being profiled

    - #### getIsExpanded

          public boolean getIsExpanded()

      are we keeping an expanded profile on the peer, or just the bare minimum. If we aren't keeping the expanded profile, all of the rates as well as the TunnelHistory and DBHistory will not be available.

    - #### getIsExpandedDB

          public boolean getIsExpandedDB()

    - #### incrementShitlists

          public int incrementShitlists()

    - #### unshitlist

          public void unshitlist()

    - #### getIsActive

          public boolean getIsActive()

      Is this peer active at the moment (sending/receiving messages within the last 5 minutes)

    - #### getIsActive

          public boolean getIsActive(long period)

      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. Note: this appears to be the only use for these two RateStats. Update: Rewritten so we can get rid of the two RateStats. This also helps by not having it depend on coalesce boundaries.
      Parameters:
        `period` - must be one of the periods in the RateStat constructors below (5*60*1000 or 60*60*1000)

    - #### getFirstHeardAbout

          public long getFirstHeardAbout()

      When did we first hear about this peer? Currently unused, candidate for removal.

    - #### setFirstHeardAbout

          public void setFirstHeardAbout(long when)

    - #### getLastHeardAbout

          public long getLastHeardAbout()

      when did we last hear about this peer?

    - #### setLastHeardAbout

          public void setLastHeardAbout(long when)

    - #### getLastSendSuccessful

          public long getLastSendSuccessful()

      when did we last send to this peer successfully?

    - #### setLastSendSuccessful

          public void setLastSendSuccessful(long when)

    - #### getLastSendFailed

          public long getLastSendFailed()

      when did we last have a problem sending to this peer?

    - #### setLastSendFailed

          public void setLastSendFailed(long when)

    - #### getLastHeardFrom

          public long getLastHeardFrom()

      when did we last hear from the peer?

    - #### setLastHeardFrom

          public void setLastHeardFrom(long when)

    - #### getTunnelHistory

          public TunnelHistory getTunnelHistory()

      history of tunnel activity with the peer Warning - may return null if !getIsExpanded()

    - #### setTunnelHistory

          public void setTunnelHistory(TunnelHistory history)

    - #### getDBHistory

          public DBHistory getDBHistory()

      history of db activity with the peer Warning - may return null if !getIsExpandedDB()

    - #### setDBHistory

          public void setDBHistory(DBHistory hist)

    - #### getDbResponseTime

          public RateStat getDbResponseTime()

      how long it takes to get a db response from the peer (in milliseconds), calculated over a 1 minute, 1 hour, and 1 day period Warning - may return null if !getIsExpandedDB()

    - #### getTunnelCreateResponseTime

          public RateStat getTunnelCreateResponseTime()

      how long it takes to get a tunnel create response from the peer (in milliseconds), calculated over a 1 minute, 1 hour, and 1 day period Warning - may return null if !getIsExpanded()

    - #### getTunnelTestResponseTime

          public RateStat getTunnelTestResponseTime()

      how long it takes to successfully test a tunnel this peer participates in (in milliseconds), calculated over a 10 minute, 1 hour, and 1 day period Warning - may return null if !getIsExpanded()

    - #### getDbIntroduction

          public RateStat getDbIntroduction()

      how many new peers we get from dbSearchReplyMessages or dbStore messages, calculated over a 1 hour, 1 day, and 1 week period Warning - may return null if !getIsExpandedDB()

    - #### getSpeedBonus

          public long getSpeedBonus()

      extra factor added to the speed ranking - this can be updated in the profile written to disk to affect how the algorithm ranks speed. Negative values are penalties

    - #### setSpeedBonus

          public void setSpeedBonus(long bonus)

    - #### getCapacityBonus

          public long 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. Negative values are penalties

    - #### setCapacityBonus

          public void setCapacityBonus(long bonus)

    - #### getIntegrationBonus

          public long 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. Negative values are penalties

    - #### setIntegrationBonus

          public void setIntegrationBonus(long bonus)

    - #### getSpeedValue

          public double getSpeedValue()

      How fast is the peer, taking into consideration both throughput and latency. This may even be made to take into consideration current rates vs. estimated (or measured) max rates, allowing this speed to reflect the speed /available/.

    - #### getCapacityValue

          public double getCapacityValue()

      How many tunnels do we think this peer can handle over the next hour?

    - #### getIntegrationValue

          public double 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). Higher numbers means better integrated

    - #### getIsFailing

          public boolean getIsFailing()

      is this peer actively failing (aka not worth touching)? deprecated - unused - always false

    - #### getTunnelTestTimeAverage

          public double getTunnelTestTimeAverage()

    - #### setTunnelTestTimeAverage

          void setTunnelTestTimeAverage(double avg)

    - #### updateTunnelTestTimeAverage

          void updateTunnelTestTimeAverage(long ms)

    - #### getPeakThroughputKBps

          public double getPeakThroughputKBps()

    - #### setPeakThroughputKBps

          public void setPeakThroughputKBps(double kBps)

    - #### dataPushed

          void dataPushed(int size)

    - #### tunnelDataTransferred

          void tunnelDataTransferred(long tunnelByteLifetime)

      the tunnel pushed that much data in its lifetime

    - #### getPeakTunnelThroughputKBps

          public double getPeakTunnelThroughputKBps()

    - #### setPeakTunnelThroughputKBps

          public void setPeakTunnelThroughputKBps(double kBps)

    - #### dataPushed1m

          void dataPushed1m(int size)

      the tunnel pushed that much data in a 1 minute period

    - #### getPeakTunnel1mThroughputKBps

          public double getPeakTunnel1mThroughputKBps()

      Returns:
        the average of the three fastest one-minute data transfers, on a per-tunnel basis, through this peer. Ever. Except that the peak values are cut in half once a day by coalesceThroughput(). This seems way too seldom.

    - #### setPeakTunnel1mThroughputKBps

          public void setPeakTunnel1mThroughputKBps(double kBps)

    - #### expandProfile

          public 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. This will not however overwrite any existing data, so it can be safely called repeatedly

    - #### expandDBProfile

          public void expandDBProfile()

      For floodfills

    - #### coalesceStats

          public void coalesceStats()

      update the stats and rates (this should be called once a minute)

    - #### setIsFailing

          void setIsFailing(boolean val)

      deprecated - unused - always false

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### main

          public static void main(String[] args)

      New measurement is 12KB per expanded profile. (2009-03 zzz) And nowhere in the code is shrinkProfile() called so the size of compact profiles doesn't matter right now. This is far bigger than the NetDB entry, which is only about 1.5KB now that most of the stats have been removed. The biggest user in the profile is the Rates. (144 bytes per according to jhat). PeerProfile: 9 RateStats, 3-5 Rates each - 35 total DBHistory: 2 RateStats, 3 each - 6 total TunnelHistory: 4 RateStats, 5 each - 20 total --- --------- 15 61 total *60 bytes *144 bytes --- --------- 900 bytes 8784 bytes The RateStat itself is 32 bytes and the Rate[] is 28 so that adds about 1KB. So two obvious things to do are cut out some of the Rates, and call shrinkProfile(). Obsolete calculation follows: Calculate the memory consumption of profiles. Measured to be ~3739 bytes for an expanded profile, and ~212 bytes for a compacted one.

    - #### main2

          public static void main2(String[] args)

      Read in all of the profiles specified and print out their calculated values. Usage:

            PeerProfile [filename]*