proxysocket: fix pow.

This commit is contained in:
Christopher Jeffrey 2016-09-07 13:52:00 -07:00
parent af7846c278
commit 4e94d4a594
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -2,6 +2,7 @@
var bcoin = require('../env'); var bcoin = require('../env');
var utils = bcoin.utils; var utils = bcoin.utils;
var crypto = require('../crypto/crypto');
var BufferWriter = require('../utils/writer'); var BufferWriter = require('../utils/writer');
var assert = utils.assert; var assert = utils.assert;
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
@ -28,6 +29,8 @@ function ProxySocket(uri) {
this._init(); this._init();
} }
utils.inherits(ProxySocket, EventEmitter);
ProxySocket.prototype._init = function _init() { ProxySocket.prototype._init = function _init() {
var self = this; var self = this;
@ -82,8 +85,6 @@ ProxySocket.prototype._init = function _init() {
}); });
}; };
utils.inherits(ProxySocket, EventEmitter);
ProxySocket.prototype.connect = function connect(port, host) { ProxySocket.prototype.connect = function connect(port, host) {
var nonce = 0; var nonce = 0;
var i, pow; var i, pow;
@ -115,7 +116,7 @@ ProxySocket.prototype.connect = function connect(port, host) {
nonce++; nonce++;
assert(nonce <= 0xffffffff, 'Could not create socket.'); assert(nonce <= 0xffffffff, 'Could not create socket.');
pow.writeUInt32LE(nonce, 0, true); pow.writeUInt32LE(nonce, 0, true);
} while (utils.cmp(utils.dsha256(pow), this.target) > 0); } while (utils.cmp(crypto.hash256(pow), this.target) > 0);
utils.log('Solved proof of work: %d', nonce); utils.log('Solved proof of work: %d', nonce);
} }
@ -129,13 +130,13 @@ ProxySocket.prototype.connect = function connect(port, host) {
}; };
ProxySocket.prototype.write = function write(data) { ProxySocket.prototype.write = function write(data) {
this.bytesWritten += data.length;
if (!this.info) { if (!this.info) {
this.sendBuffer.push(data); this.sendBuffer.push(data);
return true; return true;
} }
this.bytesWritten += data.length;
this.socket.emit('tcp data', data.toString('hex')); this.socket.emit('tcp data', data.toString('hex'));
return true; return true;