Commit 700c1d2490d63e431172a50642c254236b979d81
settings for defaults
Dominic Tarr committed on 4/7/2017, 2:29:12 AMParent: 6eb9a973795973b683f7fc873dd316713e5c643c
Files changed
inject.js | changed |
inject.js | ||
---|---|---|
@@ -15,9 +15,8 @@ | ||
15 | 15 … | var isBlobId = require('ssb-ref').isBlob |
16 | 16 … | |
17 | 17 … | var MB = 1024*1024 |
18 | 18 … | var MAX_SIZE = 5*MB |
19 | -var MIN_PUSH_PEERS = 3 | |
20 | 19 … | function noop () {} |
21 | 20 … | |
22 | 21 … | function clone (obj) { |
23 | 22 … | var o = {} |
@@ -25,10 +24,22 @@ | ||
25 | 24 … | o[k] = obj[k] |
26 | 25 … | return o |
27 | 26 … | } |
28 | 27 … | |
28 … | +function count(obj) { | |
29 … | + var c = 0 | |
30 … | + for(var k in obj) c++ | |
31 … | + return c | |
32 … | +} | |
33 … | + | |
29 | 34 … | module.exports = function inject (blobs, set, name, opts) { |
30 | 35 … | opts = opts || {} |
36 … | + //sympathy controls whether you'll replicate | |
37 … | + var sympathy = opts.sympathy == null ? 3 : opts.sympathy | 0 | |
38 … | + var stingy = opts.stingy === true | |
39 … | + var legacy = opts.legacy !== false | |
40 … | + var pushy = opts.pushy || 3 | |
41 … | + | |
31 | 42 … | var notify = Notify() |
32 | 43 … | var pushed = Notify() |
33 | 44 … | |
34 | 45 … | var peers = {} |
@@ -72,8 +83,9 @@ | ||
72 | 83 … | })) |
73 | 84 … | } |
74 | 85 … | |
75 | 86 … | function wants (peer, id, hops) { |
87 … | + if(Math.abs(hops) < sympathy) return //sorry! | |
76 | 88 … | if(!want[id] || want[id] < hops) { |
77 | 89 … | want[id] = hops |
78 | 90 … | queue(id, hops) |
79 | 91 … | if(peer = isAvailable(id)) { |
@@ -101,9 +113,9 @@ | ||
101 | 113 … | //mark this peer has it. |
102 | 114 … | //if N peers have it, we can stop broadcasting. |
103 | 115 … | if(push[id]) { |
104 | 116 … | push[id][peer_id] = size |
105 | - if(Object.keys(push[id]).length >= MIN_PUSH_PEERS) { | |
117 … | + if(count(push[id]) >= pushy) { | |
106 | 118 … | var data = {key: id, peers: push[id]} |
107 | 119 … | set.remove(id) |
108 | 120 … | delete push[id]; pushed(data) |
109 | 121 … | } |
@@ -318,5 +330,4 @@ | ||
318 | 330 … | } |
319 | 331 … | } |
320 | 332 … | |
321 | 333 … | |
322 | - |
Built with git-ssb-web