Class UnchokerUtil


  • public class UnchokerUtil
    extends java.lang.Object
    Utility collection for unchokers.
    • Constructor Summary

      Constructors 
      Constructor Description
      UnchokerUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void doHighLatencyPeers​(java.util.ArrayList<PEPeer> peers_to_choke, java.util.ArrayList<PEPeer> peers_to_unchoke, boolean allow_snubbed)  
      static PEPeer getNextOptimisticPeer​(java.util.ArrayList<PEPeer> all_peers, boolean factor_reciprocated, boolean allow_snubbed)
      Choose the next peer, optimistically, that should be unchoked.
      static java.util.ArrayList<PEPeer> getNextOptimisticPeers​(java.util.ArrayList<PEPeer> all_peers, boolean factor_reciprocated, boolean allow_snubbed, int num_needed)  
      static boolean isUnchokable​(PEPeer peer, boolean allow_snubbed)
      Test whether or not the given peer is allowed to be unchoked.
      static void performChokes​(java.util.ArrayList<PEPeer> peers_to_choke, java.util.ArrayList<PEPeer> peers_to_unchoke)
      Send choke/unchoke messages to the given peers.
      static void performChokeUnchoke​(PEPeer to_choke, PEPeer to_unchoke)  
      static void updateLargestValueFirstSort​(long new_value, long[] values, PEPeer new_item, java.util.ArrayList items, int start_pos)
      Update (if necessary) the given list with the given value while maintaining a largest-value-first (as seen so far) sort order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UnchokerUtil

        public UnchokerUtil()
    • Method Detail

      • isUnchokable

        public static boolean isUnchokable​(PEPeer peer,
                                           boolean allow_snubbed)
        Test whether or not the given peer is allowed to be unchoked.
        Parameters:
        peer - to test
        allow_snubbed - if true, ignore snubbed state
        Returns:
        true if peer is allowed to be unchoked, false if not
      • updateLargestValueFirstSort

        public static void updateLargestValueFirstSort​(long new_value,
                                                       long[] values,
                                                       PEPeer new_item,
                                                       java.util.ArrayList items,
                                                       int start_pos)
        Update (if necessary) the given list with the given value while maintaining a largest-value-first (as seen so far) sort order. NOTE: You will need to initialize the values array to Long.MIN_VALUE if you want to store negative values!
        Parameters:
        new_value - to use
        values - existing values array
        new_item - to insert
        items - existing items
        start_pos - index at which to start compare
      • getNextOptimisticPeer

        public static PEPeer getNextOptimisticPeer​(java.util.ArrayList<PEPeer> all_peers,
                                                   boolean factor_reciprocated,
                                                   boolean allow_snubbed)
        Choose the next peer, optimistically, that should be unchoked.
        Parameters:
        all_peers - list of peer to choose from
        factor_reciprocated - if true, factor in how much (if any) this peer has reciprocated when choosing
        allow_snubbed - allow the picking of snubbed-state peers as last resort
        Returns:
        the next peer to optimistically unchoke, or null if there are no peers available
      • getNextOptimisticPeers

        public static java.util.ArrayList<PEPeer> getNextOptimisticPeers​(java.util.ArrayList<PEPeer> all_peers,
                                                                         boolean factor_reciprocated,
                                                                         boolean allow_snubbed,
                                                                         int num_needed)
      • performChokes

        public static void performChokes​(java.util.ArrayList<PEPeer> peers_to_choke,
                                         java.util.ArrayList<PEPeer> peers_to_unchoke)
        Send choke/unchoke messages to the given peers.
        Parameters:
        peers_to_choke -
        peers_to_unchoke -
      • performChokeUnchoke

        public static void performChokeUnchoke​(PEPeer to_choke,
                                               PEPeer to_unchoke)
      • doHighLatencyPeers

        public static void doHighLatencyPeers​(java.util.ArrayList<PEPeer> peers_to_choke,
                                              java.util.ArrayList<PEPeer> peers_to_unchoke,
                                              boolean allow_snubbed)