hyperdrive
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -170,2 +170,3 @@ var events = require('events') | ||
self.want.splice(remove[j], 1) | ||
self.emit('unwant', want.block) | ||
want.callback(null, null) | ||
@@ -210,2 +211,3 @@ } | ||
self.want.splice(remove[j], 1) | ||
self.emit('unwant', want.block) | ||
want.callback(null, data) | ||
@@ -212,0 +214,0 @@ } |
@@ -10,2 +10,3 @@ var protocol = require('./protocol') | ||
this.name = opts.name || 'unknown' | ||
this.prioritized = 0 | ||
this.drive = drive | ||
@@ -31,2 +32,12 @@ this.peers = [] | ||
subswarm.feed.on('want', function () { | ||
self.prioritized++ | ||
subswarm.fetch() | ||
}) | ||
subswarm.feed.on('unwant', function () { | ||
self.prioritized-- | ||
if (!self.prioritized) subswarm.fetch() | ||
}) | ||
subswarm.feed.on('put', function (block) { | ||
@@ -60,2 +71,5 @@ for (var i = 0; i < subswarm.peers.length; i++) { | ||
function chooseBlock (peer) { | ||
// TODO: maintain a bitfield of perswarm blocks in progress | ||
// so we wont fetch the same data from multiple peers | ||
var len = peer.remoteBitfield.buffer.length * 8 | ||
@@ -73,3 +87,8 @@ var block = -1 | ||
var offset = (Math.random() * len) | 0 | ||
// TODO: there might be a starvation convern here. should only return *if* there are peers that | ||
// that could satisfy the want list. this is just a quick "hack" for realtime prioritization | ||
// when dealing with multiple files | ||
if (self.prioritized && !subswarm.feed.want.length) return -1 | ||
var offset = subswarm.feed.want.length ? subswarm.feed.want[0].block : ((Math.random() * len) | 0) | ||
for (var i = 0; i < len; i++) { | ||
@@ -79,2 +98,3 @@ block = (offset + i) % len | ||
if (peer.remoteBitfield.get(block) && !subswarm.feed.bitfield.get(block)) { | ||
debug('[%s] choosing unprioritized block #%d', self.name, block) | ||
return block | ||
@@ -81,0 +101,0 @@ } |
{ | ||
"name": "hyperdrive", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "A file sharing network based on rabin file chunking and append only feeds of data verified by merkle trees.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45234
2396
1288
17
0