From f31ca8e7aaf7836ffb62a04b7118e9a46a554307 Mon Sep 17 00:00:00 2001 From: OlaviSau Date: Fri, 24 Jul 2015 01:14:27 +0300 Subject: [PATCH 1/2] Some documentation for _onMetadata Writing documentation to understand webtorrent ^^ --- lib/torrent.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/lib/torrent.js b/lib/torrent.js index 48001ac2..5d934381 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1,3 +1,18 @@ +Skip to content +This repository +Search +Pull requests +Issues +Gist + @OlaviSau + Watch 395 + Unstar 4,992 + Fork 332 +feross/webtorrent + branch: master webtorrent/lib/torrent.js +@ferossfeross 7 days ago torrent.destroy() remove from client +7 contributors @feross @olalonde @OlaviSau @fisch0920 @devTristan @charlescharles @astro +RawBlameHistory 1149 lines (941 sloc) 32.428 kB module.exports = Torrent var addrToIPPort = require('addr-to-ip-port') // browser exclude @@ -251,14 +266,46 @@ Torrent.prototype._onSwarmListening = function () { /** * Called when the metadata is received. + * Does setup on torrent, if metadata is not already set. + * Sets: + * Torrent.metadata + * If the passed metadata is a decoded torrent file encodes + * the passed metadata into a torrent file + * otherwise uses the passed metadata + * {@link https://github.com/feross/parse-torrent} + * Torrent.parsedTorrent + * (note: parsedTorrent is synonym for decoded torrent file) + * If the passed metadata is already a decoded torrent file + * sets it as the parsedTorrent + * otherwise attempts to parse it + * {@link https://en.wikipedia.org/wiki/Torrent_file} + * Torrent.name + * Preliminary update to the name + * uses the torrent file's name property + * Torrent.discovery + * calls setTorrent + * Updates discovery module with full torrent metadata + * Torrent.rarityMap + * Creates a new RarityMap using the current swarm and parsedTorrent + * Torrent.storage + * If _storageImpl is default + * Creates a new Storage using parsedTorrent and self.opts + * otherwise + * uses the provided _storageImpl + * Torrent.storage.on + * Does setup on storage, setting event handlers for + * 'piece','file', 'done', 'select', 'deselect', 'critical' + * Torrent.files + * Gets all files from Torrent.storage and pushes them to Torrent.files + * + * */ Torrent.prototype._onMetadata = function (metadata) { var self = this if (self.metadata || self.destroyed) return debug('got metadata') - if (metadata && metadata.infoHash) { - // `metadata` is a parsed torrent (from parse-torrent module) + if (metadata.infoHash) { self.metadata = parseTorrent.toTorrentFile(metadata) self.parsedTorrent = metadata } else { @@ -272,10 +319,8 @@ Torrent.prototype._onMetadata = function (metadata) { self.parsedTorrent.announce = announce } - // update preliminary torrent name self.name = self.parsedTorrent.name - // update discovery module with full torrent metadata self.discovery.setTorrent(self.parsedTorrent) self.rarityMap = new RarityMap(self.swarm, self.parsedTorrent.pieces.length) From 95d0a649ed43516047031f76f71baa3332f001e3 Mon Sep 17 00:00:00 2001 From: OlaviSau Date: Fri, 24 Jul 2015 11:04:41 +0300 Subject: [PATCH 2/2] github --- lib/torrent.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/torrent.js b/lib/torrent.js index 5d934381..ee8dfb14 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1,18 +1,3 @@ -Skip to content -This repository -Search -Pull requests -Issues -Gist - @OlaviSau - Watch 395 - Unstar 4,992 - Fork 332 -feross/webtorrent - branch: master webtorrent/lib/torrent.js -@ferossfeross 7 days ago torrent.destroy() remove from client -7 contributors @feross @olalonde @OlaviSau @fisch0920 @devTristan @charlescharles @astro -RawBlameHistory 1149 lines (941 sloc) 32.428 kB module.exports = Torrent var addrToIPPort = require('addr-to-ip-port') // browser exclude