Skip to content

Commit

Permalink
Fenced frames: disableUntrustedNetwork() for WebTransport.
Browse files Browse the repository at this point in the history
This CL prevents WebTransport connections from being created in frames
with network access revoked, and closes existing WebTransport
connections if a frame loses network access.

Change-Id: Iacb3eff60c8bbd4a154d3f9390f37ad966eafcb0
Bug: 385155392
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6113689
Reviewed-by: Xiaochen Zhou <xiaochenzh@chromium.org>
Commit-Queue: Liam Brady <lbrady@google.com>
Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: Shivani Sharma <shivanisha@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1404463}
  • Loading branch information
Liam Brady authored and chromium-wpt-export-bot committed Jan 10, 2025
1 parent 2d0f23b commit d3f11d9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions webtransport/handlers/token-count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
This is a WebTransport handler that reads tokens sent from client streams and
tracks how many times the token was sent. When a client sends a token, the
server will send the total token count back to the client.
"""
streams_dict = {}

def session_established(session):
# When a WebTransport session is established, a bidirectional stream is
# created by the server, which is used to echo back stream data from the
# client.
session.create_bidirectional_stream()


def stream_data_received(session,
stream_id: int,
data: bytes,
stream_ended: bool):
count = session.stash.take(data) or 0
count += 1
session.stash.put(key=data, value=count)
# If a stream is unidirectional, create a new unidirectional stream and echo
# the token count on that stream.
if session.stream_is_unidirectional(stream_id):
if (session.session_id, stream_id) not in streams_dict.keys():
new_stream_id = session.create_unidirectional_stream()
streams_dict[(session.session_id, stream_id)] = new_stream_id
session.send_stream_data(streams_dict[(session.session_id, stream_id)],
str(count).encode())
if (stream_ended):
del streams_dict[(session.session_id, stream_id)]
return
# Otherwise (e.g. if the stream is bidirectional), echo back the token count
# on the same stream.
session.send_stream_data(stream_id, str(count).encode())

0 comments on commit d3f11d9

Please sign in to comment.