|
@ -508,33 +508,49 @@ exports.createSecurePair = function(credentials, |
|
|
* Because it is also called everywhere, we also check if the connection has |
|
|
* Because it is also called everywhere, we also check if the connection has |
|
|
* completed negotiation and emit 'secure' from here if it has. |
|
|
* completed negotiation and emit 'secure' from here if it has. |
|
|
*/ |
|
|
*/ |
|
|
SecurePair.prototype._cycle = function() { |
|
|
SecurePair.prototype._cycle = function(depth) { |
|
|
|
|
|
depth = depth ? depth : 0; |
|
|
if (this._done) { |
|
|
if (this._done) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Make this function reentrant.
|
|
|
if(depth == 0) this._writeCalled = false; |
|
|
if (this._cycleLock) return; |
|
|
|
|
|
this._cycleLock = true; |
|
|
|
|
|
this._writeCalled = false; |
|
|
|
|
|
|
|
|
|
|
|
var established = this._secureEstablished; |
|
|
var established = this._secureEstablished; |
|
|
|
|
|
|
|
|
this.encrypted._pull(); |
|
|
if (!this._cycleEncryptedPullLock) { |
|
|
this.cleartext._pull(); |
|
|
this._cycleEncryptedPullLock = true; |
|
|
this.cleartext._push(); |
|
|
this.encrypted._pull(); |
|
|
this.encrypted._push(); |
|
|
this._cycleEncryptedPullLock = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!this._cycleCleartextPullLock) { |
|
|
|
|
|
this._cycleCleartextPullLock = true; |
|
|
|
|
|
this.cleartext._pull(); |
|
|
|
|
|
this._cycleCleartextPullLock = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this._cycleLock = false; |
|
|
if (!this._cycleCleartextPushLock) { |
|
|
|
|
|
this._cycleCleartextPushLock = true; |
|
|
|
|
|
this.cleartext._push(); |
|
|
|
|
|
this._cycleCleartextPushLock = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!this._cycleEncryptedPushLock) { |
|
|
|
|
|
this._cycleEncryptedPushLock = true; |
|
|
|
|
|
this.encrypted._push(); |
|
|
|
|
|
this._cycleEncryptedPushLock = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (this._done) { |
|
|
if (this._done) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ((!established && this._secureEstablished) || this._writeCalled) { |
|
|
if ((!established && this._secureEstablished) || |
|
|
|
|
|
(depth == 0 && this._writeCalled)) { |
|
|
// If we were not established but now we are, let's cycle again.
|
|
|
// If we were not established but now we are, let's cycle again.
|
|
|
// Or if there is some data to write...
|
|
|
// Or if there is some data to write...
|
|
|
this._cycle(); |
|
|
this._cycle(depth + 1); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|