mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #596 from matiu/feature/errorHandling
Feature/error handling
This commit is contained in:
commit
8cf72ecaf7
|
@ -10,7 +10,7 @@
|
|||
"angular-foundation": "*",
|
||||
"angular-route": "~1.2.14",
|
||||
"angular-qrcode": "~3.1.0",
|
||||
"peerjs": "~0.3.8",
|
||||
"peerjs": "=0.3.8",
|
||||
"angular-mocks": "~1.2.14",
|
||||
"mocha": "~1.18.2",
|
||||
"chai": "~1.9.1",
|
||||
|
|
56
config.js
56
config.js
|
@ -28,7 +28,7 @@ var defaultConfig = {
|
|||
|
||||
// other PeerJS config
|
||||
maxPeers: 15,
|
||||
debug: 1,
|
||||
debug: 3,
|
||||
|
||||
// Network encryption config
|
||||
sjclParams: {
|
||||
|
@ -43,20 +43,6 @@ var defaultConfig = {
|
|||
'iceServers': [
|
||||
// Pass in STUN and TURN servers for maximum network compatibility
|
||||
{
|
||||
url: 'stun:stun01.sipphone.com'
|
||||
}, {
|
||||
url: 'stun:stun.ekiga.net'
|
||||
}, {
|
||||
url: 'stun:stun.fwdnet.net'
|
||||
}, {
|
||||
url: 'stun:stun.ideasip.com'
|
||||
}, {
|
||||
url: 'stun:stun.iptel.org'
|
||||
}, {
|
||||
url: 'stun:stun.rixtelecom.se'
|
||||
}, {
|
||||
url: 'stun:stun.schlund.de'
|
||||
}, {
|
||||
url: 'stun:stun.l.google.com:19302'
|
||||
}, {
|
||||
url: 'stun:stun1.l.google.com:19302'
|
||||
|
@ -68,31 +54,21 @@ var defaultConfig = {
|
|||
url: 'stun:stun4.l.google.com:19302'
|
||||
}, {
|
||||
url: 'stun:stunserver.org'
|
||||
}, {
|
||||
url: 'stun:stun.softjoys.com'
|
||||
}, {
|
||||
url: 'stun:stun.voiparound.com'
|
||||
}, {
|
||||
url: 'stun:stun.voipbuster.com'
|
||||
}, {
|
||||
url: 'stun:stun.voipstunt.com'
|
||||
}, {
|
||||
url: 'stun:stun.voxgratia.org'
|
||||
}, {
|
||||
url: 'stun:stun.xten.com'
|
||||
}, {
|
||||
url: 'turn:numb.viagenie.ca',
|
||||
credential: 'muazkh',
|
||||
username: 'webrtc@live.com'
|
||||
}, {
|
||||
url: 'turn:192.158.29.39:3478?transport=udp',
|
||||
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
|
||||
username: '28224511:1379330808'
|
||||
}, {
|
||||
url: 'turn:192.158.29.39:3478?transport=tcp',
|
||||
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
|
||||
username: '28224511:1379330808'
|
||||
}
|
||||
// Options fot TURN servers with p2p communications are not possible.
|
||||
// {
|
||||
// url: 'turn:numb.viagenie.ca',
|
||||
// credential: 'muazkh',
|
||||
// username: 'webrtc@live.com'
|
||||
// }, {
|
||||
// url: 'turn:192.158.29.39:3478?transport=udp',
|
||||
// credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
|
||||
// username: '28224511:1379330808'
|
||||
// }, {
|
||||
// url: 'turn:192.158.29.39:3478?transport=tcp',
|
||||
// credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
|
||||
// username: '28224511:1379330808'
|
||||
// }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -103,7 +79,7 @@ var defaultConfig = {
|
|||
totalCopayers: 3,
|
||||
spendUnconfirmed: 1,
|
||||
verbose: 1,
|
||||
reconnectDelay: 5000,
|
||||
reconnectDelay: 500,
|
||||
},
|
||||
|
||||
// blockchain service API config
|
||||
|
|
|
@ -194,10 +194,6 @@
|
|||
<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i>
|
||||
Authenticating and looking for peers...
|
||||
</div>
|
||||
<div class="alert-box error radius" ng-show="failure">
|
||||
Oops, we had an error! Looks like you are already connected to this wallet,
|
||||
please close all other Copay Wallets and <a ng-click='failure = false; loading = false'>Try again</a>.
|
||||
</div>
|
||||
<div ng-show="!loading">
|
||||
<div class="row">
|
||||
<div class="large-6 medium-6 columns">
|
||||
|
@ -787,7 +783,7 @@ on supported browsers please check <a href="http://www.webrtc.org/">http://www.w
|
|||
<script src="lib/angular-route/angular-route.min.js"></script>
|
||||
<script src="lib/angular-foundation/mm-foundation.min.js"></script>
|
||||
<script src="lib/angular-foundation/mm-foundation-tpls.min.js"></script>
|
||||
<script src="lib/peer.js"></script> <!-- TODO Change this on new PeerJS version -->
|
||||
<script src="lib/peerjs/dist/peer.js"></script>
|
||||
<script src="lib/bitcore/browser/bundle.js"></script>
|
||||
<script src="lib/crypto-js/rollups/sha256.js"></script>
|
||||
<script src="lib/crypto-js/rollups/pbkdf2.js"></script>
|
||||
|
|
|
@ -7,7 +7,7 @@ angular.module('copayApp.controllers').controller('SigninController',
|
|||
return v1 > v2 ? 1 : ( v1 < v2 ) ? -1 : 0;
|
||||
};
|
||||
$rootScope.videoInfo = {};
|
||||
$scope.loading = $scope.failure = false;
|
||||
$scope.loading = false;
|
||||
$scope.wallets = walletFactory.getWallets().sort(cmp);
|
||||
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
|
||||
$scope.openPassword = '';
|
||||
|
@ -29,7 +29,7 @@ angular.module('copayApp.controllers').controller('SigninController',
|
|||
errMsg = e.message;
|
||||
};
|
||||
if (!w) {
|
||||
$scope.loading = $scope.failure = false;
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: errMsg || 'Wrong password', type: 'error'};
|
||||
$rootScope.$digest();
|
||||
return;
|
||||
|
@ -71,16 +71,17 @@ angular.module('copayApp.controllers').controller('SigninController',
|
|||
};
|
||||
|
||||
function installStartupHandlers(wallet) {
|
||||
wallet.on('connectionError', function(err) {
|
||||
$scope.failure = true;
|
||||
wallet.on('serverError', function(msg) {
|
||||
$rootScope.$flashMessage = {
|
||||
message: 'There was an error connecting to the PeerJS server.'
|
||||
+(msg||'Check you settings and Internet connection.'),
|
||||
type: 'error',
|
||||
};
|
||||
controllerUtils.onErrorDigest($scope);
|
||||
});
|
||||
wallet.on('ready', function() {
|
||||
$scope.loading = false;
|
||||
});
|
||||
wallet.on('serverError', function() {
|
||||
$rootScope.$flashMessage = { message: 'The PeerJS server is not responding, please try again', type: 'error'};
|
||||
controllerUtils.onErrorDigest($scope);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -161,6 +161,7 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
Wallet.prototype._handleConnect = function(newCopayerId) {
|
||||
if (newCopayerId) {
|
||||
this.log('#### Setting new COPAYER:', newCopayerId);
|
||||
this.currentDelay = null;
|
||||
this.sendWalletId(newCopayerId);
|
||||
}
|
||||
var peerID = this.network.peerFromCopayer(newCopayerId)
|
||||
|
@ -232,18 +233,11 @@ Wallet.prototype.netStart = function() {
|
|||
net.on('connect', self._handleConnect.bind(self));
|
||||
net.on('disconnect', self._handleDisconnect.bind(self));
|
||||
net.on('data', self._handleData.bind(self));
|
||||
net.on('openError', function() {
|
||||
self.log('[Wallet.js.132:openError:] GOT openError'); //TODO
|
||||
self.emit('openError');
|
||||
});
|
||||
net.on('error', function() {
|
||||
self.emit('connectionError');
|
||||
});
|
||||
net.on('close', function() {
|
||||
self.emit('close');
|
||||
});
|
||||
net.on('serverError', function() {
|
||||
self.emit('serverError');
|
||||
net.on('serverError', function(msg) {
|
||||
self.emit('serverError', msg);
|
||||
});
|
||||
|
||||
var myId = self.getMyCopayerId();
|
||||
|
@ -257,6 +251,7 @@ Wallet.prototype.netStart = function() {
|
|||
if (this.publicKeyRing.isComplete()) {
|
||||
this._lockIncomming();
|
||||
}
|
||||
|
||||
net.start(startOpts, function() {
|
||||
self.emit('ready', net.getPeer());
|
||||
self.token = net.peer.options.token;
|
||||
|
@ -273,7 +268,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ function Network(opts) {
|
|||
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
||||
this.debug = opts.debug || 3;
|
||||
this.maxPeers = opts.maxPeers || 10;
|
||||
this.reconnectAttempts = opts.reconnectAttempts || 3;
|
||||
this.sjclParams = opts.sjclParams || {
|
||||
salt: 'f28bfb49ef70573c',
|
||||
iter:500,
|
||||
|
@ -49,6 +50,7 @@ Network.prototype.cleanUp = function() {
|
|||
this.isInboundPeerAuth=[];
|
||||
this.copayerForPeer={};
|
||||
this.connections={};
|
||||
this.criticalErr='';
|
||||
if (this.peer) {
|
||||
this.peer.disconnect();
|
||||
this.peer.destroy();
|
||||
|
@ -187,11 +189,7 @@ Network.prototype._onData = function(encStr, isInbound, peerId) {
|
|||
}
|
||||
};
|
||||
|
||||
Network.prototype._checkAnyPeer = function() {
|
||||
if (!this.connectedPeers.length) {
|
||||
this.cleanUp();
|
||||
this.emit('openError');
|
||||
}
|
||||
Network.prototype._checkAnyPeer = function(msg) {
|
||||
if (this.connectedPeers.length === 1) {
|
||||
this.emit('onlyYou');
|
||||
}
|
||||
|
@ -246,10 +244,10 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
|||
});
|
||||
|
||||
p.on('error', function(err) {
|
||||
if (!err.message.match(/Could\snot\sconnect\sto peer/)) {
|
||||
self.emit('error', err);
|
||||
console.log('RECV ERROR: ', err); //TODO
|
||||
if (!err.message.match(/Could\snot\sconnect\sto peer/) ) {
|
||||
self.criticalError=err.message;
|
||||
}
|
||||
self._checkAnyPeer();
|
||||
});
|
||||
|
||||
p.on('connection', function(dataConn) {
|
||||
|
@ -319,17 +317,18 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
self.peer.removeAllListeners();
|
||||
}
|
||||
|
||||
if (self.tries < 2) {
|
||||
if (!self.criticalError && self.tries < self.reconnectAttempts) {
|
||||
self.tries++;
|
||||
self.peer = new Peer(self.peerId, self.opts);
|
||||
self.started = true;
|
||||
self._setupPeerHandlers(openCallback);
|
||||
|
||||
setTimeout(setupPeer, 3000); // Schedule retry
|
||||
return;
|
||||
}
|
||||
|
||||
self.emit('serverError');
|
||||
if (self.criticalError && self.criticalError.match(/taken/)) {
|
||||
self.criticalError=' Looks like you are already connected to this wallet please close all other Copay Wallets '
|
||||
}
|
||||
self.emit('serverError', self.criticalError);
|
||||
self.cleanUp();
|
||||
}
|
||||
|
||||
|
|
|
@ -79,8 +79,9 @@ angular.module('copayApp.services')
|
|||
}
|
||||
});
|
||||
});
|
||||
w.on('openError', root.onErrorDigest);
|
||||
w.on('connectionError', root.onErrorDigest);
|
||||
w.on('connectionError', function(msg) {
|
||||
root.onErrorDigest(msg);
|
||||
});
|
||||
w.on('connect', function(peerID) {
|
||||
if (peerID) {
|
||||
video.callPeer(peerID, handlePeerVideo);
|
||||
|
|
2657
lib/peer.js
2657
lib/peer.js
File diff suppressed because it is too large
Load Diff
|
@ -239,12 +239,23 @@ describe('Wallet model', function() {
|
|||
|
||||
it('call reconnect after interval', function(done) {
|
||||
var w = createW2();
|
||||
var testTime = 1000;
|
||||
var callCount = 0;
|
||||
var cT=w.reconnectDelay;
|
||||
var t=0;
|
||||
|
||||
do {
|
||||
callCount++;
|
||||
t += cT;
|
||||
cT *= 2;
|
||||
} while (t<testTime);
|
||||
|
||||
var spy = sinon.spy(w, 'scheduleConnect');
|
||||
w.netStart();
|
||||
setTimeout(function() {
|
||||
sinon.assert.callCount(spy, 10);
|
||||
sinon.assert.callCount(spy, callCount);
|
||||
done();
|
||||
}, 1000);
|
||||
}, testTime);
|
||||
});
|
||||
|
||||
it('handle network indexes correctly', function() {
|
||||
|
|
Loading…
Reference in New Issue