Class: QuartzTorrent::Extension

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_torrent/extension.rb

Overview

This class contains constants that represent our numbering of the Bittorrent peer-protocol extensions we support. It also has some utility methods related to extensions.

Constant Summary collapse

MetadataExtensionId =

The metadata extension (BEP 9)

1

Class Method Summary collapse

Class Method Details

.createExtendedHandshake(info) ⇒ Object

Create an ExtendedHandshake object based on the passed Torrent metadata info struct.

Parameters:

  • info

    The torrent metadata info struct. It is used to determine the size to send when negotiating the metadata extension.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/quartz_torrent/extension.rb', line 13

def self.createExtendedHandshake(info)
  msg = ExtendedHandshake.new
  
  extensionIds = {
    'ut_metadata' => MetadataExtensionId
  }

  msg.dict['m'] = extensionIds

  if info
    msg.dict['metadata_size'] = info.bencode.length
  else
    msg.dict['metadata_size'] = 0
  end

  msg
end

.peerMsgClassForExtensionName(info) ⇒ Object

Get the class to use to serialize and unserialize the specified Bittorent extension. Returns nil if we don’t support that extension.

Parameters:

  • info

    The name of a bittorrent extension as specified in the BEP, for example ‘ut_metadata’.



33
34
35
36
37
38
39
# File 'lib/quartz_torrent/extension.rb', line 33

def self.peerMsgClassForExtensionName(info)
  if info == 'ut_metadata'
    ExtendedMetaInfo
  else
    nil
  end
end