MCPcopy Index your code
hub / github.com/nodejs/node / TLSSocket

Function TLSSocket

lib/internal/tls/wrap.js:621–725  ·  view source on GitHub ↗

* Provides a wrap of socket stream to do encrypted communication.

(socket, opts)

Source from the content-addressed store, hash-verified

619 */
620
621function TLSSocket(socket, opts) {
622 const tlsOptions = { ...opts };
623 let enableTrace = tlsOptions.enableTrace;
624
625 if (enableTrace == null) {
626 enableTrace = traceTls;
627
628 if (enableTrace && !tlsTracingWarned) {
629 tlsTracingWarned = true;
630 process.emitWarning('Enabling --trace-tls can expose sensitive data in ' +
631 'the resulting log.');
632 }
633 } else {
634 validateBoolean(enableTrace, 'options.enableTrace');
635 }
636
637 if (tlsOptions.ALPNProtocols)
638 tls.convertALPNProtocols(tlsOptions.ALPNProtocols, tlsOptions);
639
640 this._tlsOptions = tlsOptions;
641 this._secureEstablished = false;
642 this._securePending = false;
643 this._newSessionPending = false;
644 this._controlReleased = false;
645 this.secureConnecting = true;
646 this._SNICallback = null;
647 this[kALPNCallback] = null;
648 this.servername = null;
649 this.alpnProtocol = null;
650 this.authorized = false;
651 this.authorizationError = null;
652 this[kRes] = null;
653 this[kIsVerified] = false;
654 this[kPendingSession] = null;
655
656 let wrap;
657 let handle;
658 let wrapHasActiveWriteFromPrevOwner;
659
660 if (socket) {
661 if (socket instanceof net.Socket && socket._handle) {
662 // 1. connected socket
663 wrap = socket;
664 } else {
665 // 2. socket has no handle so it is js not c++
666 // 3. unconnected sockets are wrapped
667 // TLS expects to interact from C++ with a net.Socket that has a C++ stream
668 // handle, but a JS stream doesn't have one. Wrap it up to make it look like
669 // a socket.
670 wrap = new JSStreamSocket(socket);
671 }
672
673 handle = wrap._handle;
674 wrapHasActiveWriteFromPrevOwner = wrap.writableLength > 0;
675 } else {
676 // 4. no socket, one will be created with net.Socket().connect
677 wrap = null;
678 wrapHasActiveWriteFromPrevOwner = false;

Callers

nothing calls this directly

Calls 5

_initMethod · 0.80
debugFunction · 0.50
onMethod · 0.45
writeMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…