class QuartzTorrent::ClassifiedPeers

This class is used to classift torrent peers by connection state.

Attributes

chokedInterestedPeers[RW]

Peers that we have an established connection to, and are choked but are interested.

chokedUninterestedPeers[RW]

Peers that we have an established connection to, and are choked and are not interested.

disconnectedPeers[RW]

Peers that are disconnected. Either they have never been connected to, or they were connected to and have been disconnected.

establishedPeers[RW]

Peers with an established connection. This is the union of chokedInterestedPeers, chokedUninterestedPeers, and unchokedPeers.

handshakingPeers[RW]

Peers still performing a handshake.

interestedPeers[RW]

Peers that we have an established connection to, and are interested

requestablePeers[RW]

Peers that we have an established connection to, that are not choking us, that we are interested in

unchokedInterestedPeers[RW]

Peers that we have an established connection to, and are not choked and are interested.

unchokedUninterestedPeers[RW]

Peers that we have an established connection to, and are not choked and are not interested.

uninterestedPeers[RW]

Peers that we have an established connection to, and are not interested

Public Class Methods

new(peers) click to toggle source

Pass a list of Peer objects for a specific torrent

# File lib/quartz_torrent/classifiedpeers.rb, line 5
def initialize(peers)
  # Classify peers by state
  @disconnectedPeers = []
  @handshakingPeers = []
  @establishedPeers = []
  @interestedPeers = []
  @uninterestedPeers = []
  @chokedInterestedPeers = []
  @chokedUninterestedPeers = []
  @unchokedInterestedPeers = []
  @unchokedUninterestedPeers = []
  @requestablePeers = []

  peers.each do |peer|

    # If we come across ourself, ignore it.
    next if peer.isUs

    if peer.state == :disconnected
      @disconnectedPeers.push peer
    elsif peer.state == :handshaking
      @handshakingPeers.push peer
    elsif peer.state == :established
      @establishedPeers.push peer
      if peer.peerChoked
        if peer.peerInterested
          @chokedInterestedPeers.push peer
          @interestedPeers.push peer
        else
          @chokedUninterestedPeers.push peer
          @uninterestedPeers.push peer
        end
      else
        if peer.peerInterested
          @unchokedInterestedPeers.push peer
          @interestedPeers.push peer
        else
          @unchokedUninterestedPeers.push peer
          @uninterestedPeers.push peer
        end
      end

      if !peer.amChoked
        @requestablePeers.push peer
      end
    end
  end
end

Public Instance Methods

to_s() click to toggle source
# File lib/quartz_torrent/classifiedpeers.rb, line 86
def to_s
  s = ""
  s << "  Choked and interested #{chokedInterestedPeers.inspect}"
  s << "  Choked and uninterested #{chokedUninterestedPeers.inspect}"
  s << "  Unchoked and interested #{unchokedInterestedPeers.inspect}"
  s << "  Unchoked and uninterested #{unchokedUninterestedPeers.inspect}"
  s  
end