git ssb

3+

Dominic / ssb-blobs



Commit 700c1d2490d63e431172a50642c254236b979d81

settings for defaults

Dominic Tarr committed on 4/7/2017, 2:29:12 AM
Parent: 6eb9a973795973b683f7fc873dd316713e5c643c

Files changed

inject.jschanged
inject.jsView
@@ -15,9 +15,8 @@
1515 var isBlobId = require('ssb-ref').isBlob
1616
1717 var MB = 1024*1024
1818 var MAX_SIZE = 5*MB
19-var MIN_PUSH_PEERS = 3
2019 function noop () {}
2120
2221 function clone (obj) {
2322 var o = {}
@@ -25,10 +24,22 @@
2524 o[k] = obj[k]
2625 return o
2726 }
2827
28 +function count(obj) {
29 + var c = 0
30 + for(var k in obj) c++
31 + return c
32 +}
33 +
2934 module.exports = function inject (blobs, set, name, opts) {
3035 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 +
3142 var notify = Notify()
3243 var pushed = Notify()
3344
3445 var peers = {}
@@ -72,8 +83,9 @@
7283 }))
7384 }
7485
7586 function wants (peer, id, hops) {
87 + if(Math.abs(hops) < sympathy) return //sorry!
7688 if(!want[id] || want[id] < hops) {
7789 want[id] = hops
7890 queue(id, hops)
7991 if(peer = isAvailable(id)) {
@@ -101,9 +113,9 @@
101113 //mark this peer has it.
102114 //if N peers have it, we can stop broadcasting.
103115 if(push[id]) {
104116 push[id][peer_id] = size
105- if(Object.keys(push[id]).length >= MIN_PUSH_PEERS) {
117 + if(count(push[id]) >= pushy) {
106118 var data = {key: id, peers: push[id]}
107119 set.remove(id)
108120 delete push[id]; pushed(data)
109121 }
@@ -318,5 +330,4 @@
318330 }
319331 }
320332
321333
322-

Built with git-ssb-web