aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-07-06 17:55:27 -0300
committerGravatar GitHub <noreply@github.com> 2023-07-06 13:55:27 -0700
commit954b6fcaf39c2346762ff40e9cf25705fcbd7ffb (patch)
tree5a8665eb68b02a13e43a05375be8270217353aea /src/js
parentabe095dd1e0962e3510596ccb8c66e0695947c3a (diff)
downloadbun-954b6fcaf39c2346762ff40e9cf25705fcbd7ffb.tar.gz
bun-954b6fcaf39c2346762ff40e9cf25705fcbd7ffb.tar.zst
bun-954b6fcaf39c2346762ff40e9cf25705fcbd7ffb.zip
refactor (#3543)
Diffstat (limited to 'src/js')
-rw-r--r--src/js/node/net.js29
-rw-r--r--src/js/out/modules/node/net.js17
2 files changed, 25 insertions, 21 deletions
diff --git a/src/js/node/net.js b/src/js/node/net.js
index 1b7742dd1..6c690b349 100644
--- a/src/js/node/net.js
+++ b/src/js/node/net.js
@@ -120,11 +120,16 @@ const Socket = (function (InternalSocket) {
socket.ref();
self[bunSocketInternal] = socket;
self.connecting = false;
- self.emit("connect", self);
+ if (!self.#upgraded) {
+ // this is not actually emitted on nodejs when socket used on the connection
+ // this is already emmited on non-TLS socket and on TLS socket is emmited secureConnect on handshake
+ self.emit("connect", self);
+ }
Socket.#Drain(socket);
},
handshake(socket, success, verifyError) {
const { data: self } = socket;
+
self._securePending = false;
self.secureConnecting = false;
self._secureEstablished = !!success;
@@ -301,6 +306,7 @@ const Socket = (function (InternalSocket) {
_parent;
_parentWrap;
#socket;
+ #upgraded;
constructor(options) {
const { socket, signal, write, read, allowHalfOpen = false, ...opts } = options || {};
@@ -314,6 +320,7 @@ const Socket = (function (InternalSocket) {
this._parent = this;
this._parentWrap = this;
this.#pendingRead = undefined;
+ this.#upgraded = false;
if (socket instanceof Socket) {
this.#socket = socket;
}
@@ -442,7 +449,9 @@ const Socket = (function (InternalSocket) {
const socket = connection[bunSocketInternal];
if (socket) {
- const result = socket.wrapTLS({
+ this.connecting = true;
+ this.#upgraded = true;
+ const result = socket.upgradeTLS({
data: this,
tls,
socket: Socket.#Handlers,
@@ -453,13 +462,7 @@ const Socket = (function (InternalSocket) {
connection[bunSocketInternal] = raw;
raw.timeout(raw.timeout);
raw.connecting = false;
- // set new socket
this[bunSocketInternal] = tls;
- tls.timeout(tls.timeout);
- tls.connecting = true;
- this[bunSocketInternal] = socket;
- // start tls
- tls.open();
} else {
this[bunSocketInternal] = null;
throw new Error("Invalid socket");
@@ -470,7 +473,9 @@ const Socket = (function (InternalSocket) {
const socket = connection[bunSocketInternal];
if (!socket) return;
- const result = socket.wrapTLS({
+ this.connecting = true;
+ this.#upgraded = true;
+ const result = socket.upgradeTLS({
data: this,
tls,
socket: Socket.#Handlers,
@@ -482,13 +487,7 @@ const Socket = (function (InternalSocket) {
connection[bunSocketInternal] = raw;
raw.timeout(raw.timeout);
raw.connecting = false;
- // set new socket
this[bunSocketInternal] = tls;
- tls.timeout(tls.timeout);
- tls.connecting = true;
- this[bunSocketInternal] = socket;
- // start tls
- tls.open();
} else {
this[bunSocketInternal] = null;
throw new Error("Invalid socket");
diff --git a/src/js/out/modules/node/net.js b/src/js/out/modules/node/net.js
index c34f86b04..7f3102648 100644
--- a/src/js/out/modules/node/net.js
+++ b/src/js/out/modules/node/net.js
@@ -62,7 +62,9 @@ var isIPv4 = function(s) {
},
open(socket) {
const self = socket.data;
- socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1, self.emit("connect", self), Socket2.#Drain(socket);
+ if (socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1, !self.#upgraded)
+ self.emit("connect", self);
+ Socket2.#Drain(socket);
},
handshake(socket, success, verifyError) {
const { data: self } = socket;
@@ -173,6 +175,7 @@ var isIPv4 = function(s) {
_parent;
_parentWrap;
#socket;
+ #upgraded;
constructor(options) {
const { socket, signal, write, read, allowHalfOpen = !1, ...opts } = options || {};
super({
@@ -181,7 +184,7 @@ var isIPv4 = function(s) {
readable: !0,
writable: !0
});
- if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = void 0, socket instanceof Socket2)
+ if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = void 0, this.#upgraded = !1, socket instanceof Socket2)
this.#socket = socket;
signal?.once("abort", () => this.destroy()), this.once("connect", () => this.emit("ready"));
}
@@ -256,14 +259,15 @@ var isIPv4 = function(s) {
if (connection) {
const socket2 = connection[bunSocketInternal];
if (socket2) {
- const result = socket2.wrapTLS({
+ this.connecting = !0, this.#upgraded = !0;
+ const result = socket2.upgradeTLS({
data: this,
tls,
socket: Socket2.#Handlers
});
if (result) {
const [raw, tls2] = result;
- connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2, tls2.timeout(tls2.timeout), tls2.connecting = !0, this[bunSocketInternal] = socket2, tls2.open();
+ connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;
} else
throw this[bunSocketInternal] = null, new Error("Invalid socket");
} else
@@ -271,14 +275,15 @@ var isIPv4 = function(s) {
const socket3 = connection[bunSocketInternal];
if (!socket3)
return;
- const result = socket3.wrapTLS({
+ this.connecting = !0, this.#upgraded = !0;
+ const result = socket3.upgradeTLS({
data: this,
tls,
socket: Socket2.#Handlers
});
if (result) {
const [raw, tls2] = result;
- connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2, tls2.timeout(tls2.timeout), tls2.connecting = !0, this[bunSocketInternal] = socket3, tls2.open();
+ connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;
} else
throw this[bunSocketInternal] = null, new Error("Invalid socket");
});