• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2021 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This header contains interfaces that abstract away different backing
6 // protocols for WebTransport.
7 
8 #ifndef QUICHE_QUIC_CORE_WEB_TRANSPORT_INTERFACE_H_
9 #define QUICHE_QUIC_CORE_WEB_TRANSPORT_INTERFACE_H_
10 
11 #include "quiche/quic/core/quic_types.h"
12 #include "quiche/web_transport/web_transport.h"
13 
14 namespace quic {
15 
16 using WebTransportSessionError = webtransport::SessionErrorCode;
17 using WebTransportStreamError = webtransport::StreamErrorCode;
18 
19 using WebTransportStreamVisitor = webtransport::StreamVisitor;
20 using WebTransportStream = webtransport::Stream;
21 using WebTransportVisitor = webtransport::SessionVisitor;
22 using WebTransportSession = webtransport::Session;
23 
MessageStatusToWebTransportStatus(MessageStatus status)24 inline webtransport::DatagramStatus MessageStatusToWebTransportStatus(
25     MessageStatus status) {
26   switch (status) {
27     case MESSAGE_STATUS_SUCCESS:
28       return webtransport::DatagramStatus(
29           webtransport::DatagramStatusCode::kSuccess, "");
30     case MESSAGE_STATUS_BLOCKED:
31       return webtransport::DatagramStatus(
32           webtransport::DatagramStatusCode::kBlocked,
33           "QUIC connection write-blocked");
34     case MESSAGE_STATUS_TOO_LARGE:
35       return webtransport::DatagramStatus(
36           webtransport::DatagramStatusCode::kTooBig,
37           "Datagram payload exceeded maximum allowed size");
38     case MESSAGE_STATUS_ENCRYPTION_NOT_ESTABLISHED:
39     case MESSAGE_STATUS_INTERNAL_ERROR:
40     case MESSAGE_STATUS_UNSUPPORTED:
41       return webtransport::DatagramStatus(
42           webtransport::DatagramStatusCode::kInternalError,
43           absl::StrCat("Internal error: ", MessageStatusToString(status)));
44     default:
45       return webtransport::DatagramStatus(
46           webtransport::DatagramStatusCode::kInternalError,
47           absl::StrCat("Unknown status: ", MessageStatusToString(status)));
48   }
49 }
50 
51 }  // namespace quic
52 
53 #endif  // QUICHE_QUIC_CORE_WEB_TRANSPORT_INTERFACE_H_
54