mirror of https://github.com/grpc/grpc.git
commit
be9e135d6f
83 changed files with 2259 additions and 3204 deletions
@ -1,52 +0,0 @@ |
||||
// 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. |
||||
|
||||
// TODO(jtattermusch): switch to proto3 once C# supports that. |
||||
syntax = "proto3"; |
||||
|
||||
package grpc.health.v1alpha; |
||||
option csharp_namespace = "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); |
||||
} |
@ -1,49 +0,0 @@ |
||||
// 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 service = 1; |
||||
} |
||||
|
||||
message HealthCheckResponse { |
||||
enum ServingStatus { |
||||
UNKNOWN = 0; |
||||
SERVING = 1; |
||||
NOT_SERVING = 2; |
||||
} |
||||
ServingStatus status = 1; |
||||
} |
||||
|
||||
service Health { |
||||
rpc Check(HealthCheckRequest) returns (HealthCheckResponse); |
||||
} |
@ -0,0 +1,336 @@ |
||||
/* |
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
/** |
||||
* Benchmark client module |
||||
* @module |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var fs = require('fs'); |
||||
var path = require('path'); |
||||
var util = require('util'); |
||||
var EventEmitter = require('events'); |
||||
var _ = require('lodash'); |
||||
var PoissonProcess = require('poisson-process'); |
||||
var Histogram = require('./histogram'); |
||||
var grpc = require('../../../'); |
||||
var serviceProto = grpc.load({ |
||||
root: __dirname + '/../../..', |
||||
file: 'test/proto/benchmarks/services.proto'}).grpc.testing; |
||||
|
||||
/** |
||||
* Create a buffer filled with size zeroes |
||||
* @param {number} size The length of the buffer |
||||
* @return {Buffer} The new buffer |
||||
*/ |
||||
function zeroBuffer(size) { |
||||
var zeros = new Buffer(size); |
||||
zeros.fill(0); |
||||
return zeros; |
||||
} |
||||
|
||||
/** |
||||
* Convert a time difference, as returned by process.hrtime, to a number of |
||||
* nanoseconds. |
||||
* @param {Array.<number>} time_diff The time diff, represented as |
||||
* [seconds, nanoseconds] |
||||
* @return {number} The total number of nanoseconds |
||||
*/ |
||||
function timeDiffToNanos(time_diff) { |
||||
return time_diff[0] * 1e9 + time_diff[1]; |
||||
} |
||||
|
||||
/** |
||||
* The BenchmarkClient class. Opens channels to servers and makes RPCs based on |
||||
* parameters from the driver, and records statistics about those RPCs. |
||||
* @param {Array.<string>} server_targets List of servers to connect to |
||||
* @param {number} channels The total number of channels to open |
||||
* @param {Object} histogram_params Options for setting up the histogram |
||||
* @param {Object=} security_params Options for TLS setup. If absent, don't use |
||||
* TLS |
||||
*/ |
||||
function BenchmarkClient(server_targets, channels, histogram_params, |
||||
security_params) { |
||||
var options = {}; |
||||
var creds; |
||||
if (security_params) { |
||||
var ca_path; |
||||
if (security_params.use_test_ca) { |
||||
ca_path = path.join(__dirname, '../test/data/ca.pem'); |
||||
var ca_data = fs.readFileSync(ca_path); |
||||
creds = grpc.credentials.createSsl(ca_data); |
||||
} else { |
||||
creds = grpc.credentials.createSsl(); |
||||
} |
||||
if (security_params.server_host_override) { |
||||
var host_override = security_params.server_host_override; |
||||
options['grpc.ssl_target_name_override'] = host_override; |
||||
options['grpc.default_authority'] = host_override; |
||||
} |
||||
} else { |
||||
creds = grpc.credentials.createInsecure(); |
||||
} |
||||
|
||||
this.clients = []; |
||||
|
||||
for (var i = 0; i < channels; i++) { |
||||
this.clients[i] = new serviceProto.BenchmarkService( |
||||
server_targets[i % server_targets.length], creds, options); |
||||
} |
||||
|
||||
this.histogram = new Histogram(histogram_params.resolution, |
||||
histogram_params.max_possible); |
||||
|
||||
this.running = false; |
||||
|
||||
this.pending_calls = 0; |
||||
}; |
||||
|
||||
util.inherits(BenchmarkClient, EventEmitter); |
||||
|
||||
/** |
||||
* Start a closed-loop test. For each channel, start |
||||
* outstanding_rpcs_per_channel RPCs. Then, whenever an RPC finishes, start |
||||
* another one. |
||||
* @param {number} outstanding_rpcs_per_channel Number of RPCs to start per |
||||
* channel |
||||
* @param {string} rpc_type Which method to call. Should be 'UNARY' or |
||||
* 'STREAMING' |
||||
* @param {number} req_size The size of the payload to send with each request |
||||
* @param {number} resp_size The size of payload to request be sent in responses |
||||
*/ |
||||
BenchmarkClient.prototype.startClosedLoop = function( |
||||
outstanding_rpcs_per_channel, rpc_type, req_size, resp_size) { |
||||
var self = this; |
||||
|
||||
self.running = true; |
||||
|
||||
self.last_wall_time = process.hrtime(); |
||||
|
||||
var makeCall; |
||||
|
||||
var argument = { |
||||
response_size: resp_size, |
||||
payload: { |
||||
body: zeroBuffer(req_size) |
||||
} |
||||
}; |
||||
|
||||
if (rpc_type == 'UNARY') { |
||||
makeCall = function(client) { |
||||
if (self.running) { |
||||
self.pending_calls++; |
||||
var start_time = process.hrtime(); |
||||
client.unaryCall(argument, function(error, response) { |
||||
if (error) { |
||||
self.emit('error', new Error('Client error: ' + error.message)); |
||||
self.running = false; |
||||
return; |
||||
} |
||||
var time_diff = process.hrtime(start_time); |
||||
self.histogram.add(timeDiffToNanos(time_diff)); |
||||
makeCall(client); |
||||
self.pending_calls--; |
||||
if ((!self.running) && self.pending_calls == 0) { |
||||
self.emit('finished'); |
||||
} |
||||
}); |
||||
} |
||||
}; |
||||
} else { |
||||
makeCall = function(client) { |
||||
if (self.running) { |
||||
self.pending_calls++; |
||||
var start_time = process.hrtime(); |
||||
var call = client.streamingCall(); |
||||
call.write(argument); |
||||
call.on('data', function() { |
||||
}); |
||||
call.on('end', function() { |
||||
var time_diff = process.hrtime(start_time); |
||||
self.histogram.add(timeDiffToNanos(time_diff)); |
||||
makeCall(client); |
||||
self.pending_calls--; |
||||
if ((!self.running) && self.pending_calls == 0) { |
||||
self.emit('finished'); |
||||
} |
||||
}); |
||||
call.on('error', function(error) { |
||||
self.emit('error', new Error('Client error: ' + error.message)); |
||||
self.running = false; |
||||
}); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
_.each(self.clients, function(client) { |
||||
_.times(outstanding_rpcs_per_channel, function() { |
||||
makeCall(client); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
/** |
||||
* Start a poisson test. For each channel, this initiates a number of Poisson |
||||
* processes equal to outstanding_rpcs_per_channel, where each Poisson process |
||||
* has the load parameter offered_load. |
||||
* @param {number} outstanding_rpcs_per_channel Number of RPCs to start per |
||||
* channel |
||||
* @param {string} rpc_type Which method to call. Should be 'UNARY' or |
||||
* 'STREAMING' |
||||
* @param {number} req_size The size of the payload to send with each request |
||||
* @param {number} resp_size The size of payload to request be sent in responses |
||||
* @param {number} offered_load The load parameter for the Poisson process |
||||
*/ |
||||
BenchmarkClient.prototype.startPoisson = function( |
||||
outstanding_rpcs_per_channel, rpc_type, req_size, resp_size, offered_load) { |
||||
var self = this; |
||||
|
||||
self.running = true; |
||||
|
||||
self.last_wall_time = process.hrtime(); |
||||
|
||||
var makeCall; |
||||
|
||||
var argument = { |
||||
response_size: resp_size, |
||||
payload: { |
||||
body: zeroBuffer(req_size) |
||||
} |
||||
}; |
||||
|
||||
if (rpc_type == 'UNARY') { |
||||
makeCall = function(client, poisson) { |
||||
if (self.running) { |
||||
self.pending_calls++; |
||||
var start_time = process.hrtime(); |
||||
client.unaryCall(argument, function(error, response) { |
||||
if (error) { |
||||
self.emit('error', new Error('Client error: ' + error.message)); |
||||
self.running = false; |
||||
return; |
||||
} |
||||
var time_diff = process.hrtime(start_time); |
||||
self.histogram.add(timeDiffToNanos(time_diff)); |
||||
self.pending_calls--; |
||||
if ((!self.running) && self.pending_calls == 0) { |
||||
self.emit('finished'); |
||||
} |
||||
}); |
||||
} else { |
||||
poisson.stop(); |
||||
} |
||||
}; |
||||
} else { |
||||
makeCall = function(client, poisson) { |
||||
if (self.running) { |
||||
self.pending_calls++; |
||||
var start_time = process.hrtime(); |
||||
var call = client.streamingCall(); |
||||
call.write(argument); |
||||
call.on('data', function() { |
||||
}); |
||||
call.on('end', function() { |
||||
var time_diff = process.hrtime(start_time); |
||||
self.histogram.add(timeDiffToNanos(time_diff)); |
||||
self.pending_calls--; |
||||
if ((!self.running) && self.pending_calls == 0) { |
||||
self.emit('finished'); |
||||
} |
||||
}); |
||||
call.on('error', function(error) { |
||||
self.emit('error', new Error('Client error: ' + error.message)); |
||||
self.running = false; |
||||
}); |
||||
} else { |
||||
poisson.stop(); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
var averageIntervalMs = (1 / offered_load) * 1000; |
||||
|
||||
_.each(self.clients, function(client) { |
||||
_.times(outstanding_rpcs_per_channel, function() { |
||||
var p = PoissonProcess.create(averageIntervalMs, function() { |
||||
makeCall(client, p); |
||||
}); |
||||
p.start(); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
/** |
||||
* Return curent statistics for the client. If reset is set, restart |
||||
* statistic collection. |
||||
* @param {boolean} reset Indicates that statistics should be reset |
||||
* @return {object} Client statistics |
||||
*/ |
||||
BenchmarkClient.prototype.mark = function(reset) { |
||||
var wall_time_diff = process.hrtime(this.last_wall_time); |
||||
var histogram = this.histogram; |
||||
if (reset) { |
||||
this.last_wall_time = process.hrtime(); |
||||
this.histogram = new Histogram(histogram.resolution, |
||||
histogram.max_possible); |
||||
} |
||||
|
||||
return { |
||||
latencies: { |
||||
bucket: histogram.getContents(), |
||||
min_seen: histogram.minimum(), |
||||
max_seen: histogram.maximum(), |
||||
sum: histogram.getSum(), |
||||
sum_of_squares: histogram.sumOfSquares(), |
||||
count: histogram.getCount() |
||||
}, |
||||
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9, |
||||
// Not sure how to measure these values
|
||||
time_user: 0, |
||||
time_system: 0 |
||||
}; |
||||
}; |
||||
|
||||
/** |
||||
* Stop the clients. |
||||
* @param {function} callback Called when the clients have finished shutting |
||||
* down |
||||
*/ |
||||
BenchmarkClient.prototype.stop = function(callback) { |
||||
this.running = false; |
||||
this.on('finished', callback); |
||||
}; |
||||
|
||||
module.exports = BenchmarkClient; |
@ -0,0 +1,162 @@ |
||||
/* |
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
/** |
||||
* Benchmark server module |
||||
* @module |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var fs = require('fs'); |
||||
var path = require('path'); |
||||
|
||||
var grpc = require('../../../'); |
||||
var serviceProto = grpc.load({ |
||||
root: __dirname + '/../../..', |
||||
file: 'test/proto/benchmarks/services.proto'}).grpc.testing; |
||||
|
||||
/** |
||||
* Create a buffer filled with size zeroes |
||||
* @param {number} size The length of the buffer |
||||
* @return {Buffer} The new buffer |
||||
*/ |
||||
function zeroBuffer(size) { |
||||
var zeros = new Buffer(size); |
||||
zeros.fill(0); |
||||
return zeros; |
||||
} |
||||
|
||||
/** |
||||
* Handler for the unary benchmark method. Simply responds with a payload |
||||
* containing the requested number of zero bytes. |
||||
* @param {Call} call The call object to be handled |
||||
* @param {function} callback The callback to call with the response |
||||
*/ |
||||
function unaryCall(call, callback) { |
||||
var req = call.request; |
||||
var payload = {body: zeroBuffer(req.response_size)}; |
||||
callback(null, {payload: payload}); |
||||
} |
||||
|
||||
/** |
||||
* Handler for the streaming benchmark method. Simply responds to each request |
||||
* with a payload containing the requested number of zero bytes. |
||||
* @param {Call} call The call object to be handled |
||||
*/ |
||||
function streamingCall(call) { |
||||
call.on('data', function(value) { |
||||
var payload = {body: zeroBuffer(value.repsonse_size)}; |
||||
call.write({payload: payload}); |
||||
}); |
||||
call.on('end', function() { |
||||
call.end(); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* BenchmarkServer class. Constructed based on parameters from the driver and |
||||
* stores statistics. |
||||
* @param {string} host The host to serve on |
||||
* @param {number} port The port to listen to |
||||
* @param {tls} Indicates whether TLS should be used |
||||
*/ |
||||
function BenchmarkServer(host, port, tls) { |
||||
var server_creds; |
||||
var host_override; |
||||
if (tls) { |
||||
var key_path = path.join(__dirname, '../test/data/server1.key'); |
||||
var pem_path = path.join(__dirname, '../test/data/server1.pem'); |
||||
|
||||
var key_data = fs.readFileSync(key_path); |
||||
var pem_data = fs.readFileSync(pem_path); |
||||
server_creds = grpc.ServerCredentials.createSsl(null, |
||||
[{private_key: key_data, |
||||
cert_chain: pem_data}]); |
||||
} else { |
||||
server_creds = grpc.ServerCredentials.createInsecure(); |
||||
} |
||||
|
||||
var server = new grpc.Server(); |
||||
this.port = server.bind(host + ':' + port, server_creds); |
||||
server.addProtoService(serviceProto.BenchmarkService.service, { |
||||
unaryCall: unaryCall, |
||||
streamingCall: streamingCall |
||||
}); |
||||
this.server = server; |
||||
} |
||||
|
||||
/** |
||||
* Start the benchmark server. |
||||
*/ |
||||
BenchmarkServer.prototype.start = function() { |
||||
this.server.start(); |
||||
this.last_wall_time = process.hrtime(); |
||||
}; |
||||
|
||||
/** |
||||
* Return the port number that the server is bound to. |
||||
* @return {Number} The port number |
||||
*/ |
||||
BenchmarkServer.prototype.getPort = function() { |
||||
return this.port; |
||||
}; |
||||
|
||||
/** |
||||
* Return current statistics for the server. If reset is set, restart |
||||
* statistic collection. |
||||
* @param {boolean} reset Indicates that statistics should be reset |
||||
* @return {object} Server statistics |
||||
*/ |
||||
BenchmarkServer.prototype.mark = function(reset) { |
||||
var wall_time_diff = process.hrtime(this.last_wall_time); |
||||
if (reset) { |
||||
this.last_wall_time = process.hrtime(); |
||||
} |
||||
return { |
||||
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9, |
||||
// Not sure how to measure these values
|
||||
time_user: 0, |
||||
time_system: 0 |
||||
}; |
||||
}; |
||||
|
||||
/** |
||||
* Stop the server. |
||||
* @param {function} callback Called when the server has finished shutting down |
||||
*/ |
||||
BenchmarkServer.prototype.stop = function(callback) { |
||||
this.server.tryShutdown(callback); |
||||
}; |
||||
|
||||
module.exports = BenchmarkServer; |
@ -0,0 +1,180 @@ |
||||
/* |
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
/** |
||||
* Histogram module. Exports the Histogram class |
||||
* @module |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
/** |
||||
* Histogram class. Collects data and exposes a histogram and other statistics. |
||||
* This data structure is taken directly from src/core/support/histogram.c, but |
||||
* pared down to the statistics needed for client stats in |
||||
* test/proto/benchmarks/stats.proto. |
||||
* @constructor |
||||
* @param {number} resolution The histogram's bucket resolution. Must be positive |
||||
* @param {number} max_possible The maximum allowed value. Must be greater than 1 |
||||
*/ |
||||
function Histogram(resolution, max_possible) { |
||||
this.resolution = resolution; |
||||
this.max_possible = max_possible; |
||||
|
||||
this.sum = 0; |
||||
this.sum_of_squares = 0; |
||||
this.multiplier = 1 + resolution; |
||||
this.count = 0; |
||||
this.min_seen = max_possible; |
||||
this.max_seen = 0; |
||||
this.buckets = []; |
||||
for (var i = 0; i < this.bucketFor(max_possible) + 1; i++) { |
||||
this.buckets[i] = 0; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Get the bucket index for a given value. |
||||
* @param {number} value The value to check |
||||
* @return {number} The bucket index |
||||
*/ |
||||
Histogram.prototype.bucketFor = function(value) { |
||||
return Math.floor(Math.log(value) / Math.log(this.multiplier)); |
||||
}; |
||||
|
||||
/** |
||||
* Get the minimum value for a given bucket index |
||||
* @param {number} The bucket index to check |
||||
* @return {number} The minimum value for that bucket |
||||
*/ |
||||
Histogram.prototype.bucketStart = function(index) { |
||||
return Math.pow(this.multiplier, index); |
||||
}; |
||||
|
||||
/** |
||||
* Add a value to the histogram. This updates all statistics with the new |
||||
* value. Those statistics should not be modified except with this function |
||||
* @param {number} value The value to add |
||||
*/ |
||||
Histogram.prototype.add = function(value) { |
||||
// Ensure value is a number
|
||||
value = +value; |
||||
this.sum += value; |
||||
this.sum_of_squares += value * value; |
||||
this.count++; |
||||
if (value < this.min_seen) { |
||||
this.min_seen = value; |
||||
} |
||||
if (value > this.max_seen) { |
||||
this.max_seen = value; |
||||
} |
||||
this.buckets[this.bucketFor(value)]++; |
||||
}; |
||||
|
||||
/** |
||||
* Get the mean of all added values |
||||
* @return {number} The mean |
||||
*/ |
||||
Histogram.prototype.mean = function() { |
||||
return this.sum / this.count; |
||||
}; |
||||
|
||||
/** |
||||
* Get the variance of all added values. Used to calulate the standard deviation |
||||
* @return {number} The variance |
||||
*/ |
||||
Histogram.prototype.variance = function() { |
||||
if (this.count == 0) { |
||||
return 0; |
||||
} |
||||
return (this.sum_of_squares * this.count - this.sum * this.sum) / |
||||
(this.count * this.count); |
||||
}; |
||||
|
||||
/** |
||||
* Get the standard deviation of all added values |
||||
* @return {number} The standard deviation |
||||
*/ |
||||
Histogram.prototype.stddev = function() { |
||||
return Math.sqrt(this.variance); |
||||
}; |
||||
|
||||
/** |
||||
* Get the maximum among all added values |
||||
* @return {number} The maximum |
||||
*/ |
||||
Histogram.prototype.maximum = function() { |
||||
return this.max_seen; |
||||
}; |
||||
|
||||
/** |
||||
* Get the minimum among all added values |
||||
* @return {number} The minimum |
||||
*/ |
||||
Histogram.prototype.minimum = function() { |
||||
return this.min_seen; |
||||
}; |
||||
|
||||
/** |
||||
* Get the number of all added values |
||||
* @return {number} The count |
||||
*/ |
||||
Histogram.prototype.getCount = function() { |
||||
return this.count; |
||||
}; |
||||
|
||||
/** |
||||
* Get the sum of all added values |
||||
* @return {number} The sum |
||||
*/ |
||||
Histogram.prototype.getSum = function() { |
||||
return this.sum; |
||||
}; |
||||
|
||||
/** |
||||
* Get the sum of squares of all added values |
||||
* @return {number} The sum of squares |
||||
*/ |
||||
Histogram.prototype.sumOfSquares = function() { |
||||
return this.sum_of_squares; |
||||
}; |
||||
|
||||
/** |
||||
* Get the raw histogram as a list of bucket sizes |
||||
* @return {Array.<number>} The buckets |
||||
*/ |
||||
Histogram.prototype.getContents = function() { |
||||
return this.buckets; |
||||
}; |
||||
|
||||
module.exports = Histogram; |
@ -1,119 +0,0 @@ |
||||
/* |
||||
* |
||||
* 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 testProto = grpc.load(__dirname + '/../interop/test.proto').grpc.testing; |
||||
var _ = require('lodash'); |
||||
var interop_server = require('../interop/interop_server.js'); |
||||
|
||||
function runTest(iterations, callback) { |
||||
var testServer = interop_server.getServer(0, false); |
||||
testServer.server.start(); |
||||
var client = new testProto.TestService('localhost:' + testServer.port, |
||||
grpc.credentials.createInsecure()); |
||||
|
||||
function runIterations(finish) { |
||||
var start = process.hrtime(); |
||||
var intervals = []; |
||||
function next(i) { |
||||
if (i >= iterations) { |
||||
testServer.server.shutdown(); |
||||
var totalDiff = process.hrtime(start); |
||||
finish({ |
||||
total: totalDiff[0] * 1000000 + totalDiff[1] / 1000, |
||||
intervals: intervals |
||||
}); |
||||
} else{ |
||||
var deadline = new Date(); |
||||
deadline.setSeconds(deadline.getSeconds() + 3); |
||||
var startTime = process.hrtime(); |
||||
client.emptyCall({}, function(err, resp) { |
||||
var timeDiff = process.hrtime(startTime); |
||||
intervals[i] = timeDiff[0] * 1000000 + timeDiff[1] / 1000; |
||||
next(i+1); |
||||
}, {}, {deadline: deadline}); |
||||
} |
||||
} |
||||
next(0); |
||||
} |
||||
|
||||
function warmUp(num) { |
||||
var pending = num; |
||||
function startCall() { |
||||
client.emptyCall({}, function(err, resp) { |
||||
pending--; |
||||
if (pending === 0) { |
||||
runIterations(callback); |
||||
} |
||||
}); |
||||
} |
||||
for (var i = 0; i < num; i++) { |
||||
startCall(); |
||||
} |
||||
} |
||||
warmUp(100); |
||||
} |
||||
|
||||
function percentile(arr, pct) { |
||||
if (pct > 99) { |
||||
pct = 99; |
||||
} |
||||
if (pct < 0) { |
||||
pct = 0; |
||||
} |
||||
var index = Math.floor(arr.length * pct / 100); |
||||
return arr[index]; |
||||
} |
||||
|
||||
if (require.main === module) { |
||||
var count; |
||||
if (process.argv.length >= 3) { |
||||
count = process.argv[2]; |
||||
} else { |
||||
count = 100; |
||||
} |
||||
runTest(count, function(results) { |
||||
var sorted_intervals = _.sortBy(results.intervals, _.identity); |
||||
console.log('count:', count); |
||||
console.log('total time:', results.total, 'us'); |
||||
console.log('median:', percentile(sorted_intervals, 50), 'us'); |
||||
console.log('90th percentile:', percentile(sorted_intervals, 90), 'us'); |
||||
console.log('95th percentile:', percentile(sorted_intervals, 95), 'us'); |
||||
console.log('99th percentile:', percentile(sorted_intervals, 99), 'us'); |
||||
console.log('QPS:', (count / results.total) * 1000000); |
||||
}); |
||||
} |
||||
|
||||
module.exports = runTest; |
@ -1,137 +0,0 @@ |
||||
/* |
||||
* |
||||
* 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 script runs a QPS test. It sends requests for a specified length of time |
||||
* with a specified number pending at any one time. It then outputs the measured |
||||
* QPS. Usage: |
||||
* node qps_test.js [--concurrent=count] [--time=seconds] |
||||
* concurrent defaults to 100 and time defaults to 10 |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var async = require('async'); |
||||
var parseArgs = require('minimist'); |
||||
|
||||
var grpc = require('..'); |
||||
var testProto = grpc.load(__dirname + '/../interop/test.proto').grpc.testing; |
||||
var interop_server = require('../interop/interop_server.js'); |
||||
|
||||
/** |
||||
* Runs the QPS test. Sends requests constantly for the given number of seconds, |
||||
* and keeps concurrent_calls requests pending at all times. When the test ends, |
||||
* the callback is called with the number of calls that completed within the |
||||
* time limit. |
||||
* @param {number} concurrent_calls The number of calls to have pending |
||||
* simultaneously |
||||
* @param {number} seconds The number of seconds to run the test for |
||||
* @param {function(Error, number)} callback Callback for test completion |
||||
*/ |
||||
function runTest(concurrent_calls, seconds, callback) { |
||||
var testServer = interop_server.getServer(0, false); |
||||
testServer.server.start(); |
||||
var client = new testProto.TestService('localhost:' + testServer.port, |
||||
grpc.credentials.createInsecure()); |
||||
|
||||
var warmup_num = 100; |
||||
|
||||
/** |
||||
* Warms up the client to avoid counting startup time in the test result |
||||
* @param {function(Error)} callback Called when warmup is complete |
||||
*/ |
||||
function warmUp(callback) { |
||||
var pending = warmup_num; |
||||
function startCall() { |
||||
client.emptyCall({}, function(err, resp) { |
||||
if (err) { |
||||
callback(err); |
||||
return; |
||||
} |
||||
pending--; |
||||
if (pending === 0) { |
||||
callback(null); |
||||
} |
||||
}); |
||||
} |
||||
for (var i = 0; i < warmup_num; i++) { |
||||
startCall(); |
||||
} |
||||
} |
||||
/** |
||||
* Run the QPS test. Starts concurrent_calls requests, then starts a new |
||||
* request whenever one completes until time runs out. |
||||
* @param {function(Error, number)} callback Called when the test is complete. |
||||
* The second argument is the number of calls that finished within the |
||||
* time limit |
||||
*/ |
||||
function run(callback) { |
||||
var running = 0; |
||||
var count = 0; |
||||
var start = process.hrtime(); |
||||
function responseCallback(err, resp) { |
||||
if (process.hrtime(start)[0] < seconds) { |
||||
count += 1; |
||||
client.emptyCall({}, responseCallback); |
||||
} else { |
||||
running -= 1; |
||||
if (running <= 0) { |
||||
callback(null, count); |
||||
} |
||||
} |
||||
} |
||||
for (var i = 0; i < concurrent_calls; i++) { |
||||
running += 1; |
||||
client.emptyCall({}, responseCallback); |
||||
} |
||||
} |
||||
async.waterfall([warmUp, run], function(err, count) { |
||||
testServer.server.shutdown(); |
||||
callback(err, count); |
||||
}); |
||||
} |
||||
|
||||
if (require.main === module) { |
||||
var argv = parseArgs(process.argv.slice(2), { |
||||
default: {'concurrent': 100, |
||||
'time': 10} |
||||
}); |
||||
runTest(argv.concurrent, argv.time, function(err, count) { |
||||
if (err) { |
||||
throw err; |
||||
} |
||||
console.log('Concurrent calls:', argv.concurrent); |
||||
console.log('Time:', argv.time, 'seconds'); |
||||
console.log('QPS:', (count/argv.time)); |
||||
}); |
||||
} |
@ -0,0 +1,132 @@ |
||||
/* |
||||
* |
||||
* 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 BenchmarkClient = require('./benchmark_client'); |
||||
var BenchmarkServer = require('./benchmark_server'); |
||||
|
||||
exports.runClient = function runClient(call) { |
||||
var client; |
||||
call.on('data', function(request) { |
||||
var stats; |
||||
switch (request.argtype) { |
||||
case 'setup': |
||||
var setup = request.setup; |
||||
client = new BenchmarkClient(setup.server_targets, |
||||
setup.client_channels, |
||||
setup.histogram_params, |
||||
setup.security_params); |
||||
client.on('error', function(error) { |
||||
call.emit('error', error); |
||||
}); |
||||
switch (setup.load_params.load) { |
||||
case 'closed_loop': |
||||
client.startClosedLoop(setup.outstanding_rpcs_per_channel, |
||||
setup.rpc_type, |
||||
setup.payload_config.simple_params.req_size, |
||||
setup.payload_config.simple_params.resp_size); |
||||
break; |
||||
case 'poisson': |
||||
client.startPoisson(setup.outstanding_rpcs_per_channel, |
||||
setup.rpc_type, setup.payload_config.req_size, |
||||
setup.payload_config.resp_size, |
||||
setup.load_params.poisson.offered_load); |
||||
break; |
||||
default: |
||||
call.emit('error', new Error('Unsupported LoadParams type' + |
||||
setup.load_params.load)); |
||||
} |
||||
stats = client.mark(); |
||||
call.write({ |
||||
stats: stats |
||||
}); |
||||
break; |
||||
case 'mark': |
||||
if (client) { |
||||
stats = client.mark(request.mark.reset); |
||||
call.write({ |
||||
stats: stats |
||||
}); |
||||
} else { |
||||
call.emit('error', new Error('Got Mark before ClientConfig')); |
||||
} |
||||
break; |
||||
default: |
||||
throw new Error('Nonexistent client argtype option: ' + request.argtype); |
||||
} |
||||
}); |
||||
call.on('end', function() { |
||||
client.stop(function() { |
||||
call.end(); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
exports.runServer = function runServer(call) { |
||||
var server; |
||||
call.on('data', function(request) { |
||||
var stats; |
||||
switch (request.argtype) { |
||||
case 'setup': |
||||
server = new BenchmarkServer(request.setup.host, request.setup.port, |
||||
request.setup.security_params); |
||||
server.start(); |
||||
stats = server.mark(); |
||||
call.write({ |
||||
stats: stats, |
||||
port: server.getPort() |
||||
}); |
||||
break; |
||||
case 'mark': |
||||
if (server) { |
||||
stats = server.mark(request.mark.reset); |
||||
call.write({ |
||||
stats: stats, |
||||
port: server.getPort(), |
||||
cores: 1 |
||||
}); |
||||
} else { |
||||
call.emit('error', new Error('Got Mark before ServerConfig')); |
||||
} |
||||
break; |
||||
default: |
||||
throw new Error('Nonexistent server argtype option'); |
||||
} |
||||
}); |
||||
call.on('end', function() { |
||||
server.stop(function() { |
||||
call.end(); |
||||
}); |
||||
}); |
||||
}; |
@ -1,80 +0,0 @@ |
||||
|
||||
// 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 math; |
||||
|
||||
message DivArgs { |
||||
int64 dividend = 1; |
||||
int64 divisor = 2; |
||||
} |
||||
|
||||
message DivReply { |
||||
int64 quotient = 1; |
||||
int64 remainder = 2; |
||||
} |
||||
|
||||
message FibArgs { |
||||
int64 limit = 1; |
||||
} |
||||
|
||||
message Num { |
||||
int64 num = 1; |
||||
} |
||||
|
||||
message FibReply { |
||||
int64 count = 1; |
||||
} |
||||
|
||||
service Math { |
||||
// Div divides args.dividend by args.divisor and returns the quotient and |
||||
// remainder. |
||||
rpc Div (DivArgs) returns (DivReply) { |
||||
} |
||||
|
||||
// DivMany accepts an arbitrary number of division args from the client stream |
||||
// and sends back the results in the reply stream. The stream continues until |
||||
// the client closes its end; the server does the same after sending all the |
||||
// replies. The stream ends immediately if either end aborts. |
||||
rpc DivMany (stream DivArgs) returns (stream DivReply) { |
||||
} |
||||
|
||||
// Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib |
||||
// generates up to limit numbers; otherwise it continues until the call is |
||||
// canceled. Unlike Fib above, Fib has no final FibReply. |
||||
rpc Fib (FibArgs) returns (stream Num) { |
||||
} |
||||
|
||||
// Sum sums a stream of numbers, returning the final result once the stream |
||||
// is closed. |
||||
rpc Sum (stream Num) returns (Num) { |
||||
} |
||||
} |
@ -1,286 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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__ADAPTER__C_TYPES_H_ |
||||
#define GRPC__ADAPTER__C_TYPES_H_ |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
|
||||
|
||||
/*=========================*/ |
||||
/* Client-side credentials */ |
||||
/*=========================*/ |
||||
|
||||
typedef struct ChannelCredentials { |
||||
PyObject_HEAD |
||||
grpc_channel_credentials *c_creds; |
||||
} ChannelCredentials; |
||||
void pygrpc_ChannelCredentials_dealloc(ChannelCredentials *self); |
||||
ChannelCredentials *pygrpc_ChannelCredentials_google_default( |
||||
PyTypeObject *type, PyObject *ignored); |
||||
ChannelCredentials *pygrpc_ChannelCredentials_ssl( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
ChannelCredentials *pygrpc_ChannelCredentials_composite( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
extern PyTypeObject pygrpc_ChannelCredentials_type; |
||||
|
||||
typedef struct CallCredentials { |
||||
PyObject_HEAD |
||||
grpc_call_credentials *c_creds; |
||||
} CallCredentials; |
||||
void pygrpc_CallCredentials_dealloc(CallCredentials *self); |
||||
CallCredentials *pygrpc_CallCredentials_composite( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
CallCredentials *pygrpc_CallCredentials_compute_engine( |
||||
PyTypeObject *type, PyObject *ignored); |
||||
CallCredentials *pygrpc_CallCredentials_jwt( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
CallCredentials *pygrpc_CallCredentials_refresh_token( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
CallCredentials *pygrpc_CallCredentials_iam( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
extern PyTypeObject pygrpc_CallCredentials_type; |
||||
|
||||
/*=========================*/ |
||||
/* Server-side credentials */ |
||||
/*=========================*/ |
||||
|
||||
typedef struct ServerCredentials { |
||||
PyObject_HEAD |
||||
grpc_server_credentials *c_creds; |
||||
} ServerCredentials; |
||||
void pygrpc_ServerCredentials_dealloc(ServerCredentials *self); |
||||
ServerCredentials *pygrpc_ServerCredentials_ssl( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
extern PyTypeObject pygrpc_ServerCredentials_type; |
||||
|
||||
|
||||
/*==================*/ |
||||
/* Completion queue */ |
||||
/*==================*/ |
||||
|
||||
typedef struct CompletionQueue { |
||||
PyObject_HEAD |
||||
grpc_completion_queue *c_cq; |
||||
} CompletionQueue; |
||||
CompletionQueue *pygrpc_CompletionQueue_new( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
void pygrpc_CompletionQueue_dealloc(CompletionQueue *self); |
||||
PyObject *pygrpc_CompletionQueue_next( |
||||
CompletionQueue *self, PyObject *args, PyObject *kwargs); |
||||
PyObject *pygrpc_CompletionQueue_shutdown( |
||||
CompletionQueue *self, PyObject *ignored); |
||||
extern PyTypeObject pygrpc_CompletionQueue_type; |
||||
|
||||
|
||||
/*======*/ |
||||
/* Call */ |
||||
/*======*/ |
||||
|
||||
typedef struct Call { |
||||
PyObject_HEAD |
||||
grpc_call *c_call; |
||||
CompletionQueue *cq; |
||||
} Call; |
||||
Call *pygrpc_Call_new_empty(CompletionQueue *cq); |
||||
void pygrpc_Call_dealloc(Call *self); |
||||
PyObject *pygrpc_Call_start_batch(Call *self, PyObject *args, PyObject *kwargs); |
||||
PyObject *pygrpc_Call_cancel(Call *self, PyObject *args, PyObject *kwargs); |
||||
PyObject *pygrpc_Call_peer(Call *self); |
||||
PyObject *pygrpc_Call_set_credentials(Call *self, PyObject *args, |
||||
PyObject *kwargs); |
||||
extern PyTypeObject pygrpc_Call_type; |
||||
|
||||
|
||||
/*=========*/ |
||||
/* Channel */ |
||||
/*=========*/ |
||||
|
||||
typedef struct Channel { |
||||
PyObject_HEAD |
||||
grpc_channel *c_chan; |
||||
} Channel; |
||||
Channel *pygrpc_Channel_new( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
void pygrpc_Channel_dealloc(Channel *self); |
||||
Call *pygrpc_Channel_create_call( |
||||
Channel *self, PyObject *args, PyObject *kwargs); |
||||
PyObject *pygrpc_Channel_check_connectivity_state(Channel *self, PyObject *args, |
||||
PyObject *kwargs); |
||||
PyObject *pygrpc_Channel_watch_connectivity_state(Channel *self, PyObject *args, |
||||
PyObject *kwargs); |
||||
PyObject *pygrpc_Channel_target(Channel *self); |
||||
extern PyTypeObject pygrpc_Channel_type; |
||||
|
||||
|
||||
/*========*/ |
||||
/* Server */ |
||||
/*========*/ |
||||
|
||||
typedef struct Server { |
||||
PyObject_HEAD |
||||
grpc_server *c_serv; |
||||
CompletionQueue *cq; |
||||
int shutdown_called; |
||||
} Server; |
||||
Server *pygrpc_Server_new(PyTypeObject *type, PyObject *args, PyObject *kwargs); |
||||
void pygrpc_Server_dealloc(Server *self); |
||||
PyObject *pygrpc_Server_request_call( |
||||
Server *self, PyObject *args, PyObject *kwargs); |
||||
PyObject *pygrpc_Server_add_http2_port( |
||||
Server *self, PyObject *args, PyObject *kwargs); |
||||
PyObject *pygrpc_Server_start(Server *self, PyObject *ignored); |
||||
PyObject *pygrpc_Server_shutdown( |
||||
Server *self, PyObject *args, PyObject *kwargs); |
||||
PyObject *pygrpc_Server_cancel_all_calls(Server *self, PyObject *unused); |
||||
extern PyTypeObject pygrpc_Server_type; |
||||
|
||||
/*=========*/ |
||||
/* Utility */ |
||||
/*=========*/ |
||||
|
||||
/* Every tag that passes from Python GRPC to GRPC core is of this type. */ |
||||
typedef struct pygrpc_tag { |
||||
PyObject *user_tag; |
||||
Call *call; |
||||
grpc_call_details request_call_details; |
||||
grpc_metadata_array request_metadata; |
||||
grpc_op *ops; |
||||
size_t nops; |
||||
int is_new_call; |
||||
} pygrpc_tag; |
||||
|
||||
/* Construct a tag associated with a batch call. Does not take ownership of the
|
||||
resources in the elements of ops. */ |
||||
pygrpc_tag *pygrpc_produce_batch_tag(PyObject *user_tag, Call *call, |
||||
grpc_op *ops, size_t nops); |
||||
|
||||
|
||||
/* Construct a tag associated with a server request. The calling code should
|
||||
use the appropriate fields of the produced tag in the invocation of |
||||
grpc_server_request_call. */ |
||||
pygrpc_tag *pygrpc_produce_request_tag(PyObject *user_tag, Call *empty_call); |
||||
|
||||
/* Construct a tag associated with a server shutdown. */ |
||||
pygrpc_tag *pygrpc_produce_server_shutdown_tag(PyObject *user_tag); |
||||
|
||||
/* Construct a tag associated with a channel state change. */ |
||||
pygrpc_tag *pygrpc_produce_channel_state_change_tag(PyObject *user_tag); |
||||
|
||||
/* Frees all resources owned by the tag and the tag itself. */ |
||||
void pygrpc_discard_tag(pygrpc_tag *tag); |
||||
|
||||
/* Consumes an event and its associated tag, providing a Python tuple of the
|
||||
form `(type, tag, call, call_details, results)` (where type is an integer |
||||
corresponding to a grpc_completion_type, tag is an arbitrary PyObject, call |
||||
is the call object associated with the event [if any], call_details is a |
||||
tuple of form `(method, host, deadline)` [if such details are available], |
||||
and resultd is a list of tuples of form `(type, metadata, message, status, |
||||
cancelled)` [where type corresponds to a grpc_op_type, metadata is a |
||||
sequence of 2-sequences of strings, message is a byte string, and status is |
||||
a 2-tuple of an integer corresponding to grpc_status_code and a string of |
||||
status details]). |
||||
|
||||
Frees all resources associated with the event tag. */ |
||||
PyObject *pygrpc_consume_event(grpc_event event); |
||||
|
||||
/* Transliterate the Python tuple of form `(type, metadata, message,
|
||||
status)` (where type is an integer corresponding to a grpc_op_type, metadata |
||||
is a sequence of 2-sequences of strings, message is a byte string, and |
||||
status is 2-tuple of an integer corresponding to grpc_status_code and a |
||||
string of status details) to a grpc_op suitable for use in a |
||||
grpc_call_start_batch invocation. The grpc_op is a 'directory' of resources |
||||
that must be freed after GRPC core is done with them. |
||||
|
||||
Calls gpr_malloc (or the appropriate type-specific grpc_*_create function) |
||||
to populate the appropriate union-discriminated members of the op. |
||||
|
||||
Returns true on success, false on failure. */ |
||||
int pygrpc_produce_op(PyObject *op, grpc_op *result); |
||||
|
||||
/* Discards all resources associated with the passed in op that was produced by
|
||||
pygrpc_produce_op. */ |
||||
void pygrpc_discard_op(grpc_op op); |
||||
|
||||
/* Transliterate the grpc_ops (which have been sent through a
|
||||
grpc_call_start_batch invocation and whose corresponding event has appeared |
||||
on a completion queue) to a Python tuple of form `(type, metadata, message, |
||||
status, cancelled)` (where type is an integer corresponding to a |
||||
grpc_op_type, metadata is a sequence of 2-sequences of strings, message is a |
||||
byte string, and status is 2-tuple of an integer corresponding to |
||||
grpc_status_code and a string of status details). |
||||
|
||||
Calls gpr_free (or the appropriate type-specific grpc_*_destroy function) on |
||||
the appropriate union-discriminated populated members of the ops. */ |
||||
PyObject *pygrpc_consume_ops(grpc_op *op, size_t nops); |
||||
|
||||
/* Transliterate from a gpr_timespec to a double (in units of seconds, either
|
||||
from the epoch if interpreted absolutely or as a delta otherwise). */ |
||||
double pygrpc_cast_gpr_timespec_to_double(gpr_timespec timespec); |
||||
|
||||
/* Transliterate from a double (in units of seconds from the epoch if
|
||||
interpreted absolutely or as a delta otherwise) to a gpr_timespec. */ |
||||
gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds); |
||||
|
||||
/* Returns true on success, false on failure. */ |
||||
int pygrpc_cast_pyseq_to_send_metadata( |
||||
PyObject *pyseq, grpc_metadata **metadata, size_t *count); |
||||
/* Returns a metadata array as a Python object on success, else NULL. */ |
||||
PyObject *pygrpc_cast_metadata_array_to_pyseq(grpc_metadata_array metadata); |
||||
|
||||
/* Transliterate from a list of python channel arguments (2-tuples of string
|
||||
and string|integer|None) to a grpc_channel_args object. The strings placed |
||||
in the grpc_channel_args object's grpc_arg elements are views of the Python |
||||
object. The Python object must live long enough for the grpc_channel_args |
||||
to be used. Arguments set to None are silently ignored. Returns true on |
||||
success, false on failure. */ |
||||
int pygrpc_produce_channel_args(PyObject *py_args, grpc_channel_args *c_args); |
||||
void pygrpc_discard_channel_args(grpc_channel_args args); |
||||
|
||||
/* Read the bytes from grpc_byte_buffer to a gpr_malloc'd array of bytes;
|
||||
output to result and result_size. */ |
||||
void pygrpc_byte_buffer_to_bytes( |
||||
grpc_byte_buffer *buffer, char **result, size_t *result_size); |
||||
|
||||
|
||||
/*========*/ |
||||
/* Module */ |
||||
/*========*/ |
||||
|
||||
/* Returns 0 on success, -1 on failure. */ |
||||
int pygrpc_module_add_types(PyObject *module); |
||||
|
||||
#endif /* GRPC__ADAPTER__C_TYPES_H_ */ |
@ -1,186 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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/_adapter/_c/types.h" |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/alloc.h> |
||||
|
||||
|
||||
PyMethodDef pygrpc_Call_methods[] = { |
||||
{"start_batch", (PyCFunction)pygrpc_Call_start_batch, METH_KEYWORDS, ""}, |
||||
{"cancel", (PyCFunction)pygrpc_Call_cancel, METH_KEYWORDS, ""}, |
||||
{"peer", (PyCFunction)pygrpc_Call_peer, METH_NOARGS, ""}, |
||||
{"set_credentials", (PyCFunction)pygrpc_Call_set_credentials, METH_KEYWORDS, |
||||
""}, |
||||
{NULL} |
||||
}; |
||||
const char pygrpc_Call_doc[] = "See grpc._adapter._types.Call."; |
||||
PyTypeObject pygrpc_Call_type = { |
||||
PyObject_HEAD_INIT(NULL) |
||||
0, /* ob_size */ |
||||
"Call", /* tp_name */ |
||||
sizeof(Call), /* tp_basicsize */ |
||||
0, /* tp_itemsize */ |
||||
(destructor)pygrpc_Call_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 | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
||||
pygrpc_Call_doc, /* tp_doc */ |
||||
0, /* tp_traverse */ |
||||
0, /* tp_clear */ |
||||
0, /* tp_richcompare */ |
||||
0, /* tp_weaklistoffset */ |
||||
0, /* tp_iter */ |
||||
0, /* tp_iternext */ |
||||
pygrpc_Call_methods, /* 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 */ |
||||
0, /* tp_init */ |
||||
0, /* tp_alloc */ |
||||
0 /* tp_new */ |
||||
}; |
||||
|
||||
Call *pygrpc_Call_new_empty(CompletionQueue *cq) { |
||||
Call *call = (Call *)pygrpc_Call_type.tp_alloc(&pygrpc_Call_type, 0); |
||||
call->c_call = NULL; |
||||
call->cq = cq; |
||||
Py_XINCREF(call->cq); |
||||
return call; |
||||
} |
||||
void pygrpc_Call_dealloc(Call *self) { |
||||
if (self->c_call) { |
||||
grpc_call_destroy(self->c_call); |
||||
} |
||||
Py_XDECREF(self->cq); |
||||
self->ob_type->tp_free((PyObject *)self); |
||||
} |
||||
PyObject *pygrpc_Call_start_batch(Call *self, PyObject *args, PyObject *kwargs) { |
||||
PyObject *op_list; |
||||
PyObject *user_tag; |
||||
grpc_op *ops; |
||||
size_t nops; |
||||
size_t i; |
||||
size_t j; |
||||
pygrpc_tag *tag; |
||||
grpc_call_error errcode; |
||||
static char *keywords[] = {"ops", "tag", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:start_batch", keywords, |
||||
&op_list, &user_tag)) { |
||||
return NULL; |
||||
} |
||||
if (!PyList_Check(op_list)) { |
||||
PyErr_SetString(PyExc_TypeError, "expected a list of OpArgs"); |
||||
return NULL; |
||||
} |
||||
nops = PyList_Size(op_list); |
||||
ops = gpr_malloc(sizeof(grpc_op) * nops); |
||||
for (i = 0; i < nops; ++i) { |
||||
PyObject *item = PyList_GET_ITEM(op_list, i); |
||||
if (!pygrpc_produce_op(item, &ops[i])) { |
||||
for (j = 0; j < i; ++j) { |
||||
pygrpc_discard_op(ops[j]); |
||||
} |
||||
return NULL; |
||||
} |
||||
} |
||||
tag = pygrpc_produce_batch_tag(user_tag, self, ops, nops); |
||||
errcode = grpc_call_start_batch(self->c_call, tag->ops, tag->nops, tag, NULL); |
||||
gpr_free(ops); |
||||
return PyInt_FromLong(errcode); |
||||
} |
||||
PyObject *pygrpc_Call_cancel(Call *self, PyObject *args, PyObject *kwargs) { |
||||
PyObject *py_code = NULL; |
||||
grpc_call_error errcode; |
||||
int code; |
||||
char *details = NULL; |
||||
static char *keywords[] = {"code", "details", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Os:start_batch", keywords, |
||||
&py_code, &details)) { |
||||
return NULL; |
||||
} |
||||
if (py_code != NULL && details != NULL) { |
||||
if (!PyInt_Check(py_code)) { |
||||
PyErr_SetString(PyExc_TypeError, "expected integer code"); |
||||
return NULL; |
||||
} |
||||
code = PyInt_AsLong(py_code); |
||||
errcode = grpc_call_cancel_with_status(self->c_call, code, details, NULL); |
||||
} else if (py_code != NULL || details != NULL) { |
||||
PyErr_SetString(PyExc_ValueError, |
||||
"if `code` is specified, so must `details`"); |
||||
return NULL; |
||||
} else { |
||||
errcode = grpc_call_cancel(self->c_call, NULL); |
||||
} |
||||
return PyInt_FromLong(errcode); |
||||
} |
||||
|
||||
PyObject *pygrpc_Call_peer(Call *self) { |
||||
char *peer = grpc_call_get_peer(self->c_call); |
||||
PyObject *py_peer = PyString_FromString(peer); |
||||
gpr_free(peer); |
||||
return py_peer; |
||||
} |
||||
PyObject *pygrpc_Call_set_credentials(Call *self, PyObject *args, |
||||
PyObject *kwargs) { |
||||
CallCredentials *creds; |
||||
grpc_call_error errcode; |
||||
static char *keywords[] = {"creds", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords( |
||||
args, kwargs, "O!:set_credentials", keywords, |
||||
&pygrpc_CallCredentials_type, &creds)) { |
||||
return NULL; |
||||
} |
||||
errcode = grpc_call_set_credentials(self->c_call, creds->c_creds); |
||||
return PyInt_FromLong(errcode); |
||||
} |
@ -1,203 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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/_adapter/_c/types.h" |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
|
||||
|
||||
PyMethodDef pygrpc_CallCredentials_methods[] = { |
||||
{"composite", (PyCFunction)pygrpc_CallCredentials_composite, |
||||
METH_CLASS|METH_KEYWORDS, ""}, |
||||
{"compute_engine", (PyCFunction)pygrpc_CallCredentials_compute_engine, |
||||
METH_CLASS|METH_NOARGS, ""}, |
||||
{"jwt", (PyCFunction)pygrpc_CallCredentials_jwt, |
||||
METH_CLASS|METH_KEYWORDS, ""}, |
||||
{"refresh_token", (PyCFunction)pygrpc_CallCredentials_refresh_token, |
||||
METH_CLASS|METH_KEYWORDS, ""}, |
||||
{"iam", (PyCFunction)pygrpc_CallCredentials_iam, |
||||
METH_CLASS|METH_KEYWORDS, ""}, |
||||
{NULL} |
||||
}; |
||||
|
||||
const char pygrpc_CallCredentials_doc[] = ""; |
||||
PyTypeObject pygrpc_CallCredentials_type = { |
||||
PyObject_HEAD_INIT(NULL) |
||||
0, /* ob_size */ |
||||
"CallCredentials", /* tp_name */ |
||||
sizeof(CallCredentials), /* tp_basicsize */ |
||||
0, /* tp_itemsize */ |
||||
(destructor)pygrpc_CallCredentials_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 | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
||||
pygrpc_CallCredentials_doc, /* tp_doc */ |
||||
0, /* tp_traverse */ |
||||
0, /* tp_clear */ |
||||
0, /* tp_richcompare */ |
||||
0, /* tp_weaklistoffset */ |
||||
0, /* tp_iter */ |
||||
0, /* tp_iternext */ |
||||
pygrpc_CallCredentials_methods, /* 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 */ |
||||
0, /* tp_init */ |
||||
0, /* tp_alloc */ |
||||
0 /* tp_new */ |
||||
}; |
||||
|
||||
void pygrpc_CallCredentials_dealloc(CallCredentials *self) { |
||||
grpc_call_credentials_release(self->c_creds); |
||||
self->ob_type->tp_free((PyObject *)self); |
||||
} |
||||
|
||||
CallCredentials *pygrpc_CallCredentials_composite( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
CallCredentials *self; |
||||
CallCredentials *creds1; |
||||
CallCredentials *creds2; |
||||
static char *keywords[] = {"creds1", "creds2", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!:composite", keywords, |
||||
&pygrpc_CallCredentials_type, &creds1, |
||||
&pygrpc_CallCredentials_type, &creds2)) { |
||||
return NULL; |
||||
} |
||||
self = (CallCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = |
||||
grpc_composite_call_credentials_create( |
||||
creds1->c_creds, creds2->c_creds, NULL); |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString(PyExc_RuntimeError, "couldn't create composite credentials"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
CallCredentials *pygrpc_CallCredentials_compute_engine( |
||||
PyTypeObject *type, PyObject *ignored) { |
||||
CallCredentials *self = (CallCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = grpc_google_compute_engine_credentials_create(NULL); |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString(PyExc_RuntimeError, |
||||
"couldn't create compute engine credentials"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
/* TODO: Rename this credentials to something like service_account_jwt_access */ |
||||
CallCredentials *pygrpc_CallCredentials_jwt( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
CallCredentials *self; |
||||
const char *json_key; |
||||
double lifetime; |
||||
static char *keywords[] = {"json_key", "token_lifetime", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sd:jwt", keywords, |
||||
&json_key, &lifetime)) { |
||||
return NULL; |
||||
} |
||||
self = (CallCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = grpc_service_account_jwt_access_credentials_create( |
||||
json_key, pygrpc_cast_double_to_gpr_timespec(lifetime), NULL); |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString(PyExc_RuntimeError, "couldn't create JWT credentials"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
CallCredentials *pygrpc_CallCredentials_refresh_token( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
CallCredentials *self; |
||||
const char *json_refresh_token; |
||||
static char *keywords[] = {"json_refresh_token", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:refresh_token", keywords, |
||||
&json_refresh_token)) { |
||||
return NULL; |
||||
} |
||||
self = (CallCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = |
||||
grpc_google_refresh_token_credentials_create(json_refresh_token, NULL); |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString(PyExc_RuntimeError, |
||||
"couldn't create credentials from refresh token"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
CallCredentials *pygrpc_CallCredentials_iam( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
CallCredentials *self; |
||||
const char *authorization_token; |
||||
const char *authority_selector; |
||||
static char *keywords[] = {"authorization_token", "authority_selector", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss:iam", keywords, |
||||
&authorization_token, &authority_selector)) { |
||||
return NULL; |
||||
} |
||||
self = (CallCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = grpc_google_iam_credentials_create(authorization_token, |
||||
authority_selector, NULL); |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString(PyExc_RuntimeError, "couldn't create IAM credentials"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
@ -1,187 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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/_adapter/_c/types.h" |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/alloc.h> |
||||
|
||||
|
||||
PyMethodDef pygrpc_Channel_methods[] = { |
||||
{"create_call", (PyCFunction)pygrpc_Channel_create_call, METH_KEYWORDS, ""}, |
||||
{"check_connectivity_state", (PyCFunction)pygrpc_Channel_check_connectivity_state, METH_KEYWORDS, ""}, |
||||
{"watch_connectivity_state", (PyCFunction)pygrpc_Channel_watch_connectivity_state, METH_KEYWORDS, ""}, |
||||
{"target", (PyCFunction)pygrpc_Channel_target, METH_NOARGS, ""}, |
||||
{NULL} |
||||
}; |
||||
const char pygrpc_Channel_doc[] = "See grpc._adapter._types.Channel."; |
||||
PyTypeObject pygrpc_Channel_type = { |
||||
PyObject_HEAD_INIT(NULL) |
||||
0, /* ob_size */ |
||||
"Channel", /* tp_name */ |
||||
sizeof(Channel), /* tp_basicsize */ |
||||
0, /* tp_itemsize */ |
||||
(destructor)pygrpc_Channel_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 | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
||||
pygrpc_Channel_doc, /* tp_doc */ |
||||
0, /* tp_traverse */ |
||||
0, /* tp_clear */ |
||||
0, /* tp_richcompare */ |
||||
0, /* tp_weaklistoffset */ |
||||
0, /* tp_iter */ |
||||
0, /* tp_iternext */ |
||||
pygrpc_Channel_methods, /* 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 */ |
||||
0, /* tp_init */ |
||||
0, /* tp_alloc */ |
||||
(newfunc)pygrpc_Channel_new /* tp_new */ |
||||
}; |
||||
|
||||
Channel *pygrpc_Channel_new( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
Channel *self; |
||||
const char *target; |
||||
PyObject *py_args; |
||||
ChannelCredentials *creds = NULL; |
||||
grpc_channel_args c_args; |
||||
char *keywords[] = {"target", "args", "creds", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|O!:Channel", keywords, |
||||
&target, &py_args, &pygrpc_ChannelCredentials_type, &creds)) { |
||||
return NULL; |
||||
} |
||||
if (!pygrpc_produce_channel_args(py_args, &c_args)) { |
||||
return NULL; |
||||
} |
||||
self = (Channel *)type->tp_alloc(type, 0); |
||||
if (creds) { |
||||
self->c_chan = |
||||
grpc_secure_channel_create(creds->c_creds, target, &c_args, NULL); |
||||
} else { |
||||
self->c_chan = grpc_insecure_channel_create(target, &c_args, NULL); |
||||
} |
||||
pygrpc_discard_channel_args(c_args); |
||||
return self; |
||||
} |
||||
void pygrpc_Channel_dealloc(Channel *self) { |
||||
grpc_channel_destroy(self->c_chan); |
||||
self->ob_type->tp_free((PyObject *)self); |
||||
} |
||||
|
||||
Call *pygrpc_Channel_create_call( |
||||
Channel *self, PyObject *args, PyObject *kwargs) { |
||||
Call *call; |
||||
CompletionQueue *cq; |
||||
const char *method; |
||||
const char *host; |
||||
double deadline; |
||||
char *keywords[] = {"cq", "method", "host", "deadline", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!szd:create_call", keywords, |
||||
&pygrpc_CompletionQueue_type, &cq, &method, &host, &deadline)) { |
||||
return NULL; |
||||
} |
||||
call = pygrpc_Call_new_empty(cq); |
||||
call->c_call = grpc_channel_create_call( |
||||
self->c_chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq->c_cq, method, host, |
||||
pygrpc_cast_double_to_gpr_timespec(deadline), NULL); |
||||
return call; |
||||
} |
||||
|
||||
PyObject *pygrpc_Channel_check_connectivity_state( |
||||
Channel *self, PyObject *args, PyObject *kwargs) { |
||||
PyObject *py_try_to_connect; |
||||
int try_to_connect; |
||||
char *keywords[] = {"try_to_connect", NULL}; |
||||
grpc_connectivity_state state; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:connectivity_state", keywords, |
||||
&py_try_to_connect)) { |
||||
return NULL; |
||||
} |
||||
if (!PyBool_Check(py_try_to_connect)) { |
||||
Py_XDECREF(py_try_to_connect); |
||||
return NULL; |
||||
} |
||||
try_to_connect = Py_True == py_try_to_connect; |
||||
Py_DECREF(py_try_to_connect); |
||||
state = grpc_channel_check_connectivity_state(self->c_chan, try_to_connect); |
||||
return PyInt_FromLong(state); |
||||
} |
||||
|
||||
PyObject *pygrpc_Channel_watch_connectivity_state( |
||||
Channel *self, PyObject *args, PyObject *kwargs) { |
||||
PyObject *tag; |
||||
double deadline; |
||||
int last_observed_state; |
||||
CompletionQueue *completion_queue; |
||||
char *keywords[] = {"last_observed_state", "deadline", |
||||
"completion_queue", "tag", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords( |
||||
args, kwargs, "idO!O:watch_connectivity_state", keywords, |
||||
&last_observed_state, &deadline, &pygrpc_CompletionQueue_type, |
||||
&completion_queue, &tag)) { |
||||
return NULL; |
||||
} |
||||
grpc_channel_watch_connectivity_state( |
||||
self->c_chan, (grpc_connectivity_state)last_observed_state, |
||||
pygrpc_cast_double_to_gpr_timespec(deadline), completion_queue->c_cq, |
||||
pygrpc_produce_channel_state_change_tag(tag)); |
||||
Py_RETURN_NONE; |
||||
} |
||||
|
||||
PyObject *pygrpc_Channel_target(Channel *self) { |
||||
char *target = grpc_channel_get_target(self->c_chan); |
||||
PyObject *py_target = PyString_FromString(target); |
||||
gpr_free(target); |
||||
return py_target; |
||||
} |
@ -1,165 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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/_adapter/_c/types.h" |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
|
||||
|
||||
PyMethodDef pygrpc_ChannelCredentials_methods[] = { |
||||
{"google_default", (PyCFunction)pygrpc_ChannelCredentials_google_default, |
||||
METH_CLASS|METH_NOARGS, ""}, |
||||
{"ssl", (PyCFunction)pygrpc_ChannelCredentials_ssl, |
||||
METH_CLASS|METH_KEYWORDS, ""}, |
||||
{"composite", (PyCFunction)pygrpc_ChannelCredentials_composite, |
||||
METH_CLASS|METH_KEYWORDS, ""}, |
||||
{NULL} |
||||
}; |
||||
|
||||
const char pygrpc_ChannelCredentials_doc[] = ""; |
||||
PyTypeObject pygrpc_ChannelCredentials_type = { |
||||
PyObject_HEAD_INIT(NULL) |
||||
0, /* ob_size */ |
||||
"ChannelCredentials", /* tp_name */ |
||||
sizeof(ChannelCredentials), /* tp_basicsize */ |
||||
0, /* tp_itemsize */ |
||||
(destructor)pygrpc_ChannelCredentials_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 | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
||||
pygrpc_ChannelCredentials_doc, /* tp_doc */ |
||||
0, /* tp_traverse */ |
||||
0, /* tp_clear */ |
||||
0, /* tp_richcompare */ |
||||
0, /* tp_weaklistoffset */ |
||||
0, /* tp_iter */ |
||||
0, /* tp_iternext */ |
||||
pygrpc_ChannelCredentials_methods, /* 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 */ |
||||
0, /* tp_init */ |
||||
0, /* tp_alloc */ |
||||
0 /* tp_new */ |
||||
}; |
||||
|
||||
void pygrpc_ChannelCredentials_dealloc(ChannelCredentials *self) { |
||||
grpc_channel_credentials_release(self->c_creds); |
||||
self->ob_type->tp_free((PyObject *)self); |
||||
} |
||||
|
||||
ChannelCredentials *pygrpc_ChannelCredentials_google_default( |
||||
PyTypeObject *type, PyObject *ignored) { |
||||
ChannelCredentials *self = (ChannelCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = grpc_google_default_credentials_create(); |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString(PyExc_RuntimeError, |
||||
"couldn't create Google default credentials"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
ChannelCredentials *pygrpc_ChannelCredentials_ssl( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
ChannelCredentials *self; |
||||
const char *root_certs; |
||||
const char *private_key = NULL; |
||||
const char *cert_chain = NULL; |
||||
grpc_ssl_pem_key_cert_pair key_cert_pair; |
||||
static char *keywords[] = {"root_certs", "private_key", "cert_chain", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|zz:ssl", keywords, |
||||
&root_certs, &private_key, &cert_chain)) { |
||||
return NULL; |
||||
} |
||||
self = (ChannelCredentials *)type->tp_alloc(type, 0); |
||||
if (private_key && cert_chain) { |
||||
key_cert_pair.private_key = private_key; |
||||
key_cert_pair.cert_chain = cert_chain; |
||||
self->c_creds = |
||||
grpc_ssl_credentials_create(root_certs, &key_cert_pair, NULL); |
||||
} else { |
||||
self->c_creds = grpc_ssl_credentials_create(root_certs, NULL, NULL); |
||||
} |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString(PyExc_RuntimeError, "couldn't create ssl credentials"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
ChannelCredentials *pygrpc_ChannelCredentials_composite( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
ChannelCredentials *self; |
||||
ChannelCredentials *creds1; |
||||
CallCredentials *creds2; |
||||
static char *keywords[] = {"creds1", "creds2", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!:composite", keywords, |
||||
&pygrpc_ChannelCredentials_type, &creds1, |
||||
&pygrpc_CallCredentials_type, &creds2)) { |
||||
return NULL; |
||||
} |
||||
self = (ChannelCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = |
||||
grpc_composite_channel_credentials_create( |
||||
creds1->c_creds, creds2->c_creds, NULL); |
||||
if (!self->c_creds) { |
||||
Py_DECREF(self); |
||||
PyErr_SetString( |
||||
PyExc_RuntimeError, "couldn't create composite credentials"); |
||||
return NULL; |
||||
} |
||||
return self; |
||||
} |
||||
|
@ -1,124 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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/_adapter/_c/types.h" |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
|
||||
|
||||
PyMethodDef pygrpc_CompletionQueue_methods[] = { |
||||
{"next", (PyCFunction)pygrpc_CompletionQueue_next, METH_KEYWORDS, ""}, |
||||
{"shutdown", (PyCFunction)pygrpc_CompletionQueue_shutdown, METH_NOARGS, ""}, |
||||
{NULL} |
||||
}; |
||||
const char pygrpc_CompletionQueue_doc[] = |
||||
"See grpc._adapter._types.CompletionQueue."; |
||||
PyTypeObject pygrpc_CompletionQueue_type = { |
||||
PyObject_HEAD_INIT(NULL) |
||||
0, /* ob_size */ |
||||
"CompletionQueue", /* tp_name */ |
||||
sizeof(CompletionQueue), /* tp_basicsize */ |
||||
0, /* tp_itemsize */ |
||||
(destructor)pygrpc_CompletionQueue_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 | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
||||
pygrpc_CompletionQueue_doc, /* tp_doc */ |
||||
0, /* tp_traverse */ |
||||
0, /* tp_clear */ |
||||
0, /* tp_richcompare */ |
||||
0, /* tp_weaklistoffset */ |
||||
0, /* tp_iter */ |
||||
0, /* tp_iternext */ |
||||
pygrpc_CompletionQueue_methods, /* 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 */ |
||||
0, /* tp_init */ |
||||
0, /* tp_alloc */ |
||||
(newfunc)pygrpc_CompletionQueue_new /* tp_new */ |
||||
}; |
||||
|
||||
CompletionQueue *pygrpc_CompletionQueue_new( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
CompletionQueue *self = (CompletionQueue *)type->tp_alloc(type, 0); |
||||
self->c_cq = grpc_completion_queue_create(NULL); |
||||
return self; |
||||
} |
||||
|
||||
void pygrpc_CompletionQueue_dealloc(CompletionQueue *self) { |
||||
grpc_completion_queue_destroy(self->c_cq); |
||||
self->ob_type->tp_free((PyObject *)self); |
||||
} |
||||
|
||||
PyObject *pygrpc_CompletionQueue_next( |
||||
CompletionQueue *self, PyObject *args, PyObject *kwargs) { |
||||
double deadline; |
||||
grpc_event event; |
||||
PyObject *transliterated_event; |
||||
static char *keywords[] = {"deadline", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "d:next", keywords, |
||||
&deadline)) { |
||||
return NULL; |
||||
} |
||||
Py_BEGIN_ALLOW_THREADS; |
||||
event = grpc_completion_queue_next( |
||||
self->c_cq, pygrpc_cast_double_to_gpr_timespec(deadline), NULL); |
||||
Py_END_ALLOW_THREADS; |
||||
transliterated_event = pygrpc_consume_event(event); |
||||
return transliterated_event; |
||||
} |
||||
|
||||
PyObject *pygrpc_CompletionQueue_shutdown( |
||||
CompletionQueue *self, PyObject *ignored) { |
||||
grpc_completion_queue_shutdown(self->c_cq); |
||||
Py_RETURN_NONE; |
||||
} |
@ -1,196 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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/_adapter/_c/types.h" |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
|
||||
|
||||
PyMethodDef pygrpc_Server_methods[] = { |
||||
{"request_call", (PyCFunction)pygrpc_Server_request_call, |
||||
METH_KEYWORDS, ""}, |
||||
{"add_http2_port", (PyCFunction)pygrpc_Server_add_http2_port, |
||||
METH_KEYWORDS, ""}, |
||||
{"start", (PyCFunction)pygrpc_Server_start, METH_NOARGS, ""}, |
||||
{"shutdown", (PyCFunction)pygrpc_Server_shutdown, METH_KEYWORDS, ""}, |
||||
{"cancel_all_calls", (PyCFunction)pygrpc_Server_cancel_all_calls, |
||||
METH_NOARGS, ""}, |
||||
{NULL} |
||||
}; |
||||
const char pygrpc_Server_doc[] = "See grpc._adapter._types.Server."; |
||||
PyTypeObject pygrpc_Server_type = { |
||||
PyObject_HEAD_INIT(NULL) |
||||
0, /* ob_size */ |
||||
"Server", /* tp_name */ |
||||
sizeof(Server), /* tp_basicsize */ |
||||
0, /* tp_itemsize */ |
||||
(destructor)pygrpc_Server_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 | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
||||
pygrpc_Server_doc, /* tp_doc */ |
||||
0, /* tp_traverse */ |
||||
0, /* tp_clear */ |
||||
0, /* tp_richcompare */ |
||||
0, /* tp_weaklistoffset */ |
||||
0, /* tp_iter */ |
||||
0, /* tp_iternext */ |
||||
pygrpc_Server_methods, /* 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 */ |
||||
0, /* tp_init */ |
||||
0, /* tp_alloc */ |
||||
(newfunc)pygrpc_Server_new /* tp_new */ |
||||
}; |
||||
|
||||
Server *pygrpc_Server_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
Server *self; |
||||
CompletionQueue *cq; |
||||
PyObject *py_args; |
||||
grpc_channel_args c_args; |
||||
char *keywords[] = {"cq", "args", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O:Server", keywords, |
||||
&pygrpc_CompletionQueue_type, &cq, &py_args)) { |
||||
return NULL; |
||||
} |
||||
if (!pygrpc_produce_channel_args(py_args, &c_args)) { |
||||
return NULL; |
||||
} |
||||
self = (Server *)type->tp_alloc(type, 0); |
||||
self->c_serv = grpc_server_create(&c_args, NULL); |
||||
grpc_server_register_completion_queue(self->c_serv, cq->c_cq, NULL); |
||||
pygrpc_discard_channel_args(c_args); |
||||
self->cq = cq; |
||||
Py_INCREF(self->cq); |
||||
self->shutdown_called = 0; |
||||
return self; |
||||
} |
||||
|
||||
void pygrpc_Server_dealloc(Server *self) { |
||||
grpc_server_destroy(self->c_serv); |
||||
Py_XDECREF(self->cq); |
||||
self->ob_type->tp_free((PyObject *)self); |
||||
} |
||||
|
||||
PyObject *pygrpc_Server_request_call( |
||||
Server *self, PyObject *args, PyObject *kwargs) { |
||||
CompletionQueue *cq; |
||||
PyObject *user_tag; |
||||
pygrpc_tag *tag; |
||||
Call *empty_call; |
||||
grpc_call_error errcode; |
||||
static char *keywords[] = {"cq", "tag", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords( |
||||
args, kwargs, "O!O", keywords, |
||||
&pygrpc_CompletionQueue_type, &cq, &user_tag)) { |
||||
return NULL; |
||||
} |
||||
empty_call = pygrpc_Call_new_empty(cq); |
||||
tag = pygrpc_produce_request_tag(user_tag, empty_call); |
||||
errcode = grpc_server_request_call( |
||||
self->c_serv, &tag->call->c_call, &tag->request_call_details, |
||||
&tag->request_metadata, tag->call->cq->c_cq, self->cq->c_cq, tag); |
||||
Py_DECREF(empty_call); |
||||
return PyInt_FromLong(errcode); |
||||
} |
||||
|
||||
PyObject *pygrpc_Server_add_http2_port( |
||||
Server *self, PyObject *args, PyObject *kwargs) { |
||||
const char *addr; |
||||
ServerCredentials *creds = NULL; |
||||
int port; |
||||
static char *keywords[] = {"addr", "creds", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords( |
||||
args, kwargs, "s|O!:add_http2_port", keywords, |
||||
&addr, &pygrpc_ServerCredentials_type, &creds)) { |
||||
return NULL; |
||||
} |
||||
if (creds) { |
||||
port = grpc_server_add_secure_http2_port( |
||||
self->c_serv, addr, creds->c_creds); |
||||
} else { |
||||
port = grpc_server_add_insecure_http2_port(self->c_serv, addr); |
||||
} |
||||
return PyInt_FromLong(port); |
||||
|
||||
} |
||||
|
||||
PyObject *pygrpc_Server_start(Server *self, PyObject *ignored) { |
||||
grpc_server_start(self->c_serv); |
||||
self->shutdown_called = 0; |
||||
Py_RETURN_NONE; |
||||
} |
||||
|
||||
PyObject *pygrpc_Server_shutdown( |
||||
Server *self, PyObject *args, PyObject *kwargs) { |
||||
PyObject *user_tag; |
||||
pygrpc_tag *tag; |
||||
static char *keywords[] = {"tag", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", keywords, &user_tag)) { |
||||
return NULL; |
||||
} |
||||
tag = pygrpc_produce_server_shutdown_tag(user_tag); |
||||
grpc_server_shutdown_and_notify(self->c_serv, self->cq->c_cq, tag); |
||||
self->shutdown_called = 1; |
||||
Py_RETURN_NONE; |
||||
} |
||||
|
||||
PyObject *pygrpc_Server_cancel_all_calls(Server *self, PyObject *unused) { |
||||
if (!self->shutdown_called) { |
||||
PyErr_SetString( |
||||
PyExc_RuntimeError, |
||||
"shutdown must have been called prior to calling cancel_all_calls!"); |
||||
return NULL; |
||||
} |
||||
grpc_server_cancel_all_calls(self->c_serv); |
||||
Py_RETURN_NONE; |
||||
} |
@ -1,137 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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/_adapter/_c/types.h" |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
#include <grpc/support/alloc.h> |
||||
|
||||
|
||||
PyMethodDef pygrpc_ServerCredentials_methods[] = { |
||||
{"ssl", (PyCFunction)pygrpc_ServerCredentials_ssl, |
||||
METH_CLASS|METH_KEYWORDS, ""}, |
||||
{NULL} |
||||
}; |
||||
const char pygrpc_ServerCredentials_doc[] = ""; |
||||
PyTypeObject pygrpc_ServerCredentials_type = { |
||||
PyObject_HEAD_INIT(NULL) |
||||
0, /* ob_size */ |
||||
"ServerCredentials", /* tp_name */ |
||||
sizeof(ServerCredentials), /* tp_basicsize */ |
||||
0, /* tp_itemsize */ |
||||
(destructor)pygrpc_ServerCredentials_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 | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
||||
pygrpc_ServerCredentials_doc, /* tp_doc */ |
||||
0, /* tp_traverse */ |
||||
0, /* tp_clear */ |
||||
0, /* tp_richcompare */ |
||||
0, /* tp_weaklistoffset */ |
||||
0, /* tp_iter */ |
||||
0, /* tp_iternext */ |
||||
pygrpc_ServerCredentials_methods, /* 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 */ |
||||
0, /* tp_init */ |
||||
0, /* tp_alloc */ |
||||
0 /* tp_new */ |
||||
}; |
||||
|
||||
void pygrpc_ServerCredentials_dealloc(ServerCredentials *self) { |
||||
grpc_server_credentials_release(self->c_creds); |
||||
self->ob_type->tp_free((PyObject *)self); |
||||
} |
||||
|
||||
ServerCredentials *pygrpc_ServerCredentials_ssl( |
||||
PyTypeObject *type, PyObject *args, PyObject *kwargs) { |
||||
ServerCredentials *self; |
||||
const char *root_certs; |
||||
PyObject *py_key_cert_pairs; |
||||
grpc_ssl_pem_key_cert_pair *key_cert_pairs; |
||||
int force_client_auth; |
||||
size_t num_key_cert_pairs; |
||||
size_t i; |
||||
static char *keywords[] = { |
||||
"root_certs", "key_cert_pairs", "force_client_auth", NULL}; |
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "zOi:ssl", keywords, |
||||
&root_certs, &py_key_cert_pairs, &force_client_auth)) { |
||||
return NULL; |
||||
} |
||||
if (!PyList_Check(py_key_cert_pairs)) { |
||||
PyErr_SetString(PyExc_TypeError, "expected a list of 2-tuples of strings"); |
||||
return NULL; |
||||
} |
||||
num_key_cert_pairs = PyList_Size(py_key_cert_pairs); |
||||
key_cert_pairs = |
||||
gpr_malloc(sizeof(grpc_ssl_pem_key_cert_pair) * num_key_cert_pairs); |
||||
for (i = 0; i < num_key_cert_pairs; ++i) { |
||||
PyObject *item = PyList_GET_ITEM(py_key_cert_pairs, i); |
||||
const char *key; |
||||
const char *cert; |
||||
if (!PyArg_ParseTuple(item, "zz", &key, &cert)) { |
||||
gpr_free(key_cert_pairs); |
||||
PyErr_SetString(PyExc_TypeError, |
||||
"expected a list of 2-tuples of strings"); |
||||
return NULL; |
||||
} |
||||
key_cert_pairs[i].private_key = key; |
||||
key_cert_pairs[i].cert_chain = cert; |
||||
} |
||||
|
||||
self = (ServerCredentials *)type->tp_alloc(type, 0); |
||||
self->c_creds = grpc_ssl_server_credentials_create( |
||||
root_certs, key_cert_pairs, num_key_cert_pairs, force_client_auth, NULL); |
||||
gpr_free(key_cert_pairs); |
||||
return self; |
||||
} |
@ -1,524 +0,0 @@ |
||||
/*
|
||||
* |
||||
* 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 <math.h> |
||||
#include <string.h> |
||||
|
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/byte_buffer_reader.h> |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/slice.h> |
||||
#include <grpc/support/time.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "grpc/_adapter/_c/types.h" |
||||
|
||||
pygrpc_tag *pygrpc_produce_batch_tag( |
||||
PyObject *user_tag, Call *call, grpc_op *ops, size_t nops) { |
||||
pygrpc_tag *tag = gpr_malloc(sizeof(pygrpc_tag)); |
||||
tag->user_tag = user_tag; |
||||
Py_XINCREF(tag->user_tag); |
||||
tag->call = call; |
||||
Py_XINCREF(tag->call); |
||||
tag->ops = gpr_malloc(sizeof(grpc_op)*nops); |
||||
memcpy(tag->ops, ops, sizeof(grpc_op)*nops); |
||||
tag->nops = nops; |
||||
grpc_call_details_init(&tag->request_call_details); |
||||
grpc_metadata_array_init(&tag->request_metadata); |
||||
tag->is_new_call = 0; |
||||
return tag; |
||||
} |
||||
|
||||
pygrpc_tag *pygrpc_produce_request_tag(PyObject *user_tag, Call *empty_call) { |
||||
pygrpc_tag *tag = gpr_malloc(sizeof(pygrpc_tag)); |
||||
tag->user_tag = user_tag; |
||||
Py_XINCREF(tag->user_tag); |
||||
tag->call = empty_call; |
||||
Py_XINCREF(tag->call); |
||||
tag->ops = NULL; |
||||
tag->nops = 0; |
||||
grpc_call_details_init(&tag->request_call_details); |
||||
grpc_metadata_array_init(&tag->request_metadata); |
||||
tag->is_new_call = 1; |
||||
return tag; |
||||
} |
||||
|
||||
pygrpc_tag *pygrpc_produce_server_shutdown_tag(PyObject *user_tag) { |
||||
pygrpc_tag *tag = gpr_malloc(sizeof(pygrpc_tag)); |
||||
tag->user_tag = user_tag; |
||||
Py_XINCREF(tag->user_tag); |
||||
tag->call = NULL; |
||||
tag->ops = NULL; |
||||
tag->nops = 0; |
||||
grpc_call_details_init(&tag->request_call_details); |
||||
grpc_metadata_array_init(&tag->request_metadata); |
||||
tag->is_new_call = 0; |
||||
return tag; |
||||
} |
||||
|
||||
pygrpc_tag *pygrpc_produce_channel_state_change_tag(PyObject *user_tag) { |
||||
pygrpc_tag *tag = gpr_malloc(sizeof(pygrpc_tag)); |
||||
tag->user_tag = user_tag; |
||||
Py_XINCREF(tag->user_tag); |
||||
tag->call = NULL; |
||||
tag->ops = NULL; |
||||
tag->nops = 0; |
||||
grpc_call_details_init(&tag->request_call_details); |
||||
grpc_metadata_array_init(&tag->request_metadata); |
||||
tag->is_new_call = 0; |
||||
return tag; |
||||
} |
||||
|
||||
void pygrpc_discard_tag(pygrpc_tag *tag) { |
||||
if (!tag) { |
||||
return; |
||||
} |
||||
Py_XDECREF(tag->user_tag); |
||||
Py_XDECREF(tag->call); |
||||
gpr_free(tag->ops); |
||||
grpc_call_details_destroy(&tag->request_call_details); |
||||
grpc_metadata_array_destroy(&tag->request_metadata); |
||||
gpr_free(tag); |
||||
} |
||||
|
||||
PyObject *pygrpc_consume_event(grpc_event event) { |
||||
pygrpc_tag *tag; |
||||
PyObject *result; |
||||
if (event.type == GRPC_QUEUE_TIMEOUT) { |
||||
Py_RETURN_NONE; |
||||
} |
||||
tag = event.tag; |
||||
switch (event.type) { |
||||
case GRPC_QUEUE_SHUTDOWN: |
||||
result = Py_BuildValue("iOOOOO", GRPC_QUEUE_SHUTDOWN, |
||||
Py_None, Py_None, Py_None, Py_None, Py_True); |
||||
break; |
||||
case GRPC_OP_COMPLETE: |
||||
if (tag->is_new_call) { |
||||
result = Py_BuildValue( |
||||
"iOO(ssd)[(iNOOOO)]O", GRPC_OP_COMPLETE, tag->user_tag, tag->call, |
||||
tag->request_call_details.method, tag->request_call_details.host, |
||||
pygrpc_cast_gpr_timespec_to_double(tag->request_call_details.deadline), |
||||
GRPC_OP_RECV_INITIAL_METADATA, |
||||
pygrpc_cast_metadata_array_to_pyseq(tag->request_metadata), Py_None, |
||||
Py_None, Py_None, Py_None, |
||||
event.success ? Py_True : Py_False); |
||||
} else { |
||||
result = Py_BuildValue("iOOONO", GRPC_OP_COMPLETE, tag->user_tag, |
||||
tag->call ? (PyObject*)tag->call : Py_None, Py_None, |
||||
pygrpc_consume_ops(tag->ops, tag->nops), |
||||
event.success ? Py_True : Py_False); |
||||
} |
||||
break; |
||||
default: |
||||
PyErr_SetString(PyExc_ValueError, |
||||
"unknown completion type; could not translate event"); |
||||
return NULL; |
||||
} |
||||
pygrpc_discard_tag(tag); |
||||
return result; |
||||
} |
||||
|
||||
int pygrpc_produce_op(PyObject *op, grpc_op *result) { |
||||
static const int OP_TUPLE_SIZE = 6; |
||||
static const int STATUS_TUPLE_SIZE = 2; |
||||
static const int TYPE_INDEX = 0; |
||||
static const int INITIAL_METADATA_INDEX = 1; |
||||
static const int TRAILING_METADATA_INDEX = 2; |
||||
static const int MESSAGE_INDEX = 3; |
||||
static const int STATUS_INDEX = 4; |
||||
static const int STATUS_CODE_INDEX = 0; |
||||
static const int STATUS_DETAILS_INDEX = 1; |
||||
static const int WRITE_FLAGS_INDEX = 5; |
||||
int type; |
||||
Py_ssize_t message_size; |
||||
char *message; |
||||
char *status_details; |
||||
gpr_slice message_slice; |
||||
grpc_op c_op; |
||||
if (!PyTuple_Check(op)) { |
||||
PyErr_SetString(PyExc_TypeError, "expected tuple op"); |
||||
return 0; |
||||
} |
||||
if (PyTuple_Size(op) != OP_TUPLE_SIZE) { |
||||
char *buf; |
||||
gpr_asprintf(&buf, "expected tuple op of length %d", OP_TUPLE_SIZE); |
||||
PyErr_SetString(PyExc_ValueError, buf); |
||||
gpr_free(buf); |
||||
return 0; |
||||
} |
||||
type = PyInt_AsLong(PyTuple_GET_ITEM(op, TYPE_INDEX)); |
||||
if (PyErr_Occurred()) { |
||||
return 0; |
||||
} |
||||
c_op.op = type; |
||||
c_op.reserved = NULL; |
||||
c_op.flags = PyInt_AsLong(PyTuple_GET_ITEM(op, WRITE_FLAGS_INDEX)); |
||||
if (PyErr_Occurred()) { |
||||
return 0; |
||||
} |
||||
switch (type) { |
||||
case GRPC_OP_SEND_INITIAL_METADATA: |
||||
if (!pygrpc_cast_pyseq_to_send_metadata( |
||||
PyTuple_GetItem(op, INITIAL_METADATA_INDEX), |
||||
&c_op.data.send_initial_metadata.metadata, |
||||
&c_op.data.send_initial_metadata.count)) { |
||||
return 0; |
||||
} |
||||
break; |
||||
case GRPC_OP_SEND_MESSAGE: |
||||
PyString_AsStringAndSize( |
||||
PyTuple_GET_ITEM(op, MESSAGE_INDEX), &message, &message_size); |
||||
message_slice = gpr_slice_from_copied_buffer(message, message_size); |
||||
c_op.data.send_message = grpc_raw_byte_buffer_create(&message_slice, 1); |
||||
gpr_slice_unref(message_slice); |
||||
break; |
||||
case GRPC_OP_SEND_CLOSE_FROM_CLIENT: |
||||
/* Don't need to fill in any other fields. */ |
||||
break; |
||||
case GRPC_OP_SEND_STATUS_FROM_SERVER: |
||||
if (!pygrpc_cast_pyseq_to_send_metadata( |
||||
PyTuple_GetItem(op, TRAILING_METADATA_INDEX), |
||||
&c_op.data.send_status_from_server.trailing_metadata, |
||||
&c_op.data.send_status_from_server.trailing_metadata_count)) { |
||||
return 0; |
||||
} |
||||
if (!PyTuple_Check(PyTuple_GET_ITEM(op, STATUS_INDEX))) { |
||||
char *buf; |
||||
gpr_asprintf(&buf, "expected tuple status in op of length %d", |
||||
STATUS_TUPLE_SIZE); |
||||
PyErr_SetString(PyExc_ValueError, buf); |
||||
gpr_free(buf); |
||||
return 0; |
||||
} |
||||
c_op.data.send_status_from_server.status = PyInt_AsLong( |
||||
PyTuple_GET_ITEM(PyTuple_GET_ITEM(op, STATUS_INDEX), STATUS_CODE_INDEX)); |
||||
status_details = PyString_AsString( |
||||
PyTuple_GET_ITEM(PyTuple_GET_ITEM(op, STATUS_INDEX), STATUS_DETAILS_INDEX)); |
||||
if (PyErr_Occurred()) { |
||||
return 0; |
||||
} |
||||
c_op.data.send_status_from_server.status_details = |
||||
gpr_malloc(strlen(status_details) + 1); |
||||
strcpy((char *)c_op.data.send_status_from_server.status_details, |
||||
status_details); |
||||
break; |
||||
case GRPC_OP_RECV_INITIAL_METADATA: |
||||
c_op.data.recv_initial_metadata = gpr_malloc(sizeof(grpc_metadata_array)); |
||||
grpc_metadata_array_init(c_op.data.recv_initial_metadata); |
||||
break; |
||||
case GRPC_OP_RECV_MESSAGE: |
||||
c_op.data.recv_message = gpr_malloc(sizeof(grpc_byte_buffer *)); |
||||
break; |
||||
case GRPC_OP_RECV_STATUS_ON_CLIENT: |
||||
c_op.data.recv_status_on_client.trailing_metadata = |
||||
gpr_malloc(sizeof(grpc_metadata_array)); |
||||
grpc_metadata_array_init(c_op.data.recv_status_on_client.trailing_metadata); |
||||
c_op.data.recv_status_on_client.status = |
||||
gpr_malloc(sizeof(grpc_status_code *)); |
||||
c_op.data.recv_status_on_client.status_details = |
||||
gpr_malloc(sizeof(char *)); |
||||
*c_op.data.recv_status_on_client.status_details = NULL; |
||||
c_op.data.recv_status_on_client.status_details_capacity = |
||||
gpr_malloc(sizeof(size_t)); |
||||
*c_op.data.recv_status_on_client.status_details_capacity = 0; |
||||
break; |
||||
case GRPC_OP_RECV_CLOSE_ON_SERVER: |
||||
c_op.data.recv_close_on_server.cancelled = gpr_malloc(sizeof(int)); |
||||
break; |
||||
default: |
||||
return 0; |
||||
} |
||||
*result = c_op; |
||||
return 1; |
||||
} |
||||
|
||||
void pygrpc_discard_op(grpc_op op) { |
||||
size_t i; |
||||
switch(op.op) { |
||||
case GRPC_OP_SEND_INITIAL_METADATA: |
||||
/* Whenever we produce send-metadata, we allocate new strings (to handle
|
||||
arbitrary sequence input as opposed to just lists or just tuples). We |
||||
thus must free those elements. */ |
||||
for (i = 0; i < op.data.send_initial_metadata.count; ++i) { |
||||
gpr_free((void *)op.data.send_initial_metadata.metadata[i].key); |
||||
gpr_free((void *)op.data.send_initial_metadata.metadata[i].value); |
||||
} |
||||
gpr_free(op.data.send_initial_metadata.metadata); |
||||
break; |
||||
case GRPC_OP_SEND_MESSAGE: |
||||
grpc_byte_buffer_destroy(op.data.send_message); |
||||
break; |
||||
case GRPC_OP_SEND_CLOSE_FROM_CLIENT: |
||||
/* Don't need to free any fields. */ |
||||
break; |
||||
case GRPC_OP_SEND_STATUS_FROM_SERVER: |
||||
/* Whenever we produce send-metadata, we allocate new strings (to handle
|
||||
arbitrary sequence input as opposed to just lists or just tuples). We |
||||
thus must free those elements. */ |
||||
for (i = 0; i < op.data.send_status_from_server.trailing_metadata_count; |
||||
++i) { |
||||
gpr_free( |
||||
(void *)op.data.send_status_from_server.trailing_metadata[i].key); |
||||
gpr_free( |
||||
(void *)op.data.send_status_from_server.trailing_metadata[i].value); |
||||
} |
||||
gpr_free(op.data.send_status_from_server.trailing_metadata); |
||||
gpr_free((char *)op.data.send_status_from_server.status_details); |
||||
break; |
||||
case GRPC_OP_RECV_INITIAL_METADATA: |
||||
grpc_metadata_array_destroy(op.data.recv_initial_metadata); |
||||
gpr_free(op.data.recv_initial_metadata); |
||||
break; |
||||
case GRPC_OP_RECV_MESSAGE: |
||||
grpc_byte_buffer_destroy(*op.data.recv_message); |
||||
gpr_free(op.data.recv_message); |
||||
break; |
||||
case GRPC_OP_RECV_STATUS_ON_CLIENT: |
||||
grpc_metadata_array_destroy(op.data.recv_status_on_client.trailing_metadata); |
||||
gpr_free(op.data.recv_status_on_client.trailing_metadata); |
||||
gpr_free(op.data.recv_status_on_client.status); |
||||
gpr_free(*op.data.recv_status_on_client.status_details); |
||||
gpr_free(op.data.recv_status_on_client.status_details); |
||||
gpr_free(op.data.recv_status_on_client.status_details_capacity); |
||||
break; |
||||
case GRPC_OP_RECV_CLOSE_ON_SERVER: |
||||
gpr_free(op.data.recv_close_on_server.cancelled); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
PyObject *pygrpc_consume_ops(grpc_op *op, size_t nops) { |
||||
static const int TYPE_INDEX = 0; |
||||
static const int INITIAL_METADATA_INDEX = 1; |
||||
static const int TRAILING_METADATA_INDEX = 2; |
||||
static const int MESSAGE_INDEX = 3; |
||||
static const int STATUS_INDEX = 4; |
||||
static const int CANCELLED_INDEX = 5; |
||||
static const int OPRESULT_LENGTH = 6; |
||||
PyObject *list; |
||||
size_t i; |
||||
size_t j; |
||||
char *bytes; |
||||
size_t bytes_size; |
||||
PyObject *results = PyList_New(nops); |
||||
if (!results) { |
||||
return NULL; |
||||
} |
||||
for (i = 0; i < nops; ++i) { |
||||
PyObject *result = PyTuple_Pack(OPRESULT_LENGTH, Py_None, Py_None, Py_None, |
||||
Py_None, Py_None, Py_None); |
||||
PyTuple_SetItem(result, TYPE_INDEX, PyInt_FromLong(op[i].op)); |
||||
switch(op[i].op) { |
||||
case GRPC_OP_RECV_INITIAL_METADATA: |
||||
PyTuple_SetItem(result, INITIAL_METADATA_INDEX, |
||||
list=PyList_New(op[i].data.recv_initial_metadata->count)); |
||||
for (j = 0; j < op[i].data.recv_initial_metadata->count; ++j) { |
||||
grpc_metadata md = op[i].data.recv_initial_metadata->metadata[j]; |
||||
PyList_SetItem(list, j, Py_BuildValue("ss#", md.key, md.value, |
||||
(Py_ssize_t)md.value_length)); |
||||
} |
||||
break; |
||||
case GRPC_OP_RECV_MESSAGE: |
||||
if (*op[i].data.recv_message) { |
||||
pygrpc_byte_buffer_to_bytes( |
||||
*op[i].data.recv_message, &bytes, &bytes_size); |
||||
PyTuple_SetItem(result, MESSAGE_INDEX, |
||||
PyString_FromStringAndSize(bytes, bytes_size)); |
||||
gpr_free(bytes); |
||||
} else { |
||||
PyTuple_SetItem(result, MESSAGE_INDEX, Py_BuildValue("")); |
||||
} |
||||
break; |
||||
case GRPC_OP_RECV_STATUS_ON_CLIENT: |
||||
PyTuple_SetItem( |
||||
result, TRAILING_METADATA_INDEX, |
||||
list = PyList_New(op[i].data.recv_status_on_client.trailing_metadata->count)); |
||||
for (j = 0; j < op[i].data.recv_status_on_client.trailing_metadata->count; ++j) { |
||||
grpc_metadata md = |
||||
op[i].data.recv_status_on_client.trailing_metadata->metadata[j]; |
||||
PyList_SetItem(list, j, Py_BuildValue("ss#", md.key, md.value, |
||||
(Py_ssize_t)md.value_length)); |
||||
} |
||||
PyTuple_SetItem( |
||||
result, STATUS_INDEX, Py_BuildValue( |
||||
"is", *op[i].data.recv_status_on_client.status, |
||||
*op[i].data.recv_status_on_client.status_details)); |
||||
break; |
||||
case GRPC_OP_RECV_CLOSE_ON_SERVER: |
||||
PyTuple_SetItem( |
||||
result, CANCELLED_INDEX, |
||||
PyBool_FromLong(*op[i].data.recv_close_on_server.cancelled)); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
pygrpc_discard_op(op[i]); |
||||
PyList_SetItem(results, i, result); |
||||
} |
||||
return results; |
||||
} |
||||
|
||||
double pygrpc_cast_gpr_timespec_to_double(gpr_timespec timespec) { |
||||
timespec = gpr_convert_clock_type(timespec, GPR_CLOCK_REALTIME); |
||||
return timespec.tv_sec + 1e-9*timespec.tv_nsec; |
||||
} |
||||
|
||||
/* Because C89 doesn't have a way to check for infinity... */ |
||||
static int pygrpc_isinf(double x) { |
||||
return x * 0 != 0; |
||||
} |
||||
|
||||
gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds) { |
||||
gpr_timespec result; |
||||
if (pygrpc_isinf(seconds)) { |
||||
result = seconds > 0.0 ? gpr_inf_future(GPR_CLOCK_REALTIME) |
||||
: gpr_inf_past(GPR_CLOCK_REALTIME); |
||||
} else { |
||||
result.tv_sec = (time_t)seconds; |
||||
result.tv_nsec = ((seconds - result.tv_sec) * 1e9); |
||||
result.clock_type = GPR_CLOCK_REALTIME; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
int pygrpc_produce_channel_args(PyObject *py_args, grpc_channel_args *c_args) { |
||||
size_t num_args = PyList_Size(py_args); |
||||
size_t i; |
||||
grpc_channel_args args; |
||||
args.num_args = num_args; |
||||
args.args = gpr_malloc(sizeof(grpc_arg) * num_args); |
||||
for (i = 0; i < args.num_args; ++i) { |
||||
char *key; |
||||
PyObject *value; |
||||
if (!PyArg_ParseTuple(PyList_GetItem(py_args, i), "zO", &key, &value)) { |
||||
gpr_free(args.args); |
||||
args.num_args = 0; |
||||
args.args = NULL; |
||||
PyErr_SetString(PyExc_TypeError, |
||||
"expected a list of 2-tuple of str and str|int|None"); |
||||
return 0; |
||||
} |
||||
args.args[i].key = key; |
||||
if (PyInt_Check(value)) { |
||||
args.args[i].type = GRPC_ARG_INTEGER; |
||||
args.args[i].value.integer = PyInt_AsLong(value); |
||||
} else if (PyString_Check(value)) { |
||||
args.args[i].type = GRPC_ARG_STRING; |
||||
args.args[i].value.string = PyString_AsString(value); |
||||
} else if (value == Py_None) { |
||||
--args.num_args; |
||||
--i; |
||||
continue; |
||||
} else { |
||||
gpr_free(args.args); |
||||
args.num_args = 0; |
||||
args.args = NULL; |
||||
PyErr_SetString(PyExc_TypeError, |
||||
"expected a list of 2-tuple of str and str|int|None"); |
||||
return 0; |
||||
} |
||||
} |
||||
*c_args = args; |
||||
return 1; |
||||
} |
||||
|
||||
void pygrpc_discard_channel_args(grpc_channel_args args) { |
||||
gpr_free(args.args); |
||||
} |
||||
|
||||
int pygrpc_cast_pyseq_to_send_metadata( |
||||
PyObject *pyseq, grpc_metadata **metadata, size_t *count) { |
||||
size_t i; |
||||
Py_ssize_t value_length; |
||||
char *key; |
||||
char *value; |
||||
if (!PySequence_Check(pyseq)) { |
||||
return 0; |
||||
} |
||||
*count = PySequence_Size(pyseq); |
||||
*metadata = gpr_malloc(sizeof(grpc_metadata) * *count); |
||||
for (i = 0; i < *count; ++i) { |
||||
PyObject *item = PySequence_GetItem(pyseq, i); |
||||
if (!PyArg_ParseTuple(item, "ss#", &key, &value, &value_length)) { |
||||
Py_DECREF(item); |
||||
gpr_free(*metadata); |
||||
*count = 0; |
||||
*metadata = NULL; |
||||
return 0; |
||||
} else { |
||||
(*metadata)[i].key = gpr_strdup(key); |
||||
(*metadata)[i].value = gpr_malloc(value_length); |
||||
memcpy((void *)(*metadata)[i].value, value, value_length); |
||||
Py_DECREF(item); |
||||
} |
||||
(*metadata)[i].value_length = value_length; |
||||
} |
||||
return 1; |
||||
} |
||||
|
||||
PyObject *pygrpc_cast_metadata_array_to_pyseq(grpc_metadata_array metadata) { |
||||
PyObject *result = PyTuple_New(metadata.count); |
||||
size_t i; |
||||
for (i = 0; i < metadata.count; ++i) { |
||||
PyTuple_SetItem( |
||||
result, i, Py_BuildValue( |
||||
"ss#", metadata.metadata[i].key, metadata.metadata[i].value, |
||||
(Py_ssize_t)metadata.metadata[i].value_length)); |
||||
if (PyErr_Occurred()) { |
||||
Py_DECREF(result); |
||||
return NULL; |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
void pygrpc_byte_buffer_to_bytes( |
||||
grpc_byte_buffer *buffer, char **result, size_t *result_size) { |
||||
grpc_byte_buffer_reader reader; |
||||
gpr_slice slice; |
||||
char *read_result = NULL; |
||||
size_t size = 0; |
||||
grpc_byte_buffer_reader_init(&reader, buffer); |
||||
while (grpc_byte_buffer_reader_next(&reader, &slice)) { |
||||
read_result = gpr_realloc(read_result, size + GPR_SLICE_LENGTH(slice)); |
||||
memcpy(read_result + size, GPR_SLICE_START_PTR(slice), |
||||
GPR_SLICE_LENGTH(slice)); |
||||
size = size + GPR_SLICE_LENGTH(slice); |
||||
gpr_slice_unref(slice); |
||||
} |
||||
*result_size = size; |
||||
*result = read_result; |
||||
} |
@ -1,187 +0,0 @@ |
||||
# 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. |
||||
|
||||
# Fork of grpc._adapter._low_test; the grpc._cython.types adapter in |
||||
# grpc._cython.low should transparently support the semantics expected of |
||||
# grpc._adapter._low. |
||||
|
||||
import time |
||||
import unittest |
||||
|
||||
from grpc._adapter import _types |
||||
from grpc._cython import adapter_low as _low |
||||
|
||||
|
||||
class InsecureServerInsecureClient(unittest.TestCase): |
||||
|
||||
def setUp(self): |
||||
self.server_completion_queue = _low.CompletionQueue() |
||||
self.server = _low.Server(self.server_completion_queue, []) |
||||
self.port = self.server.add_http2_port('[::]:0') |
||||
self.client_completion_queue = _low.CompletionQueue() |
||||
self.client_channel = _low.Channel('localhost:%d'%self.port, []) |
||||
|
||||
self.server.start() |
||||
|
||||
def tearDown(self): |
||||
self.server.shutdown() |
||||
del self.client_channel |
||||
|
||||
self.client_completion_queue.shutdown() |
||||
while (self.client_completion_queue.next().type != |
||||
_types.EventType.QUEUE_SHUTDOWN): |
||||
pass |
||||
self.server_completion_queue.shutdown() |
||||
while (self.server_completion_queue.next().type != |
||||
_types.EventType.QUEUE_SHUTDOWN): |
||||
pass |
||||
|
||||
del self.client_completion_queue |
||||
del self.server_completion_queue |
||||
del self.server |
||||
|
||||
@unittest.skip('TODO(atash): implement grpc._cython.adapter_low') |
||||
def testEcho(self): |
||||
DEADLINE = time.time()+5 |
||||
DEADLINE_TOLERANCE = 0.25 |
||||
CLIENT_METADATA_ASCII_KEY = 'key' |
||||
CLIENT_METADATA_ASCII_VALUE = 'val' |
||||
CLIENT_METADATA_BIN_KEY = 'key-bin' |
||||
CLIENT_METADATA_BIN_VALUE = b'\0'*1000 |
||||
SERVER_INITIAL_METADATA_KEY = 'init_me_me_me' |
||||
SERVER_INITIAL_METADATA_VALUE = 'whodawha?' |
||||
SERVER_TRAILING_METADATA_KEY = 'california_is_in_a_drought' |
||||
SERVER_TRAILING_METADATA_VALUE = 'zomg it is' |
||||
SERVER_STATUS_CODE = _types.StatusCode.OK |
||||
SERVER_STATUS_DETAILS = 'our work is never over' |
||||
REQUEST = 'in death a member of project mayhem has a name' |
||||
RESPONSE = 'his name is robert paulson' |
||||
METHOD = 'twinkies' |
||||
HOST = 'hostess' |
||||
server_request_tag = object() |
||||
request_call_result = self.server.request_call(self.server_completion_queue, |
||||
server_request_tag) |
||||
|
||||
self.assertEqual(_types.CallError.OK, request_call_result) |
||||
|
||||
client_call_tag = object() |
||||
client_call = self.client_channel.create_call(self.client_completion_queue, |
||||
METHOD, HOST, DEADLINE) |
||||
client_initial_metadata = [ |
||||
(CLIENT_METADATA_ASCII_KEY, CLIENT_METADATA_ASCII_VALUE), |
||||
(CLIENT_METADATA_BIN_KEY, CLIENT_METADATA_BIN_VALUE)] |
||||
client_start_batch_result = client_call.start_batch([ |
||||
_types.OpArgs.send_initial_metadata(client_initial_metadata), |
||||
_types.OpArgs.send_message(REQUEST), |
||||
_types.OpArgs.send_close_from_client(), |
||||
_types.OpArgs.recv_initial_metadata(), |
||||
_types.OpArgs.recv_message(), |
||||
_types.OpArgs.recv_status_on_client() |
||||
], client_call_tag) |
||||
self.assertEqual(_types.CallError.OK, client_start_batch_result) |
||||
|
||||
request_event = self.server_completion_queue.next(DEADLINE) |
||||
self.assertEqual(_types.EventType.OP_COMPLETE, request_event.type) |
||||
self.assertIsInstance(request_event.call, _low.Call) |
||||
self.assertIs(server_request_tag, request_event.tag) |
||||
self.assertEqual(1, len(request_event.results)) |
||||
self.assertEqual(dict(client_initial_metadata), |
||||
dict(request_event.results[0].initial_metadata)) |
||||
self.assertEqual(METHOD, request_event.call_details.method) |
||||
self.assertEqual(HOST, request_event.call_details.host) |
||||
self.assertLess(abs(DEADLINE - request_event.call_details.deadline), |
||||
DEADLINE_TOLERANCE) |
||||
|
||||
server_call_tag = object() |
||||
server_call = request_event.call |
||||
server_initial_metadata = [ |
||||
(SERVER_INITIAL_METADATA_KEY, SERVER_INITIAL_METADATA_VALUE)] |
||||
server_trailing_metadata = [ |
||||
(SERVER_TRAILING_METADATA_KEY, SERVER_TRAILING_METADATA_VALUE)] |
||||
server_start_batch_result = server_call.start_batch([ |
||||
_types.OpArgs.send_initial_metadata(server_initial_metadata), |
||||
_types.OpArgs.recv_message(), |
||||
_types.OpArgs.send_message(RESPONSE), |
||||
_types.OpArgs.recv_close_on_server(), |
||||
_types.OpArgs.send_status_from_server( |
||||
server_trailing_metadata, SERVER_STATUS_CODE, SERVER_STATUS_DETAILS) |
||||
], server_call_tag) |
||||
self.assertEqual(_types.CallError.OK, server_start_batch_result) |
||||
|
||||
client_event = self.client_completion_queue.next(DEADLINE) |
||||
server_event = self.server_completion_queue.next(DEADLINE) |
||||
|
||||
self.assertEqual(6, len(client_event.results)) |
||||
found_client_op_types = set() |
||||
for client_result in client_event.results: |
||||
# we expect each op type to be unique |
||||
self.assertNotIn(client_result.type, found_client_op_types) |
||||
found_client_op_types.add(client_result.type) |
||||
if client_result.type == _types.OpType.RECV_INITIAL_METADATA: |
||||
self.assertEqual(dict(server_initial_metadata), |
||||
dict(client_result.initial_metadata)) |
||||
elif client_result.type == _types.OpType.RECV_MESSAGE: |
||||
self.assertEqual(RESPONSE, client_result.message) |
||||
elif client_result.type == _types.OpType.RECV_STATUS_ON_CLIENT: |
||||
self.assertEqual(dict(server_trailing_metadata), |
||||
dict(client_result.trailing_metadata)) |
||||
self.assertEqual(SERVER_STATUS_DETAILS, client_result.status.details) |
||||
self.assertEqual(SERVER_STATUS_CODE, client_result.status.code) |
||||
self.assertEqual(set([ |
||||
_types.OpType.SEND_INITIAL_METADATA, |
||||
_types.OpType.SEND_MESSAGE, |
||||
_types.OpType.SEND_CLOSE_FROM_CLIENT, |
||||
_types.OpType.RECV_INITIAL_METADATA, |
||||
_types.OpType.RECV_MESSAGE, |
||||
_types.OpType.RECV_STATUS_ON_CLIENT |
||||
]), found_client_op_types) |
||||
|
||||
self.assertEqual(5, len(server_event.results)) |
||||
found_server_op_types = set() |
||||
for server_result in server_event.results: |
||||
self.assertNotIn(client_result.type, found_server_op_types) |
||||
found_server_op_types.add(server_result.type) |
||||
if server_result.type == _types.OpType.RECV_MESSAGE: |
||||
self.assertEqual(REQUEST, server_result.message) |
||||
elif server_result.type == _types.OpType.RECV_CLOSE_ON_SERVER: |
||||
self.assertFalse(server_result.cancelled) |
||||
self.assertEqual(set([ |
||||
_types.OpType.SEND_INITIAL_METADATA, |
||||
_types.OpType.RECV_MESSAGE, |
||||
_types.OpType.SEND_MESSAGE, |
||||
_types.OpType.RECV_CLOSE_ON_SERVER, |
||||
_types.OpType.SEND_STATUS_FROM_SERVER |
||||
]), found_server_op_types) |
||||
|
||||
del client_call |
||||
del server_call |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
unittest.main(verbosity=2) |
@ -1,80 +0,0 @@ |
||||
|
||||
// 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 math; |
||||
|
||||
message DivArgs { |
||||
int64 dividend = 1; |
||||
int64 divisor = 2; |
||||
} |
||||
|
||||
message DivReply { |
||||
int64 quotient = 1; |
||||
int64 remainder = 2; |
||||
} |
||||
|
||||
message FibArgs { |
||||
int64 limit = 1; |
||||
} |
||||
|
||||
message Num { |
||||
int64 num = 1; |
||||
} |
||||
|
||||
message FibReply { |
||||
int64 count = 1; |
||||
} |
||||
|
||||
service Math { |
||||
// Div divides args.dividend by args.divisor and returns the quotient and |
||||
// remainder. |
||||
rpc Div (DivArgs) returns (DivReply) { |
||||
} |
||||
|
||||
// DivMany accepts an arbitrary number of division args from the client stream |
||||
// and sends back the results in the reply stream. The stream continues until |
||||
// the client closes its end; the server does the same after sending all the |
||||
// replies. The stream ends immediately if either end aborts. |
||||
rpc DivMany (stream DivArgs) returns (stream DivReply) { |
||||
} |
||||
|
||||
// Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib |
||||
// generates up to limit numbers; otherwise it continues until the call is |
||||
// canceled. Unlike Fib above, Fib has no final FibReply. |
||||
rpc Fib (FibArgs) returns (stream Num) { |
||||
} |
||||
|
||||
// Sum sums a stream of numbers, returning the final result once the stream |
||||
// is closed. |
||||
rpc Sum (stream Num) returns (Num) { |
||||
} |
||||
} |
@ -0,0 +1,187 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<Import Project="..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.props" Condition="Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\1.0.204.1.props')" /> |
||||
<ItemGroup Label="ProjectConfigurations"> |
||||
<ProjectConfiguration Include="Debug|Win32"> |
||||
<Configuration>Debug</Configuration> |
||||
<Platform>Win32</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Debug|x64"> |
||||
<Configuration>Debug</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Release|Win32"> |
||||
<Configuration>Release</Configuration> |
||||
<Platform>Win32</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Release|x64"> |
||||
<Configuration>Release</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
</ItemGroup> |
||||
<PropertyGroup Label="Globals"> |
||||
<ProjectGuid>{9E0A2239-20D5-DB2D-CA0D-69F24E3416E7}</ProjectGuid> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0'" Label="Configuration"> |
||||
<PlatformToolset>v100</PlatformToolset> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '11.0'" Label="Configuration"> |
||||
<PlatformToolset>v110</PlatformToolset> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '12.0'" Label="Configuration"> |
||||
<PlatformToolset>v120</PlatformToolset> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>true</UseDebugLibraries> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>false</UseDebugLibraries> |
||||
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||
<ImportGroup Label="ExtensionSettings"> |
||||
</ImportGroup> |
||||
<ImportGroup Label="PropertySheets"> |
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
<Import Project="..\..\..\..\vsprojects\global.props" /> |
||||
<Import Project="..\..\..\..\vsprojects\openssl.props" /> |
||||
<Import Project="..\..\..\..\vsprojects\winsock.props" /> |
||||
<Import Project="..\..\..\..\vsprojects\zlib.props" /> |
||||
</ImportGroup> |
||||
<PropertyGroup Label="UserMacros" /> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'"> |
||||
<TargetName>unknown_frame_bad_client_test</TargetName> |
||||
<Linkage-grpc_dependencies_zlib>static</Linkage-grpc_dependencies_zlib> |
||||
<Configuration-grpc_dependencies_zlib>Debug</Configuration-grpc_dependencies_zlib> |
||||
<Configuration-grpc_dependencies_openssl>Debug</Configuration-grpc_dependencies_openssl> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'"> |
||||
<TargetName>unknown_frame_bad_client_test</TargetName> |
||||
<Linkage-grpc_dependencies_zlib>static</Linkage-grpc_dependencies_zlib> |
||||
<Configuration-grpc_dependencies_zlib>Debug</Configuration-grpc_dependencies_zlib> |
||||
<Configuration-grpc_dependencies_openssl>Debug</Configuration-grpc_dependencies_openssl> |
||||
</PropertyGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
<ClCompile> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<Optimization>Disabled</Optimization> |
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
<ClCompile> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<Optimization>Disabled</Optimization> |
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<Optimization>MaxSpeed</Optimization> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<Optimization>MaxSpeed</Optimization> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemGroup> |
||||
<ClCompile Include="..\..\..\..\test\core\bad_client\tests\unknown_frame.c"> |
||||
</ClCompile> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\..\..\vsprojects\vcxproj\test\bad_client_test\bad_client_test.vcxproj"> |
||||
<Project>{BA67B418-B699-E41A-9CC4-0279C49481A5}</Project> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\vsprojects\vcxproj\.\grpc_test_util_unsecure\grpc_test_util_unsecure.vcxproj"> |
||||
<Project>{0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF}</Project> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\vsprojects\vcxproj\.\grpc_unsecure\grpc_unsecure.vcxproj"> |
||||
<Project>{46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}</Project> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\vsprojects\vcxproj\.\gpr_test_util\gpr_test_util.vcxproj"> |
||||
<Project>{EAB0A629-17A9-44DB-B5FF-E91A721FE037}</Project> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\vsprojects\vcxproj\.\gpr\gpr.vcxproj"> |
||||
<Project>{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}</Project> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="packages.config" /> |
||||
</ItemGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
<ImportGroup Label="ExtensionTargets"> |
||||
<Import Project="..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies.zlib.redist.targets" Condition="Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies\grpc.dependencies.zlib.targets')" /> |
||||
<Import Project="..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies.zlib.targets" Condition="Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies\grpc.dependencies.zlib.targets')" /> |
||||
<Import Project="..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies.openssl.redist.targets" Condition="Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies\grpc.dependencies.openssl.targets')" /> |
||||
<Import Project="..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.targets" Condition="Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies\grpc.dependencies.openssl.targets')" /> |
||||
</ImportGroup> |
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
||||
<PropertyGroup> |
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> |
||||
</PropertyGroup> |
||||
<Error Condition="!Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies.zlib.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies.zlib.redist.targets')" /> |
||||
<Error Condition="!Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies.zlib.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies.zlib.targets')" /> |
||||
<Error Condition="!Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies.openssl.redist.targets')" /> |
||||
<Error Condition="!Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.props')" /> |
||||
<Error Condition="!Exists('..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.targets')" /> |
||||
</Target> |
||||
</Project> |
||||
|
@ -0,0 +1,24 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup> |
||||
<ClCompile Include="..\..\..\..\test\core\bad_client\tests\unknown_frame.c"> |
||||
<Filter>test\core\bad_client\tests</Filter> |
||||
</ClCompile> |
||||
</ItemGroup> |
||||
|
||||
<ItemGroup> |
||||
<Filter Include="test"> |
||||
<UniqueIdentifier>{77ca54f4-deb2-3a34-5548-0a2bc7cbacc1}</UniqueIdentifier> |
||||
</Filter> |
||||
<Filter Include="test\core"> |
||||
<UniqueIdentifier>{2e30ac00-932d-ab0d-fabf-e0ea035aae46}</UniqueIdentifier> |
||||
</Filter> |
||||
<Filter Include="test\core\bad_client"> |
||||
<UniqueIdentifier>{527abde4-b314-c50f-b007-dd3fdb2445ba}</UniqueIdentifier> |
||||
</Filter> |
||||
<Filter Include="test\core\bad_client\tests"> |
||||
<UniqueIdentifier>{691de782-c331-3836-ac26-43873334f0c0}</UniqueIdentifier> |
||||
</Filter> |
||||
</ItemGroup> |
||||
</Project> |
||||
|
Loading…
Reference in new issue