Merge pull request #256 from matiu/feature/reconnect-simpler-peer-mgmt
better peer management / peer reconection
This commit is contained in:
commit
aa0ed193fd
4 changed files with 41 additions and 74 deletions
|
|
@ -49,6 +49,16 @@ Wallet.getRandomId = function() {
|
|||
return r;
|
||||
};
|
||||
|
||||
Wallet.prototype.connectToAll = function() {
|
||||
var all = this.publicKeyRing.getAllCopayerIds();
|
||||
this.network.connectToCopayers(all);
|
||||
if (this.firstCopayerId) {
|
||||
this.sendWalletReady(this.firstCopayerId);
|
||||
this.firstCopayerId = null;
|
||||
}
|
||||
this.emit('refresh');
|
||||
};
|
||||
|
||||
Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||
this.log('RECV PUBLICKEYRING:', data);
|
||||
|
||||
|
|
@ -57,10 +67,12 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
|||
|
||||
var hasChanged = pkr.merge(inPKR, true);
|
||||
if (hasChanged) {
|
||||
this.connectToAll();
|
||||
if (this.publicKeyRing.isComplete()) {
|
||||
this._lockIncomming();
|
||||
}
|
||||
this.log('### BROADCASTING PKR');
|
||||
|
||||
recipients = null;
|
||||
this.sendPublicKeyRing(recipients);
|
||||
}
|
||||
|
|
@ -92,7 +104,6 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
this.log('badMessage FROM:', senderId); //TODO
|
||||
return;
|
||||
}
|
||||
this.log('[Wallet.js.98]', data.type); //TODO
|
||||
switch (data.type) {
|
||||
// This handler is repeaded on WalletFactory (#join). TODO
|
||||
case 'walletId':
|
||||
|
|
@ -196,17 +207,7 @@ Wallet.prototype.netStart = function() {
|
|||
|
||||
net.start(startOpts, function() {
|
||||
self.emit('created', net.getPeer());
|
||||
for (var i = 0; i < self.publicKeyRing.registeredCopayers(); i++) {
|
||||
var otherId = self.getCopayerId(i);
|
||||
if (otherId !== myId) {
|
||||
net.connectTo(otherId);
|
||||
}
|
||||
if (self.firstCopayerId) {
|
||||
self.sendWalletReady(self.firstCopayerId);
|
||||
self.firstCopayerId = null;
|
||||
}
|
||||
self.emit('refresh');
|
||||
}
|
||||
self.connectToAll();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -559,10 +560,6 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
|
|||
return true;
|
||||
};
|
||||
|
||||
Wallet.prototype.connectTo = function(peerId) {
|
||||
throw new Error('Wallet.connectTo.. not yet implemented!');
|
||||
};
|
||||
|
||||
Wallet.prototype.disconnect = function() {
|
||||
this.log('## DISCONNECTING');
|
||||
this.network.disconnect();
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ WalletFactory.prototype.open = function(walletId, opts) {
|
|||
opts = opts || {};
|
||||
opts.id = walletId;
|
||||
opts.verbose = this.verbose;
|
||||
|
||||
this.storage._setPassphrase(opts.passphrase);
|
||||
|
||||
var w = this.read(walletId) || this.create(opts);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue