git ssb

4+

Dominic / scuttlebot



Commit 3f99bb4d8aafc51133acb53c3ff0b7d52f71aa1a

move friends and block plugin out into a module

Dominic Tarr committed on 5/31/2017, 9:57:54 PM
Parent: 862bba47be153d8955724bcb5e6b29a18d6ca29b

Files changed

test/block.jschanged
test/block2.jschanged
test/block3.jschanged
test/caps.jschanged
test/friends.jschanged
test/gossip.jschanged
test/invite.jschanged
test/random.jschanged
test/realtime.jschanged
test/server.jschanged
test/block.jsView
@@ -4,10 +4,9 @@
44 var ssbKeys = require('ssb-keys')
55 var u = require('./util')
66
77 var createSbot = require('../')
8- .use(require('../plugins/friends'))
9- .use(require('../plugins/block'))
8+ .use(require('ssb-friends'))
109 .use(require('../plugins/replicate'))
1110
1211 var toAddress = require('../lib/util').toAddress
1312
@@ -41,15 +40,25 @@
4140 temp: 'test-block-carol', timeout: 600,
4241 keys:ssbKeys.generate()
4342 })
4443
44+//carol.post(function (data) {
45+// console.log('CAROL RECEIVED', names[data.value.author])
46+// console.log(data.value)
47+//})
48+
49+var names = {}
50+names[alice.id] = 'alice'
51+names[bob.id] = 'bob'
52+names[carol.id] = 'carol'
53+
4554 tape('alice blocks bob, and bob cannot connect to alice', function (t) {
4655
47- console.log({
48- alice: alice.id,
49- bob: bob.id,
50- carol: carol.id
51- })
56+// console.log({
57+// alice: alice.id,
58+// bob: bob.id,
59+// carol: carol.id
60+// })
5261
5362 //in the beginning alice and bob follow each other
5463 cont.para([
5564 cont(alice.publish)(u.follow(bob.id)),
@@ -90,8 +99,9 @@
9099 aliceCancel(); bobCancel()
91100 console.log('ALICE BLOCKS BOB', {
92101 source: alice.id, dest: bob.id
93102 })
103+
94104 alice.publish(u.block(bob.id))
95105 (function (err) {
96106 if(err) throw err
97107
@@ -118,9 +128,9 @@
118128 bob.connect(alice.getAddress(), function (err, rpc) {
119129 t.ok(err, 'bob is blocked, should fail to connect to alice')
120130
121131
122- carol.post(function (msg) {
132+ var carolCancel = carol.post(function (msg) {
123133 console.log('CAROL RECV', msg, alice.id)
124134 if(msg.author === alice.id) {
125135 if(msg.sequence == 2)
126136 t.end()
@@ -131,8 +141,9 @@
131141 carol.connect(alice.getAddress(), function (err, rpc) {
132142 if(err) throw err
133143 console.log('CAROL CONNECTED TO ALICE', carol.id, alice.id)
134144 rpc.on('closed', function () {
145+ carolCancel()
135146 pull(
136147 carol.createHistoryStream({id: alice.id, seq: 0, live: false}),
137148 pull.collect(function (err, ary) {
138149 if(err) throw err
@@ -160,15 +171,79 @@
160171 bob.once('replicate:finish', function (vclock) {
161172 console.log('BOB REPLICATED FROM CAROL')
162173 t.equal(vclock[alice.id], 1)
163174 console.log('ALICE:', alice.id)
164- t.end()
175+ //t.end()
165176 })
166- bob.connect(carol.getAddress(), function(err) {
177+ bob.connect(carol.getAddress(), function(err, rpc) {
167178 if(err) throw err
179+ rpc.on('closed', function () {
180+ t.end()
181+ })
168182 })
169183 })
170184
185+
186+tape('alice does not replicate messages from bob, but carol does', function (t) {
187+
188+ var friends = 0
189+ carol.friends.get(console.log)
190+ pull(carol.friends.createFriendStream({meta: true, live: true}), pull.drain(function (v) {
191+ friends ++
192+ console.log('************', v)
193+ }))
194+
195+ cont.para([
196+ cont(alice.publish)(u.follow(carol.id)),
197+ cont(bob.publish)({type:'post', text: 'hello'}),
198+ cont(carol.publish)(u.follow(bob.id))
199+ ]) (function () {
200+ var recv = {alice: 0, carol: 0}
201+
202+ carol.post(function (msg) {
203+ recv.carol ++
204+ //will receive one message from bob and carol
205+ }, false)
206+
207+ alice.post(function (msg) {
208+ recv.alice ++
209+ //alice will only receive the message from carol, but not bob.
210+ console.log("ALICE_RECV", names[msg.value.author], msg)
211+ t.equal(msg.value.author, carol.id)
212+ }, false)
213+
214+ console.log("carol's friends")
215+ carol.friends.get(function (err, g) {
216+ t.ok(g[carol.id][bob.id])
217+ })
218+ console.log("alices friends")
219+ alice.friends.get(console.log)
220+
221+
222+ var n = 2
223+ carol.connect(alice.getAddress(), cb)
224+ carol.connect(bob.getAddress(), cb)
225+
226+ function cb (err, rpc) {
227+ if(err) throw err
228+ rpc.on('closed', next)
229+ }
230+ function next () {
231+ if(--n) return
232+ pull(
233+ carol.createLogStream(),
234+ pull.collect(function (err, ary) {
235+ if(err) throw err
236+ console.log(ary)
237+ t.deepEqual(recv, {carol: 2, alice: 2})
238+ t.equal(friends, 3, "carol's createFriendStream has 3 peers")
239+ t.end()
240+ })
241+ )
242+ }
243+ })
244+})
245+
171246 //TODO test that bob is disconnected from alice if he is connected
172247 // and she blocks him.
173248
174249 //TODO test that blocks work in realtime. if alice blocks him
@@ -181,5 +256,4 @@
181256
182257
183258
184259
185-
test/block2.jsView
@@ -4,11 +4,10 @@
44 var ssbKeys = require('ssb-keys')
55 var u = require('./util')
66
77 var createSbot = require('../')
8- .use(require('../plugins/friends'))
8+ .use(require('ssb-friends'))
99 .use(require('../plugins/replicate'))
10- .use(require('../plugins/block'))
1110
1211 var alice = createSbot({
1312 temp: 'test-block-alice', //timeout: 1400,
1413 keys: ssbKeys.generate()
@@ -57,4 +56,5 @@
5756
5857 })
5958 })
6059
60+
test/block3.jsView
@@ -3,10 +3,9 @@
33 var pull = require('pull-stream')
44 var u = require('./util')
55
66 var replicate = require('../plugins/replicate')
7-var friends = require('../plugins/friends')
8-var block = require('../plugins/block')
7+var friends = require('ssb-friends')
98 var ssbKeys = require('ssb-keys')
109 var toAddress = require('../lib/util').toAddress
1110
1211
@@ -18,11 +17,10 @@
1817 // 2. alice never tries to connect to bob. (removed from peers)
1918 // 3. carol will not give bob any, she will not give him any data from alice.
2019
2120 var createSbot = require('../')
22- .use(require('../plugins/friends'))
21+ .use(require('ssb-friends'))
2322 .use(require('../plugins/replicate'))
24- .use(require('../plugins/block'))
2523
2624 var alice = createSbot({
2725 temp: 'test-block-alice', timeout: 1000,
2826 keys: ssbKeys.generate()
@@ -81,4 +79,6 @@
8179 }, false)
8280 })
8381 })
8482
83+
84+
test/caps.jsView
@@ -11,9 +11,9 @@
1111 // give them all pub servers (on localhost)
1212 // and get them to follow each other...
1313
1414 var createSbot = require('../')
15- .use(require('../plugins/friends'))
15+ .use(require('ssb-friends'))
1616 .use(require('../plugins/replicate'))
1717 .use(require('../plugins/gossip'))
1818 .use(require('../plugins/logging'))
1919
test/friends.jsView
@@ -10,9 +10,9 @@
1010 // add some of friend edges (follow, flag)
1111 // make sure the friends plugin analyzes correctly
1212
1313 var createSbot = require('../')
14- .use(require('../plugins/friends'))
14+ .use(require('ssb-friends'))
1515
1616
1717 function sort (ary) {
1818 return ary.sort(function (a, b) {
test/gossip.jsView
@@ -8,9 +8,9 @@
88 var u = require('./util')
99 var isArray = Array.isArray
1010
1111 var createSbot = require('../')
12- .use(require('../plugins/friends'))
12+ .use(require('ssb-friends'))
1313 .use(require('../plugins/gossip'))
1414 // .use(require('../plugins/logging'))
1515
1616
test/invite.jsView
@@ -9,9 +9,9 @@
99
1010 var createSbot = require('../')
1111 .use(require('../plugins/master'))
1212 .use(require('../plugins/invite'))
13- .use(require('../plugins/friends'))
13+ .use(require('ssb-friends'))
1414 .use(require('ssb-ws'))
1515
1616 function all(stream, cb) {
1717 return pull(stream, pull.collect(cb))
test/random.jsView
@@ -36,9 +36,9 @@
3636 }
3737 }
3838
3939 var createSbot = require('../')
40- .use(require('../plugins/friends'))
40+ .use(require('ssb-friends'))
4141 .use(require('../plugins/replicate'))
4242 .use(require('../plugins/gossip'))
4343
4444 function generateAnimals (sbot, feed, f, n, cb) {
test/realtime.jsView
@@ -6,12 +6,10 @@
66
77 var ssbKeys = require('ssb-keys')
88
99 var createSbot = require('../')
10- .use(require('../plugins/friends'))
10+ .use(require('ssb-friends'))
1111 .use(require('../plugins/replicate'))
12-// .use(require('../plugins/gossip'))
13-// .use(require('../plugins/logging'))
1412
1513 tape('replicate between 3 peers', function (t) {
1614
1715 var bob = createSbot({
@@ -69,4 +67,5 @@
6967 }, 200)
7068
7169 })
7270 })
71+
test/server.jsView
@@ -11,9 +11,9 @@
1111 // give them all pub servers (on localhost)
1212 // and get them to follow each other...
1313
1414 var createSbot = require('../')
15- .use(require('../plugins/friends'))
15+ .use(require('ssb-friends'))
1616 .use(require('../plugins/replicate'))
1717 .use(require('../plugins/gossip'))
1818 .use(require('../plugins/logging'))
1919

Built with git-ssb-web