@ -54,13 +54,14 @@ function CryptoStream(pair) {
this . _ writeState = true ;
this . _ writeState = true ;
this . _ pending = [ ] ;
this . _ pending = [ ] ;
this . _ pendingCallbacks = [ ] ;
this . _ pendingCallbacks = [ ] ;
this . _ pendingBytes = 0 ;
}
}
util . inherits ( CryptoStream , stream . Stream ) ;
util . inherits ( CryptoStream , stream . Stream ) ;
CryptoStream . prototype . write = function ( data /* , encoding, cb */ ) {
CryptoStream . prototype . write = function ( data /* , encoding, cb */ ) {
if ( this == this . pair . cleartext ) {
if ( this == this . pair . cleartext ) {
debug ( 'cleartext.write called with ((( ' + data . toString ( ) + '))) ') ;
debug ( 'cleartext.write called with ' + data . length + ' bytes ') ;
} else {
} else {
debug ( 'encrypted.write called with ' + data . length + ' bytes' ) ;
debug ( 'encrypted.write called with ' + data . length + ' bytes' ) ;
}
}
@ -90,10 +91,12 @@ CryptoStream.prototype.write = function(data /* , encoding, cb */) {
this . _ pending . push ( data ) ;
this . _ pending . push ( data ) ;
this . _ pendingCallbacks . push ( cb ) ;
this . _ pendingCallbacks . push ( cb ) ;
this . _ pendingBytes += data . length ;
this . pair . _ writeCalled = true ;
this . pair . _ writeCalled = true ;
this . pair . _ cycle ( ) ;
this . pair . _ cycle ( ) ;
return this . _ writeState ;
return this . _ pendingBytes < 128 * 1024 ;
} ;
} ;
@ -263,7 +266,7 @@ CryptoStream.prototype._push = function() {
// Bail out if we didn't read any data.
// Bail out if we didn't read any data.
if ( bytesRead == 0 ) {
if ( bytesRead == 0 ) {
if ( this . _ p endingBytes( ) == 0 && this . _ destroyAfterPush ) {
if ( this . _ internallyP endingBytes( ) == 0 && this . _ destroyAfterPush ) {
this . _ done ( ) ;
this . _ done ( ) ;
}
}
return ;
return ;
@ -272,7 +275,7 @@ CryptoStream.prototype._push = function() {
var chunk = pool . slice ( 0 , bytesRead ) ;
var chunk = pool . slice ( 0 , bytesRead ) ;
if ( this === this . pair . cleartext ) {
if ( this === this . pair . cleartext ) {
debug ( 'cleartext emit "data" called with ((( ' + chunk . toString ( ) + '))) ') ;
debug ( 'cleartext emit "data" with ' + bytesRead + ' bytes ') ;
} else {
} else {
debug ( 'encrypted emit "data" with ' + bytesRead + ' bytes' ) ;
debug ( 'encrypted emit "data" with ' + bytesRead + ' bytes' ) ;
}
}
@ -307,6 +310,8 @@ CryptoStream.prototype._push = function() {
CryptoStream . prototype . _ pull = function ( ) {
CryptoStream . prototype . _ pull = function ( ) {
var havePending = this . _ pending . length > 0 ;
var havePending = this . _ pending . length > 0 ;
assert ( havePending || this . _ pendingBytes == 0 ) ;
while ( this . _ pending . length > 0 ) {
while ( this . _ pending . length > 0 ) {
if ( ! this . pair . _ ssl ) break ;
if ( ! this . pair . _ ssl ) break ;
@ -355,6 +360,9 @@ CryptoStream.prototype._pull = function() {
break ;
break ;
}
}
this . _ pendingBytes -= tmp . length ;
assert ( this . _ pendingBytes >= 0 ) ;
if ( cb ) cb ( ) ;
if ( cb ) cb ( ) ;
assert ( rv === tmp . length ) ;
assert ( rv === tmp . length ) ;
@ -375,7 +383,7 @@ function CleartextStream(pair) {
util . inherits ( CleartextStream , CryptoStream ) ;
util . inherits ( CleartextStream , CryptoStream ) ;
CleartextStream . prototype . _ p endingBytes = function ( ) {
CleartextStream . prototype . _ internallyP endingBytes = function ( ) {
if ( this . pair . _ ssl ) {
if ( this . pair . _ ssl ) {
return this . pair . _ ssl . clearPending ( ) ;
return this . pair . _ ssl . clearPending ( ) ;
} else {
} else {
@ -403,7 +411,7 @@ function EncryptedStream(pair) {
util . inherits ( EncryptedStream , CryptoStream ) ;
util . inherits ( EncryptedStream , CryptoStream ) ;
EncryptedStream . prototype . _ p endingBytes = function ( ) {
EncryptedStream . prototype . _ internallyP endingBytes = function ( ) {
if ( this . pair . _ ssl ) {
if ( this . pair . _ ssl ) {
return this . pair . _ ssl . encPending ( ) ;
return this . pair . _ ssl . encPending ( ) ;
} else {
} else {
@ -539,24 +547,28 @@ SecurePair.prototype._cycle = function(depth) {
if ( ! this . _ cycleEncryptedPullLock ) {
if ( ! this . _ cycleEncryptedPullLock ) {
this . _ cycleEncryptedPullLock = true ;
this . _ cycleEncryptedPullLock = true ;
debug ( "encrypted._pull" ) ;
this . encrypted . _ pull ( ) ;
this . encrypted . _ pull ( ) ;
this . _ cycleEncryptedPullLock = false ;
this . _ cycleEncryptedPullLock = false ;
}
}
if ( ! this . _ cycleCleartextPullLock ) {
if ( ! this . _ cycleCleartextPullLock ) {
this . _ cycleCleartextPullLock = true ;
this . _ cycleCleartextPullLock = true ;
debug ( "cleartext._pull" ) ;
this . cleartext . _ pull ( ) ;
this . cleartext . _ pull ( ) ;
this . _ cycleCleartextPullLock = false ;
this . _ cycleCleartextPullLock = false ;
}
}
if ( ! this . _ cycleCleartextPushLock ) {
if ( ! this . _ cycleCleartextPushLock ) {
this . _ cycleCleartextPushLock = true ;
this . _ cycleCleartextPushLock = true ;
debug ( "cleartext._push" ) ;
this . cleartext . _ push ( ) ;
this . cleartext . _ push ( ) ;
this . _ cycleCleartextPushLock = false ;
this . _ cycleCleartextPushLock = false ;
}
}
if ( ! this . _ cycleEncryptedPushLock ) {
if ( ! this . _ cycleEncryptedPushLock ) {
this . _ cycleEncryptedPushLock = true ;
this . _ cycleEncryptedPushLock = true ;
debug ( "encrypted._push" ) ;
this . encrypted . _ push ( ) ;
this . encrypted . _ push ( ) ;
this . _ cycleEncryptedPushLock = false ;
this . _ cycleEncryptedPushLock = false ;
}
}