commit
4746a8734d
136 changed files with 3250 additions and 793 deletions
@ -1,83 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/iomgr/port.h" |
||||
#if GRPC_ARES == 1 && (defined(GRPC_UV) || defined(GPR_WINDOWS)) |
||||
|
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "src/core/ext/filters/client_channel/parse_address.h" |
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" |
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv_windows.h" |
||||
#include "src/core/ext/filters/client_channel/server_address.h" |
||||
#include "src/core/lib/gpr/host_port.h" |
||||
#include "src/core/lib/gpr/string.h" |
||||
|
||||
bool inner_maybe_resolve_localhost_manually_locked( |
||||
const char* name, const char* default_port, |
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host, |
||||
char** port) { |
||||
gpr_split_host_port(name, host, port); |
||||
if (*host == nullptr) { |
||||
gpr_log(GPR_ERROR, |
||||
"Failed to parse %s into host:port during manual localhost " |
||||
"resolution check.", |
||||
name); |
||||
return false; |
||||
} |
||||
if (*port == nullptr) { |
||||
if (default_port == nullptr) { |
||||
gpr_log(GPR_ERROR, |
||||
"No port or default port for %s during manual localhost " |
||||
"resolution check.", |
||||
name); |
||||
return false; |
||||
} |
||||
*port = gpr_strdup(default_port); |
||||
} |
||||
if (gpr_stricmp(*host, "localhost") == 0) { |
||||
GPR_ASSERT(*addrs == nullptr); |
||||
*addrs = grpc_core::MakeUnique<grpc_core::ServerAddressList>(); |
||||
uint16_t numeric_port = grpc_strhtons(*port); |
||||
// Append the ipv6 loopback address.
|
||||
struct sockaddr_in6 ipv6_loopback_addr; |
||||
memset(&ipv6_loopback_addr, 0, sizeof(ipv6_loopback_addr)); |
||||
((char*)&ipv6_loopback_addr.sin6_addr)[15] = 1; |
||||
ipv6_loopback_addr.sin6_family = AF_INET6; |
||||
ipv6_loopback_addr.sin6_port = numeric_port; |
||||
(*addrs)->emplace_back(&ipv6_loopback_addr, sizeof(ipv6_loopback_addr), |
||||
nullptr /* args */); |
||||
// Append the ipv4 loopback address.
|
||||
struct sockaddr_in ipv4_loopback_addr; |
||||
memset(&ipv4_loopback_addr, 0, sizeof(ipv4_loopback_addr)); |
||||
((char*)&ipv4_loopback_addr.sin_addr)[0] = 0x7f; |
||||
((char*)&ipv4_loopback_addr.sin_addr)[3] = 0x01; |
||||
ipv4_loopback_addr.sin_family = AF_INET; |
||||
ipv4_loopback_addr.sin_port = numeric_port; |
||||
(*addrs)->emplace_back(&ipv4_loopback_addr, sizeof(ipv4_loopback_addr), |
||||
nullptr /* args */); |
||||
// Let the address sorter figure out which one should be tried first.
|
||||
grpc_cares_wrapper_address_sorting_sort(addrs->get()); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
#endif /* GRPC_ARES == 1 && (defined(GRPC_UV) || defined(GPR_WINDOWS)) */ |
@ -1,34 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_LIBUV_WINDOWS_H |
||||
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_LIBUV_WINDOWS_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" |
||||
|
||||
bool inner_maybe_resolve_localhost_manually_locked( |
||||
const char* name, const char* default_port, |
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host, |
||||
char** port); |
||||
|
||||
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_LIBUV_WINDOWS_H \ |
||||
*/ |
@ -0,0 +1,96 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/cpp/server/external_connection_acceptor_impl.h" |
||||
|
||||
#include <memory> |
||||
|
||||
#include <grpcpp/server_builder_impl.h> |
||||
#include <grpcpp/support/channel_arguments.h> |
||||
|
||||
namespace grpc { |
||||
namespace internal { |
||||
namespace { |
||||
// The actual type to return to user. It co-owns the internal impl object with
|
||||
// the server.
|
||||
class AcceptorWrapper : public experimental::ExternalConnectionAcceptor { |
||||
public: |
||||
explicit AcceptorWrapper(std::shared_ptr<ExternalConnectionAcceptorImpl> impl) |
||||
: impl_(std::move(impl)) {} |
||||
void HandleNewConnection(NewConnectionParameters* p) override { |
||||
impl_->HandleNewConnection(p); |
||||
} |
||||
|
||||
private: |
||||
std::shared_ptr<ExternalConnectionAcceptorImpl> impl_; |
||||
}; |
||||
} // namespace
|
||||
|
||||
ExternalConnectionAcceptorImpl::ExternalConnectionAcceptorImpl( |
||||
const grpc::string& name, |
||||
ServerBuilder::experimental_type::ExternalConnectionType type, |
||||
std::shared_ptr<ServerCredentials> creds) |
||||
: name_(name), creds_(std::move(creds)) { |
||||
GPR_ASSERT(type == |
||||
ServerBuilder::experimental_type::ExternalConnectionType::FROM_FD); |
||||
} |
||||
|
||||
std::unique_ptr<experimental::ExternalConnectionAcceptor> |
||||
ExternalConnectionAcceptorImpl::GetAcceptor() { |
||||
std::lock_guard<std::mutex> lock(mu_); |
||||
GPR_ASSERT(!has_acceptor_); |
||||
has_acceptor_ = true; |
||||
return std::unique_ptr<experimental::ExternalConnectionAcceptor>( |
||||
new AcceptorWrapper(shared_from_this())); |
||||
} |
||||
|
||||
void ExternalConnectionAcceptorImpl::HandleNewConnection( |
||||
experimental::ExternalConnectionAcceptor::NewConnectionParameters* p) { |
||||
std::lock_guard<std::mutex> lock(mu_); |
||||
if (shutdown_ || !started_) { |
||||
// TODO(yangg) clean up.
|
||||
gpr_log( |
||||
GPR_ERROR, |
||||
"NOT handling external connection with fd %d, started %d, shutdown %d", |
||||
p->fd, started_, shutdown_); |
||||
return; |
||||
} |
||||
if (handler_) { |
||||
handler_->Handle(p->fd, p->read_buffer.c_buffer()); |
||||
} |
||||
} |
||||
|
||||
void ExternalConnectionAcceptorImpl::Shutdown() { |
||||
std::lock_guard<std::mutex> lock(mu_); |
||||
shutdown_ = true; |
||||
} |
||||
|
||||
void ExternalConnectionAcceptorImpl::Start() { |
||||
std::lock_guard<std::mutex> lock(mu_); |
||||
GPR_ASSERT(!started_); |
||||
GPR_ASSERT(has_acceptor_); |
||||
GPR_ASSERT(!shutdown_); |
||||
started_ = true; |
||||
} |
||||
|
||||
void ExternalConnectionAcceptorImpl::SetToChannelArgs(ChannelArguments* args) { |
||||
args->SetPointer(name_.c_str(), &handler_); |
||||
} |
||||
|
||||
} // namespace internal
|
||||
} // namespace grpc
|
@ -0,0 +1,72 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_ |
||||
#define SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_ |
||||
|
||||
#include <memory> |
||||
#include <mutex> |
||||
|
||||
#include <grpc/impl/codegen/grpc_types.h> |
||||
#include <grpcpp/security/server_credentials.h> |
||||
#include <grpcpp/security/server_credentials_impl.h> |
||||
#include <grpcpp/server_builder.h> |
||||
#include <grpcpp/support/channel_arguments.h> |
||||
|
||||
#include "src/core/lib/iomgr/tcp_server.h" |
||||
|
||||
namespace grpc { |
||||
namespace internal { |
||||
|
||||
class ExternalConnectionAcceptorImpl |
||||
: public std::enable_shared_from_this<ExternalConnectionAcceptorImpl> { |
||||
public: |
||||
ExternalConnectionAcceptorImpl( |
||||
const grpc::string& name, |
||||
ServerBuilder::experimental_type::ExternalConnectionType type, |
||||
std::shared_ptr<ServerCredentials> creds); |
||||
// Should only be called once.
|
||||
std::unique_ptr<experimental::ExternalConnectionAcceptor> GetAcceptor(); |
||||
|
||||
void HandleNewConnection( |
||||
experimental::ExternalConnectionAcceptor::NewConnectionParameters* p); |
||||
|
||||
void Shutdown(); |
||||
|
||||
void Start(); |
||||
|
||||
const char* name() { return name_.c_str(); } |
||||
|
||||
ServerCredentials* GetCredentials() { return creds_.get(); } |
||||
|
||||
void SetToChannelArgs(::grpc::ChannelArguments* args); |
||||
|
||||
private: |
||||
const grpc::string name_; |
||||
std::shared_ptr<ServerCredentials> creds_; |
||||
grpc_core::TcpServerFdHandler* handler_ = nullptr; // not owned
|
||||
std::mutex mu_; |
||||
bool has_acceptor_ = false; |
||||
bool started_ = false; |
||||
bool shutdown_ = false; |
||||
}; |
||||
|
||||
} // namespace internal
|
||||
} // namespace grpc
|
||||
|
||||
#endif // SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue