Skip to content

Commit

Permalink
Merge pull request #198 from fails-components/thirdpartylibtracker
Browse files Browse the repository at this point in the history
Automated update of thirdparty libraries
  • Loading branch information
martenrichter committed Sep 16, 2023
2 parents 8c8ba0f + c7ecc39 commit 4953060
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -758,6 +758,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 @@ -20,6 +20,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 @@ -9,6 +9,8 @@ import { Http3WTStream } from './stream.js'
* @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 @@ -19,6 +21,7 @@ import { Http3WTStream } from './stream.js'
* @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 @@ -148,6 +151,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 @@ -172,25 +185,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 @@ -324,6 +384,9 @@ export class Http3WTSession {
for (const rej of this.rejectBiDi) rej()
for (const rej of this.rejectUniDi) rej()
for (const rej of this.writeDatagramRej) rej()
for (const rej of this.rejectSessionStats) rej()
for (const rej of this.rejectDatagramStats) rej()

this.writeDatagramRej = []
this.writeDatagramRes = []
this.writeDatagramProm = []
Expand All @@ -332,6 +395,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 @@ -458,7 +526,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) {
// console.log('Session callback called', args)
Expand All @@ -483,6 +551,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
27 changes: 26 additions & 1 deletion lib/types.ts
Expand Up @@ -8,7 +8,8 @@ import type { WebTransport } 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
101 changes: 101 additions & 0 deletions src/http3eventloop.cc
Expand Up @@ -220,6 +220,31 @@ namespace quic
progress_->Send(&report, 1);
}

void Http3EventLoop::informSessionStats(Http3WTSession *sessionobj, webtransport::SessionStats * sessstats)
{
Http3ProgressReport report;
report.type = Http3ProgressReport::SessionStats;
report.sessionobj = sessionobj;
report.sessionStats = sessstats;

report.timestamp = new absl::Duration();
report.timestamp[0] = absl::Now() - absl::UnixEpoch();
if (progress_)
progress_->Send(&report, 1);
}

void Http3EventLoop::informDatagramStats(Http3WTSession *sessionobj, webtransport::DatagramStats * datastats)
{
Http3ProgressReport report;
report.type = Http3ProgressReport::DatagramStats;
report.sessionobj = sessionobj;
report.datagramStats = datastats;
report.timestamp = new absl::Duration();
report.timestamp[0] = absl::Now() - absl::UnixEpoch();
if (progress_)
progress_->Send(&report, 1);
}

void Http3EventLoop::informUnref(LifetimeHelper *obj)
{
Http3ProgressReport report;
Expand Down Expand Up @@ -591,6 +616,70 @@ namespace quic
cbsession_.Call({retObj});
}

void Http3EventLoop::processSessionStats(Http3WTSession *sessionobj, absl::Duration* timestamp, webtransport::SessionStats * sessstats)
{
if (!checkQw())
return;
HandleScope scope(qw_->Env());


auto session = sessionobj->getJS();
if (!session)
return;
Napi::Object objVal = session->Value();

Napi::Object retObj = Napi::Object::New(qw_->Env());
retObj.Set("purpose", "SessionStats");
retObj.Set("object", objVal);
// expiredOutgoing: bigint
// lostOutgoing: bigint

// non Datagram
// minRtt: number
// smoothedRtt: number
// rttVariation: number
// estimatedSendRateBps: bigint
retObj.Set("timestamp", absl::ToDoubleMilliseconds(*timestamp)); // absl::Duration
// datagram
retObj.Set("expiredOutgoing", Napi::BigInt::New(qw_->Env(), sessstats->datagram_stats.expired_outgoing)); //uint64_t
retObj.Set("lostOutgoing", Napi::BigInt::New(qw_->Env(), sessstats->datagram_stats.lost_outgoing)); //uint64_t

// non Datagram
retObj.Set("minRtt", absl::ToDoubleMilliseconds(sessstats->min_rtt)); // absl::Duration
retObj.Set("smoothedRtt", absl::ToDoubleMilliseconds(sessstats->smoothed_rtt)); // absl::Duration
retObj.Set("rttVariation", absl::ToDoubleMilliseconds(sessstats->rtt_variation)); // absl::Duration
retObj.Set("estimatedSendRateBps", sessstats->estimated_send_rate_bps); // absl::Duration

cbsession_.Call({retObj});
delete sessstats;
delete timestamp;
}

void Http3EventLoop::processDatagramStats(Http3WTSession *sessionobj, absl::Duration* timestamp, webtransport::DatagramStats * datastats)
{
if (!checkQw())
return;
HandleScope scope(qw_->Env());


auto session = sessionobj->getJS();
if (!session)
return;
Napi::Object objVal = session->Value();

Napi::Object retObj = Napi::Object::New(qw_->Env());
retObj.Set("purpose", "DatagramStats");
retObj.Set("object", objVal);
retObj.Set("timestamp", absl::ToDoubleMilliseconds(*timestamp)); // absl::Duration
// datagram
retObj.Set("expiredOutgoing", Napi::BigInt::New(qw_->Env(), datastats->expired_outgoing)); //uint64_t
retObj.Set("lostOutgoing", Napi::BigInt::New(qw_->Env(), datastats->lost_outgoing)); //uint64_t

cbsession_.Call({retObj});
delete datastats;
delete timestamp;
}

void Http3EventLoop::processNewSessionRequest(Http3Server *serverobj, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr *promise)
{
if (!checkQw())
Expand Down Expand Up @@ -883,6 +972,18 @@ namespace quic
processGoawayReceived(cur.sessionobj);
}
break;
case Http3ProgressReport::SessionStats:
{
processSessionStats(cur.sessionobj, cur.timestamp, cur.sessionStats);
cur.para = nullptr; // take ownership of the data
}
break;
case Http3ProgressReport::DatagramStats:
{
processDatagramStats(cur.sessionobj, cur.timestamp, cur.datagramStats);
cur.para = nullptr; // take ownership of the data
}
break;
case Http3ProgressReport::Unref:
{
cur.obj->doUnref();
Expand Down

0 comments on commit 4953060

Please sign in to comment.