|
| 1 | +var protocol = require('./') |
| 2 | + |
| 3 | +var p1 = protocol({ |
| 4 | + id: Buffer('max'), |
| 5 | + join: function (id, cb) { |
| 6 | + cb(null, Buffer('deadbeefdeadbeefdeadbeefdeadbeef')) |
| 7 | + } |
| 8 | +}) |
| 9 | + |
| 10 | +var p2 = protocol({ |
| 11 | + id: Buffer('mathias'), |
| 12 | + join: function (id, cb) { |
| 13 | + cb(null, Buffer('deadbeefdeadbeefdeadbeefdeadbeef')) |
| 14 | + } |
| 15 | +}) |
| 16 | + |
| 17 | +p1.on('handshake', function () { |
| 18 | + console.log('got handshake, remote peer:', p1.remoteId) |
| 19 | +}) |
| 20 | + |
| 21 | +p1.on('channel', function (key, channel) { |
| 22 | + channel.on('request', function (block) { |
| 23 | + console.log('remote requests:', block) |
| 24 | + channel.response(block, Buffer('hello')) |
| 25 | + }) |
| 26 | +}) |
| 27 | + |
| 28 | +p2.on('channel', function (key, channel) { |
| 29 | + channel.request(1) |
| 30 | + channel.request(2) |
| 31 | + channel.on('response', function (block, data, proof) { |
| 32 | + console.log('got response:', block, data, proof) |
| 33 | + }) |
| 34 | +}) |
| 35 | + |
| 36 | +p1.pipe(p2).pipe(p1) |
| 37 | + |
| 38 | +var ch = p1.join(Buffer('deadbeefdeadbeefdeadbeefdeadbeef')) |
| 39 | + |
| 40 | +ch.on('open', function () { |
| 41 | + console.log('remote opened...') |
| 42 | +}) |
0 commit comments