https://github.com/hackergrrl/ssb-exchange
Fully sync two secure-scuttlebutt databases over a duplex stream.
https://github.com/hackergrrl/ssb-exchange
Last synced: 6 months ago
JSON representation
Fully sync two secure-scuttlebutt databases over a duplex stream.
- Host: GitHub
- URL: https://github.com/hackergrrl/ssb-exchange
- Owner: hackergrrl
- Created: 2018-06-12T17:11:27.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-13T03:44:12.000Z (about 7 years ago)
- Last Synced: 2024-12-28T21:44:12.883Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 15
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ssb-exchange
> fully exchange two secure-scuttlebutt databases over a duplex stream
## Usage
```js
var replicate = require('ssb-exchange')
var path = require('path')
var pull = require('pull-stream')var alice = createDbAndFeed('alice')
var bob = createDbAndFeed('bob')alice.feed.add({ type: 'post', text: 'alice\'s First Post!' }, function (err, msg, hash) {
alice.feed.add({ type: 'post', text: 'alice\'s Second Post!' }, function (err, msg, hash) {
bob.feed.add({ type: 'post', text: 'bob\'s First Post!' }, function (err, msg, hash) {
sync()
})
})
})function sync () {
var r1 = replicate(alice.ssb, 'alice')
var r2 = replicate(bob.ssb, 'bob')r1.pipe(r2).pipe(r1)
r1.on('end', function () {
pull(
alice.ssb.createLogStream({keys: false, values: true}),
pull.drain(console.log)
)
})
}function createDbAndFeed (dir) {
var keys = require('ssb-keys').loadOrCreateSync(path.join(dir, 'secret'))
var ssb = require('secure-scuttlebutt/create')(path.join(dir, 'db'))
var feed = ssb.createFeed(keys)
return {ssb: ssb, feed: feed}
}
```outputs
```
{ previous: null,
sequence: 1,
author: '@6VKBcLTLgL8vDuLHtgFlYEg/yTgYqI1WoPENQrzJNs4=.ed25519',
timestamp: 1528823339650,
hash: 'sha256',
content: { type: 'post', text: 'alice\'s First Post!' },
signature: 'aBLQHwohD2FlTtLU1tsrFovoRQk+cTjgEi2SWZw+A1/Z+RlkDuRvFDplwI9oATzAprWhm1KuA69D9dUAnzMICA==.sig.ed25519' }
{ previous: '%spHHU8AUpoLU7+tTvdPrfFoGmST/twD/xRH0Jd2Jhgw=.sha256',
sequence: 2,
author: '@6VKBcLTLgL8vDuLHtgFlYEg/yTgYqI1WoPENQrzJNs4=.ed25519',
timestamp: 1528823339700,
hash: 'sha256',
content: { type: 'post', text: 'alice\'s Second Post!' },
signature: 'mZJqo73/jHAyoOajkInsAMicSx/iTvZg0f5FONuXspuXfzkxKtVUH8atYFmL5JNPxEXc6IR0dhpeMhAN/CHZDg==.sig.ed25519' }
{ previous: null,
sequence: 1,
author: '@SWgLOnMBG7wEnmyP+vjueVluNj46IYRiktfyErVbjhA=.ed25519',
timestamp: 1528823339717,
hash: 'sha256',
content: { type: 'post', text: 'bob\'s First Post!' },
signature: 'xrhWyHx129zjk7Bg2CPUQtASqehoeK7Yp6m9n3Yd2DgtMLzDlj1LPBCQIEglnUK2h7uLzKZQnAFrDrYjLYopAQ==.sig.ed25519' }
```## API
```js
var replicate = require('ssb-exchange')
```### var stream = replicate(ssb)
Returns a duplex stream, `stream`, that can be piped into another ssb-exchange
duplex stream. The two will exchange information about what feeds they have, and
send only new information to the other end. The stream terminates once all data
has been sent and written to the local ssb database.## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install ssb-exchange
```## License
ISC