Browse Source

Fix style in SSL patch

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
129310676d
  1. 24
      lib/net.js

24
lib/net.js

@ -257,6 +257,7 @@ var securePool = null;
function allocNewSecurePool () {
securePool = new Buffer(40*1024);
}
var emptyBuffer = null;
function allocEmptyBuffer () {
emptyBuffer = new Buffer(1);
@ -295,7 +296,9 @@ function initStream (self) {
if (!securePool) allocNewSecurePool();
secureBytesRead = read(self.fd, securePool, 0, securePool.length);
self.secureStream.readInject(securePool, 0, secureBytesRead);
bytesRead = self.secureStream.readExtract(pool, pool.used, pool.length - pool.used);
bytesRead = self.secureStream.readExtract(pool,
pool.used,
pool.length - pool.used);
if (!self.secureEstablished) {
if (self.secureStream.isInitFinished()) {
self.secureEstablished = true;
@ -324,8 +327,11 @@ function initStream (self) {
if (self.server) {
self._checkForSecureHandshake();
} else {
if (self.secureEstablised) self.flush();
else self._checkForSecureHandshake();
if (self.secureEstablised) {
self.flush();
} else {
self._checkForSecureHandshake();
}
}
} else if (bytesRead === 0) {
self.readable = false;
@ -434,16 +440,16 @@ Stream.prototype.setSecure = function(credentials) {
} else {
this.credentials = credentials;
}
this.secureStream = new SecureStream(this.credentials.context, this.server ? 1 : 0);
if (!this.server) {
// If client, trigger handshake
this._checkForSecureHandshake();
}
}
Stream.prototype.verifyPeer = function() {
if (!this.secure) {
throw new Error('Stream is not a secure stream.');
@ -451,12 +457,14 @@ Stream.prototype.verifyPeer = function() {
return this.secureStream.verifyPeer(this.credentials.context);
}
Stream.prototype._checkForSecureHandshake = function() {
// Do an empty write to see if we need to write out as part of handshake
if (!emptyBuffer) allocEmptyBuffer();
this.write(emptyBuffer);
}
Stream.prototype.getPeerCertificate = function(credentials) {
if (!this.secure) {
throw new Error('Stream is not a secure stream.');
@ -464,6 +472,7 @@ Stream.prototype.getPeerCertificate = function(credentials) {
return this.secureStream.getPeerCertificate();
}
Stream.prototype.getCipher = function() {
if (!this.secure) {
throw new Error('Stream is not a secure stream.');
@ -535,7 +544,8 @@ Stream.prototype._shutdownSecure = function () {
var secureLen = this.secureStream.writeExtract(securePool, 0, securePool.length);
try {
var secureBytesWritten = write(this.fd, securePool, 0, secureLen);
} catch (e) {}
} catch (e) {
}
}
// Directly writes the data to socket.
@ -552,10 +562,10 @@ Stream.prototype._writeOut = function (data, encoding) {
else throw new Error('Stream is not writable');
}
var buffer, off, len;
var bytesWritten, charsWritten;
var queuedData = false;
if (typeof data != 'string') {
// 'data' is a buffer, ignore 'encoding'
buffer = data;

Loading…
Cancel
Save