├── .gitignore ├── quic ├── docs │ └── docsite │ │ ├── docs │ │ ├── intro.md │ │ └── mvfst-architecture │ │ │ ├── _category_.json │ │ │ └── thread.png │ │ ├── static │ │ ├── .nojekyll │ │ └── img │ │ │ ├── favicon.ico │ │ │ ├── oss_logo.png │ │ │ ├── docusaurus.png │ │ │ └── tutorial │ │ │ ├── localeDropdown.png │ │ │ └── docsVersionDropdown.png │ │ ├── .prettierignore │ │ ├── src │ │ ├── pages │ │ │ ├── markdown-page.md │ │ │ └── styles.module.css │ │ └── css │ │ │ └── custom.css │ │ ├── .prettierrc │ │ ├── babel.config.js │ │ ├── .gitignore │ │ ├── .stylelintrc.js │ │ ├── sidebars.js │ │ └── README.md ├── server │ ├── third-party │ │ └── BUCK │ ├── QuicUDPSocketFactory.h │ ├── handshake │ │ ├── ServerHandshakeFactory.h │ │ ├── test │ │ │ └── CMakeLists.txt │ │ ├── TokenGenerator.h │ │ ├── DefaultAppTokenValidator.h │ │ ├── AppToken.h │ │ ├── StatelessResetGenerator.cpp │ │ └── StatelessResetGenerator.h │ ├── async_tran │ │ ├── BUCK │ │ ├── test │ │ │ └── BUCK │ │ ├── QuicAsyncTransportAcceptor.h │ │ ├── QuicServerAsyncTransport.cpp │ │ └── QuicServerAsyncTransport.h │ ├── RateLimiter.h │ ├── QuicServerTransportFactory.h │ ├── QuicSharedUDPSocketFactory.h │ ├── state │ │ └── ServerConnectionIdRejector.h │ ├── QuicReusePortUDPSocketFactory.h │ ├── test │ │ └── CMakeLists.txt │ └── SlidingWindowRateLimiter.h ├── tools │ ├── CMakeLists.txt │ └── tperf │ │ ├── test │ │ ├── BUCK │ │ └── CMakeLists.txt │ │ └── CMakeLists.txt ├── logging │ ├── test │ │ ├── CMakeLists.txt │ │ └── BUCK │ ├── BaseQLogger.h │ ├── QLogger.cpp │ └── CMakeLists.txt ├── congestion_control │ ├── third_party │ │ ├── BUCK │ │ └── LICENSE │ ├── PacerFactory.cpp │ ├── BbrTesting.h │ ├── PacerFactoryMobile.cpp │ ├── Pacer.h │ ├── BbrTesting.cpp │ ├── PacerFactory.h │ ├── test │ │ ├── TestingCubic.h │ │ ├── CMakeLists.txt │ │ ├── Utils.h │ │ ├── BbrRttSamplerTest.cpp │ │ └── Mocks.h │ ├── BbrRttSampler.h │ ├── BbrRttSampler.cpp │ ├── ServerCongestionControllerFactory.h │ ├── CongestionControllerFactory.h │ ├── EcnL4sTracker.h │ └── CongestionControllerFactoryMobile.cpp ├── fizz │ ├── CMakeLists.txt │ ├── client │ │ ├── test │ │ │ └── CMakeLists.txt │ │ ├── handshake │ │ │ ├── test │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── MockQuicPskCache.h │ │ │ ├── QuicTokenCache.h │ │ │ ├── BUCK │ │ │ └── QuicPskCache.h │ │ └── CMakeLists.txt │ ├── handshake │ │ ├── FizzRetryIntegrityTagGenerator.h │ │ ├── QuicFizzFactory.h │ │ ├── test │ │ │ ├── CMakeLists.txt │ │ │ └── BUCK │ │ ├── FizzBridge.cpp │ │ ├── BUCK │ │ ├── FizzPacketNumberCipher.h │ │ ├── FizzCryptoFactory.h │ │ └── CMakeLists.txt │ └── server │ │ └── handshake │ │ ├── BUCK │ │ └── AppToken.h ├── folly_utils │ ├── BUCK │ ├── Utils.h │ ├── CMakeLists.txt │ └── Utils.cpp ├── common │ ├── testutil │ │ └── BUCK │ ├── third-party │ │ ├── BUCK │ │ └── LICENSE.md │ ├── StringUtils.h │ ├── events │ │ ├── QuicTimer.h │ │ ├── CMakeLists.txt │ │ ├── test │ │ │ └── BUCK │ │ └── BUCK │ ├── Optional.h │ ├── test │ │ ├── TestMain.cpp │ │ ├── TestClientUtils.h │ │ ├── BufAccessorTest.cpp │ │ ├── TimeUtilTest.cpp │ │ └── QuicRangeConversionTest.cpp │ ├── udpsocket │ │ ├── test │ │ │ ├── FollyQuicAsyncUDPSocketTest.cpp │ │ │ ├── LibevQuicAsyncUDPSocketTest.cpp │ │ │ └── BUCK │ │ ├── QuicAsyncUDPSocketImpl.h │ │ └── CMakeLists.txt │ ├── TransportKnobs.h │ ├── SocketUtil.h │ └── EnumArray.h ├── flowcontrol │ ├── test │ │ ├── CMakeLists.txt │ │ └── BUCK │ ├── BUCK │ └── CMakeLists.txt ├── observer │ ├── test │ │ ├── BUCK │ │ └── CMakeLists.txt │ ├── BUCK │ ├── SocketObserverTypes.h │ └── CMakeLists.txt ├── state │ ├── QuicPacingFunctions.h │ ├── QuicPacingFunctions.cpp │ ├── DatagramHandlers.h │ ├── stream │ │ ├── test │ │ │ ├── CMakeLists.txt │ │ │ └── BUCK │ │ ├── BUCK │ │ ├── StreamReceiveHandlers.h │ │ ├── StreamSendHandlers.h │ │ └── StreamStateFunctions.h │ ├── QuicStreamGroupRetransmissionPolicy.h │ ├── test │ │ ├── QuicPacingFunctionsTest.cpp │ │ ├── AckEventTestUtil.cpp │ │ ├── AckEventTestUtil.h │ │ ├── CMakeLists.txt │ │ └── ClonedPacketIdentifierTest.cpp │ ├── TransportSettingsFunctions.h │ ├── QuicAckFrequencyFunctions.h │ ├── ClonedPacketIdentifier.cpp │ ├── DatagramHandlers.cpp │ ├── QuicConnectionStats.h │ ├── QuicAckFrequencyFunctions.cpp │ ├── AckedPacketIterator.h │ └── SimpleFrameFunctions.h ├── datagram │ ├── BUCK │ └── CMakeLists.txt ├── client │ ├── test │ │ └── CMakeLists.txt │ ├── handshake │ │ ├── ClientHandshakeFactory.h │ │ └── CachedServerTransportParameters.h │ ├── connector │ │ └── BUCK │ └── QuicClientAsyncTransport.h ├── loss │ ├── test │ │ ├── CMakeLists.txt │ │ └── BUCK │ ├── BUCK │ └── CMakeLists.txt ├── QuicTLSException.h ├── priority │ ├── test │ │ ├── CMakeLists.txt │ │ └── BUCK │ ├── BUCK │ └── RoundRobin.h ├── codec │ ├── test │ │ └── ServerConnectionIdParamsTest.cpp │ ├── QuicHeaderCodec.h │ ├── PacketNumber.h │ └── ConnectionIdAlgo.h ├── handshake │ ├── RetryIntegrityTagGenerator.h │ ├── test │ │ └── BUCK │ ├── HandshakeLayer.cpp │ ├── CMakeLists.txt │ └── BUCK ├── .clang-tidy ├── QuicTypealiases.h ├── api │ ├── LoopDetectorCallback.h │ ├── QuicAckScheduler.h │ ├── QuicBatchWriterFactoryMobile.cpp │ └── QuicBatchWriterFactory.cpp ├── QuicTLSExceptionFizz.cpp ├── happyeyeballs │ ├── BUCK │ └── CMakeLists.txt ├── samples │ ├── CMakeLists.txt │ └── echo │ │ └── BUCK ├── xsk │ ├── CMakeLists.txt │ ├── ThreadLocalXskContainer.h │ ├── BaseXskContainer.h │ ├── packet_utils.h │ ├── HashingXskContainer.h │ └── BUCK └── BUILD_MODE.bzl ├── logo.png ├── .buckconfig.d ├── external_cells │ ├── facebook │ │ ├── folly │ │ │ └── external_cell.buckconfig │ │ └── buck2-shims-meta │ │ │ └── external_cell.buckconfig │ └── facebookincubator │ │ └── fizz │ │ └── external_cell.buckconfig └── common.buckconfig ├── cmake ├── FindLibrt.cmake ├── FindLibevent.cmake ├── FindGlog.cmake └── FindDoubleConversion.cmake ├── install.sh ├── getdeps.sh └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | -------------------------------------------------------------------------------- /quic/docs/docsite/docs/intro.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /quic/docs/docsite/static/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mvfst/HEAD/logo.png -------------------------------------------------------------------------------- /quic/docs/docsite/.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | .docusaurus 4 | -------------------------------------------------------------------------------- /quic/docs/docsite/docs/mvfst-architecture/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Mvfst architecture", 3 | "position": 4 4 | } 5 | -------------------------------------------------------------------------------- /quic/docs/docsite/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mvfst/HEAD/quic/docs/docsite/static/img/favicon.ico -------------------------------------------------------------------------------- /quic/docs/docsite/static/img/oss_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mvfst/HEAD/quic/docs/docsite/static/img/oss_logo.png -------------------------------------------------------------------------------- /quic/docs/docsite/static/img/docusaurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mvfst/HEAD/quic/docs/docsite/static/img/docusaurus.png -------------------------------------------------------------------------------- /quic/docs/docsite/docs/mvfst-architecture/thread.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mvfst/HEAD/quic/docs/docsite/docs/mvfst-architecture/thread.png -------------------------------------------------------------------------------- /quic/docs/docsite/static/img/tutorial/localeDropdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mvfst/HEAD/quic/docs/docsite/static/img/tutorial/localeDropdown.png -------------------------------------------------------------------------------- /quic/docs/docsite/static/img/tutorial/docsVersionDropdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mvfst/HEAD/quic/docs/docsite/static/img/tutorial/docsVersionDropdown.png -------------------------------------------------------------------------------- /quic/docs/docsite/src/pages/markdown-page.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Markdown page example 3 | --- 4 | 5 | # Markdown page example 6 | 7 | You don't need React to write simple standalone pages. 8 | -------------------------------------------------------------------------------- /quic/server/third-party/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "siphash", 7 | headers = ["siphash.h"], 8 | ) 9 | -------------------------------------------------------------------------------- /quic/tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_subdirectory(tperf) 7 | -------------------------------------------------------------------------------- /quic/docs/docsite/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "bracketSpacing": false, 4 | "jsxBracketSameLine": true, 5 | "printWidth": 80, 6 | "proseWrap": "never", 7 | "singleQuote": true, 8 | "trailingComma": "all" 9 | } 10 | -------------------------------------------------------------------------------- /quic/logging/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | -------------------------------------------------------------------------------- /quic/congestion_control/third_party/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "chromium_windowed_filter", 7 | headers = [ 8 | "windowed_filter.h", 9 | ], 10 | ) 11 | -------------------------------------------------------------------------------- /quic/fizz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_subdirectory(client) 7 | add_subdirectory(handshake) 8 | -------------------------------------------------------------------------------- /.buckconfig.d/external_cells/facebook/folly/external_cell.buckconfig: -------------------------------------------------------------------------------- 1 | [cells] 2 | gh_facebook_folly = gh_facebook_folly 3 | 4 | [external_cells] 5 | gh_facebook_folly = git 6 | 7 | [external_cell_gh_facebook_folly] 8 | git_origin = https://github.com/facebook/folly.git 9 | commit_hash = 7f29727df622b615ae6b487c16f7712d5329ed99 10 | -------------------------------------------------------------------------------- /.buckconfig.d/external_cells/facebookincubator/fizz/external_cell.buckconfig: -------------------------------------------------------------------------------- 1 | [cells] 2 | gh_facebookincubator_fizz = gh_facebookincubator_fizz 3 | 4 | [external_cells] 5 | gh_facebookincubator_fizz = git 6 | 7 | [external_cell_gh_facebookincubator_fizz] 8 | git_origin = https://github.com/facebookincubator/fizz.git 9 | commit_hash = 40bc5879c0c50b59d37c3fb79ec033c6add18933 10 | -------------------------------------------------------------------------------- /quic/docs/docsite/babel.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | module.exports = { 11 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 12 | }; 13 | -------------------------------------------------------------------------------- /quic/docs/docsite/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | 22 | # ESLint 23 | .eslintcache 24 | -------------------------------------------------------------------------------- /quic/docs/docsite/.stylelintrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | module.exports = { 9 | plugins: ['stylelint-copyright'], 10 | rules: { 11 | 'docusaurus/copyright-header': true, 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /.buckconfig.d/external_cells/facebook/buck2-shims-meta/external_cell.buckconfig: -------------------------------------------------------------------------------- 1 | [cells] 2 | gh_facebook_buck2_shims_meta = gh_facebook_buck2_shims_meta 3 | 4 | [external_cells] 5 | gh_facebook_buck2_shims_meta = git 6 | 7 | [external_cell_gh_facebook_buck2_shims_meta] 8 | git_origin = https://github.com/facebook/buck2-shims-meta.git 9 | commit_hash = 27d858a184940f7c8c7a95d60e8ea62e61025785 10 | -------------------------------------------------------------------------------- /quic/folly_utils/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "folly_utils", 7 | srcs = [ 8 | "Utils.cpp", 9 | ], 10 | headers = [ 11 | "Utils.h", 12 | ], 13 | exported_deps = [ 14 | "//folly/io:iobuf", 15 | "//quic/common:optional", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /quic/tools/tperf/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_test( 6 | name = "PacingObserverTest", 7 | srcs = [ 8 | "PacingObserverTest.cpp", 9 | ], 10 | deps = [ 11 | "//quic/common/test:test_utils", 12 | "//quic/logging/test:mocks", 13 | "//quic/tools/tperf:pacing_observer", 14 | ], 15 | ) 16 | -------------------------------------------------------------------------------- /quic/tools/tperf/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET PacingObserverTest 11 | SOURCES 12 | PacingObserverTest.cpp 13 | DEPENDS 14 | Folly::folly 15 | ) 16 | -------------------------------------------------------------------------------- /quic/common/testutil/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "mock_async_udp_socket", 7 | headers = [ 8 | "MockAsyncUDPSocket.h", 9 | ], 10 | exported_deps = [ 11 | "//folly/portability:gmock", 12 | "//quic/common/events:folly_eventbase", 13 | "//quic/common/udpsocket:folly_async_udp_socket", 14 | ], 15 | ) 16 | -------------------------------------------------------------------------------- /quic/flowcontrol/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET QuicFlowControlTest 11 | SOURCES 12 | QuicFlowControlTest.cpp 13 | DEPENDS 14 | Folly::folly 15 | mvfst_client 16 | mvfst_flowcontrol 17 | mvfst_test_utils 18 | ) 19 | -------------------------------------------------------------------------------- /quic/observer/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_test( 6 | name = "SocketObserverInterfaceTest", 7 | srcs = [ 8 | "SocketObserverInterfaceTest.cpp", 9 | ], 10 | deps = [ 11 | "fbsource//third-party/googletest:gmock", 12 | "//quic/common/test:test_packet_builders", 13 | "//quic/common/test:test_utils", 14 | "//quic/observer:socket_observer_interface", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /quic/state/QuicPacingFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | void updatePacingOnKeyEstablished(QuicConnectionStateBase& conn); 15 | 16 | void updatePacingOnClose(QuicConnectionStateBase& conn); 17 | 18 | } // namespace quic 19 | -------------------------------------------------------------------------------- /quic/flowcontrol/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_test( 6 | name = "QuicFlowControlTest", 7 | srcs = [ 8 | "QuicFlowControlTest.cpp", 9 | ], 10 | deps = [ 11 | "fbsource//third-party/googletest:gmock", 12 | "//quic/client:state_and_handshake", 13 | "//quic/common/test:test_utils", 14 | "//quic/flowcontrol:flow_control", 15 | "//quic/state/test:mocks", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /quic/common/third-party/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "better_enums", 7 | headers = [ 8 | "enum.h", 9 | ], 10 | ) 11 | 12 | mvfst_cpp_library( 13 | name = "tiny_optional", 14 | headers = [ 15 | "optional.h", 16 | "optional_flag_manipulator_fwd.h", 17 | ], 18 | ) 19 | 20 | mvfst_cpp_library( 21 | name = "expected", 22 | headers = [ 23 | "expected.hpp", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /quic/flowcontrol/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "flow_control", 7 | srcs = [ 8 | "QuicFlowController.cpp", 9 | ], 10 | headers = ["QuicFlowController.h"], 11 | deps = [ 12 | "//quic:constants", 13 | "//quic:exception", 14 | ], 15 | exported_deps = [ 16 | "//quic/codec:types", 17 | "//quic/common:expected", 18 | "//quic/state:quic_state_machine", 19 | ], 20 | ) 21 | -------------------------------------------------------------------------------- /quic/datagram/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "datagram_flow_manager", 7 | srcs = ["DatagramFlowManager.cpp"], 8 | headers = ["DatagramFlowManager.h"], 9 | deps = [], 10 | exported_deps = [ 11 | "//folly/container:f14_hash", 12 | "//folly/io:iobuf", 13 | "//quic:constants", 14 | "//quic/common:buf_util", 15 | "//quic/common:circular_deque", 16 | "//quic/priority:priority_queue", 17 | ], 18 | ) 19 | -------------------------------------------------------------------------------- /quic/client/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET ClientStateMachineTest 11 | SOURCES 12 | ClientStateMachineTest.cpp 13 | QuicClientTransportTest.cpp 14 | QuicClientTransportLiteTest.cpp 15 | QuicConnectorTest.cpp 16 | DEPENDS 17 | Folly::folly 18 | mvfst_client 19 | mvfst_test_utils 20 | ) 21 | -------------------------------------------------------------------------------- /quic/loss/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET QuicLossFunctionsTest 11 | SOURCES 12 | QuicLossFunctionsTest.cpp 13 | DEPENDS 14 | Folly::folly 15 | mvfst_codec_types 16 | mvfst_folly_utils 17 | mvfst_client 18 | mvfst_loss 19 | mvfst_server 20 | mvfst_test_utils 21 | mvfst_transport 22 | ) 23 | -------------------------------------------------------------------------------- /quic/fizz/client/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET QuicClientTransportTest 11 | SOURCES 12 | QuicClientTransportTest.cpp 13 | DEPENDS 14 | Folly::folly 15 | ${LIBGMOCK_LIBRARIES} 16 | mvfst_fizz_client 17 | mvfst_codec_types 18 | mvfst_folly_utils 19 | mvfst_server 20 | mvfst_test_utils 21 | ) 22 | -------------------------------------------------------------------------------- /quic/state/QuicPacingFunctions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | void updatePacingOnKeyEstablished(QuicConnectionStateBase& conn) { 13 | conn.canBePaced = true; 14 | } 15 | 16 | void updatePacingOnClose(QuicConnectionStateBase& conn) { 17 | conn.canBePaced = false; 18 | } 19 | 20 | } // namespace quic 21 | -------------------------------------------------------------------------------- /quic/fizz/client/handshake/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET ClientHandshakeTest 11 | SOURCES 12 | FizzClientHandshakeTest.cpp 13 | FizzClientExtensionsTest.cpp 14 | DEPENDS 15 | mvfst_fizz_client 16 | mvfst_codec_types 17 | mvfst_folly_utils 18 | mvfst_constants 19 | mvfst_server 20 | mvfst_test_utils 21 | ) 22 | -------------------------------------------------------------------------------- /quic/state/DatagramHandlers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | /** 16 | * Processes a Datagram frame 17 | */ 18 | void handleDatagram( 19 | QuicConnectionStateBase& conn, 20 | DatagramFrame& frame, 21 | TimePoint recvTimePoint); 22 | 23 | } // namespace quic 24 | -------------------------------------------------------------------------------- /quic/QuicTLSException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | /** 16 | * Convert the crypto error code to a string representation. 17 | * This function provides TLS-specific error descriptions for crypto errors. 18 | */ 19 | std::string cryptoErrorToString(TransportErrorCode code); 20 | 21 | } // namespace quic 22 | -------------------------------------------------------------------------------- /quic/server/QuicUDPSocketFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class QuicUDPSocketFactory { 15 | public: 16 | virtual ~QuicUDPSocketFactory() = default; 17 | 18 | virtual std::unique_ptr make( 19 | folly::EventBase* evb, 20 | int fd) = 0; 21 | }; 22 | } // namespace quic 23 | -------------------------------------------------------------------------------- /quic/congestion_control/PacerFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | std::unique_ptr createPacer( 15 | const QuicConnectionStateBase& conn, 16 | uint64_t minCwndInMss) { 17 | return std::make_unique(conn, minCwndInMss); 18 | } 19 | 20 | } // namespace quic 21 | -------------------------------------------------------------------------------- /quic/state/stream/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET StreamStateMachineTest 11 | SOURCES 12 | StreamStateMachineTest.cpp 13 | StreamStateFunctionsTest.cpp 14 | DEPENDS 15 | Folly::folly 16 | mvfst_codec_types 17 | mvfst_folly_utils 18 | mvfst_server 19 | mvfst_state_stream 20 | mvfst_state_stream_functions 21 | mvfst_test_utils 22 | mvfst_transport 23 | ) 24 | -------------------------------------------------------------------------------- /quic/congestion_control/BbrTesting.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | // A congestion controller for testing modifications to the base BBR 14 | // implementation 15 | class BbrTestingCongestionController : public BbrCongestionController { 16 | public: 17 | explicit BbrTestingCongestionController(QuicConnectionStateBase& conn); 18 | }; 19 | } // namespace quic 20 | -------------------------------------------------------------------------------- /cmake/FindLibrt.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | # - Try to find librt 7 | # Once done, this will define 8 | # 9 | # LIBRT_FOUND - system has librt 10 | # LIBRT_LIBRARIES - link these to use librt 11 | 12 | include(FindPackageHandleStandardArgs) 13 | 14 | find_library(LIBRT_LIBRARY rt 15 | PATHS ${LIBRT_LIBRARYDIR}) 16 | 17 | find_package_handle_standard_args(librt DEFAULT_MSG LIBRT_LIBRARY) 18 | 19 | mark_as_advanced(LIBRT_LIBRARY) 20 | 21 | set(LIBRT_LIBRARIES ${LIBRT_LIBRARY}) 22 | -------------------------------------------------------------------------------- /quic/fizz/handshake/FizzRetryIntegrityTagGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class FizzRetryIntegrityTagGenerator : public RetryIntegrityTagGenerator { 15 | public: 16 | std::unique_ptr getRetryIntegrityTag( 17 | QuicVersion version, 18 | const folly::IOBuf* pseudoRetryPacket) override; 19 | }; 20 | 21 | } // namespace quic 22 | -------------------------------------------------------------------------------- /quic/congestion_control/PacerFactoryMobile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | std::unique_ptr createPacer( 13 | const QuicConnectionStateBase& /* conn */, 14 | uint64_t /* minCwndInMss */) { 15 | // Mobile builds don't use pacing to reduce binary size. 16 | // The transport has null checks for the pacer throughout. 17 | return nullptr; 18 | } 19 | 20 | } // namespace quic 21 | -------------------------------------------------------------------------------- /quic/priority/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | # Always install this header, even when not building tests. 7 | # It can be used by dependent projects to build their own tests 8 | 9 | if(NOT BUILD_TESTS) 10 | return() 11 | endif() 12 | 13 | quic_add_test(TARGET PriorityQueueTest 14 | SOURCES 15 | PriorityQueueTest.cpp 16 | RoundRobinTests.cpp 17 | HTTPPriorityQueueTest.cpp 18 | DEPENDS 19 | Folly::folly 20 | mvfst_round_robin 21 | mvfst_http_priority_queue 22 | ) 23 | -------------------------------------------------------------------------------- /quic/codec/test/ServerConnectionIdParamsTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | namespace quic::test { 12 | TEST(ServerConnectionIdParamsTest, EqOpTest) { 13 | ServerConnectionIdParams first(1, 5, 7); 14 | ServerConnectionIdParams second(1, 7, 5); 15 | ServerConnectionIdParams third(1, 5, 7); 16 | EXPECT_EQ(first, third); 17 | EXPECT_NE(first, second); 18 | } 19 | } // namespace quic::test 20 | -------------------------------------------------------------------------------- /quic/handshake/RetryIntegrityTagGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | class RetryIntegrityTagGenerator { 16 | public: 17 | virtual ~RetryIntegrityTagGenerator() = default; 18 | 19 | virtual std::unique_ptr getRetryIntegrityTag( 20 | QuicVersion version, 21 | const folly::IOBuf* pseudoRetryPacket) = 0; 22 | }; 23 | 24 | } // namespace quic 25 | -------------------------------------------------------------------------------- /quic/.clang-tidy: -------------------------------------------------------------------------------- 1 | # NOTE there must be no spaces before the '-', so put the comma after. 2 | # When making changes, be sure to verify the output of the following command to ensure 3 | # the desired checks are enabled (run from the directory containing a .clang-tidy file): 4 | # `clang-tidy -list-checks` 5 | # NOTE: Please don't disable inheritance from the parent to make sure that common checks get propagated. 6 | --- 7 | InheritParentConfig: true 8 | Checks: ' 9 | boost-*, 10 | bugprone-*, 11 | clang-analyzer-*, 12 | modernize-*, 13 | performance-*, 14 | -modernize-use-trailing-return-type, 15 | cppcoreguidelines-pro-type-member-init, 16 | cppcoreguidelines-init-variables, 17 | ' 18 | ... 19 | -------------------------------------------------------------------------------- /quic/congestion_control/Pacer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | /** 15 | * Returns a pair consisting of the length of the burst interval and the number 16 | * of packets in a burst interval. 17 | */ 18 | using PacingRateCalculator = std::function; 23 | } // namespace quic 24 | -------------------------------------------------------------------------------- /quic/congestion_control/BbrTesting.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | BbrTestingCongestionController::BbrTestingCongestionController( 13 | QuicConnectionStateBase& conn) 14 | : BbrCongestionController(conn) { 15 | // These are now set in QuicTransportBase.cpp in validateCongestionAndPacing() 16 | // conn.transportSettings.defaultRttFactor = {1, 1}; 17 | // conn.transportSettings.startupRttFactor = {1, 1}; 18 | } 19 | } // namespace quic 20 | -------------------------------------------------------------------------------- /.buckconfig.d/common.buckconfig: -------------------------------------------------------------------------------- 1 | [cells] 2 | prelude = prelude 3 | none = none 4 | 5 | [cell_aliases] 6 | config = prelude 7 | ovr_config = prelude 8 | bazel_skylib = gh_facebook_buck2_shims_meta 9 | buck = gh_facebook_buck2_shims_meta 10 | fbcode = gh_facebook_buck2_shims_meta 11 | fbcode_macros = gh_facebook_buck2_shims_meta 12 | fbsource = gh_facebook_buck2_shims_meta 13 | shim = gh_facebook_buck2_shims_meta 14 | toolchains = gh_facebook_buck2_shims_meta 15 | 16 | [external_cells] 17 | prelude = bundled 18 | 19 | [build] 20 | execution_platforms = prelude//platforms:default 21 | 22 | [parser] 23 | target_platform_detector_spec = target:root//...->prelude//platforms:default target:shim//...->prelude//platforms:default 24 | -------------------------------------------------------------------------------- /quic/state/stream/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "stream", 7 | srcs = [ 8 | "StreamReceiveHandlers.cpp", 9 | "StreamSendHandlers.cpp", 10 | "StreamStateFunctions.cpp", 11 | ], 12 | headers = [ 13 | "StreamReceiveHandlers.h", 14 | "StreamSendHandlers.h", 15 | "StreamStateFunctions.h", 16 | ], 17 | deps = [ 18 | "//quic/flowcontrol:flow_control", 19 | ], 20 | exported_deps = [ 21 | "//quic/state:quic_state_machine", 22 | "//quic/state:quic_stream_utilities", 23 | "//quic/state:stream_functions", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /quic/state/stream/StreamReceiveHandlers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | [[nodiscard]] quic::Expected receiveReadStreamFrameSMHandler( 15 | QuicStreamState& stream, 16 | ReadStreamFrame&& frame); 17 | 18 | [[nodiscard]] quic::Expected receiveRstStreamSMHandler( 19 | QuicStreamState& stream, 20 | const RstStreamFrame& rst); 21 | 22 | } // namespace quic 23 | -------------------------------------------------------------------------------- /quic/QuicTypealiases.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | using ByteRange = folly::ByteRange; 15 | using MutableByteRange = folly::MutableByteRange; 16 | using BufHelpers = folly::IOBuf; // For stuff like BufHelpers::create, etc. 17 | using Buf = folly::IOBuf; // Used when we're not wrapping the buffer in an 18 | // std::unique_ptr 19 | using BufPtr = std::unique_ptr; 20 | using BufEq = folly::IOBufEqualTo; 21 | 22 | } // namespace quic 23 | -------------------------------------------------------------------------------- /quic/client/handshake/ClientHandshakeFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class ClientHandshake; 15 | struct QuicClientConnectionState; 16 | 17 | class ClientHandshakeFactory { 18 | public: 19 | virtual ~ClientHandshakeFactory() = default; 20 | 21 | /** 22 | * Construct a new client handshake. 23 | */ 24 | virtual std::unique_ptr makeClientHandshake( 25 | QuicClientConnectionState* conn) && = 0; 26 | }; 27 | 28 | } // namespace quic 29 | -------------------------------------------------------------------------------- /quic/server/handshake/ServerHandshakeFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class ServerHandshake; 15 | struct QuicServerConnectionState; 16 | 17 | class ServerHandshakeFactory { 18 | public: 19 | virtual ~ServerHandshakeFactory() = default; 20 | 21 | /** 22 | * Construct a new server handshake. 23 | */ 24 | virtual std::unique_ptr makeServerHandshake( 25 | QuicServerConnectionState* conn) && = 0; 26 | }; 27 | 28 | } // namespace quic 29 | -------------------------------------------------------------------------------- /quic/common/StringUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | namespace quic { 16 | 17 | /** 18 | * Convert input to hexadecimal representation. 19 | */ 20 | std::string hexlify(const std::string& input); 21 | 22 | /** 23 | * Get binary data from hexadecimal representation. 24 | */ 25 | quic::Expected unhexlify(const std::string& input); 26 | 27 | std::string errnoStr(int err); 28 | 29 | } // namespace quic 30 | -------------------------------------------------------------------------------- /quic/congestion_control/PacerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | struct Pacer; 14 | struct QuicConnectionStateBase; 15 | 16 | /** 17 | * Creates a Pacer for the given connection. 18 | * 19 | * On mobile builds, this returns nullptr to reduce binary size. 20 | * The transport already has null checks for the pacer throughout. 21 | */ 22 | std::unique_ptr createPacer( 23 | const QuicConnectionStateBase& conn, 24 | uint64_t minCwndInMss); 25 | 26 | } // namespace quic 27 | -------------------------------------------------------------------------------- /quic/observer/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | # Always install this header, even when not building tests. 7 | # It can be used by dependent projects to build their own tests 8 | install(FILES MockQuicSocket.h Mocks.h DESTINATION include/quic/api/test) 9 | 10 | if(NOT BUILD_TESTS) 11 | return() 12 | endif() 13 | 14 | quic_add_test(TARGET SocketObserverInterfaceTest 15 | SOURCES 16 | SocketObserverInterfaceTest.cpp 17 | DEPENDS 18 | Folly::folly 19 | mvfst_observer 20 | mvfst_constants 21 | mvfst_exception 22 | mvfst_state_ack_handler 23 | mvfst_state_machine 24 | ) 25 | -------------------------------------------------------------------------------- /quic/fizz/client/handshake/test/MockQuicPskCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace quic { 18 | class MockQuicPskCache : public QuicPskCache { 19 | public: 20 | MOCK_METHOD(Optional, getPsk, (const std::string&)); 21 | MOCK_METHOD(void, putPsk, (const std::string&, QuicCachedPsk)); 22 | MOCK_METHOD(void, removePsk, (const std::string&)); 23 | }; 24 | } // namespace quic 25 | -------------------------------------------------------------------------------- /quic/codec/QuicHeaderCodec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace quic { 15 | 16 | struct ParsedHeaderResult { 17 | bool isVersionNegotiation; 18 | Optional parsedHeader; 19 | 20 | ParsedHeaderResult( 21 | bool isVersionNegotiationIn, 22 | Optional parsedHeaderIn); 23 | }; 24 | 25 | quic::Expected parseHeader( 26 | const folly::IOBuf& data); 27 | } // namespace quic 28 | -------------------------------------------------------------------------------- /quic/server/async_tran/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "server_async_transport", 7 | srcs = [ 8 | "QuicAsyncTransportAcceptor.cpp", 9 | "QuicAsyncTransportServer.cpp", 10 | "QuicServerAsyncTransport.cpp", 11 | ], 12 | headers = [ 13 | "QuicAsyncTransportAcceptor.h", 14 | "QuicAsyncTransportServer.h", 15 | "QuicServerAsyncTransport.h", 16 | ], 17 | deps = ["//folly/system:hardware_concurrency"], 18 | exported_deps = [ 19 | "//folly/io/async:async_transport", 20 | "//folly/io/async:scoped_event_base_thread", 21 | "//quic/api:stream_async_transport", 22 | "//quic/server:server", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /quic/api/LoopDetectorCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class LoopDetectorCallback { 15 | public: 16 | virtual ~LoopDetectorCallback() = default; 17 | 18 | virtual void onSuspiciousWriteLoops( 19 | uint64_t emptyLoopCount, 20 | WriteDataReason writeReason, 21 | NoWriteReason noWriteReason, 22 | const std::string& scheduler) = 0; 23 | 24 | virtual void onSuspiciousReadLoops( 25 | uint64_t emptyLoopCount, 26 | NoReadReason noReadReason) = 0; 27 | }; 28 | 29 | } // namespace quic 30 | -------------------------------------------------------------------------------- /quic/folly_utils/Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic::follyutils { 14 | 15 | /** 16 | * Reads an integer out of the cursor and returns a pair with the integer and 17 | * the numbers of bytes read, or std::nullopt if there are not enough bytes to 18 | * read the int. It only advances the cursor in case of success. 19 | */ 20 | Optional> decodeQuicInteger( 21 | folly::io::Cursor& cursor, 22 | uint64_t atMost = sizeof(uint64_t)); 23 | 24 | } // namespace quic::follyutils 25 | -------------------------------------------------------------------------------- /quic/state/QuicStreamGroupRetransmissionPolicy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | struct QuicStreamGroupRetransmissionPolicy { 15 | // Params controlling retransmission. 16 | DurationRep timeReorderingThreshDividend{ 17 | kDefaultTimeReorderingThreshDividend}; 18 | DurationRep timeReorderingThreshDivisor{kDefaultTimeReorderingThreshDivisor}; 19 | uint32_t reorderingThreshold{kReorderingThreshold}; 20 | 21 | // Disables retransmission. completely. 22 | bool disableRetransmission{false}; 23 | }; 24 | 25 | } // namespace quic 26 | -------------------------------------------------------------------------------- /quic/logging/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "mocks", 7 | headers = [ 8 | "Mocks.h", 9 | ], 10 | exported_deps = [ 11 | "//folly/portability:gmock", 12 | "//quic/logging:qlogger", 13 | ], 14 | ) 15 | 16 | mvfst_cpp_test( 17 | name = "QLoggerTest", 18 | srcs = [ 19 | "QLoggerTest.cpp", 20 | ], 21 | deps = [ 22 | "//folly:dynamic", 23 | "//folly:file_util", 24 | "//folly:random", 25 | "//folly/portability:filesystem", 26 | "//quic/common/test:test_utils", 27 | "//quic/congestion_control:bbr", 28 | "//quic/logging:file_qlogger", 29 | "//quic/logging:qlogger", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /quic/server/RateLimiter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace quic { 15 | 16 | /* 17 | * Basic rate limiter interface that is driven solely by a monotonically 18 | * clocked events. 19 | */ 20 | class RateLimiter { 21 | public: 22 | RateLimiter() = default; 23 | 24 | virtual ~RateLimiter() = default; 25 | 26 | /* 27 | * Check if an event at a certain time should be rate limited. Returns true 28 | * if it should be rate limited. 29 | */ 30 | virtual bool check(TimePoint time) = 0; 31 | }; 32 | 33 | } // namespace quic 34 | -------------------------------------------------------------------------------- /quic/congestion_control/test/TestingCubic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic::test { 11 | 12 | class TestingCubic : public Cubic { 13 | public: 14 | TestingCubic( 15 | QuicConnectionStateBase& conn, 16 | uint64_t initCwndBytes = 0, 17 | uint64_t initSsthresh = Cubic::INIT_SSTHRESH, 18 | bool tcpFriendly = true, 19 | bool ackTrain = false) 20 | : Cubic(conn, initCwndBytes, initSsthresh, tcpFriendly, ackTrain) {} 21 | 22 | void setStateForTest(CubicStates state) { 23 | state_ = state; 24 | } 25 | }; 26 | 27 | } // namespace quic::test 28 | -------------------------------------------------------------------------------- /quic/server/handshake/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET ServerHandshakeTest 11 | SOURCES 12 | AppTokenTest.cpp 13 | DefaultAppTokenValidatorTest.cpp 14 | RetryTokenGeneratorTest.cpp 15 | ServerHandshakeTest.cpp 16 | ServerTransportParametersTest.cpp 17 | StatelessResetGeneratorTest.cpp 18 | DEPENDS 19 | Folly::folly 20 | ${LIBFIZZ_LIBRARY} 21 | mvfst_client 22 | mvfst_codec_types 23 | mvfst_folly_utils 24 | mvfst_constants 25 | mvfst_handshake 26 | mvfst_server 27 | mvfst_state_machine 28 | mvfst_string_utils 29 | mvfst_test_utils 30 | ) 31 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eu 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | ## Run this script to (re)install mvfst and its dependencies (fizz 8 | ## and folly). You must first compile all the dependencies before running this. This 9 | ## Usually this is done by first running `build_helper.sh`. 10 | 11 | set -e 12 | start_dir=$(pwd) 13 | trap 'cd $start_dir' EXIT 14 | 15 | # Must execute from the directory containing this script 16 | cd "$(dirname "$0")" 17 | 18 | cd _build/build 19 | # Uninstall is expected to fail the first time 20 | sudo make uninstall || true 21 | sudo make install 22 | 23 | # Make sure the libraries are available 24 | # Linux only 25 | sudo /sbin/ldconfig || true 26 | -------------------------------------------------------------------------------- /quic/QuicTLSExceptionFizz.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | std::string cryptoErrorToString(TransportErrorCode code) { 16 | auto codeVal = static_cast>(code); 17 | auto alertDescNum = codeVal - 18 | static_cast>( 19 | TransportErrorCode::CRYPTO_ERROR); 20 | 21 | return "Crypto error: " + 22 | toString(static_cast(alertDescNum)); 23 | } 24 | 25 | } // namespace quic 26 | -------------------------------------------------------------------------------- /quic/happyeyeballs/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "happyeyeballs", 7 | srcs = [ 8 | "QuicHappyEyeballsFunctions.cpp", 9 | ], 10 | headers = [ 11 | "QuicHappyEyeballsFunctions.h", 12 | ], 13 | deps = [ 14 | "//common/network:mvfst_hooks", # @manual 15 | "//folly:network_address", 16 | "//folly/portability:sockets", 17 | "//quic/common:socket_util", 18 | "//quic/state:quic_state_machine", 19 | ], 20 | exported_deps = [ 21 | "//folly/io:socket_option_map", 22 | "//folly/net:net_ops", 23 | "//quic/client:state_and_handshake", 24 | "//quic/common/events:eventbase", 25 | "//quic/common/udpsocket:quic_async_udp_socket", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /quic/congestion_control/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET CongestionControllerTests 11 | SOURCES 12 | BandwidthTest.cpp 13 | BbrBandwidthSamplerTest.cpp 14 | BbrRttSamplerTest.cpp 15 | BbrTest.cpp 16 | Bbr2Test.cpp 17 | CongestionControlFunctionsTest.cpp 18 | CopaTest.cpp 19 | CubicHystartTest.cpp 20 | CubicRecoveryTest.cpp 21 | CubicStateTest.cpp 22 | CubicSteadyTest.cpp 23 | CubicTest.cpp 24 | NewRenoTest.cpp 25 | PacerTest.cpp 26 | SimulatedTBFTest.cpp 27 | ThrottlingSignalProviderTest.cpp 28 | Utils.cpp 29 | DEPENDS 30 | Folly::folly 31 | mvfst_cc_algo 32 | mvfst_test_utils 33 | ) 34 | -------------------------------------------------------------------------------- /quic/server/handshake/TokenGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace quic { 15 | 16 | using TokenSecret = std::array; 17 | 18 | /** 19 | * A RetryToken and NewToken generator. 20 | */ 21 | class TokenGenerator { 22 | public: 23 | explicit TokenGenerator(TokenSecret secret); 24 | 25 | Optional encryptToken(const QuicAddrValidationToken& token); 26 | 27 | uint64_t decryptToken(BufPtr encryptedToken, BufPtr aeadAssocData); 28 | 29 | private: 30 | fizz::server::Aead128GCMTokenCipher cipher_; 31 | }; 32 | } // namespace quic 33 | -------------------------------------------------------------------------------- /quic/common/events/QuicTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace quic { 15 | 16 | class QuicTimer : public folly::DelayedDestruction { 17 | public: 18 | using UniquePtr = std::unique_ptr; 19 | using SharedPtr = std::shared_ptr; 20 | using Callback = QuicTimerCallback; 21 | 22 | ~QuicTimer() override = default; 23 | 24 | [[nodiscard]] virtual std::chrono::microseconds getTickInterval() const = 0; 25 | 26 | virtual void scheduleTimeout( 27 | QuicTimerCallback* callback, 28 | std::chrono::microseconds timeout) = 0; 29 | }; 30 | 31 | } // namespace quic 32 | -------------------------------------------------------------------------------- /getdeps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | 8 | set -xeo pipefail 9 | 10 | TOOLCHAIN_DIR=/opt/rh/devtoolset-8/root/usr/bin 11 | if [[ -d "$TOOLCHAIN_DIR" ]]; then 12 | PATH="$TOOLCHAIN_DIR:$PATH" 13 | fi 14 | 15 | PROJECT_DIR=$(dirname "$0") 16 | GETDEPS_PATHS=( 17 | "$PROJECT_DIR/build/fbcode_builder/getdeps.py" 18 | "$PROJECT_DIR/../../opensource/fbcode_builder/getdeps.py" 19 | ) 20 | 21 | ROOT_DIR=$(pwd) 22 | STAGE=${ROOT_DIR}/_build/ 23 | mkdir -p "$STAGE" 24 | 25 | for getdeps in "${GETDEPS_PATHS[@]}"; do 26 | if [[ -x "$getdeps" ]]; then 27 | "$getdeps" build mvfst --current-project mvfst "$@" --install-prefix=${STAGE} 28 | exit 0 29 | fi 30 | done 31 | 32 | echo "Could not find getdeps.py!?" >&2 33 | exit 1 34 | -------------------------------------------------------------------------------- /quic/docs/docsite/src/pages/styles.module.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | /** 11 | * CSS files with the .module.css suffix will be treated as CSS modules 12 | * and scoped locally. 13 | */ 14 | 15 | .heroBanner { 16 | padding: 4rem 0; 17 | text-align: center; 18 | position: relative; 19 | overflow: hidden; 20 | } 21 | 22 | @media screen and (max-width: 966px) { 23 | .heroBanner { 24 | padding: 2rem; 25 | } 26 | } 27 | 28 | .buttons { 29 | display: flex; 30 | align-items: center; 31 | justify-content: center; 32 | } 33 | 34 | .features { 35 | display: flex; 36 | align-items: center; 37 | padding: 2rem 0; 38 | width: 100%; 39 | } 40 | 41 | .featureImage { 42 | height: 200px; 43 | width: 200px; 44 | } 45 | -------------------------------------------------------------------------------- /quic/server/QuicServerTransportFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace quic { 17 | 18 | class QuicServerTransportFactory { 19 | public: 20 | virtual ~QuicServerTransportFactory() = default; 21 | 22 | virtual QuicServerTransport::Ptr make( 23 | folly::EventBase* evb, 24 | std::unique_ptr socket, 25 | const folly::SocketAddress& addr, 26 | QuicVersion quicVersion, 27 | std::shared_ptr ctx) noexcept = 0; 28 | }; 29 | } // namespace quic 30 | -------------------------------------------------------------------------------- /quic/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | file( 11 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 12 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 13 | *.h 14 | ) 15 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 16 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 17 | get_filename_component(header_dir ${header} DIRECTORY) 18 | install(FILES ${header} DESTINATION include/quic/samples/${header_dir}) 19 | endforeach() 20 | 21 | add_executable(echo echo/main.cpp) 22 | 23 | target_compile_options( 24 | echo 25 | PRIVATE 26 | ${_QUIC_COMMON_COMPILE_OPTIONS} 27 | ) 28 | 29 | target_link_libraries( 30 | echo PUBLIC 31 | mvfst_test_utils 32 | ${GFLAGS_LIBRARIES} 33 | ${LIBGMOCK_LIBRARIES} 34 | ) 35 | -------------------------------------------------------------------------------- /quic/tools/tperf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | add_executable( 11 | tperf 12 | tperf.cpp 13 | TperfClient.cpp 14 | TperfServer.cpp 15 | ) 16 | 17 | target_compile_options( 18 | tperf 19 | PRIVATE 20 | ${_QUIC_COMMON_COMPILE_OPTIONS} 21 | ) 22 | 23 | target_include_directories(tperf PRIVATE 24 | ${LIBGMOCK_INCLUDE_DIR} 25 | ${LIBGTEST_INCLUDE_DIR} 26 | ) 27 | 28 | target_link_libraries( 29 | tperf PUBLIC 30 | Folly::folly 31 | fizz::fizz 32 | mvfst_test_utils 33 | ${GFLAGS_LIBRARIES} 34 | ${LIBGMOCK_LIBRARIES} 35 | ) 36 | 37 | install( 38 | TARGETS tperf 39 | EXPORT mvfst-exports 40 | ARCHIVE DESTINATION ${CMAKE_INSTALL_DIR} 41 | LIBRARY DESTINATION ${CMAKE_INSTALL_DIR} 42 | ) 43 | -------------------------------------------------------------------------------- /cmake/FindLibevent.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | # - Try to find Libevent 7 | # Once done, this will define 8 | # 9 | # LIBEVENT_FOUND - system has Libevent 10 | # LIBEVENT_INCLUDE_DIRS - the Libevent include directories 11 | # LIBEVENT_LIBRARIES - link these to use Libevent 12 | 13 | include(FindPackageHandleStandardArgs) 14 | 15 | find_library(LIBEVENT_LIBRARY event 16 | PATHS ${LIBEVENT_LIBRARYDIR}) 17 | 18 | find_path(LIBEVENT_INCLUDE_DIR event.h 19 | PATHS ${LIBEVENT_INCLUDEDIR}) 20 | 21 | find_package_handle_standard_args(libevent DEFAULT_MSG 22 | LIBEVENT_LIBRARY 23 | LIBEVENT_INCLUDE_DIR) 24 | 25 | mark_as_advanced( 26 | LIBEVENT_LIBRARY 27 | LIBEVENT_INCLUDE_DIR) 28 | 29 | set(LIBEVENT_LIBRARIES ${LIBEVENT_LIBRARY}) 30 | set(LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR}) 31 | -------------------------------------------------------------------------------- /quic/observer/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "socket_observer_container", 7 | headers = ["SocketObserverContainer.h"], 8 | exported_deps = [ 9 | ":socket_observer_interface", 10 | "//folly:observer_container", 11 | ], 12 | ) 13 | 14 | mvfst_cpp_library( 15 | name = "socket_observer_interface", 16 | srcs = [ 17 | "SocketObserverInterface.cpp", 18 | ], 19 | headers = ["SocketObserverInterface.h"], 20 | exported_deps = [ 21 | "//quic:exception", 22 | "//quic/state:ack_event", 23 | "//quic/state:outstanding_packet", 24 | "//quic/state:quic_stream_utilities", 25 | ], 26 | ) 27 | 28 | mvfst_cpp_library( 29 | name = "socket_observer_types", 30 | headers = ["SocketObserverTypes.h"], 31 | exported_deps = [ 32 | ":socket_observer_container", 33 | ], 34 | ) 35 | -------------------------------------------------------------------------------- /quic/state/test/QuicPacingFunctionsTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | using namespace testing; 13 | 14 | namespace quic::test { 15 | 16 | class QuicPacingFunctionsTest : public Test {}; 17 | 18 | TEST_F(QuicPacingFunctionsTest, OnKeyEstablished) { 19 | QuicConnectionStateBase conn(QuicNodeType::Client); 20 | EXPECT_FALSE(conn.canBePaced); 21 | updatePacingOnKeyEstablished(conn); 22 | EXPECT_TRUE(conn.canBePaced); 23 | } 24 | 25 | TEST_F(QuicPacingFunctionsTest, OnClose) { 26 | QuicConnectionStateBase conn(QuicNodeType::Client); 27 | conn.canBePaced = true; 28 | updatePacingOnClose(conn); 29 | EXPECT_FALSE(conn.canBePaced); 30 | } 31 | 32 | } // namespace quic::test 33 | -------------------------------------------------------------------------------- /quic/server/handshake/DefaultAppTokenValidator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace fizz::server { 19 | struct ResumptionState; 20 | } // namespace fizz::server 21 | 22 | namespace quic { 23 | struct QuicServerConnectionState; 24 | 25 | class DefaultAppTokenValidator : public fizz::server::AppTokenValidator { 26 | public: 27 | explicit DefaultAppTokenValidator(QuicServerConnectionState* conn); 28 | 29 | [[nodiscard]] bool validate( 30 | const fizz::server::ResumptionState&) const override; 31 | 32 | private: 33 | QuicServerConnectionState* conn_; 34 | }; 35 | 36 | } // namespace quic 37 | -------------------------------------------------------------------------------- /quic/fizz/handshake/QuicFizzFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class QuicFizzFactory : public ::fizz::DefaultFactory { 15 | std::unique_ptr makePlaintextReadRecordLayer() 16 | const override; 17 | 18 | std::unique_ptr 19 | makePlaintextWriteRecordLayer() const override; 20 | 21 | std::unique_ptr makeEncryptedReadRecordLayer( 22 | fizz::EncryptionLevel encryptionLevel) const override; 23 | 24 | std::unique_ptr 25 | makeEncryptedWriteRecordLayer( 26 | fizz::EncryptionLevel encryptionLevel) const override; 27 | }; 28 | 29 | } // namespace quic 30 | -------------------------------------------------------------------------------- /quic/fizz/handshake/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET FizzTransportParametersTest 11 | SOURCES 12 | FizzTransportParametersTest.cpp 13 | DEPENDS 14 | Folly::folly 15 | mvfst_handshake 16 | mvfst_test_utils 17 | ) 18 | 19 | quic_add_test(TARGET FizzCryptoFactoryTest 20 | SOURCES 21 | FizzCryptoFactoryTest.cpp 22 | DEPENDS 23 | Folly::folly 24 | mvfst_codec_types 25 | mvfst_folly_utils 26 | mvfst_fizz_handshake 27 | mvfst_string_utils 28 | mvfst_test_utils 29 | ) 30 | 31 | quic_add_test(TARGET FizzPacketNumberCipherTest 32 | SOURCES 33 | FizzPacketNumberCipherTest.cpp 34 | DEPENDS 35 | Folly::folly 36 | mvfst_fizz_handshake 37 | mvfst_codec_packet_number_cipher 38 | mvfst_string_utils 39 | ) 40 | -------------------------------------------------------------------------------- /quic/docs/docsite/sidebars.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | /** 11 | * Creating a sidebar enables you to: 12 | - create an ordered group of docs 13 | - render a sidebar for each doc of that group 14 | - provide next/previous navigation 15 | 16 | The sidebars can be generated from the filesystem, or explicitly defined here. 17 | 18 | Create as many sidebars as you want. 19 | */ 20 | 21 | module.exports = { 22 | // By default, Docusaurus generates a sidebar from the docs folder structure 23 | tutorialSidebar: [{type: 'autogenerated', dirName: '.'}], 24 | 25 | // But you can create a sidebar manually 26 | /* 27 | tutorialSidebar: [ 28 | { 29 | type: 'category', 30 | label: 'Tutorial', 31 | items: ['hello'], 32 | }, 33 | ], 34 | */ 35 | }; 36 | -------------------------------------------------------------------------------- /quic/server/async_tran/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_unittest.bzl", "fb_dirsync_cpp_unittest") 2 | 3 | oncall("traffic_protocols") 4 | 5 | fb_dirsync_cpp_unittest( 6 | name = "QuicAsyncTransportServerTest", 7 | srcs = [ 8 | "QuicAsyncTransportServerTest.cpp", 9 | ], 10 | deps = [ 11 | "//folly/futures:core", 12 | "//folly/io/async:async_transport", 13 | "//folly/io/async/test:mocks", 14 | "//folly/portability:gmock", 15 | "//folly/portability:gtest", 16 | "//quic/api/test:mocks", 17 | "//quic/client:client", 18 | "//quic/client:client_async_transport", 19 | "//quic/common/test:test_client_utils", 20 | "//quic/common/test:test_utils", 21 | "//quic/fizz/client/handshake:fizz_client_handshake", 22 | "//quic/server:server", 23 | "//quic/server/async_tran:server_async_transport", 24 | "//quic/server/test:mocks", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /quic/server/QuicSharedUDPSocketFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class QuicSharedUDPSocketFactory : public QuicUDPSocketFactory { 15 | public: 16 | ~QuicSharedUDPSocketFactory() override = default; 17 | 18 | QuicSharedUDPSocketFactory() = default; 19 | 20 | std::unique_ptr make(folly::EventBase* evb, int fd) 21 | override { 22 | auto sock = std::make_unique(evb); 23 | if (fd != -1) { 24 | sock->setFD( 25 | folly::NetworkSocket::fromFd(fd), 26 | FollyAsyncUDPSocketAlias::FDOwnership::SHARED); 27 | sock->setDFAndTurnOffPMTU(); 28 | } 29 | return sock; 30 | } 31 | }; 32 | } // namespace quic 33 | -------------------------------------------------------------------------------- /cmake/FindGlog.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | include(FindPackageHandleStandardArgs) 7 | 8 | find_library(GLOG_LIBRARY glog 9 | PATHS ${GLOG_LIBRARYDIR}) 10 | 11 | find_path(GLOG_INCLUDE_DIR glog/logging.h 12 | PATHS ${GLOG_INCLUDEDIR}) 13 | 14 | find_package_handle_standard_args(glog DEFAULT_MSG 15 | GLOG_LIBRARY 16 | GLOG_INCLUDE_DIR) 17 | 18 | mark_as_advanced( 19 | GLOG_LIBRARY 20 | GLOG_INCLUDE_DIR) 21 | 22 | set(GLOG_LIBRARIES ${GLOG_LIBRARY}) 23 | set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) 24 | 25 | if (NOT TARGET glog::glog) 26 | add_library(glog::glog UNKNOWN IMPORTED) 27 | set_target_properties(glog::glog PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIRS}") 28 | set_target_properties(glog::glog PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${GLOG_LIBRARIES}") 29 | endif() 30 | -------------------------------------------------------------------------------- /quic/server/state/ServerConnectionIdRejector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | /** 15 | * When ConnectionIdAlgo encodes a ConnectionID, Rejector gives the user a way 16 | * to reject the resulted ConnectionID. For example, a Quic server may have many 17 | * ongoing connections that all needs different ConnectionID. If the 18 | * ConnectionID generated by ConnectionIdAlgo is duplicated to an existing one, 19 | * the server can use this interface to reject the ConnectionID. 20 | */ 21 | class ServerConnectionIdRejector { 22 | public: 23 | virtual ~ServerConnectionIdRejector() = default; 24 | [[nodiscard]] virtual bool rejectConnectionId( 25 | const ConnectionId& candidate) const noexcept = 0; 26 | }; 27 | 28 | } // namespace quic 29 | -------------------------------------------------------------------------------- /quic/common/Optional.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace quic { 15 | 16 | template 17 | [[nodiscard]] inline auto make_optional(PayloadType&& v) { 18 | return Optional>(std::forward(v)); 19 | } 20 | 21 | template 22 | [[nodiscard]] inline auto make_optional(ArgsT&&... args) { 23 | return Optional(std::in_place, std::forward(args)...); 24 | } 25 | 26 | template 27 | [[nodiscard]] inline auto make_optional( 28 | std::initializer_list il, 29 | ArgsT&&... args) { 30 | return Optional(std::in_place, il, std::forward(args)...); 31 | } 32 | 33 | } // namespace quic 34 | -------------------------------------------------------------------------------- /quic/loss/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "loss", 7 | srcs = [ 8 | "QuicLossFunctions.cpp", 9 | ], 10 | headers = [ 11 | "QuicLossFunctions.h", 12 | ], 13 | deps = [ 14 | "//quic/state:stream_functions", 15 | ], 16 | exported_deps = [ 17 | "//folly:chrono", 18 | "//quic:constants", 19 | "//quic/codec:types", 20 | "//quic/common:expected", 21 | "//quic/common:optional", 22 | "//quic/common:time_util", 23 | "//quic/congestion_control:congestion_control_functions", 24 | "//quic/congestion_control:congestion_controller", 25 | "//quic/flowcontrol:flow_control", 26 | "//quic/logging:qlogger_constants", 27 | "//quic/observer:socket_observer_types", 28 | "//quic/state:quic_state_machine", 29 | "//quic/state:simple_frame_functions", 30 | "//quic/state:state_functions", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /quic/server/QuicReusePortUDPSocketFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class QuicReusePortUDPSocketFactory : public QuicUDPSocketFactory { 15 | public: 16 | ~QuicReusePortUDPSocketFactory() override = default; 17 | 18 | QuicReusePortUDPSocketFactory(bool reusePort = true, bool reuseAddr = false) 19 | : reusePort_(reusePort), reuseAddr_(reuseAddr) {} 20 | 21 | std::unique_ptr make(folly::EventBase* evb, int) 22 | override { 23 | auto sock = std::make_unique(evb); 24 | sock->setReusePort(reusePort_); 25 | sock->setReuseAddr(reuseAddr_); 26 | return sock; 27 | } 28 | 29 | private: 30 | bool reusePort_; 31 | bool reuseAddr_; 32 | }; 33 | } // namespace quic 34 | -------------------------------------------------------------------------------- /quic/client/connector/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "connector", 7 | srcs = [ 8 | "QuicConnector.cpp", 9 | ], 10 | headers = [ 11 | "QuicConnector.h", 12 | ], 13 | deps = [ 14 | "//folly/io/async:async_ssl_socket", 15 | "//folly/io/async:async_udp_socket", 16 | "//quic/common/udpsocket:folly_async_udp_socket", 17 | "//quic/congestion_control:congestion_controller_factory", 18 | "//quic/fizz/client/handshake:fizz_client_handshake", 19 | ], 20 | exported_deps = [ 21 | "//fizz/client:async_fizz_client", 22 | "//folly/io:socket_option_map", 23 | "//quic/api:loop_detector_callback", 24 | "//quic/api:transport", 25 | "//quic/client:client", 26 | "//quic/common:time_util", 27 | "//quic/common/events:folly_eventbase", 28 | "//quic/fizz/client/handshake:psk_cache", 29 | "//quic/logging:qlogger", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /quic/common/test/TestMain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | * This is the recommended main function for all tests. 16 | * The Makefile links it into all of the test programs so that tests do not need 17 | * to - and indeed should typically not - define their own main() functions 18 | */ 19 | FOLLY_ATTR_WEAK int main(int argc, char** argv); 20 | 21 | int main(int argc, char** argv) { 22 | #if FOLLY_HAVE_LIBGFLAGS 23 | // Enable glog logging to stderr by default. 24 | gflags::SetCommandLineOptionWithMode( 25 | "logtostderr", "1", gflags::SET_FLAGS_DEFAULT); 26 | #endif 27 | 28 | ::testing::InitGoogleTest(&argc, argv); 29 | folly::Init init(&argc, &argv); 30 | 31 | return RUN_ALL_TESTS(); 32 | } 33 | -------------------------------------------------------------------------------- /quic/codec/PacketNumber.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | using PacketNum = uint64_t; 16 | 17 | /** 18 | * Returns a decoded packet number by using the expectedNextPacketNum to 19 | * search for the most probable packet number that could satisfy that condition. 20 | */ 21 | PacketNum decodePacketNumber( 22 | uint64_t encodedPacketNum, 23 | size_t packetNumBytes, 24 | PacketNum expectedNextPacketNum); 25 | 26 | struct PacketNumEncodingResult { 27 | PacketNum result; 28 | // This is packet number length in bytes 29 | size_t length; 30 | 31 | PacketNumEncodingResult(PacketNum resultIn, size_t lengthIn); 32 | }; 33 | 34 | PacketNumEncodingResult encodePacketNumber( 35 | PacketNum packetNum, 36 | PacketNum largestAckedPacketNum); 37 | 38 | } // namespace quic 39 | -------------------------------------------------------------------------------- /quic/state/stream/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_test( 6 | name = "StreamStateMachineTest", 7 | srcs = [ 8 | "StreamStateMachineTest.cpp", 9 | ], 10 | deps = [ 11 | "fbsource//third-party/googletest:gmock", 12 | "//quic/api:transport_helpers", 13 | "//quic/codec:types", 14 | "//quic/common/events:folly_eventbase", 15 | "//quic/common/test:test_utils", 16 | "//quic/fizz/server/handshake:fizz_server_handshake", 17 | "//quic/state/stream:stream", 18 | ], 19 | ) 20 | 21 | mvfst_cpp_test( 22 | name = "StreamStateFunctionsTest", 23 | srcs = [ 24 | "StreamStateFunctionsTest.cpp", 25 | ], 26 | deps = [ 27 | "//quic/common/test:test_utils", 28 | "//quic/fizz/server/handshake:fizz_server_handshake", 29 | "//quic/logging:file_qlogger", 30 | "//quic/server/state:server", 31 | "//quic/state:stream_functions", 32 | "//quic/state/stream:stream", 33 | ], 34 | ) 35 | -------------------------------------------------------------------------------- /quic/common/test/TestClientUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic::test { 13 | 14 | class TestCertificateVerifier : public fizz::CertificateVerifier { 15 | public: 16 | ~TestCertificateVerifier() override = default; 17 | 18 | std::shared_ptr verify( 19 | const std::vector>& certs) 20 | const override { 21 | return certs.front(); 22 | } 23 | 24 | [[nodiscard]] std::vector getCertificateRequestExtensions() 25 | const override { 26 | return std::vector(); 27 | } 28 | }; 29 | 30 | inline std::unique_ptr 31 | createTestCertificateVerifier() { 32 | return std::make_unique(); 33 | } 34 | 35 | } // namespace quic::test 36 | -------------------------------------------------------------------------------- /quic/state/stream/StreamSendHandlers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | [[nodiscard]] quic::Expected sendStopSendingSMHandler( 15 | QuicStreamState& stream, 16 | const StopSendingFrame& frame); 17 | 18 | [[nodiscard]] quic::Expected sendRstSMHandler( 19 | QuicStreamState& stream, 20 | ApplicationErrorCode errorCode, 21 | const Optional& reliableSize = std::nullopt); 22 | 23 | [[nodiscard]] quic::Expected sendAckSMHandler( 24 | QuicStreamState& stream, 25 | const WriteStreamFrame& ackedFrame); 26 | 27 | [[nodiscard]] quic::Expected sendRstAckSMHandler( 28 | QuicStreamState& stream, 29 | Optional reliableSize); 30 | 31 | } // namespace quic 32 | -------------------------------------------------------------------------------- /quic/common/udpsocket/test/FollyQuicAsyncUDPSocketTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace ::testing; 13 | 14 | class FollyQuicAsyncUDPSocketProvider { 15 | public: 16 | static std::shared_ptr makeQuicAsyncUDPSocket() { 17 | static folly::EventBase fEvb; 18 | auto evb = std::make_shared(&fEvb); 19 | return std::make_shared(evb); 20 | } 21 | }; 22 | 23 | using FollyQuicAsyncUDPSocketType = Types; 24 | 25 | INSTANTIATE_TYPED_TEST_SUITE_P( 26 | FollyQuicAsyncUDPSocketTest, // Instance name 27 | QuicAsyncUDPSocketTest, // Test case name 28 | FollyQuicAsyncUDPSocketType); // Type list 29 | -------------------------------------------------------------------------------- /quic/priority/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | # Common library 4 | 5 | oncall("traffic_protocols") 6 | 7 | mvfst_cpp_library( 8 | name = "priority_queue", 9 | headers = [ 10 | "PriorityQueue.h", 11 | ], 12 | exported_deps = [ 13 | "//quic/common:optional", 14 | ], 15 | exported_external_deps = [ 16 | "glog", 17 | ], 18 | ) 19 | 20 | mvfst_cpp_library( 21 | name = "round_robin", 22 | srcs = [ 23 | "RoundRobin.cpp", 24 | ], 25 | headers = [ 26 | "RoundRobin.h", 27 | ], 28 | exported_deps = [ 29 | ":priority_queue", 30 | "//quic:config", 31 | "//quic/common:optional", 32 | ], 33 | ) 34 | 35 | mvfst_cpp_library( 36 | name = "http_priority_queue", 37 | srcs = [ 38 | "HTTPPriorityQueue.cpp", 39 | ], 40 | headers = [ 41 | "HTTPPriorityQueue.h", 42 | ], 43 | exported_deps = [ 44 | ":priority_queue", 45 | ":round_robin", 46 | "//folly:cpp_attributes", 47 | "//quic:config", 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /quic/datagram/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_datagram_flow_manager 8 | DatagramFlowManager.cpp 9 | ) 10 | 11 | set_property(TARGET mvfst_datagram_flow_manager PROPERTY VERSION 12 | ${PACKAGE_VERSION}) 13 | 14 | target_include_directories( 15 | mvfst_datagram_flow_manager PUBLIC 16 | $ 17 | $ 18 | ) 19 | 20 | target_compile_options( 21 | mvfst_datagram_flow_manager 22 | PRIVATE 23 | ${_QUIC_COMMON_COMPILE_OPTIONS} 24 | ) 25 | 26 | target_link_libraries( 27 | mvfst_datagram_flow_manager PUBLIC 28 | Folly::folly 29 | mvfst_bufutil 30 | mvfst_constants 31 | mvfst_http_priority_queue 32 | ) 33 | 34 | install(FILES DatagramFlowManager.h DESTINATION include/quic/datagram/) 35 | 36 | install( 37 | TARGETS mvfst_datagram_flow_manager 38 | EXPORT mvfst-exports 39 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 40 | ) 41 | -------------------------------------------------------------------------------- /quic/loss/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_test( 6 | name = "QuicLossFunctionsTest", 7 | srcs = [ 8 | "QuicLossFunctionsTest.cpp", 9 | ], 10 | supports_static_listing = False, 11 | deps = [ 12 | "//folly/io/async/test:mocks", 13 | "//folly/portability:gmock", 14 | "//folly/portability:gtest", 15 | "//quic/api:transport_helpers", 16 | "//quic/api/test:mocks", 17 | "//quic/client:state_and_handshake", 18 | "//quic/codec:types", 19 | "//quic/common/events:folly_eventbase", 20 | "//quic/common/test:test_utils", 21 | "//quic/common/testutil:mock_async_udp_socket", 22 | "//quic/fizz/client/handshake:fizz_client_handshake", 23 | "//quic/fizz/server/handshake:fizz_server_handshake", 24 | "//quic/logging/test:mocks", 25 | "//quic/loss:loss", 26 | "//quic/server/state:server", 27 | "//quic/state:ack_event", 28 | "//quic/state/stream:stream", 29 | "//quic/state/test:mocks", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /quic/congestion_control/BbrRttSampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | class BbrRttSampler : public BbrCongestionController::MinRttSampler { 16 | public: 17 | explicit BbrRttSampler(std::chrono::seconds expiration); 18 | ~BbrRttSampler() override = default; 19 | 20 | [[nodiscard]] std::chrono::microseconds minRtt() const noexcept override; 21 | [[nodiscard]] bool minRttExpired() const noexcept override; 22 | bool newRttSample( 23 | std::chrono::microseconds rttSample, 24 | TimePoint sampledTime) noexcept override; 25 | void timestampMinRtt(TimePoint timestamp) noexcept override; 26 | 27 | private: 28 | std::chrono::seconds expiration_; 29 | std::chrono::microseconds minRtt_{kDefaultMinRtt}; 30 | Optional minRttTimestamp_; 31 | bool rttSampleExpired_; 32 | }; 33 | } // namespace quic 34 | -------------------------------------------------------------------------------- /quic/client/handshake/CachedServerTransportParameters.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace quic { 15 | 16 | struct CachedServerTransportParameters { 17 | uint64_t idleTimeout{0}; 18 | uint64_t maxRecvPacketSize{0}; 19 | uint64_t initialMaxData{0}; 20 | uint64_t initialMaxStreamDataBidiLocal{0}; 21 | uint64_t initialMaxStreamDataBidiRemote{0}; 22 | uint64_t initialMaxStreamDataUni{0}; 23 | uint64_t initialMaxStreamsBidi{0}; 24 | uint64_t initialMaxStreamsUni{0}; 25 | uint64_t maxReceiveTimestampsPerAck{0}; 26 | uint64_t receiveTimestampsExponent{0}; 27 | // Underlying type is currently uint8_t so this struct is still packed 28 | ExtendedAckFeatureMaskType extendedAckFeatures{0}; 29 | bool knobFrameSupport{false}; 30 | bool ackReceiveTimestampsEnabled{false}; 31 | bool reliableStreamResetSupport{false}; 32 | }; 33 | 34 | } // namespace quic 35 | -------------------------------------------------------------------------------- /quic/docs/docsite/src/css/custom.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | /** 11 | * Any CSS included here will be global. The classic template 12 | * bundles Infima by default. Infima is a CSS framework designed to 13 | * work well for content-centric websites. 14 | */ 15 | 16 | /* You can override the default Infima variables here. */ 17 | :root { 18 | --ifm-color-primary: #25c2a0; 19 | --ifm-color-primary-dark: rgb(33, 175, 144); 20 | --ifm-color-primary-darker: rgb(31, 165, 136); 21 | --ifm-color-primary-darkest: rgb(26, 136, 112); 22 | --ifm-color-primary-light: rgb(70, 203, 174); 23 | --ifm-color-primary-lighter: rgb(102, 212, 189); 24 | --ifm-color-primary-lightest: rgb(146, 224, 208); 25 | --ifm-code-font-size: 95%; 26 | } 27 | 28 | .docusaurus-highlight-code-line { 29 | background-color: rgb(72, 77, 91); 30 | display: block; 31 | margin: 0 calc(-1 * var(--ifm-pre-padding)); 32 | padding: 0 var(--ifm-pre-padding); 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Meta Platforms, Inc. and affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /quic/state/TransportSettingsFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include // @manual=//folly:dynamic 11 | #include 12 | 13 | namespace quic { 14 | 15 | void populateAckFrequencyConfig( 16 | const folly::dynamic& srcAckFrequencyConfigDyn, 17 | CongestionControlConfig& dstCcaConfig); 18 | 19 | // Parses the JSON string into a CongestionControlConfig. 20 | // - Fields not present in the JSON string will use their default values 21 | // - Additional fields in the JSON string will be ignored 22 | // - Throws if parsing fails or fields have a wrong type 23 | quic::CongestionControlConfig parseCongestionControlConfig( 24 | const std::string& ccaConfigJson); 25 | 26 | // Same as parse function but returns std::nullopt on error instead of throwing. 27 | Optional tryParseCongestionControlConfig( 28 | const std::string& ccaConfigJson); 29 | } // namespace quic 30 | -------------------------------------------------------------------------------- /quic/state/QuicAckFrequencyFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | /** 15 | * Check whether the peer supports ACK_FREQUENCY and IMMEDIATE_ACK frames 16 | */ 17 | bool canSendAckControlFrames(const QuicConnectionStateBase& conn); 18 | 19 | /** 20 | * Send an ACK_FREQUENCY frame to request the peer to change its ACKing 21 | * behavior 22 | */ 23 | void requestPeerAckFrequencyChange( 24 | QuicConnectionStateBase& conn, 25 | uint64_t ackElicitingThreshold, 26 | std::chrono::microseconds maxAckDelay, 27 | uint64_t reorderThreshold); 28 | 29 | std::chrono::microseconds clampMaxAckDelay( 30 | const QuicConnectionStateBase& conn, 31 | std::chrono::microseconds maxAckDelay); 32 | 33 | /** 34 | * Send an IMMEDIATE_ACK frame to request the peer to send an ACK immediately 35 | */ 36 | void requestPeerImmediateAck(QuicConnectionStateBase& conn); 37 | 38 | } // namespace quic 39 | -------------------------------------------------------------------------------- /quic/api/QuicAckScheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | class AckScheduler { 16 | public: 17 | AckScheduler(const QuicConnectionStateBase& conn, const AckState& ackState); 18 | 19 | [[nodiscard]] quic::Expected, QuicError> writeNextAcks( 20 | PacketBuilderInterface& builder); 21 | 22 | [[nodiscard]] bool hasPendingAcks() const; 23 | 24 | private: 25 | const QuicConnectionStateBase& conn_; 26 | const AckState& ackState_; 27 | }; 28 | 29 | /** 30 | * Returns whether or not the Ack scheduler has acks to schedule. This does not 31 | * tell you when the ACKs can be written. 32 | */ 33 | bool hasAcksToSchedule(const AckState& ackState); 34 | 35 | /** 36 | * Returns the largest packet received which needs to be acked. 37 | */ 38 | Optional largestAckToSend(const AckState& ackState); 39 | 40 | } // namespace quic 41 | -------------------------------------------------------------------------------- /cmake/FindDoubleConversion.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | # - Try to find double-conversion 7 | # Once done, this will define 8 | # 9 | # DOUBLE_CONVERSION_FOUND - system has double-conversion 10 | # DOUBLE_CONVERSION_INCLUDE_DIRS - the double-conversion include directories 11 | # DOUBLE_CONVERSION_LIBRARIES - link these to use double-conversion 12 | 13 | include(FindPackageHandleStandardArgs) 14 | 15 | find_library(DOUBLE_CONVERSION_LIBRARY double-conversion 16 | PATHS ${DOUBLE_CONVERSION_LIBRARYDIR}) 17 | 18 | find_path(DOUBLE_CONVERSION_INCLUDE_DIR double-conversion/double-conversion.h 19 | PATHS ${DOUBLE_CONVERSION_INCLUDEDIR}) 20 | 21 | find_package_handle_standard_args(double_conversion DEFAULT_MSG 22 | DOUBLE_CONVERSION_LIBRARY 23 | DOUBLE_CONVERSION_INCLUDE_DIR) 24 | 25 | mark_as_advanced( 26 | DOUBLE_CONVERSION_LIBRARY 27 | DOUBLE_CONVERSION_INCLUDE_DIR) 28 | 29 | set(DOUBLE_CONVERSION_LIBRARIES ${DOUBLE_CONVERSION_LIBRARY}) 30 | set(DOUBLE_CONVERSION_INCLUDE_DIRS ${DOUBLE_CONVERSION_INCLUDE_DIR}) 31 | -------------------------------------------------------------------------------- /quic/docs/docsite/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. 4 | 5 | ### Installation 6 | 7 | ``` 8 | $ yarn 9 | ``` 10 | 11 | ### Local Development 12 | 13 | ``` 14 | $ yarn start 15 | ``` 16 | 17 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ### Build 20 | 21 | ``` 22 | $ yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ### Deployment 28 | 29 | ``` 30 | $ GIT_USER= USE_SSH=true yarn deploy 31 | ``` 32 | 33 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 34 | 35 | ### Continuous Integration 36 | 37 | Some common defaults for linting/formatting have been set for you. If you integrate your project with an open source Continuous Integration system (e.g. Travis CI, CircleCI), you may check for issues using the following command. 38 | 39 | ``` 40 | $ yarn ci 41 | ``` 42 | -------------------------------------------------------------------------------- /quic/state/stream/StreamStateFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | // Common operations to conduct on QuicStreamState when send reset on it 15 | [[nodiscard]] quic::Expected resetQuicStream( 16 | QuicStreamState& stream, 17 | ApplicationErrorCode error, 18 | Optional reliableSize = std::nullopt); 19 | 20 | // Common operations to conduct on QuicStreamState when receive reset on it 21 | [[nodiscard]] quic::Expected onResetQuicStream( 22 | QuicStreamState& stream, 23 | const RstStreamFrame& frame); 24 | 25 | bool isAllDataReceived(const QuicStreamState& stream); 26 | 27 | // Returns true if the QUIC layer has read all data up to and including the 28 | // given offset. This function can still return true even if the application has 29 | // not read all of it. 30 | bool isAllDataReceivedUntil(const QuicStreamState& stream, uint64_t offset); 31 | } // namespace quic 32 | -------------------------------------------------------------------------------- /quic/common/TransportKnobs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace quic { 16 | 17 | /** 18 | * This is not to be confused with the structure of knob frame, or QUIC's 19 | * transport parameter. Knob frame has space, id and a blob. Arbitrary data can 20 | * be stored in the blob. TransportKnobParam is a kind of blob that designated 21 | * to pass transport-level parameter that's no transferable via existing 22 | * methods (e.g. transport parameter). 23 | */ 24 | struct TransportKnobParam { 25 | using Val = std::variant; 26 | uint64_t id; 27 | Val val; 28 | }; 29 | 30 | constexpr uint64_t kPriorityThresholdKnobMultiplier = 1000; 31 | 32 | using TransportKnobParams = std::vector; 33 | 34 | Optional parseTransportKnobs( 35 | const std::string& serializedParams); 36 | 37 | } // namespace quic 38 | -------------------------------------------------------------------------------- /quic/handshake/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "mocks", 7 | headers = [ 8 | "Mocks.h", 9 | ], 10 | exported_deps = [ 11 | "//folly:unit", 12 | "//folly/portability:gmock", 13 | "//quic:exception", 14 | "//quic/codec:packet_number_cipher", 15 | "//quic/common:expected", 16 | "//quic/fizz/handshake:fizz_handshake", 17 | "//quic/handshake:aead", 18 | "//quic/handshake:handshake", 19 | ], 20 | ) 21 | 22 | mvfst_cpp_test( 23 | name = "TransportParametersTest", 24 | srcs = [ 25 | "TransportParametersTest.cpp", 26 | ], 27 | supports_static_listing = False, 28 | deps = [ 29 | "//folly:network_address", 30 | "//folly/portability:gmock", 31 | "//folly/portability:gtest", 32 | "//quic/client:state_and_handshake", 33 | "//quic/fizz/client/handshake:fizz_client_handshake", 34 | "//quic/fizz/server/handshake:fizz_server_handshake", 35 | "//quic/handshake:transport_parameters", 36 | "//quic/server/state:server", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /quic/common/udpsocket/QuicAsyncUDPSocketImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class QuicAsyncUDPSocketImpl : public QuicAsyncUDPSocket { 15 | public: 16 | quic::Expected recvmmsgNetworkData( 17 | uint64_t readBufferSize, 18 | uint16_t numPackets, 19 | NetworkData& networkData, 20 | Optional& peerAddress, 21 | size_t& totalData) override; 22 | 23 | private: 24 | struct RecvmmsgStorage { 25 | struct impl_ { 26 | struct sockaddr_storage addr; 27 | struct iovec iovec; 28 | // Buffers we pass to recvmmsg. 29 | BufPtr readBuffer; 30 | }; 31 | 32 | // Storage for the recvmmsg system call. 33 | std::vector msgs; 34 | std::vector impl_; 35 | void resize(size_t numPackets); 36 | }; 37 | 38 | RecvmmsgStorage recvmmsgStorage_; 39 | }; 40 | } // namespace quic 41 | -------------------------------------------------------------------------------- /quic/congestion_control/test/Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic::test { 14 | 15 | /** 16 | * Wrapper function for sending packets that updates inflight bytes 17 | * and calls the congestion controller's onPacketSent method. 18 | * This eliminates code duplication across test files. 19 | */ 20 | void onPacketsSentWrapper( 21 | quic::QuicConnectionStateBase* conn, 22 | quic::CongestionController* cc, 23 | const quic::OutstandingPacketWrapper& packet); 24 | 25 | void onPacketAckOrLossWrapper( 26 | quic::QuicConnectionStateBase* conn, 27 | quic::CongestionController* cc, 28 | quic::Optional ack, 29 | quic::Optional loss); 30 | 31 | void removeBytesFromInflight( 32 | quic::QuicConnectionStateBase* conn, 33 | uint64_t bytesToRemove, 34 | quic::CongestionController* cc); 35 | } // namespace quic::test 36 | -------------------------------------------------------------------------------- /quic/observer/SocketObserverTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | /** 15 | * Helper class for writing an observer that monitors a single socket. 16 | * 17 | * Designed to support use cases where the observer implementation is driven 18 | * entirely by observer events generated by the monitored socket or by events 19 | * dispatched by the socket's event base. 20 | * 21 | * ManagedObserver tracks the folly::ObserverContainer it is in (if any). If the 22 | * observer's destructor is triggered while it is in an container, it will be 23 | * removed from the container during the destruction process. 24 | */ 25 | using ManagedObserver = SocketObserverContainer::ManagedObserver; 26 | 27 | /** 28 | * Legacy observer for implementations prior to folly::ObserverContainer. 29 | * 30 | * TODO(bschlinker): Complete depreciation. 31 | */ 32 | using LegacyObserver = SocketObserverContainer::LegacyObserver; 33 | 34 | } // namespace quic 35 | -------------------------------------------------------------------------------- /quic/common/events/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_events 8 | FollyQuicEventBase.cpp 9 | ) 10 | 11 | set_property(TARGET mvfst_events PROPERTY VERSION ${PACKAGE_VERSION}) 12 | 13 | target_include_directories( 14 | mvfst_events PUBLIC 15 | $ 16 | $ 17 | ) 18 | 19 | target_compile_options( 20 | mvfst_events 21 | PRIVATE 22 | ${_QUIC_COMMON_COMPILE_OPTIONS} 23 | ) 24 | 25 | target_link_libraries( 26 | mvfst_events PUBLIC 27 | Folly::folly 28 | ) 29 | 30 | file( 31 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 32 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 33 | *.h 34 | ) 35 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 36 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 37 | get_filename_component(header_dir ${header} DIRECTORY) 38 | install(FILES ${header} DESTINATION include/quic/api/${header_dir}) 39 | endforeach() 40 | 41 | install( 42 | TARGETS mvfst_events 43 | EXPORT mvfst-exports 44 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 45 | ) 46 | -------------------------------------------------------------------------------- /quic/folly_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_folly_utils 8 | Utils.cpp 9 | ) 10 | 11 | set_property(TARGET mvfst_folly_utils PROPERTY VERSION ${PACKAGE_VERSION}) 12 | 13 | target_include_directories( 14 | mvfst_folly_utils PUBLIC 15 | $ 16 | $ 17 | ) 18 | 19 | target_compile_options( 20 | mvfst_folly_utils 21 | PRIVATE 22 | ${_QUIC_COMMON_COMPILE_OPTIONS} 23 | ) 24 | 25 | target_link_libraries( 26 | mvfst_folly_utils PUBLIC 27 | Folly::folly 28 | ) 29 | 30 | file( 31 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 32 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 33 | *.h 34 | ) 35 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 36 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 37 | get_filename_component(header_dir ${header} DIRECTORY) 38 | install(FILES ${header} DESTINATION include/quic/folly_utils/${header_dir}) 39 | endforeach() 40 | 41 | install( 42 | TARGETS mvfst_folly_utils 43 | EXPORT mvfst-exports 44 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 45 | ) 46 | -------------------------------------------------------------------------------- /quic/congestion_control/BbrRttSampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | BbrRttSampler::BbrRttSampler(std::chrono::seconds expiration) 13 | : expiration_(expiration), rttSampleExpired_{true} {} 14 | 15 | std::chrono::microseconds BbrRttSampler::minRtt() const noexcept { 16 | return minRtt_; 17 | } 18 | 19 | bool BbrRttSampler::newRttSample( 20 | std::chrono::microseconds rttSample, 21 | TimePoint sampledTime) noexcept { 22 | rttSampleExpired_ = minRttTimestamp_.has_value() 23 | ? sampledTime > *minRttTimestamp_ + expiration_ 24 | : false; 25 | if (rttSampleExpired_ || minRtt_ > rttSample) { 26 | minRtt_ = rttSample; 27 | minRttTimestamp_ = sampledTime; 28 | return true; 29 | } 30 | return false; 31 | } 32 | 33 | bool BbrRttSampler::minRttExpired() const noexcept { 34 | return rttSampleExpired_; 35 | } 36 | 37 | void BbrRttSampler::timestampMinRtt(TimePoint timestamp) noexcept { 38 | minRttTimestamp_ = timestamp; 39 | } 40 | 41 | } // namespace quic 42 | -------------------------------------------------------------------------------- /quic/congestion_control/ServerCongestionControllerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | /** 15 | * Interface to create CongestionController instances on *server*-side 16 | * applications only. 17 | * 18 | * This interface allows for the use of some algorithms that should not be used 19 | * on client applications, such as CCP. The separation prevents client 20 | * applications from depending upon these unused algorithm implementations. 21 | * 22 | * To use this interface instead of the default, pass a new instance of this 23 | * class to QuicServer::setCongestionControllerFactory. 24 | */ 25 | class ServerCongestionControllerFactory : public CongestionControllerFactory { 26 | public: 27 | ~ServerCongestionControllerFactory() override = default; 28 | 29 | std::unique_ptr makeCongestionController( 30 | QuicConnectionStateBase& conn, 31 | CongestionControlType type) override; 32 | }; 33 | 34 | } // namespace quic 35 | -------------------------------------------------------------------------------- /quic/fizz/handshake/FizzBridge.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | EncryptionLevel getEncryptionLevelFromFizz( 13 | const fizz::EncryptionLevel encryptionLevel) { 14 | switch (encryptionLevel) { 15 | case fizz::EncryptionLevel::Plaintext: 16 | return EncryptionLevel::Initial; 17 | case fizz::EncryptionLevel::Handshake: 18 | return EncryptionLevel::Handshake; 19 | case fizz::EncryptionLevel::EarlyData: 20 | return EncryptionLevel::EarlyData; 21 | case fizz::EncryptionLevel::AppTraffic: 22 | return EncryptionLevel::AppData; 23 | } 24 | 25 | folly::assume_unreachable(); 26 | } 27 | 28 | Optional FizzAead::getKey() const { 29 | if (!fizzAead) { 30 | return std::nullopt; 31 | } 32 | auto fizzKey = fizzAead->getKey(); 33 | if (!fizzKey) { 34 | return std::nullopt; 35 | } 36 | TrafficKey quicKey; 37 | quicKey.key = std::move(fizzKey->key); 38 | quicKey.iv = std::move(fizzKey->iv); 39 | return quicKey; 40 | } 41 | 42 | } // namespace quic 43 | -------------------------------------------------------------------------------- /quic/common/test/BufAccessorTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace quic { 13 | TEST(BufAccessor, BasicAccess) { 14 | BufAccessor accessor(1000); 15 | EXPECT_TRUE(accessor.ownsBuffer()); 16 | auto buf = accessor.obtain(); 17 | EXPECT_LE(1000, buf->capacity()); 18 | EXPECT_FALSE(accessor.ownsBuffer()); 19 | auto empty = accessor.obtain(); 20 | EXPECT_EQ(nullptr, empty); 21 | accessor.release(buf->clone()); 22 | EXPECT_TRUE(accessor.ownsBuffer()); 23 | EXPECT_DEATH(accessor.release(std::move(buf)), ""); 24 | } 25 | 26 | TEST(BufAccessor, CapacityMatch) { 27 | BufAccessor accessor(1000); 28 | auto buf = accessor.obtain(); 29 | buf = folly::IOBuf::create(500); 30 | EXPECT_DEATH(accessor.release(std::move(buf)), ""); 31 | } 32 | 33 | TEST(BufAccessor, RefuseChainedBuf) { 34 | BufAccessor accessor(1000); 35 | auto buf = accessor.obtain(); 36 | buf->appendToChain(folly::IOBuf::create(0)); 37 | EXPECT_DEATH(accessor.release(std::move(buf)), ""); 38 | } 39 | } // namespace quic 40 | -------------------------------------------------------------------------------- /quic/api/QuicBatchWriterFactoryMobile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | // BatchWriterDeleter 13 | void BatchWriterDeleter::operator()(BatchWriter* batchWriter) { 14 | delete batchWriter; 15 | } 16 | 17 | BatchWriterPtr makeGsoBatchWriter(uint32_t) { 18 | LOG(FATAL) << "not implemented for mobile"; 19 | return nullptr; 20 | } 21 | 22 | BatchWriterPtr makeGsoInPlaceBatchWriter(uint32_t, QuicConnectionStateBase&) { 23 | LOG(FATAL) << "not implemented for mobile"; 24 | return nullptr; 25 | } 26 | 27 | BatchWriterPtr makeSendmmsgGsoBatchWriter(uint32_t) { 28 | LOG(FATAL) << "not implemented for mobile"; 29 | return nullptr; 30 | } 31 | 32 | BatchWriterPtr BatchWriterFactory::makeBatchWriter( 33 | const quic::QuicBatchingMode& batchingMode, 34 | uint32_t batchSize, 35 | DataPathType dataPathType, 36 | QuicConnectionStateBase& conn, 37 | bool gsoSupported) { 38 | return makeBatchWriterHelper( 39 | batchingMode, batchSize, dataPathType, conn, gsoSupported); 40 | } 41 | 42 | } // namespace quic 43 | -------------------------------------------------------------------------------- /quic/state/test/AckEventTestUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic::test { 11 | 12 | AckEventStreamDetailsMatcherBuilder&& 13 | AckEventStreamDetailsMatcherBuilder::setStreamID(const uint64_t streamIdIn) { 14 | maybeStreamId = streamIdIn; 15 | return std::move(*this); 16 | } 17 | 18 | AckEventStreamDetailsMatcherBuilder&& 19 | AckEventStreamDetailsMatcherBuilder::addDupAckedStreamInterval( 20 | const DupAckedStreamIntervals::interval_type& interval) { 21 | dupAckedStreamIntervals.insert(interval); 22 | return std::move(*this); 23 | } 24 | 25 | AckEventStreamDetailsMatcherBuilder&& 26 | AckEventStreamDetailsMatcherBuilder::addDupAckedStreamInterval( 27 | const uint64_t startIn, 28 | const uint64_t endIn) { 29 | dupAckedStreamIntervals.insert(startIn, endIn); 30 | return std::move(*this); 31 | } 32 | 33 | AckEventStreamDetailsMatcherBuilder&& 34 | AckEventStreamDetailsMatcherBuilder::clearDupAckedStreamIntervals() { 35 | dupAckedStreamIntervals.clear(); 36 | return std::move(*this); 37 | } 38 | 39 | } // namespace quic::test 40 | -------------------------------------------------------------------------------- /quic/priority/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_benchmark", "mvfst_cpp_test") 2 | 3 | # Common library 4 | 5 | oncall("traffic_protocols") 6 | 7 | mvfst_cpp_test( 8 | name = "priority_queue_test", 9 | srcs = ["PriorityQueueTest.cpp"], 10 | headers = [], 11 | deps = [ 12 | "//folly/portability:gmock", 13 | "//folly/portability:gtest", 14 | "//quic/priority:priority_queue", 15 | ], 16 | ) 17 | 18 | mvfst_cpp_test( 19 | name = "round_robin_test", 20 | srcs = ["RoundRobinTests.cpp"], 21 | headers = [], 22 | deps = [ 23 | "//folly/portability:gmock", 24 | "//folly/portability:gtest", 25 | "//quic/priority:round_robin", 26 | ], 27 | ) 28 | 29 | mvfst_cpp_test( 30 | name = "http_priority_queue_test", 31 | srcs = ["HTTPPriorityQueueTest.cpp"], 32 | headers = [], 33 | deps = [ 34 | "//folly/portability:gmock", 35 | "//folly/portability:gtest", 36 | "//quic/priority:http_priority_queue", 37 | ], 38 | ) 39 | 40 | mvfst_cpp_benchmark( 41 | name = "priority_queue_benchmark", 42 | srcs = ["QuicPriorityQueueBenchmark.cpp"], 43 | deps = [ 44 | "//common/init:init", 45 | "//folly:benchmark", 46 | "//quic/priority:http_priority_queue", 47 | ], 48 | ) 49 | -------------------------------------------------------------------------------- /quic/congestion_control/CongestionControllerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace quic { 15 | struct CongestionController; 16 | struct QuicConnectionStateBase; 17 | 18 | /** 19 | * Interface to create CongestionController instance. 20 | * If application supplies the implementation of this factory, the transport 21 | * calls 'makeCongestionController' for each accepted connection. 22 | */ 23 | class CongestionControllerFactory { 24 | public: 25 | virtual ~CongestionControllerFactory() = default; 26 | 27 | virtual std::unique_ptr makeCongestionController( 28 | QuicConnectionStateBase& conn, 29 | CongestionControlType type) = 0; 30 | }; 31 | 32 | class DefaultCongestionControllerFactory : public CongestionControllerFactory { 33 | public: 34 | ~DefaultCongestionControllerFactory() override = default; 35 | 36 | std::unique_ptr makeCongestionController( 37 | QuicConnectionStateBase& conn, 38 | CongestionControlType type) override; 39 | }; 40 | 41 | } // namespace quic 42 | -------------------------------------------------------------------------------- /quic/xsk/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_xsk 8 | packet_utils.cpp 9 | xsk_lib.cpp 10 | BaseXskContainer.cpp 11 | HashingXskContainer.cpp 12 | ThreadLocalXskContainer.cpp 13 | XskSender.cpp 14 | ) 15 | 16 | set_property(TARGET mvfst_xsk PROPERTY VERSION ${PACKAGE_VERSION}) 17 | 18 | target_include_directories( 19 | mvfst_xsk PUBLIC 20 | $ 21 | $ 22 | ) 23 | 24 | target_link_libraries( 25 | mvfst_xsk PUBLIC 26 | Folly::folly 27 | ) 28 | 29 | target_compile_options( 30 | mvfst_xsk 31 | PRIVATE 32 | ${_QUIC_COMMON_COMPILE_OPTIONS} 33 | ) 34 | 35 | file( 36 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 37 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 38 | *.h 39 | ) 40 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 41 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 42 | get_filename_component(header_dir ${header} DIRECTORY) 43 | install(FILES ${header} DESTINATION include/quic/dsr/${header_dir}) 44 | endforeach() 45 | 46 | install( 47 | TARGETS mvfst_xsk 48 | EXPORT mvfst-exports 49 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 50 | ) 51 | -------------------------------------------------------------------------------- /quic/common/test/TimeUtilTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace quic::test { 13 | 14 | using namespace quic; 15 | 16 | TEST(TimeUtil, TestMinTwo) { 17 | std::chrono::milliseconds ms1 = 10ms; 18 | std::chrono::milliseconds ms2 = 20ms; 19 | EXPECT_EQ(timeMin(ms1, ms2).count(), 10); 20 | } 21 | 22 | TEST(TimeUtil, TestMinFive) { 23 | std::chrono::milliseconds ms1 = 20ms; 24 | std::chrono::milliseconds ms2 = 30ms; 25 | std::chrono::milliseconds ms3 = 40ms; 26 | std::chrono::milliseconds ms4 = 10ms; 27 | EXPECT_EQ(timeMin(ms1, ms2, ms3, ms4).count(), 10); 28 | } 29 | 30 | TEST(TimeUtil, TestMaxTwo) { 31 | std::chrono::milliseconds ms1 = 10ms; 32 | std::chrono::milliseconds ms2 = 20ms; 33 | EXPECT_EQ(timeMax(ms1, ms2).count(), 20); 34 | } 35 | 36 | TEST(TimeUtil, TestMaxFive) { 37 | std::chrono::milliseconds ms1 = 20ms; 38 | std::chrono::milliseconds ms2 = 30ms; 39 | std::chrono::milliseconds ms3 = 40ms; 40 | std::chrono::milliseconds ms4 = 10ms; 41 | EXPECT_EQ(timeMax(ms1, ms2, ms3, ms4).count(), 40); 42 | } 43 | } // namespace quic::test 44 | -------------------------------------------------------------------------------- /quic/server/handshake/AppToken.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace folly { 20 | class IOBuf; 21 | } 22 | 23 | namespace quic { 24 | 25 | struct AppToken { 26 | TicketTransportParameters transportParams; 27 | std::vector sourceAddresses; 28 | QuicVersion version; 29 | std::unique_ptr appParams; 30 | }; 31 | 32 | quic::Expected 33 | createTicketTransportParameters( 34 | uint64_t idleTimeout, 35 | uint64_t maxRecvPacketSize, 36 | uint64_t initialMaxData, 37 | uint64_t initialMaxStreamDataBidiLocal, 38 | uint64_t initialMaxStreamDataBidiRemote, 39 | uint64_t initialMaxStreamDataUni, 40 | uint64_t initialMaxStreamsBidi, 41 | uint64_t initialMaxStreamsUni, 42 | ExtendedAckFeatureMaskType extendedAckSupport, 43 | Optional cwndHintBytes = std::nullopt); 44 | 45 | } // namespace quic 46 | -------------------------------------------------------------------------------- /quic/logging/BaseQLogger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace quic { 15 | 16 | class BaseQLogger : public QLogger { 17 | public: 18 | explicit BaseQLogger(VantagePoint vantagePointIn, std::string protocolTypeIn) 19 | : QLogger(vantagePointIn, std::move(protocolTypeIn)) {} 20 | 21 | ~BaseQLogger() override = default; 22 | 23 | protected: 24 | std::unique_ptr createPacketEvent( 25 | const RegularQuicPacket& regularPacket, 26 | uint64_t packetSize); 27 | 28 | std::unique_ptr createPacketEvent( 29 | const RegularQuicWritePacket& writePacket, 30 | uint64_t packetSize); 31 | 32 | std::unique_ptr createPacketEvent( 33 | const VersionNegotiationPacket& versionPacket, 34 | uint64_t packetSize, 35 | bool isPacketRecvd); 36 | 37 | std::unique_ptr createPacketEvent( 38 | const RetryPacket& retryPacket, 39 | uint64_t packetSize, 40 | bool isPacketRecvd); 41 | }; 42 | } // namespace quic 43 | -------------------------------------------------------------------------------- /quic/state/ClonedPacketIdentifier.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | ClonedPacketIdentifier::ClonedPacketIdentifier( 16 | PacketNumberSpace packetNumberSpaceIn, 17 | PacketNum packetNumberIn) 18 | : packetNumber(packetNumberIn), packetNumberSpace(packetNumberSpaceIn) {} 19 | 20 | bool operator==( 21 | const ClonedPacketIdentifier& lhs, 22 | const ClonedPacketIdentifier& rhs) { 23 | return static_cast>( 24 | lhs.packetNumberSpace) == 25 | static_cast>( 26 | rhs.packetNumberSpace) && 27 | lhs.packetNumber == rhs.packetNumber; 28 | } 29 | 30 | size_t ClonedPacketIdentifierHash::operator()( 31 | const ClonedPacketIdentifier& clonedPacketIdentifier) const noexcept { 32 | return folly::hash::hash_combine( 33 | static_cast>( 34 | clonedPacketIdentifier.packetNumberSpace), 35 | clonedPacketIdentifier.packetNumber); 36 | } 37 | } // namespace quic 38 | -------------------------------------------------------------------------------- /quic/common/udpsocket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_async_udp_socket 8 | QuicAsyncUDPSocket.cpp 9 | QuicAsyncUDPSocketImpl.cpp 10 | FollyQuicAsyncUDPSocket.cpp 11 | ) 12 | 13 | set_property(TARGET mvfst_async_udp_socket PROPERTY VERSION ${PACKAGE_VERSION}) 14 | 15 | target_include_directories( 16 | mvfst_async_udp_socket PUBLIC 17 | $ 18 | $ 19 | ) 20 | 21 | target_compile_options( 22 | mvfst_async_udp_socket 23 | PRIVATE 24 | ${_QUIC_COMMON_COMPILE_OPTIONS} 25 | ) 26 | 27 | target_link_libraries( 28 | mvfst_async_udp_socket PUBLIC 29 | Folly::folly 30 | mvfst_events 31 | ) 32 | 33 | file( 34 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 35 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 36 | *.h 37 | ) 38 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 39 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 40 | get_filename_component(header_dir ${header} DIRECTORY) 41 | install(FILES ${header} DESTINATION include/quic/api/${header_dir}) 42 | endforeach() 43 | 44 | install( 45 | TARGETS mvfst_async_udp_socket 46 | EXPORT mvfst-exports 47 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 48 | ) 49 | -------------------------------------------------------------------------------- /quic/common/third-party/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2021, Anton Bachin 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /quic/state/DatagramHandlers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | void handleDatagram( 13 | QuicConnectionStateBase& conn, 14 | DatagramFrame& frame, 15 | TimePoint recvTimePoint) { 16 | // TODO(lniccolini) update max datagram frame size 17 | // https://github.com/quicwg/datagram/issues/3 18 | // For now, max_datagram_size > 0 means the peer supports datagram frames 19 | if (conn.datagramState.maxReadFrameSize == 0) { 20 | frame.data.move(); 21 | QUIC_STATS(conn.statsCallback, onDatagramDroppedOnRead); 22 | return; 23 | } 24 | if (conn.datagramState.readBuffer.size() >= 25 | conn.datagramState.maxReadBufferSize) { 26 | QUIC_STATS(conn.statsCallback, onDatagramDroppedOnRead); 27 | if (!conn.transportSettings.datagramConfig.recvDropOldDataFirst) { 28 | frame.data.move(); 29 | return; 30 | } else { 31 | conn.datagramState.readBuffer.pop_front(); 32 | } 33 | } 34 | QUIC_STATS(conn.statsCallback, onDatagramRead, frame.data.chainLength()); 35 | conn.datagramState.readBuffer.emplace_back( 36 | recvTimePoint, std::move(frame.data)); 37 | } 38 | 39 | } // namespace quic 40 | -------------------------------------------------------------------------------- /quic/xsk/ThreadLocalXskContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #if defined(__linux__) && !defined(ANDROID) 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace facebook::xdpsocket { 19 | 20 | class ThreadLocalXskContainer : public BaseXskContainer { 21 | public: 22 | ThreadLocalXskContainer() = default; 23 | 24 | ~ThreadLocalXskContainer() override = default; 25 | 26 | quic::Expected init( 27 | const XskContainerConfig& xskContainerConfig) override; 28 | 29 | XskSender* pickXsk( 30 | const folly::SocketAddress& src, 31 | const folly::SocketAddress& dst) override; 32 | 33 | // The user needs to call this function within each thread that 34 | // will use an AF_XDP socket, in order to set the thread local 35 | // XskSender. 36 | void setOwnerForXsk(); 37 | 38 | private: 39 | std::vector> xskSenders_; 40 | uint32_t ownerIdToAssign_{0}; 41 | folly::ThreadLocalPtr xskSender_; 42 | }; 43 | 44 | } // namespace facebook::xdpsocket 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /quic/server/async_tran/QuicAsyncTransportAcceptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | class QuicAsyncTransportAcceptor : public quic::QuicServerTransportFactory { 16 | public: 17 | // Hook/Callback function to be invoked when a new connection is accepted and 18 | // passed in the associated AsyncTransport. 19 | using AsyncTransportHook = 20 | std::function; 21 | 22 | QuicAsyncTransportAcceptor( 23 | folly::EventBase* evb, 24 | AsyncTransportHook asyncTransportHook); 25 | ~QuicAsyncTransportAcceptor() override = default; 26 | 27 | // quic::QuicServerTransportFactory 28 | quic::QuicServerTransport::Ptr make( 29 | folly::EventBase* evb, 30 | std::unique_ptr sock, 31 | const folly::SocketAddress&, 32 | QuicVersion quickVersion, 33 | std::shared_ptr ctx) noexcept 34 | override; 35 | 36 | private: 37 | AsyncTransportHook asyncTransportHook_; 38 | folly::EventBase* evb_; 39 | }; 40 | 41 | } // namespace quic 42 | -------------------------------------------------------------------------------- /quic/logging/QLogger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | std::string getFlowControlEvent(int offset) { 15 | return fmt::format("flow control event, new offset: {}", offset); 16 | } 17 | 18 | std::string 19 | getRxStreamWU(StreamId streamId, PacketNum packetNum, uint64_t maximumData) { 20 | return fmt::format( 21 | "rx stream, streamId: {}, packetNum: {}, maximumData: {}", 22 | streamId, 23 | packetNum, 24 | maximumData); 25 | } 26 | 27 | std::string getRxConnWU(PacketNum packetNum, uint64_t maximumData) { 28 | return fmt::format( 29 | "rx, packetNum: {}, maximumData: {}", packetNum, maximumData); 30 | } 31 | 32 | std::string getPeerClose(const std::string& peerCloseReason) { 33 | return fmt::format("error message: {}", peerCloseReason); 34 | } 35 | 36 | std::string getFlowControlWindowAvailable(uint64_t windowAvailable) { 37 | return fmt::format("on flow control, window available: {}", windowAvailable); 38 | } 39 | 40 | std::string getClosingStream(const std::string& streamId) { 41 | return fmt::format("closing stream, stream id: {}", streamId); 42 | } 43 | 44 | } // namespace quic 45 | -------------------------------------------------------------------------------- /quic/fizz/server/handshake/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "fizz_server_handshake", 7 | srcs = [ 8 | "FizzServerHandshake.cpp", 9 | "FizzServerQuicHandshakeContext.cpp", 10 | ], 11 | headers = [ 12 | "FizzServerHandshake.h", 13 | "FizzServerQuicHandshakeContext.h", 14 | ], 15 | deps = [ 16 | ":handshake_app_token", 17 | "//fizz/protocol:protocol", 18 | "//fizz/server:replay_cache", 19 | "//quic:constants", 20 | "//quic/server/state:server", 21 | ], 22 | exported_deps = [ 23 | "//fizz/server:fizz_server_context", 24 | "//fizz/server:protocol", 25 | "//quic/common:circular_deque", 26 | "//quic/fizz/handshake:fizz_handshake", 27 | "//quic/server/handshake:server_handshake", 28 | ], 29 | ) 30 | 31 | mvfst_cpp_library( 32 | name = "handshake_app_token", 33 | srcs = [ 34 | "AppToken.cpp", 35 | ], 36 | headers = [ 37 | "AppToken.h", 38 | ], 39 | deps = [ 40 | "//fizz/server:protocol", 41 | "//quic:constants", 42 | "//quic/fizz/handshake:fizz_handshake", 43 | ], 44 | exported_deps = [ 45 | "//fizz/record:record", 46 | "//quic/common:optional", 47 | "//quic/server/handshake:app_token", 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /quic/server/handshake/StatelessResetGenerator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace { 14 | constexpr folly::StringPiece kSalt{"Stateless reset"}; 15 | } 16 | 17 | namespace quic { 18 | 19 | StatelessResetGenerator::StatelessResetGenerator( 20 | StatelessResetSecret secret, 21 | const std::string& addressStr) 22 | : addressStr_(std::move(addressStr)), 23 | hkdf_(fizz::openssl::createHkdf()) { 24 | extractedSecret_ = 25 | hkdf_.extract(kSalt, ByteRange(secret.data(), secret.size())); 26 | } 27 | 28 | StatelessResetToken StatelessResetGenerator::generateToken( 29 | const ConnectionId& connId) const { 30 | StatelessResetToken token; 31 | auto info = toData(connId); 32 | info.appendToChain( 33 | BufHelpers::wrapBuffer(addressStr_.data(), addressStr_.size())); 34 | auto out = hkdf_.expand( 35 | ByteRange(extractedSecret_.data(), extractedSecret_.size()), 36 | info, 37 | token.size()); 38 | out->coalesce(); 39 | memcpy(token.data(), out->data(), out->length()); 40 | return token; 41 | } 42 | 43 | } // namespace quic 44 | -------------------------------------------------------------------------------- /quic/congestion_control/EcnL4sTracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | // This class tracks the L4S weight (alpha) according to the latest Prague 16 | // Congestion Control Draft 17 | // (https://datatracker.ietf.org/doc/draft-briscoe-iccrg-prague-congestion-control/) 18 | class EcnL4sTracker : public PacketProcessor { 19 | public: 20 | explicit EcnL4sTracker(QuicConnectionStateBase& conn); 21 | 22 | void onPacketAck(const AckEvent* FOLLY_NULLABLE /* ackEvent */) override; 23 | 24 | // The latest l4s weight calculated by the tracker. 25 | [[nodiscard]] double getL4sWeight() const; 26 | 27 | // The latest l4s weight normalized by the RTT. This is the value 28 | // the congestion controller uses to react to the ECN markings once per RTT. 29 | [[nodiscard]] double getNormalizedL4sWeight() const; 30 | 31 | private: 32 | QuicConnectionStateBase& conn_; 33 | std::chrono::microseconds rttVirt_; 34 | 35 | double l4sWeight_{0.0}; 36 | TimePoint lastUpdateTime_{Clock::now()}; 37 | uint32_t lastECT1Echoed_{0}; 38 | uint32_t lastCEEchoed_{0}; 39 | }; 40 | 41 | } // namespace quic 42 | -------------------------------------------------------------------------------- /quic/fizz/handshake/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "fizz_handshake", 7 | srcs = [ 8 | "FizzBridge.cpp", 9 | "FizzCryptoFactory.cpp", 10 | "FizzPacketNumberCipher.cpp", 11 | "FizzRetryIntegrityTagGenerator.cpp", 12 | "QuicFizzFactory.cpp", 13 | ], 14 | headers = [ 15 | "FizzBridge.h", 16 | "FizzCryptoFactory.h", 17 | "FizzPacketNumberCipher.h", 18 | "FizzRetryIntegrityTagGenerator.h", 19 | "FizzTransportParameters.h", 20 | "QuicFizzFactory.h", 21 | ], 22 | deps = [ 23 | "//fizz/backend:openssl", 24 | "//fizz/crypto:crypto", 25 | "//fizz/crypto:utils", 26 | "//quic/common:optional", 27 | ], 28 | exported_deps = [ 29 | "//fizz/crypto/aead:aead", 30 | "//fizz/protocol:default_factory", 31 | "//fizz/protocol:types", 32 | "//fizz/record:record", 33 | "//folly/ssl:openssl_ptr_types", 34 | "//quic:constants", 35 | "//quic/codec:packet_number_cipher", 36 | "//quic/common:buf_util", 37 | "//quic/folly_utils:folly_utils", 38 | "//quic/handshake:aead", 39 | "//quic/handshake:handshake", 40 | "//quic/handshake:retry_integrity_tag_generator", 41 | "//quic/handshake:transport_parameters", 42 | ], 43 | ) 44 | -------------------------------------------------------------------------------- /quic/fizz/handshake/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_test") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_test( 6 | name = "FizzTransportParametersTest", 7 | srcs = [ 8 | "FizzTransportParametersTest.cpp", 9 | ], 10 | deps = [ 11 | "//fizz/record/test:extension_tests_base", 12 | "//folly/portability:gmock", 13 | "//folly/portability:gtest", 14 | "//quic:constants", 15 | "//quic/common/test:test_utils", 16 | "//quic/fizz/handshake:fizz_handshake", 17 | ], 18 | ) 19 | 20 | mvfst_cpp_test( 21 | name = "FizzCryptoFactoryTest", 22 | srcs = [ 23 | "FizzCryptoFactoryTest.cpp", 24 | ], 25 | deps = [ 26 | "//fizz/crypto/aead/test:mocks", 27 | "//folly/portability:gmock", 28 | "//folly/portability:gtest", 29 | "//quic/common:string_utils", 30 | "//quic/common/test:test_utils", 31 | "//quic/fizz/handshake:fizz_handshake", 32 | "//quic/handshake/test:mocks", 33 | ], 34 | ) 35 | 36 | mvfst_cpp_test( 37 | name = "FizzPacketNumberCipherTest", 38 | srcs = [ 39 | "FizzPacketNumberCipherTest.cpp", 40 | ], 41 | supports_static_listing = False, 42 | deps = [ 43 | "//fizz/record:record", 44 | "//folly/portability:gtest", 45 | "//quic/common:string_utils", 46 | "//quic/fizz/handshake:fizz_handshake", 47 | ], 48 | ) 49 | -------------------------------------------------------------------------------- /quic/state/QuicConnectionStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace quic { 18 | 19 | struct QuicConnectionStats { 20 | uint8_t workerID{0}; 21 | uint32_t numConnIDs{0}; 22 | folly::SocketAddress localAddress; 23 | folly::SocketAddress peerAddress; 24 | std::chrono::duration duration{0}; 25 | uint64_t cwnd_bytes{0}; 26 | CongestionControlType congestionController; 27 | CongestionControllerStats congestionControllerStats; 28 | uint32_t ptoCount{0}; 29 | std::chrono::microseconds srtt{0}; 30 | std::chrono::microseconds mrtt{0}; 31 | std::chrono::microseconds lrtt{0}; 32 | std::chrono::microseconds rttvar{0}; 33 | uint64_t peerAckDelayExponent{0}; 34 | uint64_t udpSendPacketLen{0}; 35 | uint64_t numStreams{0}; 36 | std::string clientChosenDestConnectionId; 37 | std::string clientConnectionId; 38 | std::string serverConnectionId; 39 | uint64_t totalBytesSent{0}; 40 | uint64_t totalBytesReceived{0}; 41 | uint64_t totalBytesRetransmitted{0}; 42 | uint32_t version{0}; 43 | }; 44 | 45 | } // namespace quic 46 | -------------------------------------------------------------------------------- /quic/congestion_control/test/BbrRttSamplerTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | using namespace testing; 14 | 15 | namespace quic::test { 16 | 17 | class BbrMinRttSamplerTest : public Test {}; 18 | 19 | TEST_F(BbrMinRttSamplerTest, InitState) { 20 | BbrRttSampler sampler(100s); 21 | EXPECT_TRUE(sampler.minRttExpired()); 22 | EXPECT_EQ(kDefaultMinRtt, sampler.minRtt()); 23 | } 24 | 25 | TEST_F(BbrMinRttSamplerTest, NewSampleAndExpiration) { 26 | BbrRttSampler sampler(10s); 27 | auto currentTime = Clock::now(); 28 | sampler.newRttSample(50us, currentTime); 29 | EXPECT_FALSE(sampler.minRttExpired()); 30 | EXPECT_EQ(50us, sampler.minRtt()); 31 | 32 | sampler.newRttSample(60us, currentTime + 1s); 33 | EXPECT_FALSE(sampler.minRttExpired()); 34 | EXPECT_EQ(50us, sampler.minRtt()); 35 | 36 | sampler.newRttSample(40us, currentTime + 2s); 37 | EXPECT_FALSE(sampler.minRttExpired()); 38 | EXPECT_EQ(40us, sampler.minRtt()); 39 | 40 | sampler.newRttSample(100us, Clock::now() + 20s); 41 | EXPECT_TRUE(sampler.minRttExpired()); 42 | EXPECT_EQ(100us, sampler.minRtt()); 43 | } 44 | } // namespace quic::test 45 | -------------------------------------------------------------------------------- /quic/congestion_control/test/Mocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | namespace quic::test { 12 | 13 | class MockMinRttSampler : public BbrCongestionController::MinRttSampler { 14 | public: 15 | ~MockMinRttSampler() override = default; 16 | 17 | MOCK_METHOD(std::chrono::microseconds, minRtt, (), (const)); 18 | MOCK_METHOD(bool, minRttExpired, (), (const)); 19 | MOCK_METHOD( 20 | bool, 21 | newRttSample, 22 | (std::chrono::microseconds, TimePoint), 23 | (noexcept)); 24 | MOCK_METHOD(void, timestampMinRtt, (TimePoint), (noexcept)); 25 | }; 26 | 27 | class MockBandwidthSampler : public BbrCongestionController::BandwidthSampler { 28 | public: 29 | ~MockBandwidthSampler() override = default; 30 | 31 | MOCK_METHOD(Bandwidth, getBandwidth, (), (const)); 32 | MOCK_METHOD(Bandwidth, getLatestSample, (), (const)); 33 | MOCK_METHOD(bool, isAppLimited, (), (const)); 34 | 35 | MOCK_METHOD( 36 | void, 37 | onPacketAcked, 38 | (const CongestionController::AckEvent&, uint64_t)); 39 | MOCK_METHOD(void, onAppLimited, ()); 40 | MOCK_METHOD(void, setWindowLength, (const uint64_t), (noexcept)); 41 | }; 42 | 43 | } // namespace quic::test 44 | -------------------------------------------------------------------------------- /quic/happyeyeballs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_happyeyeballs 8 | QuicHappyEyeballsFunctions.cpp 9 | ) 10 | 11 | set_property(TARGET mvfst_happyeyeballs PROPERTY VERSION ${PACKAGE_VERSION}) 12 | 13 | target_include_directories( 14 | mvfst_happyeyeballs PUBLIC 15 | $ 16 | $ 17 | ) 18 | 19 | target_compile_options( 20 | mvfst_happyeyeballs 21 | PRIVATE 22 | ${_QUIC_COMMON_COMPILE_OPTIONS} 23 | ) 24 | 25 | add_dependencies( 26 | mvfst_happyeyeballs 27 | mvfst_async_udp_socket 28 | mvfst_state_machine 29 | ) 30 | 31 | target_link_libraries( 32 | mvfst_happyeyeballs PUBLIC 33 | Folly::folly 34 | mvfst_async_udp_socket 35 | mvfst_state_machine 36 | ) 37 | 38 | file( 39 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 40 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 41 | *.h 42 | ) 43 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 44 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 45 | get_filename_component(header_dir ${header} DIRECTORY) 46 | install(FILES ${header} DESTINATION include/quic/happyeyeballs/${header_dir}) 47 | endforeach() 48 | 49 | install( 50 | TARGETS mvfst_happyeyeballs 51 | EXPORT mvfst-exports 52 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 53 | ) 54 | -------------------------------------------------------------------------------- /quic/xsk/BaseXskContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #if defined(__linux__) && !defined(ANDROID) 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::xdpsocket { 17 | 18 | struct XskContainerConfig { 19 | std::string interfaceName; 20 | folly::MacAddress localMac; 21 | folly::MacAddress gatewayMac; 22 | uint32_t numFrames; 23 | uint32_t frameSize; 24 | uint32_t batchSize; 25 | uint32_t numSockets; 26 | }; 27 | 28 | class BaseXskContainer { 29 | public: 30 | BaseXskContainer() = default; 31 | 32 | virtual ~BaseXskContainer() = default; 33 | 34 | virtual quic::Expected init( 35 | const XskContainerConfig& xskContainerConfig) = 0; 36 | 37 | virtual XskSender* pickXsk( 38 | const folly::SocketAddress& src, 39 | const folly::SocketAddress& dst) = 0; 40 | 41 | protected: 42 | quic::Expected, std::runtime_error> 43 | createXskSender(int queueId, const XskSenderConfig& xskSenderConfig); 44 | 45 | void initializeQueueParams(const std::string& interfaceName); 46 | 47 | uint32_t startQueue_; 48 | uint32_t numQueues_; 49 | }; 50 | 51 | } // namespace facebook::xdpsocket 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /quic/xsk/packet_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #if defined(__linux__) && !defined(ANDROID) 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace facebook::xdpsocket { 19 | 20 | void writeMacHeader(const ethhdr* ethHdr, char*& buffer); 21 | 22 | void writeIpHeader( 23 | const folly::IPAddress& dstAddr, 24 | const folly::IPAddress& srcAddr, 25 | const iphdr* ipHdr, 26 | uint16_t payloadLen, 27 | char*& buffer); 28 | 29 | void writeIpHeader( 30 | const folly::IPAddress& dstAddr, 31 | const folly::IPAddress& srcAddr, 32 | const ipv6hdr* ipv6Hdr, 33 | uint16_t payloadLen, 34 | char*& buffer); 35 | 36 | void writeUdpHeader( 37 | uint16_t srcPort, 38 | uint16_t dstPort, 39 | uint16_t csum, 40 | uint16_t len, 41 | char*& buffer); 42 | 43 | void writeUdpPayload(const char* data, uint32_t len, char*& buffer); 44 | 45 | // The len should be the len in the udp header, not the payload len. 46 | void writeChecksum( 47 | const folly::IPAddress& dstAddr, 48 | const folly::IPAddress& srcAddr, 49 | char* packet, 50 | uint16_t len); 51 | 52 | } // namespace facebook::xdpsocket 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /quic/fizz/client/handshake/QuicTokenCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace quic { 16 | 17 | class QuicTokenCache { 18 | public: 19 | virtual ~QuicTokenCache() = default; 20 | 21 | [[nodiscard]] virtual Optional getToken( 22 | const std::string& hostname) = 0; 23 | 24 | virtual void putToken(const std::string& hostname, std::string token) = 0; 25 | 26 | virtual void removeToken(const std::string& hostname) = 0; 27 | }; 28 | 29 | class BasicQuicTokenCache : public QuicTokenCache { 30 | public: 31 | ~BasicQuicTokenCache() override = default; 32 | 33 | Optional getToken(const std::string& hostname) override { 34 | auto res = cache_.find(hostname); 35 | if (res != cache_.end()) { 36 | return res->second; 37 | } 38 | return std::nullopt; 39 | } 40 | 41 | void putToken(const std::string& hostname, std::string token) override { 42 | cache_[hostname] = std::move(token); 43 | } 44 | 45 | void removeToken(const std::string& hostname) override { 46 | cache_.erase(hostname); 47 | } 48 | 49 | private: 50 | std::unordered_map cache_; 51 | }; 52 | } // namespace quic 53 | -------------------------------------------------------------------------------- /quic/xsk/HashingXskContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #if defined(__linux__) && !defined(ANDROID) 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace facebook::xdpsocket { 18 | 19 | /* 20 | * The Linux Kernel can use one of many strategies to decide which packet to 21 | * send on which queue: skb hashing, transmit packet steering, or a custom 22 | * function in the NIC driver. The functionality of the HashingXskContainer is 23 | * modeled after the skb hashing strategy of the Linux Kernel. We use a hash of 24 | * the 4-tuple to pick which TX queue a particular packet is written to. 25 | */ 26 | class HashingXskContainer : public BaseXskContainer { 27 | public: 28 | HashingXskContainer() = default; 29 | 30 | ~HashingXskContainer() override = default; 31 | 32 | quic::Expected init( 33 | const XskContainerConfig& xskContainerConfig) override; 34 | 35 | XskSender* pickXsk( 36 | const folly::SocketAddress& src, 37 | const folly::SocketAddress& dst) override; 38 | 39 | private: 40 | folly::F14FastMap> queueIdToXsk_; 41 | }; 42 | 43 | } // namespace facebook::xdpsocket 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /quic/common/udpsocket/test/LibevQuicAsyncUDPSocketTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace ::testing; 14 | 15 | struct EvLoop : public quic::LibevQuicEventBase::EvLoopWeak { 16 | EvLoop() : evLoop_(ev_loop_new(0)) {} 17 | 18 | ~EvLoop() override { 19 | ev_loop_destroy(evLoop_); 20 | } 21 | 22 | struct ev_loop* get() override { 23 | return evLoop_; 24 | } 25 | 26 | std::optional getEventLoopThread() override { 27 | return pthread_self(); 28 | } 29 | 30 | struct ev_loop* evLoop_; 31 | }; 32 | 33 | class LibevQuicAsyncUDPSocketProvider { 34 | public: 35 | static std::shared_ptr makeQuicAsyncUDPSocket() { 36 | auto evb = 37 | std::make_shared(std::make_unique()); 38 | return std::make_shared(evb); 39 | } 40 | }; 41 | 42 | using LibevQuicAsyncUDPSocketType = Types; 43 | 44 | INSTANTIATE_TYPED_TEST_SUITE_P( 45 | LibevQuicAsyncUDPSocketTest, // Instance name 46 | QuicAsyncUDPSocketTest, // Test case name 47 | LibevQuicAsyncUDPSocketType); // Type list 48 | -------------------------------------------------------------------------------- /quic/server/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET QuicServerTest 11 | SOURCES 12 | QuicServerTest.cpp 13 | QuicSocketTest.cpp 14 | DEPENDS 15 | Folly::folly 16 | mvfst_codec 17 | mvfst_codec_types 18 | mvfst_folly_utils 19 | mvfst_server 20 | mvfst_test_utils 21 | mvfst_transport 22 | ) 23 | 24 | quic_add_test(TARGET QuicClientServerIntegrationTest 25 | SOURCES 26 | QuicClientServerIntegrationTest.cpp 27 | DEPENDS 28 | Folly::folly 29 | mvfst_codec 30 | mvfst_codec_types 31 | mvfst_folly_utils 32 | mvfst_server 33 | mvfst_test_utils 34 | mvfst_transport 35 | ) 36 | 37 | quic_add_test(TARGET QuicServerTransportTest 38 | SOURCES 39 | QuicServerTransportTest.cpp 40 | DEPENDS 41 | Folly::folly 42 | mvfst_codec_pktbuilder 43 | mvfst_codec_types 44 | mvfst_folly_utils 45 | mvfst_server 46 | mvfst_state_stream_functions 47 | mvfst_test_utils 48 | mvfst_transport 49 | ) 50 | 51 | quic_add_test(TARGET ServerStateMachineTest 52 | SOURCES 53 | ServerStateMachineTest.cpp 54 | DEPENDS 55 | Folly::folly 56 | mvfst_server 57 | mvfst_test_utils 58 | ) 59 | 60 | quic_add_test(TARGET SlidingWindowRateLimiterTest 61 | SOURCES 62 | SlidingWindowRateLimiterTest.cpp 63 | DEPENDS 64 | Folly::folly 65 | mvfst_server 66 | ) 67 | -------------------------------------------------------------------------------- /quic/common/events/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library", "mvfst_cpp_test") 2 | load("@fbsource//tools/target_determinator/macros:ci.bzl", "ci") 3 | 4 | oncall("traffic_protocols") 5 | 6 | mvfst_cpp_library( 7 | name = "QuicEventBaseTestBase", 8 | headers = [ 9 | "QuicEventBaseTestBase.h", 10 | ], 11 | exported_deps = [ 12 | "//folly/portability:gtest", 13 | "//quic/common/events:eventbase", 14 | ], 15 | ) 16 | 17 | mvfst_cpp_test( 18 | name = "FollyQuicEventBaseTest", 19 | srcs = [ 20 | "FollyQuicEventBaseTest.cpp", 21 | ], 22 | supports_static_listing = False, 23 | deps = [ 24 | ":QuicEventBaseTestBase", 25 | "//folly/portability:gtest", 26 | "//quic/common/events:folly_eventbase", 27 | ], 28 | ) 29 | 30 | mvfst_cpp_test( 31 | name = "LibevQuicEventBaseTest", 32 | srcs = [ 33 | "LibevQuicEventBaseTest.cpp", 34 | ], 35 | labels = ci.labels(ci.remove(ci.windows())), 36 | supports_static_listing = False, 37 | deps = [ 38 | ":QuicEventBaseTestBase", 39 | "//folly/portability:gtest", 40 | "//quic/common/events:libev_eventbase", 41 | ], 42 | external_deps = [ 43 | "libev", 44 | ], 45 | ) 46 | 47 | mvfst_cpp_library( 48 | name = "QuicEventBaseMock", 49 | headers = [ 50 | "QuicEventBaseMock.h", 51 | ], 52 | exported_deps = [ 53 | "//folly/portability:gmock", 54 | "//quic/common/events:eventbase", 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /quic/fizz/client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_fizz_client 8 | handshake/FizzClientQuicHandshakeContext.cpp 9 | handshake/FizzClientHandshake.cpp 10 | ) 11 | 12 | set_property(TARGET mvfst_fizz_client PROPERTY VERSION ${PACKAGE_VERSION}) 13 | 14 | target_include_directories( 15 | mvfst_fizz_client PUBLIC 16 | $ 17 | $ 18 | ) 19 | 20 | target_compile_options( 21 | mvfst_fizz_client 22 | PRIVATE 23 | ${_QUIC_COMMON_COMPILE_OPTIONS} 24 | ) 25 | 26 | add_dependencies( 27 | mvfst_fizz_client 28 | mvfst_client 29 | mvfst_fizz_handshake 30 | ) 31 | 32 | target_link_libraries( 33 | mvfst_fizz_client PUBLIC 34 | mvfst_client 35 | mvfst_fizz_handshake 36 | ) 37 | 38 | file( 39 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 40 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 41 | *.h 42 | ) 43 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 44 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 45 | get_filename_component(header_dir ${header} DIRECTORY) 46 | install(FILES ${header} DESTINATION include/quic/fizz/client/${header_dir}) 47 | endforeach() 48 | 49 | install( 50 | TARGETS mvfst_fizz_client 51 | EXPORT mvfst-exports 52 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 53 | ) 54 | 55 | add_subdirectory(test) 56 | add_subdirectory(handshake/test) 57 | -------------------------------------------------------------------------------- /quic/observer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_observer 8 | SocketObserverInterface.cpp 9 | ) 10 | 11 | set_property(TARGET mvfst_observer PROPERTY VERSION ${PACKAGE_VERSION}) 12 | 13 | target_include_directories( 14 | mvfst_observer PUBLIC 15 | $ 16 | $ 17 | ) 18 | 19 | target_compile_options( 20 | mvfst_observer 21 | PRIVATE 22 | ${_QUIC_COMMON_COMPILE_OPTIONS} 23 | ) 24 | 25 | add_dependencies( 26 | mvfst_observer 27 | mvfst_constants 28 | mvfst_exception 29 | mvfst_state_ack_handler 30 | mvfst_state_machine 31 | ) 32 | 33 | target_link_libraries( 34 | mvfst_observer PUBLIC 35 | Folly::folly 36 | mvfst_constants 37 | mvfst_exception 38 | mvfst_state_ack_handler 39 | mvfst_state_machine 40 | PRIVATE 41 | ${BOOST_LIBRARIES} 42 | ) 43 | 44 | file( 45 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 46 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 47 | *.h 48 | ) 49 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 50 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 51 | get_filename_component(header_dir ${header} DIRECTORY) 52 | install(FILES ${header} DESTINATION include/quic/observer/${header_dir}) 53 | endforeach() 54 | 55 | install( 56 | TARGETS mvfst_observer 57 | EXPORT mvfst-exports 58 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 59 | ) 60 | -------------------------------------------------------------------------------- /quic/congestion_control/CongestionControllerFactoryMobile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace quic { 16 | std::unique_ptr 17 | DefaultCongestionControllerFactory::makeCongestionController( 18 | QuicConnectionStateBase& conn, 19 | CongestionControlType type) { 20 | std::unique_ptr congestionController; 21 | switch (type) { 22 | case CongestionControlType::Cubic: 23 | congestionController = std::make_unique(conn); 24 | break; 25 | case CongestionControlType::Copa: 26 | congestionController = std::make_unique(conn); 27 | break; 28 | case CongestionControlType::None: 29 | break; 30 | default: 31 | // Mobile builds only support Cubic and Copa 32 | LOG(ERROR) << "Unsupported congestion controller for mobile: " 33 | << congestionControlTypeToString(type) 34 | << ". Falling back to Cubic."; 35 | congestionController = std::make_unique(conn); 36 | break; 37 | } 38 | QUIC_STATS(conn.statsCallback, onNewCongestionController, type); 39 | return congestionController; 40 | } 41 | } // namespace quic 42 | -------------------------------------------------------------------------------- /quic/handshake/HandshakeLayer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | EncryptionLevel protectionTypeToEncryptionLevel(ProtectionType type) { 13 | switch (type) { 14 | case ProtectionType::Initial: 15 | return EncryptionLevel::Initial; 16 | case ProtectionType::Handshake: 17 | return EncryptionLevel::Handshake; 18 | case ProtectionType::ZeroRtt: 19 | return EncryptionLevel::EarlyData; 20 | case ProtectionType::KeyPhaseZero: 21 | case ProtectionType::KeyPhaseOne: 22 | return EncryptionLevel::AppData; 23 | } 24 | folly::assume_unreachable(); 25 | } 26 | 27 | folly::StringPiece getQuicVersionSalt(QuicVersion version) { 28 | switch (version) { 29 | case QuicVersion::MVFST_EXPERIMENTAL4: 30 | [[fallthrough]]; 31 | case QuicVersion::MVFST_EXPERIMENTAL5: 32 | return kQuicExperimentalSalt; 33 | case QuicVersion::QUIC_V1: 34 | [[fallthrough]]; 35 | case QuicVersion::QUIC_V1_ALIAS: 36 | [[fallthrough]]; 37 | case QuicVersion::QUIC_V1_ALIAS2: 38 | [[fallthrough]]; 39 | case QuicVersion::MVFST_PRIMING: 40 | return kQuicV1Salt; 41 | case QuicVersion::MVFST: 42 | [[fallthrough]]; 43 | default: 44 | // Default to one arbitrarily. 45 | return kQuicDraft23Salt; 46 | } 47 | } 48 | } // namespace quic 49 | -------------------------------------------------------------------------------- /quic/logging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_qlogger 8 | BaseQLogger.cpp 9 | FileQLogger.cpp 10 | QLogger.cpp 11 | QLoggerConstants.cpp 12 | QLoggerTypes.cpp 13 | QLogSchema.cpp 14 | ) 15 | 16 | set_property(TARGET mvfst_qlogger PROPERTY VERSION ${PACKAGE_VERSION}) 17 | 18 | target_include_directories( 19 | mvfst_qlogger PUBLIC 20 | $ 21 | $ 22 | ) 23 | 24 | target_compile_options( 25 | mvfst_qlogger 26 | PRIVATE 27 | ${_QUIC_COMMON_COMPILE_OPTIONS} 28 | ) 29 | 30 | add_dependencies( 31 | mvfst_qlogger 32 | mvfst_codec_types 33 | mvfst_folly_utils 34 | mvfst_state_machine 35 | ) 36 | 37 | target_link_libraries( 38 | mvfst_qlogger PUBLIC 39 | Folly::folly 40 | mvfst_codec_types 41 | mvfst_string_utils 42 | mvfst_folly_utils 43 | ) 44 | 45 | file( 46 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 47 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 48 | *.h 49 | ) 50 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 51 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 52 | get_filename_component(header_dir ${header} DIRECTORY) 53 | install(FILES ${header} DESTINATION include/quic/logging/${header_dir}) 54 | endforeach() 55 | 56 | install( 57 | TARGETS mvfst_qlogger 58 | EXPORT mvfst-exports 59 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 60 | ) 61 | 62 | add_subdirectory(test) 63 | -------------------------------------------------------------------------------- /quic/server/async_tran/QuicServerAsyncTransport.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | void QuicServerAsyncTransport::setServerSocket( 13 | std::shared_ptr sock) { 14 | setSocket(std::move(sock)); 15 | } 16 | 17 | void QuicServerAsyncTransport::onNewBidirectionalStream(StreamId id) noexcept { 18 | CHECK_EQ(id, 0) << "only single stream w/ id=0 is supported"; 19 | setStreamId(id); 20 | } 21 | 22 | void QuicServerAsyncTransport::onNewUnidirectionalStream( 23 | StreamId /*id*/) noexcept { 24 | LOG(FATAL) << "Unidirectional stream not supported"; 25 | } 26 | 27 | void QuicServerAsyncTransport::onStopSending( 28 | StreamId /*id*/, 29 | ApplicationErrorCode /*error*/) noexcept {} 30 | 31 | void QuicServerAsyncTransport::onConnectionEnd() noexcept { 32 | folly::AsyncSocketException ex( 33 | folly::AsyncSocketException::UNKNOWN, "Quic connection ended"); 34 | closeNowImpl(std::move(ex)); 35 | } 36 | 37 | void QuicServerAsyncTransport::onConnectionError(QuicError code) noexcept { 38 | folly::AsyncSocketException ex( 39 | folly::AsyncSocketException::UNKNOWN, 40 | fmt::format("Quic connection error {}", code.message)); 41 | closeNowImpl(std::move(ex)); 42 | } 43 | 44 | void QuicServerAsyncTransport::onTransportReady() noexcept {} 45 | 46 | } // namespace quic 47 | -------------------------------------------------------------------------------- /quic/fizz/handshake/FizzPacketNumberCipher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace quic { 15 | 16 | class Aes128PacketNumberCipher : public PacketNumberCipher { 17 | public: 18 | ~Aes128PacketNumberCipher() override = default; 19 | 20 | [[nodiscard]] quic::Expected setKey(ByteRange key) override; 21 | 22 | [[nodiscard]] const BufPtr& getKey() const override; 23 | 24 | [[nodiscard]] quic::Expected mask( 25 | ByteRange sample) const override; 26 | 27 | [[nodiscard]] size_t keyLength() const override; 28 | 29 | private: 30 | folly::ssl::EvpCipherCtxUniquePtr encryptCtx_; 31 | 32 | BufPtr pnKey_; 33 | }; 34 | 35 | class Aes256PacketNumberCipher : public PacketNumberCipher { 36 | public: 37 | ~Aes256PacketNumberCipher() override = default; 38 | 39 | [[nodiscard]] quic::Expected setKey(ByteRange key) override; 40 | 41 | [[nodiscard]] const BufPtr& getKey() const override; 42 | 43 | [[nodiscard]] quic::Expected mask( 44 | ByteRange sample) const override; 45 | 46 | [[nodiscard]] size_t keyLength() const override; 47 | 48 | private: 49 | folly::ssl::EvpCipherCtxUniquePtr encryptCtx_; 50 | 51 | BufPtr pnKey_; 52 | }; 53 | 54 | } // namespace quic 55 | -------------------------------------------------------------------------------- /quic/xsk/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "xsk_lib", 7 | srcs = [ 8 | "packet_utils.cpp", 9 | "xsk_lib.cpp", 10 | ], 11 | headers = [ 12 | "packet_utils.h", 13 | "xsk_lib.h", 14 | ], 15 | deps = [ 16 | "//folly:benchmark", 17 | ], 18 | exported_deps = [ 19 | "//folly:network_address", 20 | ], 21 | external_deps = [ 22 | ("glibc", None, "rt"), 23 | ], 24 | ) 25 | 26 | mvfst_cpp_library( 27 | name = "xsk_container", 28 | srcs = [ 29 | "BaseXskContainer.cpp", 30 | "HashingXskContainer.cpp", 31 | "ThreadLocalXskContainer.cpp", 32 | ], 33 | headers = [ 34 | "BaseXskContainer.h", 35 | "HashingXskContainer.h", 36 | "ThreadLocalXskContainer.h", 37 | ], 38 | deps = [ 39 | ], 40 | exported_deps = [ 41 | ":xsk_sender", 42 | "//folly:thread_local", 43 | "//folly/container:f14_hash", 44 | ], 45 | ) 46 | 47 | mvfst_cpp_library( 48 | name = "xsk_sender", 49 | srcs = ["XskSender.cpp"], 50 | headers = [ 51 | "XskSender.h", 52 | ], 53 | deps = [ 54 | "//folly:benchmark", 55 | "//quic/common:string_utils", 56 | ], 57 | exported_deps = [ 58 | ":xsk_lib", 59 | "//folly:network_address", 60 | "//folly/container:f14_hash", 61 | "//folly/io:iobuf", 62 | "//quic/common:expected", 63 | "//quic/common:optional", 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /quic/server/handshake/StatelessResetGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace quic { 15 | 16 | using StatelessResetSecret = 17 | std::array; 18 | 19 | /** 20 | * A StatelessResetToken generator. 21 | * 22 | * This generator takes in a StatelessResetSecret, and a string that represents 23 | * the server address. It generates a different StatelessResetToken given a 24 | * different ConnectionId. 25 | * 26 | * The StatelessResetSecret is provided to HKDF to generate a pesudorandom key. 27 | * Address string and ConnectionId are concated together, as app specific 28 | * input in HKDF-Expand. The output of HKDF will be the StatelessResetToken. 29 | * 30 | * PRK = HKDF-Extract(Salt, secret) 31 | * appInfo = Concat(connId, addrString); 32 | * Token = HKDF-Expand(PRK, appInfo, tokenLength) 33 | */ 34 | class StatelessResetGenerator { 35 | public: 36 | explicit StatelessResetGenerator( 37 | StatelessResetSecret secret, 38 | const std::string& addressStr); 39 | 40 | [[nodiscard]] StatelessResetToken generateToken( 41 | const ConnectionId& connId) const; 42 | 43 | private: 44 | std::string addressStr_; 45 | fizz::Hkdf hkdf_; 46 | std::vector extractedSecret_; 47 | }; 48 | } // namespace quic 49 | -------------------------------------------------------------------------------- /quic/server/async_tran/QuicServerAsyncTransport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace quic { 13 | 14 | class QuicServerAsyncTransport : public QuicStreamAsyncTransport, 15 | public QuicSocket::ConnectionSetupCallback, 16 | public QuicSocket::ConnectionCallback { 17 | public: 18 | using UniquePtr = std::unique_ptr< 19 | QuicServerAsyncTransport, 20 | folly::DelayedDestruction::Destructor>; 21 | QuicServerAsyncTransport() = default; 22 | void setServerSocket(std::shared_ptr sock); 23 | 24 | protected: 25 | ~QuicServerAsyncTransport() override = default; 26 | 27 | // 28 | // QuicSocket::ConnectionCallback 29 | // 30 | void onNewBidirectionalStream(StreamId id) noexcept override; 31 | void onNewUnidirectionalStream(StreamId id) noexcept override; 32 | void onStopSending(StreamId id, ApplicationErrorCode error) noexcept override; 33 | void onConnectionEnd() noexcept override; 34 | 35 | void onConnectionSetupError(QuicError code) noexcept override { 36 | onConnectionError(std::move(code)); 37 | } 38 | 39 | void onConnectionError(QuicError code) noexcept override; 40 | 41 | void onConnectionEnd(QuicError /*error*/) noexcept override {} 42 | 43 | void onTransportReady() noexcept override; 44 | }; 45 | } // namespace quic 46 | -------------------------------------------------------------------------------- /quic/BUILD_MODE.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Facebook 2 | 3 | """ build mode definitions for quic """ 4 | 5 | load("@fbcode//:BUILD_MODE.bzl", get_parent_modes = "get_empty_modes") 6 | load("@fbcode_macros//build_defs:create_build_mode.bzl", "extend_build_modes") 7 | 8 | _extra_cflags = [ 9 | ] 10 | 11 | _common_flags = [ 12 | "-Wextra-semi", 13 | "-Wformat", 14 | "-Wformat-security", 15 | "-Wunused-function", 16 | "-Wunused-parameter", 17 | "-Wunused-variable", 18 | "-Wsign-compare", 19 | "-Wtype-limits", 20 | "-Wunused-value", 21 | # TODO this seems to break trunk (https://fb.workplace.com/groups/askbuck/permalink/4366767820038466/) 22 | # Re-enable after investigating the issue 23 | # "-Wno-module-import-in-extern-c", 24 | ] 25 | 26 | _extra_clang_flags = _common_flags + [ 27 | "-Wconstant-conversion", 28 | # Default value for clang (3.4) is 256, change it to GCC's default value 29 | # (https://fburl.com/23278774). 30 | "-ftemplate-depth=900", 31 | "-Wmismatched-tags", 32 | # Only check shadowing with Clang: gcc complains about constructor 33 | # argument shadowing 34 | "-Wshadow", 35 | "-Wunused-exception-parameter", 36 | "-Wheader-hygiene", 37 | "-Wall", 38 | "-Wextra", 39 | ] 40 | 41 | _extra_gcc_flags = _common_flags + [ 42 | "-Wall", 43 | ] 44 | 45 | _modes = extend_build_modes( 46 | get_parent_modes(), 47 | c_flags = _extra_cflags, 48 | clang_flags = _extra_clang_flags, 49 | gcc_flags = _extra_gcc_flags, 50 | ) 51 | 52 | def get_modes(): 53 | """ Return modes for this file """ 54 | return _modes 55 | -------------------------------------------------------------------------------- /quic/priority/RoundRobin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace quic { 17 | 18 | class RoundRobin { 19 | public: 20 | void advanceAfterNext(size_t n); 21 | void advanceAfterBytes(uint64_t bytes); 22 | 23 | [[nodiscard]] bool empty() const; 24 | void insert(quic::PriorityQueue::Identifier value); 25 | bool erase(quic::PriorityQueue::Identifier value); 26 | quic::PriorityQueue::Identifier getNext( 27 | const quic::Optional& bytes); 28 | [[nodiscard]] quic::PriorityQueue::Identifier peekNext() const; 29 | void consume(const quic::Optional& bytes); 30 | void clear(); 31 | 32 | private: 33 | using ListType = std::list; 34 | 35 | void erase(ListType::iterator eraseIt); 36 | void maybeAdvance(); 37 | void buildIndex(); 38 | 39 | ListType list_; 40 | ListType::iterator nextIt_{list_.end()}; 41 | ValueMap< 42 | PriorityQueue::Identifier, 43 | ListType::iterator, 44 | PriorityQueue::Identifier::hash> 45 | indexMap_; 46 | enum class AdvanceType : uint8_t { Nexts, Bytes }; 47 | AdvanceType advanceType_{AdvanceType::Nexts}; 48 | bool useIndexMap_{false}; 49 | uint64_t advanceAfter_{1}; 50 | uint64_t current_{0}; 51 | }; 52 | 53 | } // namespace quic 54 | -------------------------------------------------------------------------------- /quic/common/udpsocket/test/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library", "mvfst_cpp_test") 2 | load("@fbsource//tools/target_determinator/macros:ci.bzl", "ci") 3 | 4 | oncall("traffic_protocols") 5 | 6 | mvfst_cpp_library( 7 | name = "QuicAsyncUDPSocketMock", 8 | headers = [ 9 | "QuicAsyncUDPSocketMock.h", 10 | ], 11 | exported_deps = [ 12 | "//folly/portability:gmock", 13 | "//quic/common/udpsocket:quic_async_udp_socket", 14 | ], 15 | ) 16 | 17 | mvfst_cpp_library( 18 | name = "QuicAsyncUDPSocketTestBase", 19 | headers = [ 20 | "QuicAsyncUDPSocketTestBase.h", 21 | ], 22 | exported_deps = [ 23 | ":QuicAsyncUDPSocketMock", 24 | "//folly/portability:gtest", 25 | ], 26 | ) 27 | 28 | mvfst_cpp_test( 29 | name = "FollyQuicAsyncUDPSocketTest", 30 | srcs = [ 31 | "FollyQuicAsyncUDPSocketTest.cpp", 32 | ], 33 | supports_static_listing = False, 34 | deps = [ 35 | ":QuicAsyncUDPSocketTestBase", 36 | "//folly/portability:gtest", 37 | "//quic/common/udpsocket:folly_async_udp_socket", 38 | ], 39 | ) 40 | 41 | mvfst_cpp_test( 42 | name = "LibevQuicAsyncUDPSocketTest", 43 | srcs = [ 44 | "LibevQuicAsyncUDPSocketTest.cpp", 45 | ], 46 | labels = ci.labels(ci.remove(ci.windows())), 47 | supports_static_listing = False, 48 | deps = [ 49 | ":QuicAsyncUDPSocketTestBase", 50 | "//folly/portability:gtest", 51 | "//quic/common/udpsocket:libev_async_udp_socket", 52 | ], 53 | external_deps = [ 54 | "libev", 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /quic/handshake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_handshake 8 | CryptoFactory.cpp 9 | HandshakeLayer.cpp 10 | TransportParameters.cpp 11 | ) 12 | 13 | set_property(TARGET mvfst_handshake PROPERTY VERSION ${PACKAGE_VERSION}) 14 | 15 | target_include_directories( 16 | mvfst_handshake PUBLIC 17 | $ 18 | $ 19 | ) 20 | 21 | target_compile_options( 22 | mvfst_handshake 23 | PRIVATE 24 | ${_QUIC_COMMON_COMPILE_OPTIONS} 25 | ) 26 | 27 | add_dependencies( 28 | mvfst_handshake 29 | mvfst_constants 30 | mvfst_exception 31 | mvfst_codec_types 32 | mvfst_folly_utils 33 | mvfst_codec_packet_number_cipher 34 | ) 35 | 36 | target_link_libraries( 37 | mvfst_handshake PUBLIC 38 | Folly::folly 39 | mvfst_constants 40 | mvfst_exception 41 | mvfst_codec_types 42 | mvfst_folly_utils 43 | mvfst_codec_packet_number_cipher 44 | ) 45 | 46 | file( 47 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 48 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 49 | *.h 50 | ) 51 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 52 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 53 | get_filename_component(header_dir ${header} DIRECTORY) 54 | install(FILES ${header} DESTINATION include/quic/handshake/${header_dir}) 55 | endforeach() 56 | 57 | install( 58 | TARGETS mvfst_handshake 59 | EXPORT mvfst-exports 60 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 61 | ) 62 | -------------------------------------------------------------------------------- /quic/state/QuicAckFrequencyFunctions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | namespace quic { 12 | 13 | bool canSendAckControlFrames(const QuicConnectionStateBase& conn) { 14 | return conn.peerMinAckDelay.has_value(); 15 | } 16 | 17 | void requestPeerAckFrequencyChange( 18 | QuicConnectionStateBase& conn, 19 | uint64_t ackElicitingThreshold, 20 | std::chrono::microseconds maxAckDelay, 21 | uint64_t reorderThreshold) { 22 | CHECK(conn.peerMinAckDelay.has_value()); 23 | AckFrequencyFrame frame; 24 | frame.packetTolerance = ackElicitingThreshold; 25 | frame.updateMaxAckDelay = maxAckDelay.count(); 26 | frame.reorderThreshold = reorderThreshold; 27 | frame.sequenceNumber = conn.nextAckFrequencyFrameSequenceNumber++; 28 | conn.pendingEvents.frames.emplace_back(frame); 29 | } 30 | 31 | std::chrono::microseconds clampMaxAckDelay( 32 | const QuicConnectionStateBase& conn, 33 | std::chrono::microseconds maxAckDelay) { 34 | CHECK(conn.peerMinAckDelay.has_value()); 35 | return timeMax(maxAckDelay, conn.peerMinAckDelay.value()); 36 | } 37 | 38 | /** 39 | * Send an IMMEDIATE_ACK frame to request the peer to send an ACK immediately 40 | */ 41 | void requestPeerImmediateAck(QuicConnectionStateBase& conn) { 42 | CHECK(conn.peerMinAckDelay.has_value()); 43 | conn.pendingEvents.requestImmediateAck = true; 44 | } 45 | } // namespace quic 46 | -------------------------------------------------------------------------------- /quic/flowcontrol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_flowcontrol 8 | QuicFlowController.cpp 9 | ) 10 | 11 | set_property(TARGET mvfst_flowcontrol PROPERTY VERSION ${PACKAGE_VERSION}) 12 | 13 | target_include_directories( 14 | mvfst_flowcontrol PUBLIC 15 | $ 16 | $ 17 | ) 18 | 19 | target_compile_options( 20 | mvfst_flowcontrol 21 | PRIVATE 22 | ${_QUIC_COMMON_COMPILE_OPTIONS} 23 | ) 24 | 25 | add_dependencies( 26 | mvfst_flowcontrol 27 | mvfst_constants 28 | mvfst_exception 29 | mvfst_codec_types 30 | mvfst_folly_utils 31 | mvfst_state_machine 32 | mvfst_qlogger 33 | ) 34 | 35 | target_link_libraries( 36 | mvfst_flowcontrol PUBLIC 37 | Folly::folly 38 | mvfst_codec_types 39 | mvfst_folly_utils 40 | mvfst_constants 41 | mvfst_exception 42 | mvfst_state_machine 43 | mvfst_qlogger 44 | ) 45 | 46 | file( 47 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 48 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 49 | *.h 50 | ) 51 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 52 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 53 | get_filename_component(header_dir ${header} DIRECTORY) 54 | install(FILES ${header} DESTINATION include/quic/flowcontrol/${header_dir}) 55 | endforeach() 56 | 57 | install( 58 | TARGETS mvfst_flowcontrol 59 | EXPORT mvfst-exports 60 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 61 | ) 62 | 63 | add_subdirectory(test) 64 | -------------------------------------------------------------------------------- /quic/fizz/server/handshake/AppToken.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace quic { 17 | 18 | std::unique_ptr encodeAppToken(const AppToken& appToken); 19 | 20 | Optional decodeAppToken(const folly::IOBuf& buf); 21 | 22 | } // namespace quic 23 | 24 | namespace fizz::detail { 25 | 26 | template <> 27 | struct Reader { 28 | template 29 | size_t read(folly::IPAddress& ipAddress, folly::io::Cursor& cursor) { 30 | std::unique_ptr sourceAddressBuf; 31 | size_t len = readBuf(sourceAddressBuf, cursor); 32 | ipAddress = folly::IPAddress::fromBinary(sourceAddressBuf->coalesce()); 33 | return len; 34 | } 35 | }; 36 | 37 | template <> 38 | struct Writer { 39 | template 40 | void write(const folly::IPAddress& ipAddress, folly::io::Appender& out) { 41 | DCHECK(!ipAddress.empty()); 42 | auto buf = 43 | folly::IOBuf::wrapBuffer(ipAddress.bytes(), ipAddress.byteCount()); 44 | writeBuf(buf, out); 45 | } 46 | }; 47 | 48 | template <> 49 | struct Sizer { 50 | template 51 | size_t getSize(const folly::IPAddress& ipAddress) { 52 | return sizeof(uint8_t) + ipAddress.byteCount(); 53 | } 54 | }; 55 | 56 | } // namespace fizz::detail 57 | -------------------------------------------------------------------------------- /quic/fizz/handshake/FizzCryptoFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | class FizzCryptoFactory : public CryptoFactory { 16 | public: 17 | FizzCryptoFactory() : fizzFactory_{std::make_shared()} {} 18 | 19 | [[nodiscard]] quic::Expected makeInitialTrafficSecret( 20 | folly::StringPiece label, 21 | const ConnectionId& clientDestinationConnId, 22 | QuicVersion version) const override; 23 | 24 | [[nodiscard]] quic::Expected, QuicError> 25 | makeInitialAead( 26 | folly::StringPiece label, 27 | const ConnectionId& clientDestinationConnId, 28 | QuicVersion version) const override; 29 | 30 | [[nodiscard]] quic::Expected, QuicError> 31 | makePacketNumberCipher(ByteRange baseSecret) const override; 32 | 33 | [[nodiscard]] virtual quic:: 34 | Expected, QuicError> 35 | makePacketNumberCipher(fizz::CipherSuite cipher) const; 36 | 37 | [[nodiscard]] std::function 38 | getCryptoEqualFunction() const override; 39 | 40 | std::shared_ptr getFizzFactory() { 41 | return fizzFactory_; 42 | } 43 | 44 | protected: 45 | std::shared_ptr fizzFactory_; 46 | }; 47 | 48 | } // namespace quic 49 | -------------------------------------------------------------------------------- /quic/handshake/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "aead", 7 | headers = [ 8 | "Aead.h", 9 | ], 10 | exported_deps = [ 11 | "//quic:constants", 12 | "//quic:exception", 13 | "//quic/common:expected", 14 | "//quic/common:optional", 15 | ], 16 | ) 17 | 18 | mvfst_cpp_library( 19 | name = "handshake", 20 | srcs = [ 21 | "CryptoFactory.cpp", 22 | "HandshakeLayer.cpp", 23 | ], 24 | headers = [ 25 | "CryptoFactory.h", 26 | "HandshakeLayer.h", 27 | ], 28 | exported_deps = [ 29 | ":aead", 30 | "//quic:constants", 31 | "//quic:exception", 32 | "//quic/codec:packet_number_cipher", 33 | "//quic/codec:types", 34 | "//quic/common:expected", 35 | ], 36 | ) 37 | 38 | mvfst_cpp_library( 39 | name = "transport_parameters", 40 | srcs = [ 41 | "TransportParameters.cpp", 42 | ], 43 | headers = [ 44 | "TransportParameters.h", 45 | ], 46 | deps = [ 47 | "//quic/common:buf_util", 48 | "//quic/state:quic_state_machine", 49 | ], 50 | exported_deps = [ 51 | "//quic:constants", 52 | "//quic:exception", 53 | "//quic/codec:types", 54 | "//quic/common:expected", 55 | ], 56 | ) 57 | 58 | mvfst_cpp_library( 59 | name = "retry_integrity_tag_generator", 60 | headers = [ 61 | "RetryIntegrityTagGenerator.h", 62 | ], 63 | exported_deps = [ 64 | "//folly/io:iobuf", 65 | "//quic:constants", 66 | ], 67 | ) 68 | -------------------------------------------------------------------------------- /quic/server/SlidingWindowRateLimiter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace quic { 15 | 16 | /* 17 | * Simple "sliding window" rate limiter. This enforces a rate limit of count 18 | * events per window. The window "slides" by multiplying the average rate of 19 | * the previous full window by the amount of time that the current sliding 20 | * window occurred in the previous window. 21 | * E.g. 22 | * Limit of 100 events per 10s. The previous window had 50 events. The current 23 | * window has had 5 events. We check an event 3 seconds into our current 24 | * window. The sliding window has 3 seconds in our current window, and 7 25 | * seconds in the previous window. We psuedo-count for the current sliding 26 | * window is: 50/10 * 7 + 5 + 1 = 41. 27 | */ 28 | class SlidingWindowRateLimiter : public RateLimiter { 29 | public: 30 | SlidingWindowRateLimiter( 31 | std::function count, 32 | std::chrono::seconds window) 33 | : count_(std::move(count)), window_(window) {} 34 | 35 | bool check(TimePoint time) override; 36 | 37 | private: 38 | const std::function count_; 39 | const std::chrono::microseconds window_; 40 | Optional currentWindowStartPoint_{std::nullopt}; 41 | uint64_t countInPrevWindow_{0}; 42 | uint64_t countInCurWindow_{0}; 43 | }; 44 | 45 | } // namespace quic 46 | -------------------------------------------------------------------------------- /quic/state/test/AckEventTestUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace quic::test { 16 | 17 | /** 18 | * Builder for matcher for AckEvent::detailsPerStream elements. 19 | * 20 | * Reduces the amount of boilerplate code in unit tests, improving readability. 21 | */ 22 | struct AckEventStreamDetailsMatcherBuilder { 23 | using Builder = AckEventStreamDetailsMatcherBuilder; 24 | using DupAckedStreamIntervals = 25 | AckEvent::AckPacket::StreamDetails::DupAckedStreamIntervals; 26 | 27 | explicit AckEventStreamDetailsMatcherBuilder() = default; 28 | 29 | Builder&& setStreamID(const uint64_t streamIdIn); 30 | Builder&& addDupAckedStreamInterval( 31 | const DupAckedStreamIntervals::interval_type& intervalIn); 32 | Builder&& addDupAckedStreamInterval( 33 | const uint64_t startIn, 34 | const uint64_t endIn); 35 | Builder&& clearDupAckedStreamIntervals(); 36 | 37 | auto build() && { 38 | CHECK(maybeStreamId.has_value()); 39 | return ::testing::Pair( 40 | maybeStreamId.value(), 41 | ::testing::Field( 42 | &AckEvent::AckPacket::StreamDetails::dupAckedStreamIntervals, 43 | dupAckedStreamIntervals)); 44 | } 45 | 46 | private: 47 | Optional maybeStreamId; 48 | DupAckedStreamIntervals dupAckedStreamIntervals; 49 | }; 50 | 51 | } // namespace quic::test 52 | -------------------------------------------------------------------------------- /quic/common/test/QuicRangeConversionTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | namespace quic::test { 12 | 13 | TEST(QuicRangeConversionTest, MutableToConstConversion) { 14 | // Test basic conversion from MutableByteRange to ByteRange 15 | uint8_t data[] = {1, 2, 3, 4, 5}; 16 | MutableByteRange mutableRange(data, sizeof(data)); 17 | 18 | // Implicit conversion should work 19 | ByteRange constRange = mutableRange; 20 | 21 | EXPECT_EQ(constRange.size(), 5); 22 | EXPECT_EQ(constRange[0], 1); 23 | EXPECT_EQ(constRange[4], 5); 24 | } 25 | 26 | TEST(QuicRangeConversionTest, PassToFunction) { 27 | // Test that we can pass MutableByteRange to a function expecting ByteRange 28 | auto processBytes = [](ByteRange range) -> size_t { return range.size(); }; 29 | 30 | uint8_t data[] = {1, 2, 3}; 31 | MutableByteRange mutableRange(data, sizeof(data)); 32 | 33 | // Should be able to pass mutableRange directly 34 | EXPECT_EQ(processBytes(mutableRange), 3); 35 | } 36 | 37 | TEST(QuicRangeConversionTest, CopyConstruction) { 38 | // Test explicit copy construction 39 | uint8_t data[] = {10, 20, 30}; 40 | MutableByteRange mutableRange(data, sizeof(data)); 41 | 42 | ByteRange constRange(mutableRange); 43 | 44 | EXPECT_EQ(constRange.size(), 3); 45 | EXPECT_EQ(constRange[0], 10); 46 | EXPECT_EQ(constRange[1], 20); 47 | EXPECT_EQ(constRange[2], 30); 48 | } 49 | 50 | } // namespace quic::test 51 | -------------------------------------------------------------------------------- /quic/api/QuicBatchWriterFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic { 11 | 12 | // BatchWriterDeleter 13 | void BatchWriterDeleter::operator()(BatchWriter* batchWriter) { 14 | delete batchWriter; 15 | } 16 | 17 | BatchWriterPtr makeGsoBatchWriter(uint32_t batchSize) { 18 | return BatchWriterPtr(new GSOPacketBatchWriter(batchSize)); 19 | } 20 | 21 | BatchWriterPtr makeGsoInPlaceBatchWriter( 22 | uint32_t batchSize, 23 | QuicConnectionStateBase& conn) { 24 | return BatchWriterPtr(new GSOInplacePacketBatchWriter(conn, batchSize)); 25 | } 26 | 27 | BatchWriterPtr makeSendmmsgGsoBatchWriter(uint32_t batchSize) { 28 | return BatchWriterPtr(new SendmmsgGSOPacketBatchWriter(batchSize)); 29 | } 30 | 31 | BatchWriterPtr makeSendmmsgInplaceGsoInplaceBatchWriter( 32 | uint32_t batchSize, 33 | QuicConnectionStateBase& conn) { 34 | return BatchWriterPtr( 35 | new SendmmsgGSOInplacePacketBatchWriter(conn, batchSize)); 36 | } 37 | 38 | BatchWriterPtr BatchWriterFactory::makeBatchWriter( 39 | const quic::QuicBatchingMode& batchingMode, 40 | uint32_t batchSize, 41 | bool enableBackpressure, 42 | DataPathType dataPathType, 43 | QuicConnectionStateBase& conn, 44 | bool gsoSupported) { 45 | return makeBatchWriterHelper( 46 | batchingMode, 47 | batchSize, 48 | enableBackpressure, 49 | dataPathType, 50 | conn, 51 | gsoSupported); 52 | } 53 | 54 | } // namespace quic 55 | -------------------------------------------------------------------------------- /quic/congestion_control/third_party/LICENSE: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Chromium Authors. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /quic/state/AckedPacketIterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace quic { 17 | 18 | class AckedPacketIterator { 19 | public: 20 | AckedPacketIterator( 21 | const quic::ReadAckFrame::Vec& ackBlocks, 22 | QuicConnectionStateBase& conn, 23 | PacketNumberSpace pnSpace); 24 | 25 | OutstandingPacketWrapper& operator*(); 26 | 27 | OutstandingPacketWrapper* operator->(); 28 | 29 | // Erase acked outstandings, starting at outstandingsIter_ and the ack 30 | // block starting at ackBlockIter_. The most common use case would be to 31 | // just create an AckedPacketIterator, call eraseAckedOutstandings, and 32 | // then discard the iterator. 33 | void eraseAckedOutstandings(); 34 | 35 | bool valid(); 36 | 37 | void next(); 38 | 39 | private: 40 | enum class MoveResult { SUCCESS = 0, FAILURE = 1 }; 41 | 42 | MoveResult moveToNextValid(); 43 | 44 | MoveResult moveToNextValidInAckBlock(const AckBlock& ackBlock); 45 | 46 | const quic::ReadAckFrame::Vec& ackBlocks_; 47 | QuicConnectionStateBase& conn_; 48 | PacketNumberSpace pnSpace_; 49 | std::deque::reverse_iterator outstandingsIter_; 50 | quic::ReadAckFrame::Vec::const_iterator ackBlockIter_; 51 | bool valid_{true}; 52 | }; 53 | 54 | } // namespace quic 55 | -------------------------------------------------------------------------------- /quic/fizz/handshake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_fizz_handshake 8 | FizzBridge.cpp 9 | FizzCryptoFactory.cpp 10 | FizzPacketNumberCipher.cpp 11 | FizzRetryIntegrityTagGenerator.cpp 12 | QuicFizzFactory.cpp 13 | ) 14 | 15 | set_property(TARGET mvfst_fizz_handshake PROPERTY VERSION ${PACKAGE_VERSION}) 16 | 17 | target_include_directories( 18 | mvfst_fizz_handshake PUBLIC 19 | $ 20 | $ 21 | $ 22 | ) 23 | 24 | target_compile_options( 25 | mvfst_fizz_handshake 26 | PRIVATE 27 | ${_QUIC_COMMON_COMPILE_OPTIONS} 28 | ) 29 | 30 | add_dependencies( 31 | mvfst_fizz_handshake 32 | ${LIBFIZZ_LIBRARY} 33 | mvfst_handshake 34 | mvfst_codec_packet_number_cipher 35 | ) 36 | 37 | target_link_libraries( 38 | mvfst_fizz_handshake PUBLIC 39 | ${LIBFIZZ_LIBRARY} 40 | mvfst_handshake 41 | mvfst_codec_packet_number_cipher 42 | ) 43 | 44 | file( 45 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 46 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 47 | *.h 48 | ) 49 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 50 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 51 | get_filename_component(header_dir ${header} DIRECTORY) 52 | install(FILES ${header} DESTINATION include/quic/fizz/handshake/${header_dir}) 53 | endforeach() 54 | 55 | install( 56 | TARGETS mvfst_fizz_handshake 57 | EXPORT mvfst-exports 58 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 59 | ) 60 | 61 | add_subdirectory(test) 62 | -------------------------------------------------------------------------------- /quic/loss/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | add_library( 7 | mvfst_loss 8 | QuicLossFunctions.cpp 9 | ) 10 | 11 | set_property(TARGET mvfst_loss PROPERTY VERSION ${PACKAGE_VERSION}) 12 | 13 | target_include_directories( 14 | mvfst_loss PUBLIC 15 | $ 16 | $ 17 | ) 18 | 19 | target_compile_options( 20 | mvfst_loss 21 | PRIVATE 22 | ${_QUIC_COMMON_COMPILE_OPTIONS} 23 | ) 24 | 25 | add_dependencies( 26 | mvfst_loss 27 | mvfst_codec_types 28 | mvfst_folly_utils 29 | mvfst_constants 30 | mvfst_exception 31 | mvfst_flowcontrol 32 | mvfst_state_functions 33 | mvfst_state_machine 34 | mvfst_state_simple_frame_functions 35 | ) 36 | 37 | target_link_libraries( 38 | mvfst_loss PUBLIC 39 | Folly::folly 40 | mvfst_codec_types 41 | mvfst_folly_utils 42 | mvfst_constants 43 | mvfst_exception 44 | mvfst_flowcontrol 45 | mvfst_state_functions 46 | mvfst_state_machine 47 | mvfst_state_simple_frame_functions 48 | ) 49 | 50 | file( 51 | GLOB_RECURSE QUIC_API_HEADERS_TOINSTALL 52 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 53 | *.h 54 | ) 55 | list(FILTER QUIC_API_HEADERS_TOINSTALL EXCLUDE REGEX test/) 56 | foreach(header ${QUIC_API_HEADERS_TOINSTALL}) 57 | get_filename_component(header_dir ${header} DIRECTORY) 58 | install(FILES ${header} DESTINATION include/quic/loss/${header_dir}) 59 | endforeach() 60 | 61 | install( 62 | TARGETS mvfst_loss 63 | EXPORT mvfst-exports 64 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 65 | ) 66 | 67 | add_subdirectory(test) 68 | -------------------------------------------------------------------------------- /quic/common/SocketUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace quic { 16 | 17 | inline bool isNetworkUnreachable(int err) { 18 | return err == EHOSTUNREACH || err == ENETUNREACH; 19 | } 20 | 21 | // T should have this method: 22 | // applyOptions( 23 | // const folly::SocketOptionMap& /* options */, 24 | // folly::SocketOptionKey::ApplyPos /* pos */) 25 | template 26 | quic::Expected applySocketOptions( 27 | T& sock, 28 | const folly::SocketOptionMap& options, 29 | sa_family_t family, 30 | folly::SocketOptionKey::ApplyPos pos) noexcept { 31 | folly::SocketOptionMap validOptions; 32 | 33 | for (const auto& option : options) { 34 | if (pos != option.first.applyPos_) { 35 | continue; 36 | } 37 | if ((family == AF_INET && option.first.level == IPPROTO_IP) || 38 | (family == AF_INET6 && option.first.level == IPPROTO_IPV6) || 39 | #ifdef IP_BIND_ADDRESS_NO_PORT 40 | (option.first.level == IPPROTO_IP && 41 | option.first.optname == IP_BIND_ADDRESS_NO_PORT) || 42 | #endif 43 | #ifndef _WIN32 44 | option.first.level == SOL_UDP || 45 | #endif 46 | option.first.level == IPPROTO_UDP || option.first.level == SOL_SOCKET) { 47 | validOptions.insert(option); 48 | } 49 | } 50 | return sock.applyOptions(validOptions, pos); 51 | } 52 | 53 | } // namespace quic 54 | -------------------------------------------------------------------------------- /quic/fizz/client/handshake/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "fizz_client_handshake", 7 | srcs = [ 8 | "FizzClientHandshake.cpp", 9 | "FizzClientQuicHandshakeContext.cpp", 10 | ], 11 | headers = [ 12 | "FizzClientExtensions.h", 13 | "FizzClientHandshake.h", 14 | "FizzClientQuicHandshakeContext.h", 15 | ], 16 | deps = [ 17 | "//fizz/client:early_data_rejection", 18 | "//fizz/protocol:exporter", 19 | "//fizz/protocol:protocol", 20 | "//quic/codec:pktbuilder", 21 | ], 22 | exported_deps = [ 23 | ":psk_cache", 24 | "//fizz/client:actions", 25 | "//fizz/client:async_fizz_client", 26 | "//fizz/client:client_extensions", 27 | "//fizz/client:ech_policy", 28 | "//fizz/client:fizz_client_context", 29 | "//fizz/client:protocol", 30 | "//fizz/extensions/clientpadding:types", 31 | "//fizz/protocol:default_certificate_verifier", 32 | "//quic/client:client_extension", 33 | "//quic/client:state_and_handshake", 34 | "//quic/fizz/handshake:fizz_handshake", 35 | ], 36 | ) 37 | 38 | mvfst_cpp_library( 39 | name = "psk_cache", 40 | headers = [ 41 | "QuicPskCache.h", 42 | ], 43 | exported_deps = [ 44 | "//fizz/client:psk_cache", 45 | "//quic/client:cached_server_tp", 46 | "//quic/common:optional", 47 | ], 48 | ) 49 | 50 | mvfst_cpp_library( 51 | name = "token_cache", 52 | headers = [ 53 | "QuicTokenCache.h", 54 | ], 55 | exported_deps = [ 56 | "//quic/common:optional", 57 | ], 58 | ) 59 | -------------------------------------------------------------------------------- /quic/state/SimpleFrameFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace quic { 15 | 16 | /* 17 | * Initiate a send of the given simple frame. 18 | */ 19 | void sendSimpleFrame(QuicConnectionStateBase& conn, QuicSimpleFrame frame); 20 | 21 | /* 22 | * Update connection state and the frame on clone of the given simple frame. 23 | * Returns the updated simple frame. 24 | */ 25 | Optional updateSimpleFrameOnPacketClone( 26 | QuicConnectionStateBase& conn, 27 | PathIdType pathId, 28 | const QuicSimpleFrame& frame); 29 | 30 | /* 31 | * Update the connection state after sending the given simple frame. 32 | */ 33 | void updateSimpleFrameOnPacketSent( 34 | QuicConnectionStateBase& conn, 35 | PathIdType pathId, 36 | const QuicSimpleFrame& simpleFrame); 37 | 38 | /* 39 | * Update the connection state after loss of a given simple frame. 40 | */ 41 | 42 | void updateSimpleFrameOnPacketLoss( 43 | QuicConnectionStateBase& conn, 44 | PathIdType pathId, 45 | const QuicSimpleFrame& frame); 46 | 47 | /* 48 | * Update the connection state on receipt of the given simple frame. 49 | * Returns true if the frame is NOT a probing frame 50 | */ 51 | [[nodiscard]] quic::Expected updateSimpleFrameOnPacketReceived( 52 | QuicConnectionStateBase& conn, 53 | PathIdType pathId, 54 | const QuicSimpleFrame& frameIn, 55 | const ConnectionId& dstConnId); 56 | } // namespace quic 57 | -------------------------------------------------------------------------------- /quic/client/QuicClientAsyncTransport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace quic { 14 | 15 | /** 16 | * Adaptor from QuicClientTransport to folly::AsyncTransport, 17 | * for experiments with QUIC in code using folly::AsyncSockets. 18 | */ 19 | class QuicClientAsyncTransport : public QuicStreamAsyncTransport, 20 | public QuicSocket::ConnectionSetupCallback, 21 | public QuicSocket::ConnectionCallback { 22 | public: 23 | using UniquePtr = std::unique_ptr< 24 | QuicClientAsyncTransport, 25 | folly::DelayedDestruction::Destructor>; 26 | explicit QuicClientAsyncTransport( 27 | const std::shared_ptr& clientSock); 28 | 29 | protected: 30 | ~QuicClientAsyncTransport() override; 31 | 32 | // 33 | // QuicSocket::ConnectionCallback 34 | // 35 | void onNewBidirectionalStream(StreamId id) noexcept override; 36 | void onNewUnidirectionalStream(StreamId id) noexcept override; 37 | void onStopSending(StreamId id, ApplicationErrorCode error) noexcept override; 38 | void onConnectionEnd() noexcept override; 39 | 40 | void onConnectionSetupError(QuicError code) noexcept override { 41 | onConnectionError(std::move(code)); 42 | } 43 | 44 | void onConnectionError(QuicError code) noexcept override; 45 | 46 | void onConnectionEnd(QuicError /* error */) noexcept override {} 47 | 48 | void onTransportReady() noexcept override; 49 | }; 50 | } // namespace quic 51 | -------------------------------------------------------------------------------- /quic/fizz/client/handshake/QuicPskCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace quic { 18 | 19 | struct QuicCachedPsk { 20 | fizz::client::CachedPsk cachedPsk; 21 | CachedServerTransportParameters transportParams; 22 | std::string appParams; 23 | }; 24 | 25 | class QuicPskCache { 26 | public: 27 | virtual ~QuicPskCache() = default; 28 | 29 | virtual Optional getPsk(const std::string&) = 0; 30 | virtual void putPsk(const std::string&, QuicCachedPsk) = 0; 31 | virtual void removePsk(const std::string&) = 0; 32 | }; 33 | 34 | /** 35 | * Basic PSK cache that stores PSKs in a hash map. There is no bound on the size 36 | * of this cache. 37 | */ 38 | class BasicQuicPskCache : public QuicPskCache { 39 | public: 40 | ~BasicQuicPskCache() override = default; 41 | 42 | Optional getPsk(const std::string& identity) override { 43 | auto result = cache_.find(identity); 44 | if (result != cache_.end()) { 45 | return result->second; 46 | } 47 | return std::nullopt; 48 | } 49 | 50 | void putPsk(const std::string& identity, QuicCachedPsk psk) override { 51 | cache_[identity] = std::move(psk); 52 | } 53 | 54 | void removePsk(const std::string& identity) override { 55 | cache_.erase(identity); 56 | } 57 | 58 | private: 59 | std::unordered_map cache_; 60 | }; 61 | 62 | } // namespace quic 63 | -------------------------------------------------------------------------------- /quic/folly_utils/Utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | namespace quic::follyutils { 11 | 12 | Optional> decodeQuicInteger( 13 | folly::io::Cursor& cursor, 14 | uint64_t atMost) { 15 | // checks 16 | if (atMost == 0 || !cursor.canAdvance(1)) { 17 | VLOG(10) << "Not enough bytes to decode integer, cursor len=" 18 | << cursor.totalLength(); 19 | return std::nullopt; 20 | } 21 | 22 | // get 2 msb of first byte that determines variable-length size expected 23 | const uint8_t firstByte = *cursor.peekBytes().data(); 24 | const uint8_t varintType = (firstByte >> 6) & 0x03; 25 | const uint8_t bytesExpected = (1 << varintType); 26 | 27 | // simple short-circuit eval for varint type == 0 28 | if (varintType == 0) { 29 | cursor.skip(1); 30 | return std::pair(firstByte & 0x3f, 1); 31 | } 32 | 33 | // not enough bytes to decode, undo cursor 34 | if (!cursor.canAdvance(bytesExpected) || atMost < bytesExpected) { 35 | VLOG(10) << "Could not decode integer numBytes=" << bytesExpected; 36 | return std::nullopt; 37 | } 38 | // result storage 39 | uint64_t result{0}; 40 | // pull number of bytes expected 41 | cursor.pull(&result, bytesExpected); 42 | // clear 2msb bits 43 | constexpr uint64_t msbMask = ~(0b11ull << 62); 44 | result = folly::Endian::big(result) & msbMask; 45 | // adjust quic integer 46 | result >>= (8 - bytesExpected) << 3; 47 | 48 | return std::pair{result, bytesExpected}; 49 | } 50 | 51 | } // namespace quic::follyutils 52 | -------------------------------------------------------------------------------- /quic/common/EnumArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace quic { 16 | 17 | // A generic class that extends std::array to be indexable using an Enum. 18 | // The enum K has to list enumerators with all values between 0 and K::MAX 19 | // (inclusive) and no others 20 | 21 | template 22 | class EnumArray : public std::array { 23 | public: 24 | using IntType = typename std::underlying_type::type; 25 | static constexpr IntType ArraySize = IntType(K::MAX) + 1; 26 | 27 | constexpr const V& operator[](K key) const { 28 | size_t ik = keyToInt(key); 29 | return this->std::array::operator[](ik); 30 | } 31 | 32 | constexpr V& operator[](K key) { 33 | size_t ik = keyToInt(key); 34 | return this->std::array::operator[](ik); 35 | } 36 | 37 | // Returns all valid values for the enum 38 | [[nodiscard]] constexpr std::array keys() const { 39 | return keyArrayHelper(std::make_integer_sequence{}); 40 | } 41 | 42 | private: 43 | constexpr IntType keyToInt(K key) const { 44 | auto ik = static_cast(key); 45 | DCHECK(ik >= 0 && ik < ArraySize); 46 | return ik; 47 | } 48 | 49 | template 50 | constexpr auto keyArrayHelper(std::integer_sequence) const { 51 | return std::array{static_cast(i)...}; 52 | } 53 | 54 | std::array arr; 55 | }; 56 | 57 | } // namespace quic 58 | -------------------------------------------------------------------------------- /quic/samples/echo/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_binary", "mvfst_cpp_library") 2 | 3 | oncall("traffic_protocols") 4 | 5 | mvfst_cpp_library( 6 | name = "echo_handler", 7 | headers = [ 8 | "EchoClient.h", 9 | "EchoHandler.h", 10 | "EchoServer.h", 11 | "EchoTransportServer.h", 12 | "LogQuicStats.h", 13 | ], 14 | exported_deps = [ 15 | "fbcode//fizz/backend:openssl", 16 | "fbcode//fizz/compression:zlib_certificate_decompressor", 17 | "fbcode//fizz/compression:zstd_certificate_decompressor", 18 | "fbcode//folly:file_util", 19 | "fbcode//folly:synchronized", 20 | "fbcode//folly/fibers:core", 21 | "fbcode//folly/io/async:scoped_event_base_thread", 22 | "fbcode//quic:constants", 23 | "fbcode//quic:exception", 24 | "fbcode//quic/api:transport", 25 | "fbcode//quic/client:client", 26 | "fbcode//quic/codec:types", 27 | "fbcode//quic/common:buf_util", 28 | "fbcode//quic/common/events:folly_eventbase", 29 | "fbcode//quic/common/test:test_client_utils", 30 | "fbcode//quic/common/test:test_utils", 31 | "fbcode//quic/common/udpsocket:folly_async_udp_socket", 32 | "fbcode//quic/fizz/client/handshake:fizz_client_handshake", 33 | "fbcode//quic/server:server", 34 | "fbcode//quic/state:stats_callback", 35 | ], 36 | exported_external_deps = [ 37 | "glog", 38 | ], 39 | ) 40 | 41 | mvfst_cpp_binary( 42 | name = "echo", 43 | srcs = [ 44 | "main.cpp", 45 | ], 46 | deps = [ 47 | ":echo_handler", 48 | "//fizz/crypto:utils", 49 | "//folly/init:init", 50 | "//folly/portability:gflags", 51 | ], 52 | external_deps = [ 53 | "glog", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /quic/state/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | if(NOT BUILD_TESTS) 7 | return() 8 | endif() 9 | 10 | quic_add_test(TARGET StateMachineTest 11 | SOURCES 12 | StateDataTest.cpp 13 | DEPENDS 14 | Folly::folly 15 | mvfst_state_machine 16 | mvfst_test_utils 17 | ) 18 | 19 | quic_add_test(TARGET QuicStreamFunctionsTest 20 | SOURCES 21 | QuicStreamFunctionsTest.cpp 22 | DEPENDS 23 | mvfst_client 24 | mvfst_server 25 | mvfst_state_stream_functions 26 | mvfst_test_utils 27 | ) 28 | 29 | quic_add_test(TARGET QuicStreamManagerTest 30 | SOURCES 31 | QuicStreamManagerTest.cpp 32 | DEPENDS 33 | mvfst_client 34 | mvfst_server 35 | mvfst_state_stream_functions 36 | mvfst_test_utils 37 | ) 38 | 39 | quic_add_test(TARGET AckHandlersTest 40 | SOURCES 41 | AckEventTestUtil.cpp 42 | AckHandlersTest.cpp 43 | DEPENDS 44 | mvfst_server 45 | mvfst_state_machine 46 | mvfst_state_ack_handler 47 | mvfst_test_utils 48 | ) 49 | 50 | quic_add_test(TARGET OutstandingPacketTest 51 | SOURCES 52 | OutstandingPacketTest.cpp 53 | DEPENDS 54 | mvfst_test_utils 55 | ) 56 | 57 | quic_add_test(TARGET QuicStateFunctionsTest 58 | SOURCES 59 | QuicStateFunctionsTest.cpp 60 | DEPENDS 61 | mvfst_server 62 | mvfst_test_utils 63 | mvfst_state_functions 64 | ) 65 | 66 | quic_add_test(TARGET QuicPacingFunctionsTest 67 | SOURCES 68 | QuicPacingFunctionsTest.cpp 69 | DEPENDS 70 | mvfst_state_pacing_functions 71 | ) 72 | 73 | quic_add_test(TARGET QuicTransportSettingsFunctionsTest 74 | SOURCES 75 | TransportSettingsFunctionsTest.cpp 76 | DEPENDS 77 | mvfst_test_utils 78 | mvfst_transport_settings_functions 79 | ) 80 | -------------------------------------------------------------------------------- /quic/state/test/ClonedPacketIdentifierTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace quic::test { 13 | TEST(ClonedPacketIdentifierTest, EqTest) { 14 | ClonedPacketIdentifier initialClonedPacketIdentifier( 15 | PacketNumberSpace::Initial, 0); 16 | ClonedPacketIdentifier initialClonedPacketIdentifier0( 17 | PacketNumberSpace::Initial, 0); 18 | EXPECT_TRUE(initialClonedPacketIdentifier == initialClonedPacketIdentifier0); 19 | 20 | ClonedPacketIdentifier initialClonedPacketIdentifier1( 21 | PacketNumberSpace::Initial, 1); 22 | EXPECT_FALSE( 23 | initialClonedPacketIdentifier0 == initialClonedPacketIdentifier1); 24 | 25 | ClonedPacketIdentifier handshakeClonedPacketIdentifier( 26 | PacketNumberSpace::Handshake, 0); 27 | EXPECT_FALSE( 28 | handshakeClonedPacketIdentifier == initialClonedPacketIdentifier); 29 | } 30 | 31 | TEST(ClonedPacketIdentifierTest, HashTest) { 32 | ClonedPacketIdentifierHash hashObj; 33 | ClonedPacketIdentifier initialClonedPacketIdentifier0( 34 | PacketNumberSpace::Initial, 0); 35 | ClonedPacketIdentifier initialClonedPacketIdentifier1( 36 | PacketNumberSpace::Initial, 1); 37 | EXPECT_NE( 38 | hashObj(initialClonedPacketIdentifier0), 39 | hashObj(initialClonedPacketIdentifier1)); 40 | 41 | ClonedPacketIdentifier handshakeClonedPacketIdentifier0( 42 | PacketNumberSpace::Handshake, 0); 43 | EXPECT_NE( 44 | hashObj(initialClonedPacketIdentifier0), 45 | hashObj(handshakeClonedPacketIdentifier0)); 46 | } 47 | } // namespace quic::test 48 | -------------------------------------------------------------------------------- /quic/codec/ConnectionIdAlgo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace quic { 15 | 16 | /** 17 | * Interface to encode and decode algorithms for ConnectionId given routing 18 | * info (embedded in ServerConnectionIdParams) 19 | * 20 | * NOTE: since several of these methods are called for every single packets, 21 | * and every single connection, it is important to not do any 22 | * blocking call in any of the implementation of these methods. 23 | */ 24 | class ConnectionIdAlgo { 25 | public: 26 | virtual ~ConnectionIdAlgo() = default; 27 | 28 | /** 29 | * Check if this implementation of algorithm can parse the given ConnectionId 30 | */ 31 | [[nodiscard]] virtual bool canParse( 32 | const ConnectionId& id) const noexcept = 0; 33 | 34 | /** 35 | * Parses ServerConnectionIdParams from the given connection id. 36 | */ 37 | virtual quic::Expected parseConnectionId( 38 | const ConnectionId& id) noexcept = 0; 39 | 40 | /** 41 | * Encodes the given ServerConnectionIdParams into connection id 42 | */ 43 | virtual quic::Expected encodeConnectionId( 44 | const ServerConnectionIdParams& params) noexcept = 0; 45 | }; 46 | 47 | /** 48 | * Factory interface to create ConnectionIdAlgo instance. 49 | */ 50 | class ConnectionIdAlgoFactory { 51 | public: 52 | virtual ~ConnectionIdAlgoFactory() = default; 53 | 54 | virtual std::unique_ptr make() = 0; 55 | }; 56 | 57 | } // namespace quic 58 | -------------------------------------------------------------------------------- /quic/common/events/BUCK: -------------------------------------------------------------------------------- 1 | load("@fbcode//quic:defs.bzl", "mvfst_cpp_library") 2 | load("@fbsource//tools/target_determinator/macros:ci.bzl", "ci") 3 | 4 | oncall("traffic_protocols") 5 | 6 | mvfst_cpp_library( 7 | name = "eventbase", 8 | headers = [ 9 | "QuicEventBase.h", 10 | ], 11 | exported_deps = [ 12 | "//folly:glog", 13 | ], 14 | ) 15 | 16 | mvfst_cpp_library( 17 | name = "quic_timer", 18 | srcs = [ 19 | ], 20 | headers = [ 21 | "QuicTimer.h", 22 | ], 23 | exported_deps = [ 24 | ":eventbase", 25 | "//folly/io/async:delayed_destruction", 26 | ], 27 | ) 28 | 29 | mvfst_cpp_library( 30 | name = "folly_eventbase", 31 | srcs = [ 32 | "FollyQuicEventBase.cpp", 33 | ], 34 | headers = [ 35 | "FollyQuicEventBase.h", 36 | ], 37 | exported_deps = [ 38 | ":eventbase", 39 | "//folly/io/async:async_base", 40 | "//folly/io/async:async_base_fwd", 41 | ], 42 | ) 43 | 44 | mvfst_cpp_library( 45 | name = "highres_quic_timer", 46 | srcs = [ 47 | "HighResQuicTimer.cpp", 48 | ], 49 | headers = [ 50 | "HighResQuicTimer.h", 51 | ], 52 | exported_deps = [ 53 | ":quic_timer", 54 | "//folly/io/async:async_base", 55 | "//folly/io/async:timerfd", 56 | ], 57 | ) 58 | 59 | mvfst_cpp_library( 60 | name = "libev_eventbase", 61 | srcs = [ 62 | "LibevQuicEventBase.cpp", 63 | ], 64 | headers = [ 65 | "LibevQuicEventBase.h", 66 | ], 67 | labels = ci.labels(ci.remove(ci.windows())), 68 | exported_deps = [ 69 | ":eventbase", 70 | ":quic_timer", 71 | "//folly:glog", 72 | "//folly:intrusive_list", 73 | ], 74 | exported_external_deps = [ 75 | "libev", 76 | ], 77 | ) 78 | --------------------------------------------------------------------------------