mirror of https://github.com/grpc/grpc.git
commit
d88e1d8f4e
255 changed files with 20377 additions and 2300 deletions
@ -1,289 +0,0 @@ |
||||
#gRPC Authentication support |
||||
|
||||
gRPC is designed to plug-in a number of authentication mechanisms. This document |
||||
provides a quick overview of the various auth mechanisms supported, discusses |
||||
the API with some examples, and concludes with a discussion of extensibility. |
||||
More documentation and examples are coming soon! |
||||
|
||||
## Supported auth mechanisms |
||||
|
||||
###SSL/TLS |
||||
gRPC has SSL/TLS integration and promotes the use of SSL/TLS to authenticate the |
||||
server, and encrypt all the data exchanged between the client and the server. |
||||
Optional mechanisms are available for clients to provide certificates to |
||||
accomplish mutual authentication. |
||||
|
||||
###OAuth 2.0 |
||||
gRPC provides a generic mechanism (described below) to attach metadata to |
||||
requests and responses. This mechanism can be used to attach OAuth 2.0 Access |
||||
Tokens to RPCs being made at a client. Additional support for acquiring Access |
||||
Tokens while accessing Google APIs through gRPC is provided for certain auth |
||||
flows, demonstrated through code examples below. |
||||
|
||||
## API |
||||
To reduce complexity and minimize API clutter, gRPC works with a unified concept |
||||
of a Credentials object. Users construct gRPC credentials using corresponding |
||||
bootstrap credentials (e.g., SSL client certs or Service Account Keys), and use |
||||
the credentials while creating a gRPC channel to any server. Depending on the |
||||
type of credential supplied, the channel uses the credentials during the initial |
||||
SSL/TLS handshake with the server, or uses the credential to generate and |
||||
attach Access Tokens to each request being made on the channel. |
||||
|
||||
###SSL/TLS for server authentication and encryption |
||||
This is the simplest authentication scenario, where a client just wants to |
||||
authenticate the server and encrypt all data. |
||||
|
||||
```cpp |
||||
SslCredentialsOptions ssl_opts; // Options to override SSL params, empty by default |
||||
// Create the credentials object by providing service account key in constructor |
||||
std::shared_ptr<ChannelCredentials> creds = SslCredentials(ssl_opts); |
||||
// Create a channel using the credentials created in the previous step |
||||
std::shared_ptr<Channel> channel = CreateChannel(server_name, creds); |
||||
// Create a stub on the channel |
||||
std::unique_ptr<Greeter::Stub> stub(Greeter::NewStub(channel)); |
||||
// Make actual RPC calls on the stub. |
||||
grpc::Status s = stub->sayHello(&context, *request, response); |
||||
``` |
||||
|
||||
For advanced use cases such as modifying the root CA or using client certs, |
||||
the corresponding options can be set in the SslCredentialsOptions parameter |
||||
passed to the factory method. |
||||
|
||||
|
||||
###Authenticating with Google |
||||
|
||||
gRPC applications can use a simple API to create a credential that works in various deployment scenarios. |
||||
|
||||
```cpp |
||||
std::shared_ptr<ChannelCredentials> creds = GoogleDefaultCredentials(); |
||||
// Create a channel, stub and make RPC calls (same as in the previous example) |
||||
std::shared_ptr<Channel> channel = CreateChannel(server_name, creds); |
||||
std::unique_ptr<Greeter::Stub> stub(Greeter::NewStub(channel)); |
||||
grpc::Status s = stub->sayHello(&context, *request, response); |
||||
``` |
||||
|
||||
This credential works for applications using Service Accounts as well as for |
||||
applications running in [Google Compute Engine (GCE)](https://cloud.google.com/compute/). In the former case, the |
||||
service account’s private keys are loaded from the file named in the environment |
||||
variable `GOOGLE_APPLICATION_CREDENTIALS`. The |
||||
keys are used to generate bearer tokens that are attached to each outgoing RPC |
||||
on the corresponding channel. |
||||
|
||||
For applications running in GCE, a default service account and corresponding |
||||
OAuth scopes can be configured during VM setup. At run-time, this credential |
||||
handles communication with the authentication systems to obtain OAuth2 access |
||||
tokens and attaches them to each outgoing RPC on the corresponding channel. |
||||
Extending gRPC to support other authentication mechanisms |
||||
The gRPC protocol is designed with a general mechanism for sending metadata |
||||
associated with RPC. Clients can send metadata at the beginning of an RPC and |
||||
servers can send back metadata at the beginning and end of the RPC. This |
||||
provides a natural mechanism to support OAuth2 and other authentication |
||||
mechanisms that need attach bearer tokens to individual request. |
||||
|
||||
In the simplest case, there is a single line of code required on the client |
||||
to add a specific token as metadata to an RPC and a corresponding access on |
||||
the server to retrieve this piece of metadata. The generation of the token |
||||
on the client side and its verification at the server can be done separately. |
||||
|
||||
A deeper integration can be achieved by plugging in a gRPC credentials implementation for any custom authentication mechanism that needs to attach per-request tokens. gRPC internals also allow switching out SSL/TLS with other encryption mechanisms. |
||||
|
||||
## Examples |
||||
|
||||
These authentication mechanisms will be available in all gRPC's supported languages. |
||||
The following sections demonstrate how authentication and authorization features described above appear in each language: more languages are coming soon. |
||||
|
||||
###SSL/TLS for server authentication and encryption (Ruby) |
||||
```ruby |
||||
# Base case - No encryption |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051') |
||||
... |
||||
|
||||
# With server authentication SSL/TLS |
||||
creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051', creds: creds) |
||||
``` |
||||
|
||||
###SSL/TLS for server authentication and encryption (C#) |
||||
```csharp |
||||
// Base case - No encryption |
||||
var channel = new Channel("localhost:50051"); |
||||
var client = new Greeter.GreeterClient(channel); |
||||
... |
||||
|
||||
// With server authentication SSL/TLS |
||||
var credentials = new SslCredentials(File.ReadAllText("ca.pem")); // Load a CA file |
||||
var channel = new Channel("localhost:50051", credentials); |
||||
var client = new Greeter.GreeterClient(channel); |
||||
``` |
||||
|
||||
###SSL/TLS for server authentication and encryption (Objective-C) |
||||
|
||||
The default for Objective-C is to use SSL/TLS, as that's the most common use case when accessing |
||||
remote APIs. |
||||
|
||||
```objective-c |
||||
// Base case - With server authentication SSL/TLS |
||||
HLWGreeter *client = [[HLWGreeter alloc] initWithHost:@"localhost:50051"]; |
||||
// Same as using @"https://localhost:50051". |
||||
... |
||||
|
||||
// No encryption |
||||
HLWGreeter *client = [[HLWGreeter alloc] initWithHost:@"http://localhost:50051"]; |
||||
// Specifying the HTTP scheme explicitly forces no encryption. |
||||
``` |
||||
|
||||
###SSL/TLS for server authentication and encryption (Python) |
||||
```python |
||||
# Base case - No encryption |
||||
stub = early_adopter_create_GreeterService_stub('localhost', 50051) |
||||
... |
||||
|
||||
# With server authentication SSL/TLS |
||||
stub = early_adopter_create_GreeterService_stub( |
||||
'localhost', 50051, secure=True, root_certificates=open('ca.pem').read()) |
||||
... |
||||
``` |
||||
n.b.: the beta API will look different |
||||
|
||||
###Authenticating with Google (Ruby) |
||||
```ruby |
||||
# Base case - No encryption/authorization |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051') |
||||
... |
||||
|
||||
# Authenticating with Google |
||||
require 'googleauth' # from http://www.rubydoc.info/gems/googleauth/0.1.0 |
||||
... |
||||
creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file |
||||
scope = 'https://www.googleapis.com/auth/grpc-testing' |
||||
authorization = Google::Auth.get_application_default(scope) |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051', |
||||
creds: creds, |
||||
update_metadata: authorization.updater_proc) |
||||
``` |
||||
|
||||
###Authenticating with Google (Node.js) |
||||
|
||||
```node |
||||
// Base case - No encryption/authorization |
||||
var stub = new helloworld.Greeter('localhost:50051'); |
||||
... |
||||
// Authenticating with Google |
||||
var GoogleAuth = require('google-auth-library'); // from https://www.npmjs.com/package/google-auth-library |
||||
... |
||||
var creds = grpc.Credentials.createSsl(load_certs); // load_certs typically loads a CA roots file |
||||
var scope = 'https://www.googleapis.com/auth/grpc-testing'; |
||||
(new GoogleAuth()).getApplicationDefault(function(err, auth) { |
||||
if (auth.createScopeRequired()) { |
||||
auth = auth.createScoped(scope); |
||||
} |
||||
var stub = new helloworld.Greeter('localhost:50051', |
||||
{credentials: creds}, |
||||
grpc.getGoogleAuthDelegate(auth)); |
||||
}); |
||||
``` |
||||
|
||||
###Authenticating with Google (C#) |
||||
```csharp |
||||
// Base case - No encryption/authorization |
||||
var channel = new Channel("localhost:50051"); |
||||
var client = new Greeter.GreeterClient(channel); |
||||
... |
||||
|
||||
// Authenticating with Google |
||||
using Grpc.Auth; // from Grpc.Auth NuGet package |
||||
... |
||||
var credentials = new SslCredentials(File.ReadAllText("ca.pem")); // Load a CA file |
||||
var channel = new Channel("localhost:50051", credentials); |
||||
|
||||
string scope = "https://www.googleapis.com/auth/grpc-testing"; |
||||
var authorization = GoogleCredential.GetApplicationDefault(); |
||||
if (authorization.IsCreateScopedRequired) |
||||
{ |
||||
authorization = credential.CreateScoped(new[] { scope }); |
||||
} |
||||
var client = new Greeter.GreeterClient(channel, |
||||
new StubConfiguration(OAuth2InterceptorFactory.Create(credential))); |
||||
``` |
||||
|
||||
###Authenticating with Google (PHP) |
||||
```php |
||||
// Base case - No encryption/authorization |
||||
$client = new helloworld\GreeterClient( |
||||
new Grpc\BaseStub('localhost:50051', [])); |
||||
... |
||||
|
||||
// Authenticating with Google |
||||
// the environment variable "GOOGLE_APPLICATION_CREDENTIALS" needs to be set |
||||
$scope = "https://www.googleapis.com/auth/grpc-testing"; |
||||
$auth = Google\Auth\ApplicationDefaultCredentials::getCredentials($scope); |
||||
$opts = [ |
||||
'credentials' => Grpc\Credentials::createSsl(file_get_contents('ca.pem')); |
||||
'update_metadata' => $auth->getUpdateMetadataFunc(), |
||||
]; |
||||
|
||||
$client = new helloworld\GreeterClient( |
||||
new Grpc\BaseStub('localhost:50051', $opts)); |
||||
|
||||
``` |
||||
|
||||
###Authenticating with Google (Objective-C) |
||||
|
||||
This example uses the [Google iOS Sign-In library](https://developers.google.com/identity/sign-in/ios/), |
||||
but it's easily extrapolated to any other OAuth2 library. |
||||
|
||||
```objective-c |
||||
// Base case - No authentication |
||||
[client sayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { |
||||
... |
||||
}]; |
||||
|
||||
... |
||||
|
||||
// Authenticating with Google |
||||
|
||||
// When signing the user in, ask her for the relevant scopes. |
||||
GIDSignIn.sharedInstance.scopes = @[@"https://www.googleapis.com/auth/grpc-testing"]; |
||||
|
||||
... |
||||
|
||||
#import <ProtoRPC/ProtoRPC.h> |
||||
|
||||
// Create a not-yet-started RPC. We want to set the request headers on this object before starting |
||||
// it. |
||||
ProtoRPC *call = |
||||
[client RPCToSayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { |
||||
... |
||||
}]; |
||||
|
||||
// Set the access token to be used. |
||||
NSString *accessToken = GIDSignIn.sharedInstance.currentUser.authentication.accessToken; |
||||
call.requestMetadata[@"Authorization"] = [@"Bearer " stringByAppendingString:accessToken]}]; |
||||
|
||||
// Start the RPC. |
||||
[call start]; |
||||
``` |
||||
|
||||
You can see a working example app, with a more detailed explanation, [here](examples/objective-c/auth_sample). |
||||
|
||||
### Authenticating with Google (Python) |
||||
```python |
||||
# Base case - No encryption |
||||
stub = early_adopter_create_GreeterService_stub('localhost', 50051) |
||||
... |
||||
|
||||
# With server authentication SSL/TLS |
||||
import oauth2client.client |
||||
credentials = oauth2client.GoogleCredentials.get_application_default() |
||||
scope = 'https://www.googleapis.com/auth/grpc-testing' |
||||
scoped_credentials = credentials.create_scoped([scope]) |
||||
access_token = scoped_credentials.get_access_token().access_token |
||||
metadata_transformer = ( |
||||
lambda x: [('Authorization', 'Bearer {}'.format(access_token))]) |
||||
|
||||
stub = early_adopter_create_GreeterService_stub( |
||||
'localhost', 50051, secure=True, root_certificates=open('ca.pem').read(), |
||||
metadata_transformer=metadata_transformer) |
||||
... |
||||
``` |
||||
n.b.: the beta API will look different |
@ -0,0 +1,91 @@ |
||||
/*
|
||||
* |
||||
* 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_SUPPORT_AVL_H |
||||
#define GRPC_SUPPORT_AVL_H |
||||
|
||||
#include <grpc/support/sync.h> |
||||
|
||||
/** internal node of an AVL tree */ |
||||
typedef struct gpr_avl_node { |
||||
gpr_refcount refs; |
||||
void *key; |
||||
void *value; |
||||
struct gpr_avl_node *left; |
||||
struct gpr_avl_node *right; |
||||
long height; |
||||
} gpr_avl_node; |
||||
|
||||
typedef struct gpr_avl_vtable { |
||||
/** destroy a key */ |
||||
void (*destroy_key)(void *key); |
||||
/** copy a key, returning new value */ |
||||
void *(*copy_key)(void *key); |
||||
/** compare key1, key2; return <0 if key1 < key2,
|
||||
>0 if key1 > key2, 0 if key1 == key2 */ |
||||
long (*compare_keys)(void *key1, void *key2); |
||||
/** destroy a value */ |
||||
void (*destroy_value)(void *value); |
||||
/** copy a value */ |
||||
void *(*copy_value)(void *value); |
||||
} gpr_avl_vtable; |
||||
|
||||
/** "pointer" to an AVL tree - this is a reference
|
||||
counted object - use gpr_avl_ref to add a reference, |
||||
gpr_avl_unref when done with a reference */ |
||||
typedef struct gpr_avl { |
||||
const gpr_avl_vtable *vtable; |
||||
gpr_avl_node *root; |
||||
} gpr_avl; |
||||
|
||||
/** create an immutable AVL tree */ |
||||
gpr_avl gpr_avl_create(const gpr_avl_vtable *vtable); |
||||
/** add a reference to an existing tree - returns
|
||||
the tree as a convenience */ |
||||
gpr_avl gpr_avl_ref(gpr_avl avl); |
||||
/** remove a reference to a tree - destroying it if there
|
||||
are no references left */ |
||||
void gpr_avl_unref(gpr_avl avl); |
||||
/** return a new tree with (key, value) added to avl.
|
||||
implicitly unrefs avl to allow easy chaining. |
||||
if key exists in avl, the new tree's key entry updated |
||||
(i.e. a duplicate is not created) */ |
||||
gpr_avl gpr_avl_add(gpr_avl avl, void *key, void *value); |
||||
/** return a new tree with key deleted */ |
||||
gpr_avl gpr_avl_remove(gpr_avl avl, void *key); |
||||
/** lookup key, and return the associated value.
|
||||
does not mutate avl. |
||||
returns NULL if key is not found. */ |
||||
void *gpr_avl_get(gpr_avl avl, void *key); |
||||
|
||||
#endif |
@ -0,0 +1,141 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head><title>Interop Test Result</title></head> |
||||
<body> |
||||
|
||||
<%def name="fill_one_test_result(shortname, resultset)"> |
||||
% if shortname in resultset: |
||||
## Because interop tests does not have runs_per_test flag, each test is |
||||
## run once. So there should only be one element for each result. |
||||
<% result = resultset[shortname][0] %> |
||||
% if result.state == 'PASSED': |
||||
<td bgcolor="green">PASS</td> |
||||
% else: |
||||
<% |
||||
tooltip = '' |
||||
if result.returncode > 0 or result.message: |
||||
if result.returncode > 0: |
||||
tooltip = 'returncode: %d ' % result.returncode |
||||
if result.message: |
||||
tooltip = '%smessage: %s' % (tooltip, result.message) |
||||
%> |
||||
% if result.state == 'FAILED': |
||||
<td bgcolor="red"> |
||||
% if tooltip: |
||||
<a href="#" data-toggle="tooltip" data-placement="auto" title="${tooltip | h}">FAIL</a></td> |
||||
% else: |
||||
FAIL</td> |
||||
% endif |
||||
% elif result.state == 'TIMEOUT': |
||||
<td bgcolor="yellow"> |
||||
% if tooltip: |
||||
<a href="#" data-toggle="tooltip" data-placement="auto" title="${tooltip | h}">TIMEOUT</a></td> |
||||
% else: |
||||
TIMEOUT</td> |
||||
% endif |
||||
% endif |
||||
% endif |
||||
% else: |
||||
<td bgcolor="magenta">Not implemented</td> |
||||
% endif |
||||
</%def> |
||||
|
||||
% if num_failures > 1: |
||||
<p><h2><font color="red">${num_failures} tests failed!</font></h2></p> |
||||
% elif num_failures: |
||||
<p><h2><font color="red">${num_failures} test failed!</font></h2></p> |
||||
% else: |
||||
<p><h2><font color="green">All tests passed!</font></h2></p> |
||||
% endif |
||||
|
||||
% if cloud_to_prod: |
||||
## Each column header is the client language. |
||||
<h2>Cloud to Prod</h2> |
||||
<table style="width:100%" border="1"> |
||||
<tr bgcolor="#00BFFF"> |
||||
<th>Client languages ►<br/>Test Cases ▼</th> |
||||
% for client_lang in client_langs: |
||||
<th>${client_lang}</th> |
||||
% endfor |
||||
</tr> |
||||
% for test_case in test_cases + auth_test_cases: |
||||
<tr><td><b>${test_case}</b></td> |
||||
% for client_lang in client_langs: |
||||
<% |
||||
if test_case in auth_test_cases: |
||||
shortname = 'cloud_to_prod_auth:%s:%s' % (client_lang, test_case) |
||||
else: |
||||
shortname = 'cloud_to_prod:%s:%s' % (client_lang, test_case) |
||||
%> |
||||
${fill_one_test_result(shortname, resultset)} |
||||
% endfor |
||||
</tr> |
||||
% endfor |
||||
</table> |
||||
% endif |
||||
|
||||
% if http2_interop: |
||||
## Each column header is the server language. |
||||
<h2>HTTP/2 Interop</h2> |
||||
<table style="width:100%" border="1"> |
||||
<tr bgcolor="#00BFFF"> |
||||
<th>Servers ►<br/>Test Cases ▼</th> |
||||
% for server_lang in server_langs: |
||||
<th>${server_lang}</th> |
||||
% endfor |
||||
% if cloud_to_prod: |
||||
<th>prod</th> |
||||
% endif |
||||
</tr> |
||||
% for test_case in http2_cases: |
||||
<tr><td><b>${test_case}</b></td> |
||||
## Fill up the cells with test result. |
||||
% for server_lang in server_langs: |
||||
<% |
||||
shortname = 'cloud_to_cloud:http2:%s_server:%s' % ( |
||||
server_lang, test_case) |
||||
%> |
||||
${fill_one_test_result(shortname, resultset)} |
||||
% endfor |
||||
% if cloud_to_prod: |
||||
<% shortname = 'cloud_to_prod:http2:%s' % test_case %> |
||||
${fill_one_test_result(shortname, resultset)} |
||||
% endif |
||||
</tr> |
||||
% endfor |
||||
</table> |
||||
% endif |
||||
|
||||
% if server_langs: |
||||
% for test_case in test_cases: |
||||
## Each column header is the client language. |
||||
<h2>${test_case}</h2> |
||||
<table style="width:100%" border="1"> |
||||
<tr bgcolor="#00BFFF"> |
||||
<th>Client languages ►<br/>Server languages ▼</th> |
||||
% for client_lang in client_langs: |
||||
<th>${client_lang}</th> |
||||
% endfor |
||||
</tr> |
||||
## Each row head is the server language. |
||||
% for server_lang in server_langs: |
||||
<tr> |
||||
<td><b>${server_lang}</b></td> |
||||
% for client_lang in client_langs: |
||||
<% |
||||
shortname = 'cloud_to_cloud:%s:%s_server:%s' % ( |
||||
client_lang, server_lang, test_case) |
||||
%> |
||||
${fill_one_test_result(shortname, resultset)} |
||||
% endfor |
||||
</tr> |
||||
% endfor |
||||
</table> |
||||
% endfor |
||||
% endif |
||||
|
||||
<script> |
||||
$(document).ready(function(){$('[data-toggle="tooltip"]').tooltip();}); |
||||
</script> |
||||
</body> |
||||
</html> |
@ -0,0 +1,39 @@ |
||||
/*
|
||||
* |
||||
* 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/support/slice.h> |
||||
#include "src/core/iomgr/sockaddr.h" |
||||
|
||||
void grpc_set_default_initial_connect_string(struct sockaddr **addr, |
||||
size_t *addr_len, |
||||
gpr_slice *initial_str) {} |
@ -0,0 +1,53 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/client_config/initial_connect_string.h" |
||||
|
||||
#include <stddef.h> |
||||
|
||||
extern void grpc_set_default_initial_connect_string(struct sockaddr **addr, |
||||
size_t *addr_len, |
||||
gpr_slice *initial_str); |
||||
|
||||
static grpc_set_initial_connect_string_func g_set_initial_connect_string_func = |
||||
grpc_set_default_initial_connect_string; |
||||
|
||||
void grpc_test_set_initial_connect_string_function( |
||||
grpc_set_initial_connect_string_func func) { |
||||
g_set_initial_connect_string_func = func; |
||||
} |
||||
|
||||
void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, |
||||
gpr_slice *initial_str) { |
||||
g_set_initial_connect_string_func(addr, addr_len, initial_str); |
||||
} |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H |
||||
#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H |
||||
|
||||
#include <grpc/support/slice.h> |
||||
#include "src/core/iomgr/sockaddr.h" |
||||
|
||||
typedef void (*grpc_set_initial_connect_string_func)(struct sockaddr **addr, |
||||
size_t *addr_len, |
||||
gpr_slice *initial_str); |
||||
void grpc_test_set_initial_connect_string_function( |
||||
grpc_set_initial_connect_string_func func); |
||||
|
||||
/** Set a string to be sent once connected. Optionally reset addr. */ |
||||
void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, |
||||
gpr_slice *connect_string); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H */ |
@ -0,0 +1,53 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_COMPRESSION_ALGORITHM_METADATA_H |
||||
#define GRPC_INTERNAL_CORE_COMPRESSION_ALGORITHM_METADATA_H |
||||
|
||||
#include <grpc/compression.h> |
||||
#include "src/core/transport/metadata.h" |
||||
|
||||
/** Return compression algorithm based metadata value */ |
||||
grpc_mdstr *grpc_compression_algorithm_mdstr( |
||||
grpc_compression_algorithm algorithm); |
||||
|
||||
/** Return compression algorithm based metadata element (grpc-encoding: xxx) */ |
||||
grpc_mdelem *grpc_compression_encoding_mdelem( |
||||
grpc_compression_algorithm algorithm); |
||||
|
||||
/** Find compression algorithm based on passed in mdstr - returns
|
||||
* GRPC_COMPRESS_ALGORITHM_COUNT on failure */ |
||||
grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( |
||||
grpc_mdstr *str); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_COMPRESSION_ALGORITHM_METADATA_H */ |
@ -0,0 +1,288 @@ |
||||
/*
|
||||
* |
||||
* 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/support/avl.h> |
||||
|
||||
#include <assert.h> |
||||
#include <stdlib.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/string_util.h> |
||||
#include <grpc/support/useful.h> |
||||
|
||||
gpr_avl gpr_avl_create(const gpr_avl_vtable *vtable) { |
||||
gpr_avl out; |
||||
out.vtable = vtable; |
||||
out.root = NULL; |
||||
return out; |
||||
} |
||||
|
||||
static gpr_avl_node *ref_node(gpr_avl_node *node) { |
||||
if (node) { |
||||
gpr_ref(&node->refs); |
||||
} |
||||
return node; |
||||
} |
||||
|
||||
static void unref_node(const gpr_avl_vtable *vtable, gpr_avl_node *node) { |
||||
if (node == NULL) { |
||||
return; |
||||
} |
||||
if (gpr_unref(&node->refs)) { |
||||
vtable->destroy_key(node->key); |
||||
vtable->destroy_value(node->value); |
||||
unref_node(vtable, node->left); |
||||
unref_node(vtable, node->right); |
||||
gpr_free(node); |
||||
} |
||||
} |
||||
|
||||
static long node_height(gpr_avl_node *node) { |
||||
return node == NULL ? 0 : node->height; |
||||
} |
||||
|
||||
#ifndef NDEBUG |
||||
static long calculate_height(gpr_avl_node *node) { |
||||
return node == NULL ? 0 : 1 + GPR_MAX(calculate_height(node->left), |
||||
calculate_height(node->right)); |
||||
} |
||||
|
||||
static gpr_avl_node *assert_invariants(gpr_avl_node *n) { |
||||
if (n == NULL) return NULL; |
||||
assert_invariants(n->left); |
||||
assert_invariants(n->right); |
||||
assert(calculate_height(n) == n->height); |
||||
assert(labs(node_height(n->left) - node_height(n->right)) <= 1); |
||||
return n; |
||||
} |
||||
#else |
||||
static gpr_avl_node *assert_invariants(gpr_avl_node *n) { return n; } |
||||
#endif |
||||
|
||||
gpr_avl_node *new_node(void *key, void *value, gpr_avl_node *left, |
||||
gpr_avl_node *right) { |
||||
gpr_avl_node *node = gpr_malloc(sizeof(*node)); |
||||
gpr_ref_init(&node->refs, 1); |
||||
node->key = key; |
||||
node->value = value; |
||||
node->left = assert_invariants(left); |
||||
node->right = assert_invariants(right); |
||||
node->height = 1 + GPR_MAX(node_height(left), node_height(right)); |
||||
return node; |
||||
} |
||||
|
||||
static gpr_avl_node *get(const gpr_avl_vtable *vtable, gpr_avl_node *node, |
||||
void *key) { |
||||
long cmp; |
||||
|
||||
if (node == NULL) { |
||||
return NULL; |
||||
} |
||||
|
||||
cmp = vtable->compare_keys(node->key, key); |
||||
if (cmp == 0) { |
||||
return node; |
||||
} else if (cmp > 0) { |
||||
return get(vtable, node->left, key); |
||||
} else { |
||||
return get(vtable, node->right, key); |
||||
} |
||||
} |
||||
|
||||
void *gpr_avl_get(gpr_avl avl, void *key) { |
||||
gpr_avl_node *node = get(avl.vtable, avl.root, key); |
||||
return node ? node->value : NULL; |
||||
} |
||||
|
||||
static gpr_avl_node *rotate_left(const gpr_avl_vtable *vtable, void *key, |
||||
void *value, gpr_avl_node *left, |
||||
gpr_avl_node *right) { |
||||
gpr_avl_node *n = |
||||
new_node(vtable->copy_key(right->key), vtable->copy_value(right->value), |
||||
new_node(key, value, left, ref_node(right->left)), |
||||
ref_node(right->right)); |
||||
unref_node(vtable, right); |
||||
return n; |
||||
} |
||||
|
||||
static gpr_avl_node *rotate_right(const gpr_avl_vtable *vtable, void *key, |
||||
void *value, gpr_avl_node *left, |
||||
gpr_avl_node *right) { |
||||
gpr_avl_node *n = new_node( |
||||
vtable->copy_key(left->key), vtable->copy_value(left->value), |
||||
ref_node(left->left), new_node(key, value, ref_node(left->right), right)); |
||||
unref_node(vtable, left); |
||||
return n; |
||||
} |
||||
|
||||
static gpr_avl_node *rotate_left_right(const gpr_avl_vtable *vtable, void *key, |
||||
void *value, gpr_avl_node *left, |
||||
gpr_avl_node *right) { |
||||
/* rotate_right(..., rotate_left(left), right) */ |
||||
gpr_avl_node *n = new_node( |
||||
vtable->copy_key(left->right->key), |
||||
vtable->copy_value(left->right->value), |
||||
new_node(vtable->copy_key(left->key), vtable->copy_value(left->value), |
||||
ref_node(left->left), ref_node(left->right->left)), |
||||
new_node(key, value, ref_node(left->right->right), right)); |
||||
unref_node(vtable, left); |
||||
return n; |
||||
} |
||||
|
||||
static gpr_avl_node *rotate_right_left(const gpr_avl_vtable *vtable, void *key, |
||||
void *value, gpr_avl_node *left, |
||||
gpr_avl_node *right) { |
||||
/* rotate_left(..., left, rotate_right(right)) */ |
||||
gpr_avl_node *n = new_node( |
||||
vtable->copy_key(right->left->key), |
||||
vtable->copy_value(right->left->value), |
||||
new_node(key, value, left, ref_node(right->left->left)), |
||||
new_node(vtable->copy_key(right->key), vtable->copy_key(right->value), |
||||
ref_node(right->left->right), ref_node(right->right))); |
||||
unref_node(vtable, right); |
||||
return n; |
||||
} |
||||
|
||||
static gpr_avl_node *rebalance(const gpr_avl_vtable *vtable, void *key, |
||||
void *value, gpr_avl_node *left, |
||||
gpr_avl_node *right) { |
||||
switch (node_height(left) - node_height(right)) { |
||||
case 2: |
||||
if (node_height(left->left) - node_height(left->right) == -1) { |
||||
return assert_invariants( |
||||
rotate_left_right(vtable, key, value, left, right)); |
||||
} else { |
||||
return assert_invariants(rotate_right(vtable, key, value, left, right)); |
||||
} |
||||
case -2: |
||||
if (node_height(right->left) - node_height(right->right) == 1) { |
||||
return assert_invariants( |
||||
rotate_right_left(vtable, key, value, left, right)); |
||||
} else { |
||||
return assert_invariants(rotate_left(vtable, key, value, left, right)); |
||||
} |
||||
default: |
||||
return assert_invariants(new_node(key, value, left, right)); |
||||
} |
||||
} |
||||
|
||||
static gpr_avl_node *add(const gpr_avl_vtable *vtable, gpr_avl_node *node, |
||||
void *key, void *value) { |
||||
long cmp; |
||||
if (node == NULL) { |
||||
return new_node(key, value, NULL, NULL); |
||||
} |
||||
cmp = vtable->compare_keys(node->key, key); |
||||
if (cmp == 0) { |
||||
return new_node(key, value, ref_node(node->left), ref_node(node->right)); |
||||
} else if (cmp > 0) { |
||||
return rebalance( |
||||
vtable, vtable->copy_key(node->key), vtable->copy_value(node->value), |
||||
add(vtable, node->left, key, value), ref_node(node->right)); |
||||
} else { |
||||
return rebalance(vtable, vtable->copy_key(node->key), |
||||
vtable->copy_value(node->value), ref_node(node->left), |
||||
add(vtable, node->right, key, value)); |
||||
} |
||||
} |
||||
|
||||
gpr_avl gpr_avl_add(gpr_avl avl, void *key, void *value) { |
||||
gpr_avl_node *old_root = avl.root; |
||||
avl.root = add(avl.vtable, avl.root, key, value); |
||||
assert_invariants(avl.root); |
||||
unref_node(avl.vtable, old_root); |
||||
return avl; |
||||
} |
||||
|
||||
static gpr_avl_node *in_order_head(gpr_avl_node *node) { |
||||
while (node->left != NULL) { |
||||
node = node->left; |
||||
} |
||||
return node; |
||||
} |
||||
|
||||
static gpr_avl_node *in_order_tail(gpr_avl_node *node) { |
||||
while (node->right != NULL) { |
||||
node = node->right; |
||||
} |
||||
return node; |
||||
} |
||||
|
||||
static gpr_avl_node *remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, |
||||
void *key) { |
||||
long cmp; |
||||
if (node == NULL) { |
||||
return NULL; |
||||
} |
||||
cmp = vtable->compare_keys(node->key, key); |
||||
if (cmp == 0) { |
||||
if (node->left == NULL) { |
||||
return ref_node(node->right); |
||||
} else if (node->right == NULL) { |
||||
return ref_node(node->left); |
||||
} else if (node->left->height < node->right->height) { |
||||
gpr_avl_node *h = in_order_head(node->right); |
||||
return rebalance(vtable, vtable->copy_key(h->key), |
||||
vtable->copy_value(h->value), ref_node(node->left), |
||||
remove(vtable, node->right, h->key)); |
||||
} else { |
||||
gpr_avl_node *h = in_order_tail(node->left); |
||||
return rebalance( |
||||
vtable, vtable->copy_key(h->key), vtable->copy_value(h->value), |
||||
remove(vtable, node->left, h->key), ref_node(node->right)); |
||||
} |
||||
} else if (cmp > 0) { |
||||
return rebalance(vtable, vtable->copy_key(node->key), |
||||
vtable->copy_value(node->value), |
||||
remove(vtable, node->left, key), ref_node(node->right)); |
||||
} else { |
||||
return rebalance(vtable, vtable->copy_key(node->key), |
||||
vtable->copy_value(node->value), ref_node(node->left), |
||||
remove(vtable, node->right, key)); |
||||
} |
||||
} |
||||
|
||||
gpr_avl gpr_avl_remove(gpr_avl avl, void *key) { |
||||
gpr_avl_node *old_root = avl.root; |
||||
avl.root = remove(avl.vtable, avl.root, key); |
||||
assert_invariants(avl.root); |
||||
unref_node(avl.vtable, old_root); |
||||
return avl; |
||||
} |
||||
|
||||
gpr_avl gpr_avl_ref(gpr_avl avl) { |
||||
ref_node(avl.root); |
||||
return avl; |
||||
} |
||||
|
||||
void gpr_avl_unref(gpr_avl avl) { unref_node(avl.vtable, avl.root); } |
@ -0,0 +1,157 @@ |
||||
/*
|
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
/*
|
||||
* WARNING: Auto-generated code. |
||||
* |
||||
* To make changes to this file, change |
||||
* tools/codegen/core/gen_static_metadata.py, |
||||
* and then re-run it. |
||||
* |
||||
* See metadata.h for an explanation of the interface here, and metadata.c for |
||||
* an |
||||
* explanation of what's going on. |
||||
*/ |
||||
|
||||
#include "src/core/transport/static_metadata.h" |
||||
|
||||
grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; |
||||
|
||||
grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; |
||||
gpr_uintptr grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 3, 7, 5, 2, 4, 8, 6, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
||||
|
||||
const gpr_uint8 |
||||
grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = { |
||||
11, 33, 10, 33, 12, 33, 12, 47, 13, 33, 14, 33, 15, 33, 16, 33, 17, 33, |
||||
19, 33, 20, 33, 21, 33, 22, 33, 23, 33, 24, 33, 25, 33, 26, 33, 27, 33, |
||||
28, 18, 28, 33, 29, 33, 30, 33, 34, 33, 35, 33, 36, 33, 37, 33, 40, 31, |
||||
40, 32, 40, 46, 40, 51, 40, 52, 40, 53, 40, 54, 41, 31, 41, 46, 41, 51, |
||||
44, 0, 44, 1, 44, 2, 48, 33, 55, 33, 56, 33, 57, 33, 58, 33, 59, 33, |
||||
60, 33, 61, 33, 62, 33, 63, 33, 64, 38, 64, 66, 65, 76, 65, 77, 67, 33, |
||||
68, 33, 69, 33, 70, 33, 71, 33, 72, 33, 73, 39, 73, 49, 73, 50, 74, 33, |
||||
75, 33, 78, 3, 78, 4, 78, 5, 78, 6, 78, 7, 78, 8, 78, 9, 79, 33, |
||||
80, 81, 82, 33, 83, 33, 84, 33, 85, 33, 86, 33}; |
||||
|
||||
const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = { |
||||
"0", |
||||
"1", |
||||
"2", |
||||
"200", |
||||
"204", |
||||
"206", |
||||
"304", |
||||
"400", |
||||
"404", |
||||
"500", |
||||
"accept", |
||||
"accept-charset", |
||||
"accept-encoding", |
||||
"accept-language", |
||||
"accept-ranges", |
||||
"access-control-allow-origin", |
||||
"age", |
||||
"allow", |
||||
"application/grpc", |
||||
":authority", |
||||
"authorization", |
||||
"cache-control", |
||||
"content-disposition", |
||||
"content-encoding", |
||||
"content-language", |
||||
"content-length", |
||||
"content-location", |
||||
"content-range", |
||||
"content-type", |
||||
"cookie", |
||||
"date", |
||||
"deflate", |
||||
"deflate,gzip", |
||||
"", |
||||
"etag", |
||||
"expect", |
||||
"expires", |
||||
"from", |
||||
"GET", |
||||
"grpc", |
||||
"grpc-accept-encoding", |
||||
"grpc-encoding", |
||||
"grpc-internal-encoding-request", |
||||
"grpc-message", |
||||
"grpc-status", |
||||
"grpc-timeout", |
||||
"gzip", |
||||
"gzip, deflate", |
||||
"host", |
||||
"http", |
||||
"https", |
||||
"identity", |
||||
"identity,deflate", |
||||
"identity,deflate,gzip", |
||||
"identity,gzip", |
||||
"if-match", |
||||
"if-modified-since", |
||||
"if-none-match", |
||||
"if-range", |
||||
"if-unmodified-since", |
||||
"last-modified", |
||||
"link", |
||||
"location", |
||||
"max-forwards", |
||||
":method", |
||||
":path", |
||||
"POST", |
||||
"proxy-authenticate", |
||||
"proxy-authorization", |
||||
"range", |
||||
"referer", |
||||
"refresh", |
||||
"retry-after", |
||||
":scheme", |
||||
"server", |
||||
"set-cookie", |
||||
"/", |
||||
"/index.html", |
||||
":status", |
||||
"strict-transport-security", |
||||
"te", |
||||
"trailers", |
||||
"transfer-encoding", |
||||
"user-agent", |
||||
"vary", |
||||
"via", |
||||
"www-authenticate"}; |
||||
|
||||
const gpr_uint8 grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, |
||||
28, 32, 27, 31}; |
@ -0,0 +1,402 @@ |
||||
/*
|
||||
* 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. |
||||
*/ |
||||
|
||||
/*
|
||||
* WARNING: Auto-generated code. |
||||
* |
||||
* To make changes to this file, change |
||||
* tools/codegen/core/gen_static_metadata.py, |
||||
* and then re-run it. |
||||
* |
||||
* See metadata.h for an explanation of the interface here, and metadata.c for |
||||
* an |
||||
* explanation of what's going on. |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_TRANSPORT_STATIC_METADATA_H |
||||
#define GRPC_INTERNAL_CORE_TRANSPORT_STATIC_METADATA_H |
||||
|
||||
#include "src/core/transport/metadata.h" |
||||
|
||||
#define GRPC_STATIC_MDSTR_COUNT 87 |
||||
extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; |
||||
/* "0" */ |
||||
#define GRPC_MDSTR_0 (&grpc_static_mdstr_table[0]) |
||||
/* "1" */ |
||||
#define GRPC_MDSTR_1 (&grpc_static_mdstr_table[1]) |
||||
/* "2" */ |
||||
#define GRPC_MDSTR_2 (&grpc_static_mdstr_table[2]) |
||||
/* "200" */ |
||||
#define GRPC_MDSTR_200 (&grpc_static_mdstr_table[3]) |
||||
/* "204" */ |
||||
#define GRPC_MDSTR_204 (&grpc_static_mdstr_table[4]) |
||||
/* "206" */ |
||||
#define GRPC_MDSTR_206 (&grpc_static_mdstr_table[5]) |
||||
/* "304" */ |
||||
#define GRPC_MDSTR_304 (&grpc_static_mdstr_table[6]) |
||||
/* "400" */ |
||||
#define GRPC_MDSTR_400 (&grpc_static_mdstr_table[7]) |
||||
/* "404" */ |
||||
#define GRPC_MDSTR_404 (&grpc_static_mdstr_table[8]) |
||||
/* "500" */ |
||||
#define GRPC_MDSTR_500 (&grpc_static_mdstr_table[9]) |
||||
/* "accept" */ |
||||
#define GRPC_MDSTR_ACCEPT (&grpc_static_mdstr_table[10]) |
||||
/* "accept-charset" */ |
||||
#define GRPC_MDSTR_ACCEPT_CHARSET (&grpc_static_mdstr_table[11]) |
||||
/* "accept-encoding" */ |
||||
#define GRPC_MDSTR_ACCEPT_ENCODING (&grpc_static_mdstr_table[12]) |
||||
/* "accept-language" */ |
||||
#define GRPC_MDSTR_ACCEPT_LANGUAGE (&grpc_static_mdstr_table[13]) |
||||
/* "accept-ranges" */ |
||||
#define GRPC_MDSTR_ACCEPT_RANGES (&grpc_static_mdstr_table[14]) |
||||
/* "access-control-allow-origin" */ |
||||
#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (&grpc_static_mdstr_table[15]) |
||||
/* "age" */ |
||||
#define GRPC_MDSTR_AGE (&grpc_static_mdstr_table[16]) |
||||
/* "allow" */ |
||||
#define GRPC_MDSTR_ALLOW (&grpc_static_mdstr_table[17]) |
||||
/* "application/grpc" */ |
||||
#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (&grpc_static_mdstr_table[18]) |
||||
/* ":authority" */ |
||||
#define GRPC_MDSTR_AUTHORITY (&grpc_static_mdstr_table[19]) |
||||
/* "authorization" */ |
||||
#define GRPC_MDSTR_AUTHORIZATION (&grpc_static_mdstr_table[20]) |
||||
/* "cache-control" */ |
||||
#define GRPC_MDSTR_CACHE_CONTROL (&grpc_static_mdstr_table[21]) |
||||
/* "content-disposition" */ |
||||
#define GRPC_MDSTR_CONTENT_DISPOSITION (&grpc_static_mdstr_table[22]) |
||||
/* "content-encoding" */ |
||||
#define GRPC_MDSTR_CONTENT_ENCODING (&grpc_static_mdstr_table[23]) |
||||
/* "content-language" */ |
||||
#define GRPC_MDSTR_CONTENT_LANGUAGE (&grpc_static_mdstr_table[24]) |
||||
/* "content-length" */ |
||||
#define GRPC_MDSTR_CONTENT_LENGTH (&grpc_static_mdstr_table[25]) |
||||
/* "content-location" */ |
||||
#define GRPC_MDSTR_CONTENT_LOCATION (&grpc_static_mdstr_table[26]) |
||||
/* "content-range" */ |
||||
#define GRPC_MDSTR_CONTENT_RANGE (&grpc_static_mdstr_table[27]) |
||||
/* "content-type" */ |
||||
#define GRPC_MDSTR_CONTENT_TYPE (&grpc_static_mdstr_table[28]) |
||||
/* "cookie" */ |
||||
#define GRPC_MDSTR_COOKIE (&grpc_static_mdstr_table[29]) |
||||
/* "date" */ |
||||
#define GRPC_MDSTR_DATE (&grpc_static_mdstr_table[30]) |
||||
/* "deflate" */ |
||||
#define GRPC_MDSTR_DEFLATE (&grpc_static_mdstr_table[31]) |
||||
/* "deflate,gzip" */ |
||||
#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (&grpc_static_mdstr_table[32]) |
||||
/* "" */ |
||||
#define GRPC_MDSTR_EMPTY (&grpc_static_mdstr_table[33]) |
||||
/* "etag" */ |
||||
#define GRPC_MDSTR_ETAG (&grpc_static_mdstr_table[34]) |
||||
/* "expect" */ |
||||
#define GRPC_MDSTR_EXPECT (&grpc_static_mdstr_table[35]) |
||||
/* "expires" */ |
||||
#define GRPC_MDSTR_EXPIRES (&grpc_static_mdstr_table[36]) |
||||
/* "from" */ |
||||
#define GRPC_MDSTR_FROM (&grpc_static_mdstr_table[37]) |
||||
/* "GET" */ |
||||
#define GRPC_MDSTR_GET (&grpc_static_mdstr_table[38]) |
||||
/* "grpc" */ |
||||
#define GRPC_MDSTR_GRPC (&grpc_static_mdstr_table[39]) |
||||
/* "grpc-accept-encoding" */ |
||||
#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (&grpc_static_mdstr_table[40]) |
||||
/* "grpc-encoding" */ |
||||
#define GRPC_MDSTR_GRPC_ENCODING (&grpc_static_mdstr_table[41]) |
||||
/* "grpc-internal-encoding-request" */ |
||||
#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (&grpc_static_mdstr_table[42]) |
||||
/* "grpc-message" */ |
||||
#define GRPC_MDSTR_GRPC_MESSAGE (&grpc_static_mdstr_table[43]) |
||||
/* "grpc-status" */ |
||||
#define GRPC_MDSTR_GRPC_STATUS (&grpc_static_mdstr_table[44]) |
||||
/* "grpc-timeout" */ |
||||
#define GRPC_MDSTR_GRPC_TIMEOUT (&grpc_static_mdstr_table[45]) |
||||
/* "gzip" */ |
||||
#define GRPC_MDSTR_GZIP (&grpc_static_mdstr_table[46]) |
||||
/* "gzip, deflate" */ |
||||
#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (&grpc_static_mdstr_table[47]) |
||||
/* "host" */ |
||||
#define GRPC_MDSTR_HOST (&grpc_static_mdstr_table[48]) |
||||
/* "http" */ |
||||
#define GRPC_MDSTR_HTTP (&grpc_static_mdstr_table[49]) |
||||
/* "https" */ |
||||
#define GRPC_MDSTR_HTTPS (&grpc_static_mdstr_table[50]) |
||||
/* "identity" */ |
||||
#define GRPC_MDSTR_IDENTITY (&grpc_static_mdstr_table[51]) |
||||
/* "identity,deflate" */ |
||||
#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (&grpc_static_mdstr_table[52]) |
||||
/* "identity,deflate,gzip" */ |
||||
#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ |
||||
(&grpc_static_mdstr_table[53]) |
||||
/* "identity,gzip" */ |
||||
#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (&grpc_static_mdstr_table[54]) |
||||
/* "if-match" */ |
||||
#define GRPC_MDSTR_IF_MATCH (&grpc_static_mdstr_table[55]) |
||||
/* "if-modified-since" */ |
||||
#define GRPC_MDSTR_IF_MODIFIED_SINCE (&grpc_static_mdstr_table[56]) |
||||
/* "if-none-match" */ |
||||
#define GRPC_MDSTR_IF_NONE_MATCH (&grpc_static_mdstr_table[57]) |
||||
/* "if-range" */ |
||||
#define GRPC_MDSTR_IF_RANGE (&grpc_static_mdstr_table[58]) |
||||
/* "if-unmodified-since" */ |
||||
#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (&grpc_static_mdstr_table[59]) |
||||
/* "last-modified" */ |
||||
#define GRPC_MDSTR_LAST_MODIFIED (&grpc_static_mdstr_table[60]) |
||||
/* "link" */ |
||||
#define GRPC_MDSTR_LINK (&grpc_static_mdstr_table[61]) |
||||
/* "location" */ |
||||
#define GRPC_MDSTR_LOCATION (&grpc_static_mdstr_table[62]) |
||||
/* "max-forwards" */ |
||||
#define GRPC_MDSTR_MAX_FORWARDS (&grpc_static_mdstr_table[63]) |
||||
/* ":method" */ |
||||
#define GRPC_MDSTR_METHOD (&grpc_static_mdstr_table[64]) |
||||
/* ":path" */ |
||||
#define GRPC_MDSTR_PATH (&grpc_static_mdstr_table[65]) |
||||
/* "POST" */ |
||||
#define GRPC_MDSTR_POST (&grpc_static_mdstr_table[66]) |
||||
/* "proxy-authenticate" */ |
||||
#define GRPC_MDSTR_PROXY_AUTHENTICATE (&grpc_static_mdstr_table[67]) |
||||
/* "proxy-authorization" */ |
||||
#define GRPC_MDSTR_PROXY_AUTHORIZATION (&grpc_static_mdstr_table[68]) |
||||
/* "range" */ |
||||
#define GRPC_MDSTR_RANGE (&grpc_static_mdstr_table[69]) |
||||
/* "referer" */ |
||||
#define GRPC_MDSTR_REFERER (&grpc_static_mdstr_table[70]) |
||||
/* "refresh" */ |
||||
#define GRPC_MDSTR_REFRESH (&grpc_static_mdstr_table[71]) |
||||
/* "retry-after" */ |
||||
#define GRPC_MDSTR_RETRY_AFTER (&grpc_static_mdstr_table[72]) |
||||
/* ":scheme" */ |
||||
#define GRPC_MDSTR_SCHEME (&grpc_static_mdstr_table[73]) |
||||
/* "server" */ |
||||
#define GRPC_MDSTR_SERVER (&grpc_static_mdstr_table[74]) |
||||
/* "set-cookie" */ |
||||
#define GRPC_MDSTR_SET_COOKIE (&grpc_static_mdstr_table[75]) |
||||
/* "/" */ |
||||
#define GRPC_MDSTR_SLASH (&grpc_static_mdstr_table[76]) |
||||
/* "/index.html" */ |
||||
#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (&grpc_static_mdstr_table[77]) |
||||
/* ":status" */ |
||||
#define GRPC_MDSTR_STATUS (&grpc_static_mdstr_table[78]) |
||||
/* "strict-transport-security" */ |
||||
#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (&grpc_static_mdstr_table[79]) |
||||
/* "te" */ |
||||
#define GRPC_MDSTR_TE (&grpc_static_mdstr_table[80]) |
||||
/* "trailers" */ |
||||
#define GRPC_MDSTR_TRAILERS (&grpc_static_mdstr_table[81]) |
||||
/* "transfer-encoding" */ |
||||
#define GRPC_MDSTR_TRANSFER_ENCODING (&grpc_static_mdstr_table[82]) |
||||
/* "user-agent" */ |
||||
#define GRPC_MDSTR_USER_AGENT (&grpc_static_mdstr_table[83]) |
||||
/* "vary" */ |
||||
#define GRPC_MDSTR_VARY (&grpc_static_mdstr_table[84]) |
||||
/* "via" */ |
||||
#define GRPC_MDSTR_VIA (&grpc_static_mdstr_table[85]) |
||||
/* "www-authenticate" */ |
||||
#define GRPC_MDSTR_WWW_AUTHENTICATE (&grpc_static_mdstr_table[86]) |
||||
|
||||
#define GRPC_STATIC_MDELEM_COUNT 78 |
||||
extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; |
||||
extern gpr_uintptr grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; |
||||
/* "accept-charset": "" */ |
||||
#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY (&grpc_static_mdelem_table[0]) |
||||
/* "accept": "" */ |
||||
#define GRPC_MDELEM_ACCEPT_EMPTY (&grpc_static_mdelem_table[1]) |
||||
/* "accept-encoding": "" */ |
||||
#define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY (&grpc_static_mdelem_table[2]) |
||||
/* "accept-encoding": "gzip, deflate" */ |
||||
#define GRPC_MDELEM_ACCEPT_ENCODING_GZIP_COMMA_DEFLATE \ |
||||
(&grpc_static_mdelem_table[3]) |
||||
/* "accept-language": "" */ |
||||
#define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY (&grpc_static_mdelem_table[4]) |
||||
/* "accept-ranges": "" */ |
||||
#define GRPC_MDELEM_ACCEPT_RANGES_EMPTY (&grpc_static_mdelem_table[5]) |
||||
/* "access-control-allow-origin": "" */ |
||||
#define GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY \ |
||||
(&grpc_static_mdelem_table[6]) |
||||
/* "age": "" */ |
||||
#define GRPC_MDELEM_AGE_EMPTY (&grpc_static_mdelem_table[7]) |
||||
/* "allow": "" */ |
||||
#define GRPC_MDELEM_ALLOW_EMPTY (&grpc_static_mdelem_table[8]) |
||||
/* ":authority": "" */ |
||||
#define GRPC_MDELEM_AUTHORITY_EMPTY (&grpc_static_mdelem_table[9]) |
||||
/* "authorization": "" */ |
||||
#define GRPC_MDELEM_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[10]) |
||||
/* "cache-control": "" */ |
||||
#define GRPC_MDELEM_CACHE_CONTROL_EMPTY (&grpc_static_mdelem_table[11]) |
||||
/* "content-disposition": "" */ |
||||
#define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY (&grpc_static_mdelem_table[12]) |
||||
/* "content-encoding": "" */ |
||||
#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY (&grpc_static_mdelem_table[13]) |
||||
/* "content-language": "" */ |
||||
#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY (&grpc_static_mdelem_table[14]) |
||||
/* "content-length": "" */ |
||||
#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY (&grpc_static_mdelem_table[15]) |
||||
/* "content-location": "" */ |
||||
#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY (&grpc_static_mdelem_table[16]) |
||||
/* "content-range": "" */ |
||||
#define GRPC_MDELEM_CONTENT_RANGE_EMPTY (&grpc_static_mdelem_table[17]) |
||||
/* "content-type": "application/grpc" */ |
||||
#define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ |
||||
(&grpc_static_mdelem_table[18]) |
||||
/* "content-type": "" */ |
||||
#define GRPC_MDELEM_CONTENT_TYPE_EMPTY (&grpc_static_mdelem_table[19]) |
||||
/* "cookie": "" */ |
||||
#define GRPC_MDELEM_COOKIE_EMPTY (&grpc_static_mdelem_table[20]) |
||||
/* "date": "" */ |
||||
#define GRPC_MDELEM_DATE_EMPTY (&grpc_static_mdelem_table[21]) |
||||
/* "etag": "" */ |
||||
#define GRPC_MDELEM_ETAG_EMPTY (&grpc_static_mdelem_table[22]) |
||||
/* "expect": "" */ |
||||
#define GRPC_MDELEM_EXPECT_EMPTY (&grpc_static_mdelem_table[23]) |
||||
/* "expires": "" */ |
||||
#define GRPC_MDELEM_EXPIRES_EMPTY (&grpc_static_mdelem_table[24]) |
||||
/* "from": "" */ |
||||
#define GRPC_MDELEM_FROM_EMPTY (&grpc_static_mdelem_table[25]) |
||||
/* "grpc-accept-encoding": "deflate" */ |
||||
#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE (&grpc_static_mdelem_table[26]) |
||||
/* "grpc-accept-encoding": "deflate,gzip" */ |
||||
#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ |
||||
(&grpc_static_mdelem_table[27]) |
||||
/* "grpc-accept-encoding": "gzip" */ |
||||
#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP (&grpc_static_mdelem_table[28]) |
||||
/* "grpc-accept-encoding": "identity" */ |
||||
#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ |
||||
(&grpc_static_mdelem_table[29]) |
||||
/* "grpc-accept-encoding": "identity,deflate" */ |
||||
#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ |
||||
(&grpc_static_mdelem_table[30]) |
||||
/* "grpc-accept-encoding": "identity,deflate,gzip" */ |
||||
#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ |
||||
(&grpc_static_mdelem_table[31]) |
||||
/* "grpc-accept-encoding": "identity,gzip" */ |
||||
#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ |
||||
(&grpc_static_mdelem_table[32]) |
||||
/* "grpc-encoding": "deflate" */ |
||||
#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE (&grpc_static_mdelem_table[33]) |
||||
/* "grpc-encoding": "gzip" */ |
||||
#define GRPC_MDELEM_GRPC_ENCODING_GZIP (&grpc_static_mdelem_table[34]) |
||||
/* "grpc-encoding": "identity" */ |
||||
#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY (&grpc_static_mdelem_table[35]) |
||||
/* "grpc-status": "0" */ |
||||
#define GRPC_MDELEM_GRPC_STATUS_0 (&grpc_static_mdelem_table[36]) |
||||
/* "grpc-status": "1" */ |
||||
#define GRPC_MDELEM_GRPC_STATUS_1 (&grpc_static_mdelem_table[37]) |
||||
/* "grpc-status": "2" */ |
||||
#define GRPC_MDELEM_GRPC_STATUS_2 (&grpc_static_mdelem_table[38]) |
||||
/* "host": "" */ |
||||
#define GRPC_MDELEM_HOST_EMPTY (&grpc_static_mdelem_table[39]) |
||||
/* "if-match": "" */ |
||||
#define GRPC_MDELEM_IF_MATCH_EMPTY (&grpc_static_mdelem_table[40]) |
||||
/* "if-modified-since": "" */ |
||||
#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY (&grpc_static_mdelem_table[41]) |
||||
/* "if-none-match": "" */ |
||||
#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY (&grpc_static_mdelem_table[42]) |
||||
/* "if-range": "" */ |
||||
#define GRPC_MDELEM_IF_RANGE_EMPTY (&grpc_static_mdelem_table[43]) |
||||
/* "if-unmodified-since": "" */ |
||||
#define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY (&grpc_static_mdelem_table[44]) |
||||
/* "last-modified": "" */ |
||||
#define GRPC_MDELEM_LAST_MODIFIED_EMPTY (&grpc_static_mdelem_table[45]) |
||||
/* "link": "" */ |
||||
#define GRPC_MDELEM_LINK_EMPTY (&grpc_static_mdelem_table[46]) |
||||
/* "location": "" */ |
||||
#define GRPC_MDELEM_LOCATION_EMPTY (&grpc_static_mdelem_table[47]) |
||||
/* "max-forwards": "" */ |
||||
#define GRPC_MDELEM_MAX_FORWARDS_EMPTY (&grpc_static_mdelem_table[48]) |
||||
/* ":method": "GET" */ |
||||
#define GRPC_MDELEM_METHOD_GET (&grpc_static_mdelem_table[49]) |
||||
/* ":method": "POST" */ |
||||
#define GRPC_MDELEM_METHOD_POST (&grpc_static_mdelem_table[50]) |
||||
/* ":path": "/" */ |
||||
#define GRPC_MDELEM_PATH_SLASH (&grpc_static_mdelem_table[51]) |
||||
/* ":path": "/index.html" */ |
||||
#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML (&grpc_static_mdelem_table[52]) |
||||
/* "proxy-authenticate": "" */ |
||||
#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[53]) |
||||
/* "proxy-authorization": "" */ |
||||
#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[54]) |
||||
/* "range": "" */ |
||||
#define GRPC_MDELEM_RANGE_EMPTY (&grpc_static_mdelem_table[55]) |
||||
/* "referer": "" */ |
||||
#define GRPC_MDELEM_REFERER_EMPTY (&grpc_static_mdelem_table[56]) |
||||
/* "refresh": "" */ |
||||
#define GRPC_MDELEM_REFRESH_EMPTY (&grpc_static_mdelem_table[57]) |
||||
/* "retry-after": "" */ |
||||
#define GRPC_MDELEM_RETRY_AFTER_EMPTY (&grpc_static_mdelem_table[58]) |
||||
/* ":scheme": "grpc" */ |
||||
#define GRPC_MDELEM_SCHEME_GRPC (&grpc_static_mdelem_table[59]) |
||||
/* ":scheme": "http" */ |
||||
#define GRPC_MDELEM_SCHEME_HTTP (&grpc_static_mdelem_table[60]) |
||||
/* ":scheme": "https" */ |
||||
#define GRPC_MDELEM_SCHEME_HTTPS (&grpc_static_mdelem_table[61]) |
||||
/* "server": "" */ |
||||
#define GRPC_MDELEM_SERVER_EMPTY (&grpc_static_mdelem_table[62]) |
||||
/* "set-cookie": "" */ |
||||
#define GRPC_MDELEM_SET_COOKIE_EMPTY (&grpc_static_mdelem_table[63]) |
||||
/* ":status": "200" */ |
||||
#define GRPC_MDELEM_STATUS_200 (&grpc_static_mdelem_table[64]) |
||||
/* ":status": "204" */ |
||||
#define GRPC_MDELEM_STATUS_204 (&grpc_static_mdelem_table[65]) |
||||
/* ":status": "206" */ |
||||
#define GRPC_MDELEM_STATUS_206 (&grpc_static_mdelem_table[66]) |
||||
/* ":status": "304" */ |
||||
#define GRPC_MDELEM_STATUS_304 (&grpc_static_mdelem_table[67]) |
||||
/* ":status": "400" */ |
||||
#define GRPC_MDELEM_STATUS_400 (&grpc_static_mdelem_table[68]) |
||||
/* ":status": "404" */ |
||||
#define GRPC_MDELEM_STATUS_404 (&grpc_static_mdelem_table[69]) |
||||
/* ":status": "500" */ |
||||
#define GRPC_MDELEM_STATUS_500 (&grpc_static_mdelem_table[70]) |
||||
/* "strict-transport-security": "" */ |
||||
#define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY \ |
||||
(&grpc_static_mdelem_table[71]) |
||||
/* "te": "trailers" */ |
||||
#define GRPC_MDELEM_TE_TRAILERS (&grpc_static_mdelem_table[72]) |
||||
/* "transfer-encoding": "" */ |
||||
#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY (&grpc_static_mdelem_table[73]) |
||||
/* "user-agent": "" */ |
||||
#define GRPC_MDELEM_USER_AGENT_EMPTY (&grpc_static_mdelem_table[74]) |
||||
/* "vary": "" */ |
||||
#define GRPC_MDELEM_VARY_EMPTY (&grpc_static_mdelem_table[75]) |
||||
/* "via": "" */ |
||||
#define GRPC_MDELEM_VIA_EMPTY (&grpc_static_mdelem_table[76]) |
||||
/* "www-authenticate": "" */ |
||||
#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[77]) |
||||
|
||||
extern const gpr_uint8 |
||||
grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2]; |
||||
extern const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT]; |
||||
extern const gpr_uint8 grpc_static_accept_encoding_metadata[8]; |
||||
#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ |
||||
(&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]]) |
||||
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_STATIC_METADATA_H */ |
@ -0,0 +1,3 @@ |
||||
bin |
||||
obj |
||||
|
@ -0,0 +1,60 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProjectGuid>{B82B7DFE-7F7B-40EF-B3D6-064FF2B01294}</ProjectGuid> |
||||
<OutputType>Exe</OutputType> |
||||
<RootNamespace>Grpc.IntegrationTesting.QpsWorker</RootNamespace> |
||||
<AssemblyName>Grpc.IntegrationTesting.QpsWorker</AssemblyName> |
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Debug</OutputPath> |
||||
<DefineConstants>DEBUG;</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<PlatformTarget>AnyCPU</PlatformTarget> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\Release</OutputPath> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<PlatformTarget>AnyCPU</PlatformTarget> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseSigned|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\ReleaseSigned</OutputPath> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<SignAssembly>True</SignAssembly> |
||||
<AssemblyOriginatorKeyFile>C:\keys\Grpc.snk</AssemblyOriginatorKeyFile> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="..\Grpc.Core\Version.cs"> |
||||
<Link>Version.cs</Link> |
||||
</Compile> |
||||
<Compile Include="Program.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\Grpc.Core\Grpc.Core.csproj"> |
||||
<Project>{CCC4440E-49F7-4790-B0AF-FEABB0837AE7}</Project> |
||||
<Name>Grpc.Core</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\Grpc.IntegrationTesting\Grpc.IntegrationTesting.csproj"> |
||||
<Project>{C61154BA-DD4A-4838-8420-0162A28925E0}</Project> |
||||
<Name>Grpc.IntegrationTesting</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
</Project> |
@ -0,0 +1,76 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using Google.Protobuf; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Utils; |
||||
|
||||
namespace Grpc.Testing |
||||
{ |
||||
/// <summary> |
||||
/// Implementation of BenchmarkService server |
||||
/// </summary> |
||||
public class BenchmarkServiceImpl : BenchmarkService.IBenchmarkService |
||||
{ |
||||
private readonly int responseSize; |
||||
|
||||
public BenchmarkServiceImpl(int responseSize) |
||||
{ |
||||
this.responseSize = responseSize; |
||||
} |
||||
|
||||
public Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context) |
||||
{ |
||||
var response = new SimpleResponse { Payload = CreateZerosPayload(responseSize) }; |
||||
return Task.FromResult(response); |
||||
} |
||||
|
||||
public async Task StreamingCall(IAsyncStreamReader<SimpleRequest> requestStream, IServerStreamWriter<SimpleResponse> responseStream, ServerCallContext context) |
||||
{ |
||||
await requestStream.ForEachAsync(async request => |
||||
{ |
||||
var response = new SimpleResponse { Payload = CreateZerosPayload(responseSize) }; |
||||
await responseStream.WriteAsync(response); |
||||
}); |
||||
} |
||||
|
||||
private static Payload CreateZerosPayload(int size) |
||||
{ |
||||
return new Payload { Body = ByteString.CopyFrom(new byte[size]) }; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,153 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using Google.Protobuf; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Utils; |
||||
using NUnit.Framework; |
||||
using Grpc.Testing; |
||||
|
||||
namespace Grpc.IntegrationTesting |
||||
{ |
||||
/// <summary> |
||||
/// Helper methods to start client runners for performance testing. |
||||
/// </summary> |
||||
public static class ClientRunners |
||||
{ |
||||
/// <summary> |
||||
/// Creates a started client runner. |
||||
/// </summary> |
||||
public static IClientRunner CreateStarted(ClientConfig config) |
||||
{ |
||||
string target = config.ServerTargets.Single(); |
||||
Grpc.Core.Utils.Preconditions.CheckArgument(config.LoadParams.LoadCase == LoadParams.LoadOneofCase.ClosedLoop); |
||||
|
||||
var credentials = config.SecurityParams != null ? TestCredentials.CreateSslCredentials() : ChannelCredentials.Insecure; |
||||
var channel = new Channel(target, credentials); |
||||
|
||||
switch (config.RpcType) |
||||
{ |
||||
case RpcType.UNARY: |
||||
return new SyncUnaryClientRunner(channel, |
||||
config.PayloadConfig.SimpleParams.ReqSize, |
||||
config.HistogramParams); |
||||
|
||||
case RpcType.STREAMING: |
||||
default: |
||||
throw new ArgumentException("Unsupported RpcType."); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Client that starts synchronous unary calls in a closed loop. |
||||
/// </summary> |
||||
public class SyncUnaryClientRunner : IClientRunner |
||||
{ |
||||
const double SecondsToNanos = 1e9; |
||||
|
||||
readonly Channel channel; |
||||
readonly int payloadSize; |
||||
readonly Histogram histogram; |
||||
|
||||
readonly BenchmarkService.IBenchmarkServiceClient client; |
||||
readonly Task runnerTask; |
||||
readonly CancellationTokenSource stoppedCts; |
||||
readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch(); |
||||
|
||||
public SyncUnaryClientRunner(Channel channel, int payloadSize, HistogramParams histogramParams) |
||||
{ |
||||
this.channel = Grpc.Core.Utils.Preconditions.CheckNotNull(channel); |
||||
this.payloadSize = payloadSize; |
||||
this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible); |
||||
|
||||
this.stoppedCts = new CancellationTokenSource(); |
||||
this.client = BenchmarkService.NewClient(channel); |
||||
this.runnerTask = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning); |
||||
} |
||||
|
||||
public ClientStats GetStats(bool reset) |
||||
{ |
||||
var histogramData = histogram.GetSnapshot(reset); |
||||
var secondsElapsed = wallClockStopwatch.GetElapsedSnapshot(reset).TotalSeconds; |
||||
|
||||
// TODO: populate user time and system time |
||||
return new ClientStats |
||||
{ |
||||
Latencies = histogramData, |
||||
TimeElapsed = secondsElapsed, |
||||
TimeUser = 0, |
||||
TimeSystem = 0 |
||||
}; |
||||
} |
||||
|
||||
public async Task StopAsync() |
||||
{ |
||||
stoppedCts.Cancel(); |
||||
await runnerTask; |
||||
await channel.ShutdownAsync(); |
||||
} |
||||
|
||||
private void Run() |
||||
{ |
||||
var request = new SimpleRequest |
||||
{ |
||||
Payload = CreateZerosPayload(payloadSize) |
||||
}; |
||||
var stopwatch = new Stopwatch(); |
||||
|
||||
while (!stoppedCts.Token.IsCancellationRequested) |
||||
{ |
||||
stopwatch.Restart(); |
||||
client.UnaryCall(request); |
||||
stopwatch.Stop(); |
||||
|
||||
// spec requires data point in nanoseconds. |
||||
histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); |
||||
} |
||||
} |
||||
|
||||
private static Payload CreateZerosPayload(int size) |
||||
{ |
||||
return new Payload { Body = ByteString.CopyFrom(new byte[size]) }; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue