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 all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -251,14 +251,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 +304,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.