Skip to content

Commit

Permalink
Merge branch 'thirdpartylibtracker'
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrichter committed Sep 16, 2023
2 parents 5bd062e + c7ecc39 commit b234f2e
Show file tree
Hide file tree
Showing 18 changed files with 285 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -759,6 +759,8 @@ third_party/quiche/quiche/quic/core/uber_quic_stream_id_manager.cc
third_party/quiche/quiche/quic/core/uber_quic_stream_id_manager.h
third_party/quiche/quiche/quic/core/uber_received_packet_manager.cc
third_party/quiche/quiche/quic/core/uber_received_packet_manager.h
third_party/quiche/quiche/quic/core/web_transport_stats.h
third_party/quiche/quiche/quic/core/web_transport_stats.cc
third_party/quiche/quiche/quic/platform/api/quic_bug_tracker.h
third_party/quiche/quiche/quic/platform/api/quic_client_stats.h
third_party/quiche/quiche/quic/platform/api/quic_export.h
Expand Down
1 change: 1 addition & 0 deletions lib/dom.ts
Expand Up @@ -22,6 +22,7 @@ export interface WebTransportStats {
smoothedRtt: number
rttVariation: number
minRtt: number
estimatedSendRate: bigint
datagrams: WebTransportDatagramStats
}

Expand Down
112 changes: 93 additions & 19 deletions lib/session.js
Expand Up @@ -13,6 +13,8 @@ const log = logger(`webtransport:http3wtsession(${process.pid})`)
* @typedef {import('./types').DatagramReceivedEvent} DatagramReceivedEvent
* @typedef {import('./types').DatagramSendEvent} DatagramSendEvent
* @typedef {import('./types').GoawayReceivedEvent} GoawayReceivedEvent
* @typedef {import('./types').DatagramStatsEvent} DatagramStatsEvent
* @typedef {import('./types').SessionStatsEvent} SessionStatsEvent
* @typedef {import('./types').NewStreamEvent} NewStreamEvent
*
* @typedef {import('./dom').WebTransportCloseInfo} WebTransportCloseInfo
Expand All @@ -23,6 +25,7 @@ const log = logger(`webtransport:http3wtsession(${process.pid})`)
* @typedef {import('./dom').WebTransportReliabilityMode} WebTransportReliabilityMode
* @typedef {import('./dom').WebTransportCongestionControl} WebTransportCongestionControl
* @typedef {import('./dom').WebTransportStats} WebTransportStats
* @typedef {import('./dom').WebTransportDatagramStats} WebTransportDatagramStats
*
* @typedef {import('./types').NativeHttp3WTSession} NativeHttp3WTSession
*
Expand Down Expand Up @@ -152,6 +155,16 @@ export class Http3WTSession {
/** @type {Array<(err?: Error) => void>} */
this.rejectUniDi = []

/** @type {Array<(stats: WebTransportStats) => void>} */
this.resolveSessionStats = []
/** @type {Array<(err?: Error) => void>} */
this.rejectSessionStats = []

/** @type {Array<(stats: WebTransportDatagramStats) => void>} */
this.resolveDatagramStats = []
/** @type {Array<(err?: Error) => void>} */
this.rejectDatagramStats = []

/** @type {Set<WebTransportSendStream>} */
this.sendStreams = new Set()
/** @type {Set<WebTransportReceiveStream>} */
Expand All @@ -176,25 +189,72 @@ export class Http3WTSession {
}

getStats() {
return Promise.resolve({
timestamp: Date.now(),
bytesSent: BigInt(0),
packetsSent: BigInt(0),
packetsLost: BigInt(0),
numOutgoingStreamsCreated: 0,
numIncomingStreamsCreated: 0,
bytesReceived: BigInt(0),
packetsReceived: BigInt(0),
smoothedRtt: 0,
rttVariation: 0,
minRtt: 0,
datagrams: {
timestamp: Date.now(),
expiredOutgoing: BigInt(0),
droppedIncoming: BigInt(0),
lostOutgoing: BigInt(0)
}
if (this.objint == null) {
throw new Error('this.objint not set')
}
const prom = new Promise((resolve, reject) => {
this.resolveSessionStats.push(resolve)
this.rejectSessionStats.push(reject)
})
this.objint.orderSessionStats()
return prom
}

/**
* @param {SessionStatsEvent} evt
*/
onSessionStats({
timestamp,
expiredOutgoing = BigInt(0),
lostOutgoing = BigInt(0),
// non Datagram
minRtt = 0,
smoothedRtt = 0,
rttVariation = 0,
estimatedSendRateBps
}) {
const res = this.resolveSessionStats.pop()
this.rejectSessionStats.pop()
if (res)
res({
timestamp,
bytesSent: BigInt(0),
packetsSent: BigInt(0),
packetsLost: BigInt(0),
numOutgoingStreamsCreated: 0,
numIncomingStreamsCreated: 0,
bytesReceived: BigInt(0),
packetsReceived: BigInt(0),
smoothedRtt,
rttVariation,
minRtt,
estimatedSendRate: estimatedSendRateBps,
datagrams: {
timestamp,
expiredOutgoing,
droppedIncoming: BigInt(0),
lostOutgoing
}
})
}

/**
* @param {DatagramStatsEvent} evt
*/
onDatagramStats({
timestamp,
expiredOutgoing = BigInt(0),
lostOutgoing = BigInt(0)
}) {
const res = this.resolveDatagramStats.pop()
this.rejectDatagramStats.pop()
if (res)
res({
timestamp,
expiredOutgoing,
droppedIncoming: BigInt(0),
lostOutgoing
})
}

async waitForDatagramsSend() {
Expand Down Expand Up @@ -352,6 +412,9 @@ export class Http3WTSession {
for (const rej of this.rejectBiDi) rej(error)
for (const rej of this.rejectUniDi) rej(error)
for (const rej of this.writeDatagramRej) rej(error)
for (const rej of this.rejectSessionStats) rej(error)
for (const rej of this.rejectDatagramStats) rej(error)

this.writeDatagramRej = []
this.writeDatagramRes = []
this.writeDatagramProm = []
Expand All @@ -360,6 +423,11 @@ export class Http3WTSession {
this.rejectBiDi = []
this.rejectUniDi = []

this.resolveSessionStats = []
this.rejectSessionStats = []
this.resolveDatagramStats = []
this.rejectDatagramStats = []

this.incomBiDiController.close()
this.incomUniDiController.close()
this.incomDatagramController.close()
Expand Down Expand Up @@ -495,7 +563,7 @@ export class Http3WTSession {
}

/**
* @param {SessionReadyEvent | SessionCloseEvent | DatagramReceivedEvent | DatagramSendEvent | GoawayReceivedEvent | NewStreamEvent} args
* @param {SessionReadyEvent | SessionCloseEvent | DatagramReceivedEvent | DatagramSendEvent | GoawayReceivedEvent | SessionStatsEvent | DatagramStatsEvent | NewStreamEvent} args
*/
static callback(args) {
log('callback', args?.purpose)
Expand All @@ -522,6 +590,12 @@ export class Http3WTSession {
case 'GoawayReceived':
visitor.onGoAwayReceived(args)
break
case 'SessionStats':
visitor.onSessionStats(args)
break
case 'DatagramStats':
visitor.onDatagramStats(args)
break
case 'Http3WTStreamVisitor':
if (
visitor &&
Expand Down
3 changes: 1 addition & 2 deletions lib/stream.js
Expand Up @@ -85,8 +85,7 @@ export class Http3WTStream {
})
await this.pendingoperationRead
}
if (this.incomingbufferfilled === 0)
throw new Error('error reading')
if (this.incomingbufferfilled === 0) return Promise.resolve()

this.drainBuffer()
},
Expand Down
27 changes: 26 additions & 1 deletion lib/types.ts
Expand Up @@ -8,7 +8,8 @@ import type { WebTransport, WebTransportOptions } from './dom'
writeDatagram: (chunk: Uint8Array) => void
orderUnidiStream: () => void
orderBidiStream: () => void
// orderStats: () => void
orderSessionStats: () => void
orderDatagramStats: () => void
notifySessionDraining(): () => void
close: (arg: { code: number, reason: string }) => void
}
Expand Down Expand Up @@ -82,6 +83,28 @@ export interface SessionCloseEvent {
error: string
}

export interface SessionStatsEvent {
object: NativeHttp3WTSession
purpose: 'SessionStats'
timestamp: number
expiredOutgoing: bigint
lostOutgoing: bigint

// non Datagram
minRtt: number
smoothedRtt: number
rttVariation: number
estimatedSendRateBps: bigint
}

export interface DatagramStatsEvent {
object: NativeHttp3WTSession
purpose: 'DatagramStats'
timestamp: number
expiredOutgoing: bigint
lostOutgoing: bigint
}

export interface DatagramReceivedEvent {
object: NativeHttp3WTSession
purpose: 'DatagramReceived'
Expand Down Expand Up @@ -113,6 +136,8 @@ export interface WebTransportSessionEventHandler {
onDatagramReceived: (evt: DatagramReceivedEvent) => void
onDatagramSend: (evt: DatagramSendEvent) => void
onGoAwayReceived: (evt: GoawayReceivedEvent) => void
onSessionStats: (evt: SessionStatsEvent) => void
onDatagramStats: (evt: DatagramStatsEvent) => void
onStream: (evt: NewStreamEvent) => void
closeHook?: (() => void) | null
}
Expand Down
2 changes: 2 additions & 0 deletions old_test/test.js
Expand Up @@ -98,6 +98,8 @@ async function run() {
await client.ready
console.log('client is ready')
await echoTestsConnection(client)
console.log('Test if getStats works')
console.log('getStats returned', await client.getStats())
console.log('client test finished, now close the client but wait 2 seconds')

await new Promise((resolve) => setTimeout(resolve, 2000))
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@fails-components/webtransport",
"version": "0.2.1",
"version": "0.2.2",
"description": "A component to add webtransport support (server and client) to node.js using libquiche",
"main": "lib/index.js",
"module": "lib/index.js",
Expand Down
5 changes: 0 additions & 5 deletions platform/base/strings/utf_ostream_operators.h

This file was deleted.

5 changes: 3 additions & 2 deletions src/http3dispatcher.cc
Expand Up @@ -43,13 +43,14 @@ std::unique_ptr<QuicSession> Http3Dispatcher::CreateQuicSession(
QuicConnectionId connection_id, const QuicSocketAddress& self_address,
const QuicSocketAddress& peer_address, absl::string_view /*alpn*/,
const ParsedQuicVersion& version,
const ParsedClientHello& /*parsed_chlo*/) {
const ParsedClientHello& /*parsed_chlo*/,
ConnectionIdGeneratorInterface& connection_id_generator) {
// The QuicServerSessionBase takes ownership of |connection| below.
QuicConnection* connection =
new QuicConnection(connection_id, self_address, peer_address, helper(),
alarm_factory(), writer(),
/* owns_writer= */ false, Perspective::IS_SERVER,
ParsedQuicVersionVector{version}, connection_id_generator());
ParsedQuicVersionVector{version}, connection_id_generator);

auto session = std::make_unique<Http3ServerSession>(
config(), GetSupportedVersions(), connection, this, session_helper(),
Expand Down
3 changes: 2 additions & 1 deletion src/http3dispatcher.h
Expand Up @@ -40,7 +40,8 @@ namespace quic
QuicConnectionId connection_id, const QuicSocketAddress &self_address,
const QuicSocketAddress &peer_address, absl::string_view alpn,
const ParsedQuicVersion &version,
const ParsedClientHello &parsed_chlo) override;
const ParsedClientHello &parsed_chlo,
ConnectionIdGeneratorInterface& connection_id_generator) override;

Http3ServerBackend *server_backend()
{
Expand Down

0 comments on commit b234f2e

Please sign in to comment.