polish reconnect

This commit is contained in:
Manuel Araoz 2014-06-03 11:54:07 -03:00
parent e822d57905
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() {
var all = this.publicKeyRing.getAllCopayerIds();
console.log('[Wallet.js.58] connecting'); //TODO
console.log('[Wallet.js.58] connecting'); //TODO
this.network.connectToCopayers(all);
if (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 ids = inTxp.getNtxids();
if (ids.lenght>1) {
if (ids.lenght > 1) {
this.emit('badMessage', senderId);
this.log('Received BAD TxProposal messsage FROM:', senderId); //TODO
return;
@ -165,12 +165,13 @@ Wallet.prototype._optsToObj = function() {
spendUnconfirmed: this.spendUnconfirmed,
requiredCopayers: this.requiredCopayers,
totalCopayers: this.totalCopayers,
reconnectDelay: this.reconnectDelay,
name: this.name,
netKey: this.netKey,
version: this.version,
};
if (this.token){
if (this.token) {
obj.token = this.token;
obj.tokenTime = new Date().getTime();
}
@ -244,7 +245,7 @@ Wallet.prototype.netStart = function() {
net.start(startOpts, function() {
self.emit('ready', net.getPeer());
self.token = net.peer.options.token;
setTimeout(function(){
setTimeout(function() {
console.log('[EMIT publicKeyRingUpdated:]'); //TODO
self.emit('publicKeyRingUpdated', true);
console.log('[CONNECT:]'); //TODO
@ -252,17 +253,19 @@ Wallet.prototype.netStart = function() {
console.log('[EMIT TxProposal]'); //TODO
self.emit('txProposalsUpdated');
self.store();
},10);
}, 10);
});
};
Wallet.prototype.scheduleConnect = function() {
var self = this;
self.connectToAll();
setTimeout(function() {
self.scheduleConnect();
},
self.reconnectDelay);
if (self.network.isOnline()) {
self.connectToAll();
setTimeout(function() {
self.scheduleConnect();
},
self.reconnectDelay);
}
}
Wallet.prototype.getOnlinePeerIDs = function() {
@ -341,7 +344,7 @@ Wallet.prototype.sendTxProposals = function(recipients, ntxid) {
var last = toSend[toSend];
for(var i in toSend) {
for (var i in toSend) {
var id = toSend[i];
var lastInBatch = (i == toSend.length - 1);
this.network.send(recipients, {
@ -455,7 +458,7 @@ Wallet.prototype.sign = function(ntxid, cb) {
ret = true;
}
if (cb) return cb(ret);
},10);
}, 10);
};
Wallet.prototype.sendTx = function(ntxid, cb) {
@ -635,7 +638,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
}]);
var selectedUtxos = b.getSelectedUnspent();
var inputChainPaths = selectedUtxos.map(function(utxo) {
return pkr.pathForAddress(utxo.address);
});

View File

@ -313,8 +313,8 @@ Network.prototype.setCopayerId = function(copayerId) {
};
// TODO cache this.
Network.prototype.peerFromCopayer = function(hex) {
// TODO cache this.
var SIN = bitcore.SIN;
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) {
var self = this;