Merge github.com:grpc/grpc into c++api

Conflicts:
	test/cpp/qps/server.cc
pull/501/head
Craig Tiller 10 years ago
commit 5a4f991d5d
  1. 8
      INSTALL
  2. 4
      Makefile
  3. 2
      build.json
  4. 50
      src/core/iomgr/fd_posix.c
  5. 22
      src/core/iomgr/fd_posix.h
  6. 26
      src/core/iomgr/pollset_multipoller_with_poll_posix.c
  7. 20
      src/core/iomgr/pollset_posix.c
  8. 5
      src/core/surface/call.c
  9. 2
      src/csharp/.gitignore
  10. 1
      src/csharp/GrpcApi/.gitignore
  11. 28
      src/csharp/GrpcApi/GrpcApi.csproj
  12. 11
      src/csharp/GrpcApi/packages.config
  13. 1
      src/csharp/GrpcApiTests/.gitignore
  14. 19
      src/csharp/GrpcApiTests/GrpcApiTests.csproj
  15. 5
      src/csharp/GrpcApiTests/packages.config
  16. 1
      src/csharp/GrpcCore/.gitignore
  17. 1
      src/csharp/GrpcCoreTests/.gitignore
  18. 14
      src/csharp/GrpcCoreTests/GrpcCoreTests.csproj
  19. 4
      src/csharp/GrpcCoreTests/packages.config
  20. 1
      src/csharp/InteropClient/.gitignore
  21. 16
      src/csharp/InteropClient/InteropClient.csproj
  22. 5
      src/csharp/InteropClient/packages.config
  23. 1
      src/csharp/MathClient/.gitignore
  24. 23
      src/csharp/README.md
  25. BIN
      src/csharp/lib/Google.ProtocolBuffers.dll
  26. 1
      src/python/setup.py
  27. 4
      src/python/src/_adapter/_c.c
  28. 26
      src/python/src/_adapter/_c_test.py
  29. 157
      src/python/src/_adapter/_server_credentials.c
  30. 48
      src/python/src/_adapter/_server_credentials.h
  31. 7
      test/cpp/qps/server.cc
  32. 8
      tools/run_tests/build_python.sh
  33. 28
      tools/run_tests/run_python.sh

@ -100,16 +100,16 @@ Then, you can build and install protobuf 3.0.0:
A word on OpenSSL
-----------------
Secure HTTP2 requires to have the TLS extension ALPN (see rfc 7301 and
Secure HTTP2 requires the TLS extension ALPN (see rfc 7301 and
http://http2.github.io/http2-spec/ section 3.3). Our HTTP2 implementation
relies on OpenSSL's implementation. OpenSSL 1.0.2 is the first released version
of OpenSSL that has ALPN support, and this explains our dependency on it.
Note that the Makefile supports compiling only the unsecure elements of grpc,
and if you do not have OpenSSL and do not want it, you can still proceed
with installing only the elements you require. However, it is recommended
to encrypt your network traffic, therefore we urge you to not use the unsecure
version of grpc if possible.
with installing only the elements you require. However, we strongly recommend
the use of encryption for all network traffic, and discourage the use of grpc
without TLS.
Compiling

@ -1432,10 +1432,6 @@ test_cxx: buildtests_cxx
$(Q) ./bins/$(CONFIG)/credentials_test || ( echo test credentials_test failed ; exit 1 )
$(E) "[RUN] Testing end2end_test"
$(Q) ./bins/$(CONFIG)/end2end_test || ( echo test end2end_test failed ; exit 1 )
$(E) "[RUN] Testing qps_client"
$(Q) ./bins/$(CONFIG)/qps_client || ( echo test qps_client failed ; exit 1 )
$(E) "[RUN] Testing qps_server"
$(Q) ./bins/$(CONFIG)/qps_server || ( echo test qps_server failed ; exit 1 )
$(E) "[RUN] Testing status_test"
$(Q) ./bins/$(CONFIG)/status_test || ( echo test status_test failed ; exit 1 )
$(E) "[RUN] Testing thread_pool_test"

@ -1611,6 +1611,7 @@
{
"name": "qps_client",
"build": "test",
"run": false,
"language": "c++",
"src": [
"test/cpp/qps/qpstest.proto",
@ -1628,6 +1629,7 @@
{
"name": "qps_server",
"build": "test",
"run": false,
"language": "c++",
"src": [
"test/cpp/qps/qpstest.proto",

@ -68,7 +68,6 @@ static grpc_fd *fd_freelist = NULL;
static gpr_mu fd_freelist_mu;
static void freelist_fd(grpc_fd *fd) {
gpr_free(fd->watchers);
gpr_mu_lock(&fd_freelist_mu);
fd->freelist_next = fd_freelist;
fd_freelist = fd;
@ -93,9 +92,7 @@ static grpc_fd *alloc_fd(int fd) {
gpr_atm_rel_store(&r->writest.state, NOT_READY);
gpr_atm_rel_store(&r->shutdown, 0);
r->fd = fd;
r->watchers = NULL;
r->watcher_count = 0;
r->watcher_capacity = 0;
r->watcher_root.next = r->watcher_root.prev = &r->watcher_root;
r->freelist_next = NULL;
return r;
}
@ -118,9 +115,7 @@ static void unref_by(grpc_fd *fd, int n) {
}
}
void grpc_fd_global_init(void) {
gpr_mu_init(&fd_freelist_mu);
}
void grpc_fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
void grpc_fd_global_shutdown(void) {
while (fd_freelist != NULL) {
@ -145,11 +140,11 @@ int grpc_fd_is_orphaned(grpc_fd *fd) {
}
static void wake_watchers(grpc_fd *fd) {
size_t i, n;
grpc_fd_watcher *watcher;
gpr_mu_lock(&fd->watcher_mu);
n = fd->watcher_count;
for (i = 0; i < n; i++) {
grpc_pollset_force_kick(fd->watchers[i]);
for (watcher = fd->watcher_root.next; watcher != &fd->watcher_root;
watcher = watcher->next) {
grpc_pollset_force_kick(watcher->pollset);
}
gpr_mu_unlock(&fd->watcher_mu);
}
@ -293,36 +288,27 @@ void grpc_fd_notify_on_write(grpc_fd *fd, grpc_iomgr_cb_func write_cb,
}
gpr_uint32 grpc_fd_begin_poll(grpc_fd *fd, grpc_pollset *pollset,
gpr_uint32 read_mask, gpr_uint32 write_mask) {
gpr_uint32 read_mask, gpr_uint32 write_mask,
grpc_fd_watcher *watcher) {
/* keep track of pollers that have requested our events, in case they change
*/
gpr_mu_lock(&fd->watcher_mu);
if (fd->watcher_capacity == fd->watcher_count) {
fd->watcher_capacity =
GPR_MAX(fd->watcher_capacity + 8, fd->watcher_capacity * 3 / 2);
fd->watchers = gpr_realloc(fd->watchers,
fd->watcher_capacity * sizeof(grpc_pollset *));
}
fd->watchers[fd->watcher_count++] = pollset;
watcher->next = &fd->watcher_root;
watcher->prev = watcher->next->prev;
watcher->next->prev = watcher->prev->next = watcher;
watcher->pollset = pollset;
watcher->fd = fd;
gpr_mu_unlock(&fd->watcher_mu);
return (gpr_atm_acq_load(&fd->readst.state) != READY ? read_mask : 0) |
(gpr_atm_acq_load(&fd->writest.state) != READY ? write_mask : 0);
}
void grpc_fd_end_poll(grpc_fd *fd, grpc_pollset *pollset) {
size_t r, w, n;
gpr_mu_lock(&fd->watcher_mu);
n = fd->watcher_count;
for (r = 0, w = 0; r < n; r++) {
if (fd->watchers[r] == pollset) {
fd->watcher_count--;
continue;
}
fd->watchers[w++] = fd->watchers[r];
}
gpr_mu_unlock(&fd->watcher_mu);
void grpc_fd_end_poll(grpc_fd_watcher *watcher) {
gpr_mu_lock(&watcher->fd->watcher_mu);
watcher->next->prev = watcher->prev;
watcher->prev->next = watcher->next;
gpr_mu_unlock(&watcher->fd->watcher_mu);
}
void grpc_fd_become_readable(grpc_fd *fd, int allow_synchronous_callback) {

@ -47,7 +47,16 @@ typedef struct {
gpr_atm state;
} grpc_fd_state;
typedef struct grpc_fd {
typedef struct grpc_fd grpc_fd;
typedef struct grpc_fd_watcher {
struct grpc_fd_watcher *next;
struct grpc_fd_watcher *prev;
grpc_pollset *pollset;
grpc_fd *fd;
} grpc_fd_watcher;
struct grpc_fd {
int fd;
/* refst format:
bit0: 1=active/0=orphaned
@ -60,9 +69,7 @@ typedef struct grpc_fd {
gpr_atm shutdown;
gpr_mu watcher_mu;
grpc_pollset **watchers;
size_t watcher_count;
size_t watcher_capacity;
grpc_fd_watcher watcher_root;
grpc_fd_state readst;
grpc_fd_state writest;
@ -70,7 +77,7 @@ typedef struct grpc_fd {
grpc_iomgr_cb_func on_done;
void *on_done_user_data;
struct grpc_fd *freelist_next;
} grpc_fd;
};
/* Create a wrapped file descriptor.
Requires fd is a non-blocking file descriptor.
@ -95,9 +102,10 @@ void grpc_fd_orphan(grpc_fd *fd, grpc_iomgr_cb_func on_done, void *user_data);
Polling strategies that do not need to alter their behavior depending on the
fd's current interest (such as epoll) do not need to call this function. */
gpr_uint32 grpc_fd_begin_poll(grpc_fd *fd, grpc_pollset *pollset,
gpr_uint32 read_mask, gpr_uint32 write_mask);
gpr_uint32 read_mask, gpr_uint32 write_mask,
grpc_fd_watcher *rec);
/* Complete polling previously started with grpc_fd_begin_poll */
void grpc_fd_end_poll(grpc_fd *fd, grpc_pollset *pollset);
void grpc_fd_end_poll(grpc_fd_watcher *rec);
/* Return 1 if this fd is orphaned, 0 otherwise */
int grpc_fd_is_orphaned(grpc_fd *fd);

@ -53,11 +53,11 @@ typedef struct {
size_t fd_count;
size_t fd_capacity;
grpc_fd **fds;
/* fds being polled by the current poller: parallel arrays of pollfd and the
* grpc_fd* that the pollfd was constructed from */
/* fds being polled by the current poller: parallel arrays of pollfd, and
a grpc_fd_watcher */
size_t pfd_count;
size_t pfd_capacity;
grpc_fd **selfds;
grpc_fd_watcher *watchers;
struct pollfd *pfds;
/* fds that have been removed from the pollset explicitly */
size_t del_count;
@ -98,7 +98,7 @@ static void end_polling(grpc_pollset *pollset) {
pollset_hdr *h;
h = pollset->data.ptr;
for (i = 1; i < h->pfd_count; i++) {
grpc_fd_end_poll(h->selfds[i], pollset);
grpc_fd_end_poll(&h->watchers[i]);
}
}
@ -125,9 +125,9 @@ static int multipoll_with_poll_pollset_maybe_work(
if (h->pfd_capacity < h->fd_count + 1) {
h->pfd_capacity = GPR_MAX(h->pfd_capacity * 3 / 2, h->fd_count + 1);
gpr_free(h->pfds);
gpr_free(h->selfds);
gpr_free(h->watchers);
h->pfds = gpr_malloc(sizeof(struct pollfd) * h->pfd_capacity);
h->selfds = gpr_malloc(sizeof(grpc_fd *) * h->pfd_capacity);
h->watchers = gpr_malloc(sizeof(grpc_fd_watcher) * h->pfd_capacity);
}
nf = 0;
np = 1;
@ -147,7 +147,7 @@ static int multipoll_with_poll_pollset_maybe_work(
grpc_fd_unref(h->fds[i]);
} else {
h->fds[nf++] = h->fds[i];
h->selfds[np] = h->fds[i];
h->watchers[np].fd = h->fds[i];
h->pfds[np].fd = h->fds[i]->fd;
h->pfds[np].revents = 0;
np++;
@ -167,8 +167,8 @@ static int multipoll_with_poll_pollset_maybe_work(
gpr_mu_unlock(&pollset->mu);
for (i = 1; i < np; i++) {
h->pfds[i].events =
grpc_fd_begin_poll(h->selfds[i], pollset, POLLIN, POLLOUT);
h->pfds[i].events = grpc_fd_begin_poll(h->watchers[i].fd, pollset, POLLIN,
POLLOUT, &h->watchers[i]);
}
r = poll(h->pfds, h->pfd_count, timeout);
@ -184,10 +184,10 @@ static int multipoll_with_poll_pollset_maybe_work(
}
for (i = 1; i < np; i++) {
if (h->pfds[i].revents & POLLIN) {
grpc_fd_become_readable(h->selfds[i], allow_synchronous_callback);
grpc_fd_become_readable(h->watchers[i].fd, allow_synchronous_callback);
}
if (h->pfds[i].revents & POLLOUT) {
grpc_fd_become_writable(h->selfds[i], allow_synchronous_callback);
grpc_fd_become_writable(h->watchers[i].fd, allow_synchronous_callback);
}
}
}
@ -211,7 +211,7 @@ static void multipoll_with_poll_pollset_destroy(grpc_pollset *pollset) {
grpc_fd_unref(h->dels[i]);
}
gpr_free(h->pfds);
gpr_free(h->selfds);
gpr_free(h->watchers);
gpr_free(h->fds);
gpr_free(h->dels);
gpr_free(h);
@ -234,7 +234,7 @@ void grpc_platform_become_multipoller(grpc_pollset *pollset, grpc_fd **fds,
h->pfd_count = 0;
h->pfd_capacity = 0;
h->pfds = NULL;
h->selfds = NULL;
h->watchers = NULL;
h->del_count = 0;
h->del_capacity = 0;
h->dels = NULL;

@ -80,7 +80,9 @@ void grpc_pollset_kick(grpc_pollset *p) {
}
}
void grpc_pollset_force_kick(grpc_pollset *p) { grpc_pollset_kick_kick(&p->kick_state); }
void grpc_pollset_force_kick(grpc_pollset *p) {
grpc_pollset_kick_kick(&p->kick_state);
}
/* global state management */
@ -200,8 +202,15 @@ static void unary_poll_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) {
if (fd == pollset->data.ptr) return;
fds[0] = pollset->data.ptr;
fds[1] = fd;
grpc_platform_become_multipoller(pollset, fds, GPR_ARRAY_SIZE(fds));
grpc_fd_unref(fds[0]);
if (!grpc_fd_is_orphaned(fds[0])) {
grpc_platform_become_multipoller(pollset, fds, GPR_ARRAY_SIZE(fds));
grpc_fd_unref(fds[0]);
} else {
/* old fd is orphaned and we haven't cleaned it up until now, so remain a
* unary poller */
grpc_fd_unref(fds[0]);
pollset->data.ptr = fd;
}
}
static void unary_poll_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) {
@ -217,6 +226,7 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
int allow_synchronous_callback) {
struct pollfd pfd[2];
grpc_fd *fd;
grpc_fd_watcher fd_watcher;
int timeout;
int r;
@ -249,7 +259,7 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
pollset->counter = 1;
gpr_mu_unlock(&pollset->mu);
pfd[1].events = grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT);
pfd[1].events = grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT, &fd_watcher);
r = poll(pfd, GPR_ARRAY_SIZE(pfd), timeout);
if (r < 0) {
@ -271,7 +281,7 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
}
grpc_pollset_kick_post_poll(&pollset->kick_state);
grpc_fd_end_poll(fd, pollset);
grpc_fd_end_poll(&fd_watcher);
gpr_mu_lock(&pollset->mu);
pollset->counter = 0;

@ -1264,7 +1264,10 @@ grpc_call_error grpc_call_server_accept_old(grpc_call *call,
ls = get_legacy_state(call);
err = bind_cq(call, cq);
if (err != GRPC_CALL_OK) return err;
if (err != GRPC_CALL_OK) {
unlock(call);
return err;
}
ls->finished_tag = finished_tag;

@ -1,2 +1,4 @@
*.userprefs
test-results
packages
Grpc.v12.suo

@ -1,2 +1,3 @@
test-results
bin
obj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -30,19 +30,23 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="Google.ProtocolBuffers, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Reactive.Linq, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<Private>False</Private>
<Reference Include="System.Reactive.Core">
<HintPath>..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Data.Linq" />
<Reference Include="System.Reactive.Interfaces, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<Private>False</Private>
<Reference Include="System.Reactive.Interfaces">
<HintPath>..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<Private>False</Private>
<Reference Include="System.Data.Linq" />
<Reference Include="System.Reactive.Linq">
<HintPath>..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="Google.ProtocolBuffers">
<HintPath>..\lib\Google.ProtocolBuffers.dll</HintPath>
<Reference Include="System.Reactive.PlatformServices">
<HintPath>..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@ -63,12 +67,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="proto\math.proto" />
<None Include="proto\empty.proto" />
<None Include="proto\messages.proto" />
<None Include="proto\test.proto" />
</ItemGroup>
<ItemGroup>
<Folder Include="proto\" />
</ItemGroup>
</Project>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.ProtocolBuffers" version="2.4.1.521" targetFramework="net45" />
<package id="Ix-Main" version="1.2.3" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="Rx-Core" version="2.2.5" targetFramework="net45" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" />
<package id="Rx-Linq" version="2.2.5" targetFramework="net45" />
<package id="Rx-Main" version="2.2.5" targetFramework="net45" />
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="net45" />
</packages>

@ -1,2 +1,3 @@
test-results
bin
obj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -30,13 +30,14 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Private>False</Private>
<Reference Include="Google.ProtocolBuffers, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll</HintPath>
</Reference>
<Reference Include="Google.ProtocolBuffers">
<HintPath>..\lib\Google.ProtocolBuffers.dll</HintPath>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@ -53,4 +54,10 @@
<Name>GrpcCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.ProtocolBuffers" version="2.4.1.521" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
</packages>

@ -1 +1,2 @@
bin
obj

@ -1,2 +1,3 @@
test-results
bin
obj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -30,10 +30,10 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Private>False</Private>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@ -49,4 +49,10 @@
<Name>GrpcCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net45" />
</packages>

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -33,13 +33,14 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Private>False</Private>
<Reference Include="Google.ProtocolBuffers, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll</HintPath>
</Reference>
<Reference Include="Google.ProtocolBuffers">
<HintPath>..\lib\Google.ProtocolBuffers.dll</HintPath>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@ -56,4 +57,7 @@
<Name>GrpcApi</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.ProtocolBuffers" version="2.4.1.521" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
</packages>

@ -15,8 +15,15 @@ EXPERIMENTAL ONLY
completely rewritten.
INSTALLATION AND USAGE
----------------------
INSTALLATION AND USAGE: WINDOWS
-------------------------------
- Open Grpc.sln using Visual Studio 2013. NuGet dependencies will be restored
upon build.
INSTALLATION AND USAGE: LINUX & MONO
------------------------------------
- Compile and install the gRPC C Core library
```
@ -31,6 +38,18 @@ sudo apt-get install monodevelop monodevelop-nunit
sudo apt-get install nunit nunit-console
```
- NuGet is used to manage project's dependencies. Prior opening Grpc.sln,
download dependencies using NuGet restore command:
```
# Import needed certicates into Mono certificate store:
mozroots --import --sync
# Download NuGet.exe http://nuget.codeplex.com/releases/
# Restore the nuget packages with Grpc C# dependencies
mono ~/Downloads/NuGet.exe restore Grpc.sln
```
- Use MonoDevelop to open the solution Grpc.sln (you can also run unit tests
from there).

@ -38,6 +38,7 @@ _EXTENSION_SOURCES = (
'src/_adapter/_completion_queue.c',
'src/_adapter/_error.c',
'src/_adapter/_server.c',
'src/_adapter/_server_credentials.c',
)
_EXTENSION_INCLUDE_DIRECTORIES = (

@ -38,6 +38,7 @@
#include "_adapter/_channel.h"
#include "_adapter/_call.h"
#include "_adapter/_server.h"
#include "_adapter/_server_credentials.h"
static PyObject *init(PyObject *self, PyObject *args) {
grpc_init();
@ -74,4 +75,7 @@ PyMODINIT_FUNC init_c(void) {
if (pygrpc_add_server(module) == -1) {
return;
}
if (pygrpc_add_server_credentials(module) == -1) {
return;
}
}

@ -136,6 +136,32 @@ class _CTest(unittest.TestCase):
_c.shut_down()
def test_server_credentials(self):
root_certificates = b'Trust starts here. Really.'
first_private_key = b'This is a really bad private key, yo.'
first_certificate_chain = b'Trust me! Do I not look trustworty?'
second_private_key = b'This is another bad private key, yo.'
second_certificate_chain = b'Look into my eyes; you can totes trust me.'
_c.init()
server_credentials = _c.ServerCredentials(
None, ((first_private_key, first_certificate_chain),))
del server_credentials
server_credentials = _c.ServerCredentials(
root_certificates, ((first_private_key, first_certificate_chain),))
del server_credentials
server_credentials = _c.ServerCredentials(
root_certificates,
((first_private_key, first_certificate_chain),
(second_private_key, second_certificate_chain),))
del server_credentials
with self.assertRaises(TypeError):
_c.ServerCredentials(
root_certificates, first_private_key, second_certificate_chain)
_c.shut_down()
if __name__ == '__main__':
unittest.main()

@ -0,0 +1,157 @@
/*
*
* 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 "_adapter/_server_credentials.h"
#include <Python.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
static int pygrpc_server_credentials_init(ServerCredentials *self,
PyObject *args, PyObject *kwds) {
char *root_certificates;
PyObject *pair_sequence;
Py_ssize_t pair_count;
grpc_ssl_pem_key_cert_pair *pairs;
int error;
PyObject *iterator;
int i;
PyObject *pair;
if (!(PyArg_ParseTuple(args, "zO", &root_certificates, &pair_sequence))) {
self->c_server_credentials = NULL;
return -1;
}
pair_count = PySequence_Length(pair_sequence);
if (pair_count == -1) {
self->c_server_credentials = NULL;
return -1;
}
iterator = PyObject_GetIter(pair_sequence);
if (iterator == NULL) {
self->c_server_credentials = NULL;
return -1;
}
pairs = gpr_malloc(pair_count * sizeof(grpc_ssl_pem_key_cert_pair));
error = 0;
for (i = 0; i < pair_count; i++) {
pair = PyIter_Next(iterator);
if (pair == NULL) {
error = 1;
break;
}
if (!(PyArg_ParseTuple(pair, "ss", &pairs[i].private_key,
&pairs[i].cert_chain))) {
error = 1;
Py_DECREF(pair);
break;
}
Py_DECREF(pair);
}
Py_DECREF(iterator);
if (error) {
self->c_server_credentials = NULL;
gpr_free(pairs);
return -1;
} else {
self->c_server_credentials = grpc_ssl_server_credentials_create(
root_certificates, pairs, pair_count);
gpr_free(pairs);
return 0;
}
}
static void pygrpc_server_credentials_dealloc(ServerCredentials *self) {
if (self->c_server_credentials != NULL) {
grpc_server_credentials_release(self->c_server_credentials);
}
self->ob_type->tp_free((PyObject *)self);
}
PyTypeObject pygrpc_ServerCredentialsType = {
PyObject_HEAD_INIT(NULL)0, /*ob_size*/
"_grpc.ServerCredencials", /*tp_name*/
sizeof(ServerCredentials), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)pygrpc_server_credentials_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"Wrapping of grpc_server_credentials.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)pygrpc_server_credentials_init, /* tp_init */
};
int pygrpc_add_server_credentials(PyObject *module) {
pygrpc_ServerCredentialsType.tp_new = PyType_GenericNew;
if (PyType_Ready(&pygrpc_ServerCredentialsType) < 0) {
PyErr_SetString(PyExc_RuntimeError,
"Error defining pygrpc_ServerCredentialsType!");
return -1;
}
if (PyModule_AddObject(module, "ServerCredentials",
(PyObject *)&pygrpc_ServerCredentialsType) == -1) {
PyErr_SetString(PyExc_ImportError,
"Couldn't add ServerCredentials type to module!");
return -1;
}
return 0;
}

@ -0,0 +1,48 @@
/*
*
* 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.
*
*/
#ifndef _ADAPTER__SERVER_CREDENTIALS_H_
#define _ADAPTER__SERVER_CREDENTIALS_H_
#include <Python.h>
#include <grpc/grpc_security.h>
typedef struct {
PyObject_HEAD grpc_server_credentials *c_server_credentials;
} ServerCredentials;
PyTypeObject pygrpc_ServerCredentialsType;
int pygrpc_add_server_credentials(PyObject *module);
#endif /* _ADAPTER__SERVER_CREDENTIALS_H_ */

@ -44,6 +44,7 @@
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/status.h>
#include "src/cpp/server/thread_pool.h"
#include "test/core/util/grpc_profiler.h"
#include "test/cpp/qps/qpstest.pb.h"
@ -52,10 +53,12 @@
DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls.");
DEFINE_int32(port, 0, "Server port.");
DEFINE_int32(server_threads, 4, "Number of server threads.");
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::ThreadPool;
using grpc::testing::Payload;
using grpc::testing::PayloadType;
using grpc::testing::ServerStats;
@ -126,6 +129,10 @@ static void RunServer() {
ServerBuilder builder;
builder.AddPort(server_address);
builder.RegisterService(&service);
std::unique_ptr<ThreadPool> pool(new ThreadPool(FLAGS_server_threads));
builder.SetThreadPool(pool.get());
std::unique_ptr<Server> server(builder.BuildAndStart());
gpr_log(GPR_INFO, "Server listening on %s\n", server_address);

@ -5,7 +5,11 @@ set -ex
# change to grpc repo root
cd $(dirname $0)/../..
make -j6
root=`pwd`
virtualenv python2.7_virtual_environment
python2.7_virtual_environment/bin/pip install enum34==1.0.4 futures==2.2.0 protobuf==2.6.1
python2.7_virtual_environment/bin/pip install src/python
ln -sf $root/include/grpc python2.7_virtual_environment/include/grpc
source python2.7_virtual_environment/bin/activate
pip install enum34==1.0.4 futures==2.2.0 protobuf==2.6.1
CFLAGS=-I$root/include LDFLAGS=-L$root/libs/opt pip install src/python

@ -6,19 +6,21 @@ set -ex
cd $(dirname $0)/../..
root=`pwd`
export LD_LIBRARY_PATH=$root/libs/opt
source python2.7_virtual_environment/bin/activate
# TODO(issue 215): Properly itemize these in run_tests.py so that they can be parallelized.
python2.7_virtual_environment/bin/python2.7 -B -m _adapter._blocking_invocation_inline_service_test
python2.7_virtual_environment/bin/python2.7 -B -m _adapter._c_test
python2.7_virtual_environment/bin/python2.7 -B -m _adapter._event_invocation_synchronous_event_service_test
python2.7_virtual_environment/bin/python2.7 -B -m _adapter._future_invocation_asynchronous_event_service_test
python2.7_virtual_environment/bin/python2.7 -B -m _adapter._links_test
python2.7_virtual_environment/bin/python2.7 -B -m _adapter._lonely_rear_link_test
python2.7_virtual_environment/bin/python2.7 -B -m _adapter._low_test
python2.7_virtual_environment/bin/python2.7 -B -m _framework.base.packets.implementations_test
python2.7_virtual_environment/bin/python2.7 -B -m _framework.face.blocking_invocation_inline_service_test
python2.7_virtual_environment/bin/python2.7 -B -m _framework.face.event_invocation_synchronous_event_service_test
python2.7_virtual_environment/bin/python2.7 -B -m _framework.face.future_invocation_asynchronous_event_service_test
python2.7_virtual_environment/bin/python2.7 -B -m _framework.foundation._later_test
python2.7_virtual_environment/bin/python2.7 -B -m _framework.foundation._logging_pool_test
python2.7 -B -m _adapter._blocking_invocation_inline_service_test
python2.7 -B -m _adapter._c_test
python2.7 -B -m _adapter._event_invocation_synchronous_event_service_test
python2.7 -B -m _adapter._future_invocation_asynchronous_event_service_test
python2.7 -B -m _adapter._links_test
python2.7 -B -m _adapter._lonely_rear_link_test
python2.7 -B -m _adapter._low_test
python2.7 -B -m _framework.base.packets.implementations_test
python2.7 -B -m _framework.face.blocking_invocation_inline_service_test
python2.7 -B -m _framework.face.event_invocation_synchronous_event_service_test
python2.7 -B -m _framework.face.future_invocation_asynchronous_event_service_test
python2.7 -B -m _framework.foundation._later_test
python2.7 -B -m _framework.foundation._logging_pool_test
# TODO(nathaniel): Get tests working under 3.4 (requires 3.X-friendly protobuf)
# python3.4 -B -m unittest discover -s src/python -p '*.py'

Loading…
Cancel
Save