Skip to content

Commit df1ccaf

Browse files
committed
dbg
1 parent d56159a commit df1ccaf

8 files changed

Lines changed: 385 additions & 271 deletions

File tree

lib/roles/quic/ops-quic.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,7 @@ rops_handle_POLLIN_quic(struct lws_context_per_thread *pt, struct lws *wsi,
16111611
if (nwsi && nwsi->quic.qn && nwsi->quic.qn->probing_sa46_valid &&
16121612
nwsi->quic.qn->handshake_done) {
16131613
int _li;
1614+
/* Discard Initial/Handshake TX */
16141615
for (_li = 0; _li <= LWS_QUIC_LEVEL_HANDSHAKE; _li++) {
16151616
lws_start_foreach_dll_safe(struct lws_dll2 *, _d, _d1,
16161617
nwsi->quic.qn->pending_tx[_li].head) {
@@ -1620,6 +1621,26 @@ rops_handle_POLLIN_quic(struct lws_context_per_thread *pt, struct lws *wsi,
16201621
lws_free(_f);
16211622
} lws_end_foreach_dll_safe(_d, _d1);
16221623
}
1624+
/*
1625+
* Ensure PATH_CHALLENGE is the first APP frame sent
1626+
* to the new path. A PATH_RESPONSE generated by
1627+
* parse_frames (in response to the client's
1628+
* PATH_CHALLENGE) may have been add_head'd on top
1629+
* of our PATH_CHALLENGE; move our CHALLENGE back
1630+
* to the front.
1631+
*/
1632+
if (nwsi->quic.qn->path_challenge_pending) {
1633+
lws_start_foreach_dll_safe(struct lws_dll2 *, _d, _d1,
1634+
nwsi->quic.qn->pending_tx[LWS_QUIC_LEVEL_APP].head) {
1635+
struct lws_quic_tx_frame *_f = lws_container_of(_d,
1636+
struct lws_quic_tx_frame, list);
1637+
if (_f->type == LWS_QUIC_FT_PATH_CHALLENGE) {
1638+
lws_dll2_remove(&_f->list);
1639+
lws_dll2_add_head(&_f->list,
1640+
&nwsi->quic.qn->pending_tx[LWS_QUIC_LEVEL_APP]);
1641+
}
1642+
} lws_end_foreach_dll_safe(_d, _d1);
1643+
}
16231644
}
16241645

16251646
/*
@@ -1821,8 +1842,6 @@ rops_handle_POLLOUT_quic(struct lws *wsi)
18211842
int eagain_blocked = 0;
18221843
uint8_t pkt[2048]; memset(pkt, 0, sizeof(pkt));
18231844

1824-
// lwsl_notice("QUIC TX: POLLOUT called for %s, qn=%p, is_server=%d\n", lws_wsi_tag(wsi), qn, qn ? qn->is_server : -1);
1825-
18261845
if (!qn) {
18271846
struct lws *w;
18281847
lws_handling_result_t hr_ret = LWS_HP_RET_DROP_POLLOUT;
@@ -2349,7 +2368,7 @@ rops_handle_POLLOUT_quic(struct lws *wsi)
23492368

23502369
lws_sockfd_type fd = wsi->mux_substream ? wsi->mux.parent_wsi->desc.sockfd : wsi->desc.sockfd;
23512370
size_t send_len = (size_t)(p - pkt) + 16;
2352-
2371+
23532372
/* PMTUD: tag in-flight frames with this packet's wire length so we can track MTU losses */
23542373
struct lws_dll2 *d = qn->in_flight[level].tail;
23552374
while (d) {

minimal-examples-lowlevel/http-server/minimal-http-server-hls/mount-origin/player.js

Lines changed: 117 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -111,82 +111,130 @@ document.addEventListener('DOMContentLoaded', function() {
111111
logMsg('video error: code ' + (err ? err.code : 'unknown') + ', msg: ' + (err ? err.message : 'unknown'));
112112
});
113113

114-
if (Hls.isSupported()) {
115-
logMsg('hls.js supported');
116-
var hls = new Hls({
117-
debug: false,
118-
maxBufferLength: 60,
119-
maxMaxBufferLength: 120,
120-
maxBufferHole: 0.5,
121-
startPosition: 0,
122-
nudgeMaxRetry: 5,
123-
});
124-
hls.loadSource(videoSrc);
125-
hls.attachMedia(video);
126-
127-
hls.on(Hls.Events.MANIFEST_PARSED, function() {
128-
logMsg('hls: manifest parsed, playing');
129-
video.play();
114+
function getHash(str) {
115+
if (crypto && crypto.subtle) {
116+
return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str)).then(function(buf) {
117+
return Array.from(new Uint8Array(buf)).map(function(b) { return b.toString(16).padStart(2, '0'); }).join('');
118+
});
119+
}
120+
return new Promise(function(resolve) {
121+
var hash = 0;
122+
for (var i = 0; i < str.length; i++) hash = ((hash << 5) - hash) + str.charCodeAt(i) | 0;
123+
resolve(hash.toString(36));
130124
});
125+
}
131126

132-
hls.on(Hls.Events.ERROR, function(event, data) {
133-
var msg = 'hls error: type=' + data.type + ', details=' + data.details + ', fatal=' + data.fatal;
134-
logMsg(msg);
135-
if (data.fatal) {
136-
switch(data.type) {
137-
case Hls.ErrorTypes.NETWORK_ERROR:
138-
logMsg('hls: fatal network error, trying to recover');
139-
hls.startLoad();
140-
break;
141-
case Hls.ErrorTypes.MEDIA_ERROR:
142-
logMsg('hls: fatal media error, trying to recover');
143-
hls.recoverMediaError();
144-
break;
145-
default:
146-
logMsg('hls: unrecoverable fatal error');
147-
hls.destroy();
148-
break;
127+
var tsSrc = urlParams.get('t') || '0';
128+
getHash(videoSrc + '_' + tsSrc).then(function(hk) {
129+
var hashKey = 'lws_hls_' + hk;
130+
var startPos = 0;
131+
132+
try {
133+
var saved = localStorage.getItem(hashKey);
134+
if (saved) {
135+
var parsed = JSON.parse(saved);
136+
if (Date.now() - parsed.ts < 604800000) { // 1 week
137+
startPos = parsed.pos;
138+
logMsg('resuming from ' + startPos.toFixed(1) + 's');
139+
} else {
140+
localStorage.removeItem(hashKey);
149141
}
150142
}
151-
});
143+
} catch(e) {}
152144

153-
hls.on(Hls.Events.BUFFER_APPENDED, function() {
154-
if (video.buffered.length > 0) {
155-
var ranges = [];
156-
for (var i = 0; i < video.buffered.length; i++) {
157-
ranges.push('[' + video.buffered.start(i).toFixed(1) + 's - ' + video.buffered.end(i).toFixed(1) + 's]');
158-
}
159-
logMsg('buffer: ' + ranges.join(', '));
145+
video.addEventListener('timeupdate', function() {
146+
if (!video.duration || isNaN(video.duration)) return;
147+
var pct = video.currentTime / video.duration;
148+
if (pct >= 0.95) {
149+
localStorage.removeItem(hashKey);
150+
} else if (video.currentTime > 0) {
151+
localStorage.setItem(hashKey, JSON.stringify({
152+
pos: video.currentTime,
153+
ts: Date.now()
154+
}));
160155
}
161156
});
162-
hls.on(Hls.Events.FRAG_LOADING, function(event, data) {
163-
if (data.frag) {
164-
logMsg('loading seg ' + data.frag.sn + ' (' + data.frag.start.toFixed(1) + 's - ' + (data.frag.start + data.frag.duration).toFixed(1) + 's)');
165-
}
166-
});
167-
}
168-
// For Safari, which natively supports HLS
169-
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
170-
logMsg('native HLS supported');
171-
video.src = videoSrc;
172-
video.addEventListener('loadedmetadata', function() {
173-
logMsg('native HLS metadata loaded, playing');
174-
video.play();
175-
});
176157

177-
// Polling buffer status for native HLS
178-
setInterval(function() {
179-
if (video.buffered.length > 0) {
180-
var ranges = [];
181-
for (var i = 0; i < video.buffered.length; i++) {
182-
ranges.push('[' + video.buffered.start(i).toFixed(1) + 's - ' + video.buffered.end(i).toFixed(1) + 's]');
158+
if (Hls.isSupported()) {
159+
logMsg('hls.js supported');
160+
var hls = new Hls({
161+
debug: false,
162+
maxBufferLength: 60,
163+
maxMaxBufferLength: 120,
164+
maxBufferHole: 0.5,
165+
startPosition: startPos,
166+
nudgeMaxRetry: 5,
167+
});
168+
hls.loadSource(videoSrc);
169+
hls.attachMedia(video);
170+
171+
hls.on(Hls.Events.MANIFEST_PARSED, function() {
172+
logMsg('hls: manifest parsed, playing');
173+
video.play();
174+
});
175+
176+
hls.on(Hls.Events.ERROR, function(event, data) {
177+
var msg = 'hls error: type=' + data.type + ', details=' + data.details + ', fatal=' + data.fatal;
178+
logMsg(msg);
179+
if (data.fatal) {
180+
switch(data.type) {
181+
case Hls.ErrorTypes.NETWORK_ERROR:
182+
logMsg('hls: fatal network error, trying to recover');
183+
hls.startLoad();
184+
break;
185+
case Hls.ErrorTypes.MEDIA_ERROR:
186+
logMsg('hls: fatal media error, trying to recover');
187+
hls.recoverMediaError();
188+
break;
189+
default:
190+
logMsg('hls: unrecoverable fatal error');
191+
hls.destroy();
192+
break;
193+
}
183194
}
184-
logMsg('native buffer: ' + ranges.join(', '));
185-
}
186-
}, 2000);
187-
}
188-
else {
189-
logMsg('error: browser does not support HLS');
190-
alert("Your browser does not support playing this video.");
191-
}
195+
});
196+
197+
hls.on(Hls.Events.BUFFER_APPENDED, function() {
198+
if (video.buffered.length > 0) {
199+
var ranges = [];
200+
for (var i = 0; i < video.buffered.length; i++) {
201+
ranges.push('[' + video.buffered.start(i).toFixed(1) + 's - ' + video.buffered.end(i).toFixed(1) + 's]');
202+
}
203+
logMsg('buffer: ' + ranges.join(', '));
204+
}
205+
});
206+
hls.on(Hls.Events.FRAG_LOADING, function(event, data) {
207+
if (data.frag) {
208+
logMsg('loading seg ' + data.frag.sn + ' (' + data.frag.start.toFixed(1) + 's - ' + (data.frag.start + data.frag.duration).toFixed(1) + 's)');
209+
}
210+
});
211+
}
212+
// For Safari, which natively supports HLS
213+
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
214+
logMsg('native HLS supported');
215+
video.src = videoSrc;
216+
video.addEventListener('loadedmetadata', function() {
217+
logMsg('native HLS metadata loaded, playing');
218+
if (startPos > 0) {
219+
video.currentTime = startPos;
220+
}
221+
video.play();
222+
});
223+
224+
// Polling buffer status for native HLS
225+
setInterval(function() {
226+
if (video.buffered.length > 0) {
227+
var ranges = [];
228+
for (var i = 0; i < video.buffered.length; i++) {
229+
ranges.push('[' + video.buffered.start(i).toFixed(1) + 's - ' + video.buffered.end(i).toFixed(1) + 's]');
230+
}
231+
logMsg('native buffer: ' + ranges.join(', '));
232+
}
233+
}, 2000);
234+
}
235+
else {
236+
logMsg('error: browser does not support HLS');
237+
alert("Your browser does not support playing this video.");
238+
}
239+
});
192240
});

minimal-examples-lowlevel/quic/minimal-quic-client-server/main.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,7 @@ int main(int argc, const char **argv)
381381
info.protocols = protocols;
382382
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT |
383383
LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
384-
#if !defined(WIN32)
385-
LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY |
386-
#endif
387-
0;
384+
LWS_SERVER_OPTION_DISABLE_IPV6;
388385

389386
context = lws_create_context(&info);
390387
if (!context) {

minimal-examples-lowlevel/secure-streams/minimal-secure-streams-stress/CMakeLists.txt

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,51 @@ if (requirements)
2525
if (LWS_CTEST_INTERNET_AVAILABLE AND NOT WIN32)
2626

2727
#
28-
# When running in CI, wait for a lease on the resources
29-
# before starting this test, so the server does not get
30-
# thousands of simultaneous tls connection attempts
31-
#
32-
# sai-resource holds the lease on the resources until
33-
# the time given in seconds or the sai-resource instance
34-
# exits, whichever happens first
35-
#
36-
# If running under Sai, creates a lock test called "res_sspcmin-stress"
28+
# External-egress variant: the example's default policy points at
29+
# warmcat.com, which needs real internet routing. This is only
30+
# registered for builds that can actually reach it (dual-stack /
31+
# IPv4-capable); in an IPv6-only / no-egress CI build the test
32+
# would hang on DNS / connect until the ctest timeout. The
33+
# -local variant below provides the IPv6 coverage instead.
3734
#
35+
if (LWS_IPV4)
3836

39-
sai_resource(warmcat_conns 1 40 sspcmin-stress)
37+
#
38+
# When running in CI, wait for a lease on the resources
39+
# before starting this test, so the server does not get
40+
# thousands of simultaneous tls connection attempts
41+
#
42+
# sai-resource holds the lease on the resources until
43+
# the time given in seconds or the sai-resource instance
44+
# exits, whichever happens first
45+
#
46+
# If running under Sai, creates a lock test called "res_sspcmin-stress"
47+
#
4048

41-
#
42-
# simple test not via proxy
43-
#
49+
sai_resource(warmcat_conns 1 40 sspcmin-stress)
4450

45-
if (VALGRIND)
46-
message("testing via valgrind")
47-
add_test(NAME ssstress-warmcat COMMAND
48-
${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
49-
$<TARGET_FILE:lws-minimal-secure-streams-stress> -c 2 --budget 3 --timeout_ms 60000)
50-
else()
51-
add_test(NAME ssstress-warmcat COMMAND lws-minimal-secure-streams-stress -c 2 --budget 3 --timeout_ms 50000)
52-
endif()
51+
#
52+
# simple test not via proxy
53+
#
5354

54-
set_tests_properties(ssstress-warmcat
55-
PROPERTIES
56-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples-lowlevel/secure-streams/minimal-secure-streams-stress
57-
TIMEOUT 300)
58-
if (DEFINED ENV{SAI_OVN})
59-
set_tests_properties(ssstress-warmcat PROPERTIES FIXTURES_REQUIRED "res_sspcmin")
60-
endif()
55+
if (VALGRIND)
56+
message("testing via valgrind")
57+
add_test(NAME ssstress-warmcat COMMAND
58+
${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
59+
$<TARGET_FILE:lws-minimal-secure-streams-stress> -c 2 --budget 3 --timeout_ms 60000)
60+
else()
61+
add_test(NAME ssstress-warmcat COMMAND lws-minimal-secure-streams-stress -c 2 --budget 3 --timeout_ms 50000)
62+
endif()
63+
64+
set_tests_properties(ssstress-warmcat
65+
PROPERTIES
66+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples-lowlevel/secure-streams/minimal-secure-streams-stress
67+
TIMEOUT 300)
68+
if (DEFINED ENV{SAI_OVN})
69+
set_tests_properties(ssstress-warmcat PROPERTIES FIXTURES_REQUIRED "res_sspcmin")
70+
endif()
71+
72+
endif() # LWS_IPV4 (external-egress variant)
6173

6274
#
6375
# Local-server variant: runs against a local

0 commit comments

Comments
 (0)