Colored Coins Metadata Handler
Installation
$ npm i cc-metadata-handler
Initialize
var MetadataHandler = require('cc-metadata-handler')
var properties = {
tracker: {
udp: Boolean,
http: Boolean,
ws: Boolean,
hostname: String,
port: Number
}
client: {
torrentPort: Number,
dhtPort: Number,
maxPeers: Number,
tracker: false
},
folders: {
torrents: '/torrents',
data: '/data',
capSize: '80%',
retryTime: 10000,
autoWatchInterval: 60000,
ignores: []
}
}
var handler = new MetadataHandler(settings)
Fetch Metadata
Params:
- torrentHash - The torrent infoHash of the metadata.
- metadataSHA2 - The sha256 of the metadata json.
var torrentHash = '5add2b0ce8f7da372c856d4efe6b9b6e8584919e'
var metadataSHA2 = '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4'
handler.getMetadata(torrentHash, metadataSHA2, function (err, metadata) {
if (err) return console.error(err)
console.log(metadata)
})
You can also use this method together with an event listner like this:
handler.on('downloads/'+torrentHash, function (metadata) {
console.log(metadata)
})
handler.getMetadata(torrentHash, metadataSHA2, importent)
Add new Metadata
Params:
- metadata - A new metadata json we just created and we plan on sharing with other people.
handler.addMetadata(metadata, function (err, hashes) {
if (err) return console.error(err)
console.log(hashes.torrentHash)
console.log(hashes.sha2)
})
Share Metadata
Params:
- torrentHash - The torrent info hash of the metadata we want to share with other people
handler.on('uploads/'+torrentHash, function (peer) {
console.log(peer)
})
handler.shareMetadata(torrentHash, function (err) {
if (err) console.log(err)
})
Remove Metadata
Remove torrent from BitTorrent client. Destroy all torrent connections to peers, delete all saved data.
Params:
- torrentHash - The torrent info hash of the metadata we want to remove
handler.removeMetadata(torrentHash, function (err) {
if (err) throw err
console.log('successfully deleted torrent')
})
Other Events
handler.on('downloads', function (metadata) {
console.log(metadata)
})
handler.on('uploads', function (peer) {
console.log(peer.info)
console.log(peer.file)
})
handler.on('error', function (err) {
console.error(err)
})
Testing
$ cd /"module-path"/cc-metadata-handler
$ mocha
License
Apache-2.0