17 #include <gflags/gflags.h> 24 using namespace folly;
34 frontendPipeline_(frontendPipeline) {}
37 frontendPipeline_->write(q.
move());
41 LOG(
INFO) <<
"Connection closed by remote host";
42 frontendPipeline_->close();
47 frontendPipeline_->close();
57 frontendPipeline_(frontendPipeline) {}
60 std::shared_ptr<AsyncTransportWrapper> sock)
override {
61 auto pipeline = DefaultPipeline::create();
75 remoteAddress_(remoteAddress) {}
79 if (!backendPipeline_) {
83 backendPipeline_->write(
buffer_.move());
87 LOG(
INFO) <<
"Connection closed by local host";
88 if (!backendPipeline_) {
91 backendPipeline_->close().thenValue([
this, ctx](
auto&&){
98 if (!backendPipeline_) {
101 backendPipeline_->close().thenValue([
this, ctx](
auto&&){
107 if (backendPipeline_) {
113 auto frontendPipeline =
dynamic_cast<DefaultPipeline*
>(ctx->getPipeline());
116 client_.pipelineFactory(
117 std::make_shared<ProxyBackendPipelineFactory>(frontendPipeline));
118 client_.connect(remoteAddress_)
120 backendPipeline_ = pipeline;
124 .onError([
this, ctx](
const std::exception& e){
140 remoteAddress_(remoteAddress) {}
143 std::shared_ptr<AsyncTransportWrapper> sock)
override {
144 auto pipeline = DefaultPipeline::create();
146 pipeline->addBack(std::make_shared<ProxyFrontendHandler>(remoteAddress_));
147 pipeline->finalize();
159 server.
childPipeline(std::make_shared<ProxyFrontendPipelineFactory>(
161 server.
bind(FLAGS_port);
std::enable_if<!std::is_same< T, folly::Unit >::value >::type transportInactive()
ProxyBackendHandler(DefaultPipeline *frontendPipeline)
void readException(Context *, exception_wrapper e) override
void bind(folly::AsyncServerSocket::UniquePtr s)
void read(Context *, IOBufQueue &q) override
fbstring exceptionStr(const std::exception &e)
int main(int argc, char **argv)
std::unique_ptr< folly::IOBuf > move()
ProxyFrontendHandler(SocketAddress remoteAddress)
—— Concurrent Priority Queue Implementation ——
DefaultPipeline * frontendPipeline_
ServerBootstrap * childPipeline(std::shared_ptr< PipelineFactory< Pipeline >> factory)
void init(int *argc, char ***argv, bool removeFlags)
DefaultPipeline * frontendPipeline_
std::enable_if<!std::is_same< T, folly::Unit >::value >::type transportActive()
static Options cacheChainLength()
ProxyFrontendPipelineFactory(SocketAddress remoteAddress)
void readEOF(Context *ctx) override
void transportActive(Context *ctx) override
ClientBootstrap< DefaultPipeline > client_
DefaultPipeline::Ptr newPipeline(std::shared_ptr< AsyncTransportWrapper > sock) override
DEFINE_string(remote_host,"127.0.0.1","remote host")
SocketAddress remoteAddress_
DefaultPipeline::Ptr newPipeline(std::shared_ptr< AsyncTransportWrapper > sock) override
std::shared_ptr< Pipeline > Ptr
Handler< R, R, W, W >::Context Context
void read(Context *, IOBufQueue &q) override
void readEOF(Context *) override
std::unique_ptr< unsigned char[]> buffer_
int close(NetworkSocket s)
ProxyBackendPipelineFactory(DefaultPipeline *frontendPipeline)
SocketAddress remoteAddress_
void readException(Context *ctx, exception_wrapper e) override
DEFINE_int32(port, 1080,"proxy server port")