class QuartzTorrent::TrackerPeer

Represents a peer returned by the tracker

Attributes

id[RW]

Peer Id. This may be nil.

ip[RW]

IP address, a string in dotted-quad notation

port[RW]

TCP port

Public Class Methods

new(ip, port, id = nil) click to toggle source
# File lib/quartz_torrent/trackerclient.rb, line 19
def initialize(ip, port, id = nil)
  if ip =~ /(\d+).(\d+).(\d+).(\d+)/
    @ip = ip
    @port = port
    @id = id
  
    @hash = $1.to_i << 24 + 
      $2.to_i << 16 + 
      $3.to_i << 8 +
      $4.to_i +
      port << 32

    @displayId = nil
    @displayId = id.gsub(/[\x80-\xff]/,'?') if id
  else
    raise "Invalid IP address #{ip}"
  end
end

Public Instance Methods

eql?(o) click to toggle source

Equate to another TrackerPeer.

# File lib/quartz_torrent/trackerclient.rb, line 44
def eql?(o)
  o.ip == @ip && o.port == @port
end
hash() click to toggle source

Hash code of this TrackerPeer.

# File lib/quartz_torrent/trackerclient.rb, line 39
def hash
  @hash
end
to_s() click to toggle source
# File lib/quartz_torrent/trackerclient.rb, line 55
def to_s
  "#{@displayId ? "["+@displayId+"] " : ""}#{ip}:#{port}"
end