refactor
This commit is contained in:
parent
302bc4bf7e
commit
fc5c860d49
1 changed files with 13 additions and 10 deletions
|
|
@ -218,7 +218,10 @@ Network.prototype._onMessage = function(enc) {
|
||||||
}
|
}
|
||||||
//ensure claimed public key is actually the public key of the peer
|
//ensure claimed public key is actually the public key of the peer
|
||||||
//e.g., their public key should hash to be their peerId
|
//e.g., their public key should hash to be their peerId
|
||||||
if (enc.pubkey !== this.peerFromCopayer(payload.copayerId)) {
|
if (enc.pubkey !== payload.copayerId) {
|
||||||
|
console.log(JSON.stringify(enc));
|
||||||
|
console.log(JSON.stringify(enc.pubkey));
|
||||||
|
console.log(JSON.stringify(payload.copayerId));
|
||||||
this._deletePeer(enc.pubkey, 'incorrect pubkey for peerId');
|
this._deletePeer(enc.pubkey, 'incorrect pubkey for peerId');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -346,24 +349,24 @@ Network.prototype.getCopayerIds = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Network.prototype.send = function(copayerIds, payload, cb) {
|
Network.prototype.send = function(dest, payload, cb) {
|
||||||
preconditions.checkArgument(payload);
|
preconditions.checkArgument(payload);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!copayerIds) {
|
if (!dest) {
|
||||||
copayerIds = this.getCopayerIds();
|
defst = this.getCopayerIds();
|
||||||
payload.isBroadcast = 1;
|
payload.isBroadcast = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof copayerIds === 'string')
|
if (typeof dest === 'string')
|
||||||
copayerIds = [copayerIds];
|
dest = [dest];
|
||||||
|
|
||||||
var l = copayerIds.length;
|
var l = dest.length;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
//console.log('sending ' + JSON.stringify(payload));
|
//console.log('sending ' + JSON.stringify(payload));
|
||||||
copayerIds.forEach(function(copayerId) {
|
dest.forEach(function(to) {
|
||||||
//console.log('\t to ' + copayerId);
|
//console.log('\t to ' + to);
|
||||||
var message = self.encode(copayerId, payload);
|
var message = self.encode(to, payload);
|
||||||
self.socket.emit('message', message);
|
self.socket.emit('message', message);
|
||||||
});
|
});
|
||||||
if (typeof cb === 'function') cb();
|
if (typeof cb === 'function') cb();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue