class

ActiveTorrent::Torrent

Inherits ActiveRecord::Base < ActionView::FormModel < Reference < Object

STI subclasses inherit the table name (explicit override or convention) from their model superclass (one level; deeper STI needs an explicit set_table_name). Intermediate abstract bases (ApplicationRecord) are not models — walk past them. STI shape: a non-abstract registered model superclass marks the class as single-table-inherited (abstract intermediates like ApplicationRecord do not).

Constants

METAINFO_PURPOSE = "torrent_metainfo"
SOURCE_SEEDBOX_ORIGIN = 1_i64
SOURCE_SERVER_BLOB = 0_i64

Значения ar_enum (Int64 в БД; геттеры/предикаты — Rails-семантика).

STATUS_DRAFT = 0_i64
STATUS_PUBLISHED = 1_i64
STATUS_RETIRED = 2_i64

Constructors

publish_blob!(blob : ActiveStorage::Blob, piece_length : Int32 = DEFAULT_PIECE_LENGTH) : Torrent

server_blob: файл есть на сервере (ActiveStorage::Blob) — режем на куски, хэшируем, создаём published-раздачу.

Source
publish_metainfo!(name : String, byte_size : Int64, piece_length : Int32, pieces : String | Bytes, content_type : String | Nil = nil, origin_seedbox : String | Nil = nil) : Torrent

seedbox_origin: хэши посчитаны на seedbox, файла на сервере нет (описание §3.2). pieces — hex или сырые байты.

Source

Class methods

find_signed(token : String) : Torrent | Nil
Source

Instance methods

blob

Блоб-источник (server_blob), nil в режиме seedbox_origin.

Source
magnet_uri(announce : String | Nil = nil) : String
Source
metainfo_bytes(announce : String | Nil, webseed_url : String | Nil = nil) : Bytes

.torrent собирается ИЗ МЕТАДАННЫХ (pieces в БД) — работает в обоих режимах, локальный файл не нужен (описание §5.3). webseed_url (url-list, BEP 19) передаёт приложение — оно знает свой маршрут отдачи; для seedbox_origin не передавать вовсе (сервер файла не имеет — описание §3.2). announce nil — webseed-only метаданные.

Source
piece_count
Source
pieces_bytes
Source
publish!
Source
retire!
Source
server_backed?

Файл есть на этом сервере? Управляет всем: webseed, last-resort, 503-контракт (описание §3, §8).

Source
to_signed_token

Подписанный токен metainfo (аналог blob signed_id; контроллер принимает GET /torrents/<token>/metainfo).

Source