progressive reconnect time
This commit is contained in:
parent
be7e122b0a
commit
d0e20c1bff
7 changed files with 37 additions and 18 deletions
|
|
@ -32,7 +32,6 @@ function Wallet(opts) {
|
|||
this.id = opts.id || Wallet.getRandomId();
|
||||
this.name = opts.name;
|
||||
this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64');
|
||||
this.networkName = opts.networkName;
|
||||
|
||||
// Renew token every 24hs
|
||||
if (opts.tokenTime && new Date().getTime() - opts.tokenTime < 86400000) {
|
||||
|
|
@ -93,7 +92,6 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
|||
if (hasChanged) {
|
||||
if (wasIncomplete) {
|
||||
this.sendPublicKeyRing();
|
||||
this.connectToAll();
|
||||
}
|
||||
if (this.publicKeyRing.isComplete()) {
|
||||
this._lockIncomming();
|
||||
|
|
@ -171,6 +169,7 @@ Wallet.prototype._handleConnect = function(newCopayerId) {
|
|||
};
|
||||
|
||||
Wallet.prototype._handleDisconnect = function(peerID) {
|
||||
this.currentDelay = null;
|
||||
this.emit('disconnect', peerID);
|
||||
};
|
||||
|
||||
|
|
@ -185,7 +184,6 @@ 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,
|
||||
|
|
@ -275,7 +273,8 @@ Wallet.prototype.scheduleConnect = function() {
|
|||
var self = this;
|
||||
if (self.network.isOnline()) {
|
||||
self.connectToAll();
|
||||
setTimeout(self.scheduleConnect.bind(self), self.reconnectDelay);
|
||||
self.currentDelay = self.currentDelay*2 || self.reconnectDelay;
|
||||
setTimeout(self.scheduleConnect.bind(self), self.currentDelay);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ WalletFactory.prototype._checkRead = function(walletId) {
|
|||
};
|
||||
|
||||
WalletFactory.prototype.fromObj = function(obj) {
|
||||
|
||||
// not stored options
|
||||
obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay;
|
||||
|
||||
var w = Wallet.fromObj(obj, this.storage, this.network, this.blockchain);
|
||||
w.verbose = this.verbose;
|
||||
return w;
|
||||
|
|
@ -70,10 +74,10 @@ WalletFactory.prototype.read = function(walletId) {
|
|||
var s = this.storage;
|
||||
|
||||
obj.id = walletId;
|
||||
obj.opts = s.get(walletId, 'opts');
|
||||
obj.publicKeyRing = s.get(walletId, 'publicKeyRing');
|
||||
obj.txProposals = s.get(walletId, 'txProposals');
|
||||
obj.privateKey = s.get(walletId, 'privateKey');
|
||||
obj.opts = s.get(walletId, 'opts');
|
||||
obj.publicKeyRing = s.get(walletId, 'publicKeyRing');
|
||||
obj.txProposals = s.get(walletId, 'txProposals');
|
||||
obj.privateKey = s.get(walletId, 'privateKey');
|
||||
|
||||
var w = this.fromObj(obj);
|
||||
return w;
|
||||
|
|
@ -114,10 +118,10 @@ WalletFactory.prototype.create = function(opts) {
|
|||
opts.verbose = this.verbose;
|
||||
|
||||
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
||||
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
|
||||
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
|
||||
opts.requiredCopayers = requiredCopayers;
|
||||
opts.totalCopayers = totalCopayers;
|
||||
opts.version = opts.version || this.version;
|
||||
opts.totalCopayers = totalCopayers;
|
||||
opts.version = opts.version || this.version;
|
||||
var w = new Wallet(opts);
|
||||
w.store();
|
||||
return w;
|
||||
|
|
|
|||
|
|
@ -126,12 +126,13 @@ Network.prototype._onClose = function(peerID) {
|
|||
Network.prototype.connectToCopayers = function(copayerIds) {
|
||||
var self = this;
|
||||
var arrayDiff= Network._arrayDiff(copayerIds, this.connectedCopayers());
|
||||
console.log('[WebRTC.js.128:arrayDiff:]',arrayDiff); //TODO
|
||||
|
||||
arrayDiff.forEach(function(copayerId) {
|
||||
if (this.allowedCopayerIds && !this.allowedCopayerIds[copayerId]) {
|
||||
this._deletePeer(this.peerFromCopayer(copayerId));
|
||||
} else {
|
||||
|
||||
console.log('[WebRTC.js.134] CONNECT TO', copayerId); //TODO
|
||||
self.connectTo(copayerId);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue