Commit 3f99bb4d8aafc51133acb53c3ff0b7d52f71aa1a
move friends and block plugin out into a module
Dominic Tarr committed on 5/31/2017, 9:57:54 PMParent: 862bba47be153d8955724bcb5e6b29a18d6ca29b
Files changed
test/block.js | changed |
test/block2.js | changed |
test/block3.js | changed |
test/caps.js | changed |
test/friends.js | changed |
test/gossip.js | changed |
test/invite.js | changed |
test/random.js | changed |
test/realtime.js | changed |
test/server.js | changed |
test/block.js | ||
---|---|---|
@@ -4,10 +4,9 @@ | ||
4 | 4 | var ssbKeys = require('ssb-keys') |
5 | 5 | var u = require('./util') |
6 | 6 | |
7 | 7 | var createSbot = require('../') |
8 | - .use(require('../plugins/friends')) | |
9 | - .use(require('../plugins/block')) | |
8 | + .use(require('ssb-friends')) | |
10 | 9 | .use(require('../plugins/replicate')) |
11 | 10 | |
12 | 11 | var toAddress = require('../lib/util').toAddress |
13 | 12 | |
@@ -41,15 +40,25 @@ | ||
41 | 40 | temp: 'test-block-carol', timeout: 600, |
42 | 41 | keys:ssbKeys.generate() |
43 | 42 | }) |
44 | 43 | |
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 | + | |
45 | 54 | tape('alice blocks bob, and bob cannot connect to alice', function (t) { |
46 | 55 | |
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 | +// }) | |
52 | 61 | |
53 | 62 | //in the beginning alice and bob follow each other |
54 | 63 | cont.para([ |
55 | 64 | cont(alice.publish)(u.follow(bob.id)), |
@@ -90,8 +99,9 @@ | ||
90 | 99 | aliceCancel(); bobCancel() |
91 | 100 | console.log('ALICE BLOCKS BOB', { |
92 | 101 | source: alice.id, dest: bob.id |
93 | 102 | }) |
103 | + | |
94 | 104 | alice.publish(u.block(bob.id)) |
95 | 105 | (function (err) { |
96 | 106 | if(err) throw err |
97 | 107 | |
@@ -118,9 +128,9 @@ | ||
118 | 128 | bob.connect(alice.getAddress(), function (err, rpc) { |
119 | 129 | t.ok(err, 'bob is blocked, should fail to connect to alice') |
120 | 130 | |
121 | 131 | |
122 | - carol.post(function (msg) { | |
132 | + var carolCancel = carol.post(function (msg) { | |
123 | 133 | console.log('CAROL RECV', msg, alice.id) |
124 | 134 | if(msg.author === alice.id) { |
125 | 135 | if(msg.sequence == 2) |
126 | 136 | t.end() |
@@ -131,8 +141,9 @@ | ||
131 | 141 | carol.connect(alice.getAddress(), function (err, rpc) { |
132 | 142 | if(err) throw err |
133 | 143 | console.log('CAROL CONNECTED TO ALICE', carol.id, alice.id) |
134 | 144 | rpc.on('closed', function () { |
145 | + carolCancel() | |
135 | 146 | pull( |
136 | 147 | carol.createHistoryStream({id: alice.id, seq: 0, live: false}), |
137 | 148 | pull.collect(function (err, ary) { |
138 | 149 | if(err) throw err |
@@ -160,15 +171,79 @@ | ||
160 | 171 | bob.once('replicate:finish', function (vclock) { |
161 | 172 | console.log('BOB REPLICATED FROM CAROL') |
162 | 173 | t.equal(vclock[alice.id], 1) |
163 | 174 | console.log('ALICE:', alice.id) |
164 | - t.end() | |
175 | + //t.end() | |
165 | 176 | }) |
166 | - bob.connect(carol.getAddress(), function(err) { | |
177 | + bob.connect(carol.getAddress(), function(err, rpc) { | |
167 | 178 | if(err) throw err |
179 | + rpc.on('closed', function () { | |
180 | + t.end() | |
181 | + }) | |
168 | 182 | }) |
169 | 183 | }) |
170 | 184 | |
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 | + | |
171 | 246 | //TODO test that bob is disconnected from alice if he is connected |
172 | 247 | // and she blocks him. |
173 | 248 | |
174 | 249 | //TODO test that blocks work in realtime. if alice blocks him |
@@ -181,5 +256,4 @@ | ||
181 | 256 | |
182 | 257 | |
183 | 258 | |
184 | 259 | |
185 | - |
test/block2.js | ||
---|---|---|
@@ -4,11 +4,10 @@ | ||
4 | 4 | var ssbKeys = require('ssb-keys') |
5 | 5 | var u = require('./util') |
6 | 6 | |
7 | 7 | var createSbot = require('../') |
8 | - .use(require('../plugins/friends')) | |
8 | + .use(require('ssb-friends')) | |
9 | 9 | .use(require('../plugins/replicate')) |
10 | - .use(require('../plugins/block')) | |
11 | 10 | |
12 | 11 | var alice = createSbot({ |
13 | 12 | temp: 'test-block-alice', //timeout: 1400, |
14 | 13 | keys: ssbKeys.generate() |
@@ -57,4 +56,5 @@ | ||
57 | 56 | |
58 | 57 | }) |
59 | 58 | }) |
60 | 59 | |
60 | + |
test/block3.js | ||
---|---|---|
@@ -3,10 +3,9 @@ | ||
3 | 3 | var pull = require('pull-stream') |
4 | 4 | var u = require('./util') |
5 | 5 | |
6 | 6 | var replicate = require('../plugins/replicate') |
7 | -var friends = require('../plugins/friends') | |
8 | -var block = require('../plugins/block') | |
7 | +var friends = require('ssb-friends') | |
9 | 8 | var ssbKeys = require('ssb-keys') |
10 | 9 | var toAddress = require('../lib/util').toAddress |
11 | 10 | |
12 | 11 | |
@@ -18,11 +17,10 @@ | ||
18 | 17 | // 2. alice never tries to connect to bob. (removed from peers) |
19 | 18 | // 3. carol will not give bob any, she will not give him any data from alice. |
20 | 19 | |
21 | 20 | var createSbot = require('../') |
22 | - .use(require('../plugins/friends')) | |
21 | + .use(require('ssb-friends')) | |
23 | 22 | .use(require('../plugins/replicate')) |
24 | - .use(require('../plugins/block')) | |
25 | 23 | |
26 | 24 | var alice = createSbot({ |
27 | 25 | temp: 'test-block-alice', timeout: 1000, |
28 | 26 | keys: ssbKeys.generate() |
@@ -81,4 +79,6 @@ | ||
81 | 79 | }, false) |
82 | 80 | }) |
83 | 81 | }) |
84 | 82 | |
83 | + | |
84 | + |
test/caps.js | ||
---|---|---|
@@ -11,9 +11,9 @@ | ||
11 | 11 | // give them all pub servers (on localhost) |
12 | 12 | // and get them to follow each other... |
13 | 13 | |
14 | 14 | var createSbot = require('../') |
15 | - .use(require('../plugins/friends')) | |
15 | + .use(require('ssb-friends')) | |
16 | 16 | .use(require('../plugins/replicate')) |
17 | 17 | .use(require('../plugins/gossip')) |
18 | 18 | .use(require('../plugins/logging')) |
19 | 19 |
test/friends.js | ||
---|---|---|
@@ -10,9 +10,9 @@ | ||
10 | 10 | // add some of friend edges (follow, flag) |
11 | 11 | // make sure the friends plugin analyzes correctly |
12 | 12 | |
13 | 13 | var createSbot = require('../') |
14 | - .use(require('../plugins/friends')) | |
14 | + .use(require('ssb-friends')) | |
15 | 15 | |
16 | 16 | |
17 | 17 | function sort (ary) { |
18 | 18 | return ary.sort(function (a, b) { |
test/gossip.js | ||
---|---|---|
@@ -8,9 +8,9 @@ | ||
8 | 8 | var u = require('./util') |
9 | 9 | var isArray = Array.isArray |
10 | 10 | |
11 | 11 | var createSbot = require('../') |
12 | - .use(require('../plugins/friends')) | |
12 | + .use(require('ssb-friends')) | |
13 | 13 | .use(require('../plugins/gossip')) |
14 | 14 | // .use(require('../plugins/logging')) |
15 | 15 | |
16 | 16 |
test/invite.js | ||
---|---|---|
@@ -9,9 +9,9 @@ | ||
9 | 9 | |
10 | 10 | var createSbot = require('../') |
11 | 11 | .use(require('../plugins/master')) |
12 | 12 | .use(require('../plugins/invite')) |
13 | - .use(require('../plugins/friends')) | |
13 | + .use(require('ssb-friends')) | |
14 | 14 | .use(require('ssb-ws')) |
15 | 15 | |
16 | 16 | function all(stream, cb) { |
17 | 17 | return pull(stream, pull.collect(cb)) |
test/random.js | ||
---|---|---|
@@ -36,9 +36,9 @@ | ||
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | 39 | var createSbot = require('../') |
40 | - .use(require('../plugins/friends')) | |
40 | + .use(require('ssb-friends')) | |
41 | 41 | .use(require('../plugins/replicate')) |
42 | 42 | .use(require('../plugins/gossip')) |
43 | 43 | |
44 | 44 | function generateAnimals (sbot, feed, f, n, cb) { |
test/realtime.js | ||
---|---|---|
@@ -6,12 +6,10 @@ | ||
6 | 6 | |
7 | 7 | var ssbKeys = require('ssb-keys') |
8 | 8 | |
9 | 9 | var createSbot = require('../') |
10 | - .use(require('../plugins/friends')) | |
10 | + .use(require('ssb-friends')) | |
11 | 11 | .use(require('../plugins/replicate')) |
12 | -// .use(require('../plugins/gossip')) | |
13 | -// .use(require('../plugins/logging')) | |
14 | 12 | |
15 | 13 | tape('replicate between 3 peers', function (t) { |
16 | 14 | |
17 | 15 | var bob = createSbot({ |
@@ -69,4 +67,5 @@ | ||
69 | 67 | }, 200) |
70 | 68 | |
71 | 69 | }) |
72 | 70 | }) |
71 | + |
test/server.js | ||
---|---|---|
@@ -11,9 +11,9 @@ | ||
11 | 11 | // give them all pub servers (on localhost) |
12 | 12 | // and get them to follow each other... |
13 | 13 | |
14 | 14 | var createSbot = require('../') |
15 | - .use(require('../plugins/friends')) | |
15 | + .use(require('ssb-friends')) | |
16 | 16 | .use(require('../plugins/replicate')) |
17 | 17 | .use(require('../plugins/gossip')) |
18 | 18 | .use(require('../plugins/logging')) |
19 | 19 |
Built with git-ssb-web