Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some documentation for _onMetadata #385

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Some documentation for _onMetadata

Writing documentation to understand webtorrent ^^
  • Loading branch information
OlaviSau committed Jul 23, 2015
commit f31ca8e7aaf7836ffb62a04b7118e9a46a554307
@@ -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)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.