Class: Torckapi::Response::Announce

Inherits:
Base
  • Object
show all
Defined in:
lib/torckapi/response/announce.rb

Overview

Announce response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#info_hashString (readonly)

Returns 40-char hexadecimal string.

Returns:

  • (String)

    40-char hexadecimal string



17
18
19
# File 'lib/torckapi/response/announce.rb', line 17

def info_hash
  @info_hash
end

#leechersFixnum (readonly)

Returns number of leechers.

Returns:

  • (Fixnum)

    number of leechers



17
# File 'lib/torckapi/response/announce.rb', line 17

attr_reader :info_hash, :leechers, :peers, :seeders

#peersArray<IPAddr, Fixnum> (readonly)

Returns list of peers.

Returns:

  • (Array<IPAddr, Fixnum>)

    list of peers



17
# File 'lib/torckapi/response/announce.rb', line 17

attr_reader :info_hash, :leechers, :peers, :seeders

#seedersObject (readonly)

Returns the value of attribute seeders.



17
# File 'lib/torckapi/response/announce.rb', line 17

attr_reader :info_hash, :leechers, :peers, :seeders

Class Method Details

.from_http(info_hash, data) ⇒ Torckapi::Response::Announce

Construct response object from http response data

Parameters:

  • info_hash (String)

    40-char hexadecimal string

  • data (String)

    HTTP response data (bencoded)

Returns:

Raises:



32
33
34
35
# File 'lib/torckapi/response/announce.rb', line 32

def self.from_http info_hash, data
  bdecoded_data = bdecode_and_check data, 'peers'
  new info_hash, *bdecoded_data.values_at('incomplete', 'complete'), peers_from_compact(bdecoded_data['peers'])
end

.from_udp(info_hash, data) ⇒ Torckapi::Response::Announce

Construct response object from udp response data

Parameters:

  • info_hash (String)

    40-char hexadecimal string

  • data (String)

    UDP response data (omit action and transaction_id)

Returns:



23
24
25
# File 'lib/torckapi/response/announce.rb', line 23

def self.from_udp info_hash, data
  new info_hash, *data[4..11].unpack('L>2'), peers_from_compact(data[12..-1] || '')
end