This commit is contained in:
Manuel Araoz 2014-08-19 15:15:06 -04:00
commit fc5c860d49

View file

@ -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();