Class: Torrenter::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/torrenter/tracker.rb,
lib/torrenter/tracker/udp_tracker.rb,
lib/torrenter/tracker/http_tracker.rb

Direct Known Subclasses

HTTPTracker, UDPTracker

Defined Under Namespace

Classes: HTTPTracker, UDPTracker

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



4
5
6
# File 'lib/torrenter/tracker/http_tracker.rb', line 4

def address
  @address
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/torrenter/tracker/http_tracker.rb', line 4

def response
  @response
end

Instance Method Details

#format_peers(peers) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/torrenter/tracker.rb', line 3

def format_peers(peers)
  pool = []
  peers.chars.each_slice(6) do |peer_data|
    ip = peer_data[0..3].join('').bytes.join('.')
    port = peer_data[4..5].join('').unpack("S>").first

    if !pool.find { |peer| peer.ip == ip }
      pool << Peer.new(ip, port, @params)
    end
  end

  return pool
end