add timestamp sync

This commit is contained in:
Manuel Araoz 2014-08-19 10:43:23 -04:00
commit 981c56f091
3 changed files with 12 additions and 2 deletions

View file

@ -4,6 +4,7 @@ var EventEmitter = require('events').EventEmitter;
var async = require('async'); var async = require('async');
var preconditions = require('preconditions').singleton(); var preconditions = require('preconditions').singleton();
var util = require('util'); var util = require('util');
var microtime = require('microtime');
var bitcore = require('bitcore'); var bitcore = require('bitcore');
var bignum = bitcore.Bignum; var bignum = bitcore.Bignum;
@ -315,6 +316,11 @@ Wallet.prototype._onAddressBook = function(senderId, data, isInbound) {
} }
}; };
Wallet.prototype.updateTimestamp = function() {
this.lastTimestamp = microtime.now();
};
Wallet.prototype._onData = function(senderId, data, isInbound) { Wallet.prototype._onData = function(senderId, data, isInbound) {
preconditions.checkArgument(senderId); preconditions.checkArgument(senderId);
preconditions.checkArgument(data); preconditions.checkArgument(data);
@ -326,6 +332,8 @@ Wallet.prototype._onData = function(senderId, data, isInbound) {
return; return;
} }
this.updateTimestamp();
switch (data.type) { switch (data.type) {
// This handler is repeaded on WalletFactory (#join). TODO // This handler is repeaded on WalletFactory (#join). TODO
case 'walletId': case 'walletId':
@ -438,7 +446,8 @@ Wallet.prototype.netStart = function(callback) {
var startOpts = { var startOpts = {
copayerId: myId, copayerId: myId,
privkey: myIdPriv, privkey: myIdPriv,
maxPeers: self.totalCopayers maxPeers: self.totalCopayers,
lastTimestamp: this.lastTimestamp,
}; };
if (this.publicKeyRing.isComplete()) { if (this.publicKeyRing.isComplete()) {

View file

@ -326,7 +326,7 @@ Network.prototype.start = function(opts, openCallback) {
this._setupConnectionHandlers(openCallback); this._setupConnectionHandlers(openCallback);
var pubkey = this.getKey().public.toString('hex'); var pubkey = this.getKey().public.toString('hex');
this.socket.emit('subscribe', pubkey); this.socket.emit('subscribe', pubkey);
//this.socket.emit('sync'); this.socket.emit('sync', opts.lastTimestamp);
this.started = true; this.started = true;
}; };

View file

@ -11,6 +11,7 @@
}, },
"version": "0.4.7", "version": "0.4.7",
"dependencies": { "dependencies": {
"microtime": "^1.0.1",
"mocha": "^1.18.2", "mocha": "^1.18.2",
"mocha-lcov-reporter": "0.0.1", "mocha-lcov-reporter": "0.0.1",
"optimist": "^0.6.1", "optimist": "^0.6.1",