polish reconnect

This commit is contained in:
Manuel Araoz 2014-06-03 11:54:07 -03:00
commit 3934b750f2
2 changed files with 21 additions and 14 deletions

View file

@ -65,7 +65,7 @@ Wallet.prototype.seedCopayer = function(pubKey) {
Wallet.prototype.connectToAll = function() { Wallet.prototype.connectToAll = function() {
var all = this.publicKeyRing.getAllCopayerIds(); var all = this.publicKeyRing.getAllCopayerIds();
console.log('[Wallet.js.58] connecting'); //TODO console.log('[Wallet.js.58] connecting'); //TODO
this.network.connectToCopayers(all); this.network.connectToCopayers(all);
if (this.seededCopayerId) { if (this.seededCopayerId) {
this.sendWalletReady(this.seededCopayerId); this.sendWalletReady(this.seededCopayerId);
@ -101,7 +101,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
var inTxp = copay.TxProposals.fromObj(data.txProposals); var inTxp = copay.TxProposals.fromObj(data.txProposals);
var ids = inTxp.getNtxids(); var ids = inTxp.getNtxids();
if (ids.lenght>1) { if (ids.lenght > 1) {
this.emit('badMessage', senderId); this.emit('badMessage', senderId);
this.log('Received BAD TxProposal messsage FROM:', senderId); //TODO this.log('Received BAD TxProposal messsage FROM:', senderId); //TODO
return; return;
@ -165,12 +165,13 @@ Wallet.prototype._optsToObj = function() {
spendUnconfirmed: this.spendUnconfirmed, spendUnconfirmed: this.spendUnconfirmed,
requiredCopayers: this.requiredCopayers, requiredCopayers: this.requiredCopayers,
totalCopayers: this.totalCopayers, totalCopayers: this.totalCopayers,
reconnectDelay: this.reconnectDelay,
name: this.name, name: this.name,
netKey: this.netKey, netKey: this.netKey,
version: this.version, version: this.version,
}; };
if (this.token){ if (this.token) {
obj.token = this.token; obj.token = this.token;
obj.tokenTime = new Date().getTime(); obj.tokenTime = new Date().getTime();
} }
@ -244,7 +245,7 @@ Wallet.prototype.netStart = function() {
net.start(startOpts, function() { net.start(startOpts, function() {
self.emit('ready', net.getPeer()); self.emit('ready', net.getPeer());
self.token = net.peer.options.token; self.token = net.peer.options.token;
setTimeout(function(){ setTimeout(function() {
console.log('[EMIT publicKeyRingUpdated:]'); //TODO console.log('[EMIT publicKeyRingUpdated:]'); //TODO
self.emit('publicKeyRingUpdated', true); self.emit('publicKeyRingUpdated', true);
console.log('[CONNECT:]'); //TODO console.log('[CONNECT:]'); //TODO
@ -252,17 +253,19 @@ Wallet.prototype.netStart = function() {
console.log('[EMIT TxProposal]'); //TODO console.log('[EMIT TxProposal]'); //TODO
self.emit('txProposalsUpdated'); self.emit('txProposalsUpdated');
self.store(); self.store();
},10); }, 10);
}); });
}; };
Wallet.prototype.scheduleConnect = function() { Wallet.prototype.scheduleConnect = function() {
var self = this; var self = this;
self.connectToAll(); if (self.network.isOnline()) {
setTimeout(function() { self.connectToAll();
self.scheduleConnect(); setTimeout(function() {
}, self.scheduleConnect();
self.reconnectDelay); },
self.reconnectDelay);
}
} }
Wallet.prototype.getOnlinePeerIDs = function() { Wallet.prototype.getOnlinePeerIDs = function() {
@ -341,7 +344,7 @@ Wallet.prototype.sendTxProposals = function(recipients, ntxid) {
var last = toSend[toSend]; var last = toSend[toSend];
for(var i in toSend) { for (var i in toSend) {
var id = toSend[i]; var id = toSend[i];
var lastInBatch = (i == toSend.length - 1); var lastInBatch = (i == toSend.length - 1);
this.network.send(recipients, { this.network.send(recipients, {
@ -455,7 +458,7 @@ Wallet.prototype.sign = function(ntxid, cb) {
ret = true; ret = true;
} }
if (cb) return cb(ret); if (cb) return cb(ret);
},10); }, 10);
}; };
Wallet.prototype.sendTx = function(ntxid, cb) { Wallet.prototype.sendTx = function(ntxid, cb) {
@ -635,7 +638,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
}]); }]);
var selectedUtxos = b.getSelectedUnspent(); var selectedUtxos = b.getSelectedUnspent();
var inputChainPaths = selectedUtxos.map(function(utxo) { var inputChainPaths = selectedUtxos.map(function(utxo) {
return pkr.pathForAddress(utxo.address); return pkr.pathForAddress(utxo.address);
}); });

View file

@ -313,8 +313,8 @@ Network.prototype.setCopayerId = function(copayerId) {
}; };
// TODO cache this.
Network.prototype.peerFromCopayer = function(hex) { Network.prototype.peerFromCopayer = function(hex) {
// TODO cache this.
var SIN = bitcore.SIN; var SIN = bitcore.SIN;
return new SIN(new Buffer(hex,'hex')).toString(); return new SIN(new Buffer(hex,'hex')).toString();
}; };
@ -409,6 +409,10 @@ Network.prototype.send = function(copayerIds, payload, cb) {
}; };
Network.prototype.isOnline = function() {
return !!this.peer;
};
Network.prototype.connectTo = function(copayerId) { Network.prototype.connectTo = function(copayerId) {
var self = this; var self = this;