mirror of https://github.com/grpc/grpc.git
commit
cc44ee50e4
186 changed files with 5290 additions and 853 deletions
@ -0,0 +1,62 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPCXX_AUTH_CONTEXT_H |
||||
#define GRPCXX_AUTH_CONTEXT_H |
||||
|
||||
#include <vector> |
||||
|
||||
#include <grpc++/config.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
class AuthContext { |
||||
public: |
||||
typedef std::pair<grpc::string, grpc::string> Property; |
||||
|
||||
virtual ~AuthContext() {} |
||||
|
||||
// A peer identity, in general is one or more properties (in which case they
|
||||
// have the same name).
|
||||
virtual std::vector<grpc::string> GetPeerIdentity() const = 0; |
||||
virtual grpc::string GetPeerIdentityPropertyName() const = 0; |
||||
|
||||
// Returns all the property values with the given name.
|
||||
virtual std::vector<grpc::string> FindPropertyValues( |
||||
const grpc::string& name) const = 0; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_AUTH_CONTEXT_H
|
||||
|
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
/* This file is autogenerated from:
|
||||
templates/src/core/surface/version.c.template */ |
||||
|
||||
#include <grpc/grpc.h> |
||||
|
||||
const char *grpc_version_string(void) { |
||||
return "0.10.0.0"; |
||||
} |
@ -0,0 +1,42 @@ |
||||
/*
|
||||
* |
||||
* 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 <memory> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc++/auth_context.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
std::shared_ptr<const AuthContext> CreateAuthContext(grpc_call* call); |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,45 @@ |
||||
/*
|
||||
* |
||||
* 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 <memory> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc++/auth_context.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
std::shared_ptr<const AuthContext> CreateAuthContext(grpc_call* call) { |
||||
(void)call; |
||||
return std::shared_ptr<const AuthContext>(); |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,80 @@ |
||||
/*
|
||||
* |
||||
* 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 "src/cpp/common/secure_auth_context.h" |
||||
|
||||
#include <grpc/grpc_security.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
SecureAuthContext::SecureAuthContext(grpc_auth_context* ctx) : ctx_(ctx) {} |
||||
|
||||
SecureAuthContext::~SecureAuthContext() { grpc_auth_context_release(ctx_); } |
||||
|
||||
std::vector<grpc::string> SecureAuthContext::GetPeerIdentity() const { |
||||
if (!ctx_) { |
||||
return std::vector<grpc::string>(); |
||||
} |
||||
grpc_auth_property_iterator iter = grpc_auth_context_peer_identity(ctx_); |
||||
std::vector<grpc::string> identity; |
||||
const grpc_auth_property* property = nullptr; |
||||
while ((property = grpc_auth_property_iterator_next(&iter))) { |
||||
identity.push_back(grpc::string(property->value, property->value_length)); |
||||
} |
||||
return identity; |
||||
} |
||||
|
||||
grpc::string SecureAuthContext::GetPeerIdentityPropertyName() const { |
||||
if (!ctx_) { |
||||
return ""; |
||||
} |
||||
const char* name = grpc_auth_context_peer_identity_property_name(ctx_); |
||||
return name == nullptr ? "" : name; |
||||
} |
||||
|
||||
std::vector<grpc::string> SecureAuthContext::FindPropertyValues( |
||||
const grpc::string& name) const { |
||||
if (!ctx_) { |
||||
return std::vector<grpc::string>(); |
||||
} |
||||
grpc_auth_property_iterator iter = |
||||
grpc_auth_context_find_properties_by_name(ctx_, name.c_str()); |
||||
const grpc_auth_property* property = nullptr; |
||||
std::vector<grpc::string> values; |
||||
while ((property = grpc_auth_property_iterator_next(&iter))) { |
||||
values.push_back(grpc::string(property->value, property->value_length)); |
||||
} |
||||
return values; |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,62 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPC_INTERNAL_CPP_COMMON_SECURE_AUTH_CONTEXT_H |
||||
#define GRPC_INTERNAL_CPP_COMMON_SECURE_AUTH_CONTEXT_H |
||||
|
||||
#include <grpc++/auth_context.h> |
||||
|
||||
struct grpc_auth_context; |
||||
|
||||
namespace grpc { |
||||
|
||||
class SecureAuthContext GRPC_FINAL : public AuthContext { |
||||
public: |
||||
SecureAuthContext(grpc_auth_context* ctx); |
||||
|
||||
~SecureAuthContext() GRPC_OVERRIDE; |
||||
|
||||
std::vector<grpc::string> GetPeerIdentity() const GRPC_OVERRIDE; |
||||
|
||||
grpc::string GetPeerIdentityPropertyName() const GRPC_OVERRIDE; |
||||
|
||||
std::vector<grpc::string> FindPropertyValues(const grpc::string& name) const |
||||
GRPC_OVERRIDE; |
||||
|
||||
private: |
||||
grpc_auth_context* ctx_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPC_INTERNAL_CPP_COMMON_SECURE_AUTH_CONTEXT_H
|
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* 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 <memory> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
#include <grpc++/auth_context.h> |
||||
#include "src/cpp/common/secure_auth_context.h" |
||||
|
||||
namespace grpc { |
||||
|
||||
std::shared_ptr<const AuthContext> CreateAuthContext(grpc_call* call) { |
||||
if (call == nullptr) { |
||||
return std::shared_ptr<const AuthContext>(); |
||||
} |
||||
return std::shared_ptr<const AuthContext>( |
||||
new SecureAuthContext(grpc_call_auth_context(call))); |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -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. |
||||
* |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var grpc = require('../'); |
||||
|
||||
var _ = require('lodash'); |
||||
|
||||
var health_proto = grpc.load(__dirname + '/health.proto'); |
||||
|
||||
var HealthClient = health_proto.grpc.health.v1alpha.Health; |
||||
|
||||
function HealthImplementation(statusMap) { |
||||
this.statusMap = _.clone(statusMap); |
||||
} |
||||
|
||||
HealthImplementation.prototype.setStatus = function(host, service, status) { |
||||
if (!this.statusMap[host]) { |
||||
this.statusMap[host] = {}; |
||||
} |
||||
this.statusMap[host][service] = status; |
||||
}; |
||||
|
||||
HealthImplementation.prototype.check = function(call, callback){ |
||||
var host = call.request.host; |
||||
var service = call.request.service; |
||||
var status = _.get(this.statusMap, [host, service], null); |
||||
if (status === null) { |
||||
callback({code:grpc.status.NOT_FOUND}); |
||||
} else { |
||||
callback(null, {status: status}); |
||||
} |
||||
}; |
||||
|
||||
module.exports = { |
||||
Client: HealthClient, |
||||
service: HealthClient.service, |
||||
Implementation: HealthImplementation |
||||
}; |
@ -0,0 +1,50 @@ |
||||
// 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. |
||||
|
||||
syntax = "proto3"; |
||||
|
||||
package grpc.health.v1alpha; |
||||
|
||||
message HealthCheckRequest { |
||||
string host = 1; |
||||
string service = 2; |
||||
} |
||||
|
||||
message HealthCheckResponse { |
||||
enum ServingStatus { |
||||
UNKNOWN = 0; |
||||
SERVING = 1; |
||||
NOT_SERVING = 2; |
||||
} |
||||
ServingStatus status = 1; |
||||
} |
||||
|
||||
service Health { |
||||
rpc Check(HealthCheckRequest) returns (HealthCheckResponse); |
||||
} |
@ -0,0 +1,103 @@ |
||||
/* |
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var assert = require('assert'); |
||||
|
||||
var health = require('../health_check/health.js'); |
||||
|
||||
var grpc = require('../'); |
||||
|
||||
describe('Health Checking', function() { |
||||
var statusMap = { |
||||
'': { |
||||
'': 'SERVING', |
||||
'grpc.test.TestService': 'NOT_SERVING', |
||||
}, |
||||
virtual_host: { |
||||
'grpc.test.TestService': 'SERVING' |
||||
} |
||||
}; |
||||
var HealthServer = grpc.buildServer([health.service]); |
||||
var healthServer = new HealthServer({ |
||||
'grpc.health.v1alpha.Health': new health.Implementation(statusMap) |
||||
}); |
||||
var healthClient; |
||||
before(function() { |
||||
var port_num = healthServer.bind('0.0.0.0:0'); |
||||
healthServer.listen(); |
||||
healthClient = new health.Client('localhost:' + port_num); |
||||
}); |
||||
after(function() { |
||||
healthServer.shutdown(); |
||||
}); |
||||
it('should say an enabled service is SERVING', function(done) { |
||||
healthClient.check({service: ''}, function(err, response) { |
||||
assert.ifError(err); |
||||
assert.strictEqual(response.status, 'SERVING'); |
||||
done(); |
||||
}); |
||||
}); |
||||
it('should say that a disabled service is NOT_SERVING', function(done) { |
||||
healthClient.check({service: 'grpc.test.TestService'}, |
||||
function(err, response) { |
||||
assert.ifError(err); |
||||
assert.strictEqual(response.status, 'NOT_SERVING'); |
||||
done(); |
||||
}); |
||||
}); |
||||
it('should say that a service on another host is SERVING', function(done) { |
||||
healthClient.check({host: 'virtual_host', service: 'grpc.test.TestService'}, |
||||
function(err, response) { |
||||
assert.ifError(err); |
||||
assert.strictEqual(response.status, 'SERVING'); |
||||
done(); |
||||
}); |
||||
}); |
||||
it('should get NOT_FOUND if the service is not registered', function(done) { |
||||
healthClient.check({service: 'not_registered'}, function(err, response) { |
||||
assert(err); |
||||
assert.strictEqual(err.code, grpc.status.NOT_FOUND); |
||||
done(); |
||||
}); |
||||
}); |
||||
it('should get NOT_FOUND if the host is not registered', function(done) { |
||||
healthClient.check({host: 'wrong_host', service: 'grpc.test.TestService'}, |
||||
function(err, response) { |
||||
assert(err); |
||||
assert.strictEqual(err.code, grpc.status.NOT_FOUND); |
||||
done(); |
||||
}); |
||||
}); |
||||
}); |
@ -1,3 +1,4 @@ |
||||
MANIFEST |
||||
grpcio.egg-info/ |
||||
build/ |
||||
dist/ |
||||
|
@ -0,0 +1,5 @@ |
||||
*.a |
||||
*.so |
||||
*.dll |
||||
*.pyc |
||||
*.pyd |
@ -0,0 +1,7 @@ |
||||
*.h |
||||
*.c |
||||
*.a |
||||
*.so |
||||
*.dll |
||||
*.pyc |
||||
*.pyd |
@ -0,0 +1,52 @@ |
||||
GRPC Python Cython layer |
||||
======================== |
||||
|
||||
Package for the GRPC Python Cython layer. |
||||
|
||||
What is Cython? |
||||
--------------- |
||||
|
||||
Cython is both a superset of the Python language with extensions for dealing |
||||
with C types and a tool that transpiles this superset into C code. It provides |
||||
convenient means of statically typing expressions and of converting Python |
||||
strings to pointers (among other niceties), thus dramatically smoothing the |
||||
Python/C interop by allowing fluid use of APIs in both from the same source. |
||||
See the wonderful `Cython website`_. |
||||
|
||||
Why Cython? |
||||
----------- |
||||
|
||||
- **Python 2 and 3 support** |
||||
Cython generated C code has precompiler macros to target both Python 2 and |
||||
Python 3 C APIs, even while acting as a superset of just the Python 2 |
||||
language (e.g. using ``basestring``). |
||||
- **Significantly less semantic noise** |
||||
A lot of CPython code is just glue, especially human-error-prone |
||||
``Py_INCREF``-ing and ``Py_DECREF``-ing around error handlers and such. |
||||
Cython takes care of that automagically. |
||||
- **Possible PyPy support** |
||||
One of the major developments in Cython over the past few years was the |
||||
addition of support for PyPy. We might soon be able to provide such support |
||||
ourselves through our use of Cython. |
||||
- **Less Python glue code** |
||||
There existed several adapter layers in and around the original CPython code |
||||
to smooth the surface exposed to Python due to how much trouble it was to |
||||
make such a smooth surface via the CPython API alone. Cython makes writing |
||||
such a surface incredibly easy, so these adapter layers may be removed. |
||||
|
||||
Implications for Users |
||||
---------------------- |
||||
|
||||
Nothing additional will be required for users. PyPI packages will contain |
||||
Cython generated C code and thus not necessitate a Cython installation. |
||||
|
||||
Implications for GRPC Developers |
||||
-------------------------------- |
||||
|
||||
A typical edit-compile-debug cycle now requires Cython. We install Cython in |
||||
the ``virtualenv`` generated for the Python tests in this repository, so |
||||
initial test runs may take an extra 2+ minutes to complete. Subsequent test |
||||
runs won't reinstall ``Cython`` (unless required versions change and the |
||||
``virtualenv`` doesn't have installed versions that satisfy the change). |
||||
|
||||
.. _`Cython website`: http://cython.org/ |
@ -0,0 +1,28 @@ |
||||
# 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. |
@ -0,0 +1,28 @@ |
||||
# 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. |
@ -0,0 +1,37 @@ |
||||
# 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. |
||||
|
||||
from grpc._cython._cygrpc cimport grpc |
||||
|
||||
|
||||
cdef class Call: |
||||
|
||||
cdef grpc.grpc_call *c_call |
||||
cdef list references |
||||
|
@ -0,0 +1,82 @@ |
||||
# 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. |
||||
|
||||
cimport cpython |
||||
|
||||
from grpc._cython._cygrpc cimport records |
||||
|
||||
|
||||
cdef class Call: |
||||
|
||||
def __cinit__(self): |
||||
# Create an *empty* call |
||||
self.c_call = NULL |
||||
self.references = [] |
||||
|
||||
def start_batch(self, operations, tag): |
||||
if not self.is_valid: |
||||
raise ValueError("invalid call object cannot be used from Python") |
||||
cdef records.Operations cy_operations = records.Operations(operations) |
||||
cdef records.OperationTag operation_tag = records.OperationTag(tag) |
||||
operation_tag.operation_call = self |
||||
operation_tag.batch_operations = cy_operations |
||||
cpython.Py_INCREF(operation_tag) |
||||
return grpc.grpc_call_start_batch( |
||||
self.c_call, cy_operations.c_ops, cy_operations.c_nops, |
||||
<cpython.PyObject *>operation_tag) |
||||
|
||||
def cancel(self, |
||||
grpc.grpc_status_code error_code=grpc.GRPC_STATUS__DO_NOT_USE, |
||||
details=None): |
||||
if not self.is_valid: |
||||
raise ValueError("invalid call object cannot be used from Python") |
||||
if (details is None) != (error_code == grpc.GRPC_STATUS__DO_NOT_USE): |
||||
raise ValueError("if error_code is specified, so must details " |
||||
"(and vice-versa)") |
||||
if isinstance(details, bytes): |
||||
pass |
||||
elif isinstance(details, basestring): |
||||
details = details.encode() |
||||
else: |
||||
raise TypeError("expected details to be str or bytes") |
||||
if error_code != grpc.GRPC_STATUS__DO_NOT_USE: |
||||
self.references.append(details) |
||||
return grpc.grpc_call_cancel_with_status(self.c_call, error_code, details) |
||||
else: |
||||
return grpc.grpc_call_cancel(self.c_call) |
||||
|
||||
def __dealloc__(self): |
||||
if self.c_call != NULL: |
||||
grpc.grpc_call_destroy(self.c_call) |
||||
|
||||
# The object *should* always be valid from Python. Used for debugging. |
||||
@property |
||||
def is_valid(self): |
||||
return self.c_call != NULL |
||||
|
@ -0,0 +1,36 @@ |
||||
# 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. |
||||
|
||||
from grpc._cython._cygrpc cimport grpc |
||||
|
||||
|
||||
cdef class Channel: |
||||
|
||||
cdef grpc.grpc_channel *c_channel |
||||
cdef list references |
@ -0,0 +1,84 @@ |
||||
# 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. |
||||
|
||||
from grpc._cython._cygrpc cimport call |
||||
from grpc._cython._cygrpc cimport completion_queue |
||||
from grpc._cython._cygrpc cimport credentials |
||||
from grpc._cython._cygrpc cimport records |
||||
|
||||
|
||||
cdef class Channel: |
||||
|
||||
def __cinit__(self, target, records.ChannelArgs arguments=None, |
||||
credentials.ClientCredentials client_credentials=None): |
||||
cdef grpc.grpc_channel_args *c_arguments = NULL |
||||
self.c_channel = NULL |
||||
self.references = [] |
||||
if arguments is not None: |
||||
c_arguments = &arguments.c_args |
||||
if isinstance(target, bytes): |
||||
pass |
||||
elif isinstance(target, basestring): |
||||
target = target.encode() |
||||
else: |
||||
raise TypeError("expected target to be str or bytes") |
||||
if client_credentials is None: |
||||
self.c_channel = grpc.grpc_channel_create(target, c_arguments) |
||||
else: |
||||
self.c_channel = grpc.grpc_secure_channel_create( |
||||
client_credentials.c_credentials, target, c_arguments) |
||||
self.references.append(client_credentials) |
||||
self.references.append(target) |
||||
self.references.append(arguments) |
||||
|
||||
def create_call(self, completion_queue.CompletionQueue queue not None, |
||||
method, host, records.Timespec deadline not None): |
||||
if queue.is_shutting_down: |
||||
raise ValueError("queue must not be shutting down or shutdown") |
||||
if isinstance(method, bytes): |
||||
pass |
||||
elif isinstance(method, basestring): |
||||
method = method.encode() |
||||
else: |
||||
raise TypeError("expected method to be str or bytes") |
||||
if isinstance(host, bytes): |
||||
pass |
||||
elif isinstance(host, basestring): |
||||
host = host.encode() |
||||
else: |
||||
raise TypeError("expected host to be str or bytes") |
||||
cdef call.Call operation_call = call.Call() |
||||
operation_call.references = [self, method, host, queue] |
||||
operation_call.c_call = grpc.grpc_channel_create_call( |
||||
self.c_channel, queue.c_completion_queue, method, host, deadline.c_time) |
||||
return operation_call |
||||
|
||||
def __dealloc__(self): |
||||
if self.c_channel != NULL: |
||||
grpc.grpc_channel_destroy(self.c_channel) |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue