Merge remote-tracking branch 'origin/dignifiedquire-ipfs'

This commit is contained in:
haad 2016-05-19 15:30:51 +02:00
commit c69f0187ef
9 changed files with 175609 additions and 40575 deletions

35114
dist/orbitdb.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
'use strict';
const ipfsd = require('ipfsd-ctl');
// const ipfsd = require('ipfsd-ctl');
const IPFS = require('ipfs')
const OrbitDB = require('../src/OrbitDB');
const Timer = require('./Timer');
@ -19,13 +20,17 @@ const startIpfs = () => {
// if(err) console.error(err);
// resolve(ipfs);
// });
ipfsd.local((err, node) => {
if(err) reject(err);
node.startDaemon((err, ipfs) => {
if(err) reject(err);
resolve(ipfs);
});
});
// ipfsd.local((err, node) => {
// if(err) reject(err);
// node.startDaemon((err, ipfs) => {
// if(err) reject(err);
// resolve(ipfs);
// });
// });
const ipfs = new IPFS()
ipfs.goOnline(() => {
resolve(ipfs)
})
});
};

View File

@ -1,6 +1,7 @@
'use strict';
const IpfsApi = require('ipfs-api');
// const IpfsApi = require('ipfs-api');
const IPFS = require('exports?Ipfs!ipfs/dist/index.js')
const Logger = require('logplease');
const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false });
const OrbitDB = require('../src/OrbitDB');
@ -13,7 +14,7 @@ const key = 'greeting';
const value = 'Hello world';
try {
const ipfs = IpfsApi();
const ipfs = new IPFS();
OrbitDB.connect(network, username, password, ipfs).then((orbit) => {
orbit.kvstore(channel).then((db) => {
let count = 1;
@ -31,7 +32,7 @@ try {
logger.debug(`${key} | ${result}`);
logger.debug("---------------------------------------------------")
console.log('\n');
}).catch((e) => logger.error(e));
}).catch((e) => logger.error(e.stack));
};
setInterval(query, 1000);
});

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@
const async = require('asyncawait/async');
const await = require('asyncawait/await');
// const IPFS = require('ipfs')
const ipfsd = require('ipfsd-ctl');
const OrbitDB = require('../src/OrbitDB');
const Timer = require('./Timer');
@ -20,6 +21,10 @@ const startIpfs = () => {
if(err) console.error(err);
resolve(ipfs);
});
// const ipfs = new IPFS()
// ipfs.goOnline(() => {
// resolve(ipfs)
// })
});
};

View File

@ -14,10 +14,10 @@
"main": "src/OrbitDB.js",
"dependencies": {
"logplease": "^1.2.6",
"orbit-db-counterstore": "0.0.8",
"orbit-db-eventstore": "0.0.9",
"orbit-db-feedstore": "0.0.9",
"orbit-db-kvstore": "0.0.8",
"orbit-db-counterstore": "0.0.10",
"orbit-db-eventstore": "0.0.11",
"orbit-db-feedstore": "0.0.11",
"orbit-db-kvstore": "0.0.10",
"socket.io-client": "^1.4.5"
},
"devDependencies": {
@ -26,14 +26,16 @@
"babel-loader": "^6.2.4",
"babel-plugin-transform-runtime": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"ipfs-api": "^3.0.2",
"ipfsd-ctl": "^0.13.0",
"exports-loader": "^0.6.3",
"ipfs": "^0.6.1",
"ipfs-api": "^4.1.0",
"ipfsd-ctl": "^0.14.0",
"json-loader": "^0.5.4",
"lodash": "^4.3.0",
"mocha": "^2.4.5",
"orbit-server": "^0.2.3",
"stream-http": "^2.2.1",
"webpack": "^1.12.15"
"webpack": "^2.1.0-beta.7"
},
"scripts": {
"test": "mocha",

View File

@ -45,7 +45,7 @@ class OrbitDB {
_createStore(Store, dbname, options) {
if(!options) options = {};
const replicate = options.subscribe ? options.subscribe : true;
const replicate = options.subscribe !== undefined ? options.subscribe : true;
const store = new Store(this._ipfs, this.user.username, dbname, options);
this.stores[dbname] = store;
return this._subscribe(store, dbname, replicate);
@ -111,13 +111,17 @@ class OrbitDB {
const readNetworkInfo = (hash) => {
return new Promise((resolve, reject) => {
this._ipfs.cat(hash).then((res) => {
let buf = '';
res
.on('error', (err) => reject(err))
.on('data', (data) => buf += data)
.on('end', () => resolve(buf))
}).catch((e) => reject(e));
// this._ipfs.cat(hash).then((res) => {
// let buf = '';
// res
// .on('error', (err) => reject(err))
// .on('data', (data) => buf += data)
// .on('end', () => resolve(buf))
// }).catch((e) => reject(e));
resolve(JSON.stringify({
name: 'localhost dev network',
publishers: ['localhost:3333']
}))
});
};

File diff suppressed because it is too large Load Diff

View File

@ -5,121 +5,145 @@ const path = require('path');
const fs = require('fs');
const Promise = require('bluebird');
const rimraf = require('rimraf')
const ipfsd = require('ipfsd-ctl');
const OrbitDB = require('../src/OrbitDB');
const OrbitServer = require('orbit-server/src/server');
const ipfsd = require('ipfsd-ctl');
const IPFS = require('ipfs')
// Mute logging
require('logplease').setLogLevel('ERROR');
const network = 'Qmeh6ktQ1YFKksugJb59vBxG51xXoEvjBZXRK3DdrF3mNj';
const network = 'Qmeh6ktQ1YFKksugJb59vBxG51xXoEvjBZXRK3DdrF3mNj';
const username = 'testrunner';
const username2 = 'rennurtset';
const ipfsPath = '/tmp/orbittests';
const ipfsPath = '/tmp/orbittests';
const startIpfs = () => {
return new Promise((resolve, reject) => {
OrbitServer.start();
ipfsd.disposableApi((err, ipfs) => {
if(err) reject(err);
resolve(ipfs);
let ipfs, ipfsDaemon;
const IpfsApis = [
// {
// // js-ipfs
// start: () => {
// return new Promise((resolve, reject) => {
// const IPFS = require('ipfs')
// const ipfs = new IPFS();
// ipfs.goOnline(() => resolve(ipfs));
// });
// },
// stop: () => new Promise((resolve, reject) => ipfs.goOffline(resolve))
// },
{
// js-ipfs-api via local daemon
start: () => {
return new Promise((resolve, reject) => {
ipfsd.disposableApi((err, ipfs) => {
if(err) console.error(err);
resolve(ipfs);
});
// ipfsd.local((err, node) => {
// if(err) reject(err);
// ipfsDaemon = node;
// ipfsDaemon.startDaemon((err, ipfs) => {
// if(err) reject(err);
// resolve(ipfs);
// });
// });
});
// ipfsd.local(ipfsPath, (err, node) => {
// if(err) reject(err);
// node.startDaemon((err, ipfs) => {
// if(err) reject(err);
// resolve(ipfs);
// });
// });
});
};
},
stop: () => Promise.resolve()
// stop: () => new Promise((resolve, reject) => ipfsDaemon.stopDaemon(resolve))
}
];
describe('CounterStore', function() {
this.timeout(20000);
// OrbitServer.start(); // uncomment if running this test suite stand-alone
IpfsApis.forEach(function(ipfsApi) {
let ipfs, client1, client2;
describe('CounterStore', function() {
this.timeout(40000);
let client1, client2;
before((done) => {
rimraf.sync('./orbit-db-cache.json')
startIpfs()
.then((ipfs) => {
return ipfs.add(path.resolve(process.cwd(), './test/network.json')).then(() => ipfs)
})
.then((res) => {
ipfs = res;
return Promise.map([username, username2], (login) => {
return OrbitDB.connect(network, login, '', ipfs, { allowOffline: false, cacheFile: './orbit-db-cache.json' });
}).then((clients) => {
client1 = clients[0];
client2 = clients[1];
return;
before((done) => {
rimraf.sync('./orbit-db-cache.json')
ipfsApi.start()
// .then((ipfs) => {
// return ipfs.add(path.resolve(process.cwd(), './test/network.json')).then(() => ipfs)
// })
.then((res) => {
ipfs = res;
return Promise.map([username, username2], (login) => {
return OrbitDB.connect(network, login, '', ipfs, { allowOffline: false, cacheFile: './orbit-db-cache.json' });
}).then((clients) => {
client1 = clients[0];
client2 = clients[1];
return;
}).catch((e) => {
console.log(e.stack);
assert.equal(e, null);
});
})
.then(done)
});
after((done) => {
if(client1) client1.disconnect();
if(client2) client2.disconnect();
ipfsApi.stop().then(() => {
rimraf('./orbit-db-cache.json', done)
});
});
describe('counters', function() {
it('increases a counter value', (done) => {
client1.counter('counter test', { subscribe: false, cacheFile: './orbit-db-cache.json' }).then((counter) => {
Promise.map([13, 1], (f) => counter.inc(f), { concurrency: 1 }).then(() => {
assert.equal(counter.value(), 14);
done();
}).catch((e) => {
console.error(e.stack);
assert.equal(null, e);
done();
});
}).catch((e) => {
console.log(e.stack);
assert.equal(e, null);
console.error(e.stack);
assert.equal(' ', e.message);
done();
});
})
.then(done)
});
});
after((done) => {
if(client1) client1.disconnect();
if(client2) client2.disconnect();
rimraf('./orbit-db-cache.json', done)
});
describe('counters', function() {
it('increases a counter value', (done) => {
client1.counter('counter test', { subscribe: false, cacheFile: './orbit-db-cache.json' }).then((counter) => {
Promise.map([13, 1], (f) => counter.inc(f), { concurrency: 1 }).then(() => {
it('creates a new counter from cached data', function(done) {
client1.counter('counter test', { subscribe: false, cacheFile: './orbit-db-cache.json' }).then((counter) => {
assert.equal(counter.value(), 14);
done();
}).catch((e) => {
console.error(e.stack);
assert.equal(null, e);
assert.equal(' ', e.message);
done();
});
}).catch((e) => {
console.error(e.stack);
assert.equal(' ', e.message);
done();
});
});
it('creates a new counter from cached data', function(done) {
client1.counter('counter test', { subscribe: false, cacheFile: './orbit-db-cache.json' }).then((counter) => {
assert.equal(counter.value(), 14);
done();
}).catch((e) => {
console.error(e.stack);
assert.equal(' ', e.message);
done();
});
});
it('syncs counters', (done) => {
const name = new Date().getTime();
Promise.all([client1.counter(name), client2.counter(name)]).then((counters) => {
const res1 = Promise.map([13, 10], (f) => counters[0].inc(f), { concurrency: 1 });
const res2 = Promise.map([2, 5], (f) => counters[1].inc(f), { concurrency: 1 })
Promise.all([res1, res2]).then((res) => {
setTimeout(() => {
assert.equal(counters[0].value(), 30);
assert.equal(counters[1].value(), 30);
it('syncs counters', (done) => {
const name = new Date().getTime();
Promise.all([client1.counter(name), client2.counter(name)]).then((counters) => {
const res1 = Promise.map([13, 10], (f) => counters[0].inc(f), { concurrency: 1 });
const res2 = Promise.map([2, 5], (f) => counters[1].inc(f), { concurrency: 1 })
Promise.all([res1, res2]).then((res) => {
setTimeout(() => {
assert.equal(counters[0].value(), 30);
assert.equal(counters[1].value(), 30);
done();
}, 1000)
}).catch((e) => {
console.log(e);
assert(e);
done();
}, 1000)
});
}).catch((e) => {
console.log(e);
assert(e);
done();
});
}).catch((e) => {
console.log(e);
assert(e);
done();
});
});
});
});
});