Skip to content

Commit bcc188a

Browse files
Aman Sharmameta-codesync[bot]
authored andcommitted
Create an abstract QmuxTransport
Summary: See title Reviewed By: kvtsoy Differential Revision: D114155798 fbshipit-source-id: 2555fbfd0950803b6b18c34595e61494d74d482a
1 parent ce82c49 commit bcc188a

12 files changed

Lines changed: 221 additions & 49 deletions

proxygen/lib/transport/qmux/CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,36 @@ proxygen_add_library(proxygen_transport_qmux_qmux_codec
3333
Folly::folly_io_iobuf
3434
)
3535

36+
proxygen_add_library(proxygen_transport_qmux_qmux_transport
37+
SRCS
38+
QmuxTransport.cpp
39+
EXPORTED_DEPS
40+
Folly::folly_coro_task
41+
Folly::folly_io_iobuf
42+
Folly::folly_network_address
43+
)
44+
45+
proxygen_add_library(proxygen_transport_qmux_folly_qmux_transport
46+
SRCS
47+
FollyQmuxTransport.cpp
48+
DEPS
49+
Folly::folly_io_coro_socket
50+
EXPORTED_DEPS
51+
proxygen_transport_qmux_qmux_transport
52+
)
53+
3654
proxygen_add_library(proxygen_transport_qmux_qmux_session
3755
SRCS
3856
QmuxSession.cpp
3957
DEPS
4058
proxygen_transport_qmux_qmux_codec
41-
Folly::folly_io_coro_socket
4259
Folly::folly_logging_logging
4360
EXPORTED_DEPS
4461
proxygen_http_coro_util_CoroWtSession
4562
proxygen_http_webtransport_wt_stream_manager
4663
proxygen_http_webtransport_wt_util
4764
proxygen_transport_qmux_qmux_framer
65+
proxygen_transport_qmux_qmux_transport
4866
Folly::folly_io_async_async_base
4967
)
5068

@@ -55,14 +73,14 @@ proxygen_add_library(proxygen_transport_qmux_qmux_connector
5573
mvfst::mvfst_folly_utils
5674
Folly::folly_coro_timeout
5775
Folly::folly_futures_core
58-
Folly::folly_io_coro_socket
5976
Folly::folly_io_iobuf
6077
Folly::folly_logging_logging
6178
fmt::fmt
6279
EXPORTED_DEPS
6380
proxygen_http_webtransport_wt_stream_manager
6481
proxygen_transport_qmux_qmux_framer
6582
proxygen_transport_qmux_qmux_session
83+
proxygen_transport_qmux_qmux_transport
6684
Folly::folly_coro_task
6785
)
6886

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include <proxygen/lib/transport/qmux/FollyQmuxTransport.h>
10+
11+
#include <folly/io/coro/Transport.h>
12+
13+
namespace proxygen::qmux {
14+
15+
FollyQmuxTransport::FollyQmuxTransport(
16+
std::unique_ptr<folly::coro::TransportIf> transport)
17+
: transport_(std::move(transport)) {
18+
}
19+
20+
FollyQmuxTransport::~FollyQmuxTransport() = default;
21+
22+
folly::coro::Task<size_t> FollyQmuxTransport::read(
23+
folly::IOBufQueue& readBuf,
24+
size_t minReadSize,
25+
size_t newAllocationSize,
26+
std::chrono::milliseconds timeout) {
27+
return transport_->read(readBuf, minReadSize, newAllocationSize, timeout);
28+
}
29+
30+
folly::coro::Task<folly::Unit> FollyQmuxTransport::write(
31+
folly::IOBufQueue& writeBuf, std::chrono::milliseconds timeout) {
32+
return transport_->write(writeBuf, timeout);
33+
}
34+
35+
void FollyQmuxTransport::shutdownWrite() {
36+
transport_->shutdownWrite();
37+
}
38+
39+
folly::SocketAddress FollyQmuxTransport::getLocalAddress() const noexcept {
40+
return transport_->getLocalAddress();
41+
}
42+
43+
folly::SocketAddress FollyQmuxTransport::getPeerAddress() const noexcept {
44+
return transport_->getPeerAddress();
45+
}
46+
47+
folly::AsyncTransport* FollyQmuxTransport::getUnderlyingTransport()
48+
const noexcept {
49+
return transport_->getTransport();
50+
}
51+
52+
} // namespace proxygen::qmux
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <memory>
12+
#include <proxygen/lib/transport/qmux/QmuxTransport.h>
13+
14+
namespace folly::coro {
15+
class TransportIf;
16+
}
17+
18+
namespace proxygen::qmux {
19+
20+
class FollyQmuxTransport : public QmuxTransport {
21+
public:
22+
explicit FollyQmuxTransport(
23+
std::unique_ptr<folly::coro::TransportIf> transport);
24+
~FollyQmuxTransport() override;
25+
26+
folly::coro::Task<size_t> read(folly::IOBufQueue& readBuf,
27+
size_t minReadSize,
28+
size_t newAllocationSize,
29+
std::chrono::milliseconds timeout) override;
30+
31+
folly::coro::Task<folly::Unit> write(
32+
folly::IOBufQueue& writeBuf, std::chrono::milliseconds timeout) override;
33+
34+
void shutdownWrite() override;
35+
36+
[[nodiscard]] folly::SocketAddress getLocalAddress() const noexcept override;
37+
[[nodiscard]] folly::SocketAddress getPeerAddress() const noexcept override;
38+
[[nodiscard]] folly::AsyncTransport* getUnderlyingTransport()
39+
const noexcept override;
40+
41+
private:
42+
std::unique_ptr<folly::coro::TransportIf> transport_;
43+
};
44+
45+
} // namespace proxygen::qmux

proxygen/lib/transport/qmux/QmuxConnector.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <folly/futures/ThreadWheelTimekeeper.h>
1515
#include <folly/io/Cursor.h>
1616
#include <folly/io/IOBufQueue.h>
17-
#include <folly/io/coro/Transport.h>
1817
#include <folly/logging/xlog.h>
1918
#include <quic/folly_utils/Utils.h>
2019
#include <stdexcept>
@@ -146,7 +145,7 @@ PeelOutcome peelTransportParams(folly::IOBufQueue& buf) {
146145
}
147146

148147
folly::coro::Task<QxTransportParams> readPeerTransportParams(
149-
folly::coro::TransportIf& transport,
148+
QmuxTransport& transport,
150149
folly::IOBufQueue& ingressBuf,
151150
std::chrono::milliseconds timeout) {
152151
while (true) {
@@ -198,7 +197,7 @@ folly::coro::Task<QmuxSession::Ptr> QmuxConnector::connect(
198197
folly::EventBase* evb,
199198
WtDir dir,
200199
QxTransportParams selfParams,
201-
std::unique_ptr<folly::coro::TransportIf> transport,
200+
std::unique_ptr<QmuxTransport> transport,
202201
std::chrono::milliseconds timeout,
203202
QmuxSession::Config sessionConfig) {
204203
XLOG(DBG4) << "QmuxConnector::connect dir=" << static_cast<int>(dir)

proxygen/lib/transport/qmux/QmuxConnector.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313
#include <proxygen/lib/http/webtransport/WtStreamManager.h>
1414
#include <proxygen/lib/transport/qmux/QmuxFramer.h>
1515
#include <proxygen/lib/transport/qmux/QmuxSession.h>
16+
#include <proxygen/lib/transport/qmux/QmuxTransport.h>
1617

1718
namespace folly {
1819
class EventBase;
1920
} // namespace folly
2021

21-
namespace folly::coro {
22-
class TransportIf;
23-
} // namespace folly::coro
24-
2522
namespace proxygen::qmux {
2623

2724
class QmuxConnector {
@@ -30,7 +27,7 @@ class QmuxConnector {
3027
folly::EventBase* evb,
3128
WtDir dir,
3229
QxTransportParams selfParams,
33-
std::unique_ptr<folly::coro::TransportIf> transport,
30+
std::unique_ptr<QmuxTransport> transport,
3431
std::chrono::milliseconds timeout,
3532
QmuxSession::Config sessionConfig = {});
3633
};

proxygen/lib/transport/qmux/QmuxSession.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <proxygen/lib/transport/qmux/QmuxSession.h>
1010

11-
#include <folly/io/coro/Transport.h>
1211
#include <folly/logging/xlog.h>
1312
#include <proxygen/lib/transport/qmux/QmuxCodec.h>
1413

@@ -138,7 +137,7 @@ class QmuxCallback : public QmuxCodec::Callback {
138137
QmuxSession::QmuxSession(folly::EventBase* evb,
139138
WtDir dir,
140139
QxTransportParams selfParams,
141-
std::unique_ptr<folly::coro::TransportIf> transport,
140+
std::unique_ptr<QmuxTransport> transport,
142141
WtStreamManager::WtConfig wtConfig,
143142
uint64_t peerMaxRecordSize,
144143
uint64_t effectiveMaxIdleTimeoutMs,
@@ -169,7 +168,7 @@ proxygen::detail::WtExpected<folly::Unit>::Type QmuxSession::closeSession(
169168
}
170169

171170
folly::AsyncTransport* QmuxSession::getUnderlyingTransport() const noexcept {
172-
return transport_ ? transport_->getTransport() : nullptr;
171+
return transport_ ? transport_->getUnderlyingTransport() : nullptr;
173172
}
174173

175174
proxygen::detail::WtExpected<folly::Unit>::Type QmuxSession::sendDatagram(

proxygen/lib/transport/qmux/QmuxSession.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414
#include <proxygen/lib/http/webtransport/WtStreamManager.h>
1515
#include <proxygen/lib/http/webtransport/WtUtils.h>
1616
#include <proxygen/lib/transport/qmux/QmuxFramer.h>
17+
#include <proxygen/lib/transport/qmux/QmuxTransport.h>
1718

1819
namespace folly {
1920
class AsyncTransport;
2021
}
2122

22-
namespace folly::coro {
23-
class TransportIf;
24-
}
25-
2623
namespace proxygen::qmux {
2724

2825
using WtStreamManager = proxygen::detail::WtStreamManager;
@@ -43,7 +40,7 @@ class QmuxSession
4340
QmuxSession(folly::EventBase* evb,
4441
WtDir dir,
4542
QxTransportParams selfParams,
46-
std::unique_ptr<folly::coro::TransportIf> transport,
43+
std::unique_ptr<QmuxTransport> transport,
4744
WtStreamManager::WtConfig wtConfig,
4845
uint64_t peerMaxRecordSize,
4946
uint64_t effectiveMaxIdleTimeoutMs,
@@ -110,7 +107,7 @@ class QmuxSession
110107
folly::SocketAddress localAddr_;
111108
folly::SocketAddress peerAddr_;
112109
folly::CancellationSource cs_;
113-
std::unique_ptr<folly::coro::TransportIf> transport_;
110+
std::unique_ptr<QmuxTransport> transport_;
114111
QxTransportParams selfParams_;
115112
uint64_t effectiveMaxIdleTimeoutMs_;
116113
std::unique_ptr<folly::IOBuf> initialIngress_;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include <proxygen/lib/transport/qmux/QmuxTransport.h>
10+
11+
namespace proxygen::qmux {
12+
13+
QmuxTransport::~QmuxTransport() = default;
14+
15+
} // namespace proxygen::qmux
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <folly/SocketAddress.h>
12+
#include <folly/coro/Task.h>
13+
#include <folly/io/IOBufQueue.h>
14+
15+
namespace folly {
16+
class AsyncTransport;
17+
}
18+
19+
namespace proxygen::qmux {
20+
21+
class QmuxTransport {
22+
public:
23+
virtual ~QmuxTransport();
24+
25+
virtual folly::coro::Task<size_t> read(folly::IOBufQueue& readBuf,
26+
size_t minReadSize,
27+
size_t newAllocationSize,
28+
std::chrono::milliseconds timeout) = 0;
29+
30+
virtual folly::coro::Task<folly::Unit> write(
31+
folly::IOBufQueue& writeBuf, std::chrono::milliseconds timeout) = 0;
32+
33+
virtual void shutdownWrite() = 0;
34+
35+
[[nodiscard]] virtual folly::SocketAddress getLocalAddress()
36+
const noexcept = 0;
37+
[[nodiscard]] virtual folly::SocketAddress getPeerAddress()
38+
const noexcept = 0;
39+
[[nodiscard]] virtual folly::AsyncTransport* getUnderlyingTransport()
40+
const noexcept = 0;
41+
};
42+
43+
} // namespace proxygen::qmux

proxygen/lib/transport/qmux/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ proxygen_add_test(TARGET QmuxSessionTest
4040
DEPENDS
4141
proxygen_transport_qmux_qmux_session
4242
proxygen_transport_qmux_qmux_codec
43+
proxygen_transport_qmux_folly_qmux_transport
4344
proxygen_transport_qmux_qmux_framer
4445
proxygen_http_codec_webtransport_webtransport_framer
4546
proxygen_http_webtransport_wt_stream_manager
@@ -53,6 +54,7 @@ proxygen_add_test(TARGET QmuxConnectorTest
5354
QmuxConnectorTest.cpp
5455
DEPENDS
5556
proxygen_transport_qmux_qmux_connector
57+
proxygen_transport_qmux_folly_qmux_transport
5658
proxygen_transport_qmux_qmux_framer
5759
TestCoroTransport
5860
testmain

0 commit comments

Comments
 (0)