mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Change .connect() to connect to a <host:port> instead of IPFS hash.
This commit is contained in:
12
README.md
12
README.md
@@ -37,17 +37,17 @@ npm install
|
||||
|
||||
Key-Value store [example](https://github.com/haadcode/orbit-db/blob/master/examples/keyvalue.js):
|
||||
```
|
||||
node examples/keyvalue.js <host> <username> <channel> <key> <value>
|
||||
node examples/keyvalue.js <host:port> <username> <channel> <key> <value>
|
||||
```
|
||||
|
||||
Event log [example](https://github.com/haadcode/orbit-db/blob/master/examples/eventlog.js) (run several in separate shells):
|
||||
```
|
||||
node examples/eventlog.js <host> <username> <channel> <data> <interval in ms>
|
||||
node examples/eventlog.js <host:port> <username> <channel> <data> <interval in ms>
|
||||
```
|
||||
|
||||
Benchmark writes:
|
||||
```
|
||||
node examples/benchmark.js <host> <username> <channel>;
|
||||
node examples/benchmark.js <host:port> <username> <channel>;
|
||||
```
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ Then open `examples/browser.html`. See the full example [here](https://github.co
|
||||
<script type="text/javascript" src="ipfsapi.min.js" charset="utf-8"></script>
|
||||
<script type="text/javascript">
|
||||
const ipfs = IpfsApi();
|
||||
OrbitDB.connect('QmRB8x6aErtKTFHDNRiViixSKYwW1DbfcvJHaZy1hnRzLM', 'user1', '', ipfs).then((orbit) => {
|
||||
OrbitDB.connect('localhost:3333', 'user1', '', ipfs).then((orbit) => {
|
||||
orbit.kvstore('test').then((db) => {
|
||||
db.put('hello', 'world').then((res) => {
|
||||
const result = db.get(key);
|
||||
@@ -89,7 +89,7 @@ _See usage example below_
|
||||
|
||||
_OrbitDB calls its namespaces channels. A channel is similar to "table", "keyspace", "topic", "feed" or "collection" in other db systems._
|
||||
|
||||
connect(host, port, username, password)
|
||||
connect(<host:port>, username, password)
|
||||
|
||||
channel(name, password)
|
||||
|
||||
@@ -125,7 +125,7 @@ const ipfs = ipfsAPI();
|
||||
|
||||
async(() => {
|
||||
// Connect
|
||||
const orbit = await(OrbitClient.connect('QmRB8x6aErtKTFHDNRiViixSKYwW1DbfcvJHaZy1hnRzLM', 'usernamne', '', ipfs));
|
||||
const orbit = await(OrbitClient.connect('localhost:3333', 'usernamne', '', ipfs));
|
||||
|
||||
/* Event Log */
|
||||
const eventlog = orbit.eventlog('eventlog test');
|
||||
|
||||
@@ -125,60 +125,12 @@ class OrbitDB {
|
||||
_connect(hash, username, password, allowOffline) {
|
||||
if(allowOffline === undefined) allowOffline = false;
|
||||
|
||||
const catFromJsIpfsApi = (hash) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(this._ipfs.cat) {
|
||||
logger.debug(".cat with js-ipfs-api");
|
||||
this._ipfs.cat(hash, (err, res) => {
|
||||
if(err) return reject(err)
|
||||
let buf = '';
|
||||
res
|
||||
.on('error', (err) => reject(err))
|
||||
.on('data', (data) => buf += data)
|
||||
.on('end', () => resolve(buf.toString()))
|
||||
});
|
||||
} else {
|
||||
reject("not using js-ipfs-api");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const catFromJsIpfs = (hash) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(this._ipfs.files.cat) {
|
||||
logger.debug(".cat with js-ipfs");
|
||||
setTimeout(reject, 5000);
|
||||
this._ipfs.files.cat(hash, (err, res) => {
|
||||
if(err) return reject(err);
|
||||
let buf = '';
|
||||
res.on('data', (res) => {
|
||||
res.stream
|
||||
.on('error', (err) => reject(err))
|
||||
.on('data', (data) => buf += data)
|
||||
.on('end', () => resolve(buf.toString()))
|
||||
})
|
||||
});
|
||||
} else {
|
||||
reject("not using js-ipfs");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const readNetworkInfo = (hash) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
catFromJsIpfsApi(hash).then(resolve)
|
||||
.catch((e) => {
|
||||
catFromJsIpfs(hash).then(resolve)
|
||||
.catch((e) => {
|
||||
logger.warn(".cat - no api or content found, using mock")
|
||||
resolve(JSON.stringify({
|
||||
// name: 'localhost dev network',
|
||||
name: 'Orbit DEV Network',
|
||||
// publishers: ['localhost:3333']
|
||||
publishers: ['178.62.241.75:3333']
|
||||
}));
|
||||
});
|
||||
});
|
||||
resolve(JSON.stringify({
|
||||
name: 'Orbit DEV Network',
|
||||
publishers: [hash]
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ const OrbitServer = require('orbit-server/src/server');
|
||||
require('logplease').setLogLevel('ERROR');
|
||||
|
||||
// Orbit
|
||||
// const network = 'QmRB8x6aErtKTFHDNRiViixSKYwW1DbfcvJHaZy1hnRzLM';
|
||||
const network = 'Qmeh6ktQ1YFKksugJb59vBxG51xXoEvjBZXRK3DdrF3mNj';
|
||||
const network = 'localhost:3333';
|
||||
const username = 'testrunner';
|
||||
const password = '';
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const IPFS = require('ipfs')
|
||||
// Mute logging
|
||||
require('logplease').setLogLevel('ERROR');
|
||||
|
||||
const network = 'Qmeh6ktQ1YFKksugJb59vBxG51xXoEvjBZXRK3DdrF3mNj';
|
||||
const network = 'localhost:3333';
|
||||
const username = 'testrunner';
|
||||
const username2 = 'rennurtset';
|
||||
const ipfsPath = '/tmp/orbittests';
|
||||
|
||||
Reference in New Issue
Block a user