mirror of https://github.com/BTCPrivate/copay.git
trying to fix the connection status
This commit is contained in:
parent
6be6f1e23c
commit
4d59d7cfd5
|
@ -319,6 +319,9 @@ Wallet.prototype._handleAddressBook = function(senderId, data, isInbound) {
|
|||
};
|
||||
|
||||
Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
||||
preconditions.checkArgument(senderId);
|
||||
preconditions.checkArgument(data);
|
||||
preconditions.checkArgument(data.type);
|
||||
|
||||
if (data.type !== 'walletId' && this.id !== data.walletId) {
|
||||
this.emit('badMessage', senderId);
|
||||
|
@ -453,6 +456,7 @@ Wallet.prototype.netStart = function(callback) {
|
|||
|
||||
net.start(startOpts, function() {
|
||||
self.emit('ready', net.getPeer());
|
||||
self.fakeConnections();
|
||||
setTimeout(function() {
|
||||
self.emit('publicKeyRingUpdated', true);
|
||||
//self.scheduleConnect();
|
||||
|
@ -463,6 +467,17 @@ Wallet.prototype.netStart = function(callback) {
|
|||
};
|
||||
|
||||
|
||||
// TODO temporary method. should remove this when we refactor peerID out
|
||||
Wallet.prototype.fakeConnections = function() {
|
||||
var all = this.publicKeyRing.getAllCopayerIds();
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
var copayerID = all[i];
|
||||
var peerID = this.network.peerFromCopayer(copayerID);
|
||||
this.network._addCopayerMap(peerID, copayerID);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// not being used now
|
||||
Wallet.prototype.scheduleConnect = function() {
|
||||
var self = this;
|
||||
|
@ -713,7 +728,7 @@ Wallet.prototype.getTxProposals = function() {
|
|||
txp.finallyRejected = true;
|
||||
}
|
||||
|
||||
if (txp.readonly && !txp.finallyRejected && !txp.sentTs) {} else {
|
||||
if (!txp.readonly || txp.finallyRejected || txp.sentTs) {
|
||||
ret.push(txp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ Network.prototype._deletePeer = function(peerId) {
|
|||
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
|
||||
};
|
||||
|
||||
Network.prototype._addConnectedCopayer = function(copayerId, isInbound) {
|
||||
Network.prototype._addConnectedCopayer = function(copayerId) {
|
||||
var peerId = this.peerFromCopayer(copayerId);
|
||||
this._addCopayerMap(peerId, copayerId);
|
||||
Network._arrayPushOnce(peerId, this.connectedPeers);
|
||||
|
@ -221,10 +221,11 @@ Network.prototype._onMessage = function(enc) {
|
|||
this._deletePeer(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
this._addConnectedCopayer(payload.copayerId);
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
console.log(JSON.stringify(self.copayerForPeer));
|
||||
console.log('data from '+sender+' '+self.copayerForPeer[sender]);
|
||||
this.emit('data', self.copayerForPeer[sender], payload);
|
||||
}
|
||||
};
|
||||
|
@ -243,7 +244,12 @@ Network.prototype._setupConnectionHandlers = function(cb) {
|
|||
});
|
||||
if (typeof cb === 'function') cb();
|
||||
});
|
||||
self.socket.on('message', self._onMessage.bind(self));
|
||||
self.socket.on('message', function (m) {
|
||||
// delay execution, to improve error handling
|
||||
setTimeout(function() {
|
||||
self._onMessage(m);
|
||||
}, 1);
|
||||
});
|
||||
self.socket.on('error', self._onError.bind(self));
|
||||
|
||||
};
|
||||
|
@ -273,9 +279,8 @@ Network.prototype._setInboundPeerAuth = function(peerId) {
|
|||
};
|
||||
|
||||
Network.prototype.setCopayerId = function(copayerId) {
|
||||
if (this.started) {
|
||||
throw new Error('network already started: can not change peerId')
|
||||
}
|
||||
preconditions.checkState(!this.started, 'network already started: can not change peerId');
|
||||
|
||||
this.copayerId = copayerId;
|
||||
this.copayerIdBuf = new Buffer(copayerId, 'hex');
|
||||
this.peerId = this.peerFromCopayer(this.copayerId);
|
||||
|
@ -324,8 +329,6 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
//this.socket.emit('sync');
|
||||
this.started = true;
|
||||
|
||||
//this.emit('serverError', self.criticalError);
|
||||
|
||||
};
|
||||
|
||||
Network.prototype.getOnlinePeerIDs = function() {
|
||||
|
|
Loading…
Reference in New Issue