aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-02-23 08:50:19 -0800
committerGravatar Craig Tiller <ctiller@google.com>2015-02-23 09:58:23 -0800
commit42bc87c0979f7a9f3084366fd466d382cf86ec17 (patch)
tree3e233e2126465227bbaa09fa3a6166f43585c944
parent759026cbf0419dae4edddd9e75fa338e1028a3d8 (diff)
Update C++ server with new core API
And reflects the C++ API in ServerBuilder.
-rw-r--r--Makefile8
-rw-r--r--build.json5
-rw-r--r--examples/pubsub/main.cc4
-rw-r--r--examples/pubsub/publisher_test.cc5
-rw-r--r--examples/pubsub/subscriber_test.cc5
-rw-r--r--include/grpc++/server.h11
-rw-r--r--include/grpc++/server_builder.h16
-rw-r--r--include/grpc++/server_credentials.h29
-rw-r--r--include/grpc/grpc.h3
-rw-r--r--src/core/security/factories.c2
-rw-r--r--src/core/security/security_context.c1
-rw-r--r--src/core/surface/lame_client.c2
-rw-r--r--src/cpp/client/create_channel.cc3
-rw-r--r--src/cpp/server/insecure_server_credentials.cc (renamed from src/core/surface/lame_client.h)22
-rw-r--r--src/cpp/server/secure_server_credentials.cc70
-rw-r--r--src/cpp/server/server.cc27
-rw-r--r--src/cpp/server/server_builder.cc23
-rw-r--r--src/cpp/server/server_credentials.cc22
-rw-r--r--test/core/surface/lame_client_test.c2
-rw-r--r--test/cpp/end2end/async_end2end_test.cc3
-rw-r--r--test/cpp/end2end/end2end_test.cc3
-rw-r--r--test/cpp/interop/server.cc7
-rw-r--r--test/cpp/qps/server.cc3
-rwxr-xr-xtools/run_tests/run_tests.py2
-rw-r--r--vsprojects/vs2013/grpc.vcxproj1
-rw-r--r--vsprojects/vs2013/grpc.vcxproj.filters3
-rw-r--r--vsprojects/vs2013/grpc_shared.vcxproj1
-rw-r--r--vsprojects/vs2013/grpc_shared.vcxproj.filters3
-rw-r--r--vsprojects/vs2013/grpc_unsecure.vcxproj1
-rw-r--r--vsprojects/vs2013/grpc_unsecure.vcxproj.filters3
30 files changed, 165 insertions, 125 deletions
diff --git a/Makefile b/Makefile
index df6d01c593..36a4df4fea 100644
--- a/Makefile
+++ b/Makefile
@@ -3022,6 +3022,7 @@ $(OBJDIR)/$(CONFIG)/src/core/transport/transport.o:
LIBGRPC++_SRC = \
src/cpp/client/secure_credentials.cc \
+ src/cpp/server/secure_server_credentials.cc \
src/cpp/client/channel.cc \
src/cpp/client/channel_arguments.cc \
src/cpp/client/client_context.cc \
@@ -3034,6 +3035,7 @@ LIBGRPC++_SRC = \
src/cpp/common/completion_queue.cc \
src/cpp/common/rpc_method.cc \
src/cpp/proto/proto_utils.cc \
+ src/cpp/server/insecure_server_credentials.cc \
src/cpp/server/server.cc \
src/cpp/server/server_builder.cc \
src/cpp/server/server_context.cc \
@@ -3101,6 +3103,7 @@ ifneq ($(OPENSSL_DEP),)
# installing headers to their final destination on the drive. We need this
# otherwise parallel compilation will fail if a source is compiled first.
src/cpp/client/secure_credentials.cc: $(OPENSSL_DEP)
+src/cpp/server/secure_server_credentials.cc: $(OPENSSL_DEP)
src/cpp/client/channel.cc: $(OPENSSL_DEP)
src/cpp/client/channel_arguments.cc: $(OPENSSL_DEP)
src/cpp/client/client_context.cc: $(OPENSSL_DEP)
@@ -3113,6 +3116,7 @@ src/cpp/common/call.cc: $(OPENSSL_DEP)
src/cpp/common/completion_queue.cc: $(OPENSSL_DEP)
src/cpp/common/rpc_method.cc: $(OPENSSL_DEP)
src/cpp/proto/proto_utils.cc: $(OPENSSL_DEP)
+src/cpp/server/insecure_server_credentials.cc: $(OPENSSL_DEP)
src/cpp/server/server.cc: $(OPENSSL_DEP)
src/cpp/server/server_builder.cc: $(OPENSSL_DEP)
src/cpp/server/server_context.cc: $(OPENSSL_DEP)
@@ -3169,6 +3173,7 @@ endif
endif
$(OBJDIR)/$(CONFIG)/src/cpp/client/secure_credentials.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/secure_server_credentials.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/channel.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/channel_arguments.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/client_context.o:
@@ -3181,6 +3186,7 @@ $(OBJDIR)/$(CONFIG)/src/cpp/common/call.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/completion_queue.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/rpc_method.o:
$(OBJDIR)/$(CONFIG)/src/cpp/proto/proto_utils.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/insecure_server_credentials.o:
$(OBJDIR)/$(CONFIG)/src/cpp/server/server.o:
$(OBJDIR)/$(CONFIG)/src/cpp/server/server_builder.o:
$(OBJDIR)/$(CONFIG)/src/cpp/server/server_context.o:
@@ -3268,6 +3274,7 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/common/completion_queue.cc \
src/cpp/common/rpc_method.cc \
src/cpp/proto/proto_utils.cc \
+ src/cpp/server/insecure_server_credentials.cc \
src/cpp/server/server.cc \
src/cpp/server/server_builder.cc \
src/cpp/server/server_context.cc \
@@ -3363,6 +3370,7 @@ $(OBJDIR)/$(CONFIG)/src/cpp/common/call.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/completion_queue.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/rpc_method.o:
$(OBJDIR)/$(CONFIG)/src/cpp/proto/proto_utils.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/insecure_server_credentials.o:
$(OBJDIR)/$(CONFIG)/src/cpp/server/server.o:
$(OBJDIR)/$(CONFIG)/src/cpp/server/server_builder.o:
$(OBJDIR)/$(CONFIG)/src/cpp/server/server_context.o:
diff --git a/build.json b/build.json
index 1e9b4d72a3..007b4913fb 100644
--- a/build.json
+++ b/build.json
@@ -54,6 +54,7 @@
"src/cpp/common/completion_queue.cc",
"src/cpp/common/rpc_method.cc",
"src/cpp/proto/proto_utils.cc",
+ "src/cpp/server/insecure_server_credentials.cc",
"src/cpp/server/server.cc",
"src/cpp/server/server_builder.cc",
"src/cpp/server/server_context.cc",
@@ -133,7 +134,6 @@
"src/core/surface/client.h",
"src/core/surface/completion_queue.h",
"src/core/surface/event_string.h",
- "src/core/surface/lame_client.h",
"src/core/surface/server.h",
"src/core/surface/surface_trace.h",
"src/core/transport/chttp2/bin_encoder.h",
@@ -437,7 +437,8 @@
"build": "all",
"language": "c++",
"src": [
- "src/cpp/client/secure_credentials.cc"
+ "src/cpp/client/secure_credentials.cc",
+ "src/cpp/server/secure_server_credentials.cc"
],
"deps": [
"gpr",
diff --git a/examples/pubsub/main.cc b/examples/pubsub/main.cc
index 39fb8aea15..066cfa1e01 100644
--- a/examples/pubsub/main.cc
+++ b/examples/pubsub/main.cc
@@ -96,10 +96,10 @@ int main(int argc, char** argv) {
std::unique_ptr<grpc::Credentials> creds;
if (FLAGS_service_account_key_file != "") {
grpc::string json_key = GetServiceAccountJsonKey();
- creds = grpc::CredentialsFactory::ServiceAccountCredentials(
+ creds = grpc::ServiceAccountCredentials(
json_key, FLAGS_oauth_scope, std::chrono::hours(1));
} else {
- creds = grpc::CredentialsFactory::ComputeEngineCredentials();
+ creds = grpc::ComputeEngineCredentials();
}
ss << FLAGS_server_host << ":" << FLAGS_server_port;
diff --git a/examples/pubsub/publisher_test.cc b/examples/pubsub/publisher_test.cc
index b7bea5b1bd..0bb4b84217 100644
--- a/examples/pubsub/publisher_test.cc
+++ b/examples/pubsub/publisher_test.cc
@@ -40,6 +40,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
+#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <gtest/gtest.h>
@@ -106,11 +107,11 @@ class PublisherTest : public ::testing::Test {
int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port;
ServerBuilder builder;
- builder.AddPort(server_address_.str());
+ builder.AddPort(server_address_.str(), grpc::InsecureServerCredentials());
builder.RegisterService(&service_);
server_ = builder.BuildAndStart();
- channel_ = CreateChannel(server_address_.str(), ChannelArguments());
+ channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(), ChannelArguments());
publisher_.reset(new grpc::examples::pubsub::Publisher(channel_));
}
diff --git a/examples/pubsub/subscriber_test.cc b/examples/pubsub/subscriber_test.cc
index 1fdcc8f755..49738fcda6 100644
--- a/examples/pubsub/subscriber_test.cc
+++ b/examples/pubsub/subscriber_test.cc
@@ -40,6 +40,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
+#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <gtest/gtest.h>
@@ -105,11 +106,11 @@ class SubscriberTest : public ::testing::Test {
int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port;
ServerBuilder builder;
- builder.AddPort(server_address_.str());
+ builder.AddPort(server_address_.str(), grpc::InsecureServerCredentials());
builder.RegisterService(&service_);
server_ = builder.BuildAndStart();
- channel_ = CreateChannel(server_address_.str(), ChannelArguments());
+ channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(), ChannelArguments());
subscriber_.reset(new grpc::examples::pubsub::Subscriber(channel_));
}
diff --git a/include/grpc++/server.h b/include/grpc++/server.h
index 26d18d1bbe..eeee6502ab 100644
--- a/include/grpc++/server.h
+++ b/include/grpc++/server.h
@@ -76,15 +76,14 @@ class Server final : private CallHook,
class AsyncRequest;
// ServerBuilder use only
- Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
- ServerCredentials* creds);
- Server();
+ Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned);
+ Server() = delete;
// Register a service. This call does not take ownership of the service.
// The service must exist for the lifetime of the Server instance.
bool RegisterService(RpcService* service);
bool RegisterAsyncService(AsynchronousService* service);
// Add a listening port. Can be called multiple times.
- int AddPort(const grpc::string& addr);
+ int AddPort(const grpc::string& addr, ServerCredentials* creds);
// Start the server.
bool Start();
@@ -114,13 +113,11 @@ class Server final : private CallHook,
std::list<SyncRequest> sync_methods_;
// Pointer to the c grpc server.
- grpc_server* server_;
+ grpc_server* const server_;
ThreadPoolInterface* thread_pool_;
// Whether the thread pool is created and owned by the server.
bool thread_pool_owned_;
- // Whether the server is created with credentials.
- bool secure_;
};
} // namespace grpc
diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h
index 4545c413d2..578e102d6d 100644
--- a/include/grpc++/server_builder.h
+++ b/include/grpc++/server_builder.h
@@ -65,11 +65,9 @@ class ServerBuilder {
void RegisterAsyncService(AsynchronousService* service);
// Add a listening port. Can be called multiple times.
- void AddPort(const grpc::string& addr);
-
- // Set a ServerCredentials. Can only be called once.
- // TODO(yangg) move this to be part of AddPort
- void SetCredentials(const std::shared_ptr<ServerCredentials>& creds);
+ void AddPort(const grpc::string& addr,
+ std::shared_ptr<ServerCredentials> creds,
+ int* selected_port = nullptr);
// Set the thread pool used for running appliation rpc handlers.
// Does not take ownership.
@@ -79,9 +77,15 @@ class ServerBuilder {
std::unique_ptr<Server> BuildAndStart();
private:
+ struct Port {
+ grpc::string addr;
+ std::shared_ptr<ServerCredentials> creds;
+ int* selected_port;
+ };
+
std::vector<RpcService*> services_;
std::vector<AsynchronousService*> async_services_;
- std::vector<grpc::string> ports_;
+ std::vector<Port> ports_;
std::shared_ptr<ServerCredentials> creds_;
ThreadPoolInterface* thread_pool_ = nullptr;
};
diff --git a/include/grpc++/server_credentials.h b/include/grpc++/server_credentials.h
index 5c6787a077..fd4d71db9f 100644
--- a/include/grpc++/server_credentials.h
+++ b/include/grpc++/server_credentials.h
@@ -39,24 +39,21 @@
#include <grpc++/config.h>
-struct grpc_server_credentials;
+struct grpc_server;
namespace grpc {
+class Server;
// grpc_server_credentials wrapper class.
-class ServerCredentials final {
+class ServerCredentials {
public:
- ~ServerCredentials();
+ virtual ~ServerCredentials();
private:
- explicit ServerCredentials(grpc_server_credentials* c_creds);
+ friend class ::grpc::Server;
- grpc_server_credentials* GetRawCreds();
-
- friend class ServerCredentialsFactory;
- friend class Server;
-
- grpc_server_credentials* creds_;
+ virtual int AddPortToServer(const grpc::string& addr,
+ grpc_server* server) = 0;
};
// Options to create ServerCredentials with SSL
@@ -69,13 +66,11 @@ struct SslServerCredentialsOptions {
std::vector<PemKeyCertPair> pem_key_cert_pairs;
};
-// Factory for building different types of ServerCredentials
-class ServerCredentialsFactory {
- public:
- // Builds SSL ServerCredentials given SSL specific options
- static std::shared_ptr<ServerCredentials> SslCredentials(
- const SslServerCredentialsOptions& options);
-};
+// Builds SSL ServerCredentials given SSL specific options
+std::shared_ptr<ServerCredentials> SslServerCredentials(
+ const SslServerCredentialsOptions& options);
+
+std::shared_ptr<ServerCredentials> InsecureServerCredentials();
} // namespace grpc
diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h
index 4a720d11f8..2df80b1e31 100644
--- a/include/grpc/grpc.h
+++ b/include/grpc/grpc.h
@@ -436,6 +436,9 @@ grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops,
grpc_channel *grpc_channel_create(const char *target,
const grpc_channel_args *args);
+/* Create a lame client: this client fails every operation attempted on it. */
+grpc_channel *grpc_lame_client_channel_create(void);
+
/* Close and destroy a grpc channel */
void grpc_channel_destroy(grpc_channel *channel);
diff --git a/src/core/security/factories.c b/src/core/security/factories.c
index 372ee256f2..02267d5545 100644
--- a/src/core/security/factories.c
+++ b/src/core/security/factories.c
@@ -33,9 +33,9 @@
#include <string.h>
+#include <grpc/grpc.h>
#include "src/core/security/credentials.h"
#include "src/core/security/security_context.h"
-#include "src/core/surface/lame_client.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/useful.h>
diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c
index fd8baff539..4888043e6b 100644
--- a/src/core/security/security_context.c
+++ b/src/core/security/security_context.c
@@ -42,7 +42,6 @@
#include "src/core/support/env.h"
#include "src/core/support/file.h"
#include "src/core/support/string.h"
-#include "src/core/surface/lame_client.h"
#include "src/core/transport/chttp2/alpn.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
diff --git a/src/core/surface/lame_client.c b/src/core/surface/lame_client.c
index 57f6ddf0f7..b40c48381f 100644
--- a/src/core/surface/lame_client.c
+++ b/src/core/surface/lame_client.c
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/surface/lame_client.h"
+#include <grpc/grpc.h>
#include <string.h>
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index ef2deb3556..57d215d0f3 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -43,6 +43,7 @@ class ChannelArguments;
std::shared_ptr<ChannelInterface> CreateChannel(
const grpc::string &target, const std::unique_ptr<Credentials> &creds,
const ChannelArguments &args) {
- return creds->CreateChannel(target, args);
+ return creds ? creds->CreateChannel(target, args) :
+ std::shared_ptr<ChannelInterface>(new Channel(target, grpc_lame_client_channel_create()));
}
} // namespace grpc
diff --git a/src/core/surface/lame_client.h b/src/cpp/server/insecure_server_credentials.cc
index 2bd97b95eb..a99e1104cb 100644
--- a/src/core/surface/lame_client.h
+++ b/src/cpp/server/insecure_server_credentials.cc
@@ -31,12 +31,22 @@
*
*/
-#ifndef __GRPC_INTERNAL_SURFACE_LAME_CLIENT_H_
-#define __GRPC_INTERNAL_SURFACE_LAME_CLIENT_H_
+#include <grpc/grpc_security.h>
-#include <grpc/grpc.h>
+#include <grpc++/server_credentials.h>
-/* Create a lame client: this client fails every operation attempted on it. */
-grpc_channel *grpc_lame_client_channel_create(void);
+namespace grpc {
+namespace {
+class InsecureServerCredentialsImpl final : public ServerCredentials {
+ public:
+ int AddPortToServer(const grpc::string& addr, grpc_server* server) {
+ return grpc_server_add_http2_port(server, addr.c_str());
+ }
+};
+} // namespace
-#endif /* __GRPC_INTERNAL_SURFACE_LAME_CLIENT_H_ */
+std::shared_ptr<ServerCredentials> InsecureServerCredentials() {
+ return std::shared_ptr<ServerCredentials>(new InsecureServerCredentialsImpl());
+}
+
+} // namespace grpc
diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc
new file mode 100644
index 0000000000..f90838b086
--- /dev/null
+++ b/src/cpp/server/secure_server_credentials.cc
@@ -0,0 +1,70 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc/grpc_security.h>
+
+#include <grpc++/server_credentials.h>
+
+namespace grpc {
+
+namespace {
+class SecureServerCredentials final : public ServerCredentials {
+ public:
+ explicit SecureServerCredentials(grpc_server_credentials* creds) : creds_(creds) {}
+ ~SecureServerCredentials() override {
+ grpc_server_credentials_release(creds_);
+ }
+
+ int AddPortToServer(const grpc::string& addr, grpc_server* server) override {
+ return grpc_server_add_secure_http2_port(server, addr.c_str(), creds_);
+ }
+
+ private:
+ grpc_server_credentials* const creds_;
+};
+} // namespace
+
+std::shared_ptr<ServerCredentials> SslServerCredentials(
+ const SslServerCredentialsOptions &options) {
+ std::vector<grpc_ssl_pem_key_cert_pair> pem_key_cert_pairs;
+ for (const auto &key_cert_pair : options.pem_key_cert_pairs) {
+ pem_key_cert_pairs.push_back(
+ {key_cert_pair.private_key.c_str(), key_cert_pair.cert_chain.c_str()});
+ }
+ grpc_server_credentials *c_creds = grpc_ssl_server_credentials_create(
+ options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(),
+ &pem_key_cert_pairs[0], pem_key_cert_pairs.size());
+ return std::shared_ptr<ServerCredentials>(new SecureServerCredentials(c_creds));
+}
+
+} // namespace grpc
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index f565d3aa5d..0d81f0b126 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -169,26 +169,13 @@ class Server::SyncRequest final : public CompletionQueueTag {
grpc_completion_queue* cq_;
};
-Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
- ServerCredentials* creds)
+Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned)
: started_(false),
shutdown_(false),
num_running_cb_(0),
+ server_(grpc_server_create(cq_.cq(), nullptr)),
thread_pool_(thread_pool),
- thread_pool_owned_(thread_pool_owned),
- secure_(creds != nullptr) {
- if (creds) {
- server_ =
- grpc_secure_server_create(creds->GetRawCreds(), cq_.cq(), nullptr);
- } else {
- server_ = grpc_server_create(cq_.cq(), nullptr);
- }
-}
-
-Server::Server() {
- // Should not be called.
- GPR_ASSERT(false);
-}
+ thread_pool_owned_(thread_pool_owned) {}
Server::~Server() {
std::unique_lock<std::mutex> lock(mu_);
@@ -238,13 +225,9 @@ bool Server::RegisterAsyncService(AsynchronousService* service) {
return true;
}
-int Server::AddPort(const grpc::string& addr) {
+int Server::AddPort(const grpc::string& addr, ServerCredentials* creds) {
GPR_ASSERT(!started_);
- if (secure_) {
- return grpc_server_add_secure_http2_port(server_, addr.c_str());
- } else {
- return grpc_server_add_http2_port(server_, addr.c_str());
- }
+ return creds->AddPortToServer(addr, server_);
}
bool Server::Start() {
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index 3c2093c363..d8b3f74939 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -51,14 +51,10 @@ void ServerBuilder::RegisterAsyncService(AsynchronousService* service) {
async_services_.push_back(service);
}
-void ServerBuilder::AddPort(const grpc::string& addr) {
- ports_.push_back(addr);
-}
-
-void ServerBuilder::SetCredentials(
- const std::shared_ptr<ServerCredentials>& creds) {
- GPR_ASSERT(!creds_);
- creds_ = creds;
+void ServerBuilder::AddPort(const grpc::string& addr,
+ std::shared_ptr<ServerCredentials> creds,
+ int* selected_port) {
+ ports_.push_back(Port{addr, creds, selected_port});
}
void ServerBuilder::SetThreadPool(ThreadPoolInterface* thread_pool) {
@@ -71,14 +67,13 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
gpr_log(GPR_ERROR, "Mixing async and sync services is unsupported for now");
return nullptr;
}
- if (!thread_pool_ && services_.size()) {
+ if (!thread_pool_ && !services_.empty()) {
int cores = gpr_cpu_num_cores();
if (!cores) cores = 4;
thread_pool_ = new ThreadPool(cores);
thread_pool_owned = true;
}
- std::unique_ptr<Server> server(
- new Server(thread_pool_, thread_pool_owned, creds_.get()));
+ std::unique_ptr<Server> server(new Server(thread_pool_, thread_pool_owned));
for (auto* service : services_) {
if (!server->RegisterService(service)) {
return nullptr;
@@ -90,8 +85,10 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
}
}
for (auto& port : ports_) {
- if (!server->AddPort(port)) {
- return nullptr;
+ int r = server->AddPort(port.addr, port.creds.get());
+ if (!r) return nullptr;
+ if (port.selected_port != nullptr) {
+ *port.selected_port = r;
}
}
if (!server->Start()) {
diff --git a/src/cpp/server/server_credentials.cc b/src/cpp/server/server_credentials.cc
index 69ad000ccc..6bdb465baa 100644
--- a/src/cpp/server/server_credentials.cc
+++ b/src/cpp/server/server_credentials.cc
@@ -37,26 +37,6 @@
namespace grpc {
-ServerCredentials::ServerCredentials(grpc_server_credentials *c_creds)
- : creds_(c_creds) {}
-
-ServerCredentials::~ServerCredentials() {
- grpc_server_credentials_release(creds_);
-}
-
-grpc_server_credentials *ServerCredentials::GetRawCreds() { return creds_; }
-
-std::shared_ptr<ServerCredentials> ServerCredentialsFactory::SslCredentials(
- const SslServerCredentialsOptions &options) {
- std::vector<grpc_ssl_pem_key_cert_pair> pem_key_cert_pairs;
- for (const auto &key_cert_pair : options.pem_key_cert_pairs) {
- pem_key_cert_pairs.push_back(
- {key_cert_pair.private_key.c_str(), key_cert_pair.cert_chain.c_str()});
- }
- grpc_server_credentials *c_creds = grpc_ssl_server_credentials_create(
- options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(),
- &pem_key_cert_pairs[0], pem_key_cert_pairs.size());
- return std::shared_ptr<ServerCredentials>(new ServerCredentials(c_creds));
-}
+ServerCredentials::~ServerCredentials() {}
} // namespace grpc
diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c
index 0142768261..cae49271ee 100644
--- a/test/core/surface/lame_client_test.c
+++ b/test/core/surface/lame_client_test.c
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/surface/lame_client.h"
+#include <grpc/grpc.h>
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/test_config.h"
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 85b4ff8120..01134a3dc3 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -47,6 +47,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
+#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "test/core/util/port.h"
@@ -84,7 +85,7 @@ class AsyncEnd2endTest : public ::testing::Test {
server_address_ << "localhost:" << port;
// Setup server
ServerBuilder builder;
- builder.AddPort(server_address_.str());
+ builder.AddPort(server_address_.str(), grpc::InsecureServerCredentials());
builder.RegisterAsyncService(&service_);
server_ = builder.BuildAndStart();
}
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index f5ecd1a20c..e9f0ce9097 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -47,6 +47,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
+#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "test/core/util/port.h"
@@ -150,7 +151,7 @@ class End2endTest : public ::testing::Test {
server_address_ << "localhost:" << port;
// Setup server
ServerBuilder builder;
- builder.AddPort(server_address_.str());
+ builder.AddPort(server_address_.str(), InsecureServerCredentials());
builder.RegisterService(&service_);
builder.RegisterService(&dup_pkg_service_);
builder.SetThreadPool(&thread_pool_);
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index 7a7287438f..1ec51004fa 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -59,7 +59,6 @@ using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::ServerCredentials;
-using grpc::ServerCredentialsFactory;
using grpc::ServerReader;
using grpc::ServerReaderWriter;
using grpc::ServerWriter;
@@ -210,14 +209,14 @@ void RunServer() {
SimpleResponse response;
ServerBuilder builder;
- builder.AddPort(server_address.str());
builder.RegisterService(&service);
+ std::shared_ptr<ServerCredentials> creds = grpc::InsecureServerCredentials();
if (FLAGS_enable_ssl) {
SslServerCredentialsOptions ssl_opts = {
"", {{test_server1_key, test_server1_cert}}};
- std::shared_ptr<ServerCredentials> creds = ServerSslCredentials(ssl_opts);
- builder.SetCredentials(creds);
+ creds = grpc::SslServerCredentials(ssl_opts);
}
+ builder.AddPort(server_address.str(), creds);
std::unique_ptr<Server> server(builder.BuildAndStart());
gpr_log(GPR_INFO, "Server listening on %s", server_address.str().c_str());
while (!got_sigint) {
diff --git a/test/cpp/qps/server.cc b/test/cpp/qps/server.cc
index 8e136349a1..b54f14d798 100644
--- a/test/cpp/qps/server.cc
+++ b/test/cpp/qps/server.cc
@@ -43,6 +43,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
+#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include "src/cpp/server/thread_pool.h"
#include "test/core/util/grpc_profiler.h"
@@ -134,7 +135,7 @@ static void RunServer() {
SimpleResponse response;
ServerBuilder builder;
- builder.AddPort(server_address);
+ builder.AddPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<ThreadPool> pool(new ThreadPool(FLAGS_server_threads));
diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index 64478b3753..649cf9f35c 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -271,7 +271,7 @@ test_cache.maybe_load()
if forever:
success = True
while True:
- dw = watch_dirs.DirWatcher(['src', 'include', 'test'])
+ dw = watch_dirs.DirWatcher(['src', 'include', 'test', 'examples'])
initial_time = dw.most_recent_change()
have_files_changed = lambda: dw.most_recent_change() != initial_time
previous_success = success
diff --git a/vsprojects/vs2013/grpc.vcxproj b/vsprojects/vs2013/grpc.vcxproj
index 1b4005e036..02c16b5967 100644
--- a/vsprojects/vs2013/grpc.vcxproj
+++ b/vsprojects/vs2013/grpc.vcxproj
@@ -160,7 +160,6 @@
<ClInclude Include="..\..\src\core\surface\client.h" />
<ClInclude Include="..\..\src\core\surface\completion_queue.h" />
<ClInclude Include="..\..\src\core\surface\event_string.h" />
- <ClInclude Include="..\..\src\core\surface\lame_client.h" />
<ClInclude Include="..\..\src\core\surface\server.h" />
<ClInclude Include="..\..\src\core\surface\surface_trace.h" />
<ClInclude Include="..\..\src\core\transport\chttp2\bin_encoder.h" />
diff --git a/vsprojects/vs2013/grpc.vcxproj.filters b/vsprojects/vs2013/grpc.vcxproj.filters
index 949be75180..bd75788761 100644
--- a/vsprojects/vs2013/grpc.vcxproj.filters
+++ b/vsprojects/vs2013/grpc.vcxproj.filters
@@ -578,9 +578,6 @@
<ClInclude Include="..\..\src\core\surface\event_string.h">
<Filter>src\core\surface</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\core\surface\lame_client.h">
- <Filter>src\core\surface</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\core\surface\server.h">
<Filter>src\core\surface</Filter>
</ClInclude>
diff --git a/vsprojects/vs2013/grpc_shared.vcxproj b/vsprojects/vs2013/grpc_shared.vcxproj
index 6bbe656a80..0a0ce887ca 100644
--- a/vsprojects/vs2013/grpc_shared.vcxproj
+++ b/vsprojects/vs2013/grpc_shared.vcxproj
@@ -164,7 +164,6 @@
<ClInclude Include="..\..\src\core\surface\client.h" />
<ClInclude Include="..\..\src\core\surface\completion_queue.h" />
<ClInclude Include="..\..\src\core\surface\event_string.h" />
- <ClInclude Include="..\..\src\core\surface\lame_client.h" />
<ClInclude Include="..\..\src\core\surface\server.h" />
<ClInclude Include="..\..\src\core\surface\surface_trace.h" />
<ClInclude Include="..\..\src\core\transport\chttp2\bin_encoder.h" />
diff --git a/vsprojects/vs2013/grpc_shared.vcxproj.filters b/vsprojects/vs2013/grpc_shared.vcxproj.filters
index 949be75180..bd75788761 100644
--- a/vsprojects/vs2013/grpc_shared.vcxproj.filters
+++ b/vsprojects/vs2013/grpc_shared.vcxproj.filters
@@ -578,9 +578,6 @@
<ClInclude Include="..\..\src\core\surface\event_string.h">
<Filter>src\core\surface</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\core\surface\lame_client.h">
- <Filter>src\core\surface</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\core\surface\server.h">
<Filter>src\core\surface</Filter>
</ClInclude>
diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj b/vsprojects/vs2013/grpc_unsecure.vcxproj
index 0c81ec4768..7421524f1e 100644
--- a/vsprojects/vs2013/grpc_unsecure.vcxproj
+++ b/vsprojects/vs2013/grpc_unsecure.vcxproj
@@ -145,7 +145,6 @@
<ClInclude Include="..\..\src\core\surface\client.h" />
<ClInclude Include="..\..\src\core\surface\completion_queue.h" />
<ClInclude Include="..\..\src\core\surface\event_string.h" />
- <ClInclude Include="..\..\src\core\surface\lame_client.h" />
<ClInclude Include="..\..\src\core\surface\server.h" />
<ClInclude Include="..\..\src\core\surface\surface_trace.h" />
<ClInclude Include="..\..\src\core\transport\chttp2\bin_encoder.h" />
diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
index 4b5370a573..90d4417545 100644
--- a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
+++ b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
@@ -482,9 +482,6 @@
<ClInclude Include="..\..\src\core\surface\event_string.h">
<Filter>src\core\surface</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\core\surface\lame_client.h">
- <Filter>src\core\surface</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\core\surface\server.h">
<Filter>src\core\surface</Filter>
</ClInclude>