mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-07 22:56:36 +00:00
Testing
This commit is contained in:
parent
78481cd96a
commit
079ea9853b
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
debug.log
|
debug.log
|
||||||
WIP/
|
WIP/
|
||||||
|
.vagrant/
|
||||||
|
@ -26,9 +26,11 @@ let run = (async(() => {
|
|||||||
let timer = new Timer(true);
|
let timer = new Timer(true);
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
channel.add(id + count);
|
// channel.add(id + count);
|
||||||
|
|
||||||
let items = channel.iterator({ limit: 20 }).collect();
|
console.log("Query...");
|
||||||
|
let items = channel.iterator({ limit: 1 }).collect();
|
||||||
|
console.log(`Found items ${items.length} items`);
|
||||||
|
|
||||||
var g = items.filter((e) => e.item.Payload.startsWith(id))
|
var g = items.filter((e) => e.item.Payload.startsWith(id))
|
||||||
var prev = -1;
|
var prev = -1;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var a = require('async');
|
|
||||||
var async = require('asyncawait/async');
|
var async = require('asyncawait/async');
|
||||||
var await = require('asyncawait/await');
|
var await = require('asyncawait/await');
|
||||||
var Keystore = require('orbit-common/lib/Keystore');
|
var Keystore = require('orbit-common/lib/Keystore');
|
||||||
@ -31,7 +30,10 @@ class OrbitClient {
|
|||||||
channel(hash, password) {
|
channel(hash, password) {
|
||||||
if(password === undefined) password = '';
|
if(password === undefined) password = '';
|
||||||
|
|
||||||
this._pubsub.subscribe(hash, password);
|
this._pubsub.subscribe(hash, password, async((hash, message, seq) => {
|
||||||
|
// let m = Aggregator._fetchOne(this.ipfs, message, password);
|
||||||
|
// console.log(">", message);
|
||||||
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
info: (options) => this._info(hash, password),
|
info: (options) => this._info(hash, password),
|
||||||
@ -206,6 +208,7 @@ class OrbitClient {
|
|||||||
// this.client = this._pubsub._client;
|
// this.client = this._pubsub._client;
|
||||||
// this.user = this.client.info.user;
|
// this.user = this.client.info.user;
|
||||||
this.user = { id: 'hello' }
|
this.user = { id: 'hello' }
|
||||||
|
console.log("Connected to redis")
|
||||||
// this.network = {
|
// this.network = {
|
||||||
// id: this.client.info.networkId,
|
// id: this.client.info.networkId,
|
||||||
// name: this.client.info.name,
|
// name: this.client.info.name,
|
||||||
|
@ -11,8 +11,8 @@ class PubSub {
|
|||||||
this._subscriptions = {};
|
this._subscriptions = {};
|
||||||
this.client1 = redis.createClient({ host: host, port: port });
|
this.client1 = redis.createClient({ host: host, port: port });
|
||||||
this.client2 = redis.createClient({ host: host, port: port });
|
this.client2 = redis.createClient({ host: host, port: port });
|
||||||
this.publishQueue = [];
|
|
||||||
this.client1.on("message", this._handleMessage.bind(this));
|
this.client1.on("message", this._handleMessage.bind(this));
|
||||||
|
this.publishQueue = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(hash, password, callback) {
|
subscribe(hash, password, callback) {
|
||||||
@ -51,17 +51,20 @@ class PubSub {
|
|||||||
|
|
||||||
_handleMessage(hash, event) {
|
_handleMessage(hash, event) {
|
||||||
if(this._subscriptions[hash]) {
|
if(this._subscriptions[hash]) {
|
||||||
var e = JSON.parse(event)
|
var message = JSON.parse(event)
|
||||||
var newHead = e.hash;
|
var newHead = message.hash;
|
||||||
var seq = e.seq;
|
var seq = message.seq;
|
||||||
var isNewer = seq > this._subscriptions[hash].seq;
|
var isNewer = seq > this._subscriptions[hash].seq;
|
||||||
|
var item = this.publishQueue[this.publishQueue.length - 1];
|
||||||
|
|
||||||
var item = this.publishQueue[this.publishQueue.length - 1];
|
// console.log(".", newHead, item ? item.hash : '')
|
||||||
if(item && item.hash === newHead) {
|
|
||||||
item.callback(isNewer);
|
if(item) {
|
||||||
|
item.callback(isNewer && newHead === item.hash);
|
||||||
this.publishQueue.pop();
|
this.publishQueue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.log(isNewer, seq, this._subscriptions[hash].seq)
|
||||||
if(isNewer)
|
if(isNewer)
|
||||||
this._updateSubscription(hash, newHead, seq);
|
this._updateSubscription(hash, newHead, seq);
|
||||||
}
|
}
|
||||||
@ -70,6 +73,7 @@ class PubSub {
|
|||||||
_updateSubscription(hash, message, seq) {
|
_updateSubscription(hash, message, seq) {
|
||||||
this._subscriptions[hash].seq = seq;
|
this._subscriptions[hash].seq = seq;
|
||||||
this._subscriptions[hash].head = message;
|
this._subscriptions[hash].head = message;
|
||||||
|
this._subscriptions[hash].callback(hash, message, seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user