Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Dec 2, 2010
1 parent e232f6e commit dd53cee
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 147 deletions.
28 changes: 14 additions & 14 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ function Stream() {
util.inherits(Stream, events.EventEmitter);
exports.Stream = Stream;

Stream.prototype.pipe = function (dest, options) {
Stream.prototype.pipe = function(dest, options) {
var source = this;

function ondata (chunk) {
function ondata(chunk) {
if (dest.writable) {
if (false === dest.write(chunk)) source.pause();
}
}

source.on("data", ondata);
source.on('data', ondata);

function ondrain () {
function ondrain() {
if (source.readable) source.resume();
}

dest.on("drain", ondrain);
dest.on('drain', ondrain);

/*
* If the 'end' option is not supplied, dest.end() will be called when
* source gets the 'end' event.
*/

if (!options || options.end !== false) {
function onend () {
function onend() {
dest.end();
}

source.on("end", onend);
source.on('end', onend);
}

dest.on('close', function () {
dest.on('close', function() {
source.removeListener('data', ondata);
dest.removeListener('drain', ondrain);
source.removeListener('end', onend);
Expand All @@ -49,22 +49,22 @@ Stream.prototype.pipe = function (dest, options) {
*/

if (!source.pause) {
source.pause = function () {
source.emit("pause");
source.pause = function() {
source.emit('pause');
};
}

if (!source.resume) {
source.resume = function () {
source.emit("resume");
source.resume = function() {
source.emit('resume');
};
}

dest.on("pause", function () {
dest.on('pause', function() {
source.pause();
});

dest.on("resume", function () {
dest.on('resume', function() {
if (source.readable) source.resume();
});
};
15 changes: 8 additions & 7 deletions lib/string_decoder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var StringDecoder = exports.StringDecoder = function (encoding) {
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/,'');
var StringDecoder = exports.StringDecoder = function(encoding) {
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
if (this.encoding === 'utf8') {
this.charBuffer = new Buffer(4);
this.charReceived = 0;
Expand All @@ -8,7 +8,7 @@ var StringDecoder = exports.StringDecoder = function (encoding) {
};


StringDecoder.prototype.write = function (buffer) {
StringDecoder.prototype.write = function(buffer) {
// If not utf8...
if (this.encoding !== 'utf8') {
return buffer.toString(this.encoding);
Expand All @@ -18,9 +18,9 @@ StringDecoder.prototype.write = function (buffer) {
// if our last write ended with an incomplete multibyte character
if (this.charLength) {
// determine how many remaining bytes this buffer has to offer for this char
var i = (buffer.length >= this.charLength - this.charReceived)
? this.charLength - this.charReceived
: buffer.length;
var i = (buffer.length >= this.charLength - this.charReceived) ?
this.charLength - this.charReceived :
buffer.length;

// add the new bytes to the char buffer
buffer.copy(this.charBuffer, this.charReceived, 0, i);
Expand All @@ -46,7 +46,8 @@ StringDecoder.prototype.write = function (buffer) {
// determine how many bytes we have to check at the end of this buffer
var i = (buffer.length >= 3) ? 3 : buffer.length;

// figure out if one of the last i bytes of our buffer announces an incomplete char
// Figure out if one of the last i bytes of our buffer announces an
// incomplete char.
for (; i > 0; i--) {
c = buffer[buffer.length - i];

Expand Down
5 changes: 3 additions & 2 deletions lib/sys.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var util = require("util");
var util = require('util');

var sysWarning;
if (!sysWarning) {
sysWarning = "The 'sys' module is now called 'util'. It should have a similar interface.";
sysWarning = 'The "sys" module is now called "util". ' +
'It should have a similar interface.';
// Uncomment in 2011
//util.error(sysWarning);
}
Expand Down
46 changes: 24 additions & 22 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ var assert = process.assert;
* To enable debug statements for the timers do NODE_DEBUG=8 ./node script.js
*/
var debugLevel = parseInt(process.env.NODE_DEBUG, 16);
function debug () {
if (debugLevel & 0x8) {
require('util').error.apply(this, arguments);
}
var debug;
if (debugLevel & 0x8) {
debug = function() { require('util').error.apply(this, arguments); };
} else {
debug = function() { };
}


// IDLE TIMEOUTS
//
// Because often many sockets will have the same idle timeout we will not
Expand All @@ -25,29 +27,29 @@ function debug () {
var lists = {};

// show the most idle item
function peek (list) {
function peek(list) {
if (list._idlePrev == list) return null;
return list._idlePrev;
}


// remove the most idle item from the list
function shift (list) {
function shift(list) {
var first = list._idlePrev;
remove(first);
return first;
}


// remove a item from its list
function remove (item) {
function remove(item) {
item._idleNext._idlePrev = item._idlePrev;
item._idlePrev._idleNext = item._idleNext;
}


// remove a item from its list and place at the end.
function append (list, item) {
function append(list, item) {
item._idleNext = list._idleNext;
list._idleNext._idlePrev = item;
item._idlePrev = list;
Expand All @@ -57,7 +59,7 @@ function append (list, item) {

// the main function - creates lists on demand and the watchers associated
// with them.
function insert (item, msecs) {
function insert(item, msecs) {
item._idleStart = new Date();
item._idleTimeout = msecs;

Expand All @@ -74,18 +76,18 @@ function insert (item, msecs) {

lists[msecs] = list;

list.callback = function () {
list.callback = function() {
debug('timeout callback ' + msecs);
// TODO - don't stop and start the watcher all the time.
// just set its repeat
var now = new Date();
debug("now: " + now);
debug('now: ' + now);
var first;
while (first = peek(list)) {
var diff = now - first._idleStart;
if (diff < msecs) {
list.again(msecs - diff);
debug(msecs + ' list wait because diff is ' + diff);
debug(msecs + ' list wait because diff is ' + diff);
return;
} else {
remove(first);
Expand All @@ -109,7 +111,7 @@ function insert (item, msecs) {
}


var unenroll = exports.unenroll = function (item) {
var unenroll = exports.unenroll = function(item) {
if (item._idleNext) {
remove(item);

Expand All @@ -125,7 +127,7 @@ var unenroll = exports.unenroll = function (item) {


// Does not start the time, just sets up the members needed.
exports.enroll = function (item, msecs) {
exports.enroll = function(item, msecs) {
// if this item was already in a list somewhere
// then we should unenroll it from that
if (item._idleNext) unenroll(item);
Expand All @@ -137,7 +139,7 @@ exports.enroll = function (item, msecs) {

// call this whenever the item is active (not idle)
// it will reset its timeout.
exports.active = function (item) {
exports.active = function(item) {
var msecs = item._idleTimeout;
if (msecs >= 0) {
var list = lists[msecs];
Expand All @@ -162,8 +164,8 @@ exports.active = function (item) {
*/


exports.setTimeout = function (callback, after) {
var timer;
exports.setTimeout = function(callback, after) {
var timer;

if (after <= 0) {
// Use the slow case for after == 0
Expand All @@ -186,7 +188,7 @@ exports.setTimeout = function (callback, after) {
*/
if (arguments.length > 2) {
var args = Array.prototype.slice.call(arguments, 2);
var c = function () {
var c = function() {
callback.apply(timer, args);
};

Expand All @@ -207,7 +209,7 @@ exports.setTimeout = function (callback, after) {
};


exports.clearTimeout = function (timer) {
exports.clearTimeout = function(timer) {
if (timer && (timer.callback || timer._onTimeout)) {
timer.callback = timer._onTimeout = null;
exports.unenroll(timer);
Expand All @@ -216,12 +218,12 @@ exports.clearTimeout = function (timer) {
};


exports.setInterval = function (callback, repeat) {
exports.setInterval = function(callback, repeat) {
var timer = new Timer();

if (arguments.length > 2) {
var args = Array.prototype.slice.call(arguments, 2);
timer.callback = function () {
timer.callback = function() {
callback.apply(timer, args);
};
} else {
Expand All @@ -233,7 +235,7 @@ exports.setInterval = function (callback, repeat) {
};


exports.clearInterval = function (timer) {
exports.clearInterval = function(timer) {
if (timer instanceof Timer) {
timer.callback = null;
timer.stop();
Expand Down
33 changes: 13 additions & 20 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ var inherits = require('util').inherits;
// TODO:
// cleartext.credentials (by mirroring from pair object)
// cleartext.getCertificate() (by mirroring from pair.credentials.context)
function Server ( /* [options], listener */) {
function Server(/* [options], listener */) {
var options, listener;
if (typeof arguments[0] == "object") {
if (typeof arguments[0] == 'object') {
options = arguments[0];
listener = arguments[1];
} else if (typeof arguments[0] == "function") {
} else if (typeof arguments[0] == 'function') {
options = {};
listener = arguments[0];
}
Expand All @@ -51,10 +51,9 @@ function Server ( /* [options], listener */) {
var self = this;

// constructor call
net.Server.call(this, function (socket) {
var creds = crypto.createCredentials({ key: self.key,
cert: self.cert,
ca: self.ca });
net.Server.call(this, function(socket) {
var creds = crypto.createCredentials(
{ key: self.key, cert: self.cert, ca: self.ca });
creds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');

var pair = crypto.createPair(creds,
Expand All @@ -63,30 +62,24 @@ function Server ( /* [options], listener */) {
pair.encrypted.pipe(socket);
socket.pipe(pair.encrypted);

pair.on('secure', function () {
pair.on('secure', function() {
var verifyError = pair._ssl.verifyError();

if (verifyError) {
if (self.unauthorizedPeers) {
self.emit('unauthorized', pair.cleartext, verifyError);
} else {
console.error("REJECT PEER. verify error: %s", verifyError);
console.error('REJECT PEER. verify error: %s', verifyError);
socket.destroy();
}
} else {
self.emit('authorized', pair.cleartext);
}
});

pair.on('error', function (e) {
pair.on('error', function(e) {
console.log('pair got error: ' + e);

// TODO better way to get error code.
if (/no shared cipher/.test(e.message)) {
;
} else {
self.emit('error', e);
}
self.emit('error', e);
});

pair.cleartext.on('error', function(err) {
Expand All @@ -110,13 +103,13 @@ function Server ( /* [options], listener */) {

inherits(Server, net.Server);
exports.Server = Server;
exports.createServer = function (options, listener) {
exports.createServer = function(options, listener) {
return new Server(options, listener);
};


Server.prototype.setOptions = function (options) {
if (typeof options.unauthorizedPeers == "boolean") {
Server.prototype.setOptions = function(options) {
if (typeof options.unauthorizedPeers == 'boolean') {
this.unauthorizedPeers = options.unauthorizedPeers;
} else {
this.unauthorizedPeers = false;
Expand Down
Loading

0 comments on commit dd53cee

Please sign in to comment.