browser: improve wsproxy.
This commit is contained in:
parent
d55f6c9c78
commit
154bc6fb4d
@ -102,7 +102,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(utils.dsha256(pow), this.target) > 0);
|
||||||
|
|
||||||
utils.log('Solved proof of work: %d', nonce);
|
utils.log('Solved proof of work: %d', nonce);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,8 @@ module.exports = function wsproxy(options) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!utils.isNumber(port)
|
if (!utils.isNumber(port)
|
||||||
|| typeof host !== 'string') {
|
|| typeof host !== 'string'
|
||||||
|
|| host.length === 0) {
|
||||||
utils.error('Client gave bad arguments.');
|
utils.error('Client gave bad arguments.');
|
||||||
ws.emit('tcp close');
|
ws.emit('tcp close');
|
||||||
ws.disconnect();
|
ws.disconnect();
|
||||||
@ -72,7 +73,7 @@ module.exports = function wsproxy(options) {
|
|||||||
pow.writeString(host, 'ascii');
|
pow.writeString(host, 'ascii');
|
||||||
pow = pow.render();
|
pow = pow.render();
|
||||||
|
|
||||||
if (utils.cmp(utils.dsha256(pow), target) >= 0) {
|
if (utils.cmp(utils.dsha256(pow), target) > 0) {
|
||||||
utils.error('Client did not solve proof of work.');
|
utils.error('Client did not solve proof of work.');
|
||||||
ws.emit('tcp close');
|
ws.emit('tcp close');
|
||||||
ws.disconnect();
|
ws.disconnect();
|
||||||
@ -103,8 +104,9 @@ module.exports = function wsproxy(options) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
socket = net.connect(port, host);
|
socket = net.connect(port, host);
|
||||||
utils.error('Connecting to %s:%d.', host, port);
|
utils.log('Connecting to %s:%d.', host, port);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
utils.error(e.message);
|
||||||
utils.error('Closing %s:%d.', host, port);
|
utils.error('Closing %s:%d.', host, port);
|
||||||
ws.emit('tcp close');
|
ws.emit('tcp close');
|
||||||
ws.disconnect();
|
ws.disconnect();
|
||||||
@ -127,12 +129,14 @@ module.exports = function wsproxy(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('close', function() {
|
socket.on('close', function() {
|
||||||
utils.error('Closing %s:%d.', host, port);
|
utils.log('Closing %s:%d.', host, port);
|
||||||
ws.emit('tcp close');
|
ws.emit('tcp close');
|
||||||
ws.disconnect();
|
ws.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('tcp data', function(data) {
|
ws.on('tcp data', function(data) {
|
||||||
|
if (typeof data !== 'string')
|
||||||
|
return;
|
||||||
socket.write(new Buffer(data, 'hex'));
|
socket.write(new Buffer(data, 'hex'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user