Skip to content

Commit 93da5d7

Browse files
committed
quic: add more diagnostic channels
Signed-off-by: James M Snell <jasnell@gmail.com>
1 parent 83257d1 commit 93da5d7

File tree

1 file changed

+118
-1
lines changed

1 file changed

+118
-1
lines changed

lib/internal/quic/quic.js

+118-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ const onEndpointErrorChannel = dc.channel('quic.endpoint.error');
143143
const onEndpointBusyChangeChannel = dc.channel('quic.endpoint.busy.change');
144144
const onEndpointClientSessionChannel = dc.channel('quic.session.created.client');
145145
const onEndpointServerSessionChannel = dc.channel('quic.session.created.server');
146+
const onSessionOpenStreamChannel = dc.channel('quic.session.open.stream');
147+
const onSessionReceivedStreamChannel = dc.channel('quic.session.received.stream');
148+
const onSessionSendDatagramChannel = dc.channel('quic.session.send.datagram');
149+
const onSessionUpdateKeyChannel = dc.channel('quic.session.update.key');
150+
const onSessionClosingChannel = dc.channel('quic.session.closing');
151+
const onSessionClosedChannel = dc.channel('quic.session.closed');
152+
const onSessionReceiveDatagramChannel = dc.channel('quic.session.receive.datagram');
153+
const onSessionReceiveDatagramStatusChannel = dc.channel('quic.session.receive.datagram.status');
154+
const onSessionPathValidationChannel = dc.channel('quic.session.path.validation');
155+
const onSessionTicketChannel = dc.channel('quic.session.ticket');
156+
const onSessionVersionNegotiationChannel = dc.channel('quic.session.version.negotiation');
157+
const onSessionHandshakeChannel = dc.channel('quic.session.handshake');
146158

147159
/**
148160
* @typedef {import('../socketaddress.js').SocketAddress} SocketAddress
@@ -873,6 +885,13 @@ class QuicSession {
873885
const stream = new QuicStream(kPrivateConstructor, this.#streamConfig, handle,
874886
this, 0 /* Bidirectional */);
875887
this.#streams.add(stream);
888+
889+
if (onSessionOpenStreamChannel.hasSubscribers) {
890+
onSessionOpenStreamChannel.publish({
891+
stream,
892+
session: this,
893+
});
894+
}
876895
return stream;
877896
}
878897

@@ -893,6 +912,14 @@ class QuicSession {
893912
const stream = new QuicStream(kPrivateConstructor, this.#streamConfig, handle,
894913
this, 1 /* Unidirectional */);
895914
this.#streams.add(stream);
915+
916+
if (onSessionOpenStreamChannel.hasSubscribers) {
917+
onSessionOpenStreamChannel.publish({
918+
stream,
919+
session: this,
920+
});
921+
}
922+
896923
return stream;
897924
}
898925

@@ -923,7 +950,17 @@ class QuicSession {
923950
datagram.byteOffset,
924951
datagram.byteLength);
925952
}
926-
return this.#handle.sendDatagram(datagram);
953+
const id = this.#handle.sendDatagram(datagram);
954+
955+
if (onSessionSendDatagramChannel.hasSubscribers) {
956+
onSessionSendDatagramChannel.publish({
957+
id,
958+
length: datagram.byteLength,
959+
session: this,
960+
});
961+
}
962+
963+
return id;
927964
}
928965

929966
/**
@@ -934,6 +971,11 @@ class QuicSession {
934971
throw new ERR_INVALID_STATE('Session is closed');
935972
}
936973
this.#handle.updateKey();
974+
if (onSessionUpdateKeyChannel.hasSubscribers) {
975+
onSessionUpdateKeyChannel.publish({
976+
session: this,
977+
});
978+
}
937979
}
938980

939981
/**
@@ -950,6 +992,11 @@ class QuicSession {
950992
if (!this.#isClosedOrClosing) {
951993
this.#isPendingClose = true;
952994
this.#handle?.gracefulClose();
995+
if (onSessionClosingChannel.hasSubscribers) {
996+
onSessionClosingChannel.publish({
997+
session: this,
998+
});
999+
}
9531000
}
9541001
return this.closed;
9551002
}
@@ -1023,6 +1070,12 @@ class QuicSession {
10231070
this.#handle.destroy();
10241071
this.#handle = undefined;
10251072

1073+
if (onSessionClosedChannel.hasSubscribers) {
1074+
onSessionClosedChannel.publish({
1075+
session: this,
1076+
});
1077+
}
1078+
10261079
return this.closed;
10271080
}
10281081

@@ -1069,6 +1122,14 @@ class QuicSession {
10691122
assert(this.#ondatagram, 'Unexpected datagram event');
10701123
if (this.destroyed) return;
10711124
this.#ondatagram(u8, early);
1125+
1126+
if (onSessionReceiveDatagramChannel.hasSubscribers) {
1127+
onSessionReceiveDatagramChannel.publish({
1128+
length: u8.byteLength,
1129+
early,
1130+
session: this,
1131+
});
1132+
}
10721133
}
10731134

10741135
/**
@@ -1080,6 +1141,14 @@ class QuicSession {
10801141
// The ondatagramstatus callback may not have been specified. That's ok.
10811142
// We'll just ignore the event in that case.
10821143
this.#ondatagramstatus?.(id, status);
1144+
1145+
if (onSessionReceiveDatagramStatusChannel.hasSubscribers) {
1146+
onSessionReceiveDatagramStatusChannel.publish({
1147+
id,
1148+
status,
1149+
session: this,
1150+
});
1151+
}
10831152
}
10841153

10851154
/**
@@ -1098,6 +1167,18 @@ class QuicSession {
10981167
if (this.destroyed) return;
10991168
this.#onpathvalidation(result, newLocalAddress, newRemoteAddress,
11001169
oldLocalAddress, oldRemoteAddress, preferredAddress);
1170+
1171+
if (onSessionPathValidationChannel.hasSubscribers) {
1172+
onSessionPathValidationChannel.publish({
1173+
result,
1174+
newLocalAddress,
1175+
newRemoteAddress,
1176+
oldLocalAddress,
1177+
oldRemoteAddress,
1178+
preferredAddress,
1179+
session: this,
1180+
});
1181+
}
11011182
}
11021183

11031184
/**
@@ -1109,6 +1190,12 @@ class QuicSession {
11091190
assert(this.#onsessionticket, 'Unexpected session ticket event');
11101191
if (this.destroyed) return;
11111192
this.#onsessionticket(ticket);
1193+
if (onSessionTicketChannel.hasSubscribers) {
1194+
onSessionTicketChannel.publish({
1195+
ticket,
1196+
session: this,
1197+
});
1198+
}
11121199
}
11131200

11141201
/**
@@ -1123,6 +1210,15 @@ class QuicSession {
11231210
if (this.destroyed) return;
11241211
this.#onversionnegotiation(version, requestedVersions, supportedVersions);
11251212
this.destroy(new ERR_QUIC_VERSION_NEGOTIATION_ERROR());
1213+
1214+
if (onSessionVersionNegotiationChannel.hasSubscribers) {
1215+
onSessionVersionNegotiationChannel.publish({
1216+
version,
1217+
requestedVersions,
1218+
supportedVersions,
1219+
session: this,
1220+
});
1221+
}
11261222
}
11271223

11281224
/**
@@ -1141,6 +1237,19 @@ class QuicSession {
11411237
// We'll just ignore the event in that case.
11421238
this.#onhandshake?.(sni, alpn, cipher, cipherVersion, validationErrorReason,
11431239
validationErrorCode, earlyDataAccepted);
1240+
1241+
if (onSessionHandshakeChannel.hasSubscribers) {
1242+
onSessionHandshakeChannel.publish({
1243+
sni,
1244+
alpn,
1245+
cipher,
1246+
cipherVersion,
1247+
validationErrorReason,
1248+
validationErrorCode,
1249+
earlyDataAccepted,
1250+
session: this,
1251+
});
1252+
}
11441253
}
11451254

11461255
/**
@@ -1161,6 +1270,13 @@ class QuicSession {
11611270
this.#streams.add(stream);
11621271

11631272
this.#onstream(stream);
1273+
1274+
if (onSessionReceivedStreamChannel.hasSubscribers) {
1275+
onSessionReceivedStreamChannel.publish({
1276+
stream,
1277+
session: this,
1278+
});
1279+
}
11641280
}
11651281

11661282
[kRemoveStream](stream) {
@@ -1442,6 +1558,7 @@ class QuicEndpoint {
14421558
#newSession(handle) {
14431559
const session = new QuicSession(kPrivateConstructor, this.#sessionConfig, handle, this);
14441560
this.#sessions.add(session);
1561+
return session;
14451562
}
14461563

14471564
/**

0 commit comments

Comments
 (0)