forked from mystiq/dex
*: revendor
This commit is contained in:
parent
2cc197b8a4
commit
0be8cc723a
141 changed files with 30027 additions and 2 deletions
20
glide.lock
generated
20
glide.lock
generated
|
@ -1,5 +1,5 @@
|
||||||
hash: 149c717bc83cc279ab6192364776b8c1b6bad8a620ce9d64c56d946276630437
|
hash: 8b7a5f94584ecd144fc3ce94bb0b09f8e96c94b5a8e10d5053bd24bb597367ce
|
||||||
updated: 2016-09-30T21:01:57.607704513-07:00
|
updated: 2016-10-03T23:25:41.280181088-07:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/cockroachdb/cockroach-go
|
- name: github.com/cockroachdb/cockroach-go
|
||||||
version: 31611c0501c812f437d4861d87d117053967c955
|
version: 31611c0501c812f437d4861d87d117053967c955
|
||||||
|
@ -52,6 +52,11 @@ imports:
|
||||||
version: 6a513affb38dc9788b449d59ffed099b8de18fa0
|
version: 6a513affb38dc9788b449d59ffed099b8de18fa0
|
||||||
subpackages:
|
subpackages:
|
||||||
- context
|
- context
|
||||||
|
- http2
|
||||||
|
- http2/hpack
|
||||||
|
- internal/timeseries
|
||||||
|
- lex/httplex
|
||||||
|
- trace
|
||||||
- name: golang.org/x/oauth2
|
- name: golang.org/x/oauth2
|
||||||
version: 08c8d727d2392d18286f9f88ad775ad98f09ab33
|
version: 08c8d727d2392d18286f9f88ad775ad98f09ab33
|
||||||
subpackages:
|
subpackages:
|
||||||
|
@ -67,6 +72,17 @@ imports:
|
||||||
- internal/remote_api
|
- internal/remote_api
|
||||||
- internal/urlfetch
|
- internal/urlfetch
|
||||||
- urlfetch
|
- urlfetch
|
||||||
|
- name: google.golang.org/grpc
|
||||||
|
version: b1a2821ca5a4fd6b6e48ddfbb7d6d7584d839d21
|
||||||
|
subpackages:
|
||||||
|
- codes
|
||||||
|
- credentials
|
||||||
|
- grpclog
|
||||||
|
- internal
|
||||||
|
- metadata
|
||||||
|
- naming
|
||||||
|
- peer
|
||||||
|
- transport
|
||||||
- name: gopkg.in/asn1-ber.v1
|
- name: gopkg.in/asn1-ber.v1
|
||||||
version: 4e86f4367175e39f69d9358a5f17b4dda270378d
|
version: 4e86f4367175e39f69d9358a5f17b4dda270378d
|
||||||
- name: gopkg.in/ldap.v2
|
- name: gopkg.in/ldap.v2
|
||||||
|
|
18
vendor/google.golang.org/grpc/.travis.yml
generated
vendored
Normal file
18
vendor/google.golang.org/grpc/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
language: go
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.5.4
|
||||||
|
- 1.6.3
|
||||||
|
- 1.7
|
||||||
|
|
||||||
|
go_import_path: google.golang.org/grpc
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- go get -u golang.org/x/tools/cmd/goimports github.com/golang/lint/golint github.com/axw/gocov/gocov github.com/mattn/goveralls golang.org/x/tools/cmd/cover
|
||||||
|
|
||||||
|
script:
|
||||||
|
- '! gofmt -s -d -l . 2>&1 | read'
|
||||||
|
- '! goimports -l . | read'
|
||||||
|
- '! golint ./... | grep -vE "(_string|\.pb)\.go:"'
|
||||||
|
- '! go tool vet -all . 2>&1 | grep -vE "constant [0-9]+ not a string in call to Errorf" | grep -vF .pb.go:' # https://github.com/golang/protobuf/issues/214
|
||||||
|
- make test testrace
|
46
vendor/google.golang.org/grpc/CONTRIBUTING.md
generated
vendored
Normal file
46
vendor/google.golang.org/grpc/CONTRIBUTING.md
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# How to contribute
|
||||||
|
|
||||||
|
We definitely welcome patches and contribution to grpc! Here are some guidelines
|
||||||
|
and information about how to do so.
|
||||||
|
|
||||||
|
## Sending patches
|
||||||
|
|
||||||
|
### Getting started
|
||||||
|
|
||||||
|
1. Check out the code:
|
||||||
|
|
||||||
|
$ go get google.golang.org/grpc
|
||||||
|
$ cd $GOPATH/src/google.golang.org/grpc
|
||||||
|
|
||||||
|
1. Create a fork of the grpc-go repository.
|
||||||
|
1. Add your fork as a remote:
|
||||||
|
|
||||||
|
$ git remote add fork git@github.com:$YOURGITHUBUSERNAME/grpc-go.git
|
||||||
|
|
||||||
|
1. Make changes, commit them.
|
||||||
|
1. Run the test suite:
|
||||||
|
|
||||||
|
$ make test
|
||||||
|
|
||||||
|
1. Push your changes to your fork:
|
||||||
|
|
||||||
|
$ git push fork ...
|
||||||
|
|
||||||
|
1. Open a pull request.
|
||||||
|
|
||||||
|
## Legal requirements
|
||||||
|
|
||||||
|
In order to protect both you and ourselves, you will need to sign the
|
||||||
|
[Contributor License Agreement](https://cla.developers.google.com/clas).
|
||||||
|
|
||||||
|
## Filing Issues
|
||||||
|
When filing an issue, make sure to answer these five questions:
|
||||||
|
|
||||||
|
1. What version of Go are you using (`go version`)?
|
||||||
|
2. What operating system and processor architecture are you using?
|
||||||
|
3. What did you do?
|
||||||
|
4. What did you expect to see?
|
||||||
|
5. What did you see instead?
|
||||||
|
|
||||||
|
### Contributing code
|
||||||
|
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
|
41
vendor/google.golang.org/grpc/Documentation/grpc-auth-support.md
generated
vendored
Normal file
41
vendor/google.golang.org/grpc/Documentation/grpc-auth-support.md
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# Authentication
|
||||||
|
|
||||||
|
As outlined in the [gRPC authentication guide](http://www.grpc.io/docs/guides/auth.html) there are a number of different mechanisms for asserting identity between an client and server. We'll present some code-samples here demonstrating how to provide TLS support encryption and identity assertions as well as passing OAuth2 tokens to services that support it.
|
||||||
|
|
||||||
|
# Enabling TLS on a gRPC client
|
||||||
|
|
||||||
|
```Go
|
||||||
|
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")))
|
||||||
|
```
|
||||||
|
|
||||||
|
# Enabling TLS on a gRPC server
|
||||||
|
|
||||||
|
```Go
|
||||||
|
creds, err := credentials.NewServerTLSFromFile(certFile, keyFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to generate credentials %v", err)
|
||||||
|
}
|
||||||
|
lis, err := net.Listen("tcp", ":0")
|
||||||
|
server := grpc.NewServer(grpc.Creds(creds))
|
||||||
|
...
|
||||||
|
server.Serve(lis)
|
||||||
|
```
|
||||||
|
|
||||||
|
# Authenticating with Google
|
||||||
|
|
||||||
|
## Google Compute Engine (GCE)
|
||||||
|
|
||||||
|
```Go
|
||||||
|
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""), grpc.WithPerRPCCredentials(oauth.NewComputeEngine())))
|
||||||
|
```
|
||||||
|
|
||||||
|
## JWT
|
||||||
|
|
||||||
|
```Go
|
||||||
|
jwtCreds, err := oauth.NewServiceAccountFromFile(*serviceAccountKeyFile, *oauthScope)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create JWT credentials: %v", err)
|
||||||
|
}
|
||||||
|
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""), grpc.WithPerRPCCredentials(jwtCreds)))
|
||||||
|
```
|
||||||
|
|
201
vendor/google.golang.org/grpc/Documentation/grpc-metadata.md
generated
vendored
Normal file
201
vendor/google.golang.org/grpc/Documentation/grpc-metadata.md
generated
vendored
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
# Metadata
|
||||||
|
|
||||||
|
gRPC supports sending metadata between client and server.
|
||||||
|
This doc shows how to send and receive metadata in gRPC-go.
|
||||||
|
|
||||||
|
## Background
|
||||||
|
|
||||||
|
Four kinds of service method:
|
||||||
|
|
||||||
|
- [Unary RPC](http://www.grpc.io/docs/guides/concepts.html#unary-rpc)
|
||||||
|
- [Server streaming RPC](http://www.grpc.io/docs/guides/concepts.html#server-streaming-rpc)
|
||||||
|
- [Client streaming RPC](http://www.grpc.io/docs/guides/concepts.html#client-streaming-rpc)
|
||||||
|
- [Bidirectional streaming RPC](http://www.grpc.io/docs/guides/concepts.html#bidirectional-streaming-rpc)
|
||||||
|
|
||||||
|
And concept of [metadata](http://www.grpc.io/docs/guides/concepts.html#metadata).
|
||||||
|
|
||||||
|
## Constructing metadata
|
||||||
|
|
||||||
|
A metadata can be created using package [metadata](https://godoc.org/google.golang.org/grpc/metadata).
|
||||||
|
The type MD is actually a map from string to a list of strings:
|
||||||
|
|
||||||
|
```go
|
||||||
|
type MD map[string][]string
|
||||||
|
```
|
||||||
|
|
||||||
|
Metadata can be read like a normal map.
|
||||||
|
Note that the value type of this map is `[]string`,
|
||||||
|
so that users can attach multiple values using a single key.
|
||||||
|
|
||||||
|
### Creating a new metadata
|
||||||
|
|
||||||
|
A metadata can be created from a `map[string]string` using function `New`:
|
||||||
|
|
||||||
|
```go
|
||||||
|
md := metadata.New(map[string]string{"key1": "val1", "key2": "val2"})
|
||||||
|
```
|
||||||
|
|
||||||
|
Another way is to use `Pairs`.
|
||||||
|
Values with the same key will be merged into a list:
|
||||||
|
|
||||||
|
```go
|
||||||
|
md := metadata.Pairs(
|
||||||
|
"key1", "val1",
|
||||||
|
"key1", "val1-2", // "key1" will have map value []string{"val1", "val1-2"}
|
||||||
|
"key2", "val2",
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
__Note:__ all the keys will be automatically converted to lowercase,
|
||||||
|
so "key1" and "kEy1" will be the same key and their values will be merged into the same list.
|
||||||
|
This happens for both `New` and `Pairs`.
|
||||||
|
|
||||||
|
### Storing binary data in metadata
|
||||||
|
|
||||||
|
In metadata, keys are always strings. But values can be strings or binary data.
|
||||||
|
To store binary data value in metadata, simply add "-bin" suffix to the key.
|
||||||
|
The values with "-bin" suffixed keys will be encoded when creating the metadata:
|
||||||
|
|
||||||
|
```go
|
||||||
|
md := metadata.Pairs(
|
||||||
|
"key", "string value",
|
||||||
|
"key-bin", string([]byte{96, 102}), // this binary data will be encoded (base64) before sending
|
||||||
|
// and will be decoded after being transferred.
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Retrieving metadata from context
|
||||||
|
|
||||||
|
Metadata can be retrieved from context using `FromContext`:
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *server) SomeRPC(ctx context.Context, in *pb.SomeRequest) (*pb.SomeResponse, err) {
|
||||||
|
md, ok := metadata.FromContext(ctx)
|
||||||
|
// do something with metadata
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sending and receiving metadata - client side
|
||||||
|
|
||||||
|
[//]: # "TODO: uncomment next line after example source added"
|
||||||
|
[//]: # "Real metadata sending and receiving examples are available [here](TODO:example_dir)."
|
||||||
|
|
||||||
|
### Sending metadata
|
||||||
|
|
||||||
|
To send metadata to server, the client can wrap the metadata into a context using `NewContext`, and make the RPC with this context:
|
||||||
|
|
||||||
|
```go
|
||||||
|
md := metadata.Pairs("key", "val")
|
||||||
|
|
||||||
|
// create a new context with this metadata
|
||||||
|
ctx := metadata.NewContext(context.Background(), md)
|
||||||
|
|
||||||
|
// make unary RPC
|
||||||
|
response, err := client.SomeRPC(ctx, someRequest)
|
||||||
|
|
||||||
|
// or make streaming RPC
|
||||||
|
stream, err := client.SomeStreamingRPC(ctx)
|
||||||
|
```
|
||||||
|
### Receiving metadata
|
||||||
|
|
||||||
|
Metadata that a client can receive includes header and trailer.
|
||||||
|
|
||||||
|
#### Unary call
|
||||||
|
|
||||||
|
Header and trailer sent along with a unary call can be retrieved using function [Header](https://godoc.org/google.golang.org/grpc#Header) and [Trailer](https://godoc.org/google.golang.org/grpc#Trailer) in [CallOption](https://godoc.org/google.golang.org/grpc#CallOption):
|
||||||
|
|
||||||
|
```go
|
||||||
|
var header, trailer metadata.MD // variable to store header and trailer
|
||||||
|
r, err := client.SomeRPC(
|
||||||
|
ctx,
|
||||||
|
someRequest,
|
||||||
|
grpc.Header(&header), // will retrieve header
|
||||||
|
grpc.Trailer(&trailer), // will retrieve trailer
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with header and trailer
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Streaming call
|
||||||
|
|
||||||
|
For streaming calls including:
|
||||||
|
|
||||||
|
- Server streaming RPC
|
||||||
|
- Client streaming RPC
|
||||||
|
- Bidirectional streaming RPC
|
||||||
|
|
||||||
|
Header and trailer can be retrieved from the returned stream using function `Header` and `Trailer` in interface [ClientStream](https://godoc.org/google.golang.org/grpc#ClientStream):
|
||||||
|
|
||||||
|
```go
|
||||||
|
stream, err := client.SomeStreamingRPC(ctx)
|
||||||
|
|
||||||
|
// retrieve header
|
||||||
|
header, err := stream.Header()
|
||||||
|
|
||||||
|
// retrieve trailer
|
||||||
|
trailer := stream.Trailer()
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sending and receiving metadata - server side
|
||||||
|
|
||||||
|
[//]: # "TODO: uncomment next line after example source added"
|
||||||
|
[//]: # "Real metadata sending and receiving examples are available [here](TODO:example_dir)."
|
||||||
|
|
||||||
|
### Receiving metadata
|
||||||
|
|
||||||
|
To read metadata sent by the client, the server needs to retrieve it from RPC context.
|
||||||
|
If it is a unary call, the RPC handler's context can be used.
|
||||||
|
For streaming calls, the server needs to get context from the stream.
|
||||||
|
|
||||||
|
#### Unary call
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *server) SomeRPC(ctx context.Context, in *pb.someRequest) (*pb.someResponse, error) {
|
||||||
|
md, ok := metadata.FromContext(ctx)
|
||||||
|
// do something with metadata
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Streaming call
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *server) SomeStreamingRPC(stream pb.Service_SomeStreamingRPCServer) error {
|
||||||
|
md, ok := metadata.FromContext(stream.Context()) // get context from stream
|
||||||
|
// do something with metadata
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sending metadata
|
||||||
|
|
||||||
|
#### Unary call
|
||||||
|
|
||||||
|
To send header and trailer to client in unary call, the server can call [SendHeader](https://godoc.org/google.golang.org/grpc#SendHeader) and [SetTrailer](https://godoc.org/google.golang.org/grpc#SetTrailer) functions in module [grpc](https://godoc.org/google.golang.org/grpc).
|
||||||
|
These two functions take a context as the first parameter.
|
||||||
|
It should be the RPC handler's context or one derived from it:
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *server) SomeRPC(ctx context.Context, in *pb.someRequest) (*pb.someResponse, error) {
|
||||||
|
// create and send header
|
||||||
|
header := metadata.Pairs("header-key", "val")
|
||||||
|
grpc.SendHeader(ctx, header)
|
||||||
|
// create and set trailer
|
||||||
|
trailer := metadata.Pairs("trailer-key", "val")
|
||||||
|
grpc.SetTrailer(ctx, trailer)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Streaming call
|
||||||
|
|
||||||
|
For streaming calls, header and trailer can be sent using function `SendHeader` and `SetTrailer` in interface [ServerStream](https://godoc.org/google.golang.org/grpc#ServerStream):
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *server) SomeStreamingRPC(stream pb.Service_SomeStreamingRPCServer) error {
|
||||||
|
// create and send header
|
||||||
|
header := metadata.Pairs("header-key", "val")
|
||||||
|
stream.SendHeader(header)
|
||||||
|
// create and set trailer
|
||||||
|
trailer := metadata.Pairs("trailer-key", "val")
|
||||||
|
stream.SetTrailer(trailer)
|
||||||
|
}
|
||||||
|
```
|
28
vendor/google.golang.org/grpc/LICENSE
generated
vendored
Normal file
28
vendor/google.golang.org/grpc/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
Copyright 2014, 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.
|
52
vendor/google.golang.org/grpc/Makefile
generated
vendored
Normal file
52
vendor/google.golang.org/grpc/Makefile
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
all: test testrace
|
||||||
|
|
||||||
|
deps:
|
||||||
|
go get -d -v google.golang.org/grpc/...
|
||||||
|
|
||||||
|
updatedeps:
|
||||||
|
go get -d -v -u -f google.golang.org/grpc/...
|
||||||
|
|
||||||
|
testdeps:
|
||||||
|
go get -d -v -t google.golang.org/grpc/...
|
||||||
|
|
||||||
|
updatetestdeps:
|
||||||
|
go get -d -v -t -u -f google.golang.org/grpc/...
|
||||||
|
|
||||||
|
build: deps
|
||||||
|
go build google.golang.org/grpc/...
|
||||||
|
|
||||||
|
proto:
|
||||||
|
@ if ! which protoc > /dev/null; then \
|
||||||
|
echo "error: protoc not installed" >&2; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
go get -u -v github.com/golang/protobuf/protoc-gen-go
|
||||||
|
# use $$dir as the root for all proto files in the same directory
|
||||||
|
for dir in $$(git ls-files '*.proto' | xargs -n1 dirname | uniq); do \
|
||||||
|
protoc -I $$dir --go_out=plugins=grpc:$$dir $$dir/*.proto; \
|
||||||
|
done
|
||||||
|
|
||||||
|
test: testdeps
|
||||||
|
go test -v -cpu 1,4 google.golang.org/grpc/...
|
||||||
|
|
||||||
|
testrace: testdeps
|
||||||
|
go test -v -race -cpu 1,4 google.golang.org/grpc/...
|
||||||
|
|
||||||
|
clean:
|
||||||
|
go clean -i google.golang.org/grpc/...
|
||||||
|
|
||||||
|
coverage: testdeps
|
||||||
|
./coverage.sh --coveralls
|
||||||
|
|
||||||
|
.PHONY: \
|
||||||
|
all \
|
||||||
|
deps \
|
||||||
|
updatedeps \
|
||||||
|
testdeps \
|
||||||
|
updatetestdeps \
|
||||||
|
build \
|
||||||
|
proto \
|
||||||
|
test \
|
||||||
|
testrace \
|
||||||
|
clean \
|
||||||
|
coverage
|
22
vendor/google.golang.org/grpc/PATENTS
generated
vendored
Normal file
22
vendor/google.golang.org/grpc/PATENTS
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
Additional IP Rights Grant (Patents)
|
||||||
|
|
||||||
|
"This implementation" means the copyrightable works distributed by
|
||||||
|
Google as part of the gRPC project.
|
||||||
|
|
||||||
|
Google hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||||
|
no-charge, royalty-free, irrevocable (except as stated in this section)
|
||||||
|
patent license to make, have made, use, offer to sell, sell, import,
|
||||||
|
transfer and otherwise run, modify and propagate the contents of this
|
||||||
|
implementation of gRPC, where such license applies only to those patent
|
||||||
|
claims, both currently owned or controlled by Google and acquired in
|
||||||
|
the future, licensable by Google that are necessarily infringed by this
|
||||||
|
implementation of gRPC. This grant does not include claims that would be
|
||||||
|
infringed only as a consequence of further modification of this
|
||||||
|
implementation. If you or your agent or exclusive licensee institute or
|
||||||
|
order or agree to the institution of patent litigation against any
|
||||||
|
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||||
|
that this implementation of gRPC or any code incorporated within this
|
||||||
|
implementation of gRPC constitutes direct or contributory patent
|
||||||
|
infringement, or inducement of patent infringement, then any patent
|
||||||
|
rights granted to you under this License for this implementation of gRPC
|
||||||
|
shall terminate as of the date such litigation is filed.
|
32
vendor/google.golang.org/grpc/README.md
generated
vendored
Normal file
32
vendor/google.golang.org/grpc/README.md
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#gRPC-Go
|
||||||
|
|
||||||
|
[![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go) [![GoDoc](https://godoc.org/google.golang.org/grpc?status.svg)](https://godoc.org/google.golang.org/grpc)
|
||||||
|
|
||||||
|
The Go implementation of [gRPC](http://www.grpc.io/): A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the [gRPC Quick Start](http://www.grpc.io/docs/) guide.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
To install this package, you need to install Go and setup your Go workspace on your computer. The simplest way to install the library is to run:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go get google.golang.org/grpc
|
||||||
|
```
|
||||||
|
|
||||||
|
Prerequisites
|
||||||
|
-------------
|
||||||
|
|
||||||
|
This requires Go 1.5 or later .
|
||||||
|
|
||||||
|
Constraints
|
||||||
|
-----------
|
||||||
|
The grpc package should only depend on standard Go packages and a small number of exceptions. If your contribution introduces new dependencies which are NOT in the [list](http://godoc.org/google.golang.org/grpc?imports), you need a discussion with gRPC-Go authors and consultants.
|
||||||
|
|
||||||
|
Documentation
|
||||||
|
-------------
|
||||||
|
See [API documentation](https://godoc.org/google.golang.org/grpc) for package and API descriptions and find examples in the [examples directory](examples/).
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
GA
|
||||||
|
|
80
vendor/google.golang.org/grpc/backoff.go
generated
vendored
Normal file
80
vendor/google.golang.org/grpc/backoff.go
generated
vendored
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DefaultBackoffConfig uses values specified for backoff in
|
||||||
|
// https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.
|
||||||
|
var (
|
||||||
|
DefaultBackoffConfig = BackoffConfig{
|
||||||
|
MaxDelay: 120 * time.Second,
|
||||||
|
baseDelay: 1.0 * time.Second,
|
||||||
|
factor: 1.6,
|
||||||
|
jitter: 0.2,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// backoffStrategy defines the methodology for backing off after a grpc
|
||||||
|
// connection failure.
|
||||||
|
//
|
||||||
|
// This is unexported until the gRPC project decides whether or not to allow
|
||||||
|
// alternative backoff strategies. Once a decision is made, this type and its
|
||||||
|
// method may be exported.
|
||||||
|
type backoffStrategy interface {
|
||||||
|
// backoff returns the amount of time to wait before the next retry given
|
||||||
|
// the number of consecutive failures.
|
||||||
|
backoff(retries int) time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// BackoffConfig defines the parameters for the default gRPC backoff strategy.
|
||||||
|
type BackoffConfig struct {
|
||||||
|
// MaxDelay is the upper bound of backoff delay.
|
||||||
|
MaxDelay time.Duration
|
||||||
|
|
||||||
|
// TODO(stevvooe): The following fields are not exported, as allowing
|
||||||
|
// changes would violate the current gRPC specification for backoff. If
|
||||||
|
// gRPC decides to allow more interesting backoff strategies, these fields
|
||||||
|
// may be opened up in the future.
|
||||||
|
|
||||||
|
// baseDelay is the amount of time to wait before retrying after the first
|
||||||
|
// failure.
|
||||||
|
baseDelay time.Duration
|
||||||
|
|
||||||
|
// factor is applied to the backoff after each retry.
|
||||||
|
factor float64
|
||||||
|
|
||||||
|
// jitter provides a range to randomize backoff delays.
|
||||||
|
jitter float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func setDefaults(bc *BackoffConfig) {
|
||||||
|
md := bc.MaxDelay
|
||||||
|
*bc = DefaultBackoffConfig
|
||||||
|
|
||||||
|
if md > 0 {
|
||||||
|
bc.MaxDelay = md
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc BackoffConfig) backoff(retries int) (t time.Duration) {
|
||||||
|
if retries == 0 {
|
||||||
|
return bc.baseDelay
|
||||||
|
}
|
||||||
|
backoff, max := float64(bc.baseDelay), float64(bc.MaxDelay)
|
||||||
|
for backoff < max && retries > 0 {
|
||||||
|
backoff *= bc.factor
|
||||||
|
retries--
|
||||||
|
}
|
||||||
|
if backoff > max {
|
||||||
|
backoff = max
|
||||||
|
}
|
||||||
|
// Randomize backoff delays so that if a cluster of requests start at
|
||||||
|
// the same time, they won't operate in lockstep.
|
||||||
|
backoff *= 1 + bc.jitter*(rand.Float64()*2-1)
|
||||||
|
if backoff < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return time.Duration(backoff)
|
||||||
|
}
|
11
vendor/google.golang.org/grpc/backoff_test.go
generated
vendored
Normal file
11
vendor/google.golang.org/grpc/backoff_test.go
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestBackoffConfigDefaults(t *testing.T) {
|
||||||
|
b := BackoffConfig{}
|
||||||
|
setDefaults(&b)
|
||||||
|
if b != DefaultBackoffConfig {
|
||||||
|
t.Fatalf("expected BackoffConfig to pickup default parameters: %v != %v", b, DefaultBackoffConfig)
|
||||||
|
}
|
||||||
|
}
|
399
vendor/google.golang.org/grpc/balancer.go
generated
vendored
Normal file
399
vendor/google.golang.org/grpc/balancer.go
generated
vendored
Normal file
|
@ -0,0 +1,399 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/naming"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Address represents a server the client connects to.
|
||||||
|
// This is the EXPERIMENTAL API and may be changed or extended in the future.
|
||||||
|
type Address struct {
|
||||||
|
// Addr is the server address on which a connection will be established.
|
||||||
|
Addr string
|
||||||
|
// Metadata is the information associated with Addr, which may be used
|
||||||
|
// to make load balancing decision.
|
||||||
|
Metadata interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BalancerConfig specifies the configurations for Balancer.
|
||||||
|
type BalancerConfig struct {
|
||||||
|
// DialCreds is the transport credential the Balancer implementation can
|
||||||
|
// use to dial to a remote load balancer server. The Balancer implementations
|
||||||
|
// can ignore this if it does not need to talk to another party securely.
|
||||||
|
DialCreds credentials.TransportCredentials
|
||||||
|
}
|
||||||
|
|
||||||
|
// BalancerGetOptions configures a Get call.
|
||||||
|
// This is the EXPERIMENTAL API and may be changed or extended in the future.
|
||||||
|
type BalancerGetOptions struct {
|
||||||
|
// BlockingWait specifies whether Get should block when there is no
|
||||||
|
// connected address.
|
||||||
|
BlockingWait bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Balancer chooses network addresses for RPCs.
|
||||||
|
// This is the EXPERIMENTAL API and may be changed or extended in the future.
|
||||||
|
type Balancer interface {
|
||||||
|
// Start does the initialization work to bootstrap a Balancer. For example,
|
||||||
|
// this function may start the name resolution and watch the updates. It will
|
||||||
|
// be called when dialing.
|
||||||
|
Start(target string, config BalancerConfig) error
|
||||||
|
// Up informs the Balancer that gRPC has a connection to the server at
|
||||||
|
// addr. It returns down which is called once the connection to addr gets
|
||||||
|
// lost or closed.
|
||||||
|
// TODO: It is not clear how to construct and take advantage of the meaningful error
|
||||||
|
// parameter for down. Need realistic demands to guide.
|
||||||
|
Up(addr Address) (down func(error))
|
||||||
|
// Get gets the address of a server for the RPC corresponding to ctx.
|
||||||
|
// i) If it returns a connected address, gRPC internals issues the RPC on the
|
||||||
|
// connection to this address;
|
||||||
|
// ii) If it returns an address on which the connection is under construction
|
||||||
|
// (initiated by Notify(...)) but not connected, gRPC internals
|
||||||
|
// * fails RPC if the RPC is fail-fast and connection is in the TransientFailure or
|
||||||
|
// Shutdown state;
|
||||||
|
// or
|
||||||
|
// * issues RPC on the connection otherwise.
|
||||||
|
// iii) If it returns an address on which the connection does not exist, gRPC
|
||||||
|
// internals treats it as an error and will fail the corresponding RPC.
|
||||||
|
//
|
||||||
|
// Therefore, the following is the recommended rule when writing a custom Balancer.
|
||||||
|
// If opts.BlockingWait is true, it should return a connected address or
|
||||||
|
// block if there is no connected address. It should respect the timeout or
|
||||||
|
// cancellation of ctx when blocking. If opts.BlockingWait is false (for fail-fast
|
||||||
|
// RPCs), it should return an address it has notified via Notify(...) immediately
|
||||||
|
// instead of blocking.
|
||||||
|
//
|
||||||
|
// The function returns put which is called once the rpc has completed or failed.
|
||||||
|
// put can collect and report RPC stats to a remote load balancer.
|
||||||
|
//
|
||||||
|
// This function should only return the errors Balancer cannot recover by itself.
|
||||||
|
// gRPC internals will fail the RPC if an error is returned.
|
||||||
|
Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error)
|
||||||
|
// Notify returns a channel that is used by gRPC internals to watch the addresses
|
||||||
|
// gRPC needs to connect. The addresses might be from a name resolver or remote
|
||||||
|
// load balancer. gRPC internals will compare it with the existing connected
|
||||||
|
// addresses. If the address Balancer notified is not in the existing connected
|
||||||
|
// addresses, gRPC starts to connect the address. If an address in the existing
|
||||||
|
// connected addresses is not in the notification list, the corresponding connection
|
||||||
|
// is shutdown gracefully. Otherwise, there are no operations to take. Note that
|
||||||
|
// the Address slice must be the full list of the Addresses which should be connected.
|
||||||
|
// It is NOT delta.
|
||||||
|
Notify() <-chan []Address
|
||||||
|
// Close shuts down the balancer.
|
||||||
|
Close() error
|
||||||
|
}
|
||||||
|
|
||||||
|
// downErr implements net.Error. It is constructed by gRPC internals and passed to the down
|
||||||
|
// call of Balancer.
|
||||||
|
type downErr struct {
|
||||||
|
timeout bool
|
||||||
|
temporary bool
|
||||||
|
desc string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e downErr) Error() string { return e.desc }
|
||||||
|
func (e downErr) Timeout() bool { return e.timeout }
|
||||||
|
func (e downErr) Temporary() bool { return e.temporary }
|
||||||
|
|
||||||
|
func downErrorf(timeout, temporary bool, format string, a ...interface{}) downErr {
|
||||||
|
return downErr{
|
||||||
|
timeout: timeout,
|
||||||
|
temporary: temporary,
|
||||||
|
desc: fmt.Sprintf(format, a...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoundRobin returns a Balancer that selects addresses round-robin. It uses r to watch
|
||||||
|
// the name resolution updates and updates the addresses available correspondingly.
|
||||||
|
func RoundRobin(r naming.Resolver) Balancer {
|
||||||
|
return &roundRobin{r: r}
|
||||||
|
}
|
||||||
|
|
||||||
|
type addrInfo struct {
|
||||||
|
addr Address
|
||||||
|
connected bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type roundRobin struct {
|
||||||
|
r naming.Resolver
|
||||||
|
w naming.Watcher
|
||||||
|
addrs []*addrInfo // all the addresses the client should potentially connect
|
||||||
|
mu sync.Mutex
|
||||||
|
addrCh chan []Address // the channel to notify gRPC internals the list of addresses the client should connect to.
|
||||||
|
next int // index of the next address to return for Get()
|
||||||
|
waitCh chan struct{} // the channel to block when there is no connected address available
|
||||||
|
done bool // The Balancer is closed.
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr *roundRobin) watchAddrUpdates() error {
|
||||||
|
updates, err := rr.w.Next()
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Printf("grpc: the naming watcher stops working due to %v.\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rr.mu.Lock()
|
||||||
|
defer rr.mu.Unlock()
|
||||||
|
for _, update := range updates {
|
||||||
|
addr := Address{
|
||||||
|
Addr: update.Addr,
|
||||||
|
Metadata: update.Metadata,
|
||||||
|
}
|
||||||
|
switch update.Op {
|
||||||
|
case naming.Add:
|
||||||
|
var exist bool
|
||||||
|
for _, v := range rr.addrs {
|
||||||
|
if addr == v.addr {
|
||||||
|
exist = true
|
||||||
|
grpclog.Println("grpc: The name resolver wanted to add an existing address: ", addr)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rr.addrs = append(rr.addrs, &addrInfo{addr: addr})
|
||||||
|
case naming.Delete:
|
||||||
|
for i, v := range rr.addrs {
|
||||||
|
if addr == v.addr {
|
||||||
|
copy(rr.addrs[i:], rr.addrs[i+1:])
|
||||||
|
rr.addrs = rr.addrs[:len(rr.addrs)-1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
grpclog.Println("Unknown update.Op ", update.Op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Make a copy of rr.addrs and write it onto rr.addrCh so that gRPC internals gets notified.
|
||||||
|
open := make([]Address, len(rr.addrs))
|
||||||
|
for i, v := range rr.addrs {
|
||||||
|
open[i] = v.addr
|
||||||
|
}
|
||||||
|
if rr.done {
|
||||||
|
return ErrClientConnClosing
|
||||||
|
}
|
||||||
|
rr.addrCh <- open
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr *roundRobin) Start(target string, config BalancerConfig) error {
|
||||||
|
rr.mu.Lock()
|
||||||
|
defer rr.mu.Unlock()
|
||||||
|
if rr.done {
|
||||||
|
return ErrClientConnClosing
|
||||||
|
}
|
||||||
|
if rr.r == nil {
|
||||||
|
// If there is no name resolver installed, it is not needed to
|
||||||
|
// do name resolution. In this case, target is added into rr.addrs
|
||||||
|
// as the only address available and rr.addrCh stays nil.
|
||||||
|
rr.addrs = append(rr.addrs, &addrInfo{addr: Address{Addr: target}})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
w, err := rr.r.Resolve(target)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rr.w = w
|
||||||
|
rr.addrCh = make(chan []Address)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if err := rr.watchAddrUpdates(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Up sets the connected state of addr and sends notification if there are pending
|
||||||
|
// Get() calls.
|
||||||
|
func (rr *roundRobin) Up(addr Address) func(error) {
|
||||||
|
rr.mu.Lock()
|
||||||
|
defer rr.mu.Unlock()
|
||||||
|
var cnt int
|
||||||
|
for _, a := range rr.addrs {
|
||||||
|
if a.addr == addr {
|
||||||
|
if a.connected {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
a.connected = true
|
||||||
|
}
|
||||||
|
if a.connected {
|
||||||
|
cnt++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// addr is only one which is connected. Notify the Get() callers who are blocking.
|
||||||
|
if cnt == 1 && rr.waitCh != nil {
|
||||||
|
close(rr.waitCh)
|
||||||
|
rr.waitCh = nil
|
||||||
|
}
|
||||||
|
return func(err error) {
|
||||||
|
rr.down(addr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// down unsets the connected state of addr.
|
||||||
|
func (rr *roundRobin) down(addr Address, err error) {
|
||||||
|
rr.mu.Lock()
|
||||||
|
defer rr.mu.Unlock()
|
||||||
|
for _, a := range rr.addrs {
|
||||||
|
if addr == a.addr {
|
||||||
|
a.connected = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns the next addr in the rotation.
|
||||||
|
func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) {
|
||||||
|
var ch chan struct{}
|
||||||
|
rr.mu.Lock()
|
||||||
|
if rr.done {
|
||||||
|
rr.mu.Unlock()
|
||||||
|
err = ErrClientConnClosing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(rr.addrs) > 0 {
|
||||||
|
if rr.next >= len(rr.addrs) {
|
||||||
|
rr.next = 0
|
||||||
|
}
|
||||||
|
next := rr.next
|
||||||
|
for {
|
||||||
|
a := rr.addrs[next]
|
||||||
|
next = (next + 1) % len(rr.addrs)
|
||||||
|
if a.connected {
|
||||||
|
addr = a.addr
|
||||||
|
rr.next = next
|
||||||
|
rr.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if next == rr.next {
|
||||||
|
// Has iterated all the possible address but none is connected.
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !opts.BlockingWait {
|
||||||
|
if len(rr.addrs) == 0 {
|
||||||
|
rr.mu.Unlock()
|
||||||
|
err = fmt.Errorf("there is no address available")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Returns the next addr on rr.addrs for failfast RPCs.
|
||||||
|
addr = rr.addrs[rr.next].addr
|
||||||
|
rr.next++
|
||||||
|
rr.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Wait on rr.waitCh for non-failfast RPCs.
|
||||||
|
if rr.waitCh == nil {
|
||||||
|
ch = make(chan struct{})
|
||||||
|
rr.waitCh = ch
|
||||||
|
} else {
|
||||||
|
ch = rr.waitCh
|
||||||
|
}
|
||||||
|
rr.mu.Unlock()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
err = ctx.Err()
|
||||||
|
return
|
||||||
|
case <-ch:
|
||||||
|
rr.mu.Lock()
|
||||||
|
if rr.done {
|
||||||
|
rr.mu.Unlock()
|
||||||
|
err = ErrClientConnClosing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(rr.addrs) > 0 {
|
||||||
|
if rr.next >= len(rr.addrs) {
|
||||||
|
rr.next = 0
|
||||||
|
}
|
||||||
|
next := rr.next
|
||||||
|
for {
|
||||||
|
a := rr.addrs[next]
|
||||||
|
next = (next + 1) % len(rr.addrs)
|
||||||
|
if a.connected {
|
||||||
|
addr = a.addr
|
||||||
|
rr.next = next
|
||||||
|
rr.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if next == rr.next {
|
||||||
|
// Has iterated all the possible address but none is connected.
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The newly added addr got removed by Down() again.
|
||||||
|
if rr.waitCh == nil {
|
||||||
|
ch = make(chan struct{})
|
||||||
|
rr.waitCh = ch
|
||||||
|
} else {
|
||||||
|
ch = rr.waitCh
|
||||||
|
}
|
||||||
|
rr.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr *roundRobin) Notify() <-chan []Address {
|
||||||
|
return rr.addrCh
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr *roundRobin) Close() error {
|
||||||
|
rr.mu.Lock()
|
||||||
|
defer rr.mu.Unlock()
|
||||||
|
rr.done = true
|
||||||
|
if rr.w != nil {
|
||||||
|
rr.w.Close()
|
||||||
|
}
|
||||||
|
if rr.waitCh != nil {
|
||||||
|
close(rr.waitCh)
|
||||||
|
rr.waitCh = nil
|
||||||
|
}
|
||||||
|
if rr.addrCh != nil {
|
||||||
|
close(rr.addrCh)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
438
vendor/google.golang.org/grpc/balancer_test.go
generated
vendored
Normal file
438
vendor/google.golang.org/grpc/balancer_test.go
generated
vendored
Normal file
|
@ -0,0 +1,438 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/naming"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testWatcher struct {
|
||||||
|
// the channel to receives name resolution updates
|
||||||
|
update chan *naming.Update
|
||||||
|
// the side channel to get to know how many updates in a batch
|
||||||
|
side chan int
|
||||||
|
// the channel to notifiy update injector that the update reading is done
|
||||||
|
readDone chan int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *testWatcher) Next() (updates []*naming.Update, err error) {
|
||||||
|
n := <-w.side
|
||||||
|
if n == 0 {
|
||||||
|
return nil, fmt.Errorf("w.side is closed")
|
||||||
|
}
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
u := <-w.update
|
||||||
|
if u != nil {
|
||||||
|
updates = append(updates, u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.readDone <- 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *testWatcher) Close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject naming resolution updates to the testWatcher.
|
||||||
|
func (w *testWatcher) inject(updates []*naming.Update) {
|
||||||
|
w.side <- len(updates)
|
||||||
|
for _, u := range updates {
|
||||||
|
w.update <- u
|
||||||
|
}
|
||||||
|
<-w.readDone
|
||||||
|
}
|
||||||
|
|
||||||
|
type testNameResolver struct {
|
||||||
|
w *testWatcher
|
||||||
|
addr string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *testNameResolver) Resolve(target string) (naming.Watcher, error) {
|
||||||
|
r.w = &testWatcher{
|
||||||
|
update: make(chan *naming.Update, 1),
|
||||||
|
side: make(chan int, 1),
|
||||||
|
readDone: make(chan int),
|
||||||
|
}
|
||||||
|
r.w.side <- 1
|
||||||
|
r.w.update <- &naming.Update{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: r.addr,
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
<-r.w.readDone
|
||||||
|
}()
|
||||||
|
return r.w, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func startServers(t *testing.T, numServers int, maxStreams uint32) ([]*server, *testNameResolver) {
|
||||||
|
var servers []*server
|
||||||
|
for i := 0; i < numServers; i++ {
|
||||||
|
s := newTestServer()
|
||||||
|
servers = append(servers, s)
|
||||||
|
go s.start(t, 0, maxStreams)
|
||||||
|
s.wait(t, 2*time.Second)
|
||||||
|
}
|
||||||
|
// Point to server[0]
|
||||||
|
addr := "127.0.0.1:" + servers[0].port
|
||||||
|
return servers, &testNameResolver{
|
||||||
|
addr: addr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNameDiscovery(t *testing.T) {
|
||||||
|
// Start 2 servers on 2 ports.
|
||||||
|
numServers := 2
|
||||||
|
servers, r := startServers(t, numServers, math.MaxUint32)
|
||||||
|
cc, err := Dial("foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
req := "port"
|
||||||
|
var reply string
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err == nil || ErrorDesc(err) != servers[0].port {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want %s", err, servers[0].port)
|
||||||
|
}
|
||||||
|
// Inject the name resolution change to remove servers[0] and add servers[1].
|
||||||
|
var updates []*naming.Update
|
||||||
|
updates = append(updates, &naming.Update{
|
||||||
|
Op: naming.Delete,
|
||||||
|
Addr: "127.0.0.1:" + servers[0].port,
|
||||||
|
})
|
||||||
|
updates = append(updates, &naming.Update{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: "127.0.0.1:" + servers[1].port,
|
||||||
|
})
|
||||||
|
r.w.inject(updates)
|
||||||
|
// Loop until the rpcs in flight talks to servers[1].
|
||||||
|
for {
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err != nil && ErrorDesc(err) == servers[1].port {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
for i := 0; i < numServers; i++ {
|
||||||
|
servers[i].stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEmptyAddrs(t *testing.T) {
|
||||||
|
servers, r := startServers(t, 1, math.MaxUint32)
|
||||||
|
cc, err := Dial("foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
var reply string
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc); err != nil || reply != expectedResponse {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, reply = %q, want %q, <nil>", err, reply, expectedResponse)
|
||||||
|
}
|
||||||
|
// Inject name resolution change to remove the server so that there is no address
|
||||||
|
// available after that.
|
||||||
|
u := &naming.Update{
|
||||||
|
Op: naming.Delete,
|
||||||
|
Addr: "127.0.0.1:" + servers[0].port,
|
||||||
|
}
|
||||||
|
r.w.inject([]*naming.Update{u})
|
||||||
|
// Loop until the above updates apply.
|
||||||
|
for {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
||||||
|
if err := Invoke(ctx, "/foo/bar", &expectedRequest, &reply, cc); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
servers[0].stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRoundRobin(t *testing.T) {
|
||||||
|
// Start 3 servers on 3 ports.
|
||||||
|
numServers := 3
|
||||||
|
servers, r := startServers(t, numServers, math.MaxUint32)
|
||||||
|
cc, err := Dial("foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
// Add servers[1] to the service discovery.
|
||||||
|
u := &naming.Update{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: "127.0.0.1:" + servers[1].port,
|
||||||
|
}
|
||||||
|
r.w.inject([]*naming.Update{u})
|
||||||
|
req := "port"
|
||||||
|
var reply string
|
||||||
|
// Loop until servers[1] is up
|
||||||
|
for {
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err != nil && ErrorDesc(err) == servers[1].port {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
// Add server2[2] to the service discovery.
|
||||||
|
u = &naming.Update{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: "127.0.0.1:" + servers[2].port,
|
||||||
|
}
|
||||||
|
r.w.inject([]*naming.Update{u})
|
||||||
|
// Loop until both servers[2] are up.
|
||||||
|
for {
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err != nil && ErrorDesc(err) == servers[2].port {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
// Check the incoming RPCs served in a round-robin manner.
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err == nil || ErrorDesc(err) != servers[i%numServers].port {
|
||||||
|
t.Fatalf("Index %d: Invoke(_, _, _, _, _) = %v, want %s", i, err, servers[i%numServers].port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
for i := 0; i < numServers; i++ {
|
||||||
|
servers[i].stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCloseWithPendingRPC(t *testing.T) {
|
||||||
|
servers, r := startServers(t, 1, math.MaxUint32)
|
||||||
|
cc, err := Dial("foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
var reply string
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc, FailFast(false)); err != nil {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want %s", err, servers[0].port)
|
||||||
|
}
|
||||||
|
// Remove the server.
|
||||||
|
updates := []*naming.Update{{
|
||||||
|
Op: naming.Delete,
|
||||||
|
Addr: "127.0.0.1:" + servers[0].port,
|
||||||
|
}}
|
||||||
|
r.w.inject(updates)
|
||||||
|
// Loop until the above update applies.
|
||||||
|
for {
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
||||||
|
if err := Invoke(ctx, "/foo/bar", &expectedRequest, &reply, cc, FailFast(false)); Code(err) == codes.DeadlineExceeded {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
// Issue 2 RPCs which should be completed with error status once cc is closed.
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(2)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
var reply string
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc, FailFast(false)); err == nil {
|
||||||
|
t.Errorf("grpc.Invoke(_, _, _, _, _) = %v, want not nil", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
var reply string
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc, FailFast(false)); err == nil {
|
||||||
|
t.Errorf("grpc.Invoke(_, _, _, _, _) = %v, want not nil", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
cc.Close()
|
||||||
|
wg.Wait()
|
||||||
|
servers[0].stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetOnWaitChannel(t *testing.T) {
|
||||||
|
servers, r := startServers(t, 1, math.MaxUint32)
|
||||||
|
cc, err := Dial("foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
// Remove all servers so that all upcoming RPCs will block on waitCh.
|
||||||
|
updates := []*naming.Update{{
|
||||||
|
Op: naming.Delete,
|
||||||
|
Addr: "127.0.0.1:" + servers[0].port,
|
||||||
|
}}
|
||||||
|
r.w.inject(updates)
|
||||||
|
for {
|
||||||
|
var reply string
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
||||||
|
if err := Invoke(ctx, "/foo/bar", &expectedRequest, &reply, cc, FailFast(false)); Code(err) == codes.DeadlineExceeded {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
var reply string
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc, FailFast(false)); err != nil {
|
||||||
|
t.Errorf("grpc.Invoke(_, _, _, _, _) = %v, want <nil>", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// Add a connected server to get the above RPC through.
|
||||||
|
updates = []*naming.Update{{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: "127.0.0.1:" + servers[0].port,
|
||||||
|
}}
|
||||||
|
r.w.inject(updates)
|
||||||
|
// Wait until the above RPC succeeds.
|
||||||
|
wg.Wait()
|
||||||
|
cc.Close()
|
||||||
|
servers[0].stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOneServerDown(t *testing.T) {
|
||||||
|
// Start 2 servers.
|
||||||
|
numServers := 2
|
||||||
|
servers, r := startServers(t, numServers, math.MaxUint32)
|
||||||
|
cc, err := Dial("foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
// Add servers[1] to the service discovery.
|
||||||
|
var updates []*naming.Update
|
||||||
|
updates = append(updates, &naming.Update{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: "127.0.0.1:" + servers[1].port,
|
||||||
|
})
|
||||||
|
r.w.inject(updates)
|
||||||
|
req := "port"
|
||||||
|
var reply string
|
||||||
|
// Loop until servers[1] is up
|
||||||
|
for {
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err != nil && ErrorDesc(err) == servers[1].port {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
numRPC := 100
|
||||||
|
sleepDuration := 10 * time.Millisecond
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
time.Sleep(sleepDuration)
|
||||||
|
// After sleepDuration, kill server[0].
|
||||||
|
servers[0].stop()
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// All non-failfast RPCs should not block because there's at least one connection available.
|
||||||
|
for i := 0; i < numRPC; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
time.Sleep(sleepDuration)
|
||||||
|
// After sleepDuration, invoke RPC.
|
||||||
|
// server[0] is killed around the same time to make it racy between balancer and gRPC internals.
|
||||||
|
Invoke(context.Background(), "/foo/bar", &req, &reply, cc, FailFast(false))
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
cc.Close()
|
||||||
|
for i := 0; i < numServers; i++ {
|
||||||
|
servers[i].stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOneAddressRemoval(t *testing.T) {
|
||||||
|
// Start 2 servers.
|
||||||
|
numServers := 2
|
||||||
|
servers, r := startServers(t, numServers, math.MaxUint32)
|
||||||
|
cc, err := Dial("foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
// Add servers[1] to the service discovery.
|
||||||
|
var updates []*naming.Update
|
||||||
|
updates = append(updates, &naming.Update{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: "127.0.0.1:" + servers[1].port,
|
||||||
|
})
|
||||||
|
r.w.inject(updates)
|
||||||
|
req := "port"
|
||||||
|
var reply string
|
||||||
|
// Loop until servers[1] is up
|
||||||
|
for {
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err != nil && ErrorDesc(err) == servers[1].port {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
numRPC := 100
|
||||||
|
sleepDuration := 10 * time.Millisecond
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
time.Sleep(sleepDuration)
|
||||||
|
// After sleepDuration, delete server[0].
|
||||||
|
var updates []*naming.Update
|
||||||
|
updates = append(updates, &naming.Update{
|
||||||
|
Op: naming.Delete,
|
||||||
|
Addr: "127.0.0.1:" + servers[0].port,
|
||||||
|
})
|
||||||
|
r.w.inject(updates)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// All non-failfast RPCs should not fail because there's at least one connection available.
|
||||||
|
for i := 0; i < numRPC; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
var reply string
|
||||||
|
time.Sleep(sleepDuration)
|
||||||
|
// After sleepDuration, invoke RPC.
|
||||||
|
// server[0] is removed around the same time to make it racy between balancer and gRPC internals.
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc, FailFast(false)); err != nil {
|
||||||
|
t.Errorf("grpc.Invoke(_, _, _, _, _) = %v, want not nil", err)
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
cc.Close()
|
||||||
|
for i := 0; i < numServers; i++ {
|
||||||
|
servers[i].stop()
|
||||||
|
}
|
||||||
|
}
|
224
vendor/google.golang.org/grpc/benchmark/benchmark.go
generated
vendored
Normal file
224
vendor/google.golang.org/grpc/benchmark/benchmark.go
generated
vendored
Normal file
|
@ -0,0 +1,224 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package benchmark implements the building blocks to setup end-to-end gRPC benchmarks.
|
||||||
|
*/
|
||||||
|
package benchmark
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
testpb "google.golang.org/grpc/benchmark/grpc_testing"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newPayload(t testpb.PayloadType, size int) *testpb.Payload {
|
||||||
|
if size < 0 {
|
||||||
|
grpclog.Fatalf("Requested a response with invalid length %d", size)
|
||||||
|
}
|
||||||
|
body := make([]byte, size)
|
||||||
|
switch t {
|
||||||
|
case testpb.PayloadType_COMPRESSABLE:
|
||||||
|
case testpb.PayloadType_UNCOMPRESSABLE:
|
||||||
|
grpclog.Fatalf("PayloadType UNCOMPRESSABLE is not supported")
|
||||||
|
default:
|
||||||
|
grpclog.Fatalf("Unsupported payload type: %d", t)
|
||||||
|
}
|
||||||
|
return &testpb.Payload{
|
||||||
|
Type: t,
|
||||||
|
Body: body,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServer struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||||
|
return &testpb.SimpleResponse{
|
||||||
|
Payload: newPayload(in.ResponseType, int(in.ResponseSize)),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
// read done.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := stream.Send(&testpb.SimpleResponse{
|
||||||
|
Payload: newPayload(in.ResponseType, int(in.ResponseSize)),
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// byteBufServer is a gRPC server that sends and receives byte buffer.
|
||||||
|
// The purpose is to benchmark the gRPC performance without protobuf serialization/deserialization overhead.
|
||||||
|
type byteBufServer struct {
|
||||||
|
respSize int32
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnaryCall is an empty function and is not used for benchmark.
|
||||||
|
// If bytebuf UnaryCall benchmark is needed later, the function body needs to be updated.
|
||||||
|
func (s *byteBufServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||||
|
return &testpb.SimpleResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *byteBufServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
|
||||||
|
for {
|
||||||
|
var in []byte
|
||||||
|
err := stream.(grpc.ServerStream).RecvMsg(&in)
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out := make([]byte, s.respSize)
|
||||||
|
if err := stream.(grpc.ServerStream).SendMsg(&out); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerInfo contains the information to create a gRPC benchmark server.
|
||||||
|
type ServerInfo struct {
|
||||||
|
// Addr is the address of the server.
|
||||||
|
Addr string
|
||||||
|
|
||||||
|
// Type is the type of the server.
|
||||||
|
// It should be "protobuf" or "bytebuf".
|
||||||
|
Type string
|
||||||
|
|
||||||
|
// Metadata is an optional configuration.
|
||||||
|
// For "protobuf", it's ignored.
|
||||||
|
// For "bytebuf", it should be an int representing response size.
|
||||||
|
Metadata interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartServer starts a gRPC server serving a benchmark service according to info.
|
||||||
|
// It returns its listen address and a function to stop the server.
|
||||||
|
func StartServer(info ServerInfo, opts ...grpc.ServerOption) (string, func()) {
|
||||||
|
lis, err := net.Listen("tcp", info.Addr)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
s := grpc.NewServer(opts...)
|
||||||
|
switch info.Type {
|
||||||
|
case "protobuf":
|
||||||
|
testpb.RegisterBenchmarkServiceServer(s, &testServer{})
|
||||||
|
case "bytebuf":
|
||||||
|
respSize, ok := info.Metadata.(int32)
|
||||||
|
if !ok {
|
||||||
|
grpclog.Fatalf("failed to StartServer, invalid metadata: %v, for Type: %v", info.Metadata, info.Type)
|
||||||
|
}
|
||||||
|
testpb.RegisterBenchmarkServiceServer(s, &byteBufServer{respSize: respSize})
|
||||||
|
default:
|
||||||
|
grpclog.Fatalf("failed to StartServer, unknown Type: %v", info.Type)
|
||||||
|
}
|
||||||
|
go s.Serve(lis)
|
||||||
|
return lis.Addr().String(), func() {
|
||||||
|
s.Stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoUnaryCall performs an unary RPC with given stub and request and response sizes.
|
||||||
|
func DoUnaryCall(tc testpb.BenchmarkServiceClient, reqSize, respSize int) error {
|
||||||
|
pl := newPayload(testpb.PayloadType_COMPRESSABLE, reqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: pl.Type,
|
||||||
|
ResponseSize: int32(respSize),
|
||||||
|
Payload: pl,
|
||||||
|
}
|
||||||
|
if _, err := tc.UnaryCall(context.Background(), req); err != nil {
|
||||||
|
return fmt.Errorf("/BenchmarkService/UnaryCall(_, _) = _, %v, want _, <nil>", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoStreamingRoundTrip performs a round trip for a single streaming rpc.
|
||||||
|
func DoStreamingRoundTrip(stream testpb.BenchmarkService_StreamingCallClient, reqSize, respSize int) error {
|
||||||
|
pl := newPayload(testpb.PayloadType_COMPRESSABLE, reqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: pl.Type,
|
||||||
|
ResponseSize: int32(respSize),
|
||||||
|
Payload: pl,
|
||||||
|
}
|
||||||
|
if err := stream.Send(req); err != nil {
|
||||||
|
return fmt.Errorf("/BenchmarkService/StreamingCall.Send(_) = %v, want <nil>", err)
|
||||||
|
}
|
||||||
|
if _, err := stream.Recv(); err != nil {
|
||||||
|
// EOF is a valid error here.
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("/BenchmarkService/StreamingCall.Recv(_) = %v, want <nil>", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoByteBufStreamingRoundTrip performs a round trip for a single streaming rpc, using a custom codec for byte buffer.
|
||||||
|
func DoByteBufStreamingRoundTrip(stream testpb.BenchmarkService_StreamingCallClient, reqSize, respSize int) error {
|
||||||
|
out := make([]byte, reqSize)
|
||||||
|
if err := stream.(grpc.ClientStream).SendMsg(&out); err != nil {
|
||||||
|
return fmt.Errorf("/BenchmarkService/StreamingCall.(ClientStream).SendMsg(_) = %v, want <nil>", err)
|
||||||
|
}
|
||||||
|
var in []byte
|
||||||
|
if err := stream.(grpc.ClientStream).RecvMsg(&in); err != nil {
|
||||||
|
// EOF is a valid error here.
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("/BenchmarkService/StreamingCall.(ClientStream).RecvMsg(_) = %v, want <nil>", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientConn creates a gRPC client connection to addr.
|
||||||
|
func NewClientConn(addr string, opts ...grpc.DialOption) *grpc.ClientConn {
|
||||||
|
conn, err := grpc.Dial(addr, opts...)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("NewClientConn(%q) failed to create a ClientConn %v", addr, err)
|
||||||
|
}
|
||||||
|
return conn
|
||||||
|
}
|
202
vendor/google.golang.org/grpc/benchmark/benchmark_test.go
generated
vendored
Normal file
202
vendor/google.golang.org/grpc/benchmark/benchmark_test.go
generated
vendored
Normal file
|
@ -0,0 +1,202 @@
|
||||||
|
package benchmark
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
testpb "google.golang.org/grpc/benchmark/grpc_testing"
|
||||||
|
"google.golang.org/grpc/benchmark/stats"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runUnary(b *testing.B, maxConcurrentCalls int) {
|
||||||
|
s := stats.AddStats(b, 38)
|
||||||
|
b.StopTimer()
|
||||||
|
target, stopper := StartServer(ServerInfo{Addr: "localhost:0", Type: "protobuf"})
|
||||||
|
defer stopper()
|
||||||
|
conn := NewClientConn(target, grpc.WithInsecure())
|
||||||
|
tc := testpb.NewBenchmarkServiceClient(conn)
|
||||||
|
|
||||||
|
// Warm up connection.
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
unaryCaller(tc)
|
||||||
|
}
|
||||||
|
ch := make(chan int, maxConcurrentCalls*4)
|
||||||
|
var (
|
||||||
|
mu sync.Mutex
|
||||||
|
wg sync.WaitGroup
|
||||||
|
)
|
||||||
|
wg.Add(maxConcurrentCalls)
|
||||||
|
|
||||||
|
// Distribute the b.N calls over maxConcurrentCalls workers.
|
||||||
|
for i := 0; i < maxConcurrentCalls; i++ {
|
||||||
|
go func() {
|
||||||
|
for range ch {
|
||||||
|
start := time.Now()
|
||||||
|
unaryCaller(tc)
|
||||||
|
elapse := time.Since(start)
|
||||||
|
mu.Lock()
|
||||||
|
s.Add(elapse)
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ch <- i
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
close(ch)
|
||||||
|
wg.Wait()
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func runStream(b *testing.B, maxConcurrentCalls int) {
|
||||||
|
s := stats.AddStats(b, 38)
|
||||||
|
b.StopTimer()
|
||||||
|
target, stopper := StartServer(ServerInfo{Addr: "localhost:0", Type: "protobuf"})
|
||||||
|
defer stopper()
|
||||||
|
conn := NewClientConn(target, grpc.WithInsecure())
|
||||||
|
tc := testpb.NewBenchmarkServiceClient(conn)
|
||||||
|
|
||||||
|
// Warm up connection.
|
||||||
|
stream, err := tc.StreamingCall(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("%v.StreamingCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
streamCaller(stream)
|
||||||
|
}
|
||||||
|
|
||||||
|
ch := make(chan int, maxConcurrentCalls*4)
|
||||||
|
var (
|
||||||
|
mu sync.Mutex
|
||||||
|
wg sync.WaitGroup
|
||||||
|
)
|
||||||
|
wg.Add(maxConcurrentCalls)
|
||||||
|
|
||||||
|
// Distribute the b.N calls over maxConcurrentCalls workers.
|
||||||
|
for i := 0; i < maxConcurrentCalls; i++ {
|
||||||
|
go func() {
|
||||||
|
stream, err := tc.StreamingCall(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("%v.StreamingCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
for range ch {
|
||||||
|
start := time.Now()
|
||||||
|
streamCaller(stream)
|
||||||
|
elapse := time.Since(start)
|
||||||
|
mu.Lock()
|
||||||
|
s.Add(elapse)
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ch <- i
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
close(ch)
|
||||||
|
wg.Wait()
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
func unaryCaller(client testpb.BenchmarkServiceClient) {
|
||||||
|
if err := DoUnaryCall(client, 1, 1); err != nil {
|
||||||
|
grpclog.Fatalf("DoUnaryCall failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func streamCaller(stream testpb.BenchmarkService_StreamingCallClient) {
|
||||||
|
if err := DoStreamingRoundTrip(stream, 1, 1); err != nil {
|
||||||
|
grpclog.Fatalf("DoStreamingRoundTrip failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamc1(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runStream(b, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamc8(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runStream(b, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamc64(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runStream(b, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamc512(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runStream(b, 512)
|
||||||
|
}
|
||||||
|
func BenchmarkClientUnaryc1(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runUnary(b, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientUnaryc8(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runUnary(b, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientUnaryc64(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runUnary(b, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientUnaryc512(b *testing.B) {
|
||||||
|
grpc.EnableTracing = true
|
||||||
|
runUnary(b, 512)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamNoTracec1(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runStream(b, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamNoTracec8(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runStream(b, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamNoTracec64(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runStream(b, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientStreamNoTracec512(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runStream(b, 512)
|
||||||
|
}
|
||||||
|
func BenchmarkClientUnaryNoTracec1(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runUnary(b, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientUnaryNoTracec8(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runUnary(b, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientUnaryNoTracec64(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runUnary(b, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkClientUnaryNoTracec512(b *testing.B) {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
runUnary(b, 512)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Exit(stats.RunTestMain(m))
|
||||||
|
}
|
162
vendor/google.golang.org/grpc/benchmark/client/main.go
generated
vendored
Normal file
162
vendor/google.golang.org/grpc/benchmark/client/main.go
generated
vendored
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"math"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/benchmark"
|
||||||
|
testpb "google.golang.org/grpc/benchmark/grpc_testing"
|
||||||
|
"google.golang.org/grpc/benchmark/stats"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
server = flag.String("server", "", "The server address")
|
||||||
|
maxConcurrentRPCs = flag.Int("max_concurrent_rpcs", 1, "The max number of concurrent RPCs")
|
||||||
|
duration = flag.Int("duration", math.MaxInt32, "The duration in seconds to run the benchmark client")
|
||||||
|
trace = flag.Bool("trace", true, "Whether tracing is on")
|
||||||
|
rpcType = flag.Int("rpc_type", 0,
|
||||||
|
`Configure different client rpc type. Valid options are:
|
||||||
|
0 : unary call;
|
||||||
|
1 : streaming call.`)
|
||||||
|
)
|
||||||
|
|
||||||
|
func unaryCaller(client testpb.BenchmarkServiceClient) {
|
||||||
|
benchmark.DoUnaryCall(client, 1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func streamCaller(stream testpb.BenchmarkService_StreamingCallClient) {
|
||||||
|
benchmark.DoStreamingRoundTrip(stream, 1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildConnection() (s *stats.Stats, conn *grpc.ClientConn, tc testpb.BenchmarkServiceClient) {
|
||||||
|
s = stats.NewStats(256)
|
||||||
|
conn = benchmark.NewClientConn(*server)
|
||||||
|
tc = testpb.NewBenchmarkServiceClient(conn)
|
||||||
|
return s, conn, tc
|
||||||
|
}
|
||||||
|
|
||||||
|
func closeLoopUnary() {
|
||||||
|
s, conn, tc := buildConnection()
|
||||||
|
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
unaryCaller(tc)
|
||||||
|
}
|
||||||
|
ch := make(chan int, *maxConcurrentRPCs*4)
|
||||||
|
var (
|
||||||
|
mu sync.Mutex
|
||||||
|
wg sync.WaitGroup
|
||||||
|
)
|
||||||
|
wg.Add(*maxConcurrentRPCs)
|
||||||
|
|
||||||
|
for i := 0; i < *maxConcurrentRPCs; i++ {
|
||||||
|
go func() {
|
||||||
|
for range ch {
|
||||||
|
start := time.Now()
|
||||||
|
unaryCaller(tc)
|
||||||
|
elapse := time.Since(start)
|
||||||
|
mu.Lock()
|
||||||
|
s.Add(elapse)
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
// Stop the client when time is up.
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
<-time.After(time.Duration(*duration) * time.Second)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
ok := true
|
||||||
|
for ok {
|
||||||
|
select {
|
||||||
|
case ch <- 0:
|
||||||
|
case <-done:
|
||||||
|
ok = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(ch)
|
||||||
|
wg.Wait()
|
||||||
|
conn.Close()
|
||||||
|
grpclog.Println(s.String())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func closeLoopStream() {
|
||||||
|
s, conn, tc := buildConnection()
|
||||||
|
ch := make(chan int, *maxConcurrentRPCs*4)
|
||||||
|
var (
|
||||||
|
mu sync.Mutex
|
||||||
|
wg sync.WaitGroup
|
||||||
|
)
|
||||||
|
wg.Add(*maxConcurrentRPCs)
|
||||||
|
// Distribute RPCs over maxConcurrentCalls workers.
|
||||||
|
for i := 0; i < *maxConcurrentRPCs; i++ {
|
||||||
|
go func() {
|
||||||
|
stream, err := tc.StreamingCall(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.StreamingCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
// Do some warm up.
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
streamCaller(stream)
|
||||||
|
}
|
||||||
|
for range ch {
|
||||||
|
start := time.Now()
|
||||||
|
streamCaller(stream)
|
||||||
|
elapse := time.Since(start)
|
||||||
|
mu.Lock()
|
||||||
|
s.Add(elapse)
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
// Stop the client when time is up.
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
<-time.After(time.Duration(*duration) * time.Second)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
ok := true
|
||||||
|
for ok {
|
||||||
|
select {
|
||||||
|
case ch <- 0:
|
||||||
|
case <-done:
|
||||||
|
ok = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(ch)
|
||||||
|
wg.Wait()
|
||||||
|
conn.Close()
|
||||||
|
grpclog.Println(s.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
grpc.EnableTracing = *trace
|
||||||
|
go func() {
|
||||||
|
lis, err := net.Listen("tcp", ":0")
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
grpclog.Println("Client profiling address: ", lis.Addr().String())
|
||||||
|
if err := http.Serve(lis, nil); err != nil {
|
||||||
|
grpclog.Fatalf("Failed to serve: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
switch *rpcType {
|
||||||
|
case 0:
|
||||||
|
closeLoopUnary()
|
||||||
|
case 1:
|
||||||
|
closeLoopStream()
|
||||||
|
}
|
||||||
|
}
|
977
vendor/google.golang.org/grpc/benchmark/grpc_testing/control.pb.go
generated
vendored
Normal file
977
vendor/google.golang.org/grpc/benchmark/grpc_testing/control.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,977 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: control.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpc_testing is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
control.proto
|
||||||
|
messages.proto
|
||||||
|
payloads.proto
|
||||||
|
services.proto
|
||||||
|
stats.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
PoissonParams
|
||||||
|
UniformParams
|
||||||
|
DeterministicParams
|
||||||
|
ParetoParams
|
||||||
|
ClosedLoopParams
|
||||||
|
LoadParams
|
||||||
|
SecurityParams
|
||||||
|
ClientConfig
|
||||||
|
ClientStatus
|
||||||
|
Mark
|
||||||
|
ClientArgs
|
||||||
|
ServerConfig
|
||||||
|
ServerArgs
|
||||||
|
ServerStatus
|
||||||
|
CoreRequest
|
||||||
|
CoreResponse
|
||||||
|
Void
|
||||||
|
Scenario
|
||||||
|
Scenarios
|
||||||
|
Payload
|
||||||
|
EchoStatus
|
||||||
|
SimpleRequest
|
||||||
|
SimpleResponse
|
||||||
|
StreamingInputCallRequest
|
||||||
|
StreamingInputCallResponse
|
||||||
|
ResponseParameters
|
||||||
|
StreamingOutputCallRequest
|
||||||
|
StreamingOutputCallResponse
|
||||||
|
ReconnectParams
|
||||||
|
ReconnectInfo
|
||||||
|
ByteBufferParams
|
||||||
|
SimpleProtoParams
|
||||||
|
ComplexProtoParams
|
||||||
|
PayloadConfig
|
||||||
|
ServerStats
|
||||||
|
HistogramParams
|
||||||
|
HistogramData
|
||||||
|
ClientStats
|
||||||
|
*/
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
type ClientType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
ClientType_SYNC_CLIENT ClientType = 0
|
||||||
|
ClientType_ASYNC_CLIENT ClientType = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
var ClientType_name = map[int32]string{
|
||||||
|
0: "SYNC_CLIENT",
|
||||||
|
1: "ASYNC_CLIENT",
|
||||||
|
}
|
||||||
|
var ClientType_value = map[string]int32{
|
||||||
|
"SYNC_CLIENT": 0,
|
||||||
|
"ASYNC_CLIENT": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x ClientType) String() string {
|
||||||
|
return proto.EnumName(ClientType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (ClientType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
type ServerType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
ServerType_SYNC_SERVER ServerType = 0
|
||||||
|
ServerType_ASYNC_SERVER ServerType = 1
|
||||||
|
ServerType_ASYNC_GENERIC_SERVER ServerType = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var ServerType_name = map[int32]string{
|
||||||
|
0: "SYNC_SERVER",
|
||||||
|
1: "ASYNC_SERVER",
|
||||||
|
2: "ASYNC_GENERIC_SERVER",
|
||||||
|
}
|
||||||
|
var ServerType_value = map[string]int32{
|
||||||
|
"SYNC_SERVER": 0,
|
||||||
|
"ASYNC_SERVER": 1,
|
||||||
|
"ASYNC_GENERIC_SERVER": 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x ServerType) String() string {
|
||||||
|
return proto.EnumName(ServerType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (ServerType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
type RpcType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
RpcType_UNARY RpcType = 0
|
||||||
|
RpcType_STREAMING RpcType = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
var RpcType_name = map[int32]string{
|
||||||
|
0: "UNARY",
|
||||||
|
1: "STREAMING",
|
||||||
|
}
|
||||||
|
var RpcType_value = map[string]int32{
|
||||||
|
"UNARY": 0,
|
||||||
|
"STREAMING": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x RpcType) String() string {
|
||||||
|
return proto.EnumName(RpcType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (RpcType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||||
|
|
||||||
|
// Parameters of poisson process distribution, which is a good representation
|
||||||
|
// of activity coming in from independent identical stationary sources.
|
||||||
|
type PoissonParams struct {
|
||||||
|
// The rate of arrivals (a.k.a. lambda parameter of the exp distribution).
|
||||||
|
OfferedLoad float64 `protobuf:"fixed64,1,opt,name=offered_load,json=offeredLoad" json:"offered_load,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PoissonParams) Reset() { *m = PoissonParams{} }
|
||||||
|
func (m *PoissonParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*PoissonParams) ProtoMessage() {}
|
||||||
|
func (*PoissonParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
type UniformParams struct {
|
||||||
|
InterarrivalLo float64 `protobuf:"fixed64,1,opt,name=interarrival_lo,json=interarrivalLo" json:"interarrival_lo,omitempty"`
|
||||||
|
InterarrivalHi float64 `protobuf:"fixed64,2,opt,name=interarrival_hi,json=interarrivalHi" json:"interarrival_hi,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *UniformParams) Reset() { *m = UniformParams{} }
|
||||||
|
func (m *UniformParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*UniformParams) ProtoMessage() {}
|
||||||
|
func (*UniformParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
type DeterministicParams struct {
|
||||||
|
OfferedLoad float64 `protobuf:"fixed64,1,opt,name=offered_load,json=offeredLoad" json:"offered_load,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DeterministicParams) Reset() { *m = DeterministicParams{} }
|
||||||
|
func (m *DeterministicParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*DeterministicParams) ProtoMessage() {}
|
||||||
|
func (*DeterministicParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||||
|
|
||||||
|
type ParetoParams struct {
|
||||||
|
InterarrivalBase float64 `protobuf:"fixed64,1,opt,name=interarrival_base,json=interarrivalBase" json:"interarrival_base,omitempty"`
|
||||||
|
Alpha float64 `protobuf:"fixed64,2,opt,name=alpha" json:"alpha,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ParetoParams) Reset() { *m = ParetoParams{} }
|
||||||
|
func (m *ParetoParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ParetoParams) ProtoMessage() {}
|
||||||
|
func (*ParetoParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||||
|
|
||||||
|
// Once an RPC finishes, immediately start a new one.
|
||||||
|
// No configuration parameters needed.
|
||||||
|
type ClosedLoopParams struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClosedLoopParams) Reset() { *m = ClosedLoopParams{} }
|
||||||
|
func (m *ClosedLoopParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ClosedLoopParams) ProtoMessage() {}
|
||||||
|
func (*ClosedLoopParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||||
|
|
||||||
|
type LoadParams struct {
|
||||||
|
// Types that are valid to be assigned to Load:
|
||||||
|
// *LoadParams_ClosedLoop
|
||||||
|
// *LoadParams_Poisson
|
||||||
|
// *LoadParams_Uniform
|
||||||
|
// *LoadParams_Determ
|
||||||
|
// *LoadParams_Pareto
|
||||||
|
Load isLoadParams_Load `protobuf_oneof:"load"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadParams) Reset() { *m = LoadParams{} }
|
||||||
|
func (m *LoadParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*LoadParams) ProtoMessage() {}
|
||||||
|
func (*LoadParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||||
|
|
||||||
|
type isLoadParams_Load interface {
|
||||||
|
isLoadParams_Load()
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoadParams_ClosedLoop struct {
|
||||||
|
ClosedLoop *ClosedLoopParams `protobuf:"bytes,1,opt,name=closed_loop,json=closedLoop,oneof"`
|
||||||
|
}
|
||||||
|
type LoadParams_Poisson struct {
|
||||||
|
Poisson *PoissonParams `protobuf:"bytes,2,opt,name=poisson,oneof"`
|
||||||
|
}
|
||||||
|
type LoadParams_Uniform struct {
|
||||||
|
Uniform *UniformParams `protobuf:"bytes,3,opt,name=uniform,oneof"`
|
||||||
|
}
|
||||||
|
type LoadParams_Determ struct {
|
||||||
|
Determ *DeterministicParams `protobuf:"bytes,4,opt,name=determ,oneof"`
|
||||||
|
}
|
||||||
|
type LoadParams_Pareto struct {
|
||||||
|
Pareto *ParetoParams `protobuf:"bytes,5,opt,name=pareto,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*LoadParams_ClosedLoop) isLoadParams_Load() {}
|
||||||
|
func (*LoadParams_Poisson) isLoadParams_Load() {}
|
||||||
|
func (*LoadParams_Uniform) isLoadParams_Load() {}
|
||||||
|
func (*LoadParams_Determ) isLoadParams_Load() {}
|
||||||
|
func (*LoadParams_Pareto) isLoadParams_Load() {}
|
||||||
|
|
||||||
|
func (m *LoadParams) GetLoad() isLoadParams_Load {
|
||||||
|
if m != nil {
|
||||||
|
return m.Load
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadParams) GetClosedLoop() *ClosedLoopParams {
|
||||||
|
if x, ok := m.GetLoad().(*LoadParams_ClosedLoop); ok {
|
||||||
|
return x.ClosedLoop
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadParams) GetPoisson() *PoissonParams {
|
||||||
|
if x, ok := m.GetLoad().(*LoadParams_Poisson); ok {
|
||||||
|
return x.Poisson
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadParams) GetUniform() *UniformParams {
|
||||||
|
if x, ok := m.GetLoad().(*LoadParams_Uniform); ok {
|
||||||
|
return x.Uniform
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadParams) GetDeterm() *DeterministicParams {
|
||||||
|
if x, ok := m.GetLoad().(*LoadParams_Determ); ok {
|
||||||
|
return x.Determ
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadParams) GetPareto() *ParetoParams {
|
||||||
|
if x, ok := m.GetLoad().(*LoadParams_Pareto); ok {
|
||||||
|
return x.Pareto
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*LoadParams) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _LoadParams_OneofMarshaler, _LoadParams_OneofUnmarshaler, _LoadParams_OneofSizer, []interface{}{
|
||||||
|
(*LoadParams_ClosedLoop)(nil),
|
||||||
|
(*LoadParams_Poisson)(nil),
|
||||||
|
(*LoadParams_Uniform)(nil),
|
||||||
|
(*LoadParams_Determ)(nil),
|
||||||
|
(*LoadParams_Pareto)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadParams_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*LoadParams)
|
||||||
|
// load
|
||||||
|
switch x := m.Load.(type) {
|
||||||
|
case *LoadParams_ClosedLoop:
|
||||||
|
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.ClosedLoop); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *LoadParams_Poisson:
|
||||||
|
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Poisson); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *LoadParams_Uniform:
|
||||||
|
b.EncodeVarint(3<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Uniform); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *LoadParams_Determ:
|
||||||
|
b.EncodeVarint(4<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Determ); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *LoadParams_Pareto:
|
||||||
|
b.EncodeVarint(5<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Pareto); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("LoadParams.Load has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadParams_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*LoadParams)
|
||||||
|
switch tag {
|
||||||
|
case 1: // load.closed_loop
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ClosedLoopParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Load = &LoadParams_ClosedLoop{msg}
|
||||||
|
return true, err
|
||||||
|
case 2: // load.poisson
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(PoissonParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Load = &LoadParams_Poisson{msg}
|
||||||
|
return true, err
|
||||||
|
case 3: // load.uniform
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(UniformParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Load = &LoadParams_Uniform{msg}
|
||||||
|
return true, err
|
||||||
|
case 4: // load.determ
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(DeterministicParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Load = &LoadParams_Determ{msg}
|
||||||
|
return true, err
|
||||||
|
case 5: // load.pareto
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ParetoParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Load = &LoadParams_Pareto{msg}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadParams_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*LoadParams)
|
||||||
|
// load
|
||||||
|
switch x := m.Load.(type) {
|
||||||
|
case *LoadParams_ClosedLoop:
|
||||||
|
s := proto.Size(x.ClosedLoop)
|
||||||
|
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *LoadParams_Poisson:
|
||||||
|
s := proto.Size(x.Poisson)
|
||||||
|
n += proto.SizeVarint(2<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *LoadParams_Uniform:
|
||||||
|
s := proto.Size(x.Uniform)
|
||||||
|
n += proto.SizeVarint(3<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *LoadParams_Determ:
|
||||||
|
s := proto.Size(x.Determ)
|
||||||
|
n += proto.SizeVarint(4<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *LoadParams_Pareto:
|
||||||
|
s := proto.Size(x.Pareto)
|
||||||
|
n += proto.SizeVarint(5<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
// presence of SecurityParams implies use of TLS
|
||||||
|
type SecurityParams struct {
|
||||||
|
UseTestCa bool `protobuf:"varint,1,opt,name=use_test_ca,json=useTestCa" json:"use_test_ca,omitempty"`
|
||||||
|
ServerHostOverride string `protobuf:"bytes,2,opt,name=server_host_override,json=serverHostOverride" json:"server_host_override,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SecurityParams) Reset() { *m = SecurityParams{} }
|
||||||
|
func (m *SecurityParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SecurityParams) ProtoMessage() {}
|
||||||
|
func (*SecurityParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||||
|
|
||||||
|
type ClientConfig struct {
|
||||||
|
// List of targets to connect to. At least one target needs to be specified.
|
||||||
|
ServerTargets []string `protobuf:"bytes,1,rep,name=server_targets,json=serverTargets" json:"server_targets,omitempty"`
|
||||||
|
ClientType ClientType `protobuf:"varint,2,opt,name=client_type,json=clientType,enum=grpc.testing.ClientType" json:"client_type,omitempty"`
|
||||||
|
SecurityParams *SecurityParams `protobuf:"bytes,3,opt,name=security_params,json=securityParams" json:"security_params,omitempty"`
|
||||||
|
// How many concurrent RPCs to start for each channel.
|
||||||
|
// For synchronous client, use a separate thread for each outstanding RPC.
|
||||||
|
OutstandingRpcsPerChannel int32 `protobuf:"varint,4,opt,name=outstanding_rpcs_per_channel,json=outstandingRpcsPerChannel" json:"outstanding_rpcs_per_channel,omitempty"`
|
||||||
|
// Number of independent client channels to create.
|
||||||
|
// i-th channel will connect to server_target[i % server_targets.size()]
|
||||||
|
ClientChannels int32 `protobuf:"varint,5,opt,name=client_channels,json=clientChannels" json:"client_channels,omitempty"`
|
||||||
|
// Only for async client. Number of threads to use to start/manage RPCs.
|
||||||
|
AsyncClientThreads int32 `protobuf:"varint,7,opt,name=async_client_threads,json=asyncClientThreads" json:"async_client_threads,omitempty"`
|
||||||
|
RpcType RpcType `protobuf:"varint,8,opt,name=rpc_type,json=rpcType,enum=grpc.testing.RpcType" json:"rpc_type,omitempty"`
|
||||||
|
// The requested load for the entire client (aggregated over all the threads).
|
||||||
|
LoadParams *LoadParams `protobuf:"bytes,10,opt,name=load_params,json=loadParams" json:"load_params,omitempty"`
|
||||||
|
PayloadConfig *PayloadConfig `protobuf:"bytes,11,opt,name=payload_config,json=payloadConfig" json:"payload_config,omitempty"`
|
||||||
|
HistogramParams *HistogramParams `protobuf:"bytes,12,opt,name=histogram_params,json=histogramParams" json:"histogram_params,omitempty"`
|
||||||
|
// Specify the cores we should run the client on, if desired
|
||||||
|
CoreList []int32 `protobuf:"varint,13,rep,name=core_list,json=coreList" json:"core_list,omitempty"`
|
||||||
|
CoreLimit int32 `protobuf:"varint,14,opt,name=core_limit,json=coreLimit" json:"core_limit,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientConfig) Reset() { *m = ClientConfig{} }
|
||||||
|
func (m *ClientConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ClientConfig) ProtoMessage() {}
|
||||||
|
func (*ClientConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
|
||||||
|
|
||||||
|
func (m *ClientConfig) GetSecurityParams() *SecurityParams {
|
||||||
|
if m != nil {
|
||||||
|
return m.SecurityParams
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientConfig) GetLoadParams() *LoadParams {
|
||||||
|
if m != nil {
|
||||||
|
return m.LoadParams
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientConfig) GetPayloadConfig() *PayloadConfig {
|
||||||
|
if m != nil {
|
||||||
|
return m.PayloadConfig
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientConfig) GetHistogramParams() *HistogramParams {
|
||||||
|
if m != nil {
|
||||||
|
return m.HistogramParams
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientStatus struct {
|
||||||
|
Stats *ClientStats `protobuf:"bytes,1,opt,name=stats" json:"stats,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientStatus) Reset() { *m = ClientStatus{} }
|
||||||
|
func (m *ClientStatus) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ClientStatus) ProtoMessage() {}
|
||||||
|
func (*ClientStatus) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
|
||||||
|
|
||||||
|
func (m *ClientStatus) GetStats() *ClientStats {
|
||||||
|
if m != nil {
|
||||||
|
return m.Stats
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request current stats
|
||||||
|
type Mark struct {
|
||||||
|
// if true, the stats will be reset after taking their snapshot.
|
||||||
|
Reset_ bool `protobuf:"varint,1,opt,name=reset" json:"reset,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mark) Reset() { *m = Mark{} }
|
||||||
|
func (m *Mark) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Mark) ProtoMessage() {}
|
||||||
|
func (*Mark) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} }
|
||||||
|
|
||||||
|
type ClientArgs struct {
|
||||||
|
// Types that are valid to be assigned to Argtype:
|
||||||
|
// *ClientArgs_Setup
|
||||||
|
// *ClientArgs_Mark
|
||||||
|
Argtype isClientArgs_Argtype `protobuf_oneof:"argtype"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientArgs) Reset() { *m = ClientArgs{} }
|
||||||
|
func (m *ClientArgs) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ClientArgs) ProtoMessage() {}
|
||||||
|
func (*ClientArgs) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} }
|
||||||
|
|
||||||
|
type isClientArgs_Argtype interface {
|
||||||
|
isClientArgs_Argtype()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientArgs_Setup struct {
|
||||||
|
Setup *ClientConfig `protobuf:"bytes,1,opt,name=setup,oneof"`
|
||||||
|
}
|
||||||
|
type ClientArgs_Mark struct {
|
||||||
|
Mark *Mark `protobuf:"bytes,2,opt,name=mark,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ClientArgs_Setup) isClientArgs_Argtype() {}
|
||||||
|
func (*ClientArgs_Mark) isClientArgs_Argtype() {}
|
||||||
|
|
||||||
|
func (m *ClientArgs) GetArgtype() isClientArgs_Argtype {
|
||||||
|
if m != nil {
|
||||||
|
return m.Argtype
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientArgs) GetSetup() *ClientConfig {
|
||||||
|
if x, ok := m.GetArgtype().(*ClientArgs_Setup); ok {
|
||||||
|
return x.Setup
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientArgs) GetMark() *Mark {
|
||||||
|
if x, ok := m.GetArgtype().(*ClientArgs_Mark); ok {
|
||||||
|
return x.Mark
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*ClientArgs) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _ClientArgs_OneofMarshaler, _ClientArgs_OneofUnmarshaler, _ClientArgs_OneofSizer, []interface{}{
|
||||||
|
(*ClientArgs_Setup)(nil),
|
||||||
|
(*ClientArgs_Mark)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ClientArgs_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*ClientArgs)
|
||||||
|
// argtype
|
||||||
|
switch x := m.Argtype.(type) {
|
||||||
|
case *ClientArgs_Setup:
|
||||||
|
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Setup); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *ClientArgs_Mark:
|
||||||
|
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Mark); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("ClientArgs.Argtype has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ClientArgs_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*ClientArgs)
|
||||||
|
switch tag {
|
||||||
|
case 1: // argtype.setup
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ClientConfig)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Argtype = &ClientArgs_Setup{msg}
|
||||||
|
return true, err
|
||||||
|
case 2: // argtype.mark
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(Mark)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Argtype = &ClientArgs_Mark{msg}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ClientArgs_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*ClientArgs)
|
||||||
|
// argtype
|
||||||
|
switch x := m.Argtype.(type) {
|
||||||
|
case *ClientArgs_Setup:
|
||||||
|
s := proto.Size(x.Setup)
|
||||||
|
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *ClientArgs_Mark:
|
||||||
|
s := proto.Size(x.Mark)
|
||||||
|
n += proto.SizeVarint(2<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerConfig struct {
|
||||||
|
ServerType ServerType `protobuf:"varint,1,opt,name=server_type,json=serverType,enum=grpc.testing.ServerType" json:"server_type,omitempty"`
|
||||||
|
SecurityParams *SecurityParams `protobuf:"bytes,2,opt,name=security_params,json=securityParams" json:"security_params,omitempty"`
|
||||||
|
// Port on which to listen. Zero means pick unused port.
|
||||||
|
Port int32 `protobuf:"varint,4,opt,name=port" json:"port,omitempty"`
|
||||||
|
// Only for async server. Number of threads used to serve the requests.
|
||||||
|
AsyncServerThreads int32 `protobuf:"varint,7,opt,name=async_server_threads,json=asyncServerThreads" json:"async_server_threads,omitempty"`
|
||||||
|
// Specify the number of cores to limit server to, if desired
|
||||||
|
CoreLimit int32 `protobuf:"varint,8,opt,name=core_limit,json=coreLimit" json:"core_limit,omitempty"`
|
||||||
|
// payload config, used in generic server
|
||||||
|
PayloadConfig *PayloadConfig `protobuf:"bytes,9,opt,name=payload_config,json=payloadConfig" json:"payload_config,omitempty"`
|
||||||
|
// Specify the cores we should run the server on, if desired
|
||||||
|
CoreList []int32 `protobuf:"varint,10,rep,name=core_list,json=coreList" json:"core_list,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerConfig) Reset() { *m = ServerConfig{} }
|
||||||
|
func (m *ServerConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServerConfig) ProtoMessage() {}
|
||||||
|
func (*ServerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11} }
|
||||||
|
|
||||||
|
func (m *ServerConfig) GetSecurityParams() *SecurityParams {
|
||||||
|
if m != nil {
|
||||||
|
return m.SecurityParams
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerConfig) GetPayloadConfig() *PayloadConfig {
|
||||||
|
if m != nil {
|
||||||
|
return m.PayloadConfig
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerArgs struct {
|
||||||
|
// Types that are valid to be assigned to Argtype:
|
||||||
|
// *ServerArgs_Setup
|
||||||
|
// *ServerArgs_Mark
|
||||||
|
Argtype isServerArgs_Argtype `protobuf_oneof:"argtype"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerArgs) Reset() { *m = ServerArgs{} }
|
||||||
|
func (m *ServerArgs) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServerArgs) ProtoMessage() {}
|
||||||
|
func (*ServerArgs) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{12} }
|
||||||
|
|
||||||
|
type isServerArgs_Argtype interface {
|
||||||
|
isServerArgs_Argtype()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerArgs_Setup struct {
|
||||||
|
Setup *ServerConfig `protobuf:"bytes,1,opt,name=setup,oneof"`
|
||||||
|
}
|
||||||
|
type ServerArgs_Mark struct {
|
||||||
|
Mark *Mark `protobuf:"bytes,2,opt,name=mark,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ServerArgs_Setup) isServerArgs_Argtype() {}
|
||||||
|
func (*ServerArgs_Mark) isServerArgs_Argtype() {}
|
||||||
|
|
||||||
|
func (m *ServerArgs) GetArgtype() isServerArgs_Argtype {
|
||||||
|
if m != nil {
|
||||||
|
return m.Argtype
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerArgs) GetSetup() *ServerConfig {
|
||||||
|
if x, ok := m.GetArgtype().(*ServerArgs_Setup); ok {
|
||||||
|
return x.Setup
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerArgs) GetMark() *Mark {
|
||||||
|
if x, ok := m.GetArgtype().(*ServerArgs_Mark); ok {
|
||||||
|
return x.Mark
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*ServerArgs) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _ServerArgs_OneofMarshaler, _ServerArgs_OneofUnmarshaler, _ServerArgs_OneofSizer, []interface{}{
|
||||||
|
(*ServerArgs_Setup)(nil),
|
||||||
|
(*ServerArgs_Mark)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerArgs_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*ServerArgs)
|
||||||
|
// argtype
|
||||||
|
switch x := m.Argtype.(type) {
|
||||||
|
case *ServerArgs_Setup:
|
||||||
|
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Setup); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *ServerArgs_Mark:
|
||||||
|
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.Mark); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("ServerArgs.Argtype has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerArgs_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*ServerArgs)
|
||||||
|
switch tag {
|
||||||
|
case 1: // argtype.setup
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ServerConfig)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Argtype = &ServerArgs_Setup{msg}
|
||||||
|
return true, err
|
||||||
|
case 2: // argtype.mark
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(Mark)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Argtype = &ServerArgs_Mark{msg}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerArgs_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*ServerArgs)
|
||||||
|
// argtype
|
||||||
|
switch x := m.Argtype.(type) {
|
||||||
|
case *ServerArgs_Setup:
|
||||||
|
s := proto.Size(x.Setup)
|
||||||
|
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *ServerArgs_Mark:
|
||||||
|
s := proto.Size(x.Mark)
|
||||||
|
n += proto.SizeVarint(2<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerStatus struct {
|
||||||
|
Stats *ServerStats `protobuf:"bytes,1,opt,name=stats" json:"stats,omitempty"`
|
||||||
|
// the port bound by the server
|
||||||
|
Port int32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
|
||||||
|
// Number of cores available to the server
|
||||||
|
Cores int32 `protobuf:"varint,3,opt,name=cores" json:"cores,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerStatus) Reset() { *m = ServerStatus{} }
|
||||||
|
func (m *ServerStatus) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServerStatus) ProtoMessage() {}
|
||||||
|
func (*ServerStatus) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{13} }
|
||||||
|
|
||||||
|
func (m *ServerStatus) GetStats() *ServerStats {
|
||||||
|
if m != nil {
|
||||||
|
return m.Stats
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type CoreRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *CoreRequest) Reset() { *m = CoreRequest{} }
|
||||||
|
func (m *CoreRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*CoreRequest) ProtoMessage() {}
|
||||||
|
func (*CoreRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{14} }
|
||||||
|
|
||||||
|
type CoreResponse struct {
|
||||||
|
// Number of cores available on the server
|
||||||
|
Cores int32 `protobuf:"varint,1,opt,name=cores" json:"cores,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *CoreResponse) Reset() { *m = CoreResponse{} }
|
||||||
|
func (m *CoreResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*CoreResponse) ProtoMessage() {}
|
||||||
|
func (*CoreResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{15} }
|
||||||
|
|
||||||
|
type Void struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Void) Reset() { *m = Void{} }
|
||||||
|
func (m *Void) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Void) ProtoMessage() {}
|
||||||
|
func (*Void) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{16} }
|
||||||
|
|
||||||
|
// A single performance scenario: input to qps_json_driver
|
||||||
|
type Scenario struct {
|
||||||
|
// Human readable name for this scenario
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||||
|
// Client configuration
|
||||||
|
ClientConfig *ClientConfig `protobuf:"bytes,2,opt,name=client_config,json=clientConfig" json:"client_config,omitempty"`
|
||||||
|
// Number of clients to start for the test
|
||||||
|
NumClients int32 `protobuf:"varint,3,opt,name=num_clients,json=numClients" json:"num_clients,omitempty"`
|
||||||
|
// Server configuration
|
||||||
|
ServerConfig *ServerConfig `protobuf:"bytes,4,opt,name=server_config,json=serverConfig" json:"server_config,omitempty"`
|
||||||
|
// Number of servers to start for the test
|
||||||
|
NumServers int32 `protobuf:"varint,5,opt,name=num_servers,json=numServers" json:"num_servers,omitempty"`
|
||||||
|
// Warmup period, in seconds
|
||||||
|
WarmupSeconds int32 `protobuf:"varint,6,opt,name=warmup_seconds,json=warmupSeconds" json:"warmup_seconds,omitempty"`
|
||||||
|
// Benchmark time, in seconds
|
||||||
|
BenchmarkSeconds int32 `protobuf:"varint,7,opt,name=benchmark_seconds,json=benchmarkSeconds" json:"benchmark_seconds,omitempty"`
|
||||||
|
// Number of workers to spawn locally (usually zero)
|
||||||
|
SpawnLocalWorkerCount int32 `protobuf:"varint,8,opt,name=spawn_local_worker_count,json=spawnLocalWorkerCount" json:"spawn_local_worker_count,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Scenario) Reset() { *m = Scenario{} }
|
||||||
|
func (m *Scenario) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Scenario) ProtoMessage() {}
|
||||||
|
func (*Scenario) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} }
|
||||||
|
|
||||||
|
func (m *Scenario) GetClientConfig() *ClientConfig {
|
||||||
|
if m != nil {
|
||||||
|
return m.ClientConfig
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Scenario) GetServerConfig() *ServerConfig {
|
||||||
|
if m != nil {
|
||||||
|
return m.ServerConfig
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// A set of scenarios to be run with qps_json_driver
|
||||||
|
type Scenarios struct {
|
||||||
|
Scenarios []*Scenario `protobuf:"bytes,1,rep,name=scenarios" json:"scenarios,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Scenarios) Reset() { *m = Scenarios{} }
|
||||||
|
func (m *Scenarios) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Scenarios) ProtoMessage() {}
|
||||||
|
func (*Scenarios) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{18} }
|
||||||
|
|
||||||
|
func (m *Scenarios) GetScenarios() []*Scenario {
|
||||||
|
if m != nil {
|
||||||
|
return m.Scenarios
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*PoissonParams)(nil), "grpc.testing.PoissonParams")
|
||||||
|
proto.RegisterType((*UniformParams)(nil), "grpc.testing.UniformParams")
|
||||||
|
proto.RegisterType((*DeterministicParams)(nil), "grpc.testing.DeterministicParams")
|
||||||
|
proto.RegisterType((*ParetoParams)(nil), "grpc.testing.ParetoParams")
|
||||||
|
proto.RegisterType((*ClosedLoopParams)(nil), "grpc.testing.ClosedLoopParams")
|
||||||
|
proto.RegisterType((*LoadParams)(nil), "grpc.testing.LoadParams")
|
||||||
|
proto.RegisterType((*SecurityParams)(nil), "grpc.testing.SecurityParams")
|
||||||
|
proto.RegisterType((*ClientConfig)(nil), "grpc.testing.ClientConfig")
|
||||||
|
proto.RegisterType((*ClientStatus)(nil), "grpc.testing.ClientStatus")
|
||||||
|
proto.RegisterType((*Mark)(nil), "grpc.testing.Mark")
|
||||||
|
proto.RegisterType((*ClientArgs)(nil), "grpc.testing.ClientArgs")
|
||||||
|
proto.RegisterType((*ServerConfig)(nil), "grpc.testing.ServerConfig")
|
||||||
|
proto.RegisterType((*ServerArgs)(nil), "grpc.testing.ServerArgs")
|
||||||
|
proto.RegisterType((*ServerStatus)(nil), "grpc.testing.ServerStatus")
|
||||||
|
proto.RegisterType((*CoreRequest)(nil), "grpc.testing.CoreRequest")
|
||||||
|
proto.RegisterType((*CoreResponse)(nil), "grpc.testing.CoreResponse")
|
||||||
|
proto.RegisterType((*Void)(nil), "grpc.testing.Void")
|
||||||
|
proto.RegisterType((*Scenario)(nil), "grpc.testing.Scenario")
|
||||||
|
proto.RegisterType((*Scenarios)(nil), "grpc.testing.Scenarios")
|
||||||
|
proto.RegisterEnum("grpc.testing.ClientType", ClientType_name, ClientType_value)
|
||||||
|
proto.RegisterEnum("grpc.testing.ServerType", ServerType_name, ServerType_value)
|
||||||
|
proto.RegisterEnum("grpc.testing.RpcType", RpcType_name, RpcType_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("control.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 1162 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x56, 0xdd, 0x6e, 0xdb, 0x46,
|
||||||
|
0x13, 0x8d, 0x14, 0xc9, 0x96, 0x86, 0x92, 0xac, 0x6f, 0xbf, 0xa4, 0x60, 0x1c, 0x27, 0x6d, 0xd8,
|
||||||
|
0x16, 0x0d, 0x5c, 0xc0, 0x29, 0xd4, 0x02, 0x69, 0xd1, 0x8b, 0x40, 0x56, 0x85, 0xd8, 0x80, 0xe3,
|
||||||
|
0xba, 0x2b, 0x27, 0x45, 0xae, 0x08, 0x9a, 0x5a, 0x4b, 0x44, 0x24, 0x2e, 0xbb, 0x4b, 0xc6, 0xf0,
|
||||||
|
0x2b, 0xf4, 0x99, 0xfa, 0x1c, 0x7d, 0x8d, 0xbe, 0x42, 0x67, 0xff, 0x64, 0x52, 0x11, 0x10, 0xb7,
|
||||||
|
0xbd, 0xe3, 0xce, 0x9c, 0xb3, 0x3b, 0x3b, 0x67, 0x66, 0x96, 0xd0, 0x8d, 0x79, 0x9a, 0x0b, 0xbe,
|
||||||
|
0x38, 0xc8, 0x04, 0xcf, 0x39, 0xe9, 0xcc, 0x44, 0x16, 0x1f, 0xe4, 0x4c, 0xe6, 0x49, 0x3a, 0xdb,
|
||||||
|
0xed, 0x65, 0xd1, 0xf5, 0x82, 0x47, 0x53, 0x69, 0xbc, 0xbb, 0x9e, 0xcc, 0xa3, 0xdc, 0x2e, 0x82,
|
||||||
|
0x01, 0x74, 0xcf, 0x78, 0x22, 0x25, 0x4f, 0xcf, 0x22, 0x11, 0x2d, 0x25, 0x79, 0x02, 0x1d, 0x7e,
|
||||||
|
0x79, 0xc9, 0x04, 0x9b, 0x86, 0x8a, 0xe4, 0xd7, 0x3e, 0xab, 0x3d, 0xad, 0x51, 0xcf, 0xda, 0x4e,
|
||||||
|
0xd0, 0x14, 0x44, 0xd0, 0x7d, 0x9d, 0x26, 0x97, 0x5c, 0x2c, 0x2d, 0xe7, 0x2b, 0xd8, 0x49, 0xd2,
|
||||||
|
0x9c, 0x89, 0x48, 0x88, 0xe4, 0x7d, 0xb4, 0x40, 0xa2, 0xa5, 0xf5, 0xca, 0xe6, 0x13, 0xfe, 0x01,
|
||||||
|
0x70, 0x9e, 0xf8, 0xf5, 0x0f, 0x81, 0x47, 0x49, 0xf0, 0x3d, 0xfc, 0xff, 0x27, 0x86, 0x96, 0x65,
|
||||||
|
0x92, 0x26, 0x78, 0x8b, 0xf8, 0xf6, 0xc1, 0xfd, 0x02, 0x1d, 0x04, 0xb3, 0x9c, 0x5b, 0xca, 0xd7,
|
||||||
|
0xf0, 0xbf, 0xca, 0x91, 0x17, 0x91, 0x64, 0x96, 0xd7, 0x2f, 0x3b, 0x0e, 0xd1, 0x4e, 0xee, 0x41,
|
||||||
|
0x33, 0x5a, 0x64, 0xf3, 0xc8, 0x46, 0x65, 0x16, 0x01, 0x81, 0xfe, 0x68, 0xc1, 0xa5, 0x3a, 0x80,
|
||||||
|
0x67, 0x66, 0xdb, 0xe0, 0x8f, 0x3a, 0x80, 0x3a, 0xcf, 0x9e, 0x32, 0x04, 0x2f, 0xd6, 0x10, 0x8c,
|
||||||
|
0x8b, 0x67, 0x7a, 0x7f, 0x6f, 0xf0, 0xf8, 0xa0, 0xac, 0xc3, 0xc1, 0xfa, 0x1e, 0x47, 0x77, 0x28,
|
||||||
|
0xc4, 0x2b, 0x1b, 0x79, 0x0e, 0xdb, 0x99, 0x51, 0x42, 0x9f, 0xee, 0x0d, 0x1e, 0x56, 0xe9, 0x15,
|
||||||
|
0x99, 0x90, 0xeb, 0xd0, 0x8a, 0x58, 0x18, 0x39, 0xfc, 0xbb, 0x9b, 0x88, 0x15, 0xad, 0x14, 0xd1,
|
||||||
|
0xa2, 0xc9, 0x8f, 0xb0, 0x35, 0xd5, 0x49, 0xf6, 0x1b, 0x9a, 0xf7, 0xa4, 0xca, 0xdb, 0x20, 0x00,
|
||||||
|
0xb2, 0x2d, 0x85, 0x7c, 0x07, 0x5b, 0x99, 0xce, 0xb3, 0xdf, 0xd4, 0xe4, 0xdd, 0xb5, 0x68, 0x4b,
|
||||||
|
0x1a, 0x28, 0x96, 0xc1, 0x1e, 0x6e, 0x41, 0x43, 0x09, 0x17, 0x5c, 0x40, 0x6f, 0xc2, 0xe2, 0x42,
|
||||||
|
0x24, 0xf9, 0xb5, 0xcd, 0xe0, 0x63, 0xf0, 0x0a, 0xc9, 0x42, 0xc5, 0x0f, 0xe3, 0x48, 0x67, 0xb0,
|
||||||
|
0x45, 0xdb, 0x68, 0x3a, 0x47, 0xcb, 0x28, 0x22, 0xdf, 0xc0, 0x3d, 0xc9, 0xc4, 0x7b, 0x26, 0xc2,
|
||||||
|
0x39, 0x47, 0x08, 0xc7, 0x2f, 0x91, 0x4c, 0x99, 0xce, 0x55, 0x9b, 0x12, 0xe3, 0x3b, 0x42, 0xd7,
|
||||||
|
0xcf, 0xd6, 0x13, 0xfc, 0xde, 0x84, 0xce, 0x68, 0x91, 0xb0, 0x34, 0x1f, 0xf1, 0xf4, 0x32, 0x99,
|
||||||
|
0x91, 0x2f, 0xa1, 0x67, 0xb7, 0xc8, 0x23, 0x31, 0x63, 0xb9, 0xc4, 0x53, 0xee, 0x22, 0xb9, 0x6b,
|
||||||
|
0xac, 0xe7, 0xc6, 0x48, 0x7e, 0x50, 0x5a, 0x2a, 0x5a, 0x98, 0x5f, 0x67, 0xe6, 0x80, 0xde, 0xc0,
|
||||||
|
0x5f, 0xd7, 0x52, 0x01, 0xce, 0xd1, 0xaf, 0x34, 0x74, 0xdf, 0x64, 0x0c, 0x3b, 0xd2, 0x5e, 0x2b,
|
||||||
|
0xcc, 0xf4, 0xbd, 0xac, 0x24, 0x7b, 0x55, 0x7a, 0xf5, 0xee, 0xb4, 0x27, 0xab, 0xb9, 0x78, 0x01,
|
||||||
|
0x7b, 0xbc, 0xc8, 0xb1, 0x4d, 0xd3, 0x29, 0xa2, 0x43, 0x64, 0xca, 0x30, 0xc3, 0xb0, 0xe3, 0x79,
|
||||||
|
0x94, 0xa6, 0x6c, 0xa1, 0xe5, 0x6a, 0xd2, 0x07, 0x25, 0x0c, 0x45, 0xc8, 0x19, 0x13, 0x23, 0x03,
|
||||||
|
0x50, 0x7d, 0x66, 0xaf, 0x60, 0x29, 0x52, 0xab, 0xd4, 0xa4, 0x3d, 0x63, 0xb6, 0x38, 0xa9, 0xb2,
|
||||||
|
0x1a, 0xc9, 0xeb, 0x34, 0x0e, 0xdd, 0x8d, 0xe7, 0x82, 0xe1, 0xa4, 0xf0, 0xb7, 0x35, 0x9a, 0x68,
|
||||||
|
0x9f, 0xbd, 0xab, 0xf1, 0x20, 0xa3, 0x85, 0xf1, 0x98, 0xd4, 0xb4, 0x74, 0x6a, 0xee, 0x57, 0xef,
|
||||||
|
0x86, 0xa1, 0xe8, 0xbc, 0x6c, 0x0b, 0xf3, 0xa1, 0xf2, 0xa9, 0x34, 0x77, 0x09, 0x01, 0x9d, 0x90,
|
||||||
|
0xb5, 0x7c, 0xde, 0xb4, 0x12, 0x85, 0xc5, 0x4d, 0x5b, 0x1d, 0x82, 0x1b, 0x5e, 0x61, 0xac, 0x35,
|
||||||
|
0xf4, 0xbd, 0x8d, 0xad, 0x61, 0x30, 0x46, 0x66, 0xda, 0xcd, 0xca, 0x4b, 0x72, 0x04, 0xfd, 0x39,
|
||||||
|
0x96, 0x30, 0x9f, 0xe1, 0x8e, 0x2e, 0x86, 0x8e, 0xde, 0xe5, 0x51, 0x75, 0x97, 0x23, 0x87, 0xb2,
|
||||||
|
0x81, 0xec, 0xcc, 0xab, 0x06, 0xf2, 0x10, 0xda, 0x31, 0x17, 0x2c, 0x5c, 0xa0, 0xdd, 0xef, 0x62,
|
||||||
|
0xe9, 0x34, 0x69, 0x4b, 0x19, 0x4e, 0x70, 0x4d, 0x1e, 0x01, 0x58, 0xe7, 0x32, 0xc9, 0xfd, 0x9e,
|
||||||
|
0xce, 0x5f, 0xdb, 0x78, 0xd1, 0x10, 0xbc, 0x70, 0xb5, 0x38, 0xc1, 0xe1, 0x5b, 0x48, 0xf2, 0x0c,
|
||||||
|
0x9a, 0x7a, 0x0c, 0xdb, 0x51, 0xf1, 0x60, 0x53, 0x79, 0x29, 0xa8, 0xa4, 0x06, 0x17, 0xec, 0x41,
|
||||||
|
0xe3, 0x55, 0x24, 0xde, 0xa9, 0x11, 0x25, 0x98, 0x64, 0xb9, 0xed, 0x10, 0xb3, 0x08, 0x0a, 0x00,
|
||||||
|
0xc3, 0x19, 0x8a, 0x99, 0x24, 0x03, 0xdc, 0x9c, 0xe5, 0x85, 0x9b, 0x43, 0xbb, 0x9b, 0x36, 0x37,
|
||||||
|
0xd9, 0xc1, 0xd6, 0x34, 0x50, 0xf2, 0x14, 0x1a, 0x4b, 0xdc, 0xdf, 0xce, 0x1e, 0x52, 0xa5, 0xa8,
|
||||||
|
0x93, 0x11, 0xaa, 0x11, 0x87, 0x6d, 0xd8, 0xc6, 0x4e, 0x51, 0x05, 0x10, 0xfc, 0x59, 0x87, 0xce,
|
||||||
|
0x44, 0x37, 0x8f, 0x4d, 0x36, 0x6a, 0xed, 0x5a, 0x4c, 0x15, 0x48, 0x6d, 0x53, 0xef, 0x18, 0x82,
|
||||||
|
0xe9, 0x1d, 0xb9, 0xfa, 0xde, 0xd4, 0x3b, 0xf5, 0x7f, 0xd1, 0x3b, 0x04, 0x1a, 0x19, 0x17, 0xb9,
|
||||||
|
0xed, 0x11, 0xfd, 0x7d, 0x53, 0xe5, 0x2e, 0xb6, 0x0d, 0x55, 0x6e, 0xa3, 0xb2, 0x55, 0x5e, 0x55,
|
||||||
|
0xb3, 0xb5, 0xa6, 0xe6, 0x86, 0xba, 0x6c, 0xff, 0xe3, 0xba, 0xac, 0x54, 0x13, 0x54, 0xab, 0x49,
|
||||||
|
0xe9, 0x69, 0x02, 0xba, 0x85, 0x9e, 0x65, 0x01, 0xfe, 0xa3, 0x9e, 0x89, 0x93, 0xf3, 0x56, 0x55,
|
||||||
|
0x7a, 0x03, 0x75, 0x55, 0xba, 0xca, 0x7e, 0xbd, 0x94, 0x7d, 0xac, 0x58, 0x75, 0x2f, 0x33, 0x0a,
|
||||||
|
0x9b, 0xd4, 0x2c, 0x82, 0x2e, 0x78, 0x23, 0xfc, 0xa0, 0xec, 0xb7, 0x02, 0xb7, 0x0b, 0xbe, 0xc0,
|
||||||
|
0xfe, 0xd0, 0x4b, 0x99, 0xf1, 0xd4, 0xbc, 0xc4, 0x86, 0x54, 0x2b, 0x93, 0xf0, 0xf9, 0x78, 0xc3,
|
||||||
|
0x93, 0x69, 0xf0, 0x57, 0x1d, 0x5a, 0x93, 0x98, 0xa5, 0x91, 0x48, 0xb8, 0x3a, 0x33, 0x8d, 0x96,
|
||||||
|
0xa6, 0xd8, 0xda, 0x54, 0x7f, 0xe3, 0x04, 0xed, 0xba, 0x01, 0x68, 0xf4, 0xa9, 0x7f, 0xac, 0x13,
|
||||||
|
0x68, 0x27, 0x2e, 0xbf, 0x15, 0x9f, 0x82, 0x97, 0x16, 0x4b, 0x3b, 0x16, 0x5d, 0xe8, 0x80, 0x26,
|
||||||
|
0xc3, 0x51, 0x33, 0xda, 0x3e, 0x1b, 0xee, 0x84, 0xc6, 0xc7, 0xb4, 0xa1, 0x1d, 0x59, 0x6e, 0x15,
|
||||||
|
0x7b, 0x82, 0xb1, 0xb9, 0xf9, 0xac, 0x4e, 0x30, 0x1c, 0xa9, 0x9e, 0xab, 0xab, 0x48, 0x2c, 0x8b,
|
||||||
|
0x0c, 0x31, 0x78, 0x06, 0xd6, 0xeb, 0x96, 0xc6, 0x74, 0x8d, 0x75, 0x62, 0x8c, 0xea, 0x07, 0xe7,
|
||||||
|
0x82, 0xa5, 0xf1, 0x5c, 0x69, 0xb9, 0x42, 0x9a, 0xca, 0xee, 0xaf, 0x1c, 0x0e, 0xfc, 0x1c, 0x7c,
|
||||||
|
0x99, 0x45, 0x57, 0x29, 0xfe, 0xa6, 0xc4, 0xf8, 0x33, 0x74, 0xc5, 0xc5, 0x3b, 0x7d, 0x83, 0x22,
|
||||||
|
0x75, 0x55, 0x7e, 0x5f, 0xfb, 0x4f, 0x94, 0xfb, 0x57, 0xed, 0x1d, 0x29, 0x67, 0x30, 0x84, 0xb6,
|
||||||
|
0x4b, 0xb8, 0xc4, 0xb7, 0xbf, 0x2d, 0xdd, 0x42, 0xbf, 0xa1, 0xde, 0xe0, 0x93, 0xb5, 0x7b, 0x5b,
|
||||||
|
0x37, 0xbd, 0x01, 0xee, 0x3f, 0x73, 0x33, 0x4a, 0xb7, 0xfb, 0x0e, 0x78, 0x93, 0xb7, 0xa7, 0xa3,
|
||||||
|
0x70, 0x74, 0x72, 0x3c, 0x3e, 0x3d, 0xef, 0xdf, 0x21, 0x7d, 0xe8, 0x0c, 0xcb, 0x96, 0xda, 0xfe,
|
||||||
|
0xb1, 0x6b, 0x82, 0x0a, 0x61, 0x32, 0xa6, 0x6f, 0xc6, 0xb4, 0x4c, 0xb0, 0x96, 0x1a, 0xf1, 0xe1,
|
||||||
|
0x9e, 0xb1, 0xbc, 0x1c, 0x9f, 0x8e, 0xe9, 0xf1, 0xca, 0x53, 0xdf, 0xff, 0x1c, 0xb6, 0xed, 0xbb,
|
||||||
|
0x44, 0xda, 0xd0, 0x7c, 0x7d, 0x3a, 0xa4, 0x6f, 0x71, 0x87, 0x2e, 0x5e, 0xea, 0x9c, 0x8e, 0x87,
|
||||||
|
0xaf, 0x8e, 0x4f, 0x5f, 0xf6, 0x6b, 0x17, 0x5b, 0xfa, 0x97, 0xf8, 0xdb, 0xbf, 0x03, 0x00, 0x00,
|
||||||
|
0xff, 0xff, 0x75, 0x59, 0xf4, 0x03, 0x4e, 0x0b, 0x00, 0x00,
|
||||||
|
}
|
201
vendor/google.golang.org/grpc/benchmark/grpc_testing/control.proto
generated
vendored
Normal file
201
vendor/google.golang.org/grpc/benchmark/grpc_testing/control.proto
generated
vendored
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
// Copyright 2016, 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";
|
||||||
|
|
||||||
|
import "payloads.proto";
|
||||||
|
import "stats.proto";
|
||||||
|
|
||||||
|
package grpc.testing;
|
||||||
|
|
||||||
|
enum ClientType {
|
||||||
|
SYNC_CLIENT = 0;
|
||||||
|
ASYNC_CLIENT = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ServerType {
|
||||||
|
SYNC_SERVER = 0;
|
||||||
|
ASYNC_SERVER = 1;
|
||||||
|
ASYNC_GENERIC_SERVER = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum RpcType {
|
||||||
|
UNARY = 0;
|
||||||
|
STREAMING = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parameters of poisson process distribution, which is a good representation
|
||||||
|
// of activity coming in from independent identical stationary sources.
|
||||||
|
message PoissonParams {
|
||||||
|
// The rate of arrivals (a.k.a. lambda parameter of the exp distribution).
|
||||||
|
double offered_load = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UniformParams {
|
||||||
|
double interarrival_lo = 1;
|
||||||
|
double interarrival_hi = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeterministicParams {
|
||||||
|
double offered_load = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ParetoParams {
|
||||||
|
double interarrival_base = 1;
|
||||||
|
double alpha = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Once an RPC finishes, immediately start a new one.
|
||||||
|
// No configuration parameters needed.
|
||||||
|
message ClosedLoopParams {
|
||||||
|
}
|
||||||
|
|
||||||
|
message LoadParams {
|
||||||
|
oneof load {
|
||||||
|
ClosedLoopParams closed_loop = 1;
|
||||||
|
PoissonParams poisson = 2;
|
||||||
|
UniformParams uniform = 3;
|
||||||
|
DeterministicParams determ = 4;
|
||||||
|
ParetoParams pareto = 5;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// presence of SecurityParams implies use of TLS
|
||||||
|
message SecurityParams {
|
||||||
|
bool use_test_ca = 1;
|
||||||
|
string server_host_override = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ClientConfig {
|
||||||
|
// List of targets to connect to. At least one target needs to be specified.
|
||||||
|
repeated string server_targets = 1;
|
||||||
|
ClientType client_type = 2;
|
||||||
|
SecurityParams security_params = 3;
|
||||||
|
// How many concurrent RPCs to start for each channel.
|
||||||
|
// For synchronous client, use a separate thread for each outstanding RPC.
|
||||||
|
int32 outstanding_rpcs_per_channel = 4;
|
||||||
|
// Number of independent client channels to create.
|
||||||
|
// i-th channel will connect to server_target[i % server_targets.size()]
|
||||||
|
int32 client_channels = 5;
|
||||||
|
// Only for async client. Number of threads to use to start/manage RPCs.
|
||||||
|
int32 async_client_threads = 7;
|
||||||
|
RpcType rpc_type = 8;
|
||||||
|
// The requested load for the entire client (aggregated over all the threads).
|
||||||
|
LoadParams load_params = 10;
|
||||||
|
PayloadConfig payload_config = 11;
|
||||||
|
HistogramParams histogram_params = 12;
|
||||||
|
|
||||||
|
// Specify the cores we should run the client on, if desired
|
||||||
|
repeated int32 core_list = 13;
|
||||||
|
int32 core_limit = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ClientStatus {
|
||||||
|
ClientStats stats = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request current stats
|
||||||
|
message Mark {
|
||||||
|
// if true, the stats will be reset after taking their snapshot.
|
||||||
|
bool reset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ClientArgs {
|
||||||
|
oneof argtype {
|
||||||
|
ClientConfig setup = 1;
|
||||||
|
Mark mark = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message ServerConfig {
|
||||||
|
ServerType server_type = 1;
|
||||||
|
SecurityParams security_params = 2;
|
||||||
|
// Port on which to listen. Zero means pick unused port.
|
||||||
|
int32 port = 4;
|
||||||
|
// Only for async server. Number of threads used to serve the requests.
|
||||||
|
int32 async_server_threads = 7;
|
||||||
|
// Specify the number of cores to limit server to, if desired
|
||||||
|
int32 core_limit = 8;
|
||||||
|
// payload config, used in generic server
|
||||||
|
PayloadConfig payload_config = 9;
|
||||||
|
|
||||||
|
// Specify the cores we should run the server on, if desired
|
||||||
|
repeated int32 core_list = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ServerArgs {
|
||||||
|
oneof argtype {
|
||||||
|
ServerConfig setup = 1;
|
||||||
|
Mark mark = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message ServerStatus {
|
||||||
|
ServerStats stats = 1;
|
||||||
|
// the port bound by the server
|
||||||
|
int32 port = 2;
|
||||||
|
// Number of cores available to the server
|
||||||
|
int32 cores = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CoreRequest {
|
||||||
|
}
|
||||||
|
|
||||||
|
message CoreResponse {
|
||||||
|
// Number of cores available on the server
|
||||||
|
int32 cores = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Void {
|
||||||
|
}
|
||||||
|
|
||||||
|
// A single performance scenario: input to qps_json_driver
|
||||||
|
message Scenario {
|
||||||
|
// Human readable name for this scenario
|
||||||
|
string name = 1;
|
||||||
|
// Client configuration
|
||||||
|
ClientConfig client_config = 2;
|
||||||
|
// Number of clients to start for the test
|
||||||
|
int32 num_clients = 3;
|
||||||
|
// Server configuration
|
||||||
|
ServerConfig server_config = 4;
|
||||||
|
// Number of servers to start for the test
|
||||||
|
int32 num_servers = 5;
|
||||||
|
// Warmup period, in seconds
|
||||||
|
int32 warmup_seconds = 6;
|
||||||
|
// Benchmark time, in seconds
|
||||||
|
int32 benchmark_seconds = 7;
|
||||||
|
// Number of workers to spawn locally (usually zero)
|
||||||
|
int32 spawn_local_worker_count = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A set of scenarios to be run with qps_json_driver
|
||||||
|
message Scenarios {
|
||||||
|
repeated Scenario scenarios = 1;
|
||||||
|
}
|
347
vendor/google.golang.org/grpc/benchmark/grpc_testing/messages.pb.go
generated
vendored
Normal file
347
vendor/google.golang.org/grpc/benchmark/grpc_testing/messages.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,347 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: messages.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// The type of payload that should be returned.
|
||||||
|
type PayloadType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Compressable text format.
|
||||||
|
PayloadType_COMPRESSABLE PayloadType = 0
|
||||||
|
// Uncompressable binary format.
|
||||||
|
PayloadType_UNCOMPRESSABLE PayloadType = 1
|
||||||
|
// Randomly chosen from all other formats defined in this enum.
|
||||||
|
PayloadType_RANDOM PayloadType = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var PayloadType_name = map[int32]string{
|
||||||
|
0: "COMPRESSABLE",
|
||||||
|
1: "UNCOMPRESSABLE",
|
||||||
|
2: "RANDOM",
|
||||||
|
}
|
||||||
|
var PayloadType_value = map[string]int32{
|
||||||
|
"COMPRESSABLE": 0,
|
||||||
|
"UNCOMPRESSABLE": 1,
|
||||||
|
"RANDOM": 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x PayloadType) String() string {
|
||||||
|
return proto.EnumName(PayloadType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (PayloadType) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
||||||
|
|
||||||
|
// Compression algorithms
|
||||||
|
type CompressionType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
// No compression
|
||||||
|
CompressionType_NONE CompressionType = 0
|
||||||
|
CompressionType_GZIP CompressionType = 1
|
||||||
|
CompressionType_DEFLATE CompressionType = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var CompressionType_name = map[int32]string{
|
||||||
|
0: "NONE",
|
||||||
|
1: "GZIP",
|
||||||
|
2: "DEFLATE",
|
||||||
|
}
|
||||||
|
var CompressionType_value = map[string]int32{
|
||||||
|
"NONE": 0,
|
||||||
|
"GZIP": 1,
|
||||||
|
"DEFLATE": 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x CompressionType) String() string {
|
||||||
|
return proto.EnumName(CompressionType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (CompressionType) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{1} }
|
||||||
|
|
||||||
|
// A block of data, to simply increase gRPC message size.
|
||||||
|
type Payload struct {
|
||||||
|
// The type of data in body.
|
||||||
|
Type PayloadType `protobuf:"varint,1,opt,name=type,enum=grpc.testing.PayloadType" json:"type,omitempty"`
|
||||||
|
// Primary contents of payload.
|
||||||
|
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Payload) Reset() { *m = Payload{} }
|
||||||
|
func (m *Payload) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Payload) ProtoMessage() {}
|
||||||
|
func (*Payload) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
||||||
|
|
||||||
|
// A protobuf representation for grpc status. This is used by test
|
||||||
|
// clients to specify a status that the server should attempt to return.
|
||||||
|
type EchoStatus struct {
|
||||||
|
Code int32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"`
|
||||||
|
Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *EchoStatus) Reset() { *m = EchoStatus{} }
|
||||||
|
func (m *EchoStatus) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*EchoStatus) ProtoMessage() {}
|
||||||
|
func (*EchoStatus) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{1} }
|
||||||
|
|
||||||
|
// Unary request.
|
||||||
|
type SimpleRequest struct {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, server randomly chooses one from other formats.
|
||||||
|
ResponseType PayloadType `protobuf:"varint,1,opt,name=response_type,json=responseType,enum=grpc.testing.PayloadType" json:"response_type,omitempty"`
|
||||||
|
// Desired payload size in the response from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
ResponseSize int32 `protobuf:"varint,2,opt,name=response_size,json=responseSize" json:"response_size,omitempty"`
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload *Payload `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
// Whether SimpleResponse should include username.
|
||||||
|
FillUsername bool `protobuf:"varint,4,opt,name=fill_username,json=fillUsername" json:"fill_username,omitempty"`
|
||||||
|
// Whether SimpleResponse should include OAuth scope.
|
||||||
|
FillOauthScope bool `protobuf:"varint,5,opt,name=fill_oauth_scope,json=fillOauthScope" json:"fill_oauth_scope,omitempty"`
|
||||||
|
// Compression algorithm to be used by the server for the response (stream)
|
||||||
|
ResponseCompression CompressionType `protobuf:"varint,6,opt,name=response_compression,json=responseCompression,enum=grpc.testing.CompressionType" json:"response_compression,omitempty"`
|
||||||
|
// Whether server should return a given status
|
||||||
|
ResponseStatus *EchoStatus `protobuf:"bytes,7,opt,name=response_status,json=responseStatus" json:"response_status,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleRequest) Reset() { *m = SimpleRequest{} }
|
||||||
|
func (m *SimpleRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SimpleRequest) ProtoMessage() {}
|
||||||
|
func (*SimpleRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{2} }
|
||||||
|
|
||||||
|
func (m *SimpleRequest) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleRequest) GetResponseStatus() *EchoStatus {
|
||||||
|
if m != nil {
|
||||||
|
return m.ResponseStatus
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unary response, as configured by the request.
|
||||||
|
type SimpleResponse struct {
|
||||||
|
// Payload to increase message size.
|
||||||
|
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
// The user the request came from, for verifying authentication was
|
||||||
|
// successful when the client expected it.
|
||||||
|
Username string `protobuf:"bytes,2,opt,name=username" json:"username,omitempty"`
|
||||||
|
// OAuth scope.
|
||||||
|
OauthScope string `protobuf:"bytes,3,opt,name=oauth_scope,json=oauthScope" json:"oauth_scope,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleResponse) Reset() { *m = SimpleResponse{} }
|
||||||
|
func (m *SimpleResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SimpleResponse) ProtoMessage() {}
|
||||||
|
func (*SimpleResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{3} }
|
||||||
|
|
||||||
|
func (m *SimpleResponse) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming request.
|
||||||
|
type StreamingInputCallRequest struct {
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingInputCallRequest) Reset() { *m = StreamingInputCallRequest{} }
|
||||||
|
func (m *StreamingInputCallRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingInputCallRequest) ProtoMessage() {}
|
||||||
|
func (*StreamingInputCallRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{4} }
|
||||||
|
|
||||||
|
func (m *StreamingInputCallRequest) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming response.
|
||||||
|
type StreamingInputCallResponse struct {
|
||||||
|
// Aggregated size of payloads received from the client.
|
||||||
|
AggregatedPayloadSize int32 `protobuf:"varint,1,opt,name=aggregated_payload_size,json=aggregatedPayloadSize" json:"aggregated_payload_size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingInputCallResponse) Reset() { *m = StreamingInputCallResponse{} }
|
||||||
|
func (m *StreamingInputCallResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingInputCallResponse) ProtoMessage() {}
|
||||||
|
func (*StreamingInputCallResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{5} }
|
||||||
|
|
||||||
|
// Configuration for a particular response.
|
||||||
|
type ResponseParameters struct {
|
||||||
|
// Desired payload sizes in responses from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
Size int32 `protobuf:"varint,1,opt,name=size" json:"size,omitempty"`
|
||||||
|
// Desired interval between consecutive responses in the response stream in
|
||||||
|
// microseconds.
|
||||||
|
IntervalUs int32 `protobuf:"varint,2,opt,name=interval_us,json=intervalUs" json:"interval_us,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponseParameters) Reset() { *m = ResponseParameters{} }
|
||||||
|
func (m *ResponseParameters) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ResponseParameters) ProtoMessage() {}
|
||||||
|
func (*ResponseParameters) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{6} }
|
||||||
|
|
||||||
|
// Server-streaming request.
|
||||||
|
type StreamingOutputCallRequest struct {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, the payload from each response in the stream
|
||||||
|
// might be of different types. This is to simulate a mixed type of payload
|
||||||
|
// stream.
|
||||||
|
ResponseType PayloadType `protobuf:"varint,1,opt,name=response_type,json=responseType,enum=grpc.testing.PayloadType" json:"response_type,omitempty"`
|
||||||
|
// Configuration for each expected response message.
|
||||||
|
ResponseParameters []*ResponseParameters `protobuf:"bytes,2,rep,name=response_parameters,json=responseParameters" json:"response_parameters,omitempty"`
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload *Payload `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
// Compression algorithm to be used by the server for the response (stream)
|
||||||
|
ResponseCompression CompressionType `protobuf:"varint,6,opt,name=response_compression,json=responseCompression,enum=grpc.testing.CompressionType" json:"response_compression,omitempty"`
|
||||||
|
// Whether server should return a given status
|
||||||
|
ResponseStatus *EchoStatus `protobuf:"bytes,7,opt,name=response_status,json=responseStatus" json:"response_status,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) Reset() { *m = StreamingOutputCallRequest{} }
|
||||||
|
func (m *StreamingOutputCallRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingOutputCallRequest) ProtoMessage() {}
|
||||||
|
func (*StreamingOutputCallRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{7} }
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) GetResponseParameters() []*ResponseParameters {
|
||||||
|
if m != nil {
|
||||||
|
return m.ResponseParameters
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) GetResponseStatus() *EchoStatus {
|
||||||
|
if m != nil {
|
||||||
|
return m.ResponseStatus
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-streaming response, as configured by the request and parameters.
|
||||||
|
type StreamingOutputCallResponse struct {
|
||||||
|
// Payload to increase response size.
|
||||||
|
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallResponse) Reset() { *m = StreamingOutputCallResponse{} }
|
||||||
|
func (m *StreamingOutputCallResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingOutputCallResponse) ProtoMessage() {}
|
||||||
|
func (*StreamingOutputCallResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{8} }
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallResponse) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// For reconnect interop test only.
|
||||||
|
// Client tells server what reconnection parameters it used.
|
||||||
|
type ReconnectParams struct {
|
||||||
|
MaxReconnectBackoffMs int32 `protobuf:"varint,1,opt,name=max_reconnect_backoff_ms,json=maxReconnectBackoffMs" json:"max_reconnect_backoff_ms,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ReconnectParams) Reset() { *m = ReconnectParams{} }
|
||||||
|
func (m *ReconnectParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ReconnectParams) ProtoMessage() {}
|
||||||
|
func (*ReconnectParams) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{9} }
|
||||||
|
|
||||||
|
// For reconnect interop test only.
|
||||||
|
// Server tells client whether its reconnects are following the spec and the
|
||||||
|
// reconnect backoffs it saw.
|
||||||
|
type ReconnectInfo struct {
|
||||||
|
Passed bool `protobuf:"varint,1,opt,name=passed" json:"passed,omitempty"`
|
||||||
|
BackoffMs []int32 `protobuf:"varint,2,rep,name=backoff_ms,json=backoffMs" json:"backoff_ms,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ReconnectInfo) Reset() { *m = ReconnectInfo{} }
|
||||||
|
func (m *ReconnectInfo) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ReconnectInfo) ProtoMessage() {}
|
||||||
|
func (*ReconnectInfo) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{10} }
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*Payload)(nil), "grpc.testing.Payload")
|
||||||
|
proto.RegisterType((*EchoStatus)(nil), "grpc.testing.EchoStatus")
|
||||||
|
proto.RegisterType((*SimpleRequest)(nil), "grpc.testing.SimpleRequest")
|
||||||
|
proto.RegisterType((*SimpleResponse)(nil), "grpc.testing.SimpleResponse")
|
||||||
|
proto.RegisterType((*StreamingInputCallRequest)(nil), "grpc.testing.StreamingInputCallRequest")
|
||||||
|
proto.RegisterType((*StreamingInputCallResponse)(nil), "grpc.testing.StreamingInputCallResponse")
|
||||||
|
proto.RegisterType((*ResponseParameters)(nil), "grpc.testing.ResponseParameters")
|
||||||
|
proto.RegisterType((*StreamingOutputCallRequest)(nil), "grpc.testing.StreamingOutputCallRequest")
|
||||||
|
proto.RegisterType((*StreamingOutputCallResponse)(nil), "grpc.testing.StreamingOutputCallResponse")
|
||||||
|
proto.RegisterType((*ReconnectParams)(nil), "grpc.testing.ReconnectParams")
|
||||||
|
proto.RegisterType((*ReconnectInfo)(nil), "grpc.testing.ReconnectInfo")
|
||||||
|
proto.RegisterEnum("grpc.testing.PayloadType", PayloadType_name, PayloadType_value)
|
||||||
|
proto.RegisterEnum("grpc.testing.CompressionType", CompressionType_name, CompressionType_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("messages.proto", fileDescriptor1) }
|
||||||
|
|
||||||
|
var fileDescriptor1 = []byte{
|
||||||
|
// 645 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xcc, 0x55, 0x4d, 0x6f, 0xd3, 0x40,
|
||||||
|
0x10, 0x25, 0xdf, 0xe9, 0x24, 0x4d, 0xa3, 0x85, 0x82, 0x5b, 0x54, 0x51, 0x99, 0x4b, 0x55, 0x89,
|
||||||
|
0x20, 0x15, 0x09, 0x24, 0x0e, 0xa0, 0xb4, 0x4d, 0x51, 0x50, 0x9b, 0x84, 0x75, 0x7b, 0xe1, 0x62,
|
||||||
|
0x6d, 0x9c, 0x4d, 0x1a, 0x11, 0x7b, 0x8d, 0x77, 0x8d, 0x28, 0x07, 0xee, 0xfc, 0x60, 0xee, 0xec,
|
||||||
|
0xae, 0xbd, 0x8e, 0xd3, 0xf6, 0xd0, 0xc2, 0x85, 0xdb, 0xce, 0xcc, 0x9b, 0x97, 0x79, 0x33, 0xcf,
|
||||||
|
0x0a, 0xb4, 0x7c, 0xca, 0x39, 0x99, 0x51, 0xde, 0x09, 0x23, 0x26, 0x18, 0x6a, 0xce, 0xa2, 0xd0,
|
||||||
|
0xeb, 0x08, 0xca, 0xc5, 0x3c, 0x98, 0xd9, 0xa7, 0x50, 0x1b, 0x91, 0xab, 0x05, 0x23, 0x13, 0xf4,
|
||||||
|
0x02, 0xca, 0xe2, 0x2a, 0xa4, 0x56, 0x61, 0xb7, 0xb0, 0xd7, 0x3a, 0xd8, 0xea, 0xe4, 0x71, 0x9d,
|
||||||
|
0x14, 0x74, 0x2e, 0x01, 0x58, 0xc3, 0x10, 0x82, 0xf2, 0x98, 0x4d, 0xae, 0xac, 0xa2, 0x84, 0x37,
|
||||||
|
0xb1, 0x7e, 0xdb, 0x6f, 0x01, 0x7a, 0xde, 0x25, 0x73, 0x04, 0x11, 0x31, 0x57, 0x08, 0x8f, 0x4d,
|
||||||
|
0x12, 0xc2, 0x0a, 0xd6, 0x6f, 0x64, 0x41, 0x2d, 0x9d, 0x47, 0x37, 0xae, 0x61, 0x13, 0xda, 0xbf,
|
||||||
|
0x4a, 0xb0, 0xee, 0xcc, 0xfd, 0x70, 0x41, 0x31, 0xfd, 0x1a, 0xcb, 0x9f, 0x45, 0xef, 0x60, 0x3d,
|
||||||
|
0xa2, 0x3c, 0x64, 0x01, 0xa7, 0xee, 0xdd, 0x26, 0x6b, 0x1a, 0xbc, 0x8a, 0xd0, 0xf3, 0x5c, 0x3f,
|
||||||
|
0x9f, 0xff, 0x48, 0x7e, 0xb1, 0xb2, 0x04, 0x39, 0x32, 0x87, 0x5e, 0x42, 0x2d, 0x4c, 0x18, 0xac,
|
||||||
|
0x92, 0x2c, 0x37, 0x0e, 0x36, 0x6f, 0xa5, 0xc7, 0x06, 0xa5, 0x58, 0xa7, 0xf3, 0xc5, 0xc2, 0x8d,
|
||||||
|
0x39, 0x8d, 0x02, 0xe2, 0x53, 0xab, 0x2c, 0xdb, 0xea, 0xb8, 0xa9, 0x92, 0x17, 0x69, 0x0e, 0xed,
|
||||||
|
0x41, 0x5b, 0x83, 0x18, 0x89, 0xc5, 0xa5, 0xcb, 0x3d, 0x26, 0xa7, 0xaf, 0x68, 0x5c, 0x4b, 0xe5,
|
||||||
|
0x87, 0x2a, 0xed, 0xa8, 0x2c, 0x1a, 0xc1, 0xa3, 0x6c, 0x48, 0x8f, 0xf9, 0xa1, 0x0c, 0xf8, 0x9c,
|
||||||
|
0x05, 0x56, 0x55, 0x6b, 0xdd, 0x59, 0x1d, 0xe6, 0x68, 0x09, 0xd0, 0x7a, 0x1f, 0x9a, 0xd6, 0x5c,
|
||||||
|
0x01, 0x75, 0x61, 0x63, 0x29, 0x5b, 0x5f, 0xc2, 0xaa, 0x69, 0x65, 0xd6, 0x2a, 0xd9, 0xf2, 0x52,
|
||||||
|
0xb8, 0x95, 0xad, 0x44, 0xc7, 0xf6, 0x4f, 0x68, 0x99, 0x53, 0x24, 0xf9, 0xfc, 0x9a, 0x0a, 0x77,
|
||||||
|
0x5a, 0xd3, 0x36, 0xd4, 0xb3, 0x0d, 0x25, 0x97, 0xce, 0x62, 0xf4, 0x0c, 0x1a, 0xf9, 0xc5, 0x94,
|
||||||
|
0x74, 0x19, 0x58, 0xb6, 0x14, 0xe9, 0xca, 0x2d, 0x47, 0x44, 0x94, 0xf8, 0x92, 0xba, 0x1f, 0x84,
|
||||||
|
0xb1, 0x38, 0x22, 0x8b, 0x85, 0xb1, 0xc5, 0x7d, 0x47, 0xb1, 0xcf, 0x61, 0xfb, 0x36, 0xb6, 0x54,
|
||||||
|
0xd9, 0x6b, 0x78, 0x42, 0x66, 0xb3, 0x88, 0xce, 0x88, 0xa0, 0x13, 0x37, 0xed, 0x49, 0xfc, 0x92,
|
||||||
|
0x18, 0x77, 0x73, 0x59, 0x4e, 0xa9, 0x95, 0x71, 0xec, 0x3e, 0x20, 0xc3, 0x31, 0x22, 0x91, 0x94,
|
||||||
|
0x25, 0x68, 0xa4, 0x3d, 0x9f, 0x6b, 0xd5, 0x6f, 0x25, 0x77, 0x1e, 0xc8, 0xea, 0x37, 0xa2, 0x5c,
|
||||||
|
0x93, 0xba, 0x10, 0x4c, 0xea, 0x82, 0xdb, 0xbf, 0x8b, 0xb9, 0x09, 0x87, 0xb1, 0xb8, 0x26, 0xf8,
|
||||||
|
0x5f, 0xbf, 0x83, 0x4f, 0x90, 0xf9, 0x44, 0xea, 0x33, 0xa3, 0xca, 0x39, 0x4a, 0x72, 0x79, 0xbb,
|
||||||
|
0xab, 0x2c, 0x37, 0x25, 0x61, 0x14, 0xdd, 0x94, 0x79, 0xef, 0xaf, 0xe6, 0xbf, 0xb4, 0xf9, 0x00,
|
||||||
|
0x9e, 0xde, 0xba, 0xf6, 0xbf, 0xf4, 0xbc, 0xfd, 0x11, 0x36, 0x30, 0xf5, 0x58, 0x10, 0x50, 0x4f,
|
||||||
|
0xe8, 0x65, 0x71, 0xf4, 0x06, 0x2c, 0x9f, 0x7c, 0x77, 0x23, 0x93, 0x76, 0xc7, 0xc4, 0xfb, 0xc2,
|
||||||
|
0xa6, 0x53, 0xd7, 0xe7, 0xc6, 0x5e, 0xb2, 0x9e, 0x75, 0x1d, 0x26, 0xd5, 0x33, 0x6e, 0x9f, 0xc0,
|
||||||
|
0x7a, 0x96, 0xed, 0x07, 0x53, 0x86, 0x1e, 0x43, 0x35, 0x24, 0x9c, 0xd3, 0x64, 0x98, 0x3a, 0x4e,
|
||||||
|
0x23, 0xb4, 0x03, 0x90, 0xe3, 0x54, 0x47, 0xad, 0xe0, 0xb5, 0xb1, 0xe1, 0xd9, 0x7f, 0x0f, 0x8d,
|
||||||
|
0x9c, 0x33, 0x50, 0x1b, 0x9a, 0x47, 0xc3, 0xb3, 0x11, 0xee, 0x39, 0x4e, 0xf7, 0xf0, 0xb4, 0xd7,
|
||||||
|
0x7e, 0x20, 0x1d, 0xdb, 0xba, 0x18, 0xac, 0xe4, 0x0a, 0x08, 0xa0, 0x8a, 0xbb, 0x83, 0xe3, 0xe1,
|
||||||
|
0x59, 0xbb, 0xb8, 0x7f, 0x00, 0x1b, 0xd7, 0xee, 0x81, 0xea, 0x50, 0x1e, 0x0c, 0x07, 0xaa, 0x59,
|
||||||
|
0xbe, 0x3e, 0x7c, 0xee, 0x8f, 0x64, 0x4b, 0x03, 0x6a, 0xc7, 0xbd, 0x93, 0xd3, 0xee, 0x79, 0xaf,
|
||||||
|
0x5d, 0x1c, 0x57, 0xf5, 0x5f, 0xcd, 0xab, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xc2, 0x6a, 0xce,
|
||||||
|
0x1e, 0x7c, 0x06, 0x00, 0x00,
|
||||||
|
}
|
172
vendor/google.golang.org/grpc/benchmark/grpc_testing/messages.proto
generated
vendored
Normal file
172
vendor/google.golang.org/grpc/benchmark/grpc_testing/messages.proto
generated
vendored
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
// Copyright 2016, 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.
|
||||||
|
|
||||||
|
// Message definitions to be used by integration test service definitions.
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package grpc.testing;
|
||||||
|
|
||||||
|
// The type of payload that should be returned.
|
||||||
|
enum PayloadType {
|
||||||
|
// Compressable text format.
|
||||||
|
COMPRESSABLE = 0;
|
||||||
|
|
||||||
|
// Uncompressable binary format.
|
||||||
|
UNCOMPRESSABLE = 1;
|
||||||
|
|
||||||
|
// Randomly chosen from all other formats defined in this enum.
|
||||||
|
RANDOM = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compression algorithms
|
||||||
|
enum CompressionType {
|
||||||
|
// No compression
|
||||||
|
NONE = 0;
|
||||||
|
GZIP = 1;
|
||||||
|
DEFLATE = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A block of data, to simply increase gRPC message size.
|
||||||
|
message Payload {
|
||||||
|
// The type of data in body.
|
||||||
|
PayloadType type = 1;
|
||||||
|
// Primary contents of payload.
|
||||||
|
bytes body = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A protobuf representation for grpc status. This is used by test
|
||||||
|
// clients to specify a status that the server should attempt to return.
|
||||||
|
message EchoStatus {
|
||||||
|
int32 code = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unary request.
|
||||||
|
message SimpleRequest {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, server randomly chooses one from other formats.
|
||||||
|
PayloadType response_type = 1;
|
||||||
|
|
||||||
|
// Desired payload size in the response from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
int32 response_size = 2;
|
||||||
|
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload payload = 3;
|
||||||
|
|
||||||
|
// Whether SimpleResponse should include username.
|
||||||
|
bool fill_username = 4;
|
||||||
|
|
||||||
|
// Whether SimpleResponse should include OAuth scope.
|
||||||
|
bool fill_oauth_scope = 5;
|
||||||
|
|
||||||
|
// Compression algorithm to be used by the server for the response (stream)
|
||||||
|
CompressionType response_compression = 6;
|
||||||
|
|
||||||
|
// Whether server should return a given status
|
||||||
|
EchoStatus response_status = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unary response, as configured by the request.
|
||||||
|
message SimpleResponse {
|
||||||
|
// Payload to increase message size.
|
||||||
|
Payload payload = 1;
|
||||||
|
// The user the request came from, for verifying authentication was
|
||||||
|
// successful when the client expected it.
|
||||||
|
string username = 2;
|
||||||
|
// OAuth scope.
|
||||||
|
string oauth_scope = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming request.
|
||||||
|
message StreamingInputCallRequest {
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload payload = 1;
|
||||||
|
|
||||||
|
// Not expecting any payload from the response.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming response.
|
||||||
|
message StreamingInputCallResponse {
|
||||||
|
// Aggregated size of payloads received from the client.
|
||||||
|
int32 aggregated_payload_size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration for a particular response.
|
||||||
|
message ResponseParameters {
|
||||||
|
// Desired payload sizes in responses from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
int32 size = 1;
|
||||||
|
|
||||||
|
// Desired interval between consecutive responses in the response stream in
|
||||||
|
// microseconds.
|
||||||
|
int32 interval_us = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-streaming request.
|
||||||
|
message StreamingOutputCallRequest {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, the payload from each response in the stream
|
||||||
|
// might be of different types. This is to simulate a mixed type of payload
|
||||||
|
// stream.
|
||||||
|
PayloadType response_type = 1;
|
||||||
|
|
||||||
|
// Configuration for each expected response message.
|
||||||
|
repeated ResponseParameters response_parameters = 2;
|
||||||
|
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload payload = 3;
|
||||||
|
|
||||||
|
// Compression algorithm to be used by the server for the response (stream)
|
||||||
|
CompressionType response_compression = 6;
|
||||||
|
|
||||||
|
// Whether server should return a given status
|
||||||
|
EchoStatus response_status = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-streaming response, as configured by the request and parameters.
|
||||||
|
message StreamingOutputCallResponse {
|
||||||
|
// Payload to increase response size.
|
||||||
|
Payload payload = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For reconnect interop test only.
|
||||||
|
// Client tells server what reconnection parameters it used.
|
||||||
|
message ReconnectParams {
|
||||||
|
int32 max_reconnect_backoff_ms = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For reconnect interop test only.
|
||||||
|
// Server tells client whether its reconnects are following the spec and the
|
||||||
|
// reconnect backoffs it saw.
|
||||||
|
message ReconnectInfo {
|
||||||
|
bool passed = 1;
|
||||||
|
repeated int32 backoff_ms = 2;
|
||||||
|
}
|
223
vendor/google.golang.org/grpc/benchmark/grpc_testing/payloads.pb.go
generated
vendored
Normal file
223
vendor/google.golang.org/grpc/benchmark/grpc_testing/payloads.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,223 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: payloads.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
type ByteBufferParams struct {
|
||||||
|
ReqSize int32 `protobuf:"varint,1,opt,name=req_size,json=reqSize" json:"req_size,omitempty"`
|
||||||
|
RespSize int32 `protobuf:"varint,2,opt,name=resp_size,json=respSize" json:"resp_size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ByteBufferParams) Reset() { *m = ByteBufferParams{} }
|
||||||
|
func (m *ByteBufferParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ByteBufferParams) ProtoMessage() {}
|
||||||
|
func (*ByteBufferParams) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
|
||||||
|
|
||||||
|
type SimpleProtoParams struct {
|
||||||
|
ReqSize int32 `protobuf:"varint,1,opt,name=req_size,json=reqSize" json:"req_size,omitempty"`
|
||||||
|
RespSize int32 `protobuf:"varint,2,opt,name=resp_size,json=respSize" json:"resp_size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleProtoParams) Reset() { *m = SimpleProtoParams{} }
|
||||||
|
func (m *SimpleProtoParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SimpleProtoParams) ProtoMessage() {}
|
||||||
|
func (*SimpleProtoParams) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{1} }
|
||||||
|
|
||||||
|
type ComplexProtoParams struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ComplexProtoParams) Reset() { *m = ComplexProtoParams{} }
|
||||||
|
func (m *ComplexProtoParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ComplexProtoParams) ProtoMessage() {}
|
||||||
|
func (*ComplexProtoParams) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{2} }
|
||||||
|
|
||||||
|
type PayloadConfig struct {
|
||||||
|
// Types that are valid to be assigned to Payload:
|
||||||
|
// *PayloadConfig_BytebufParams
|
||||||
|
// *PayloadConfig_SimpleParams
|
||||||
|
// *PayloadConfig_ComplexParams
|
||||||
|
Payload isPayloadConfig_Payload `protobuf_oneof:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PayloadConfig) Reset() { *m = PayloadConfig{} }
|
||||||
|
func (m *PayloadConfig) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*PayloadConfig) ProtoMessage() {}
|
||||||
|
func (*PayloadConfig) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{3} }
|
||||||
|
|
||||||
|
type isPayloadConfig_Payload interface {
|
||||||
|
isPayloadConfig_Payload()
|
||||||
|
}
|
||||||
|
|
||||||
|
type PayloadConfig_BytebufParams struct {
|
||||||
|
BytebufParams *ByteBufferParams `protobuf:"bytes,1,opt,name=bytebuf_params,json=bytebufParams,oneof"`
|
||||||
|
}
|
||||||
|
type PayloadConfig_SimpleParams struct {
|
||||||
|
SimpleParams *SimpleProtoParams `protobuf:"bytes,2,opt,name=simple_params,json=simpleParams,oneof"`
|
||||||
|
}
|
||||||
|
type PayloadConfig_ComplexParams struct {
|
||||||
|
ComplexParams *ComplexProtoParams `protobuf:"bytes,3,opt,name=complex_params,json=complexParams,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*PayloadConfig_BytebufParams) isPayloadConfig_Payload() {}
|
||||||
|
func (*PayloadConfig_SimpleParams) isPayloadConfig_Payload() {}
|
||||||
|
func (*PayloadConfig_ComplexParams) isPayloadConfig_Payload() {}
|
||||||
|
|
||||||
|
func (m *PayloadConfig) GetPayload() isPayloadConfig_Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PayloadConfig) GetBytebufParams() *ByteBufferParams {
|
||||||
|
if x, ok := m.GetPayload().(*PayloadConfig_BytebufParams); ok {
|
||||||
|
return x.BytebufParams
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PayloadConfig) GetSimpleParams() *SimpleProtoParams {
|
||||||
|
if x, ok := m.GetPayload().(*PayloadConfig_SimpleParams); ok {
|
||||||
|
return x.SimpleParams
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PayloadConfig) GetComplexParams() *ComplexProtoParams {
|
||||||
|
if x, ok := m.GetPayload().(*PayloadConfig_ComplexParams); ok {
|
||||||
|
return x.ComplexParams
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*PayloadConfig) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _PayloadConfig_OneofMarshaler, _PayloadConfig_OneofUnmarshaler, _PayloadConfig_OneofSizer, []interface{}{
|
||||||
|
(*PayloadConfig_BytebufParams)(nil),
|
||||||
|
(*PayloadConfig_SimpleParams)(nil),
|
||||||
|
(*PayloadConfig_ComplexParams)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PayloadConfig_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*PayloadConfig)
|
||||||
|
// payload
|
||||||
|
switch x := m.Payload.(type) {
|
||||||
|
case *PayloadConfig_BytebufParams:
|
||||||
|
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.BytebufParams); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *PayloadConfig_SimpleParams:
|
||||||
|
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.SimpleParams); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *PayloadConfig_ComplexParams:
|
||||||
|
b.EncodeVarint(3<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.ComplexParams); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("PayloadConfig.Payload has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PayloadConfig_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*PayloadConfig)
|
||||||
|
switch tag {
|
||||||
|
case 1: // payload.bytebuf_params
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ByteBufferParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Payload = &PayloadConfig_BytebufParams{msg}
|
||||||
|
return true, err
|
||||||
|
case 2: // payload.simple_params
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(SimpleProtoParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Payload = &PayloadConfig_SimpleParams{msg}
|
||||||
|
return true, err
|
||||||
|
case 3: // payload.complex_params
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ComplexProtoParams)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.Payload = &PayloadConfig_ComplexParams{msg}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PayloadConfig_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*PayloadConfig)
|
||||||
|
// payload
|
||||||
|
switch x := m.Payload.(type) {
|
||||||
|
case *PayloadConfig_BytebufParams:
|
||||||
|
s := proto.Size(x.BytebufParams)
|
||||||
|
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *PayloadConfig_SimpleParams:
|
||||||
|
s := proto.Size(x.SimpleParams)
|
||||||
|
n += proto.SizeVarint(2<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *PayloadConfig_ComplexParams:
|
||||||
|
s := proto.Size(x.ComplexParams)
|
||||||
|
n += proto.SizeVarint(3<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*ByteBufferParams)(nil), "grpc.testing.ByteBufferParams")
|
||||||
|
proto.RegisterType((*SimpleProtoParams)(nil), "grpc.testing.SimpleProtoParams")
|
||||||
|
proto.RegisterType((*ComplexProtoParams)(nil), "grpc.testing.ComplexProtoParams")
|
||||||
|
proto.RegisterType((*PayloadConfig)(nil), "grpc.testing.PayloadConfig")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("payloads.proto", fileDescriptor2) }
|
||||||
|
|
||||||
|
var fileDescriptor2 = []byte{
|
||||||
|
// 250 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0x48, 0xac, 0xcc,
|
||||||
|
0xc9, 0x4f, 0x4c, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x49, 0x2f, 0x2a, 0x48,
|
||||||
|
0xd6, 0x2b, 0x49, 0x2d, 0x2e, 0xc9, 0xcc, 0x4b, 0x57, 0xf2, 0xe2, 0x12, 0x70, 0xaa, 0x2c, 0x49,
|
||||||
|
0x75, 0x2a, 0x4d, 0x4b, 0x4b, 0x2d, 0x0a, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0x16, 0x92, 0xe4, 0xe2,
|
||||||
|
0x28, 0x4a, 0x2d, 0x8c, 0x2f, 0xce, 0xac, 0x4a, 0x95, 0x60, 0x54, 0x60, 0xd4, 0x60, 0x0d, 0x62,
|
||||||
|
0x07, 0xf2, 0x83, 0x81, 0x5c, 0x21, 0x69, 0x2e, 0xce, 0xa2, 0xd4, 0xe2, 0x02, 0x88, 0x1c, 0x13,
|
||||||
|
0x58, 0x8e, 0x03, 0x24, 0x00, 0x92, 0x54, 0xf2, 0xe6, 0x12, 0x0c, 0xce, 0xcc, 0x2d, 0xc8, 0x49,
|
||||||
|
0x0d, 0x00, 0x59, 0x44, 0xa1, 0x61, 0x22, 0x5c, 0x42, 0xce, 0xf9, 0x20, 0xc3, 0x2a, 0x90, 0x4c,
|
||||||
|
0x53, 0xfa, 0xc6, 0xc8, 0xc5, 0x1b, 0x00, 0xf1, 0x8f, 0x73, 0x7e, 0x5e, 0x5a, 0x66, 0xba, 0x90,
|
||||||
|
0x3b, 0x17, 0x5f, 0x12, 0xd0, 0x03, 0x49, 0xa5, 0x69, 0xf1, 0x05, 0x60, 0x35, 0x60, 0x5b, 0xb8,
|
||||||
|
0x8d, 0xe4, 0xf4, 0x90, 0xfd, 0xa9, 0x87, 0xee, 0x49, 0x0f, 0x86, 0x20, 0x5e, 0xa8, 0x3e, 0xa8,
|
||||||
|
0x43, 0xdd, 0xb8, 0x78, 0x8b, 0xc1, 0xae, 0x87, 0x99, 0xc3, 0x04, 0x36, 0x47, 0x1e, 0xd5, 0x1c,
|
||||||
|
0x0c, 0x0f, 0x02, 0x0d, 0xe2, 0x81, 0xe8, 0x83, 0x9a, 0xe3, 0xc9, 0xc5, 0x97, 0x0c, 0x71, 0x38,
|
||||||
|
0xcc, 0x20, 0x66, 0xb0, 0x41, 0x0a, 0xa8, 0x06, 0x61, 0x7a, 0x0e, 0xe4, 0x24, 0xa8, 0x4e, 0x88,
|
||||||
|
0x80, 0x13, 0x27, 0x17, 0x3b, 0x34, 0xf2, 0x92, 0xd8, 0xc0, 0x91, 0x67, 0x0c, 0x08, 0x00, 0x00,
|
||||||
|
0xff, 0xff, 0xb0, 0x8c, 0x18, 0x4e, 0xce, 0x01, 0x00, 0x00,
|
||||||
|
}
|
55
vendor/google.golang.org/grpc/benchmark/grpc_testing/payloads.proto
generated
vendored
Normal file
55
vendor/google.golang.org/grpc/benchmark/grpc_testing/payloads.proto
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
// Copyright 2016, 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.testing;
|
||||||
|
|
||||||
|
message ByteBufferParams {
|
||||||
|
int32 req_size = 1;
|
||||||
|
int32 resp_size = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SimpleProtoParams {
|
||||||
|
int32 req_size = 1;
|
||||||
|
int32 resp_size = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ComplexProtoParams {
|
||||||
|
// TODO (vpai): Fill this in once the details of complex, representative
|
||||||
|
// protos are decided
|
||||||
|
}
|
||||||
|
|
||||||
|
message PayloadConfig {
|
||||||
|
oneof payload {
|
||||||
|
ByteBufferParams bytebuf_params = 1;
|
||||||
|
SimpleProtoParams simple_params = 2;
|
||||||
|
ComplexProtoParams complex_params = 3;
|
||||||
|
}
|
||||||
|
}
|
443
vendor/google.golang.org/grpc/benchmark/grpc_testing/services.pb.go
generated
vendored
Normal file
443
vendor/google.golang.org/grpc/benchmark/grpc_testing/services.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,443 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: services.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for BenchmarkService service
|
||||||
|
|
||||||
|
type BenchmarkServiceClient interface {
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error)
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
StreamingCall(ctx context.Context, opts ...grpc.CallOption) (BenchmarkService_StreamingCallClient, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type benchmarkServiceClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBenchmarkServiceClient(cc *grpc.ClientConn) BenchmarkServiceClient {
|
||||||
|
return &benchmarkServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *benchmarkServiceClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) {
|
||||||
|
out := new(SimpleResponse)
|
||||||
|
err := grpc.Invoke(ctx, "/grpc.testing.BenchmarkService/UnaryCall", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *benchmarkServiceClient) StreamingCall(ctx context.Context, opts ...grpc.CallOption) (BenchmarkService_StreamingCallClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_BenchmarkService_serviceDesc.Streams[0], c.cc, "/grpc.testing.BenchmarkService/StreamingCall", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &benchmarkServiceStreamingCallClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type BenchmarkService_StreamingCallClient interface {
|
||||||
|
Send(*SimpleRequest) error
|
||||||
|
Recv() (*SimpleResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type benchmarkServiceStreamingCallClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *benchmarkServiceStreamingCallClient) Send(m *SimpleRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *benchmarkServiceStreamingCallClient) Recv() (*SimpleResponse, error) {
|
||||||
|
m := new(SimpleResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for BenchmarkService service
|
||||||
|
|
||||||
|
type BenchmarkServiceServer interface {
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
UnaryCall(context.Context, *SimpleRequest) (*SimpleResponse, error)
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
StreamingCall(BenchmarkService_StreamingCallServer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterBenchmarkServiceServer(s *grpc.Server, srv BenchmarkServiceServer) {
|
||||||
|
s.RegisterService(&_BenchmarkService_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _BenchmarkService_UnaryCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SimpleRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(BenchmarkServiceServer).UnaryCall(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/grpc.testing.BenchmarkService/UnaryCall",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(BenchmarkServiceServer).UnaryCall(ctx, req.(*SimpleRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _BenchmarkService_StreamingCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(BenchmarkServiceServer).StreamingCall(&benchmarkServiceStreamingCallServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type BenchmarkService_StreamingCallServer interface {
|
||||||
|
Send(*SimpleResponse) error
|
||||||
|
Recv() (*SimpleRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type benchmarkServiceStreamingCallServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *benchmarkServiceStreamingCallServer) Send(m *SimpleResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *benchmarkServiceStreamingCallServer) Recv() (*SimpleRequest, error) {
|
||||||
|
m := new(SimpleRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _BenchmarkService_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "grpc.testing.BenchmarkService",
|
||||||
|
HandlerType: (*BenchmarkServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "UnaryCall",
|
||||||
|
Handler: _BenchmarkService_UnaryCall_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "StreamingCall",
|
||||||
|
Handler: _BenchmarkService_StreamingCall_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: fileDescriptor3,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client API for WorkerService service
|
||||||
|
|
||||||
|
type WorkerServiceClient interface {
|
||||||
|
// Start server with specified workload.
|
||||||
|
// First request sent specifies the ServerConfig followed by ServerStatus
|
||||||
|
// response. After that, a "Mark" can be sent anytime to request the latest
|
||||||
|
// stats. Closing the stream will initiate shutdown of the test server
|
||||||
|
// and once the shutdown has finished, the OK status is sent to terminate
|
||||||
|
// this RPC.
|
||||||
|
RunServer(ctx context.Context, opts ...grpc.CallOption) (WorkerService_RunServerClient, error)
|
||||||
|
// Start client with specified workload.
|
||||||
|
// First request sent specifies the ClientConfig followed by ClientStatus
|
||||||
|
// response. After that, a "Mark" can be sent anytime to request the latest
|
||||||
|
// stats. Closing the stream will initiate shutdown of the test client
|
||||||
|
// and once the shutdown has finished, the OK status is sent to terminate
|
||||||
|
// this RPC.
|
||||||
|
RunClient(ctx context.Context, opts ...grpc.CallOption) (WorkerService_RunClientClient, error)
|
||||||
|
// Just return the core count - unary call
|
||||||
|
CoreCount(ctx context.Context, in *CoreRequest, opts ...grpc.CallOption) (*CoreResponse, error)
|
||||||
|
// Quit this worker
|
||||||
|
QuitWorker(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Void, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerServiceClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWorkerServiceClient(cc *grpc.ClientConn) WorkerServiceClient {
|
||||||
|
return &workerServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *workerServiceClient) RunServer(ctx context.Context, opts ...grpc.CallOption) (WorkerService_RunServerClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_WorkerService_serviceDesc.Streams[0], c.cc, "/grpc.testing.WorkerService/RunServer", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &workerServiceRunServerClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkerService_RunServerClient interface {
|
||||||
|
Send(*ServerArgs) error
|
||||||
|
Recv() (*ServerStatus, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerServiceRunServerClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunServerClient) Send(m *ServerArgs) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunServerClient) Recv() (*ServerStatus, error) {
|
||||||
|
m := new(ServerStatus)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *workerServiceClient) RunClient(ctx context.Context, opts ...grpc.CallOption) (WorkerService_RunClientClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_WorkerService_serviceDesc.Streams[1], c.cc, "/grpc.testing.WorkerService/RunClient", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &workerServiceRunClientClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkerService_RunClientClient interface {
|
||||||
|
Send(*ClientArgs) error
|
||||||
|
Recv() (*ClientStatus, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerServiceRunClientClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunClientClient) Send(m *ClientArgs) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunClientClient) Recv() (*ClientStatus, error) {
|
||||||
|
m := new(ClientStatus)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *workerServiceClient) CoreCount(ctx context.Context, in *CoreRequest, opts ...grpc.CallOption) (*CoreResponse, error) {
|
||||||
|
out := new(CoreResponse)
|
||||||
|
err := grpc.Invoke(ctx, "/grpc.testing.WorkerService/CoreCount", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *workerServiceClient) QuitWorker(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Void, error) {
|
||||||
|
out := new(Void)
|
||||||
|
err := grpc.Invoke(ctx, "/grpc.testing.WorkerService/QuitWorker", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for WorkerService service
|
||||||
|
|
||||||
|
type WorkerServiceServer interface {
|
||||||
|
// Start server with specified workload.
|
||||||
|
// First request sent specifies the ServerConfig followed by ServerStatus
|
||||||
|
// response. After that, a "Mark" can be sent anytime to request the latest
|
||||||
|
// stats. Closing the stream will initiate shutdown of the test server
|
||||||
|
// and once the shutdown has finished, the OK status is sent to terminate
|
||||||
|
// this RPC.
|
||||||
|
RunServer(WorkerService_RunServerServer) error
|
||||||
|
// Start client with specified workload.
|
||||||
|
// First request sent specifies the ClientConfig followed by ClientStatus
|
||||||
|
// response. After that, a "Mark" can be sent anytime to request the latest
|
||||||
|
// stats. Closing the stream will initiate shutdown of the test client
|
||||||
|
// and once the shutdown has finished, the OK status is sent to terminate
|
||||||
|
// this RPC.
|
||||||
|
RunClient(WorkerService_RunClientServer) error
|
||||||
|
// Just return the core count - unary call
|
||||||
|
CoreCount(context.Context, *CoreRequest) (*CoreResponse, error)
|
||||||
|
// Quit this worker
|
||||||
|
QuitWorker(context.Context, *Void) (*Void, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterWorkerServiceServer(s *grpc.Server, srv WorkerServiceServer) {
|
||||||
|
s.RegisterService(&_WorkerService_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _WorkerService_RunServer_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(WorkerServiceServer).RunServer(&workerServiceRunServerServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkerService_RunServerServer interface {
|
||||||
|
Send(*ServerStatus) error
|
||||||
|
Recv() (*ServerArgs, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerServiceRunServerServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunServerServer) Send(m *ServerStatus) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunServerServer) Recv() (*ServerArgs, error) {
|
||||||
|
m := new(ServerArgs)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _WorkerService_RunClient_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(WorkerServiceServer).RunClient(&workerServiceRunClientServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkerService_RunClientServer interface {
|
||||||
|
Send(*ClientStatus) error
|
||||||
|
Recv() (*ClientArgs, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerServiceRunClientServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunClientServer) Send(m *ClientStatus) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *workerServiceRunClientServer) Recv() (*ClientArgs, error) {
|
||||||
|
m := new(ClientArgs)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _WorkerService_CoreCount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(CoreRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(WorkerServiceServer).CoreCount(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/grpc.testing.WorkerService/CoreCount",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(WorkerServiceServer).CoreCount(ctx, req.(*CoreRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _WorkerService_QuitWorker_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(Void)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(WorkerServiceServer).QuitWorker(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/grpc.testing.WorkerService/QuitWorker",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(WorkerServiceServer).QuitWorker(ctx, req.(*Void))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _WorkerService_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "grpc.testing.WorkerService",
|
||||||
|
HandlerType: (*WorkerServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "CoreCount",
|
||||||
|
Handler: _WorkerService_CoreCount_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "QuitWorker",
|
||||||
|
Handler: _WorkerService_QuitWorker_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "RunServer",
|
||||||
|
Handler: _WorkerService_RunServer_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
StreamName: "RunClient",
|
||||||
|
Handler: _WorkerService_RunClient_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: fileDescriptor3,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("services.proto", fileDescriptor3) }
|
||||||
|
|
||||||
|
var fileDescriptor3 = []byte{
|
||||||
|
// 254 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x91, 0xc1, 0x4a, 0xc4, 0x30,
|
||||||
|
0x10, 0x86, 0xa9, 0x07, 0xa1, 0xc1, 0x2e, 0x92, 0x93, 0x46, 0x1f, 0xc0, 0x53, 0x91, 0xd5, 0x17,
|
||||||
|
0x70, 0x8b, 0x1e, 0x05, 0xb7, 0xa8, 0xe7, 0x58, 0x87, 0x1a, 0x36, 0x4d, 0xea, 0xcc, 0x44, 0xf0,
|
||||||
|
0x49, 0x7c, 0x07, 0x9f, 0xd2, 0xee, 0x66, 0x0b, 0xb5, 0xe4, 0xb6, 0xc7, 0xf9, 0xbf, 0xe1, 0x23,
|
||||||
|
0x7f, 0x46, 0x2c, 0x08, 0xf0, 0xcb, 0x34, 0x40, 0x65, 0x8f, 0x9e, 0xbd, 0x3c, 0x69, 0xb1, 0x6f,
|
||||||
|
0x4a, 0x06, 0x62, 0xe3, 0x5a, 0xb5, 0xe8, 0x80, 0x48, 0xb7, 0x23, 0x55, 0x45, 0xe3, 0x1d, 0xa3,
|
||||||
|
0xb7, 0x71, 0x5c, 0xfe, 0x66, 0xe2, 0x74, 0x05, 0xae, 0xf9, 0xe8, 0x34, 0x6e, 0xea, 0x28, 0x92,
|
||||||
|
0x0f, 0x22, 0x7f, 0x76, 0x1a, 0xbf, 0x2b, 0x6d, 0xad, 0xbc, 0x28, 0xa7, 0xbe, 0xb2, 0x36, 0x5d,
|
||||||
|
0x6f, 0x61, 0x0d, 0x9f, 0x61, 0x08, 0xd4, 0x65, 0x1a, 0x52, 0xef, 0x1d, 0x81, 0x7c, 0x14, 0x45,
|
||||||
|
0xcd, 0x08, 0xba, 0x1b, 0xd8, 0x81, 0xae, 0xab, 0xec, 0x3a, 0x5b, 0xfe, 0x1c, 0x89, 0xe2, 0xd5,
|
||||||
|
0xe3, 0x06, 0x70, 0x7c, 0xe9, 0xbd, 0xc8, 0xd7, 0xc1, 0x6d, 0x27, 0x40, 0x79, 0x36, 0x13, 0xec,
|
||||||
|
0xd2, 0x3b, 0x6c, 0x49, 0xa9, 0x14, 0xa9, 0x59, 0x73, 0xa0, 0xad, 0x78, 0xaf, 0xa9, 0xac, 0x01,
|
||||||
|
0xc7, 0x73, 0x4d, 0x4c, 0x53, 0x9a, 0x48, 0x26, 0x9a, 0x95, 0xc8, 0x2b, 0x8f, 0x50, 0xf9, 0x30,
|
||||||
|
0x68, 0xce, 0x67, 0xcb, 0x03, 0x18, 0x9b, 0xaa, 0x14, 0xda, 0xff, 0xd9, 0xad, 0x10, 0x4f, 0xc1,
|
||||||
|
0x70, 0xac, 0x29, 0xe5, 0xff, 0xcd, 0x17, 0x6f, 0xde, 0x55, 0x22, 0x7b, 0x3b, 0xde, 0x5d, 0xf3,
|
||||||
|
0xe6, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x84, 0x02, 0xe3, 0x0c, 0x02, 0x00, 0x00,
|
||||||
|
}
|
71
vendor/google.golang.org/grpc/benchmark/grpc_testing/services.proto
generated
vendored
Normal file
71
vendor/google.golang.org/grpc/benchmark/grpc_testing/services.proto
generated
vendored
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
// Copyright 2016, 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.
|
||||||
|
|
||||||
|
// An integration test service that covers all the method signature permutations
|
||||||
|
// of unary/streaming requests/responses.
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
import "messages.proto";
|
||||||
|
import "control.proto";
|
||||||
|
|
||||||
|
package grpc.testing;
|
||||||
|
|
||||||
|
service BenchmarkService {
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
rpc UnaryCall(SimpleRequest) returns (SimpleResponse);
|
||||||
|
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
rpc StreamingCall(stream SimpleRequest) returns (stream SimpleResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
service WorkerService {
|
||||||
|
// Start server with specified workload.
|
||||||
|
// First request sent specifies the ServerConfig followed by ServerStatus
|
||||||
|
// response. After that, a "Mark" can be sent anytime to request the latest
|
||||||
|
// stats. Closing the stream will initiate shutdown of the test server
|
||||||
|
// and once the shutdown has finished, the OK status is sent to terminate
|
||||||
|
// this RPC.
|
||||||
|
rpc RunServer(stream ServerArgs) returns (stream ServerStatus);
|
||||||
|
|
||||||
|
// Start client with specified workload.
|
||||||
|
// First request sent specifies the ClientConfig followed by ClientStatus
|
||||||
|
// response. After that, a "Mark" can be sent anytime to request the latest
|
||||||
|
// stats. Closing the stream will initiate shutdown of the test client
|
||||||
|
// and once the shutdown has finished, the OK status is sent to terminate
|
||||||
|
// this RPC.
|
||||||
|
rpc RunClient(stream ClientArgs) returns (stream ClientStatus);
|
||||||
|
|
||||||
|
// Just return the core count - unary call
|
||||||
|
rpc CoreCount(CoreRequest) returns (CoreResponse);
|
||||||
|
|
||||||
|
// Quit this worker
|
||||||
|
rpc QuitWorker(Void) returns (Void);
|
||||||
|
}
|
111
vendor/google.golang.org/grpc/benchmark/grpc_testing/stats.pb.go
generated
vendored
Normal file
111
vendor/google.golang.org/grpc/benchmark/grpc_testing/stats.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: stats.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
type ServerStats struct {
|
||||||
|
// wall clock time change in seconds since last reset
|
||||||
|
TimeElapsed float64 `protobuf:"fixed64,1,opt,name=time_elapsed,json=timeElapsed" json:"time_elapsed,omitempty"`
|
||||||
|
// change in user time (in seconds) used by the server since last reset
|
||||||
|
TimeUser float64 `protobuf:"fixed64,2,opt,name=time_user,json=timeUser" json:"time_user,omitempty"`
|
||||||
|
// change in server time (in seconds) used by the server process and all
|
||||||
|
// threads since last reset
|
||||||
|
TimeSystem float64 `protobuf:"fixed64,3,opt,name=time_system,json=timeSystem" json:"time_system,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerStats) Reset() { *m = ServerStats{} }
|
||||||
|
func (m *ServerStats) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServerStats) ProtoMessage() {}
|
||||||
|
func (*ServerStats) Descriptor() ([]byte, []int) { return fileDescriptor4, []int{0} }
|
||||||
|
|
||||||
|
// Histogram params based on grpc/support/histogram.c
|
||||||
|
type HistogramParams struct {
|
||||||
|
Resolution float64 `protobuf:"fixed64,1,opt,name=resolution" json:"resolution,omitempty"`
|
||||||
|
MaxPossible float64 `protobuf:"fixed64,2,opt,name=max_possible,json=maxPossible" json:"max_possible,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *HistogramParams) Reset() { *m = HistogramParams{} }
|
||||||
|
func (m *HistogramParams) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*HistogramParams) ProtoMessage() {}
|
||||||
|
func (*HistogramParams) Descriptor() ([]byte, []int) { return fileDescriptor4, []int{1} }
|
||||||
|
|
||||||
|
// Histogram data based on grpc/support/histogram.c
|
||||||
|
type HistogramData struct {
|
||||||
|
Bucket []uint32 `protobuf:"varint,1,rep,name=bucket" json:"bucket,omitempty"`
|
||||||
|
MinSeen float64 `protobuf:"fixed64,2,opt,name=min_seen,json=minSeen" json:"min_seen,omitempty"`
|
||||||
|
MaxSeen float64 `protobuf:"fixed64,3,opt,name=max_seen,json=maxSeen" json:"max_seen,omitempty"`
|
||||||
|
Sum float64 `protobuf:"fixed64,4,opt,name=sum" json:"sum,omitempty"`
|
||||||
|
SumOfSquares float64 `protobuf:"fixed64,5,opt,name=sum_of_squares,json=sumOfSquares" json:"sum_of_squares,omitempty"`
|
||||||
|
Count float64 `protobuf:"fixed64,6,opt,name=count" json:"count,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *HistogramData) Reset() { *m = HistogramData{} }
|
||||||
|
func (m *HistogramData) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*HistogramData) ProtoMessage() {}
|
||||||
|
func (*HistogramData) Descriptor() ([]byte, []int) { return fileDescriptor4, []int{2} }
|
||||||
|
|
||||||
|
type ClientStats struct {
|
||||||
|
// Latency histogram. Data points are in nanoseconds.
|
||||||
|
Latencies *HistogramData `protobuf:"bytes,1,opt,name=latencies" json:"latencies,omitempty"`
|
||||||
|
// See ServerStats for details.
|
||||||
|
TimeElapsed float64 `protobuf:"fixed64,2,opt,name=time_elapsed,json=timeElapsed" json:"time_elapsed,omitempty"`
|
||||||
|
TimeUser float64 `protobuf:"fixed64,3,opt,name=time_user,json=timeUser" json:"time_user,omitempty"`
|
||||||
|
TimeSystem float64 `protobuf:"fixed64,4,opt,name=time_system,json=timeSystem" json:"time_system,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientStats) Reset() { *m = ClientStats{} }
|
||||||
|
func (m *ClientStats) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ClientStats) ProtoMessage() {}
|
||||||
|
func (*ClientStats) Descriptor() ([]byte, []int) { return fileDescriptor4, []int{3} }
|
||||||
|
|
||||||
|
func (m *ClientStats) GetLatencies() *HistogramData {
|
||||||
|
if m != nil {
|
||||||
|
return m.Latencies
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*ServerStats)(nil), "grpc.testing.ServerStats")
|
||||||
|
proto.RegisterType((*HistogramParams)(nil), "grpc.testing.HistogramParams")
|
||||||
|
proto.RegisterType((*HistogramData)(nil), "grpc.testing.HistogramData")
|
||||||
|
proto.RegisterType((*ClientStats)(nil), "grpc.testing.ClientStats")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("stats.proto", fileDescriptor4) }
|
||||||
|
|
||||||
|
var fileDescriptor4 = []byte{
|
||||||
|
// 342 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x92, 0x4f, 0x4f, 0xe3, 0x30,
|
||||||
|
0x10, 0xc5, 0x95, 0xa6, 0xed, 0xb6, 0x93, 0x76, 0x77, 0x65, 0xad, 0x56, 0x41, 0x95, 0xf8, 0x13,
|
||||||
|
0x71, 0xe8, 0x29, 0x07, 0x38, 0x71, 0x06, 0x24, 0x6e, 0x54, 0x0d, 0x9c, 0x23, 0x37, 0x4c, 0x2b,
|
||||||
|
0x8b, 0xc4, 0x0e, 0x99, 0x09, 0x2a, 0x1f, 0x09, 0xf1, 0x25, 0x71, 0x9c, 0x08, 0x0a, 0x48, 0x70,
|
||||||
|
0x49, 0xf2, 0x7e, 0x6f, 0x34, 0xe3, 0xc9, 0x33, 0x04, 0xc4, 0x92, 0x29, 0x2e, 0x2b, 0xc3, 0x46,
|
||||||
|
0x4c, 0x36, 0x55, 0x99, 0xc5, 0x8c, 0xc4, 0x4a, 0x6f, 0x22, 0x0d, 0x41, 0x82, 0xd5, 0x23, 0x56,
|
||||||
|
0x49, 0x53, 0x22, 0x8e, 0x60, 0xc2, 0xaa, 0xc0, 0x14, 0x73, 0x59, 0x12, 0xde, 0x85, 0xde, 0xa1,
|
||||||
|
0x37, 0xf7, 0x96, 0x41, 0xc3, 0x2e, 0x5b, 0x24, 0x66, 0x30, 0x76, 0x25, 0x35, 0x61, 0x15, 0xf6,
|
||||||
|
0x9c, 0x3f, 0x6a, 0xc0, 0xad, 0xd5, 0xe2, 0x00, 0x5c, 0x6d, 0x4a, 0x4f, 0xc4, 0x58, 0x84, 0xbe,
|
||||||
|
0xb3, 0xa1, 0x41, 0x89, 0x23, 0xd1, 0x0d, 0xfc, 0xb9, 0x52, 0xc4, 0x66, 0x53, 0xc9, 0x62, 0x21,
|
||||||
|
0xed, 0x83, 0xc4, 0x3e, 0x40, 0x85, 0x64, 0xf2, 0x9a, 0x95, 0xd1, 0xdd, 0xc4, 0x1d, 0xd2, 0x9c,
|
||||||
|
0xa9, 0x90, 0xdb, 0xb4, 0x34, 0x44, 0x6a, 0x95, 0x63, 0x37, 0x33, 0xb0, 0x6c, 0xd1, 0xa1, 0xe8,
|
||||||
|
0xc5, 0x83, 0xe9, 0x5b, 0xdb, 0x0b, 0xc9, 0x52, 0xfc, 0x87, 0xe1, 0xaa, 0xce, 0xee, 0x91, 0x6d,
|
||||||
|
0x43, 0x7f, 0x3e, 0x5d, 0x76, 0x4a, 0xec, 0xc1, 0xa8, 0x50, 0x3a, 0x25, 0x44, 0xdd, 0x35, 0xfa,
|
||||||
|
0x65, 0x75, 0x62, 0xa5, 0xb3, 0xec, 0x1c, 0x67, 0xf9, 0x9d, 0x25, 0xb7, 0xce, 0xfa, 0x0b, 0x3e,
|
||||||
|
0xd5, 0x45, 0xd8, 0x77, 0xb4, 0xf9, 0x14, 0xc7, 0xf0, 0xdb, 0xbe, 0x52, 0xb3, 0x4e, 0xe9, 0xa1,
|
||||||
|
0x96, 0xf6, 0xb4, 0xe1, 0xc0, 0x99, 0x13, 0x4b, 0xaf, 0xd7, 0x49, 0xcb, 0xc4, 0x3f, 0x18, 0x64,
|
||||||
|
0xa6, 0xd6, 0x1c, 0x0e, 0x9d, 0xd9, 0x8a, 0xe8, 0xd9, 0x83, 0xe0, 0x3c, 0x57, 0xa8, 0xb9, 0xfd,
|
||||||
|
0xe9, 0x67, 0x30, 0xce, 0x25, 0xa3, 0xce, 0x94, 0x6d, 0xd3, 0xec, 0x1f, 0x9c, 0xcc, 0xe2, 0xdd,
|
||||||
|
0x94, 0xe2, 0x0f, 0xbb, 0x2d, 0xdf, 0xab, 0xbf, 0xe4, 0xd5, 0xfb, 0x21, 0x2f, 0xff, 0xfb, 0xbc,
|
||||||
|
0xfa, 0x9f, 0xf3, 0x5a, 0x0d, 0xdd, 0xa5, 0x39, 0x7d, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xea, 0x75,
|
||||||
|
0x34, 0x90, 0x43, 0x02, 0x00, 0x00,
|
||||||
|
}
|
70
vendor/google.golang.org/grpc/benchmark/grpc_testing/stats.proto
generated
vendored
Normal file
70
vendor/google.golang.org/grpc/benchmark/grpc_testing/stats.proto
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
// Copyright 2016, 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.testing;
|
||||||
|
|
||||||
|
message ServerStats {
|
||||||
|
// wall clock time change in seconds since last reset
|
||||||
|
double time_elapsed = 1;
|
||||||
|
|
||||||
|
// change in user time (in seconds) used by the server since last reset
|
||||||
|
double time_user = 2;
|
||||||
|
|
||||||
|
// change in server time (in seconds) used by the server process and all
|
||||||
|
// threads since last reset
|
||||||
|
double time_system = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Histogram params based on grpc/support/histogram.c
|
||||||
|
message HistogramParams {
|
||||||
|
double resolution = 1; // first bucket is [0, 1 + resolution)
|
||||||
|
double max_possible = 2; // use enough buckets to allow this value
|
||||||
|
}
|
||||||
|
|
||||||
|
// Histogram data based on grpc/support/histogram.c
|
||||||
|
message HistogramData {
|
||||||
|
repeated uint32 bucket = 1;
|
||||||
|
double min_seen = 2;
|
||||||
|
double max_seen = 3;
|
||||||
|
double sum = 4;
|
||||||
|
double sum_of_squares = 5;
|
||||||
|
double count = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ClientStats {
|
||||||
|
// Latency histogram. Data points are in nanoseconds.
|
||||||
|
HistogramData latencies = 1;
|
||||||
|
|
||||||
|
// See ServerStats for details.
|
||||||
|
double time_elapsed = 2;
|
||||||
|
double time_user = 3;
|
||||||
|
double time_system = 4;
|
||||||
|
}
|
35
vendor/google.golang.org/grpc/benchmark/server/main.go
generated
vendored
Normal file
35
vendor/google.golang.org/grpc/benchmark/server/main.go
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"math"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/benchmark"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
duration = flag.Int("duration", math.MaxInt32, "The duration in seconds to run the benchmark server")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
go func() {
|
||||||
|
lis, err := net.Listen("tcp", ":0")
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
grpclog.Println("Server profiling address: ", lis.Addr().String())
|
||||||
|
if err := http.Serve(lis, nil); err != nil {
|
||||||
|
grpclog.Fatalf("Failed to serve: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
addr, stopper := benchmark.StartServer(benchmark.ServerInfo{Addr: ":0", Type: "protobuf"}) // listen on all interfaces
|
||||||
|
grpclog.Println("Server Address: ", addr)
|
||||||
|
<-time.After(time.Duration(*duration) * time.Second)
|
||||||
|
stopper()
|
||||||
|
}
|
15
vendor/google.golang.org/grpc/benchmark/server/testdata/ca.pem
generated
vendored
Normal file
15
vendor/google.golang.org/grpc/benchmark/server/testdata/ca.pem
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICSjCCAbOgAwIBAgIJAJHGGR4dGioHMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV
|
||||||
|
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||||
|
aWRnaXRzIFB0eSBMdGQxDzANBgNVBAMTBnRlc3RjYTAeFw0xNDExMTEyMjMxMjla
|
||||||
|
Fw0yNDExMDgyMjMxMjlaMFYxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0
|
||||||
|
YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxDzANBgNVBAMT
|
||||||
|
BnRlc3RjYTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwEDfBV5MYdlHVHJ7
|
||||||
|
+L4nxrZy7mBfAVXpOc5vMYztssUI7mL2/iYujiIXM+weZYNTEpLdjyJdu7R5gGUu
|
||||||
|
g1jSVK/EPHfc74O7AyZU34PNIP4Sh33N+/A5YexrNgJlPY+E3GdVYi4ldWJjgkAd
|
||||||
|
Qah2PH5ACLrIIC6tRka9hcaBlIECAwEAAaMgMB4wDAYDVR0TBAUwAwEB/zAOBgNV
|
||||||
|
HQ8BAf8EBAMCAgQwDQYJKoZIhvcNAQELBQADgYEAHzC7jdYlzAVmddi/gdAeKPau
|
||||||
|
sPBG/C2HCWqHzpCUHcKuvMzDVkY/MP2o6JIW2DBbY64bO/FceExhjcykgaYtCH/m
|
||||||
|
oIU63+CFOTtR7otyQAWHqXa7q4SbCDlG7DyRFxqG0txPtGvy12lgldA2+RgcigQG
|
||||||
|
Dfcog5wrJytaQ6UA0wE=
|
||||||
|
-----END CERTIFICATE-----
|
16
vendor/google.golang.org/grpc/benchmark/server/testdata/server1.key
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/benchmark/server/testdata/server1.key
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAOHDFScoLCVJpYDD
|
||||||
|
M4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1BgzkWF+slf
|
||||||
|
3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd9N8YwbBY
|
||||||
|
AckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAECgYAn7qGnM2vbjJNBm0VZCkOkTIWm
|
||||||
|
V10okw7EPJrdL2mkre9NasghNXbE1y5zDshx5Nt3KsazKOxTT8d0Jwh/3KbaN+YY
|
||||||
|
tTCbKGW0pXDRBhwUHRcuRzScjli8Rih5UOCiZkhefUTcRb6xIhZJuQy71tjaSy0p
|
||||||
|
dHZRmYyBYO2YEQ8xoQJBAPrJPhMBkzmEYFtyIEqAxQ/o/A6E+E4w8i+KM7nQCK7q
|
||||||
|
K4JXzyXVAjLfyBZWHGM2uro/fjqPggGD6QH1qXCkI4MCQQDmdKeb2TrKRh5BY1LR
|
||||||
|
81aJGKcJ2XbcDu6wMZK4oqWbTX2KiYn9GB0woM6nSr/Y6iy1u145YzYxEV/iMwff
|
||||||
|
DJULAkB8B2MnyzOg0pNFJqBJuH29bKCcHa8gHJzqXhNO5lAlEbMK95p/P2Wi+4Hd
|
||||||
|
aiEIAF1BF326QJcvYKmwSmrORp85AkAlSNxRJ50OWrfMZnBgzVjDx3xG6KsFQVk2
|
||||||
|
ol6VhqL6dFgKUORFUWBvnKSyhjJxurlPEahV6oo6+A+mPhFY8eUvAkAZQyTdupP3
|
||||||
|
XEFQKctGz+9+gKkemDp7LBBMEMBXrGTLPhpEfcjv/7KPdnFHYmhYeBTBnuVmTVWe
|
||||||
|
F98XJ7tIFfJq
|
||||||
|
-----END PRIVATE KEY-----
|
16
vendor/google.golang.org/grpc/benchmark/server/testdata/server1.pem
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/benchmark/server/testdata/server1.pem
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICnDCCAgWgAwIBAgIBBzANBgkqhkiG9w0BAQsFADBWMQswCQYDVQQGEwJBVTET
|
||||||
|
MBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQ
|
||||||
|
dHkgTHRkMQ8wDQYDVQQDEwZ0ZXN0Y2EwHhcNMTUxMTA0MDIyMDI0WhcNMjUxMTAx
|
||||||
|
MDIyMDI0WjBlMQswCQYDVQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNV
|
||||||
|
BAcTB0NoaWNhZ28xFTATBgNVBAoTDEV4YW1wbGUsIENvLjEaMBgGA1UEAxQRKi50
|
||||||
|
ZXN0Lmdvb2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOHDFSco
|
||||||
|
LCVJpYDDM4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1Bg
|
||||||
|
zkWF+slf3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd
|
||||||
|
9N8YwbBYAckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAGjazBpMAkGA1UdEwQCMAAw
|
||||||
|
CwYDVR0PBAQDAgXgME8GA1UdEQRIMEaCECoudGVzdC5nb29nbGUuZnKCGHdhdGVy
|
||||||
|
em9vaS50ZXN0Lmdvb2dsZS5iZYISKi50ZXN0LnlvdXR1YmUuY29thwTAqAEDMA0G
|
||||||
|
CSqGSIb3DQEBCwUAA4GBAJFXVifQNub1LUP4JlnX5lXNlo8FxZ2a12AFQs+bzoJ6
|
||||||
|
hM044EDjqyxUqSbVePK0ni3w1fHQB5rY9yYC5f8G7aqqTY1QOhoUk8ZTSTRpnkTh
|
||||||
|
y4jjdvTZeLDVBlueZUTDRmy2feY5aZIU18vFDK08dTG0A87pppuv1LNIR3loveU8
|
||||||
|
-----END CERTIFICATE-----
|
198
vendor/google.golang.org/grpc/benchmark/stats/histogram.go
generated
vendored
Normal file
198
vendor/google.golang.org/grpc/benchmark/stats/histogram.go
generated
vendored
Normal file
|
@ -0,0 +1,198 @@
|
||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Histogram accumulates values in the form of a histogram with
|
||||||
|
// exponentially increased bucket sizes.
|
||||||
|
type Histogram struct {
|
||||||
|
// Count is the total number of values added to the histogram.
|
||||||
|
Count int64
|
||||||
|
// Sum is the sum of all the values added to the histogram.
|
||||||
|
Sum int64
|
||||||
|
// SumOfSquares is the sum of squares of all values.
|
||||||
|
SumOfSquares int64
|
||||||
|
// Min is the minimum of all the values added to the histogram.
|
||||||
|
Min int64
|
||||||
|
// Max is the maximum of all the values added to the histogram.
|
||||||
|
Max int64
|
||||||
|
// Buckets contains all the buckets of the histogram.
|
||||||
|
Buckets []HistogramBucket
|
||||||
|
|
||||||
|
opts HistogramOptions
|
||||||
|
logBaseBucketSize float64
|
||||||
|
oneOverLogOnePlusGrowthFactor float64
|
||||||
|
}
|
||||||
|
|
||||||
|
// HistogramOptions contains the parameters that define the histogram's buckets.
|
||||||
|
// The first bucket of the created histogram (with index 0) contains [min, min+n)
|
||||||
|
// where n = BaseBucketSize, min = MinValue.
|
||||||
|
// Bucket i (i>=1) contains [min + n * m^(i-1), min + n * m^i), where m = 1+GrowthFactor.
|
||||||
|
// The type of the values is int64.
|
||||||
|
type HistogramOptions struct {
|
||||||
|
// NumBuckets is the number of buckets.
|
||||||
|
NumBuckets int
|
||||||
|
// GrowthFactor is the growth factor of the buckets. A value of 0.1
|
||||||
|
// indicates that bucket N+1 will be 10% larger than bucket N.
|
||||||
|
GrowthFactor float64
|
||||||
|
// BaseBucketSize is the size of the first bucket.
|
||||||
|
BaseBucketSize float64
|
||||||
|
// MinValue is the lower bound of the first bucket.
|
||||||
|
MinValue int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// HistogramBucket represents one histogram bucket.
|
||||||
|
type HistogramBucket struct {
|
||||||
|
// LowBound is the lower bound of the bucket.
|
||||||
|
LowBound float64
|
||||||
|
// Count is the number of values in the bucket.
|
||||||
|
Count int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHistogram returns a pointer to a new Histogram object that was created
|
||||||
|
// with the provided options.
|
||||||
|
func NewHistogram(opts HistogramOptions) *Histogram {
|
||||||
|
if opts.NumBuckets == 0 {
|
||||||
|
opts.NumBuckets = 32
|
||||||
|
}
|
||||||
|
if opts.BaseBucketSize == 0.0 {
|
||||||
|
opts.BaseBucketSize = 1.0
|
||||||
|
}
|
||||||
|
h := Histogram{
|
||||||
|
Buckets: make([]HistogramBucket, opts.NumBuckets),
|
||||||
|
Min: math.MaxInt64,
|
||||||
|
Max: math.MinInt64,
|
||||||
|
|
||||||
|
opts: opts,
|
||||||
|
logBaseBucketSize: math.Log(opts.BaseBucketSize),
|
||||||
|
oneOverLogOnePlusGrowthFactor: 1 / math.Log(1+opts.GrowthFactor),
|
||||||
|
}
|
||||||
|
m := 1.0 + opts.GrowthFactor
|
||||||
|
delta := opts.BaseBucketSize
|
||||||
|
h.Buckets[0].LowBound = float64(opts.MinValue)
|
||||||
|
for i := 1; i < opts.NumBuckets; i++ {
|
||||||
|
h.Buckets[i].LowBound = float64(opts.MinValue) + delta
|
||||||
|
delta = delta * m
|
||||||
|
}
|
||||||
|
return &h
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print writes textual output of the histogram values.
|
||||||
|
func (h *Histogram) Print(w io.Writer) {
|
||||||
|
avg := float64(h.Sum) / float64(h.Count)
|
||||||
|
fmt.Fprintf(w, "Count: %d Min: %d Max: %d Avg: %.2f\n", h.Count, h.Min, h.Max, avg)
|
||||||
|
fmt.Fprintf(w, "%s\n", strings.Repeat("-", 60))
|
||||||
|
if h.Count <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
maxBucketDigitLen := len(strconv.FormatFloat(h.Buckets[len(h.Buckets)-1].LowBound, 'f', 6, 64))
|
||||||
|
if maxBucketDigitLen < 3 {
|
||||||
|
// For "inf".
|
||||||
|
maxBucketDigitLen = 3
|
||||||
|
}
|
||||||
|
maxCountDigitLen := len(strconv.FormatInt(h.Count, 10))
|
||||||
|
percentMulti := 100 / float64(h.Count)
|
||||||
|
|
||||||
|
accCount := int64(0)
|
||||||
|
for i, b := range h.Buckets {
|
||||||
|
fmt.Fprintf(w, "[%*f, ", maxBucketDigitLen, b.LowBound)
|
||||||
|
if i+1 < len(h.Buckets) {
|
||||||
|
fmt.Fprintf(w, "%*f)", maxBucketDigitLen, h.Buckets[i+1].LowBound)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "%*s)", maxBucketDigitLen, "inf")
|
||||||
|
}
|
||||||
|
|
||||||
|
accCount += b.Count
|
||||||
|
fmt.Fprintf(w, " %*d %5.1f%% %5.1f%%", maxCountDigitLen, b.Count, float64(b.Count)*percentMulti, float64(accCount)*percentMulti)
|
||||||
|
|
||||||
|
const barScale = 0.1
|
||||||
|
barLength := int(float64(b.Count)*percentMulti*barScale + 0.5)
|
||||||
|
fmt.Fprintf(w, " %s\n", strings.Repeat("#", barLength))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the textual output of the histogram values as string.
|
||||||
|
func (h *Histogram) String() string {
|
||||||
|
var b bytes.Buffer
|
||||||
|
h.Print(&b)
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear resets all the content of histogram.
|
||||||
|
func (h *Histogram) Clear() {
|
||||||
|
h.Count = 0
|
||||||
|
h.Sum = 0
|
||||||
|
h.SumOfSquares = 0
|
||||||
|
h.Min = math.MaxInt64
|
||||||
|
h.Max = math.MinInt64
|
||||||
|
for i := range h.Buckets {
|
||||||
|
h.Buckets[i].Count = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Opts returns a copy of the options used to create the Histogram.
|
||||||
|
func (h *Histogram) Opts() HistogramOptions {
|
||||||
|
return h.opts
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add adds a value to the histogram.
|
||||||
|
func (h *Histogram) Add(value int64) error {
|
||||||
|
bucket, err := h.findBucket(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h.Buckets[bucket].Count++
|
||||||
|
h.Count++
|
||||||
|
h.Sum += value
|
||||||
|
h.SumOfSquares += value * value
|
||||||
|
if value < h.Min {
|
||||||
|
h.Min = value
|
||||||
|
}
|
||||||
|
if value > h.Max {
|
||||||
|
h.Max = value
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Histogram) findBucket(value int64) (int, error) {
|
||||||
|
delta := float64(value - h.opts.MinValue)
|
||||||
|
var b int
|
||||||
|
if delta >= h.opts.BaseBucketSize {
|
||||||
|
// b = log_{1+growthFactor} (delta / baseBucketSize) + 1
|
||||||
|
// = log(delta / baseBucketSize) / log(1+growthFactor) + 1
|
||||||
|
// = (log(delta) - log(baseBucketSize)) * (1 / log(1+growthFactor)) + 1
|
||||||
|
b = int((math.Log(delta)-h.logBaseBucketSize)*h.oneOverLogOnePlusGrowthFactor + 1)
|
||||||
|
}
|
||||||
|
if b >= len(h.Buckets) {
|
||||||
|
return 0, fmt.Errorf("no bucket for value: %d", value)
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge takes another histogram h2, and merges its content into h.
|
||||||
|
// The two histograms must be created by equivalent HistogramOptions.
|
||||||
|
func (h *Histogram) Merge(h2 *Histogram) {
|
||||||
|
if h.opts != h2.opts {
|
||||||
|
log.Fatalf("failed to merge histograms, created by inequivalent options")
|
||||||
|
}
|
||||||
|
h.Count += h2.Count
|
||||||
|
h.Sum += h2.Sum
|
||||||
|
h.SumOfSquares += h2.SumOfSquares
|
||||||
|
if h2.Min < h.Min {
|
||||||
|
h.Min = h2.Min
|
||||||
|
}
|
||||||
|
if h2.Max > h.Max {
|
||||||
|
h.Max = h2.Max
|
||||||
|
}
|
||||||
|
for i, b := range h2.Buckets {
|
||||||
|
h.Buckets[i].Count += b.Count
|
||||||
|
}
|
||||||
|
}
|
116
vendor/google.golang.org/grpc/benchmark/stats/stats.go
generated
vendored
Normal file
116
vendor/google.golang.org/grpc/benchmark/stats/stats.go
generated
vendored
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Stats is a simple helper for gathering additional statistics like histogram
|
||||||
|
// during benchmarks. This is not thread safe.
|
||||||
|
type Stats struct {
|
||||||
|
numBuckets int
|
||||||
|
unit time.Duration
|
||||||
|
min, max int64
|
||||||
|
histogram *Histogram
|
||||||
|
|
||||||
|
durations durationSlice
|
||||||
|
dirty bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type durationSlice []time.Duration
|
||||||
|
|
||||||
|
// NewStats creates a new Stats instance. If numBuckets is not positive,
|
||||||
|
// the default value (16) will be used.
|
||||||
|
func NewStats(numBuckets int) *Stats {
|
||||||
|
if numBuckets <= 0 {
|
||||||
|
numBuckets = 16
|
||||||
|
}
|
||||||
|
return &Stats{
|
||||||
|
// Use one more bucket for the last unbounded bucket.
|
||||||
|
numBuckets: numBuckets + 1,
|
||||||
|
durations: make(durationSlice, 0, 100000),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add adds an elapsed time per operation to the stats.
|
||||||
|
func (stats *Stats) Add(d time.Duration) {
|
||||||
|
stats.durations = append(stats.durations, d)
|
||||||
|
stats.dirty = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear resets the stats, removing all values.
|
||||||
|
func (stats *Stats) Clear() {
|
||||||
|
stats.durations = stats.durations[:0]
|
||||||
|
stats.histogram = nil
|
||||||
|
stats.dirty = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// maybeUpdate updates internal stat data if there was any newly added
|
||||||
|
// stats since this was updated.
|
||||||
|
func (stats *Stats) maybeUpdate() {
|
||||||
|
if !stats.dirty {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.min = math.MaxInt64
|
||||||
|
stats.max = 0
|
||||||
|
for _, d := range stats.durations {
|
||||||
|
if stats.min > int64(d) {
|
||||||
|
stats.min = int64(d)
|
||||||
|
}
|
||||||
|
if stats.max < int64(d) {
|
||||||
|
stats.max = int64(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the largest unit that can represent the minimum time duration.
|
||||||
|
stats.unit = time.Nanosecond
|
||||||
|
for _, u := range []time.Duration{time.Microsecond, time.Millisecond, time.Second} {
|
||||||
|
if stats.min <= int64(u) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
stats.unit = u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust the min/max according to the new unit.
|
||||||
|
stats.min /= int64(stats.unit)
|
||||||
|
stats.max /= int64(stats.unit)
|
||||||
|
numBuckets := stats.numBuckets
|
||||||
|
if n := int(stats.max - stats.min + 1); n < numBuckets {
|
||||||
|
numBuckets = n
|
||||||
|
}
|
||||||
|
stats.histogram = NewHistogram(HistogramOptions{
|
||||||
|
NumBuckets: numBuckets,
|
||||||
|
// max-min(lower bound of last bucket) = (1 + growthFactor)^(numBuckets-2) * baseBucketSize.
|
||||||
|
GrowthFactor: math.Pow(float64(stats.max-stats.min), 1/float64(numBuckets-2)) - 1,
|
||||||
|
BaseBucketSize: 1.0,
|
||||||
|
MinValue: stats.min})
|
||||||
|
|
||||||
|
for _, d := range stats.durations {
|
||||||
|
stats.histogram.Add(int64(d / stats.unit))
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.dirty = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print writes textual output of the Stats.
|
||||||
|
func (stats *Stats) Print(w io.Writer) {
|
||||||
|
stats.maybeUpdate()
|
||||||
|
|
||||||
|
if stats.histogram == nil {
|
||||||
|
fmt.Fprint(w, "Histogram (empty)\n")
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "Histogram (unit: %s)\n", fmt.Sprintf("%v", stats.unit)[1:])
|
||||||
|
stats.histogram.Print(w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the textual output of the Stats as string.
|
||||||
|
func (stats *Stats) String() string {
|
||||||
|
var b bytes.Buffer
|
||||||
|
stats.Print(&b)
|
||||||
|
return b.String()
|
||||||
|
}
|
191
vendor/google.golang.org/grpc/benchmark/stats/util.go
generated
vendored
Normal file
191
vendor/google.golang.org/grpc/benchmark/stats/util.go
generated
vendored
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
curB *testing.B
|
||||||
|
curBenchName string
|
||||||
|
curStats map[string]*Stats
|
||||||
|
|
||||||
|
orgStdout *os.File
|
||||||
|
nextOutPos int
|
||||||
|
|
||||||
|
injectCond *sync.Cond
|
||||||
|
injectDone chan struct{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddStats adds a new unnamed Stats instance to the current benchmark. You need
|
||||||
|
// to run benchmarks by calling RunTestMain() to inject the stats to the
|
||||||
|
// benchmark results. If numBuckets is not positive, the default value (16) will
|
||||||
|
// be used. Please note that this calls b.ResetTimer() since it may be blocked
|
||||||
|
// until the previous benchmark stats is printed out. So AddStats() should
|
||||||
|
// typically be called at the very beginning of each benchmark function.
|
||||||
|
func AddStats(b *testing.B, numBuckets int) *Stats {
|
||||||
|
return AddStatsWithName(b, "", numBuckets)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddStatsWithName adds a new named Stats instance to the current benchmark.
|
||||||
|
// With this, you can add multiple stats in a single benchmark. You need
|
||||||
|
// to run benchmarks by calling RunTestMain() to inject the stats to the
|
||||||
|
// benchmark results. If numBuckets is not positive, the default value (16) will
|
||||||
|
// be used. Please note that this calls b.ResetTimer() since it may be blocked
|
||||||
|
// until the previous benchmark stats is printed out. So AddStatsWithName()
|
||||||
|
// should typically be called at the very beginning of each benchmark function.
|
||||||
|
func AddStatsWithName(b *testing.B, name string, numBuckets int) *Stats {
|
||||||
|
var benchName string
|
||||||
|
for i := 1; ; i++ {
|
||||||
|
pc, _, _, ok := runtime.Caller(i)
|
||||||
|
if !ok {
|
||||||
|
panic("benchmark function not found")
|
||||||
|
}
|
||||||
|
p := strings.Split(runtime.FuncForPC(pc).Name(), ".")
|
||||||
|
benchName = p[len(p)-1]
|
||||||
|
if strings.HasPrefix(benchName, "Benchmark") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
procs := runtime.GOMAXPROCS(-1)
|
||||||
|
if procs != 1 {
|
||||||
|
benchName = fmt.Sprintf("%s-%d", benchName, procs)
|
||||||
|
}
|
||||||
|
|
||||||
|
stats := NewStats(numBuckets)
|
||||||
|
|
||||||
|
if injectCond != nil {
|
||||||
|
// We need to wait until the previous benchmark stats is printed out.
|
||||||
|
injectCond.L.Lock()
|
||||||
|
for curB != nil && curBenchName != benchName {
|
||||||
|
injectCond.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
curB = b
|
||||||
|
curBenchName = benchName
|
||||||
|
curStats[name] = stats
|
||||||
|
|
||||||
|
injectCond.L.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
return stats
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunTestMain runs the tests with enabling injection of benchmark stats. It
|
||||||
|
// returns an exit code to pass to os.Exit.
|
||||||
|
func RunTestMain(m *testing.M) int {
|
||||||
|
startStatsInjector()
|
||||||
|
defer stopStatsInjector()
|
||||||
|
return m.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
// startStatsInjector starts stats injection to benchmark results.
|
||||||
|
func startStatsInjector() {
|
||||||
|
orgStdout = os.Stdout
|
||||||
|
r, w, _ := os.Pipe()
|
||||||
|
os.Stdout = w
|
||||||
|
nextOutPos = 0
|
||||||
|
|
||||||
|
resetCurBenchStats()
|
||||||
|
|
||||||
|
injectCond = sync.NewCond(&sync.Mutex{})
|
||||||
|
injectDone = make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(injectDone)
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(r)
|
||||||
|
scanner.Split(splitLines)
|
||||||
|
for scanner.Scan() {
|
||||||
|
injectStatsIfFinished(scanner.Text())
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// stopStatsInjector stops stats injection and restores os.Stdout.
|
||||||
|
func stopStatsInjector() {
|
||||||
|
os.Stdout.Close()
|
||||||
|
<-injectDone
|
||||||
|
injectCond = nil
|
||||||
|
os.Stdout = orgStdout
|
||||||
|
}
|
||||||
|
|
||||||
|
// splitLines is a split function for a bufio.Scanner that returns each line
|
||||||
|
// of text, teeing texts to the original stdout even before each line ends.
|
||||||
|
func splitLines(data []byte, eof bool) (advance int, token []byte, err error) {
|
||||||
|
if eof && len(data) == 0 {
|
||||||
|
return 0, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
||||||
|
orgStdout.Write(data[nextOutPos : i+1])
|
||||||
|
nextOutPos = 0
|
||||||
|
return i + 1, data[0:i], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
orgStdout.Write(data[nextOutPos:])
|
||||||
|
nextOutPos = len(data)
|
||||||
|
|
||||||
|
if eof {
|
||||||
|
// This is a final, non-terminated line. Return it.
|
||||||
|
return len(data), data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// injectStatsIfFinished prints out the stats if the current benchmark finishes.
|
||||||
|
func injectStatsIfFinished(line string) {
|
||||||
|
injectCond.L.Lock()
|
||||||
|
defer injectCond.L.Unlock()
|
||||||
|
|
||||||
|
// We assume that the benchmark results start with the benchmark name.
|
||||||
|
if curB == nil || !strings.HasPrefix(line, curBenchName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !curB.Failed() {
|
||||||
|
// Output all stats in alphabetical order.
|
||||||
|
names := make([]string, 0, len(curStats))
|
||||||
|
for name := range curStats {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
sort.Strings(names)
|
||||||
|
for _, name := range names {
|
||||||
|
stats := curStats[name]
|
||||||
|
// The output of stats starts with a header like "Histogram (unit: ms)"
|
||||||
|
// followed by statistical properties and the buckets. Add the stats name
|
||||||
|
// if it is a named stats and indent them as Go testing outputs.
|
||||||
|
lines := strings.Split(stats.String(), "\n")
|
||||||
|
if n := len(lines); n > 0 {
|
||||||
|
if name != "" {
|
||||||
|
name = ": " + name
|
||||||
|
}
|
||||||
|
fmt.Fprintf(orgStdout, "--- %s%s\n", lines[0], name)
|
||||||
|
for _, line := range lines[1 : n-1] {
|
||||||
|
fmt.Fprintf(orgStdout, "\t%s\n", line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resetCurBenchStats()
|
||||||
|
injectCond.Signal()
|
||||||
|
}
|
||||||
|
|
||||||
|
// resetCurBenchStats resets the current benchmark stats.
|
||||||
|
func resetCurBenchStats() {
|
||||||
|
curB = nil
|
||||||
|
curBenchName = ""
|
||||||
|
curStats = make(map[string]*Stats)
|
||||||
|
}
|
399
vendor/google.golang.org/grpc/benchmark/worker/benchmark_client.go
generated
vendored
Normal file
399
vendor/google.golang.org/grpc/benchmark/worker/benchmark_client.go
generated
vendored
Normal file
|
@ -0,0 +1,399 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/benchmark"
|
||||||
|
testpb "google.golang.org/grpc/benchmark/grpc_testing"
|
||||||
|
"google.golang.org/grpc/benchmark/stats"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
caFile = "benchmark/server/testdata/ca.pem"
|
||||||
|
)
|
||||||
|
|
||||||
|
type lockingHistogram struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
histogram *stats.Histogram
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *lockingHistogram) add(value int64) {
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
h.histogram.Add(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// swap sets h.histogram to new, and returns its old value.
|
||||||
|
func (h *lockingHistogram) swap(new *stats.Histogram) *stats.Histogram {
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
old := h.histogram
|
||||||
|
h.histogram = new
|
||||||
|
return old
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *lockingHistogram) mergeInto(merged *stats.Histogram) {
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
merged.Merge(h.histogram)
|
||||||
|
}
|
||||||
|
|
||||||
|
type benchmarkClient struct {
|
||||||
|
closeConns func()
|
||||||
|
stop chan bool
|
||||||
|
lastResetTime time.Time
|
||||||
|
histogramOptions stats.HistogramOptions
|
||||||
|
lockingHistograms []lockingHistogram
|
||||||
|
}
|
||||||
|
|
||||||
|
func printClientConfig(config *testpb.ClientConfig) {
|
||||||
|
// Some config options are ignored:
|
||||||
|
// - client type:
|
||||||
|
// will always create sync client
|
||||||
|
// - async client threads.
|
||||||
|
// - core list
|
||||||
|
grpclog.Printf(" * client type: %v (ignored, always creates sync client)", config.ClientType)
|
||||||
|
grpclog.Printf(" * async client threads: %v (ignored)", config.AsyncClientThreads)
|
||||||
|
// TODO: use cores specified by CoreList when setting list of cores is supported in go.
|
||||||
|
grpclog.Printf(" * core list: %v (ignored)", config.CoreList)
|
||||||
|
|
||||||
|
grpclog.Printf(" - security params: %v", config.SecurityParams)
|
||||||
|
grpclog.Printf(" - core limit: %v", config.CoreLimit)
|
||||||
|
grpclog.Printf(" - payload config: %v", config.PayloadConfig)
|
||||||
|
grpclog.Printf(" - rpcs per chann: %v", config.OutstandingRpcsPerChannel)
|
||||||
|
grpclog.Printf(" - channel number: %v", config.ClientChannels)
|
||||||
|
grpclog.Printf(" - load params: %v", config.LoadParams)
|
||||||
|
grpclog.Printf(" - rpc type: %v", config.RpcType)
|
||||||
|
grpclog.Printf(" - histogram params: %v", config.HistogramParams)
|
||||||
|
grpclog.Printf(" - server targets: %v", config.ServerTargets)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupClientEnv(config *testpb.ClientConfig) {
|
||||||
|
// Use all cpu cores available on machine by default.
|
||||||
|
// TODO: Revisit this for the optimal default setup.
|
||||||
|
if config.CoreLimit > 0 {
|
||||||
|
runtime.GOMAXPROCS(int(config.CoreLimit))
|
||||||
|
} else {
|
||||||
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// createConns creates connections according to given config.
|
||||||
|
// It returns the connections and corresponding function to close them.
|
||||||
|
// It returns non-nil error if there is anything wrong.
|
||||||
|
func createConns(config *testpb.ClientConfig) ([]*grpc.ClientConn, func(), error) {
|
||||||
|
var opts []grpc.DialOption
|
||||||
|
|
||||||
|
// Sanity check for client type.
|
||||||
|
switch config.ClientType {
|
||||||
|
case testpb.ClientType_SYNC_CLIENT:
|
||||||
|
case testpb.ClientType_ASYNC_CLIENT:
|
||||||
|
default:
|
||||||
|
return nil, nil, grpc.Errorf(codes.InvalidArgument, "unknow client type: %v", config.ClientType)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check and set security options.
|
||||||
|
if config.SecurityParams != nil {
|
||||||
|
creds, err := credentials.NewClientTLSFromFile(abs(caFile), config.SecurityParams.ServerHostOverride)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, grpc.Errorf(codes.InvalidArgument, "failed to create TLS credentials %v", err)
|
||||||
|
}
|
||||||
|
opts = append(opts, grpc.WithTransportCredentials(creds))
|
||||||
|
} else {
|
||||||
|
opts = append(opts, grpc.WithInsecure())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use byteBufCodec if it is required.
|
||||||
|
if config.PayloadConfig != nil {
|
||||||
|
switch config.PayloadConfig.Payload.(type) {
|
||||||
|
case *testpb.PayloadConfig_BytebufParams:
|
||||||
|
opts = append(opts, grpc.WithCodec(byteBufCodec{}))
|
||||||
|
case *testpb.PayloadConfig_SimpleParams:
|
||||||
|
default:
|
||||||
|
return nil, nil, grpc.Errorf(codes.InvalidArgument, "unknow payload config: %v", config.PayloadConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create connections.
|
||||||
|
connCount := int(config.ClientChannels)
|
||||||
|
conns := make([]*grpc.ClientConn, connCount, connCount)
|
||||||
|
for connIndex := 0; connIndex < connCount; connIndex++ {
|
||||||
|
conns[connIndex] = benchmark.NewClientConn(config.ServerTargets[connIndex%len(config.ServerTargets)], opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return conns, func() {
|
||||||
|
for _, conn := range conns {
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func performRPCs(config *testpb.ClientConfig, conns []*grpc.ClientConn, bc *benchmarkClient) error {
|
||||||
|
// Read payload size and type from config.
|
||||||
|
var (
|
||||||
|
payloadReqSize, payloadRespSize int
|
||||||
|
payloadType string
|
||||||
|
)
|
||||||
|
if config.PayloadConfig != nil {
|
||||||
|
switch c := config.PayloadConfig.Payload.(type) {
|
||||||
|
case *testpb.PayloadConfig_BytebufParams:
|
||||||
|
payloadReqSize = int(c.BytebufParams.ReqSize)
|
||||||
|
payloadRespSize = int(c.BytebufParams.RespSize)
|
||||||
|
payloadType = "bytebuf"
|
||||||
|
case *testpb.PayloadConfig_SimpleParams:
|
||||||
|
payloadReqSize = int(c.SimpleParams.ReqSize)
|
||||||
|
payloadRespSize = int(c.SimpleParams.RespSize)
|
||||||
|
payloadType = "protobuf"
|
||||||
|
default:
|
||||||
|
return grpc.Errorf(codes.InvalidArgument, "unknow payload config: %v", config.PayloadConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO add open loop distribution.
|
||||||
|
switch config.LoadParams.Load.(type) {
|
||||||
|
case *testpb.LoadParams_ClosedLoop:
|
||||||
|
case *testpb.LoadParams_Poisson:
|
||||||
|
return grpc.Errorf(codes.Unimplemented, "unsupported load params: %v", config.LoadParams)
|
||||||
|
default:
|
||||||
|
return grpc.Errorf(codes.InvalidArgument, "unknown load params: %v", config.LoadParams)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcCountPerConn := int(config.OutstandingRpcsPerChannel)
|
||||||
|
|
||||||
|
switch config.RpcType {
|
||||||
|
case testpb.RpcType_UNARY:
|
||||||
|
bc.doCloseLoopUnary(conns, rpcCountPerConn, payloadReqSize, payloadRespSize)
|
||||||
|
// TODO open loop.
|
||||||
|
case testpb.RpcType_STREAMING:
|
||||||
|
bc.doCloseLoopStreaming(conns, rpcCountPerConn, payloadReqSize, payloadRespSize, payloadType)
|
||||||
|
// TODO open loop.
|
||||||
|
default:
|
||||||
|
return grpc.Errorf(codes.InvalidArgument, "unknown rpc type: %v", config.RpcType)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func startBenchmarkClient(config *testpb.ClientConfig) (*benchmarkClient, error) {
|
||||||
|
printClientConfig(config)
|
||||||
|
|
||||||
|
// Set running environment like how many cores to use.
|
||||||
|
setupClientEnv(config)
|
||||||
|
|
||||||
|
conns, closeConns, err := createConns(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcCountPerConn := int(config.OutstandingRpcsPerChannel)
|
||||||
|
bc := &benchmarkClient{
|
||||||
|
histogramOptions: stats.HistogramOptions{
|
||||||
|
NumBuckets: int(math.Log(config.HistogramParams.MaxPossible)/math.Log(1+config.HistogramParams.Resolution)) + 1,
|
||||||
|
GrowthFactor: config.HistogramParams.Resolution,
|
||||||
|
BaseBucketSize: (1 + config.HistogramParams.Resolution),
|
||||||
|
MinValue: 0,
|
||||||
|
},
|
||||||
|
lockingHistograms: make([]lockingHistogram, rpcCountPerConn*len(conns), rpcCountPerConn*len(conns)),
|
||||||
|
|
||||||
|
stop: make(chan bool),
|
||||||
|
lastResetTime: time.Now(),
|
||||||
|
closeConns: closeConns,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = performRPCs(config, conns, bc); err != nil {
|
||||||
|
// Close all connections if performRPCs failed.
|
||||||
|
closeConns()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return bc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc *benchmarkClient) doCloseLoopUnary(conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int) {
|
||||||
|
for ic, conn := range conns {
|
||||||
|
client := testpb.NewBenchmarkServiceClient(conn)
|
||||||
|
// For each connection, create rpcCountPerConn goroutines to do rpc.
|
||||||
|
for j := 0; j < rpcCountPerConn; j++ {
|
||||||
|
// Create histogram for each goroutine.
|
||||||
|
idx := ic*rpcCountPerConn + j
|
||||||
|
bc.lockingHistograms[idx].histogram = stats.NewHistogram(bc.histogramOptions)
|
||||||
|
// Start goroutine on the created mutex and histogram.
|
||||||
|
go func(idx int) {
|
||||||
|
// TODO: do warm up if necessary.
|
||||||
|
// Now relying on worker client to reserve time to do warm up.
|
||||||
|
// The worker client needs to wait for some time after client is created,
|
||||||
|
// before starting benchmark.
|
||||||
|
done := make(chan bool)
|
||||||
|
for {
|
||||||
|
go func() {
|
||||||
|
start := time.Now()
|
||||||
|
if err := benchmark.DoUnaryCall(client, reqSize, respSize); err != nil {
|
||||||
|
select {
|
||||||
|
case <-bc.stop:
|
||||||
|
case done <- false:
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
elapse := time.Since(start)
|
||||||
|
bc.lockingHistograms[idx].add(int64(elapse))
|
||||||
|
select {
|
||||||
|
case <-bc.stop:
|
||||||
|
case done <- true:
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-bc.stop:
|
||||||
|
return
|
||||||
|
case <-done:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc *benchmarkClient) doCloseLoopStreaming(conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int, payloadType string) {
|
||||||
|
var doRPC func(testpb.BenchmarkService_StreamingCallClient, int, int) error
|
||||||
|
if payloadType == "bytebuf" {
|
||||||
|
doRPC = benchmark.DoByteBufStreamingRoundTrip
|
||||||
|
} else {
|
||||||
|
doRPC = benchmark.DoStreamingRoundTrip
|
||||||
|
}
|
||||||
|
for ic, conn := range conns {
|
||||||
|
// For each connection, create rpcCountPerConn goroutines to do rpc.
|
||||||
|
for j := 0; j < rpcCountPerConn; j++ {
|
||||||
|
c := testpb.NewBenchmarkServiceClient(conn)
|
||||||
|
stream, err := c.StreamingCall(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.StreamingCall(_) = _, %v", c, err)
|
||||||
|
}
|
||||||
|
// Create histogram for each goroutine.
|
||||||
|
idx := ic*rpcCountPerConn + j
|
||||||
|
bc.lockingHistograms[idx].histogram = stats.NewHistogram(bc.histogramOptions)
|
||||||
|
// Start goroutine on the created mutex and histogram.
|
||||||
|
go func(idx int) {
|
||||||
|
// TODO: do warm up if necessary.
|
||||||
|
// Now relying on worker client to reserve time to do warm up.
|
||||||
|
// The worker client needs to wait for some time after client is created,
|
||||||
|
// before starting benchmark.
|
||||||
|
done := make(chan bool)
|
||||||
|
for {
|
||||||
|
go func() {
|
||||||
|
start := time.Now()
|
||||||
|
if err := doRPC(stream, reqSize, respSize); err != nil {
|
||||||
|
select {
|
||||||
|
case <-bc.stop:
|
||||||
|
case done <- false:
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
elapse := time.Since(start)
|
||||||
|
bc.lockingHistograms[idx].add(int64(elapse))
|
||||||
|
select {
|
||||||
|
case <-bc.stop:
|
||||||
|
case done <- true:
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-bc.stop:
|
||||||
|
return
|
||||||
|
case <-done:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getStats returns the stats for benchmark client.
|
||||||
|
// It resets lastResetTime and all histograms if argument reset is true.
|
||||||
|
func (bc *benchmarkClient) getStats(reset bool) *testpb.ClientStats {
|
||||||
|
var timeElapsed float64
|
||||||
|
mergedHistogram := stats.NewHistogram(bc.histogramOptions)
|
||||||
|
|
||||||
|
if reset {
|
||||||
|
// Merging histogram may take some time.
|
||||||
|
// Put all histograms aside and merge later.
|
||||||
|
toMerge := make([]*stats.Histogram, len(bc.lockingHistograms), len(bc.lockingHistograms))
|
||||||
|
for i := range bc.lockingHistograms {
|
||||||
|
toMerge[i] = bc.lockingHistograms[i].swap(stats.NewHistogram(bc.histogramOptions))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(toMerge); i++ {
|
||||||
|
mergedHistogram.Merge(toMerge[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
timeElapsed = time.Since(bc.lastResetTime).Seconds()
|
||||||
|
bc.lastResetTime = time.Now()
|
||||||
|
} else {
|
||||||
|
// Merge only, not reset.
|
||||||
|
for i := range bc.lockingHistograms {
|
||||||
|
bc.lockingHistograms[i].mergeInto(mergedHistogram)
|
||||||
|
}
|
||||||
|
timeElapsed = time.Since(bc.lastResetTime).Seconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
b := make([]uint32, len(mergedHistogram.Buckets), len(mergedHistogram.Buckets))
|
||||||
|
for i, v := range mergedHistogram.Buckets {
|
||||||
|
b[i] = uint32(v.Count)
|
||||||
|
}
|
||||||
|
return &testpb.ClientStats{
|
||||||
|
Latencies: &testpb.HistogramData{
|
||||||
|
Bucket: b,
|
||||||
|
MinSeen: float64(mergedHistogram.Min),
|
||||||
|
MaxSeen: float64(mergedHistogram.Max),
|
||||||
|
Sum: float64(mergedHistogram.Sum),
|
||||||
|
SumOfSquares: float64(mergedHistogram.SumOfSquares),
|
||||||
|
Count: float64(mergedHistogram.Count),
|
||||||
|
},
|
||||||
|
TimeElapsed: timeElapsed,
|
||||||
|
TimeUser: 0,
|
||||||
|
TimeSystem: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc *benchmarkClient) shutdown() {
|
||||||
|
close(bc.stop)
|
||||||
|
bc.closeConns()
|
||||||
|
}
|
173
vendor/google.golang.org/grpc/benchmark/worker/benchmark_server.go
generated
vendored
Normal file
173
vendor/google.golang.org/grpc/benchmark/worker/benchmark_server.go
generated
vendored
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/benchmark"
|
||||||
|
testpb "google.golang.org/grpc/benchmark/grpc_testing"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// File path related to google.golang.org/grpc.
|
||||||
|
certFile = "benchmark/server/testdata/server1.pem"
|
||||||
|
keyFile = "benchmark/server/testdata/server1.key"
|
||||||
|
)
|
||||||
|
|
||||||
|
type benchmarkServer struct {
|
||||||
|
port int
|
||||||
|
cores int
|
||||||
|
closeFunc func()
|
||||||
|
mu sync.RWMutex
|
||||||
|
lastResetTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func printServerConfig(config *testpb.ServerConfig) {
|
||||||
|
// Some config options are ignored:
|
||||||
|
// - server type:
|
||||||
|
// will always start sync server
|
||||||
|
// - async server threads
|
||||||
|
// - core list
|
||||||
|
grpclog.Printf(" * server type: %v (ignored, always starts sync server)", config.ServerType)
|
||||||
|
grpclog.Printf(" * async server threads: %v (ignored)", config.AsyncServerThreads)
|
||||||
|
// TODO: use cores specified by CoreList when setting list of cores is supported in go.
|
||||||
|
grpclog.Printf(" * core list: %v (ignored)", config.CoreList)
|
||||||
|
|
||||||
|
grpclog.Printf(" - security params: %v", config.SecurityParams)
|
||||||
|
grpclog.Printf(" - core limit: %v", config.CoreLimit)
|
||||||
|
grpclog.Printf(" - port: %v", config.Port)
|
||||||
|
grpclog.Printf(" - payload config: %v", config.PayloadConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func startBenchmarkServer(config *testpb.ServerConfig, serverPort int) (*benchmarkServer, error) {
|
||||||
|
printServerConfig(config)
|
||||||
|
|
||||||
|
// Use all cpu cores available on machine by default.
|
||||||
|
// TODO: Revisit this for the optimal default setup.
|
||||||
|
numOfCores := runtime.NumCPU()
|
||||||
|
if config.CoreLimit > 0 {
|
||||||
|
numOfCores = int(config.CoreLimit)
|
||||||
|
}
|
||||||
|
runtime.GOMAXPROCS(numOfCores)
|
||||||
|
|
||||||
|
var opts []grpc.ServerOption
|
||||||
|
|
||||||
|
// Sanity check for server type.
|
||||||
|
switch config.ServerType {
|
||||||
|
case testpb.ServerType_SYNC_SERVER:
|
||||||
|
case testpb.ServerType_ASYNC_SERVER:
|
||||||
|
case testpb.ServerType_ASYNC_GENERIC_SERVER:
|
||||||
|
default:
|
||||||
|
return nil, grpc.Errorf(codes.InvalidArgument, "unknow server type: %v", config.ServerType)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set security options.
|
||||||
|
if config.SecurityParams != nil {
|
||||||
|
creds, err := credentials.NewServerTLSFromFile(abs(certFile), abs(keyFile))
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("failed to generate credentials %v", err)
|
||||||
|
}
|
||||||
|
opts = append(opts, grpc.Creds(creds))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Priority: config.Port > serverPort > default (0).
|
||||||
|
port := int(config.Port)
|
||||||
|
if port == 0 {
|
||||||
|
port = serverPort
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create different benchmark server according to config.
|
||||||
|
var (
|
||||||
|
addr string
|
||||||
|
closeFunc func()
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if config.PayloadConfig != nil {
|
||||||
|
switch payload := config.PayloadConfig.Payload.(type) {
|
||||||
|
case *testpb.PayloadConfig_BytebufParams:
|
||||||
|
opts = append(opts, grpc.CustomCodec(byteBufCodec{}))
|
||||||
|
addr, closeFunc = benchmark.StartServer(benchmark.ServerInfo{
|
||||||
|
Addr: ":" + strconv.Itoa(port),
|
||||||
|
Type: "bytebuf",
|
||||||
|
Metadata: payload.BytebufParams.RespSize,
|
||||||
|
}, opts...)
|
||||||
|
case *testpb.PayloadConfig_SimpleParams:
|
||||||
|
addr, closeFunc = benchmark.StartServer(benchmark.ServerInfo{
|
||||||
|
Addr: ":" + strconv.Itoa(port),
|
||||||
|
Type: "protobuf",
|
||||||
|
}, opts...)
|
||||||
|
case *testpb.PayloadConfig_ComplexParams:
|
||||||
|
return nil, grpc.Errorf(codes.Unimplemented, "unsupported payload config: %v", config.PayloadConfig)
|
||||||
|
default:
|
||||||
|
return nil, grpc.Errorf(codes.InvalidArgument, "unknow payload config: %v", config.PayloadConfig)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Start protobuf server if payload config is nil.
|
||||||
|
addr, closeFunc = benchmark.StartServer(benchmark.ServerInfo{
|
||||||
|
Addr: ":" + strconv.Itoa(port),
|
||||||
|
Type: "protobuf",
|
||||||
|
}, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
grpclog.Printf("benchmark server listening at %v", addr)
|
||||||
|
addrSplitted := strings.Split(addr, ":")
|
||||||
|
p, err := strconv.Atoi(addrSplitted[len(addrSplitted)-1])
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("failed to get port number from server address: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &benchmarkServer{port: p, cores: numOfCores, closeFunc: closeFunc, lastResetTime: time.Now()}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getStats returns the stats for benchmark server.
|
||||||
|
// It resets lastResetTime if argument reset is true.
|
||||||
|
func (bs *benchmarkServer) getStats(reset bool) *testpb.ServerStats {
|
||||||
|
// TODO wall time, sys time, user time.
|
||||||
|
bs.mu.RLock()
|
||||||
|
defer bs.mu.RUnlock()
|
||||||
|
timeElapsed := time.Since(bs.lastResetTime).Seconds()
|
||||||
|
if reset {
|
||||||
|
bs.lastResetTime = time.Now()
|
||||||
|
}
|
||||||
|
return &testpb.ServerStats{TimeElapsed: timeElapsed, TimeUser: 0, TimeSystem: 0}
|
||||||
|
}
|
231
vendor/google.golang.org/grpc/benchmark/worker/main.go
generated
vendored
Normal file
231
vendor/google.golang.org/grpc/benchmark/worker/main.go
generated
vendored
Normal file
|
@ -0,0 +1,231 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
testpb "google.golang.org/grpc/benchmark/grpc_testing"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
driverPort = flag.Int("driver_port", 10000, "port for communication with driver")
|
||||||
|
serverPort = flag.Int("server_port", 0, "port for benchmark server if not specified by server config message")
|
||||||
|
)
|
||||||
|
|
||||||
|
type byteBufCodec struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (byteBufCodec) Marshal(v interface{}) ([]byte, error) {
|
||||||
|
b, ok := v.(*[]byte)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("failed to marshal: %v is not type of *[]byte", v)
|
||||||
|
}
|
||||||
|
return *b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (byteBufCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
|
b, ok := v.(*[]byte)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("failed to marshal: %v is not type of *[]byte", v)
|
||||||
|
}
|
||||||
|
*b = data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (byteBufCodec) String() string {
|
||||||
|
return "bytebuffer"
|
||||||
|
}
|
||||||
|
|
||||||
|
// workerServer implements WorkerService rpc handlers.
|
||||||
|
// It can create benchmarkServer or benchmarkClient on demand.
|
||||||
|
type workerServer struct {
|
||||||
|
stop chan<- bool
|
||||||
|
serverPort int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *workerServer) RunServer(stream testpb.WorkerService_RunServerServer) error {
|
||||||
|
var bs *benchmarkServer
|
||||||
|
defer func() {
|
||||||
|
// Close benchmark server when stream ends.
|
||||||
|
grpclog.Printf("closing benchmark server")
|
||||||
|
if bs != nil {
|
||||||
|
bs.closeFunc()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var out *testpb.ServerStatus
|
||||||
|
switch argtype := in.Argtype.(type) {
|
||||||
|
case *testpb.ServerArgs_Setup:
|
||||||
|
grpclog.Printf("server setup received:")
|
||||||
|
if bs != nil {
|
||||||
|
grpclog.Printf("server setup received when server already exists, closing the existing server")
|
||||||
|
bs.closeFunc()
|
||||||
|
}
|
||||||
|
bs, err = startBenchmarkServer(argtype.Setup, s.serverPort)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out = &testpb.ServerStatus{
|
||||||
|
Stats: bs.getStats(false),
|
||||||
|
Port: int32(bs.port),
|
||||||
|
Cores: int32(bs.cores),
|
||||||
|
}
|
||||||
|
|
||||||
|
case *testpb.ServerArgs_Mark:
|
||||||
|
grpclog.Printf("server mark received:")
|
||||||
|
grpclog.Printf(" - %v", argtype)
|
||||||
|
if bs == nil {
|
||||||
|
return grpc.Errorf(codes.InvalidArgument, "server does not exist when mark received")
|
||||||
|
}
|
||||||
|
out = &testpb.ServerStatus{
|
||||||
|
Stats: bs.getStats(argtype.Mark.Reset_),
|
||||||
|
Port: int32(bs.port),
|
||||||
|
Cores: int32(bs.cores),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := stream.Send(out); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *workerServer) RunClient(stream testpb.WorkerService_RunClientServer) error {
|
||||||
|
var bc *benchmarkClient
|
||||||
|
defer func() {
|
||||||
|
// Shut down benchmark client when stream ends.
|
||||||
|
grpclog.Printf("shuting down benchmark client")
|
||||||
|
if bc != nil {
|
||||||
|
bc.shutdown()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var out *testpb.ClientStatus
|
||||||
|
switch t := in.Argtype.(type) {
|
||||||
|
case *testpb.ClientArgs_Setup:
|
||||||
|
grpclog.Printf("client setup received:")
|
||||||
|
if bc != nil {
|
||||||
|
grpclog.Printf("client setup received when client already exists, shuting down the existing client")
|
||||||
|
bc.shutdown()
|
||||||
|
}
|
||||||
|
bc, err = startBenchmarkClient(t.Setup)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out = &testpb.ClientStatus{
|
||||||
|
Stats: bc.getStats(false),
|
||||||
|
}
|
||||||
|
|
||||||
|
case *testpb.ClientArgs_Mark:
|
||||||
|
grpclog.Printf("client mark received:")
|
||||||
|
grpclog.Printf(" - %v", t)
|
||||||
|
if bc == nil {
|
||||||
|
return grpc.Errorf(codes.InvalidArgument, "client does not exist when mark received")
|
||||||
|
}
|
||||||
|
out = &testpb.ClientStatus{
|
||||||
|
Stats: bc.getStats(t.Mark.Reset_),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := stream.Send(out); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *workerServer) CoreCount(ctx context.Context, in *testpb.CoreRequest) (*testpb.CoreResponse, error) {
|
||||||
|
grpclog.Printf("core count: %v", runtime.NumCPU())
|
||||||
|
return &testpb.CoreResponse{Cores: int32(runtime.NumCPU())}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *workerServer) QuitWorker(ctx context.Context, in *testpb.Void) (*testpb.Void, error) {
|
||||||
|
grpclog.Printf("quiting worker")
|
||||||
|
s.stop <- true
|
||||||
|
return &testpb.Void{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
grpc.EnableTracing = false
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
lis, err := net.Listen("tcp", ":"+strconv.Itoa(*driverPort))
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
grpclog.Printf("worker listening at port %v", *driverPort)
|
||||||
|
|
||||||
|
s := grpc.NewServer()
|
||||||
|
stop := make(chan bool)
|
||||||
|
testpb.RegisterWorkerServiceServer(s, &workerServer{
|
||||||
|
stop: stop,
|
||||||
|
serverPort: *serverPort,
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-stop
|
||||||
|
// Wait for 1 second before stopping the server to make sure the return value of QuitWorker is sent to client.
|
||||||
|
// TODO revise this once server graceful stop is supported in gRPC.
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
s.Stop()
|
||||||
|
}()
|
||||||
|
|
||||||
|
s.Serve(lis)
|
||||||
|
}
|
75
vendor/google.golang.org/grpc/benchmark/worker/util.go
generated
vendored
Normal file
75
vendor/google.golang.org/grpc/benchmark/worker/util.go
generated
vendored
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// abs returns the absolute path the given relative file or directory path,
|
||||||
|
// relative to the google.golang.org/grpc directory in the user's GOPATH.
|
||||||
|
// If rel is already absolute, it is returned unmodified.
|
||||||
|
func abs(rel string) string {
|
||||||
|
if filepath.IsAbs(rel) {
|
||||||
|
return rel
|
||||||
|
}
|
||||||
|
v, err := goPackagePath("google.golang.org/grpc")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error finding google.golang.org/grpc/testdata directory: %v", err)
|
||||||
|
}
|
||||||
|
return filepath.Join(v, rel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func goPackagePath(pkg string) (path string, err error) {
|
||||||
|
gp := os.Getenv("GOPATH")
|
||||||
|
if gp == "" {
|
||||||
|
return path, os.ErrNotExist
|
||||||
|
}
|
||||||
|
for _, p := range filepath.SplitList(gp) {
|
||||||
|
dir := filepath.Join(p, "src", filepath.FromSlash(pkg))
|
||||||
|
fi, err := os.Stat(dir)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if !fi.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return dir, nil
|
||||||
|
}
|
||||||
|
return path, os.ErrNotExist
|
||||||
|
}
|
233
vendor/google.golang.org/grpc/call.go
generated
vendored
Normal file
233
vendor/google.golang.org/grpc/call.go
generated
vendored
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"golang.org/x/net/trace"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/transport"
|
||||||
|
)
|
||||||
|
|
||||||
|
// recvResponse receives and parses an RPC response.
|
||||||
|
// On error, it returns the error and indicates whether the call should be retried.
|
||||||
|
//
|
||||||
|
// TODO(zhaoq): Check whether the received message sequence is valid.
|
||||||
|
func recvResponse(dopts dialOptions, t transport.ClientTransport, c *callInfo, stream *transport.Stream, reply interface{}) error {
|
||||||
|
// Try to acquire header metadata from the server if there is any.
|
||||||
|
var err error
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(transport.ConnectionError); !ok {
|
||||||
|
t.CloseStream(stream, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
c.headerMD, err = stream.Header()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p := &parser{r: stream}
|
||||||
|
for {
|
||||||
|
if err = recv(p, dopts.codec, stream, dopts.dc, reply, math.MaxInt32); err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.trailerMD = stream.Trailer()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendRequest writes out various information of an RPC such as Context and Message.
|
||||||
|
func sendRequest(ctx context.Context, codec Codec, compressor Compressor, callHdr *transport.CallHdr, t transport.ClientTransport, args interface{}, opts *transport.Options) (_ *transport.Stream, err error) {
|
||||||
|
stream, err := t.NewStream(ctx, callHdr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
// If err is connection error, t will be closed, no need to close stream here.
|
||||||
|
if _, ok := err.(transport.ConnectionError); !ok {
|
||||||
|
t.CloseStream(stream, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
var cbuf *bytes.Buffer
|
||||||
|
if compressor != nil {
|
||||||
|
cbuf = new(bytes.Buffer)
|
||||||
|
}
|
||||||
|
outBuf, err := encode(codec, args, compressor, cbuf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, Errorf(codes.Internal, "grpc: %v", err)
|
||||||
|
}
|
||||||
|
err = t.Write(stream, outBuf, opts)
|
||||||
|
// t.NewStream(...) could lead to an early rejection of the RPC (e.g., the service/method
|
||||||
|
// does not exist.) so that t.Write could get io.EOF from wait(...). Leave the following
|
||||||
|
// recvResponse to get the final status.
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Sent successfully.
|
||||||
|
return stream, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoke sends the RPC request on the wire and returns after response is received.
|
||||||
|
// Invoke is called by generated code. Also users can call Invoke directly when it
|
||||||
|
// is really needed in their use cases.
|
||||||
|
func Invoke(ctx context.Context, method string, args, reply interface{}, cc *ClientConn, opts ...CallOption) error {
|
||||||
|
if cc.dopts.unaryInt != nil {
|
||||||
|
return cc.dopts.unaryInt(ctx, method, args, reply, cc, invoke, opts...)
|
||||||
|
}
|
||||||
|
return invoke(ctx, method, args, reply, cc, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func invoke(ctx context.Context, method string, args, reply interface{}, cc *ClientConn, opts ...CallOption) (err error) {
|
||||||
|
c := defaultCallInfo
|
||||||
|
for _, o := range opts {
|
||||||
|
if err := o.before(&c); err != nil {
|
||||||
|
return toRPCErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
for _, o := range opts {
|
||||||
|
o.after(&c)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if EnableTracing {
|
||||||
|
c.traceInfo.tr = trace.New("grpc.Sent."+methodFamily(method), method)
|
||||||
|
defer c.traceInfo.tr.Finish()
|
||||||
|
c.traceInfo.firstLine.client = true
|
||||||
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
|
c.traceInfo.firstLine.deadline = deadline.Sub(time.Now())
|
||||||
|
}
|
||||||
|
c.traceInfo.tr.LazyLog(&c.traceInfo.firstLine, false)
|
||||||
|
// TODO(dsymonds): Arrange for c.traceInfo.firstLine.remoteAddr to be set.
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
c.traceInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true)
|
||||||
|
c.traceInfo.tr.SetError()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
topts := &transport.Options{
|
||||||
|
Last: true,
|
||||||
|
Delay: false,
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
t transport.ClientTransport
|
||||||
|
stream *transport.Stream
|
||||||
|
// Record the put handler from Balancer.Get(...). It is called once the
|
||||||
|
// RPC has completed or failed.
|
||||||
|
put func()
|
||||||
|
)
|
||||||
|
// TODO(zhaoq): Need a formal spec of fail-fast.
|
||||||
|
callHdr := &transport.CallHdr{
|
||||||
|
Host: cc.authority,
|
||||||
|
Method: method,
|
||||||
|
}
|
||||||
|
if cc.dopts.cp != nil {
|
||||||
|
callHdr.SendCompress = cc.dopts.cp.Type()
|
||||||
|
}
|
||||||
|
gopts := BalancerGetOptions{
|
||||||
|
BlockingWait: !c.failFast,
|
||||||
|
}
|
||||||
|
t, put, err = cc.getTransport(ctx, gopts)
|
||||||
|
if err != nil {
|
||||||
|
// TODO(zhaoq): Probably revisit the error handling.
|
||||||
|
if _, ok := err.(*rpcError); ok {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err == errConnClosing || err == errConnUnavailable {
|
||||||
|
if c.failFast {
|
||||||
|
return Errorf(codes.Unavailable, "%v", err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// All the other errors are treated as Internal errors.
|
||||||
|
return Errorf(codes.Internal, "%v", err)
|
||||||
|
}
|
||||||
|
if c.traceInfo.tr != nil {
|
||||||
|
c.traceInfo.tr.LazyLog(&payload{sent: true, msg: args}, true)
|
||||||
|
}
|
||||||
|
stream, err = sendRequest(ctx, cc.dopts.codec, cc.dopts.cp, callHdr, t, args, topts)
|
||||||
|
if err != nil {
|
||||||
|
if put != nil {
|
||||||
|
put()
|
||||||
|
put = nil
|
||||||
|
}
|
||||||
|
// Retry a non-failfast RPC when
|
||||||
|
// i) there is a connection error; or
|
||||||
|
// ii) the server started to drain before this RPC was initiated.
|
||||||
|
if _, ok := err.(transport.ConnectionError); ok || err == transport.ErrStreamDrain {
|
||||||
|
if c.failFast {
|
||||||
|
return toRPCErr(err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return toRPCErr(err)
|
||||||
|
}
|
||||||
|
err = recvResponse(cc.dopts, t, &c, stream, reply)
|
||||||
|
if err != nil {
|
||||||
|
if put != nil {
|
||||||
|
put()
|
||||||
|
put = nil
|
||||||
|
}
|
||||||
|
if _, ok := err.(transport.ConnectionError); ok || err == transport.ErrStreamDrain {
|
||||||
|
if c.failFast {
|
||||||
|
return toRPCErr(err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return toRPCErr(err)
|
||||||
|
}
|
||||||
|
if c.traceInfo.tr != nil {
|
||||||
|
c.traceInfo.tr.LazyLog(&payload{sent: false, msg: reply}, true)
|
||||||
|
}
|
||||||
|
t.CloseStream(stream, nil)
|
||||||
|
if put != nil {
|
||||||
|
put()
|
||||||
|
put = nil
|
||||||
|
}
|
||||||
|
return Errorf(stream.StatusCode(), "%s", stream.StatusDesc())
|
||||||
|
}
|
||||||
|
}
|
293
vendor/google.golang.org/grpc/call_test.go
generated
vendored
Normal file
293
vendor/google.golang.org/grpc/call_test.go
generated
vendored
Normal file
|
@ -0,0 +1,293 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/transport"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expectedRequest = "ping"
|
||||||
|
expectedResponse = "pong"
|
||||||
|
weirdError = "format verbs: %v%s"
|
||||||
|
sizeLargeErr = 1024 * 1024
|
||||||
|
canceled = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
type testCodec struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (testCodec) Marshal(v interface{}) ([]byte, error) {
|
||||||
|
return []byte(*(v.(*string))), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (testCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
|
*(v.(*string)) = string(data)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (testCodec) String() string {
|
||||||
|
return "test"
|
||||||
|
}
|
||||||
|
|
||||||
|
type testStreamHandler struct {
|
||||||
|
port string
|
||||||
|
t transport.ServerTransport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *testStreamHandler) handleStream(t *testing.T, s *transport.Stream) {
|
||||||
|
p := &parser{r: s}
|
||||||
|
for {
|
||||||
|
pf, req, err := p.recvMsg(math.MaxInt32)
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if pf != compressionNone {
|
||||||
|
t.Errorf("Received the mistaken message format %d, want %d", pf, compressionNone)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var v string
|
||||||
|
codec := testCodec{}
|
||||||
|
if err := codec.Unmarshal(req, &v); err != nil {
|
||||||
|
t.Errorf("Failed to unmarshal the received message: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v == "weird error" {
|
||||||
|
h.t.WriteStatus(s, codes.Internal, weirdError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v == "canceled" {
|
||||||
|
canceled++
|
||||||
|
h.t.WriteStatus(s, codes.Internal, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v == "port" {
|
||||||
|
h.t.WriteStatus(s, codes.Internal, h.port)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if v != expectedRequest {
|
||||||
|
h.t.WriteStatus(s, codes.Internal, strings.Repeat("A", sizeLargeErr))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// send a response back to end the stream.
|
||||||
|
reply, err := encode(testCodec{}, &expectedResponse, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to encode the response: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.t.Write(s, reply, &transport.Options{})
|
||||||
|
h.t.WriteStatus(s, codes.OK, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
type server struct {
|
||||||
|
lis net.Listener
|
||||||
|
port string
|
||||||
|
startedErr chan error // sent nil or an error after server starts
|
||||||
|
mu sync.Mutex
|
||||||
|
conns map[transport.ServerTransport]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestServer() *server {
|
||||||
|
return &server{startedErr: make(chan error, 1)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// start starts server. Other goroutines should block on s.startedErr for further operations.
|
||||||
|
func (s *server) start(t *testing.T, port int, maxStreams uint32) {
|
||||||
|
var err error
|
||||||
|
if port == 0 {
|
||||||
|
s.lis, err = net.Listen("tcp", "localhost:0")
|
||||||
|
} else {
|
||||||
|
s.lis, err = net.Listen("tcp", "localhost:"+strconv.Itoa(port))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
s.startedErr <- fmt.Errorf("failed to listen: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, p, err := net.SplitHostPort(s.lis.Addr().String())
|
||||||
|
if err != nil {
|
||||||
|
s.startedErr <- fmt.Errorf("failed to parse listener address: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.port = p
|
||||||
|
s.conns = make(map[transport.ServerTransport]bool)
|
||||||
|
s.startedErr <- nil
|
||||||
|
for {
|
||||||
|
conn, err := s.lis.Accept()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
st, err := transport.NewServerTransport("http2", conn, maxStreams, nil)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
s.mu.Lock()
|
||||||
|
if s.conns == nil {
|
||||||
|
s.mu.Unlock()
|
||||||
|
st.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.conns[st] = true
|
||||||
|
s.mu.Unlock()
|
||||||
|
h := &testStreamHandler{
|
||||||
|
port: s.port,
|
||||||
|
t: st,
|
||||||
|
}
|
||||||
|
go st.HandleStreams(func(s *transport.Stream) {
|
||||||
|
go h.handleStream(t, s)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *server) wait(t *testing.T, timeout time.Duration) {
|
||||||
|
select {
|
||||||
|
case err := <-s.startedErr:
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatalf("Timed out after %v waiting for server to be ready", timeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *server) stop() {
|
||||||
|
s.lis.Close()
|
||||||
|
s.mu.Lock()
|
||||||
|
for c := range s.conns {
|
||||||
|
c.Close()
|
||||||
|
}
|
||||||
|
s.conns = nil
|
||||||
|
s.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setUp(t *testing.T, port int, maxStreams uint32) (*server, *ClientConn) {
|
||||||
|
server := newTestServer()
|
||||||
|
go server.start(t, port, maxStreams)
|
||||||
|
server.wait(t, 2*time.Second)
|
||||||
|
addr := "localhost:" + server.port
|
||||||
|
cc, err := Dial(addr, WithBlock(), WithInsecure(), WithCodec(testCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create ClientConn: %v", err)
|
||||||
|
}
|
||||||
|
return server, cc
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvoke(t *testing.T) {
|
||||||
|
server, cc := setUp(t, 0, math.MaxUint32)
|
||||||
|
var reply string
|
||||||
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc); err != nil || reply != expectedResponse {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want <nil>", err)
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
server.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvokeLargeErr(t *testing.T) {
|
||||||
|
server, cc := setUp(t, 0, math.MaxUint32)
|
||||||
|
var reply string
|
||||||
|
req := "hello"
|
||||||
|
err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc)
|
||||||
|
if _, ok := err.(*rpcError); !ok {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) receives non rpc error.")
|
||||||
|
}
|
||||||
|
if Code(err) != codes.Internal || len(ErrorDesc(err)) != sizeLargeErr {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want an error of code %d and desc size %d", err, codes.Internal, sizeLargeErr)
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
server.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestInvokeErrorSpecialChars checks that error messages don't get mangled.
|
||||||
|
func TestInvokeErrorSpecialChars(t *testing.T) {
|
||||||
|
server, cc := setUp(t, 0, math.MaxUint32)
|
||||||
|
var reply string
|
||||||
|
req := "weird error"
|
||||||
|
err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc)
|
||||||
|
if _, ok := err.(*rpcError); !ok {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) receives non rpc error.")
|
||||||
|
}
|
||||||
|
if got, want := ErrorDesc(err), weirdError; got != want {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) error = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
server.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestInvokeCancel checks that an Invoke with a canceled context is not sent.
|
||||||
|
func TestInvokeCancel(t *testing.T) {
|
||||||
|
server, cc := setUp(t, 0, math.MaxUint32)
|
||||||
|
var reply string
|
||||||
|
req := "canceled"
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
Invoke(ctx, "/foo/bar", &req, &reply, cc)
|
||||||
|
}
|
||||||
|
if canceled != 0 {
|
||||||
|
t.Fatalf("received %d of 100 canceled requests", canceled)
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
server.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestInvokeCancelClosedNonFail checks that a canceled non-failfast RPC
|
||||||
|
// on a closed client will terminate.
|
||||||
|
func TestInvokeCancelClosedNonFailFast(t *testing.T) {
|
||||||
|
server, cc := setUp(t, 0, math.MaxUint32)
|
||||||
|
var reply string
|
||||||
|
cc.Close()
|
||||||
|
req := "hello"
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
if err := Invoke(ctx, "/foo/bar", &req, &reply, cc, FailFast(false)); err == nil {
|
||||||
|
t.Fatalf("canceled invoke on closed connection should fail")
|
||||||
|
}
|
||||||
|
server.stop()
|
||||||
|
}
|
884
vendor/google.golang.org/grpc/clientconn.go
generated
vendored
Normal file
884
vendor/google.golang.org/grpc/clientconn.go
generated
vendored
Normal file
|
@ -0,0 +1,884 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"golang.org/x/net/trace"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/transport"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrClientConnClosing indicates that the operation is illegal because
|
||||||
|
// the ClientConn is closing.
|
||||||
|
ErrClientConnClosing = errors.New("grpc: the client connection is closing")
|
||||||
|
// ErrClientConnTimeout indicates that the ClientConn cannot establish the
|
||||||
|
// underlying connections within the specified timeout.
|
||||||
|
ErrClientConnTimeout = errors.New("grpc: timed out when dialing")
|
||||||
|
|
||||||
|
// errNoTransportSecurity indicates that there is no transport security
|
||||||
|
// being set for ClientConn. Users should either set one or explicitly
|
||||||
|
// call WithInsecure DialOption to disable security.
|
||||||
|
errNoTransportSecurity = errors.New("grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)")
|
||||||
|
// errTransportCredentialsMissing indicates that users want to transmit security
|
||||||
|
// information (e.g., oauth2 token) which requires secure connection on an insecure
|
||||||
|
// connection.
|
||||||
|
errTransportCredentialsMissing = errors.New("grpc: the credentials require transport level security (use grpc.WithTransportCredentials() to set)")
|
||||||
|
// errCredentialsConflict indicates that grpc.WithTransportCredentials()
|
||||||
|
// and grpc.WithInsecure() are both called for a connection.
|
||||||
|
errCredentialsConflict = errors.New("grpc: transport credentials are set for an insecure connection (grpc.WithTransportCredentials() and grpc.WithInsecure() are both called)")
|
||||||
|
// errNetworkIO indicates that the connection is down due to some network I/O error.
|
||||||
|
errNetworkIO = errors.New("grpc: failed with network I/O error")
|
||||||
|
// errConnDrain indicates that the connection starts to be drained and does not accept any new RPCs.
|
||||||
|
errConnDrain = errors.New("grpc: the connection is drained")
|
||||||
|
// errConnClosing indicates that the connection is closing.
|
||||||
|
errConnClosing = errors.New("grpc: the connection is closing")
|
||||||
|
// errConnUnavailable indicates that the connection is unavailable.
|
||||||
|
errConnUnavailable = errors.New("grpc: the connection is unavailable")
|
||||||
|
errNoAddr = errors.New("grpc: there is no address available to dial")
|
||||||
|
// minimum time to give a connection to complete
|
||||||
|
minConnectTimeout = 20 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
|
// dialOptions configure a Dial call. dialOptions are set by the DialOption
|
||||||
|
// values passed to Dial.
|
||||||
|
type dialOptions struct {
|
||||||
|
unaryInt UnaryClientInterceptor
|
||||||
|
streamInt StreamClientInterceptor
|
||||||
|
codec Codec
|
||||||
|
cp Compressor
|
||||||
|
dc Decompressor
|
||||||
|
bs backoffStrategy
|
||||||
|
balancer Balancer
|
||||||
|
block bool
|
||||||
|
insecure bool
|
||||||
|
timeout time.Duration
|
||||||
|
copts transport.ConnectOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// DialOption configures how we set up the connection.
|
||||||
|
type DialOption func(*dialOptions)
|
||||||
|
|
||||||
|
// WithCodec returns a DialOption which sets a codec for message marshaling and unmarshaling.
|
||||||
|
func WithCodec(c Codec) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.codec = c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithCompressor returns a DialOption which sets a CompressorGenerator for generating message
|
||||||
|
// compressor.
|
||||||
|
func WithCompressor(cp Compressor) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.cp = cp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithDecompressor returns a DialOption which sets a DecompressorGenerator for generating
|
||||||
|
// message decompressor.
|
||||||
|
func WithDecompressor(dc Decompressor) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.dc = dc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBalancer returns a DialOption which sets a load balancer.
|
||||||
|
func WithBalancer(b Balancer) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.balancer = b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBackoffMaxDelay configures the dialer to use the provided maximum delay
|
||||||
|
// when backing off after failed connection attempts.
|
||||||
|
func WithBackoffMaxDelay(md time.Duration) DialOption {
|
||||||
|
return WithBackoffConfig(BackoffConfig{MaxDelay: md})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBackoffConfig configures the dialer to use the provided backoff
|
||||||
|
// parameters after connection failures.
|
||||||
|
//
|
||||||
|
// Use WithBackoffMaxDelay until more parameters on BackoffConfig are opened up
|
||||||
|
// for use.
|
||||||
|
func WithBackoffConfig(b BackoffConfig) DialOption {
|
||||||
|
// Set defaults to ensure that provided BackoffConfig is valid and
|
||||||
|
// unexported fields get default values.
|
||||||
|
setDefaults(&b)
|
||||||
|
return withBackoff(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// withBackoff sets the backoff strategy used for retries after a
|
||||||
|
// failed connection attempt.
|
||||||
|
//
|
||||||
|
// This can be exported if arbitrary backoff strategies are allowed by gRPC.
|
||||||
|
func withBackoff(bs backoffStrategy) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.bs = bs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBlock returns a DialOption which makes caller of Dial blocks until the underlying
|
||||||
|
// connection is up. Without this, Dial returns immediately and connecting the server
|
||||||
|
// happens in background.
|
||||||
|
func WithBlock() DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.block = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithInsecure returns a DialOption which disables transport security for this ClientConn.
|
||||||
|
// Note that transport security is required unless WithInsecure is set.
|
||||||
|
func WithInsecure() DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.insecure = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithTransportCredentials returns a DialOption which configures a
|
||||||
|
// connection level security credentials (e.g., TLS/SSL).
|
||||||
|
func WithTransportCredentials(creds credentials.TransportCredentials) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.copts.TransportCredentials = creds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithPerRPCCredentials returns a DialOption which sets
|
||||||
|
// credentials which will place auth state on each outbound RPC.
|
||||||
|
func WithPerRPCCredentials(creds credentials.PerRPCCredentials) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.copts.PerRPCCredentials = append(o.copts.PerRPCCredentials, creds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithTimeout returns a DialOption that configures a timeout for dialing a ClientConn
|
||||||
|
// initially. This is valid if and only if WithBlock() is present.
|
||||||
|
func WithTimeout(d time.Duration) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.timeout = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithDialer returns a DialOption that specifies a function to use for dialing network addresses.
|
||||||
|
func WithDialer(f func(string, time.Duration) (net.Conn, error)) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.copts.Dialer = func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
|
return f(addr, deadline.Sub(time.Now()))
|
||||||
|
}
|
||||||
|
return f(addr, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithUserAgent returns a DialOption that specifies a user agent string for all the RPCs.
|
||||||
|
func WithUserAgent(s string) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.copts.UserAgent = s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithUnaryInterceptor returns a DialOption that specifies the interceptor for unary RPCs.
|
||||||
|
func WithUnaryInterceptor(f UnaryClientInterceptor) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.unaryInt = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithStreamInterceptor returns a DialOption that specifies the interceptor for streaming RPCs.
|
||||||
|
func WithStreamInterceptor(f StreamClientInterceptor) DialOption {
|
||||||
|
return func(o *dialOptions) {
|
||||||
|
o.streamInt = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dial creates a client connection to the given target.
|
||||||
|
func Dial(target string, opts ...DialOption) (*ClientConn, error) {
|
||||||
|
return DialContext(context.Background(), target, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DialContext creates a client connection to the given target. ctx can be used to
|
||||||
|
// cancel or expire the pending connecting. Once this function returns, the
|
||||||
|
// cancellation and expiration of ctx will be noop. Users should call ClientConn.Close
|
||||||
|
// to terminate all the pending operations after this function returns.
|
||||||
|
// This is the EXPERIMENTAL API.
|
||||||
|
func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) {
|
||||||
|
cc := &ClientConn{
|
||||||
|
target: target,
|
||||||
|
conns: make(map[Address]*addrConn),
|
||||||
|
}
|
||||||
|
cc.ctx, cc.cancel = context.WithCancel(context.Background())
|
||||||
|
defer func() {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
conn, err = nil, ctx.Err()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
cc.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(&cc.dopts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set defaults.
|
||||||
|
if cc.dopts.codec == nil {
|
||||||
|
cc.dopts.codec = protoCodec{}
|
||||||
|
}
|
||||||
|
if cc.dopts.bs == nil {
|
||||||
|
cc.dopts.bs = DefaultBackoffConfig
|
||||||
|
}
|
||||||
|
creds := cc.dopts.copts.TransportCredentials
|
||||||
|
if creds != nil && creds.Info().ServerName != "" {
|
||||||
|
cc.authority = creds.Info().ServerName
|
||||||
|
} else {
|
||||||
|
colonPos := strings.LastIndex(target, ":")
|
||||||
|
if colonPos == -1 {
|
||||||
|
colonPos = len(target)
|
||||||
|
}
|
||||||
|
cc.authority = target[:colonPos]
|
||||||
|
}
|
||||||
|
var ok bool
|
||||||
|
waitC := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
var addrs []Address
|
||||||
|
if cc.dopts.balancer == nil {
|
||||||
|
// Connect to target directly if balancer is nil.
|
||||||
|
addrs = append(addrs, Address{Addr: target})
|
||||||
|
} else {
|
||||||
|
var credsClone credentials.TransportCredentials
|
||||||
|
if creds != nil {
|
||||||
|
credsClone = creds.Clone()
|
||||||
|
}
|
||||||
|
config := BalancerConfig{
|
||||||
|
DialCreds: credsClone,
|
||||||
|
}
|
||||||
|
if err := cc.dopts.balancer.Start(target, config); err != nil {
|
||||||
|
waitC <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ch := cc.dopts.balancer.Notify()
|
||||||
|
if ch == nil {
|
||||||
|
// There is no name resolver installed.
|
||||||
|
addrs = append(addrs, Address{Addr: target})
|
||||||
|
} else {
|
||||||
|
addrs, ok = <-ch
|
||||||
|
if !ok || len(addrs) == 0 {
|
||||||
|
waitC <- errNoAddr
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, a := range addrs {
|
||||||
|
if err := cc.resetAddrConn(a, false, nil); err != nil {
|
||||||
|
waitC <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(waitC)
|
||||||
|
}()
|
||||||
|
var timeoutCh <-chan time.Time
|
||||||
|
if cc.dopts.timeout > 0 {
|
||||||
|
timeoutCh = time.After(cc.dopts.timeout)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, ctx.Err()
|
||||||
|
case err := <-waitC:
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
case <-timeoutCh:
|
||||||
|
return nil, ErrClientConnTimeout
|
||||||
|
}
|
||||||
|
// If balancer is nil or balancer.Notify() is nil, ok will be false here.
|
||||||
|
// The lbWatcher goroutine will not be created.
|
||||||
|
if ok {
|
||||||
|
go cc.lbWatcher()
|
||||||
|
}
|
||||||
|
return cc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConnectivityState indicates the state of a client connection.
|
||||||
|
type ConnectivityState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Idle indicates the ClientConn is idle.
|
||||||
|
Idle ConnectivityState = iota
|
||||||
|
// Connecting indicates the ClienConn is connecting.
|
||||||
|
Connecting
|
||||||
|
// Ready indicates the ClientConn is ready for work.
|
||||||
|
Ready
|
||||||
|
// TransientFailure indicates the ClientConn has seen a failure but expects to recover.
|
||||||
|
TransientFailure
|
||||||
|
// Shutdown indicates the ClientConn has started shutting down.
|
||||||
|
Shutdown
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s ConnectivityState) String() string {
|
||||||
|
switch s {
|
||||||
|
case Idle:
|
||||||
|
return "IDLE"
|
||||||
|
case Connecting:
|
||||||
|
return "CONNECTING"
|
||||||
|
case Ready:
|
||||||
|
return "READY"
|
||||||
|
case TransientFailure:
|
||||||
|
return "TRANSIENT_FAILURE"
|
||||||
|
case Shutdown:
|
||||||
|
return "SHUTDOWN"
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unknown connectivity state: %d", s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientConn represents a client connection to an RPC server.
|
||||||
|
type ClientConn struct {
|
||||||
|
ctx context.Context
|
||||||
|
cancel context.CancelFunc
|
||||||
|
|
||||||
|
target string
|
||||||
|
authority string
|
||||||
|
dopts dialOptions
|
||||||
|
|
||||||
|
mu sync.RWMutex
|
||||||
|
conns map[Address]*addrConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *ClientConn) lbWatcher() {
|
||||||
|
for addrs := range cc.dopts.balancer.Notify() {
|
||||||
|
var (
|
||||||
|
add []Address // Addresses need to setup connections.
|
||||||
|
del []*addrConn // Connections need to tear down.
|
||||||
|
)
|
||||||
|
cc.mu.Lock()
|
||||||
|
for _, a := range addrs {
|
||||||
|
if _, ok := cc.conns[a]; !ok {
|
||||||
|
add = append(add, a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, c := range cc.conns {
|
||||||
|
var keep bool
|
||||||
|
for _, a := range addrs {
|
||||||
|
if k == a {
|
||||||
|
keep = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !keep {
|
||||||
|
del = append(del, c)
|
||||||
|
delete(cc.conns, c.addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc.mu.Unlock()
|
||||||
|
for _, a := range add {
|
||||||
|
cc.resetAddrConn(a, true, nil)
|
||||||
|
}
|
||||||
|
for _, c := range del {
|
||||||
|
c.tearDown(errConnDrain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// resetAddrConn creates an addrConn for addr and adds it to cc.conns.
|
||||||
|
// If there is an old addrConn for addr, it will be torn down, using tearDownErr as the reason.
|
||||||
|
// If tearDownErr is nil, errConnDrain will be used instead.
|
||||||
|
func (cc *ClientConn) resetAddrConn(addr Address, skipWait bool, tearDownErr error) error {
|
||||||
|
ac := &addrConn{
|
||||||
|
cc: cc,
|
||||||
|
addr: addr,
|
||||||
|
dopts: cc.dopts,
|
||||||
|
}
|
||||||
|
ac.ctx, ac.cancel = context.WithCancel(cc.ctx)
|
||||||
|
ac.stateCV = sync.NewCond(&ac.mu)
|
||||||
|
if EnableTracing {
|
||||||
|
ac.events = trace.NewEventLog("grpc.ClientConn", ac.addr.Addr)
|
||||||
|
}
|
||||||
|
if !ac.dopts.insecure {
|
||||||
|
if ac.dopts.copts.TransportCredentials == nil {
|
||||||
|
return errNoTransportSecurity
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ac.dopts.copts.TransportCredentials != nil {
|
||||||
|
return errCredentialsConflict
|
||||||
|
}
|
||||||
|
for _, cd := range ac.dopts.copts.PerRPCCredentials {
|
||||||
|
if cd.RequireTransportSecurity() {
|
||||||
|
return errTransportCredentialsMissing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Track ac in cc. This needs to be done before any getTransport(...) is called.
|
||||||
|
cc.mu.Lock()
|
||||||
|
if cc.conns == nil {
|
||||||
|
cc.mu.Unlock()
|
||||||
|
return ErrClientConnClosing
|
||||||
|
}
|
||||||
|
stale := cc.conns[ac.addr]
|
||||||
|
cc.conns[ac.addr] = ac
|
||||||
|
cc.mu.Unlock()
|
||||||
|
if stale != nil {
|
||||||
|
// There is an addrConn alive on ac.addr already. This could be due to
|
||||||
|
// 1) a buggy Balancer notifies duplicated Addresses;
|
||||||
|
// 2) goaway was received, a new ac will replace the old ac.
|
||||||
|
// The old ac should be deleted from cc.conns, but the
|
||||||
|
// underlying transport should drain rather than close.
|
||||||
|
if tearDownErr == nil {
|
||||||
|
// tearDownErr is nil if resetAddrConn is called by
|
||||||
|
// 1) Dial
|
||||||
|
// 2) lbWatcher
|
||||||
|
// In both cases, the stale ac should drain, not close.
|
||||||
|
stale.tearDown(errConnDrain)
|
||||||
|
} else {
|
||||||
|
stale.tearDown(tearDownErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// skipWait may overwrite the decision in ac.dopts.block.
|
||||||
|
if ac.dopts.block && !skipWait {
|
||||||
|
if err := ac.resetTransport(false); err != nil {
|
||||||
|
if err != errConnClosing {
|
||||||
|
// Tear down ac and delete it from cc.conns.
|
||||||
|
cc.mu.Lock()
|
||||||
|
delete(cc.conns, ac.addr)
|
||||||
|
cc.mu.Unlock()
|
||||||
|
ac.tearDown(err)
|
||||||
|
}
|
||||||
|
if e, ok := err.(transport.ConnectionError); ok && !e.Temporary() {
|
||||||
|
return e.Origin()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Start to monitor the error status of transport.
|
||||||
|
go ac.transportMonitor()
|
||||||
|
} else {
|
||||||
|
// Start a goroutine connecting to the server asynchronously.
|
||||||
|
go func() {
|
||||||
|
if err := ac.resetTransport(false); err != nil {
|
||||||
|
grpclog.Printf("Failed to dial %s: %v; please retry.", ac.addr.Addr, err)
|
||||||
|
if err != errConnClosing {
|
||||||
|
// Keep this ac in cc.conns, to get the reason it's torn down.
|
||||||
|
ac.tearDown(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ac.transportMonitor()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *ClientConn) getTransport(ctx context.Context, opts BalancerGetOptions) (transport.ClientTransport, func(), error) {
|
||||||
|
var (
|
||||||
|
ac *addrConn
|
||||||
|
ok bool
|
||||||
|
put func()
|
||||||
|
)
|
||||||
|
if cc.dopts.balancer == nil {
|
||||||
|
// If balancer is nil, there should be only one addrConn available.
|
||||||
|
cc.mu.RLock()
|
||||||
|
if cc.conns == nil {
|
||||||
|
cc.mu.RUnlock()
|
||||||
|
return nil, nil, toRPCErr(ErrClientConnClosing)
|
||||||
|
}
|
||||||
|
for _, ac = range cc.conns {
|
||||||
|
// Break after the first iteration to get the first addrConn.
|
||||||
|
ok = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
cc.mu.RUnlock()
|
||||||
|
} else {
|
||||||
|
var (
|
||||||
|
addr Address
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
addr, put, err = cc.dopts.balancer.Get(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, toRPCErr(err)
|
||||||
|
}
|
||||||
|
cc.mu.RLock()
|
||||||
|
if cc.conns == nil {
|
||||||
|
cc.mu.RUnlock()
|
||||||
|
return nil, nil, toRPCErr(ErrClientConnClosing)
|
||||||
|
}
|
||||||
|
ac, ok = cc.conns[addr]
|
||||||
|
cc.mu.RUnlock()
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
if put != nil {
|
||||||
|
put()
|
||||||
|
}
|
||||||
|
return nil, nil, errConnClosing
|
||||||
|
}
|
||||||
|
t, err := ac.wait(ctx, cc.dopts.balancer != nil, !opts.BlockingWait)
|
||||||
|
if err != nil {
|
||||||
|
if put != nil {
|
||||||
|
put()
|
||||||
|
}
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
return t, put, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close tears down the ClientConn and all underlying connections.
|
||||||
|
func (cc *ClientConn) Close() error {
|
||||||
|
cc.cancel()
|
||||||
|
|
||||||
|
cc.mu.Lock()
|
||||||
|
if cc.conns == nil {
|
||||||
|
cc.mu.Unlock()
|
||||||
|
return ErrClientConnClosing
|
||||||
|
}
|
||||||
|
conns := cc.conns
|
||||||
|
cc.conns = nil
|
||||||
|
cc.mu.Unlock()
|
||||||
|
if cc.dopts.balancer != nil {
|
||||||
|
cc.dopts.balancer.Close()
|
||||||
|
}
|
||||||
|
for _, ac := range conns {
|
||||||
|
ac.tearDown(ErrClientConnClosing)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// addrConn is a network connection to a given address.
|
||||||
|
type addrConn struct {
|
||||||
|
ctx context.Context
|
||||||
|
cancel context.CancelFunc
|
||||||
|
|
||||||
|
cc *ClientConn
|
||||||
|
addr Address
|
||||||
|
dopts dialOptions
|
||||||
|
events trace.EventLog
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
|
state ConnectivityState
|
||||||
|
stateCV *sync.Cond
|
||||||
|
down func(error) // the handler called when a connection is down.
|
||||||
|
// ready is closed and becomes nil when a new transport is up or failed
|
||||||
|
// due to timeout.
|
||||||
|
ready chan struct{}
|
||||||
|
transport transport.ClientTransport
|
||||||
|
|
||||||
|
// The reason this addrConn is torn down.
|
||||||
|
tearDownErr error
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf records an event in ac's event log, unless ac has been closed.
|
||||||
|
// REQUIRES ac.mu is held.
|
||||||
|
func (ac *addrConn) printf(format string, a ...interface{}) {
|
||||||
|
if ac.events != nil {
|
||||||
|
ac.events.Printf(format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// errorf records an error in ac's event log, unless ac has been closed.
|
||||||
|
// REQUIRES ac.mu is held.
|
||||||
|
func (ac *addrConn) errorf(format string, a ...interface{}) {
|
||||||
|
if ac.events != nil {
|
||||||
|
ac.events.Errorf(format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getState returns the connectivity state of the Conn
|
||||||
|
func (ac *addrConn) getState() ConnectivityState {
|
||||||
|
ac.mu.Lock()
|
||||||
|
defer ac.mu.Unlock()
|
||||||
|
return ac.state
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitForStateChange blocks until the state changes to something other than the sourceState.
|
||||||
|
func (ac *addrConn) waitForStateChange(ctx context.Context, sourceState ConnectivityState) (ConnectivityState, error) {
|
||||||
|
ac.mu.Lock()
|
||||||
|
defer ac.mu.Unlock()
|
||||||
|
if sourceState != ac.state {
|
||||||
|
return ac.state, nil
|
||||||
|
}
|
||||||
|
done := make(chan struct{})
|
||||||
|
var err error
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
ac.mu.Lock()
|
||||||
|
err = ctx.Err()
|
||||||
|
ac.stateCV.Broadcast()
|
||||||
|
ac.mu.Unlock()
|
||||||
|
case <-done:
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
defer close(done)
|
||||||
|
for sourceState == ac.state {
|
||||||
|
ac.stateCV.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return ac.state, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ac.state, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac *addrConn) resetTransport(closeTransport bool) error {
|
||||||
|
for retries := 0; ; retries++ {
|
||||||
|
ac.mu.Lock()
|
||||||
|
ac.printf("connecting")
|
||||||
|
if ac.state == Shutdown {
|
||||||
|
// ac.tearDown(...) has been invoked.
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return errConnClosing
|
||||||
|
}
|
||||||
|
if ac.down != nil {
|
||||||
|
ac.down(downErrorf(false, true, "%v", errNetworkIO))
|
||||||
|
ac.down = nil
|
||||||
|
}
|
||||||
|
ac.state = Connecting
|
||||||
|
ac.stateCV.Broadcast()
|
||||||
|
t := ac.transport
|
||||||
|
ac.mu.Unlock()
|
||||||
|
if closeTransport && t != nil {
|
||||||
|
t.Close()
|
||||||
|
}
|
||||||
|
sleepTime := ac.dopts.bs.backoff(retries)
|
||||||
|
timeout := minConnectTimeout
|
||||||
|
if timeout < sleepTime {
|
||||||
|
timeout = sleepTime
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(ac.ctx, timeout)
|
||||||
|
connectTime := time.Now()
|
||||||
|
newTransport, err := transport.NewClientTransport(ctx, ac.addr.Addr, ac.dopts.copts)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
if e, ok := err.(transport.ConnectionError); ok && !e.Temporary() {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
grpclog.Printf("grpc: addrConn.resetTransport failed to create client transport: %v; Reconnecting to %v", err, ac.addr)
|
||||||
|
ac.mu.Lock()
|
||||||
|
if ac.state == Shutdown {
|
||||||
|
// ac.tearDown(...) has been invoked.
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return errConnClosing
|
||||||
|
}
|
||||||
|
ac.errorf("transient failure: %v", err)
|
||||||
|
ac.state = TransientFailure
|
||||||
|
ac.stateCV.Broadcast()
|
||||||
|
if ac.ready != nil {
|
||||||
|
close(ac.ready)
|
||||||
|
ac.ready = nil
|
||||||
|
}
|
||||||
|
ac.mu.Unlock()
|
||||||
|
closeTransport = false
|
||||||
|
select {
|
||||||
|
case <-time.After(sleepTime - time.Since(connectTime)):
|
||||||
|
case <-ac.ctx.Done():
|
||||||
|
return ac.ctx.Err()
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ac.mu.Lock()
|
||||||
|
ac.printf("ready")
|
||||||
|
if ac.state == Shutdown {
|
||||||
|
// ac.tearDown(...) has been invoked.
|
||||||
|
ac.mu.Unlock()
|
||||||
|
newTransport.Close()
|
||||||
|
return errConnClosing
|
||||||
|
}
|
||||||
|
ac.state = Ready
|
||||||
|
ac.stateCV.Broadcast()
|
||||||
|
ac.transport = newTransport
|
||||||
|
if ac.ready != nil {
|
||||||
|
close(ac.ready)
|
||||||
|
ac.ready = nil
|
||||||
|
}
|
||||||
|
if ac.cc.dopts.balancer != nil {
|
||||||
|
ac.down = ac.cc.dopts.balancer.Up(ac.addr)
|
||||||
|
}
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run in a goroutine to track the error in transport and create the
|
||||||
|
// new transport if an error happens. It returns when the channel is closing.
|
||||||
|
func (ac *addrConn) transportMonitor() {
|
||||||
|
for {
|
||||||
|
ac.mu.Lock()
|
||||||
|
t := ac.transport
|
||||||
|
ac.mu.Unlock()
|
||||||
|
select {
|
||||||
|
// This is needed to detect the teardown when
|
||||||
|
// the addrConn is idle (i.e., no RPC in flight).
|
||||||
|
case <-ac.ctx.Done():
|
||||||
|
select {
|
||||||
|
case <-t.Error():
|
||||||
|
t.Close()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case <-t.GoAway():
|
||||||
|
// If GoAway happens without any network I/O error, ac is closed without shutting down the
|
||||||
|
// underlying transport (the transport will be closed when all the pending RPCs finished or
|
||||||
|
// failed.).
|
||||||
|
// If GoAway and some network I/O error happen concurrently, ac and its underlying transport
|
||||||
|
// are closed.
|
||||||
|
// In both cases, a new ac is created.
|
||||||
|
select {
|
||||||
|
case <-t.Error():
|
||||||
|
ac.cc.resetAddrConn(ac.addr, true, errNetworkIO)
|
||||||
|
default:
|
||||||
|
ac.cc.resetAddrConn(ac.addr, true, errConnDrain)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case <-t.Error():
|
||||||
|
select {
|
||||||
|
case <-ac.ctx.Done():
|
||||||
|
t.Close()
|
||||||
|
return
|
||||||
|
case <-t.GoAway():
|
||||||
|
ac.cc.resetAddrConn(ac.addr, true, errNetworkIO)
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
ac.mu.Lock()
|
||||||
|
if ac.state == Shutdown {
|
||||||
|
// ac has been shutdown.
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ac.state = TransientFailure
|
||||||
|
ac.stateCV.Broadcast()
|
||||||
|
ac.mu.Unlock()
|
||||||
|
if err := ac.resetTransport(true); err != nil {
|
||||||
|
ac.mu.Lock()
|
||||||
|
ac.printf("transport exiting: %v", err)
|
||||||
|
ac.mu.Unlock()
|
||||||
|
grpclog.Printf("grpc: addrConn.transportMonitor exits due to: %v", err)
|
||||||
|
if err != errConnClosing {
|
||||||
|
// Keep this ac in cc.conns, to get the reason it's torn down.
|
||||||
|
ac.tearDown(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait blocks until i) the new transport is up or ii) ctx is done or iii) ac is closed or
|
||||||
|
// iv) transport is in TransientFailure and there's no balancer/failfast is true.
|
||||||
|
func (ac *addrConn) wait(ctx context.Context, hasBalancer, failfast bool) (transport.ClientTransport, error) {
|
||||||
|
for {
|
||||||
|
ac.mu.Lock()
|
||||||
|
switch {
|
||||||
|
case ac.state == Shutdown:
|
||||||
|
if failfast || !hasBalancer {
|
||||||
|
// RPC is failfast or balancer is nil. This RPC should fail with ac.tearDownErr.
|
||||||
|
err := ac.tearDownErr
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return nil, errConnClosing
|
||||||
|
case ac.state == Ready:
|
||||||
|
ct := ac.transport
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return ct, nil
|
||||||
|
case ac.state == TransientFailure:
|
||||||
|
if failfast || hasBalancer {
|
||||||
|
ac.mu.Unlock()
|
||||||
|
return nil, errConnUnavailable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ready := ac.ready
|
||||||
|
if ready == nil {
|
||||||
|
ready = make(chan struct{})
|
||||||
|
ac.ready = ready
|
||||||
|
}
|
||||||
|
ac.mu.Unlock()
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, toRPCErr(ctx.Err())
|
||||||
|
// Wait until the new transport is ready or failed.
|
||||||
|
case <-ready:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tearDown starts to tear down the addrConn.
|
||||||
|
// TODO(zhaoq): Make this synchronous to avoid unbounded memory consumption in
|
||||||
|
// some edge cases (e.g., the caller opens and closes many addrConn's in a
|
||||||
|
// tight loop.
|
||||||
|
// tearDown doesn't remove ac from ac.cc.conns.
|
||||||
|
func (ac *addrConn) tearDown(err error) {
|
||||||
|
ac.cancel()
|
||||||
|
|
||||||
|
ac.mu.Lock()
|
||||||
|
defer ac.mu.Unlock()
|
||||||
|
if ac.down != nil {
|
||||||
|
ac.down(downErrorf(false, false, "%v", err))
|
||||||
|
ac.down = nil
|
||||||
|
}
|
||||||
|
if err == errConnDrain && ac.transport != nil {
|
||||||
|
// GracefulClose(...) may be executed multiple times when
|
||||||
|
// i) receiving multiple GoAway frames from the server; or
|
||||||
|
// ii) there are concurrent name resolver/Balancer triggered
|
||||||
|
// address removal and GoAway.
|
||||||
|
ac.transport.GracefulClose()
|
||||||
|
}
|
||||||
|
if ac.state == Shutdown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ac.state = Shutdown
|
||||||
|
ac.tearDownErr = err
|
||||||
|
ac.stateCV.Broadcast()
|
||||||
|
if ac.events != nil {
|
||||||
|
ac.events.Finish()
|
||||||
|
ac.events = nil
|
||||||
|
}
|
||||||
|
if ac.ready != nil {
|
||||||
|
close(ac.ready)
|
||||||
|
ac.ready = nil
|
||||||
|
}
|
||||||
|
if ac.transport != nil && err != errConnDrain {
|
||||||
|
ac.transport.Close()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
190
vendor/google.golang.org/grpc/clientconn_test.go
generated
vendored
Normal file
190
vendor/google.golang.org/grpc/clientconn_test.go
generated
vendored
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/credentials/oauth"
|
||||||
|
)
|
||||||
|
|
||||||
|
const tlsDir = "testdata/"
|
||||||
|
|
||||||
|
func TestDialTimeout(t *testing.T) {
|
||||||
|
conn, err := Dial("Non-Existent.Server:80", WithTimeout(time.Millisecond), WithBlock(), WithInsecure())
|
||||||
|
if err == nil {
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
if err != ErrClientConnTimeout {
|
||||||
|
t.Fatalf("Dial(_, _) = %v, %v, want %v", conn, err, ErrClientConnTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTLSDialTimeout(t *testing.T) {
|
||||||
|
creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create credentials %v", err)
|
||||||
|
}
|
||||||
|
conn, err := Dial("Non-Existent.Server:80", WithTransportCredentials(creds), WithTimeout(time.Millisecond), WithBlock())
|
||||||
|
if err == nil {
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
if err != ErrClientConnTimeout {
|
||||||
|
t.Fatalf("Dial(_, _) = %v, %v, want %v", conn, err, ErrClientConnTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTLSServerNameOverwrite(t *testing.T) {
|
||||||
|
overwriteServerName := "over.write.server.name"
|
||||||
|
creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", overwriteServerName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create credentials %v", err)
|
||||||
|
}
|
||||||
|
conn, err := Dial("Non-Existent.Server:80", WithTransportCredentials(creds))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Dial(_, _) = _, %v, want _, <nil>", err)
|
||||||
|
}
|
||||||
|
conn.Close()
|
||||||
|
if conn.authority != overwriteServerName {
|
||||||
|
t.Fatalf("%v.authority = %v, want %v", conn, conn.authority, overwriteServerName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDialContextCancel(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
if _, err := DialContext(ctx, "Non-Existent.Server:80", WithBlock(), WithInsecure()); err != context.Canceled {
|
||||||
|
t.Fatalf("DialContext(%v, _) = _, %v, want _, %v", ctx, err, context.Canceled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// blockingBalancer mimics the behavior of balancers whose initialization takes a long time.
|
||||||
|
// In this test, reading from blockingBalancer.Notify() blocks forever.
|
||||||
|
type blockingBalancer struct {
|
||||||
|
ch chan []Address
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBlockingBalancer() Balancer {
|
||||||
|
return &blockingBalancer{ch: make(chan []Address)}
|
||||||
|
}
|
||||||
|
func (b *blockingBalancer) Start(target string, config BalancerConfig) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (b *blockingBalancer) Up(addr Address) func(error) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (b *blockingBalancer) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) {
|
||||||
|
return Address{}, nil, nil
|
||||||
|
}
|
||||||
|
func (b *blockingBalancer) Notify() <-chan []Address {
|
||||||
|
return b.ch
|
||||||
|
}
|
||||||
|
func (b *blockingBalancer) Close() error {
|
||||||
|
close(b.ch)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDialWithBlockingBalancer(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
dialDone := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
DialContext(ctx, "Non-Existent.Server:80", WithBlock(), WithInsecure(), WithBalancer(newBlockingBalancer()))
|
||||||
|
close(dialDone)
|
||||||
|
}()
|
||||||
|
cancel()
|
||||||
|
<-dialDone
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCredentialsMisuse(t *testing.T) {
|
||||||
|
tlsCreds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create authenticator %v", err)
|
||||||
|
}
|
||||||
|
// Two conflicting credential configurations
|
||||||
|
if _, err := Dial("Non-Existent.Server:80", WithTransportCredentials(tlsCreds), WithBlock(), WithInsecure()); err != errCredentialsConflict {
|
||||||
|
t.Fatalf("Dial(_, _) = _, %v, want _, %v", err, errCredentialsConflict)
|
||||||
|
}
|
||||||
|
rpcCreds, err := oauth.NewJWTAccessFromKey(nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create credentials %v", err)
|
||||||
|
}
|
||||||
|
// security info on insecure connection
|
||||||
|
if _, err := Dial("Non-Existent.Server:80", WithPerRPCCredentials(rpcCreds), WithBlock(), WithInsecure()); err != errTransportCredentialsMissing {
|
||||||
|
t.Fatalf("Dial(_, _) = _, %v, want _, %v", err, errTransportCredentialsMissing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWithBackoffConfigDefault(t *testing.T) {
|
||||||
|
testBackoffConfigSet(t, &DefaultBackoffConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWithBackoffConfig(t *testing.T) {
|
||||||
|
b := BackoffConfig{MaxDelay: DefaultBackoffConfig.MaxDelay / 2}
|
||||||
|
expected := b
|
||||||
|
setDefaults(&expected) // defaults should be set
|
||||||
|
testBackoffConfigSet(t, &expected, WithBackoffConfig(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWithBackoffMaxDelay(t *testing.T) {
|
||||||
|
md := DefaultBackoffConfig.MaxDelay / 2
|
||||||
|
expected := BackoffConfig{MaxDelay: md}
|
||||||
|
setDefaults(&expected)
|
||||||
|
testBackoffConfigSet(t, &expected, WithBackoffMaxDelay(md))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBackoffConfigSet(t *testing.T, expected *BackoffConfig, opts ...DialOption) {
|
||||||
|
opts = append(opts, WithInsecure())
|
||||||
|
conn, err := Dial("foo:80", opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error dialing connection: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if conn.dopts.bs == nil {
|
||||||
|
t.Fatalf("backoff config not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
actual, ok := conn.dopts.bs.(BackoffConfig)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("unexpected type of backoff config: %#v", conn.dopts.bs)
|
||||||
|
}
|
||||||
|
|
||||||
|
if actual != *expected {
|
||||||
|
t.Fatalf("unexpected backoff config on connection: %v, want %v", actual, expected)
|
||||||
|
}
|
||||||
|
conn.Close()
|
||||||
|
}
|
17
vendor/google.golang.org/grpc/codegen.sh
generated
vendored
Executable file
17
vendor/google.golang.org/grpc/codegen.sh
generated
vendored
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script serves as an example to demonstrate how to generate the gRPC-Go
|
||||||
|
# interface and the related messages from .proto file.
|
||||||
|
#
|
||||||
|
# It assumes the installation of i) Google proto buffer compiler at
|
||||||
|
# https://github.com/google/protobuf (after v2.6.1) and ii) the Go codegen
|
||||||
|
# plugin at https://github.com/golang/protobuf (after 2015-02-20). If you have
|
||||||
|
# not, please install them first.
|
||||||
|
#
|
||||||
|
# We recommend running this script at $GOPATH/src.
|
||||||
|
#
|
||||||
|
# If this is not what you need, feel free to make your own scripts. Again, this
|
||||||
|
# script is for demonstration purpose.
|
||||||
|
#
|
||||||
|
proto=$1
|
||||||
|
protoc --go_out=plugins=grpc:. $proto
|
16
vendor/google.golang.org/grpc/codes/code_string.go
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/codes/code_string.go
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// generated by stringer -type=Code; DO NOT EDIT
|
||||||
|
|
||||||
|
package codes
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
const _Code_name = "OKCanceledUnknownInvalidArgumentDeadlineExceededNotFoundAlreadyExistsPermissionDeniedResourceExhaustedFailedPreconditionAbortedOutOfRangeUnimplementedInternalUnavailableDataLossUnauthenticated"
|
||||||
|
|
||||||
|
var _Code_index = [...]uint8{0, 2, 10, 17, 32, 48, 56, 69, 85, 102, 120, 127, 137, 150, 158, 169, 177, 192}
|
||||||
|
|
||||||
|
func (i Code) String() string {
|
||||||
|
if i+1 >= Code(len(_Code_index)) {
|
||||||
|
return fmt.Sprintf("Code(%d)", i)
|
||||||
|
}
|
||||||
|
return _Code_name[_Code_index[i]:_Code_index[i+1]]
|
||||||
|
}
|
159
vendor/google.golang.org/grpc/codes/codes.go
generated
vendored
Normal file
159
vendor/google.golang.org/grpc/codes/codes.go
generated
vendored
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package codes defines the canonical error codes used by gRPC. It is
|
||||||
|
// consistent across various languages.
|
||||||
|
package codes // import "google.golang.org/grpc/codes"
|
||||||
|
|
||||||
|
// A Code is an unsigned 32-bit error code as defined in the gRPC spec.
|
||||||
|
type Code uint32
|
||||||
|
|
||||||
|
//go:generate stringer -type=Code
|
||||||
|
|
||||||
|
const (
|
||||||
|
// OK is returned on success.
|
||||||
|
OK Code = 0
|
||||||
|
|
||||||
|
// Canceled indicates the operation was cancelled (typically by the caller).
|
||||||
|
Canceled Code = 1
|
||||||
|
|
||||||
|
// Unknown error. An example of where this error may be returned is
|
||||||
|
// if a Status value received from another address space belongs to
|
||||||
|
// an error-space that is not known in this address space. Also
|
||||||
|
// errors raised by APIs that do not return enough error information
|
||||||
|
// may be converted to this error.
|
||||||
|
Unknown Code = 2
|
||||||
|
|
||||||
|
// InvalidArgument indicates client specified an invalid argument.
|
||||||
|
// Note that this differs from FailedPrecondition. It indicates arguments
|
||||||
|
// that are problematic regardless of the state of the system
|
||||||
|
// (e.g., a malformed file name).
|
||||||
|
InvalidArgument Code = 3
|
||||||
|
|
||||||
|
// DeadlineExceeded means operation expired before completion.
|
||||||
|
// For operations that change the state of the system, this error may be
|
||||||
|
// returned even if the operation has completed successfully. For
|
||||||
|
// example, a successful response from a server could have been delayed
|
||||||
|
// long enough for the deadline to expire.
|
||||||
|
DeadlineExceeded Code = 4
|
||||||
|
|
||||||
|
// NotFound means some requested entity (e.g., file or directory) was
|
||||||
|
// not found.
|
||||||
|
NotFound Code = 5
|
||||||
|
|
||||||
|
// AlreadyExists means an attempt to create an entity failed because one
|
||||||
|
// already exists.
|
||||||
|
AlreadyExists Code = 6
|
||||||
|
|
||||||
|
// PermissionDenied indicates the caller does not have permission to
|
||||||
|
// execute the specified operation. It must not be used for rejections
|
||||||
|
// caused by exhausting some resource (use ResourceExhausted
|
||||||
|
// instead for those errors). It must not be
|
||||||
|
// used if the caller cannot be identified (use Unauthenticated
|
||||||
|
// instead for those errors).
|
||||||
|
PermissionDenied Code = 7
|
||||||
|
|
||||||
|
// Unauthenticated indicates the request does not have valid
|
||||||
|
// authentication credentials for the operation.
|
||||||
|
Unauthenticated Code = 16
|
||||||
|
|
||||||
|
// ResourceExhausted indicates some resource has been exhausted, perhaps
|
||||||
|
// a per-user quota, or perhaps the entire file system is out of space.
|
||||||
|
ResourceExhausted Code = 8
|
||||||
|
|
||||||
|
// FailedPrecondition indicates operation was rejected because the
|
||||||
|
// system is not in a state required for the operation's execution.
|
||||||
|
// For example, directory to be deleted may be non-empty, an rmdir
|
||||||
|
// operation is applied to a non-directory, etc.
|
||||||
|
//
|
||||||
|
// A litmus test that may help a service implementor in deciding
|
||||||
|
// between FailedPrecondition, Aborted, and Unavailable:
|
||||||
|
// (a) Use Unavailable if the client can retry just the failing call.
|
||||||
|
// (b) Use Aborted if the client should retry at a higher-level
|
||||||
|
// (e.g., restarting a read-modify-write sequence).
|
||||||
|
// (c) Use FailedPrecondition if the client should not retry until
|
||||||
|
// the system state has been explicitly fixed. E.g., if an "rmdir"
|
||||||
|
// fails because the directory is non-empty, FailedPrecondition
|
||||||
|
// should be returned since the client should not retry unless
|
||||||
|
// they have first fixed up the directory by deleting files from it.
|
||||||
|
// (d) Use FailedPrecondition if the client performs conditional
|
||||||
|
// REST Get/Update/Delete on a resource and the resource on the
|
||||||
|
// server does not match the condition. E.g., conflicting
|
||||||
|
// read-modify-write on the same resource.
|
||||||
|
FailedPrecondition Code = 9
|
||||||
|
|
||||||
|
// Aborted indicates the operation was aborted, typically due to a
|
||||||
|
// concurrency issue like sequencer check failures, transaction aborts,
|
||||||
|
// etc.
|
||||||
|
//
|
||||||
|
// See litmus test above for deciding between FailedPrecondition,
|
||||||
|
// Aborted, and Unavailable.
|
||||||
|
Aborted Code = 10
|
||||||
|
|
||||||
|
// OutOfRange means operation was attempted past the valid range.
|
||||||
|
// E.g., seeking or reading past end of file.
|
||||||
|
//
|
||||||
|
// Unlike InvalidArgument, this error indicates a problem that may
|
||||||
|
// be fixed if the system state changes. For example, a 32-bit file
|
||||||
|
// system will generate InvalidArgument if asked to read at an
|
||||||
|
// offset that is not in the range [0,2^32-1], but it will generate
|
||||||
|
// OutOfRange if asked to read from an offset past the current
|
||||||
|
// file size.
|
||||||
|
//
|
||||||
|
// There is a fair bit of overlap between FailedPrecondition and
|
||||||
|
// OutOfRange. We recommend using OutOfRange (the more specific
|
||||||
|
// error) when it applies so that callers who are iterating through
|
||||||
|
// a space can easily look for an OutOfRange error to detect when
|
||||||
|
// they are done.
|
||||||
|
OutOfRange Code = 11
|
||||||
|
|
||||||
|
// Unimplemented indicates operation is not implemented or not
|
||||||
|
// supported/enabled in this service.
|
||||||
|
Unimplemented Code = 12
|
||||||
|
|
||||||
|
// Internal errors. Means some invariants expected by underlying
|
||||||
|
// system has been broken. If you see one of these errors,
|
||||||
|
// something is very broken.
|
||||||
|
Internal Code = 13
|
||||||
|
|
||||||
|
// Unavailable indicates the service is currently unavailable.
|
||||||
|
// This is a most likely a transient condition and may be corrected
|
||||||
|
// by retrying with a backoff.
|
||||||
|
//
|
||||||
|
// See litmus test above for deciding between FailedPrecondition,
|
||||||
|
// Aborted, and Unavailable.
|
||||||
|
Unavailable Code = 14
|
||||||
|
|
||||||
|
// DataLoss indicates unrecoverable data loss or corruption.
|
||||||
|
DataLoss Code = 15
|
||||||
|
)
|
47
vendor/google.golang.org/grpc/coverage.sh
generated
vendored
Executable file
47
vendor/google.golang.org/grpc/coverage.sh
generated
vendored
Executable file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
workdir=.cover
|
||||||
|
profile="$workdir/cover.out"
|
||||||
|
mode=set
|
||||||
|
end2endtest="google.golang.org/grpc/test"
|
||||||
|
|
||||||
|
generate_cover_data() {
|
||||||
|
rm -rf "$workdir"
|
||||||
|
mkdir "$workdir"
|
||||||
|
|
||||||
|
for pkg in "$@"; do
|
||||||
|
if [ $pkg == "google.golang.org/grpc" -o $pkg == "google.golang.org/grpc/transport" -o $pkg == "google.golang.org/grpc/metadata" -o $pkg == "google.golang.org/grpc/credentials" ]
|
||||||
|
then
|
||||||
|
f="$workdir/$(echo $pkg | tr / -)"
|
||||||
|
go test -covermode="$mode" -coverprofile="$f.cover" "$pkg"
|
||||||
|
go test -covermode="$mode" -coverpkg "$pkg" -coverprofile="$f.e2e.cover" "$end2endtest"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "mode: $mode" >"$profile"
|
||||||
|
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
|
||||||
|
}
|
||||||
|
|
||||||
|
show_cover_report() {
|
||||||
|
go tool cover -${1}="$profile"
|
||||||
|
}
|
||||||
|
|
||||||
|
push_to_coveralls() {
|
||||||
|
goveralls -coverprofile="$profile"
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_cover_data $(go list ./...)
|
||||||
|
show_cover_report func
|
||||||
|
case "$1" in
|
||||||
|
"")
|
||||||
|
;;
|
||||||
|
--html)
|
||||||
|
show_cover_report html ;;
|
||||||
|
--coveralls)
|
||||||
|
push_to_coveralls ;;
|
||||||
|
*)
|
||||||
|
echo >&2 "error: invalid option: $1" ;;
|
||||||
|
esac
|
||||||
|
rm -rf "$workdir"
|
232
vendor/google.golang.org/grpc/credentials/credentials.go
generated
vendored
Normal file
232
vendor/google.golang.org/grpc/credentials/credentials.go
generated
vendored
Normal file
|
@ -0,0 +1,232 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package credentials implements various credentials supported by gRPC library,
|
||||||
|
// which encapsulate all the state needed by a client to authenticate with a
|
||||||
|
// server and make various assertions, e.g., about the client's identity, role,
|
||||||
|
// or whether it is authorized to make a particular call.
|
||||||
|
package credentials // import "google.golang.org/grpc/credentials"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// alpnProtoStr are the specified application level protocols for gRPC.
|
||||||
|
alpnProtoStr = []string{"h2"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// PerRPCCredentials defines the common interface for the credentials which need to
|
||||||
|
// attach security information to every RPC (e.g., oauth2).
|
||||||
|
type PerRPCCredentials interface {
|
||||||
|
// GetRequestMetadata gets the current request metadata, refreshing
|
||||||
|
// tokens if required. This should be called by the transport layer on
|
||||||
|
// each request, and the data should be populated in headers or other
|
||||||
|
// context. uri is the URI of the entry point for the request. When
|
||||||
|
// supported by the underlying implementation, ctx can be used for
|
||||||
|
// timeout and cancellation.
|
||||||
|
// TODO(zhaoq): Define the set of the qualified keys instead of leaving
|
||||||
|
// it as an arbitrary string.
|
||||||
|
GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)
|
||||||
|
// RequireTransportSecurity indicates whether the credentials requires
|
||||||
|
// transport security.
|
||||||
|
RequireTransportSecurity() bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProtocolInfo provides information regarding the gRPC wire protocol version,
|
||||||
|
// security protocol, security protocol version in use, server name, etc.
|
||||||
|
type ProtocolInfo struct {
|
||||||
|
// ProtocolVersion is the gRPC wire protocol version.
|
||||||
|
ProtocolVersion string
|
||||||
|
// SecurityProtocol is the security protocol in use.
|
||||||
|
SecurityProtocol string
|
||||||
|
// SecurityVersion is the security protocol version.
|
||||||
|
SecurityVersion string
|
||||||
|
// ServerName is the user-configured server name.
|
||||||
|
ServerName string
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthInfo defines the common interface for the auth information the users are interested in.
|
||||||
|
type AuthInfo interface {
|
||||||
|
AuthType() string
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrConnDispatched indicates that rawConn has been dispatched out of gRPC
|
||||||
|
// and the caller should not close rawConn.
|
||||||
|
ErrConnDispatched = errors.New("credentials: rawConn is dispatched out of gRPC")
|
||||||
|
)
|
||||||
|
|
||||||
|
// TransportCredentials defines the common interface for all the live gRPC wire
|
||||||
|
// protocols and supported transport security protocols (e.g., TLS, SSL).
|
||||||
|
type TransportCredentials interface {
|
||||||
|
// ClientHandshake does the authentication handshake specified by the corresponding
|
||||||
|
// authentication protocol on rawConn for clients. It returns the authenticated
|
||||||
|
// connection and the corresponding auth information about the connection.
|
||||||
|
// Implementations must use the provided context to implement timely cancellation.
|
||||||
|
ClientHandshake(context.Context, string, net.Conn) (net.Conn, AuthInfo, error)
|
||||||
|
// ServerHandshake does the authentication handshake for servers. It returns
|
||||||
|
// the authenticated connection and the corresponding auth information about
|
||||||
|
// the connection.
|
||||||
|
ServerHandshake(net.Conn) (net.Conn, AuthInfo, error)
|
||||||
|
// Info provides the ProtocolInfo of this TransportCredentials.
|
||||||
|
Info() ProtocolInfo
|
||||||
|
// Clone makes a copy of this TransportCredentials.
|
||||||
|
Clone() TransportCredentials
|
||||||
|
// OverrideServerName overrides the server name used to verify the hostname on the returned certificates from the server.
|
||||||
|
// gRPC internals also use it to override the virtual hosting name if it is set.
|
||||||
|
// It must be called before dialing. Currently, this is only used by grpclb.
|
||||||
|
OverrideServerName(string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// TLSInfo contains the auth information for a TLS authenticated connection.
|
||||||
|
// It implements the AuthInfo interface.
|
||||||
|
type TLSInfo struct {
|
||||||
|
State tls.ConnectionState
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthType returns the type of TLSInfo as a string.
|
||||||
|
func (t TLSInfo) AuthType() string {
|
||||||
|
return "tls"
|
||||||
|
}
|
||||||
|
|
||||||
|
// tlsCreds is the credentials required for authenticating a connection using TLS.
|
||||||
|
type tlsCreds struct {
|
||||||
|
// TLS configuration
|
||||||
|
config *tls.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c tlsCreds) Info() ProtocolInfo {
|
||||||
|
return ProtocolInfo{
|
||||||
|
SecurityProtocol: "tls",
|
||||||
|
SecurityVersion: "1.2",
|
||||||
|
ServerName: c.config.ServerName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *tlsCreds) ClientHandshake(ctx context.Context, addr string, rawConn net.Conn) (_ net.Conn, _ AuthInfo, err error) {
|
||||||
|
// use local cfg to avoid clobbering ServerName if using multiple endpoints
|
||||||
|
cfg := cloneTLSConfig(c.config)
|
||||||
|
if cfg.ServerName == "" {
|
||||||
|
colonPos := strings.LastIndex(addr, ":")
|
||||||
|
if colonPos == -1 {
|
||||||
|
colonPos = len(addr)
|
||||||
|
}
|
||||||
|
cfg.ServerName = addr[:colonPos]
|
||||||
|
}
|
||||||
|
conn := tls.Client(rawConn, cfg)
|
||||||
|
errChannel := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
errChannel <- conn.Handshake()
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case err := <-errChannel:
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, nil, ctx.Err()
|
||||||
|
}
|
||||||
|
// TODO(zhaoq): Omit the auth info for client now. It is more for
|
||||||
|
// information than anything else.
|
||||||
|
return conn, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) {
|
||||||
|
conn := tls.Server(rawConn, c.config)
|
||||||
|
if err := conn.Handshake(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
return conn, TLSInfo{conn.ConnectionState()}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *tlsCreds) Clone() TransportCredentials {
|
||||||
|
return NewTLS(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *tlsCreds) OverrideServerName(serverNameOverride string) error {
|
||||||
|
c.config.ServerName = serverNameOverride
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTLS uses c to construct a TransportCredentials based on TLS.
|
||||||
|
func NewTLS(c *tls.Config) TransportCredentials {
|
||||||
|
tc := &tlsCreds{cloneTLSConfig(c)}
|
||||||
|
tc.config.NextProtos = alpnProtoStr
|
||||||
|
return tc
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientTLSFromCert constructs a TLS from the input certificate for client.
|
||||||
|
// serverNameOverride is for testing only. If set to a non empty string,
|
||||||
|
// it will override the virtual host name of authority (e.g. :authority header field) in requests.
|
||||||
|
func NewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string) TransportCredentials {
|
||||||
|
return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientTLSFromFile constructs a TLS from the input certificate file for client.
|
||||||
|
// serverNameOverride is for testing only. If set to a non empty string,
|
||||||
|
// it will override the virtual host name of authority (e.g. :authority header field) in requests.
|
||||||
|
func NewClientTLSFromFile(certFile, serverNameOverride string) (TransportCredentials, error) {
|
||||||
|
b, err := ioutil.ReadFile(certFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cp := x509.NewCertPool()
|
||||||
|
if !cp.AppendCertsFromPEM(b) {
|
||||||
|
return nil, fmt.Errorf("credentials: failed to append certificates")
|
||||||
|
}
|
||||||
|
return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServerTLSFromCert constructs a TLS from the input certificate for server.
|
||||||
|
func NewServerTLSFromCert(cert *tls.Certificate) TransportCredentials {
|
||||||
|
return NewTLS(&tls.Config{Certificates: []tls.Certificate{*cert}})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServerTLSFromFile constructs a TLS from the input certificate file and key
|
||||||
|
// file for server.
|
||||||
|
func NewServerTLSFromFile(certFile, keyFile string) (TransportCredentials, error) {
|
||||||
|
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewTLS(&tls.Config{Certificates: []tls.Certificate{cert}}), nil
|
||||||
|
}
|
61
vendor/google.golang.org/grpc/credentials/credentials_test.go
generated
vendored
Normal file
61
vendor/google.golang.org/grpc/credentials/credentials_test.go
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTLSOverrideServerName(t *testing.T) {
|
||||||
|
expectedServerName := "server.name"
|
||||||
|
c := NewTLS(nil)
|
||||||
|
c.OverrideServerName(expectedServerName)
|
||||||
|
if c.Info().ServerName != expectedServerName {
|
||||||
|
t.Fatalf("c.Info().ServerName = %v, want %v", c.Info().ServerName, expectedServerName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTLSClone(t *testing.T) {
|
||||||
|
expectedServerName := "server.name"
|
||||||
|
c := NewTLS(nil)
|
||||||
|
c.OverrideServerName(expectedServerName)
|
||||||
|
cc := c.Clone()
|
||||||
|
if cc.Info().ServerName != expectedServerName {
|
||||||
|
t.Fatalf("cc.Info().ServerName = %v, want %v", cc.Info().ServerName, expectedServerName)
|
||||||
|
}
|
||||||
|
cc.OverrideServerName("")
|
||||||
|
if c.Info().ServerName != expectedServerName {
|
||||||
|
t.Fatalf("Change in clone should not affect the original, c.Info().ServerName = %v, want %v", c.Info().ServerName, expectedServerName)
|
||||||
|
}
|
||||||
|
}
|
76
vendor/google.golang.org/grpc/credentials/credentials_util_go17.go
generated
vendored
Normal file
76
vendor/google.golang.org/grpc/credentials/credentials_util_go17.go
generated
vendored
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
// +build go1.7
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
)
|
||||||
|
|
||||||
|
// cloneTLSConfig returns a shallow clone of the exported
|
||||||
|
// fields of cfg, ignoring the unexported sync.Once, which
|
||||||
|
// contains a mutex and must not be copied.
|
||||||
|
//
|
||||||
|
// If cfg is nil, a new zero tls.Config is returned.
|
||||||
|
//
|
||||||
|
// TODO replace this function with official clone function.
|
||||||
|
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
|
||||||
|
if cfg == nil {
|
||||||
|
return &tls.Config{}
|
||||||
|
}
|
||||||
|
return &tls.Config{
|
||||||
|
Rand: cfg.Rand,
|
||||||
|
Time: cfg.Time,
|
||||||
|
Certificates: cfg.Certificates,
|
||||||
|
NameToCertificate: cfg.NameToCertificate,
|
||||||
|
GetCertificate: cfg.GetCertificate,
|
||||||
|
RootCAs: cfg.RootCAs,
|
||||||
|
NextProtos: cfg.NextProtos,
|
||||||
|
ServerName: cfg.ServerName,
|
||||||
|
ClientAuth: cfg.ClientAuth,
|
||||||
|
ClientCAs: cfg.ClientCAs,
|
||||||
|
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
||||||
|
CipherSuites: cfg.CipherSuites,
|
||||||
|
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
|
||||||
|
SessionTicketsDisabled: cfg.SessionTicketsDisabled,
|
||||||
|
SessionTicketKey: cfg.SessionTicketKey,
|
||||||
|
ClientSessionCache: cfg.ClientSessionCache,
|
||||||
|
MinVersion: cfg.MinVersion,
|
||||||
|
MaxVersion: cfg.MaxVersion,
|
||||||
|
CurvePreferences: cfg.CurvePreferences,
|
||||||
|
DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled,
|
||||||
|
Renegotiation: cfg.Renegotiation,
|
||||||
|
}
|
||||||
|
}
|
74
vendor/google.golang.org/grpc/credentials/credentials_util_pre_go17.go
generated
vendored
Normal file
74
vendor/google.golang.org/grpc/credentials/credentials_util_pre_go17.go
generated
vendored
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
// +build !go1.7
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
)
|
||||||
|
|
||||||
|
// cloneTLSConfig returns a shallow clone of the exported
|
||||||
|
// fields of cfg, ignoring the unexported sync.Once, which
|
||||||
|
// contains a mutex and must not be copied.
|
||||||
|
//
|
||||||
|
// If cfg is nil, a new zero tls.Config is returned.
|
||||||
|
//
|
||||||
|
// TODO replace this function with official clone function.
|
||||||
|
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
|
||||||
|
if cfg == nil {
|
||||||
|
return &tls.Config{}
|
||||||
|
}
|
||||||
|
return &tls.Config{
|
||||||
|
Rand: cfg.Rand,
|
||||||
|
Time: cfg.Time,
|
||||||
|
Certificates: cfg.Certificates,
|
||||||
|
NameToCertificate: cfg.NameToCertificate,
|
||||||
|
GetCertificate: cfg.GetCertificate,
|
||||||
|
RootCAs: cfg.RootCAs,
|
||||||
|
NextProtos: cfg.NextProtos,
|
||||||
|
ServerName: cfg.ServerName,
|
||||||
|
ClientAuth: cfg.ClientAuth,
|
||||||
|
ClientCAs: cfg.ClientCAs,
|
||||||
|
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
||||||
|
CipherSuites: cfg.CipherSuites,
|
||||||
|
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
|
||||||
|
SessionTicketsDisabled: cfg.SessionTicketsDisabled,
|
||||||
|
SessionTicketKey: cfg.SessionTicketKey,
|
||||||
|
ClientSessionCache: cfg.ClientSessionCache,
|
||||||
|
MinVersion: cfg.MinVersion,
|
||||||
|
MaxVersion: cfg.MaxVersion,
|
||||||
|
CurvePreferences: cfg.CurvePreferences,
|
||||||
|
}
|
||||||
|
}
|
180
vendor/google.golang.org/grpc/credentials/oauth/oauth.go
generated
vendored
Normal file
180
vendor/google.golang.org/grpc/credentials/oauth/oauth.go
generated
vendored
Normal file
|
@ -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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package oauth implements gRPC credentials using OAuth.
|
||||||
|
package oauth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/google"
|
||||||
|
"golang.org/x/oauth2/jwt"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TokenSource supplies PerRPCCredentials from an oauth2.TokenSource.
|
||||||
|
type TokenSource struct {
|
||||||
|
oauth2.TokenSource
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRequestMetadata gets the request metadata as a map from a TokenSource.
|
||||||
|
func (ts TokenSource) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
|
token, err := ts.Token()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]string{
|
||||||
|
"authorization": token.Type() + " " + token.AccessToken,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RequireTransportSecurity indicates whether the credentails requires transport security.
|
||||||
|
func (ts TokenSource) RequireTransportSecurity() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
type jwtAccess struct {
|
||||||
|
jsonKey []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewJWTAccessFromFile creates PerRPCCredentials from the given keyFile.
|
||||||
|
func NewJWTAccessFromFile(keyFile string) (credentials.PerRPCCredentials, error) {
|
||||||
|
jsonKey, err := ioutil.ReadFile(keyFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("credentials: failed to read the service account key file: %v", err)
|
||||||
|
}
|
||||||
|
return NewJWTAccessFromKey(jsonKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewJWTAccessFromKey creates PerRPCCredentials from the given jsonKey.
|
||||||
|
func NewJWTAccessFromKey(jsonKey []byte) (credentials.PerRPCCredentials, error) {
|
||||||
|
return jwtAccess{jsonKey}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j jwtAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
|
ts, err := google.JWTAccessTokenSourceFromJSON(j.jsonKey, uri[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
token, err := ts.Token()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]string{
|
||||||
|
"authorization": token.TokenType + " " + token.AccessToken,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j jwtAccess) RequireTransportSecurity() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// oauthAccess supplies PerRPCCredentials from a given token.
|
||||||
|
type oauthAccess struct {
|
||||||
|
token oauth2.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewOauthAccess constructs the PerRPCCredentials using a given token.
|
||||||
|
func NewOauthAccess(token *oauth2.Token) credentials.PerRPCCredentials {
|
||||||
|
return oauthAccess{token: *token}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (oa oauthAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
|
return map[string]string{
|
||||||
|
"authorization": oa.token.TokenType + " " + oa.token.AccessToken,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (oa oauthAccess) RequireTransportSecurity() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewComputeEngine constructs the PerRPCCredentials that fetches access tokens from
|
||||||
|
// Google Compute Engine (GCE)'s metadata server. It is only valid to use this
|
||||||
|
// if your program is running on a GCE instance.
|
||||||
|
// TODO(dsymonds): Deprecate and remove this.
|
||||||
|
func NewComputeEngine() credentials.PerRPCCredentials {
|
||||||
|
return TokenSource{google.ComputeTokenSource("")}
|
||||||
|
}
|
||||||
|
|
||||||
|
// serviceAccount represents PerRPCCredentials via JWT signing key.
|
||||||
|
type serviceAccount struct {
|
||||||
|
config *jwt.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s serviceAccount) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
|
token, err := s.config.TokenSource(ctx).Token()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]string{
|
||||||
|
"authorization": token.TokenType + " " + token.AccessToken,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s serviceAccount) RequireTransportSecurity() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServiceAccountFromKey constructs the PerRPCCredentials using the JSON key slice
|
||||||
|
// from a Google Developers service account.
|
||||||
|
func NewServiceAccountFromKey(jsonKey []byte, scope ...string) (credentials.PerRPCCredentials, error) {
|
||||||
|
config, err := google.JWTConfigFromJSON(jsonKey, scope...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return serviceAccount{config: config}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServiceAccountFromFile constructs the PerRPCCredentials using the JSON key file
|
||||||
|
// of a Google Developers service account.
|
||||||
|
func NewServiceAccountFromFile(keyFile string, scope ...string) (credentials.PerRPCCredentials, error) {
|
||||||
|
jsonKey, err := ioutil.ReadFile(keyFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("credentials: failed to read the service account key file: %v", err)
|
||||||
|
}
|
||||||
|
return NewServiceAccountFromKey(jsonKey, scope...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewApplicationDefault returns "Application Default Credentials". For more
|
||||||
|
// detail, see https://developers.google.com/accounts/docs/application-default-credentials.
|
||||||
|
func NewApplicationDefault(ctx context.Context, scope ...string) (credentials.PerRPCCredentials, error) {
|
||||||
|
t, err := google.DefaultTokenSource(ctx, scope...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return TokenSource{t}, nil
|
||||||
|
}
|
6
vendor/google.golang.org/grpc/doc.go
generated
vendored
Normal file
6
vendor/google.golang.org/grpc/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
/*
|
||||||
|
Package grpc implements an RPC system called gRPC.
|
||||||
|
|
||||||
|
See www.grpc.io for more information about gRPC.
|
||||||
|
*/
|
||||||
|
package grpc // import "google.golang.org/grpc"
|
57
vendor/google.golang.org/grpc/examples/README.md
generated
vendored
Normal file
57
vendor/google.golang.org/grpc/examples/README.md
generated
vendored
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
gRPC in 3 minutes (Go)
|
||||||
|
======================
|
||||||
|
|
||||||
|
BACKGROUND
|
||||||
|
-------------
|
||||||
|
For this sample, we've already generated the server and client stubs from [helloworld.proto](helloworld/helloworld/helloworld.proto).
|
||||||
|
|
||||||
|
PREREQUISITES
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- This requires Go 1.4
|
||||||
|
- Requires that [GOPATH is set](https://golang.org/doc/code.html#GOPATH)
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go help gopath
|
||||||
|
$ # ensure the PATH contains $GOPATH/bin
|
||||||
|
$ export PATH=$PATH:$GOPATH/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
INSTALL
|
||||||
|
-------
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go get -u google.golang.org/grpc/examples/helloworld/greeter_client
|
||||||
|
$ go get -u google.golang.org/grpc/examples/helloworld/greeter_server
|
||||||
|
```
|
||||||
|
|
||||||
|
TRY IT!
|
||||||
|
-------
|
||||||
|
|
||||||
|
- Run the server
|
||||||
|
|
||||||
|
```
|
||||||
|
$ greeter_server &
|
||||||
|
```
|
||||||
|
|
||||||
|
- Run the client
|
||||||
|
|
||||||
|
```
|
||||||
|
$ greeter_client
|
||||||
|
```
|
||||||
|
|
||||||
|
OPTIONAL - Rebuilding the generated code
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
1 First [install protoc](https://github.com/google/protobuf/blob/master/README.md)
|
||||||
|
- For now, this needs to be installed from source
|
||||||
|
- This is will change once proto3 is officially released
|
||||||
|
|
||||||
|
2 Install the protoc Go plugin.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go get -a github.com/golang/protobuf/protoc-gen-go
|
||||||
|
$
|
||||||
|
$ # from this dir; invoke protoc
|
||||||
|
$ protoc -I ./helloworld/helloworld/ ./helloworld/helloworld/helloworld.proto --go_out=plugins=grpc:helloworld
|
||||||
|
```
|
431
vendor/google.golang.org/grpc/examples/gotutorial.md
generated
vendored
Normal file
431
vendor/google.golang.org/grpc/examples/gotutorial.md
generated
vendored
Normal file
|
@ -0,0 +1,431 @@
|
||||||
|
#gRPC Basics: Go
|
||||||
|
|
||||||
|
This tutorial provides a basic Go programmer's introduction to working with gRPC. By walking through this example you'll learn how to:
|
||||||
|
|
||||||
|
- Define a service in a .proto file.
|
||||||
|
- Generate server and client code using the protocol buffer compiler.
|
||||||
|
- Use the Go gRPC API to write a simple client and server for your service.
|
||||||
|
|
||||||
|
It assumes that you have read the [Getting started](https://github.com/grpc/grpc/tree/master/examples) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release:you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository.
|
||||||
|
|
||||||
|
This isn't a comprehensive guide to using gRPC in Go: more reference documentation is coming soon.
|
||||||
|
|
||||||
|
## Why use gRPC?
|
||||||
|
|
||||||
|
Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients.
|
||||||
|
|
||||||
|
With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating.
|
||||||
|
|
||||||
|
## Example code and setup
|
||||||
|
|
||||||
|
The example code for our tutorial is in [grpc/grpc-go/examples/route_guide](https://github.com/grpc/grpc-go/tree/master/examples/route_guide). To download the example, clone the `grpc-go` repository by running the following command:
|
||||||
|
```shell
|
||||||
|
$ go get google.golang.org/grpc
|
||||||
|
```
|
||||||
|
|
||||||
|
Then change your current directory to `grpc-go/examples/route_guide`:
|
||||||
|
```shell
|
||||||
|
$ cd $GOPATH/src/google.golang.org/grpc/examples/route_guide
|
||||||
|
```
|
||||||
|
|
||||||
|
You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Go quick start guide](https://github.com/grpc/grpc-go/tree/master/examples/).
|
||||||
|
|
||||||
|
|
||||||
|
## Defining the service
|
||||||
|
|
||||||
|
Our first step (as you'll know from the [quick start](http://www.grpc.io/docs/#quick-start)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [examples/route_guide/routeguide/route_guide.proto](https://github.com/grpc/grpc-go/tree/master/examples/route_guide/routeguide/route_guide.proto).
|
||||||
|
|
||||||
|
To define a service, you specify a named `service` in your .proto file:
|
||||||
|
|
||||||
|
```proto
|
||||||
|
service RouteGuide {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service:
|
||||||
|
|
||||||
|
- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call.
|
||||||
|
```proto
|
||||||
|
// Obtains the feature at a given position.
|
||||||
|
rpc GetFeature(Point) returns (Feature) {}
|
||||||
|
```
|
||||||
|
|
||||||
|
- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type.
|
||||||
|
```proto
|
||||||
|
// Obtains the Features available within the given Rectangle. Results are
|
||||||
|
// streamed rather than returned at once (e.g. in a response message with a
|
||||||
|
// repeated field), as the rectangle may cover a large area and contain a
|
||||||
|
// huge number of features.
|
||||||
|
rpc ListFeatures(Rectangle) returns (stream Feature) {}
|
||||||
|
```
|
||||||
|
|
||||||
|
- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type.
|
||||||
|
```proto
|
||||||
|
// Accepts a stream of Points on a route being traversed, returning a
|
||||||
|
// RouteSummary when traversal is completed.
|
||||||
|
rpc RecordRoute(stream Point) returns (RouteSummary) {}
|
||||||
|
```
|
||||||
|
|
||||||
|
- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response.
|
||||||
|
```proto
|
||||||
|
// Accepts a stream of RouteNotes sent while a route is being traversed,
|
||||||
|
// while receiving other RouteNotes (e.g. from other users).
|
||||||
|
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
|
||||||
|
```
|
||||||
|
|
||||||
|
Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type:
|
||||||
|
```proto
|
||||||
|
// Points are represented as latitude-longitude pairs in the E7 representation
|
||||||
|
// (degrees multiplied by 10**7 and rounded to the nearest integer).
|
||||||
|
// Latitudes should be in the range +/- 90 degrees and longitude should be in
|
||||||
|
// the range +/- 180 degrees (inclusive).
|
||||||
|
message Point {
|
||||||
|
int32 latitude = 1;
|
||||||
|
int32 longitude = 2;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Generating client and server code
|
||||||
|
|
||||||
|
Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC Go plugin.
|
||||||
|
|
||||||
|
For simplicity, we've provided a [bash script](https://github.com/grpc/grpc-go/blob/master/codegen.sh) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this by yourself, make sure you've installed protoc and followed the gRPC-Go [installation instructions](https://github.com/grpc/grpc-go/blob/master/README.md) first):
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ codegen.sh route_guide.proto
|
||||||
|
```
|
||||||
|
|
||||||
|
which actually runs:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ protoc --go_out=plugins=grpc:. route_guide.proto
|
||||||
|
```
|
||||||
|
|
||||||
|
Running this command generates the following file in your current directory:
|
||||||
|
- `route_guide.pb.go`
|
||||||
|
|
||||||
|
This contains:
|
||||||
|
- All the protocol buffer code to populate, serialize, and retrieve our request and response message types
|
||||||
|
- An interface type (or *stub*) for clients to call with the methods defined in the `RouteGuide` service.
|
||||||
|
- An interface type for servers to implement, also with the methods defined in the `RouteGuide` service.
|
||||||
|
|
||||||
|
|
||||||
|
<a name="server"></a>
|
||||||
|
## Creating the server
|
||||||
|
|
||||||
|
First let's look at how we create a `RouteGuide` server. If you're only interested in creating gRPC clients, you can skip this section and go straight to [Creating the client](#client) (though you might find it interesting anyway!).
|
||||||
|
|
||||||
|
There are two parts to making our `RouteGuide` service do its job:
|
||||||
|
- Implementing the service interface generated from our service definition: doing the actual "work" of our service.
|
||||||
|
- Running a gRPC server to listen for requests from clients and dispatch them to the right service implementation.
|
||||||
|
|
||||||
|
You can find our example `RouteGuide` server in [grpc-go/examples/route_guide/server/server.go](https://github.com/grpc/grpc-go/tree/master/examples/route_guide/server/server.go). Let's take a closer look at how it works.
|
||||||
|
|
||||||
|
### Implementing RouteGuide
|
||||||
|
|
||||||
|
As you can see, our server has a `routeGuideServer` struct type that implements the generated `RouteGuideServer` interface:
|
||||||
|
|
||||||
|
```go
|
||||||
|
type routeGuideServer struct {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
...
|
||||||
|
|
||||||
|
func (s *routeGuideServer) GetFeature(ctx context.Context, point *pb.Point) (*pb.Feature, error) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
...
|
||||||
|
|
||||||
|
func (s *routeGuideServer) ListFeatures(rect *pb.Rectangle, stream pb.RouteGuide_ListFeaturesServer) error {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
...
|
||||||
|
|
||||||
|
func (s *routeGuideServer) RecordRoute(stream pb.RouteGuide_RecordRouteServer) error {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
...
|
||||||
|
|
||||||
|
func (s *routeGuideServer) RouteChat(stream pb.RouteGuide_RouteChatServer) error {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Simple RPC
|
||||||
|
`routeGuideServer` implements all our service methods. Let's look at the simplest type first, `GetFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`.
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *routeGuideServer) GetFeature(ctx context.Context, point *pb.Point) (*pb.Feature, error) {
|
||||||
|
for _, feature := range s.savedFeatures {
|
||||||
|
if proto.Equal(feature.Location, point) {
|
||||||
|
return feature, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No feature was found, return an unnamed feature
|
||||||
|
return &pb.Feature{"", point}, nil
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The method is passed a context object for the RPC and the client's `Point` protocol buffer request. It returns a `Feature` protocol buffer object with the response information and an `error`. In the method we populate the `Feature` with the appropriate information, and then `return` it along with an `nil` error to tell gRPC that we've finished dealing with the RPC and that the `Feature` can be returned to the client.
|
||||||
|
|
||||||
|
#### Server-side streaming RPC
|
||||||
|
Now let's look at one of our streaming RPCs. `ListFeatures` is a server-side streaming RPC, so we need to send back multiple `Feature`s to our client.
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *routeGuideServer) ListFeatures(rect *pb.Rectangle, stream pb.RouteGuide_ListFeaturesServer) error {
|
||||||
|
for _, feature := range s.savedFeatures {
|
||||||
|
if inRange(feature.Location, rect) {
|
||||||
|
if err := stream.Send(feature); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
As you can see, instead of getting simple request and response objects in our method parameters, this time we get a request object (the `Rectangle` in which our client wants to find `Feature`s) and a special `RouteGuide_ListFeaturesServer` object to write our responses.
|
||||||
|
|
||||||
|
In the method, we populate as many `Feature` objects as we need to return, writing them to the `RouteGuide_ListFeaturesServer` using its `Send()` method. Finally, as in our simple RPC, we return a `nil` error to tell gRPC that we've finished writing responses. Should any error happen in this call, we return a non-`nil` error; the gRPC layer will translate it into an appropriate RPC status to be sent on the wire.
|
||||||
|
|
||||||
|
#### Client-side streaming RPC
|
||||||
|
Now let's look at something a little more complicated: the client-side streaming method `RecordRoute`, where we get a stream of `Point`s from the client and return a single `RouteSummary` with information about their trip. As you can see, this time the method doesn't have a request parameter at all. Instead, it gets a `RouteGuide_RecordRouteServer` stream, which the server can use to both read *and* write messages - it can receive client messages using its `Recv()` method and return its single response using its `SendAndClose()` method.
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *routeGuideServer) RecordRoute(stream pb.RouteGuide_RecordRouteServer) error {
|
||||||
|
var pointCount, featureCount, distance int32
|
||||||
|
var lastPoint *pb.Point
|
||||||
|
startTime := time.Now()
|
||||||
|
for {
|
||||||
|
point, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
endTime := time.Now()
|
||||||
|
return stream.SendAndClose(&pb.RouteSummary{
|
||||||
|
PointCount: pointCount,
|
||||||
|
FeatureCount: featureCount,
|
||||||
|
Distance: distance,
|
||||||
|
ElapsedTime: int32(endTime.Sub(startTime).Seconds()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pointCount++
|
||||||
|
for _, feature := range s.savedFeatures {
|
||||||
|
if proto.Equal(feature.Location, point) {
|
||||||
|
featureCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if lastPoint != nil {
|
||||||
|
distance += calcDistance(lastPoint, point)
|
||||||
|
}
|
||||||
|
lastPoint = point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In the method body we use the `RouteGuide_RecordRouteServer`s `Recv()` method to repeatedly read in our client's requests to a request object (in this case a `Point`) until there are no more messages: the server needs to check the the error returned from `Recv()` after each call. If this is `nil`, the stream is still good and it can continue reading; if it's `io.EOF` the message stream has ended and the server can return its `RouteSummary`. If it has any other value, we return the error "as is" so that it'll be translated to an RPC status by the gRPC layer.
|
||||||
|
|
||||||
|
#### Bidirectional streaming RPC
|
||||||
|
Finally, let's look at our bidirectional streaming RPC `RouteChat()`.
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *routeGuideServer) RouteChat(stream pb.RouteGuide_RouteChatServer) error {
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
key := serialize(in.Location)
|
||||||
|
... // look for notes to be sent to client
|
||||||
|
for _, note := range s.routeNotes[key] {
|
||||||
|
if err := stream.Send(note); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This time we get a `RouteGuide_RouteChatServer` stream that, as in our client-side streaming example, can be used to read and write messages. However, this time we return values via our method's stream while the client is still writing messages to *their* message stream.
|
||||||
|
|
||||||
|
The syntax for reading and writing here is very similar to our client-streaming method, except the server uses the stream's `Send()` method rather than `SendAndClose()` because it's writing multiple responses. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
|
||||||
|
|
||||||
|
### Starting the server
|
||||||
|
|
||||||
|
Once we've implemented all our methods, we also need to start up a gRPC server so that clients can actually use our service. The following snippet shows how we do this for our `RouteGuide` service:
|
||||||
|
|
||||||
|
```go
|
||||||
|
flag.Parse()
|
||||||
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
grpcServer := grpc.NewServer()
|
||||||
|
pb.RegisterRouteGuideServer(grpcServer, &routeGuideServer{})
|
||||||
|
... // determine whether to use TLS
|
||||||
|
grpcServer.Serve(lis)
|
||||||
|
```
|
||||||
|
To build and start a server, we:
|
||||||
|
|
||||||
|
1. Specify the port we want to use to listen for client requests using `lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))`.
|
||||||
|
2. Create an instance of the gRPC server using `grpc.NewServer()`.
|
||||||
|
3. Register our service implementation with the gRPC server.
|
||||||
|
4. Call `Serve()` on the server with our port details to do a blocking wait until the process is killed or `Stop()` is called.
|
||||||
|
|
||||||
|
<a name="client"></a>
|
||||||
|
## Creating the client
|
||||||
|
|
||||||
|
In this section, we'll look at creating a Go client for our `RouteGuide` service. You can see our complete example client code in [grpc-go/examples/route_guide/client/client.go](https://github.com/grpc/grpc-go/tree/master/examples/route_guide/client/client.go).
|
||||||
|
|
||||||
|
### Creating a stub
|
||||||
|
|
||||||
|
To call service methods, we first need to create a gRPC *channel* to communicate with the server. We create this by passing the server address and port number to `grpc.Dial()` as follows:
|
||||||
|
|
||||||
|
```go
|
||||||
|
conn, err := grpc.Dial(*serverAddr)
|
||||||
|
if err != nil {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use `DialOptions` to set the auth credentials (e.g., TLS, GCE credentials, JWT credentials) in `grpc.Dial` if the service you request requires that - however, we don't need to do this for our `RouteGuide` service.
|
||||||
|
|
||||||
|
Once the gRPC *channel* is setup, we need a client *stub* to perform RPCs. We get this using the `NewRouteGuideClient` method provided in the `pb` package we generated from our .proto.
|
||||||
|
|
||||||
|
```go
|
||||||
|
client := pb.NewRouteGuideClient(conn)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Calling service methods
|
||||||
|
|
||||||
|
Now let's look at how we call our service methods. Note that in gRPC-Go, RPCs operate in a blocking/synchronous mode, which means that the RPC call waits for the server to respond, and will either return a response or an error.
|
||||||
|
|
||||||
|
#### Simple RPC
|
||||||
|
|
||||||
|
Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local method.
|
||||||
|
|
||||||
|
```go
|
||||||
|
feature, err := client.GetFeature(context.Background(), &pb.Point{409146138, -746188906})
|
||||||
|
if err != nil {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
As you can see, we call the method on the stub we got earlier. In our method parameters we create and populate a request protocol buffer object (in our case `Point`). We also pass a `context.Context` object which lets us change our RPC's behaviour if necessary, such as time-out/cancel an RPC in flight. If the call doesn't return an error, then we can read the response information from the server from the first return value.
|
||||||
|
|
||||||
|
```go
|
||||||
|
log.Println(feature)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Server-side streaming RPC
|
||||||
|
|
||||||
|
Here's where we call the server-side streaming method `ListFeatures`, which returns a stream of geographical `Feature`s. If you've already read [Creating the server](#server) some of this may look very familiar - streaming RPCs are implemented in a similar way on both sides.
|
||||||
|
|
||||||
|
```go
|
||||||
|
rect := &pb.Rectangle{ ... } // initialize a pb.Rectangle
|
||||||
|
stream, err := client.ListFeatures(context.Background(), rect)
|
||||||
|
if err != nil {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
feature, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v.ListFeatures(_) = _, %v", client, err)
|
||||||
|
}
|
||||||
|
log.Println(feature)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
As in the simple RPC, we pass the method a context and a request. However, instead of getting a response object back, we get back an instance of `RouteGuide_ListFeaturesClient`. The client can use the `RouteGuide_ListFeaturesClient` stream to read the server's responses.
|
||||||
|
|
||||||
|
We use the `RouteGuide_ListFeaturesClient`'s `Recv()` method to repeatedly read in the server's responses to a response protocol buffer object (in this case a `Feature`) until there are no more messages: the client needs to check the error `err` returned from `Recv()` after each call. If `nil`, the stream is still good and it can continue reading; if it's `io.EOF` then the message stream has ended; otherwise there must be an RPC error, which is passed over through `err`.
|
||||||
|
|
||||||
|
#### Client-side streaming RPC
|
||||||
|
|
||||||
|
The client-side streaming method `RecordRoute` is similar to the server-side method, except that we only pass the method a context and get a `RouteGuide_RecordRouteClient` stream back, which we can use to both write *and* read messages.
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Create a random number of random points
|
||||||
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
pointCount := int(r.Int31n(100)) + 2 // Traverse at least two points
|
||||||
|
var points []*pb.Point
|
||||||
|
for i := 0; i < pointCount; i++ {
|
||||||
|
points = append(points, randomPoint(r))
|
||||||
|
}
|
||||||
|
log.Printf("Traversing %d points.", len(points))
|
||||||
|
stream, err := client.RecordRoute(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v.RecordRoute(_) = _, %v", client, err)
|
||||||
|
}
|
||||||
|
for _, point := range points {
|
||||||
|
if err := stream.Send(point); err != nil {
|
||||||
|
log.Fatalf("%v.Send(%v) = %v", stream, point, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reply, err := stream.CloseAndRecv()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
|
||||||
|
}
|
||||||
|
log.Printf("Route summary: %v", reply)
|
||||||
|
```
|
||||||
|
|
||||||
|
The `RouteGuide_RecordRouteClient` has a `Send()` method that we can use to send requests to the server. Once we've finished writing our client's requests to the stream using `Send()`, we need to call `CloseAndRecv()` on the stream to let gRPC know that we've finished writing and are expecting to receive a response. We get our RPC status from the `err` returned from `CloseAndRecv()`. If the status is `nil`, then the first return value from `CloseAndRecv()` will be a valid server response.
|
||||||
|
|
||||||
|
#### Bidirectional streaming RPC
|
||||||
|
|
||||||
|
Finally, let's look at our bidirectional streaming RPC `RouteChat()`. As in the case of `RecordRoute`, we only pass the method a context object and get back a stream that we can use to both write and read messages. However, this time we return values via our method's stream while the server is still writing messages to *their* message stream.
|
||||||
|
|
||||||
|
```go
|
||||||
|
stream, err := client.RouteChat(context.Background())
|
||||||
|
waitc := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
// read done.
|
||||||
|
close(waitc)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to receive a note : %v", err)
|
||||||
|
}
|
||||||
|
log.Printf("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
for _, note := range notes {
|
||||||
|
if err := stream.Send(note); err != nil {
|
||||||
|
log.Fatalf("Failed to send a note: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stream.CloseSend()
|
||||||
|
<-waitc
|
||||||
|
```
|
||||||
|
|
||||||
|
The syntax for reading and writing here is very similar to our client-side streaming method, except we use the stream's `CloseSend()` method once we've finished our call. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
|
||||||
|
|
||||||
|
## Try it out!
|
||||||
|
|
||||||
|
To compile and run the server, assuming you are in the folder
|
||||||
|
`$GOPATH/src/google.golang.org/grpc/examples/route_guide`, simply:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ go run server/server.go
|
||||||
|
```
|
||||||
|
|
||||||
|
Likewise, to run the client:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ go run client/client.go
|
||||||
|
```
|
||||||
|
|
69
vendor/google.golang.org/grpc/examples/helloworld/greeter_client/main.go
generated
vendored
Normal file
69
vendor/google.golang.org/grpc/examples/helloworld/greeter_client/main.go
generated
vendored
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
pb "google.golang.org/grpc/examples/helloworld/helloworld"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
address = "localhost:50051"
|
||||||
|
defaultName = "world"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Set up a connection to the server.
|
||||||
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("did not connect: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
c := pb.NewGreeterClient(conn)
|
||||||
|
|
||||||
|
// Contact the server and print out its response.
|
||||||
|
name := defaultName
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
name = os.Args[1]
|
||||||
|
}
|
||||||
|
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("could not greet: %v", err)
|
||||||
|
}
|
||||||
|
log.Printf("Greeting: %s", r.Message)
|
||||||
|
}
|
65
vendor/google.golang.org/grpc/examples/helloworld/greeter_server/main.go
generated
vendored
Normal file
65
vendor/google.golang.org/grpc/examples/helloworld/greeter_server/main.go
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
pb "google.golang.org/grpc/examples/helloworld/helloworld"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
port = ":50051"
|
||||||
|
)
|
||||||
|
|
||||||
|
// server is used to implement helloworld.GreeterServer.
|
||||||
|
type server struct{}
|
||||||
|
|
||||||
|
// SayHello implements helloworld.GreeterServer
|
||||||
|
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
|
||||||
|
return &pb.HelloReply{Message: "Hello " + in.Name}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
lis, err := net.Listen("tcp", port)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
s := grpc.NewServer()
|
||||||
|
pb.RegisterGreeterServer(s, &server{})
|
||||||
|
s.Serve(lis)
|
||||||
|
}
|
151
vendor/google.golang.org/grpc/examples/helloworld/helloworld/helloworld.pb.go
generated
vendored
Normal file
151
vendor/google.golang.org/grpc/examples/helloworld/helloworld/helloworld.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: helloworld.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package helloworld is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
helloworld.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
HelloRequest
|
||||||
|
HelloReply
|
||||||
|
*/
|
||||||
|
package helloworld
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
// The request message containing the user's name.
|
||||||
|
type HelloRequest struct {
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *HelloRequest) Reset() { *m = HelloRequest{} }
|
||||||
|
func (m *HelloRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*HelloRequest) ProtoMessage() {}
|
||||||
|
func (*HelloRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
// The response message containing the greetings
|
||||||
|
type HelloReply struct {
|
||||||
|
Message string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *HelloReply) Reset() { *m = HelloReply{} }
|
||||||
|
func (m *HelloReply) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*HelloReply) ProtoMessage() {}
|
||||||
|
func (*HelloReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*HelloRequest)(nil), "helloworld.HelloRequest")
|
||||||
|
proto.RegisterType((*HelloReply)(nil), "helloworld.HelloReply")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for Greeter service
|
||||||
|
|
||||||
|
type GreeterClient interface {
|
||||||
|
// Sends a greeting
|
||||||
|
SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type greeterClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGreeterClient(cc *grpc.ClientConn) GreeterClient {
|
||||||
|
return &greeterClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) {
|
||||||
|
out := new(HelloReply)
|
||||||
|
err := grpc.Invoke(ctx, "/helloworld.Greeter/SayHello", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for Greeter service
|
||||||
|
|
||||||
|
type GreeterServer interface {
|
||||||
|
// Sends a greeting
|
||||||
|
SayHello(context.Context, *HelloRequest) (*HelloReply, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) {
|
||||||
|
s.RegisterService(&_Greeter_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(HelloRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(GreeterServer).SayHello(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/helloworld.Greeter/SayHello",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _Greeter_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "helloworld.Greeter",
|
||||||
|
HandlerType: (*GreeterServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "SayHello",
|
||||||
|
Handler: _Greeter_SayHello_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: fileDescriptor0,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("helloworld.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 174 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x12, 0xc8, 0x48, 0xcd, 0xc9,
|
||||||
|
0xc9, 0x2f, 0xcf, 0x2f, 0xca, 0x49, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x42, 0x88,
|
||||||
|
0x28, 0x29, 0x71, 0xf1, 0x78, 0x80, 0x78, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x42,
|
||||||
|
0x5c, 0x2c, 0x79, 0x89, 0xb9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x60, 0xb6, 0x92,
|
||||||
|
0x1a, 0x17, 0x17, 0x54, 0x4d, 0x41, 0x4e, 0xa5, 0x90, 0x04, 0x17, 0x7b, 0x6e, 0x6a, 0x71, 0x71,
|
||||||
|
0x62, 0x3a, 0x4c, 0x11, 0x8c, 0x6b, 0xe4, 0xc9, 0xc5, 0xee, 0x5e, 0x94, 0x9a, 0x5a, 0x92, 0x5a,
|
||||||
|
0x24, 0x64, 0xc7, 0xc5, 0x11, 0x9c, 0x58, 0x09, 0xd6, 0x25, 0x24, 0xa1, 0x87, 0xe4, 0x02, 0x64,
|
||||||
|
0xcb, 0xa4, 0xc4, 0xb0, 0xc8, 0x00, 0xad, 0x50, 0x62, 0x70, 0x32, 0xe0, 0x92, 0xce, 0xcc, 0xd7,
|
||||||
|
0x4b, 0x2f, 0x2a, 0x48, 0xd6, 0x4b, 0xad, 0x48, 0xcc, 0x2d, 0xc8, 0x49, 0x2d, 0x46, 0x52, 0xeb,
|
||||||
|
0xc4, 0x0f, 0x56, 0x1c, 0x0e, 0x62, 0x07, 0x80, 0xbc, 0x14, 0xc0, 0x98, 0xc4, 0x06, 0xf6, 0x9b,
|
||||||
|
0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x0f, 0xb7, 0xcd, 0xf2, 0xef, 0x00, 0x00, 0x00,
|
||||||
|
}
|
52
vendor/google.golang.org/grpc/examples/helloworld/helloworld/helloworld.proto
generated
vendored
Normal file
52
vendor/google.golang.org/grpc/examples/helloworld/helloworld/helloworld.proto
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// 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";
|
||||||
|
|
||||||
|
option java_multiple_files = true;
|
||||||
|
option java_package = "io.grpc.examples.helloworld";
|
||||||
|
option java_outer_classname = "HelloWorldProto";
|
||||||
|
|
||||||
|
package helloworld;
|
||||||
|
|
||||||
|
// The greeting service definition.
|
||||||
|
service Greeter {
|
||||||
|
// Sends a greeting
|
||||||
|
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The request message containing the user's name.
|
||||||
|
message HelloRequest {
|
||||||
|
string name = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The response message containing the greetings
|
||||||
|
message HelloReply {
|
||||||
|
string message = 1;
|
||||||
|
}
|
35
vendor/google.golang.org/grpc/examples/route_guide/README.md
generated
vendored
Normal file
35
vendor/google.golang.org/grpc/examples/route_guide/README.md
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# Description
|
||||||
|
The route guide server and client demonstrate how to use grpc go libraries to
|
||||||
|
perform unary, client streaming, server streaming and full duplex RPCs.
|
||||||
|
|
||||||
|
Please refer to [gRPC Basics: Go] (http://www.grpc.io/docs/tutorials/basic/go.html) for more information.
|
||||||
|
|
||||||
|
See the definition of the route guide service in proto/route_guide.proto.
|
||||||
|
|
||||||
|
# Run the sample code
|
||||||
|
To compile and run the server, assuming you are in the root of the route_guide
|
||||||
|
folder, i.e., .../examples/route_guide/, simply:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ go run server/server.go
|
||||||
|
```
|
||||||
|
|
||||||
|
Likewise, to run the client:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ go run client/client.go
|
||||||
|
```
|
||||||
|
|
||||||
|
# Optional command line flags
|
||||||
|
The server and client both take optional command line flags. For example, the
|
||||||
|
client and server run without TLS by default. To enable TLS:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ go run server/server.go -tls=true
|
||||||
|
```
|
||||||
|
|
||||||
|
and
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ go run client/client.go -tls=true
|
||||||
|
```
|
205
vendor/google.golang.org/grpc/examples/route_guide/client/client.go
generated
vendored
Normal file
205
vendor/google.golang.org/grpc/examples/route_guide/client/client.go
generated
vendored
Normal file
|
@ -0,0 +1,205 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package main implements a simple gRPC client that demonstrates how to use gRPC-Go libraries
|
||||||
|
// to perform unary, client streaming, server streaming and full duplex RPCs.
|
||||||
|
//
|
||||||
|
// It interacts with the route guide service whose definition can be found in proto/route_guide.proto.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"io"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
pb "google.golang.org/grpc/examples/route_guide/routeguide"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
|
||||||
|
caFile = flag.String("ca_file", "testdata/ca.pem", "The file containning the CA root cert file")
|
||||||
|
serverAddr = flag.String("server_addr", "127.0.0.1:10000", "The server address in the format of host:port")
|
||||||
|
serverHostOverride = flag.String("server_host_override", "x.test.youtube.com", "The server name use to verify the hostname returned by TLS handshake")
|
||||||
|
)
|
||||||
|
|
||||||
|
// printFeature gets the feature for the given point.
|
||||||
|
func printFeature(client pb.RouteGuideClient, point *pb.Point) {
|
||||||
|
grpclog.Printf("Getting feature for point (%d, %d)", point.Latitude, point.Longitude)
|
||||||
|
feature, err := client.GetFeature(context.Background(), point)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.GetFeatures(_) = _, %v: ", client, err)
|
||||||
|
}
|
||||||
|
grpclog.Println(feature)
|
||||||
|
}
|
||||||
|
|
||||||
|
// printFeatures lists all the features within the given bounding Rectangle.
|
||||||
|
func printFeatures(client pb.RouteGuideClient, rect *pb.Rectangle) {
|
||||||
|
grpclog.Printf("Looking for features within %v", rect)
|
||||||
|
stream, err := client.ListFeatures(context.Background(), rect)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.ListFeatures(_) = _, %v", client, err)
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
feature, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.ListFeatures(_) = _, %v", client, err)
|
||||||
|
}
|
||||||
|
grpclog.Println(feature)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// runRecordRoute sends a sequence of points to server and expects to get a RouteSummary from server.
|
||||||
|
func runRecordRoute(client pb.RouteGuideClient) {
|
||||||
|
// Create a random number of random points
|
||||||
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
pointCount := int(r.Int31n(100)) + 2 // Traverse at least two points
|
||||||
|
var points []*pb.Point
|
||||||
|
for i := 0; i < pointCount; i++ {
|
||||||
|
points = append(points, randomPoint(r))
|
||||||
|
}
|
||||||
|
grpclog.Printf("Traversing %d points.", len(points))
|
||||||
|
stream, err := client.RecordRoute(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.RecordRoute(_) = _, %v", client, err)
|
||||||
|
}
|
||||||
|
for _, point := range points {
|
||||||
|
if err := stream.Send(point); err != nil {
|
||||||
|
grpclog.Fatalf("%v.Send(%v) = %v", stream, point, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reply, err := stream.CloseAndRecv()
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
|
||||||
|
}
|
||||||
|
grpclog.Printf("Route summary: %v", reply)
|
||||||
|
}
|
||||||
|
|
||||||
|
// runRouteChat receives a sequence of route notes, while sending notes for various locations.
|
||||||
|
func runRouteChat(client pb.RouteGuideClient) {
|
||||||
|
notes := []*pb.RouteNote{
|
||||||
|
{&pb.Point{Latitude: 0, Longitude: 1}, "First message"},
|
||||||
|
{&pb.Point{Latitude: 0, Longitude: 2}, "Second message"},
|
||||||
|
{&pb.Point{Latitude: 0, Longitude: 3}, "Third message"},
|
||||||
|
{&pb.Point{Latitude: 0, Longitude: 1}, "Fourth message"},
|
||||||
|
{&pb.Point{Latitude: 0, Longitude: 2}, "Fifth message"},
|
||||||
|
{&pb.Point{Latitude: 0, Longitude: 3}, "Sixth message"},
|
||||||
|
}
|
||||||
|
stream, err := client.RouteChat(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.RouteChat(_) = _, %v", client, err)
|
||||||
|
}
|
||||||
|
waitc := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
// read done.
|
||||||
|
close(waitc)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to receive a note : %v", err)
|
||||||
|
}
|
||||||
|
grpclog.Printf("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
for _, note := range notes {
|
||||||
|
if err := stream.Send(note); err != nil {
|
||||||
|
grpclog.Fatalf("Failed to send a note: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stream.CloseSend()
|
||||||
|
<-waitc
|
||||||
|
}
|
||||||
|
|
||||||
|
func randomPoint(r *rand.Rand) *pb.Point {
|
||||||
|
lat := (r.Int31n(180) - 90) * 1e7
|
||||||
|
long := (r.Int31n(360) - 180) * 1e7
|
||||||
|
return &pb.Point{Latitude: lat, Longitude: long}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
var opts []grpc.DialOption
|
||||||
|
if *tls {
|
||||||
|
var sn string
|
||||||
|
if *serverHostOverride != "" {
|
||||||
|
sn = *serverHostOverride
|
||||||
|
}
|
||||||
|
var creds credentials.TransportCredentials
|
||||||
|
if *caFile != "" {
|
||||||
|
var err error
|
||||||
|
creds, err = credentials.NewClientTLSFromFile(*caFile, sn)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to create TLS credentials %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
creds = credentials.NewClientTLSFromCert(nil, sn)
|
||||||
|
}
|
||||||
|
opts = append(opts, grpc.WithTransportCredentials(creds))
|
||||||
|
} else {
|
||||||
|
opts = append(opts, grpc.WithInsecure())
|
||||||
|
}
|
||||||
|
conn, err := grpc.Dial(*serverAddr, opts...)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("fail to dial: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
client := pb.NewRouteGuideClient(conn)
|
||||||
|
|
||||||
|
// Looking for a valid feature
|
||||||
|
printFeature(client, &pb.Point{Latitude: 409146138, Longitude: -746188906})
|
||||||
|
|
||||||
|
// Feature missing.
|
||||||
|
printFeature(client, &pb.Point{Latitude: 0, Longitude: 0})
|
||||||
|
|
||||||
|
// Looking for features between 40, -75 and 42, -73.
|
||||||
|
printFeatures(client, &pb.Rectangle{
|
||||||
|
Lo: &pb.Point{Latitude: 400000000, Longitude: -750000000},
|
||||||
|
Hi: &pb.Point{Latitude: 420000000, Longitude: -730000000},
|
||||||
|
})
|
||||||
|
|
||||||
|
// RecordRoute
|
||||||
|
runRecordRoute(client)
|
||||||
|
|
||||||
|
// RouteChat
|
||||||
|
runRouteChat(client)
|
||||||
|
}
|
488
vendor/google.golang.org/grpc/examples/route_guide/routeguide/route_guide.pb.go
generated
vendored
Normal file
488
vendor/google.golang.org/grpc/examples/route_guide/routeguide/route_guide.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,488 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: route_guide.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package routeguide is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
route_guide.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
Point
|
||||||
|
Rectangle
|
||||||
|
Feature
|
||||||
|
RouteNote
|
||||||
|
RouteSummary
|
||||||
|
*/
|
||||||
|
package routeguide
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
// Points are represented as latitude-longitude pairs in the E7 representation
|
||||||
|
// (degrees multiplied by 10**7 and rounded to the nearest integer).
|
||||||
|
// Latitudes should be in the range +/- 90 degrees and longitude should be in
|
||||||
|
// the range +/- 180 degrees (inclusive).
|
||||||
|
type Point struct {
|
||||||
|
Latitude int32 `protobuf:"varint,1,opt,name=latitude" json:"latitude,omitempty"`
|
||||||
|
Longitude int32 `protobuf:"varint,2,opt,name=longitude" json:"longitude,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Point) Reset() { *m = Point{} }
|
||||||
|
func (m *Point) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Point) ProtoMessage() {}
|
||||||
|
func (*Point) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
// A latitude-longitude rectangle, represented as two diagonally opposite
|
||||||
|
// points "lo" and "hi".
|
||||||
|
type Rectangle struct {
|
||||||
|
// One corner of the rectangle.
|
||||||
|
Lo *Point `protobuf:"bytes,1,opt,name=lo" json:"lo,omitempty"`
|
||||||
|
// The other corner of the rectangle.
|
||||||
|
Hi *Point `protobuf:"bytes,2,opt,name=hi" json:"hi,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Rectangle) Reset() { *m = Rectangle{} }
|
||||||
|
func (m *Rectangle) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Rectangle) ProtoMessage() {}
|
||||||
|
func (*Rectangle) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
func (m *Rectangle) GetLo() *Point {
|
||||||
|
if m != nil {
|
||||||
|
return m.Lo
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Rectangle) GetHi() *Point {
|
||||||
|
if m != nil {
|
||||||
|
return m.Hi
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// A feature names something at a given point.
|
||||||
|
//
|
||||||
|
// If a feature could not be named, the name is empty.
|
||||||
|
type Feature struct {
|
||||||
|
// The name of the feature.
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||||
|
// The point where the feature is detected.
|
||||||
|
Location *Point `protobuf:"bytes,2,opt,name=location" json:"location,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Feature) Reset() { *m = Feature{} }
|
||||||
|
func (m *Feature) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Feature) ProtoMessage() {}
|
||||||
|
func (*Feature) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||||
|
|
||||||
|
func (m *Feature) GetLocation() *Point {
|
||||||
|
if m != nil {
|
||||||
|
return m.Location
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// A RouteNote is a message sent while at a given point.
|
||||||
|
type RouteNote struct {
|
||||||
|
// The location from which the message is sent.
|
||||||
|
Location *Point `protobuf:"bytes,1,opt,name=location" json:"location,omitempty"`
|
||||||
|
// The message to be sent.
|
||||||
|
Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *RouteNote) Reset() { *m = RouteNote{} }
|
||||||
|
func (m *RouteNote) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*RouteNote) ProtoMessage() {}
|
||||||
|
func (*RouteNote) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||||
|
|
||||||
|
func (m *RouteNote) GetLocation() *Point {
|
||||||
|
if m != nil {
|
||||||
|
return m.Location
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// A RouteSummary is received in response to a RecordRoute rpc.
|
||||||
|
//
|
||||||
|
// It contains the number of individual points received, the number of
|
||||||
|
// detected features, and the total distance covered as the cumulative sum of
|
||||||
|
// the distance between each point.
|
||||||
|
type RouteSummary struct {
|
||||||
|
// The number of points received.
|
||||||
|
PointCount int32 `protobuf:"varint,1,opt,name=point_count,json=pointCount" json:"point_count,omitempty"`
|
||||||
|
// The number of known features passed while traversing the route.
|
||||||
|
FeatureCount int32 `protobuf:"varint,2,opt,name=feature_count,json=featureCount" json:"feature_count,omitempty"`
|
||||||
|
// The distance covered in metres.
|
||||||
|
Distance int32 `protobuf:"varint,3,opt,name=distance" json:"distance,omitempty"`
|
||||||
|
// The duration of the traversal in seconds.
|
||||||
|
ElapsedTime int32 `protobuf:"varint,4,opt,name=elapsed_time,json=elapsedTime" json:"elapsed_time,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *RouteSummary) Reset() { *m = RouteSummary{} }
|
||||||
|
func (m *RouteSummary) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*RouteSummary) ProtoMessage() {}
|
||||||
|
func (*RouteSummary) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*Point)(nil), "routeguide.Point")
|
||||||
|
proto.RegisterType((*Rectangle)(nil), "routeguide.Rectangle")
|
||||||
|
proto.RegisterType((*Feature)(nil), "routeguide.Feature")
|
||||||
|
proto.RegisterType((*RouteNote)(nil), "routeguide.RouteNote")
|
||||||
|
proto.RegisterType((*RouteSummary)(nil), "routeguide.RouteSummary")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for RouteGuide service
|
||||||
|
|
||||||
|
type RouteGuideClient interface {
|
||||||
|
// A simple RPC.
|
||||||
|
//
|
||||||
|
// Obtains the feature at a given position.
|
||||||
|
//
|
||||||
|
// A feature with an empty name is returned if there's no feature at the given
|
||||||
|
// position.
|
||||||
|
GetFeature(ctx context.Context, in *Point, opts ...grpc.CallOption) (*Feature, error)
|
||||||
|
// A server-to-client streaming RPC.
|
||||||
|
//
|
||||||
|
// Obtains the Features available within the given Rectangle. Results are
|
||||||
|
// streamed rather than returned at once (e.g. in a response message with a
|
||||||
|
// repeated field), as the rectangle may cover a large area and contain a
|
||||||
|
// huge number of features.
|
||||||
|
ListFeatures(ctx context.Context, in *Rectangle, opts ...grpc.CallOption) (RouteGuide_ListFeaturesClient, error)
|
||||||
|
// A client-to-server streaming RPC.
|
||||||
|
//
|
||||||
|
// Accepts a stream of Points on a route being traversed, returning a
|
||||||
|
// RouteSummary when traversal is completed.
|
||||||
|
RecordRoute(ctx context.Context, opts ...grpc.CallOption) (RouteGuide_RecordRouteClient, error)
|
||||||
|
// A Bidirectional streaming RPC.
|
||||||
|
//
|
||||||
|
// Accepts a stream of RouteNotes sent while a route is being traversed,
|
||||||
|
// while receiving other RouteNotes (e.g. from other users).
|
||||||
|
RouteChat(ctx context.Context, opts ...grpc.CallOption) (RouteGuide_RouteChatClient, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type routeGuideClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRouteGuideClient(cc *grpc.ClientConn) RouteGuideClient {
|
||||||
|
return &routeGuideClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *routeGuideClient) GetFeature(ctx context.Context, in *Point, opts ...grpc.CallOption) (*Feature, error) {
|
||||||
|
out := new(Feature)
|
||||||
|
err := grpc.Invoke(ctx, "/routeguide.RouteGuide/GetFeature", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *routeGuideClient) ListFeatures(ctx context.Context, in *Rectangle, opts ...grpc.CallOption) (RouteGuide_ListFeaturesClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_RouteGuide_serviceDesc.Streams[0], c.cc, "/routeguide.RouteGuide/ListFeatures", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &routeGuideListFeaturesClient{stream}
|
||||||
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteGuide_ListFeaturesClient interface {
|
||||||
|
Recv() (*Feature, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type routeGuideListFeaturesClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideListFeaturesClient) Recv() (*Feature, error) {
|
||||||
|
m := new(Feature)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *routeGuideClient) RecordRoute(ctx context.Context, opts ...grpc.CallOption) (RouteGuide_RecordRouteClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_RouteGuide_serviceDesc.Streams[1], c.cc, "/routeguide.RouteGuide/RecordRoute", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &routeGuideRecordRouteClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteGuide_RecordRouteClient interface {
|
||||||
|
Send(*Point) error
|
||||||
|
CloseAndRecv() (*RouteSummary, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type routeGuideRecordRouteClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRecordRouteClient) Send(m *Point) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRecordRouteClient) CloseAndRecv() (*RouteSummary, error) {
|
||||||
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m := new(RouteSummary)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *routeGuideClient) RouteChat(ctx context.Context, opts ...grpc.CallOption) (RouteGuide_RouteChatClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_RouteGuide_serviceDesc.Streams[2], c.cc, "/routeguide.RouteGuide/RouteChat", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &routeGuideRouteChatClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteGuide_RouteChatClient interface {
|
||||||
|
Send(*RouteNote) error
|
||||||
|
Recv() (*RouteNote, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type routeGuideRouteChatClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRouteChatClient) Send(m *RouteNote) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRouteChatClient) Recv() (*RouteNote, error) {
|
||||||
|
m := new(RouteNote)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for RouteGuide service
|
||||||
|
|
||||||
|
type RouteGuideServer interface {
|
||||||
|
// A simple RPC.
|
||||||
|
//
|
||||||
|
// Obtains the feature at a given position.
|
||||||
|
//
|
||||||
|
// A feature with an empty name is returned if there's no feature at the given
|
||||||
|
// position.
|
||||||
|
GetFeature(context.Context, *Point) (*Feature, error)
|
||||||
|
// A server-to-client streaming RPC.
|
||||||
|
//
|
||||||
|
// Obtains the Features available within the given Rectangle. Results are
|
||||||
|
// streamed rather than returned at once (e.g. in a response message with a
|
||||||
|
// repeated field), as the rectangle may cover a large area and contain a
|
||||||
|
// huge number of features.
|
||||||
|
ListFeatures(*Rectangle, RouteGuide_ListFeaturesServer) error
|
||||||
|
// A client-to-server streaming RPC.
|
||||||
|
//
|
||||||
|
// Accepts a stream of Points on a route being traversed, returning a
|
||||||
|
// RouteSummary when traversal is completed.
|
||||||
|
RecordRoute(RouteGuide_RecordRouteServer) error
|
||||||
|
// A Bidirectional streaming RPC.
|
||||||
|
//
|
||||||
|
// Accepts a stream of RouteNotes sent while a route is being traversed,
|
||||||
|
// while receiving other RouteNotes (e.g. from other users).
|
||||||
|
RouteChat(RouteGuide_RouteChatServer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterRouteGuideServer(s *grpc.Server, srv RouteGuideServer) {
|
||||||
|
s.RegisterService(&_RouteGuide_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _RouteGuide_GetFeature_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(Point)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(RouteGuideServer).GetFeature(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/routeguide.RouteGuide/GetFeature",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(RouteGuideServer).GetFeature(ctx, req.(*Point))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _RouteGuide_ListFeatures_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
m := new(Rectangle)
|
||||||
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return srv.(RouteGuideServer).ListFeatures(m, &routeGuideListFeaturesServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteGuide_ListFeaturesServer interface {
|
||||||
|
Send(*Feature) error
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type routeGuideListFeaturesServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideListFeaturesServer) Send(m *Feature) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _RouteGuide_RecordRoute_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(RouteGuideServer).RecordRoute(&routeGuideRecordRouteServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteGuide_RecordRouteServer interface {
|
||||||
|
SendAndClose(*RouteSummary) error
|
||||||
|
Recv() (*Point, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type routeGuideRecordRouteServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRecordRouteServer) SendAndClose(m *RouteSummary) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRecordRouteServer) Recv() (*Point, error) {
|
||||||
|
m := new(Point)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _RouteGuide_RouteChat_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(RouteGuideServer).RouteChat(&routeGuideRouteChatServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteGuide_RouteChatServer interface {
|
||||||
|
Send(*RouteNote) error
|
||||||
|
Recv() (*RouteNote, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type routeGuideRouteChatServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRouteChatServer) Send(m *RouteNote) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *routeGuideRouteChatServer) Recv() (*RouteNote, error) {
|
||||||
|
m := new(RouteNote)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _RouteGuide_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "routeguide.RouteGuide",
|
||||||
|
HandlerType: (*RouteGuideServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "GetFeature",
|
||||||
|
Handler: _RouteGuide_GetFeature_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "ListFeatures",
|
||||||
|
Handler: _RouteGuide_ListFeatures_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
StreamName: "RecordRoute",
|
||||||
|
Handler: _RouteGuide_RecordRoute_Handler,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
StreamName: "RouteChat",
|
||||||
|
Handler: _RouteGuide_RouteChat_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: fileDescriptor0,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("route_guide.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 404 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x53, 0xc1, 0x4a, 0xeb, 0x40,
|
||||||
|
0x14, 0xed, 0xf4, 0xb5, 0xaf, 0x2f, 0x37, 0x79, 0x3c, 0x3a, 0x0f, 0x21, 0x54, 0x41, 0x8d, 0x9b,
|
||||||
|
0x6e, 0x0c, 0xa5, 0x82, 0x4b, 0xc5, 0x16, 0xec, 0xa6, 0x48, 0x8d, 0xdd, 0x97, 0x31, 0x19, 0xd3,
|
||||||
|
0x81, 0x24, 0x13, 0x92, 0x09, 0xe8, 0x07, 0xf8, 0x05, 0xfe, 0xb0, 0x93, 0xc9, 0xa4, 0x4d, 0xb5,
|
||||||
|
0xc5, 0x5d, 0xe6, 0xdc, 0x73, 0xee, 0x3d, 0xf7, 0x5c, 0x02, 0xfd, 0x8c, 0x17, 0x82, 0xae, 0xc2,
|
||||||
|
0x82, 0x05, 0xd4, 0x4d, 0x33, 0x2e, 0x38, 0x06, 0x05, 0x29, 0xc4, 0xb9, 0x83, 0xee, 0x82, 0xb3,
|
||||||
|
0x44, 0xe0, 0x01, 0xfc, 0x89, 0x88, 0x60, 0xa2, 0x08, 0xa8, 0x8d, 0xce, 0xd0, 0xb0, 0xeb, 0x6d,
|
||||||
|
0xde, 0xf8, 0x04, 0x8c, 0x88, 0x27, 0x61, 0x55, 0x6c, 0xab, 0xe2, 0x16, 0x70, 0x1e, 0xc1, 0xf0,
|
||||||
|
0xa8, 0x2f, 0x48, 0x12, 0x46, 0x14, 0x9f, 0x43, 0x3b, 0xe2, 0xaa, 0x81, 0x39, 0xee, 0xbb, 0xdb,
|
||||||
|
0x41, 0xae, 0x9a, 0xe2, 0xc9, 0x62, 0x49, 0x59, 0x33, 0xd5, 0x66, 0x3f, 0x65, 0xcd, 0x9c, 0x39,
|
||||||
|
0xf4, 0xee, 0x29, 0x11, 0x45, 0x46, 0x31, 0x86, 0x4e, 0x42, 0xe2, 0xca, 0x93, 0xe1, 0xa9, 0x6f,
|
||||||
|
0x7c, 0x29, 0xbd, 0x72, 0x5f, 0xba, 0xe3, 0xc9, 0xe1, 0x3e, 0x1b, 0x8a, 0xb3, 0x94, 0x06, 0xcb,
|
||||||
|
0xea, 0x03, 0x17, 0xbb, 0x5a, 0xf4, 0xa3, 0x16, 0xdb, 0xd0, 0x8b, 0x69, 0x9e, 0x93, 0xb0, 0x5a,
|
||||||
|
0xdc, 0xf0, 0xea, 0xa7, 0xf3, 0x81, 0xc0, 0x52, 0x6d, 0x9f, 0x8a, 0x38, 0x26, 0xd9, 0x1b, 0x3e,
|
||||||
|
0x05, 0x33, 0x2d, 0xd5, 0x2b, 0x9f, 0x17, 0x89, 0xd0, 0x21, 0x82, 0x82, 0xa6, 0x25, 0x82, 0x2f,
|
||||||
|
0xe0, 0xef, 0x4b, 0xb5, 0x95, 0xa6, 0x54, 0x51, 0x5a, 0x1a, 0xac, 0x48, 0xf2, 0x0e, 0x01, 0xcb,
|
||||||
|
0x65, 0x9a, 0x3e, 0xb5, 0x7f, 0x55, 0x77, 0xa8, 0xdf, 0x32, 0x39, 0x8b, 0x46, 0x24, 0xcd, 0x69,
|
||||||
|
0xb0, 0x12, 0x4c, 0x66, 0xd2, 0x51, 0x75, 0x53, 0x63, 0x4b, 0x09, 0x8d, 0xdf, 0xdb, 0x00, 0xca,
|
||||||
|
0xd5, 0xac, 0x5c, 0x07, 0x5f, 0x03, 0xcc, 0xa8, 0xa8, 0xb3, 0xfc, 0xbe, 0xe9, 0xe0, 0x7f, 0x13,
|
||||||
|
0xd2, 0x3c, 0xa7, 0x85, 0x6f, 0xc0, 0x9a, 0xcb, 0xa9, 0x1a, 0xc8, 0xf1, 0x51, 0x93, 0xb6, 0xb9,
|
||||||
|
0xf6, 0x01, 0xf5, 0x08, 0x49, 0xbd, 0x29, 0x59, 0x3c, 0x0b, 0x94, 0x97, 0x7d, 0x83, 0xed, 0x9d,
|
||||||
|
0x8e, 0x8d, 0x1c, 0x9d, 0xd6, 0x10, 0xe1, 0x5b, 0x7d, 0xb2, 0xe9, 0x9a, 0x88, 0x2f, 0xc3, 0xeb,
|
||||||
|
0x4b, 0x0e, 0xf6, 0xc3, 0xa5, 0x7c, 0x84, 0x26, 0x23, 0x38, 0x66, 0xdc, 0x0d, 0xb3, 0xd4, 0x77,
|
||||||
|
0xe9, 0x2b, 0x89, 0xd3, 0x88, 0xe6, 0x0d, 0xfa, 0xe4, 0xdf, 0x36, 0xa3, 0x45, 0xf9, 0x4f, 0x2c,
|
||||||
|
0xd0, 0xf3, 0x6f, 0xf5, 0x73, 0x5c, 0x7d, 0x06, 0x00, 0x00, 0xff, 0xff, 0xc8, 0xe4, 0xef, 0xe6,
|
||||||
|
0x31, 0x03, 0x00, 0x00,
|
||||||
|
}
|
125
vendor/google.golang.org/grpc/examples/route_guide/routeguide/route_guide.proto
generated
vendored
Normal file
125
vendor/google.golang.org/grpc/examples/route_guide/routeguide/route_guide.proto
generated
vendored
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
// 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";
|
||||||
|
|
||||||
|
option java_multiple_files = true;
|
||||||
|
option java_package = "io.grpc.examples.routeguide";
|
||||||
|
option java_outer_classname = "RouteGuideProto";
|
||||||
|
|
||||||
|
package routeguide;
|
||||||
|
|
||||||
|
// Interface exported by the server.
|
||||||
|
service RouteGuide {
|
||||||
|
// A simple RPC.
|
||||||
|
//
|
||||||
|
// Obtains the feature at a given position.
|
||||||
|
//
|
||||||
|
// A feature with an empty name is returned if there's no feature at the given
|
||||||
|
// position.
|
||||||
|
rpc GetFeature(Point) returns (Feature) {}
|
||||||
|
|
||||||
|
// A server-to-client streaming RPC.
|
||||||
|
//
|
||||||
|
// Obtains the Features available within the given Rectangle. Results are
|
||||||
|
// streamed rather than returned at once (e.g. in a response message with a
|
||||||
|
// repeated field), as the rectangle may cover a large area and contain a
|
||||||
|
// huge number of features.
|
||||||
|
rpc ListFeatures(Rectangle) returns (stream Feature) {}
|
||||||
|
|
||||||
|
// A client-to-server streaming RPC.
|
||||||
|
//
|
||||||
|
// Accepts a stream of Points on a route being traversed, returning a
|
||||||
|
// RouteSummary when traversal is completed.
|
||||||
|
rpc RecordRoute(stream Point) returns (RouteSummary) {}
|
||||||
|
|
||||||
|
// A Bidirectional streaming RPC.
|
||||||
|
//
|
||||||
|
// Accepts a stream of RouteNotes sent while a route is being traversed,
|
||||||
|
// while receiving other RouteNotes (e.g. from other users).
|
||||||
|
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Points are represented as latitude-longitude pairs in the E7 representation
|
||||||
|
// (degrees multiplied by 10**7 and rounded to the nearest integer).
|
||||||
|
// Latitudes should be in the range +/- 90 degrees and longitude should be in
|
||||||
|
// the range +/- 180 degrees (inclusive).
|
||||||
|
message Point {
|
||||||
|
int32 latitude = 1;
|
||||||
|
int32 longitude = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A latitude-longitude rectangle, represented as two diagonally opposite
|
||||||
|
// points "lo" and "hi".
|
||||||
|
message Rectangle {
|
||||||
|
// One corner of the rectangle.
|
||||||
|
Point lo = 1;
|
||||||
|
|
||||||
|
// The other corner of the rectangle.
|
||||||
|
Point hi = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A feature names something at a given point.
|
||||||
|
//
|
||||||
|
// If a feature could not be named, the name is empty.
|
||||||
|
message Feature {
|
||||||
|
// The name of the feature.
|
||||||
|
string name = 1;
|
||||||
|
|
||||||
|
// The point where the feature is detected.
|
||||||
|
Point location = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A RouteNote is a message sent while at a given point.
|
||||||
|
message RouteNote {
|
||||||
|
// The location from which the message is sent.
|
||||||
|
Point location = 1;
|
||||||
|
|
||||||
|
// The message to be sent.
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A RouteSummary is received in response to a RecordRoute rpc.
|
||||||
|
//
|
||||||
|
// It contains the number of individual points received, the number of
|
||||||
|
// detected features, and the total distance covered as the cumulative sum of
|
||||||
|
// the distance between each point.
|
||||||
|
message RouteSummary {
|
||||||
|
// The number of points received.
|
||||||
|
int32 point_count = 1;
|
||||||
|
|
||||||
|
// The number of known features passed while traversing the route.
|
||||||
|
int32 feature_count = 2;
|
||||||
|
|
||||||
|
// The distance covered in metres.
|
||||||
|
int32 distance = 3;
|
||||||
|
|
||||||
|
// The duration of the traversal in seconds.
|
||||||
|
int32 elapsed_time = 4;
|
||||||
|
}
|
239
vendor/google.golang.org/grpc/examples/route_guide/server/server.go
generated
vendored
Normal file
239
vendor/google.golang.org/grpc/examples/route_guide/server/server.go
generated
vendored
Normal file
|
@ -0,0 +1,239 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package main implements a simple gRPC server that demonstrates how to use gRPC-Go libraries
|
||||||
|
// to perform unary, client streaming, server streaming and full duplex RPCs.
|
||||||
|
//
|
||||||
|
// It implements the route guide service whose definition can be found in proto/route_guide.proto.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
|
pb "google.golang.org/grpc/examples/route_guide/routeguide"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
|
||||||
|
certFile = flag.String("cert_file", "testdata/server1.pem", "The TLS cert file")
|
||||||
|
keyFile = flag.String("key_file", "testdata/server1.key", "The TLS key file")
|
||||||
|
jsonDBFile = flag.String("json_db_file", "testdata/route_guide_db.json", "A json file containing a list of features")
|
||||||
|
port = flag.Int("port", 10000, "The server port")
|
||||||
|
)
|
||||||
|
|
||||||
|
type routeGuideServer struct {
|
||||||
|
savedFeatures []*pb.Feature
|
||||||
|
routeNotes map[string][]*pb.RouteNote
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFeature returns the feature at the given point.
|
||||||
|
func (s *routeGuideServer) GetFeature(ctx context.Context, point *pb.Point) (*pb.Feature, error) {
|
||||||
|
for _, feature := range s.savedFeatures {
|
||||||
|
if proto.Equal(feature.Location, point) {
|
||||||
|
return feature, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No feature was found, return an unnamed feature
|
||||||
|
return &pb.Feature{Location: point}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListFeatures lists all features contained within the given bounding Rectangle.
|
||||||
|
func (s *routeGuideServer) ListFeatures(rect *pb.Rectangle, stream pb.RouteGuide_ListFeaturesServer) error {
|
||||||
|
for _, feature := range s.savedFeatures {
|
||||||
|
if inRange(feature.Location, rect) {
|
||||||
|
if err := stream.Send(feature); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecordRoute records a route composited of a sequence of points.
|
||||||
|
//
|
||||||
|
// It gets a stream of points, and responds with statistics about the "trip":
|
||||||
|
// number of points, number of known features visited, total distance traveled, and
|
||||||
|
// total time spent.
|
||||||
|
func (s *routeGuideServer) RecordRoute(stream pb.RouteGuide_RecordRouteServer) error {
|
||||||
|
var pointCount, featureCount, distance int32
|
||||||
|
var lastPoint *pb.Point
|
||||||
|
startTime := time.Now()
|
||||||
|
for {
|
||||||
|
point, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
endTime := time.Now()
|
||||||
|
return stream.SendAndClose(&pb.RouteSummary{
|
||||||
|
PointCount: pointCount,
|
||||||
|
FeatureCount: featureCount,
|
||||||
|
Distance: distance,
|
||||||
|
ElapsedTime: int32(endTime.Sub(startTime).Seconds()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pointCount++
|
||||||
|
for _, feature := range s.savedFeatures {
|
||||||
|
if proto.Equal(feature.Location, point) {
|
||||||
|
featureCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if lastPoint != nil {
|
||||||
|
distance += calcDistance(lastPoint, point)
|
||||||
|
}
|
||||||
|
lastPoint = point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RouteChat receives a stream of message/location pairs, and responds with a stream of all
|
||||||
|
// previous messages at each of those locations.
|
||||||
|
func (s *routeGuideServer) RouteChat(stream pb.RouteGuide_RouteChatServer) error {
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
key := serialize(in.Location)
|
||||||
|
if _, present := s.routeNotes[key]; !present {
|
||||||
|
s.routeNotes[key] = []*pb.RouteNote{in}
|
||||||
|
} else {
|
||||||
|
s.routeNotes[key] = append(s.routeNotes[key], in)
|
||||||
|
}
|
||||||
|
for _, note := range s.routeNotes[key] {
|
||||||
|
if err := stream.Send(note); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadFeatures loads features from a JSON file.
|
||||||
|
func (s *routeGuideServer) loadFeatures(filePath string) {
|
||||||
|
file, err := ioutil.ReadFile(filePath)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to load default features: %v", err)
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(file, &s.savedFeatures); err != nil {
|
||||||
|
grpclog.Fatalf("Failed to load default features: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func toRadians(num float64) float64 {
|
||||||
|
return num * math.Pi / float64(180)
|
||||||
|
}
|
||||||
|
|
||||||
|
// calcDistance calculates the distance between two points using the "haversine" formula.
|
||||||
|
// This code was taken from http://www.movable-type.co.uk/scripts/latlong.html.
|
||||||
|
func calcDistance(p1 *pb.Point, p2 *pb.Point) int32 {
|
||||||
|
const CordFactor float64 = 1e7
|
||||||
|
const R float64 = float64(6371000) // metres
|
||||||
|
lat1 := float64(p1.Latitude) / CordFactor
|
||||||
|
lat2 := float64(p2.Latitude) / CordFactor
|
||||||
|
lng1 := float64(p1.Longitude) / CordFactor
|
||||||
|
lng2 := float64(p2.Longitude) / CordFactor
|
||||||
|
φ1 := toRadians(lat1)
|
||||||
|
φ2 := toRadians(lat2)
|
||||||
|
Δφ := toRadians(lat2 - lat1)
|
||||||
|
Δλ := toRadians(lng2 - lng1)
|
||||||
|
|
||||||
|
a := math.Sin(Δφ/2)*math.Sin(Δφ/2) +
|
||||||
|
math.Cos(φ1)*math.Cos(φ2)*
|
||||||
|
math.Sin(Δλ/2)*math.Sin(Δλ/2)
|
||||||
|
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
|
||||||
|
|
||||||
|
distance := R * c
|
||||||
|
return int32(distance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inRange(point *pb.Point, rect *pb.Rectangle) bool {
|
||||||
|
left := math.Min(float64(rect.Lo.Longitude), float64(rect.Hi.Longitude))
|
||||||
|
right := math.Max(float64(rect.Lo.Longitude), float64(rect.Hi.Longitude))
|
||||||
|
top := math.Max(float64(rect.Lo.Latitude), float64(rect.Hi.Latitude))
|
||||||
|
bottom := math.Min(float64(rect.Lo.Latitude), float64(rect.Hi.Latitude))
|
||||||
|
|
||||||
|
if float64(point.Longitude) >= left &&
|
||||||
|
float64(point.Longitude) <= right &&
|
||||||
|
float64(point.Latitude) >= bottom &&
|
||||||
|
float64(point.Latitude) <= top {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func serialize(point *pb.Point) string {
|
||||||
|
return fmt.Sprintf("%d %d", point.Latitude, point.Longitude)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newServer() *routeGuideServer {
|
||||||
|
s := new(routeGuideServer)
|
||||||
|
s.loadFeatures(*jsonDBFile)
|
||||||
|
s.routeNotes = make(map[string][]*pb.RouteNote)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
var opts []grpc.ServerOption
|
||||||
|
if *tls {
|
||||||
|
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to generate credentials %v", err)
|
||||||
|
}
|
||||||
|
opts = []grpc.ServerOption{grpc.Creds(creds)}
|
||||||
|
}
|
||||||
|
grpcServer := grpc.NewServer(opts...)
|
||||||
|
pb.RegisterRouteGuideServer(grpcServer, newServer())
|
||||||
|
grpcServer.Serve(lis)
|
||||||
|
}
|
15
vendor/google.golang.org/grpc/examples/route_guide/testdata/ca.pem
generated
vendored
Normal file
15
vendor/google.golang.org/grpc/examples/route_guide/testdata/ca.pem
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICSjCCAbOgAwIBAgIJAJHGGR4dGioHMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV
|
||||||
|
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||||
|
aWRnaXRzIFB0eSBMdGQxDzANBgNVBAMTBnRlc3RjYTAeFw0xNDExMTEyMjMxMjla
|
||||||
|
Fw0yNDExMDgyMjMxMjlaMFYxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0
|
||||||
|
YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxDzANBgNVBAMT
|
||||||
|
BnRlc3RjYTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwEDfBV5MYdlHVHJ7
|
||||||
|
+L4nxrZy7mBfAVXpOc5vMYztssUI7mL2/iYujiIXM+weZYNTEpLdjyJdu7R5gGUu
|
||||||
|
g1jSVK/EPHfc74O7AyZU34PNIP4Sh33N+/A5YexrNgJlPY+E3GdVYi4ldWJjgkAd
|
||||||
|
Qah2PH5ACLrIIC6tRka9hcaBlIECAwEAAaMgMB4wDAYDVR0TBAUwAwEB/zAOBgNV
|
||||||
|
HQ8BAf8EBAMCAgQwDQYJKoZIhvcNAQELBQADgYEAHzC7jdYlzAVmddi/gdAeKPau
|
||||||
|
sPBG/C2HCWqHzpCUHcKuvMzDVkY/MP2o6JIW2DBbY64bO/FceExhjcykgaYtCH/m
|
||||||
|
oIU63+CFOTtR7otyQAWHqXa7q4SbCDlG7DyRFxqG0txPtGvy12lgldA2+RgcigQG
|
||||||
|
Dfcog5wrJytaQ6UA0wE=
|
||||||
|
-----END CERTIFICATE-----
|
601
vendor/google.golang.org/grpc/examples/route_guide/testdata/route_guide_db.json
generated
vendored
Normal file
601
vendor/google.golang.org/grpc/examples/route_guide/testdata/route_guide_db.json
generated
vendored
Normal file
|
@ -0,0 +1,601 @@
|
||||||
|
[{
|
||||||
|
"location": {
|
||||||
|
"latitude": 407838351,
|
||||||
|
"longitude": -746143763
|
||||||
|
},
|
||||||
|
"name": "Patriots Path, Mendham, NJ 07945, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 408122808,
|
||||||
|
"longitude": -743999179
|
||||||
|
},
|
||||||
|
"name": "101 New Jersey 10, Whippany, NJ 07981, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 413628156,
|
||||||
|
"longitude": -749015468
|
||||||
|
},
|
||||||
|
"name": "U.S. 6, Shohola, PA 18458, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 419999544,
|
||||||
|
"longitude": -740371136
|
||||||
|
},
|
||||||
|
"name": "5 Conners Road, Kingston, NY 12401, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 414008389,
|
||||||
|
"longitude": -743951297
|
||||||
|
},
|
||||||
|
"name": "Mid Hudson Psychiatric Center, New Hampton, NY 10958, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 419611318,
|
||||||
|
"longitude": -746524769
|
||||||
|
},
|
||||||
|
"name": "287 Flugertown Road, Livingston Manor, NY 12758, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406109563,
|
||||||
|
"longitude": -742186778
|
||||||
|
},
|
||||||
|
"name": "4001 Tremley Point Road, Linden, NJ 07036, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 416802456,
|
||||||
|
"longitude": -742370183
|
||||||
|
},
|
||||||
|
"name": "352 South Mountain Road, Wallkill, NY 12589, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412950425,
|
||||||
|
"longitude": -741077389
|
||||||
|
},
|
||||||
|
"name": "Bailey Turn Road, Harriman, NY 10926, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412144655,
|
||||||
|
"longitude": -743949739
|
||||||
|
},
|
||||||
|
"name": "193-199 Wawayanda Road, Hewitt, NJ 07421, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 415736605,
|
||||||
|
"longitude": -742847522
|
||||||
|
},
|
||||||
|
"name": "406-496 Ward Avenue, Pine Bush, NY 12566, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 413843930,
|
||||||
|
"longitude": -740501726
|
||||||
|
},
|
||||||
|
"name": "162 Merrill Road, Highland Mills, NY 10930, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 410873075,
|
||||||
|
"longitude": -744459023
|
||||||
|
},
|
||||||
|
"name": "Clinton Road, West Milford, NJ 07480, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412346009,
|
||||||
|
"longitude": -744026814
|
||||||
|
},
|
||||||
|
"name": "16 Old Brook Lane, Warwick, NY 10990, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 402948455,
|
||||||
|
"longitude": -747903913
|
||||||
|
},
|
||||||
|
"name": "3 Drake Lane, Pennington, NJ 08534, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406337092,
|
||||||
|
"longitude": -740122226
|
||||||
|
},
|
||||||
|
"name": "6324 8th Avenue, Brooklyn, NY 11220, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406421967,
|
||||||
|
"longitude": -747727624
|
||||||
|
},
|
||||||
|
"name": "1 Merck Access Road, Whitehouse Station, NJ 08889, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 416318082,
|
||||||
|
"longitude": -749677716
|
||||||
|
},
|
||||||
|
"name": "78-98 Schalck Road, Narrowsburg, NY 12764, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 415301720,
|
||||||
|
"longitude": -748416257
|
||||||
|
},
|
||||||
|
"name": "282 Lakeview Drive Road, Highland Lake, NY 12743, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 402647019,
|
||||||
|
"longitude": -747071791
|
||||||
|
},
|
||||||
|
"name": "330 Evelyn Avenue, Hamilton Township, NJ 08619, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412567807,
|
||||||
|
"longitude": -741058078
|
||||||
|
},
|
||||||
|
"name": "New York State Reference Route 987E, Southfields, NY 10975, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 416855156,
|
||||||
|
"longitude": -744420597
|
||||||
|
},
|
||||||
|
"name": "103-271 Tempaloni Road, Ellenville, NY 12428, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404663628,
|
||||||
|
"longitude": -744820157
|
||||||
|
},
|
||||||
|
"name": "1300 Airport Road, North Brunswick Township, NJ 08902, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 407113723,
|
||||||
|
"longitude": -749746483
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 402133926,
|
||||||
|
"longitude": -743613249
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 400273442,
|
||||||
|
"longitude": -741220915
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 411236786,
|
||||||
|
"longitude": -744070769
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 411633782,
|
||||||
|
"longitude": -746784970
|
||||||
|
},
|
||||||
|
"name": "211-225 Plains Road, Augusta, NJ 07822, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 415830701,
|
||||||
|
"longitude": -742952812
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 413447164,
|
||||||
|
"longitude": -748712898
|
||||||
|
},
|
||||||
|
"name": "165 Pedersen Ridge Road, Milford, PA 18337, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 405047245,
|
||||||
|
"longitude": -749800722
|
||||||
|
},
|
||||||
|
"name": "100-122 Locktown Road, Frenchtown, NJ 08825, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 418858923,
|
||||||
|
"longitude": -746156790
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 417951888,
|
||||||
|
"longitude": -748484944
|
||||||
|
},
|
||||||
|
"name": "650-652 Willi Hill Road, Swan Lake, NY 12783, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 407033786,
|
||||||
|
"longitude": -743977337
|
||||||
|
},
|
||||||
|
"name": "26 East 3rd Street, New Providence, NJ 07974, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 417548014,
|
||||||
|
"longitude": -740075041
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 410395868,
|
||||||
|
"longitude": -744972325
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404615353,
|
||||||
|
"longitude": -745129803
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406589790,
|
||||||
|
"longitude": -743560121
|
||||||
|
},
|
||||||
|
"name": "611 Lawrence Avenue, Westfield, NJ 07090, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 414653148,
|
||||||
|
"longitude": -740477477
|
||||||
|
},
|
||||||
|
"name": "18 Lannis Avenue, New Windsor, NY 12553, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 405957808,
|
||||||
|
"longitude": -743255336
|
||||||
|
},
|
||||||
|
"name": "82-104 Amherst Avenue, Colonia, NJ 07067, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 411733589,
|
||||||
|
"longitude": -741648093
|
||||||
|
},
|
||||||
|
"name": "170 Seven Lakes Drive, Sloatsburg, NY 10974, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412676291,
|
||||||
|
"longitude": -742606606
|
||||||
|
},
|
||||||
|
"name": "1270 Lakes Road, Monroe, NY 10950, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 409224445,
|
||||||
|
"longitude": -748286738
|
||||||
|
},
|
||||||
|
"name": "509-535 Alphano Road, Great Meadows, NJ 07838, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406523420,
|
||||||
|
"longitude": -742135517
|
||||||
|
},
|
||||||
|
"name": "652 Garden Street, Elizabeth, NJ 07202, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 401827388,
|
||||||
|
"longitude": -740294537
|
||||||
|
},
|
||||||
|
"name": "349 Sea Spray Court, Neptune City, NJ 07753, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 410564152,
|
||||||
|
"longitude": -743685054
|
||||||
|
},
|
||||||
|
"name": "13-17 Stanley Street, West Milford, NJ 07480, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 408472324,
|
||||||
|
"longitude": -740726046
|
||||||
|
},
|
||||||
|
"name": "47 Industrial Avenue, Teterboro, NJ 07608, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412452168,
|
||||||
|
"longitude": -740214052
|
||||||
|
},
|
||||||
|
"name": "5 White Oak Lane, Stony Point, NY 10980, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 409146138,
|
||||||
|
"longitude": -746188906
|
||||||
|
},
|
||||||
|
"name": "Berkshire Valley Management Area Trail, Jefferson, NJ, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404701380,
|
||||||
|
"longitude": -744781745
|
||||||
|
},
|
||||||
|
"name": "1007 Jersey Avenue, New Brunswick, NJ 08901, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 409642566,
|
||||||
|
"longitude": -746017679
|
||||||
|
},
|
||||||
|
"name": "6 East Emerald Isle Drive, Lake Hopatcong, NJ 07849, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 408031728,
|
||||||
|
"longitude": -748645385
|
||||||
|
},
|
||||||
|
"name": "1358-1474 New Jersey 57, Port Murray, NJ 07865, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 413700272,
|
||||||
|
"longitude": -742135189
|
||||||
|
},
|
||||||
|
"name": "367 Prospect Road, Chester, NY 10918, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404310607,
|
||||||
|
"longitude": -740282632
|
||||||
|
},
|
||||||
|
"name": "10 Simon Lake Drive, Atlantic Highlands, NJ 07716, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 409319800,
|
||||||
|
"longitude": -746201391
|
||||||
|
},
|
||||||
|
"name": "11 Ward Street, Mount Arlington, NJ 07856, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406685311,
|
||||||
|
"longitude": -742108603
|
||||||
|
},
|
||||||
|
"name": "300-398 Jefferson Avenue, Elizabeth, NJ 07201, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 419018117,
|
||||||
|
"longitude": -749142781
|
||||||
|
},
|
||||||
|
"name": "43 Dreher Road, Roscoe, NY 12776, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412856162,
|
||||||
|
"longitude": -745148837
|
||||||
|
},
|
||||||
|
"name": "Swan Street, Pine Island, NY 10969, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 416560744,
|
||||||
|
"longitude": -746721964
|
||||||
|
},
|
||||||
|
"name": "66 Pleasantview Avenue, Monticello, NY 12701, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 405314270,
|
||||||
|
"longitude": -749836354
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 414219548,
|
||||||
|
"longitude": -743327440
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 415534177,
|
||||||
|
"longitude": -742900616
|
||||||
|
},
|
||||||
|
"name": "565 Winding Hills Road, Montgomery, NY 12549, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406898530,
|
||||||
|
"longitude": -749127080
|
||||||
|
},
|
||||||
|
"name": "231 Rocky Run Road, Glen Gardner, NJ 08826, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 407586880,
|
||||||
|
"longitude": -741670168
|
||||||
|
},
|
||||||
|
"name": "100 Mount Pleasant Avenue, Newark, NJ 07104, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 400106455,
|
||||||
|
"longitude": -742870190
|
||||||
|
},
|
||||||
|
"name": "517-521 Huntington Drive, Manchester Township, NJ 08759, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 400066188,
|
||||||
|
"longitude": -746793294
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 418803880,
|
||||||
|
"longitude": -744102673
|
||||||
|
},
|
||||||
|
"name": "40 Mountain Road, Napanoch, NY 12458, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 414204288,
|
||||||
|
"longitude": -747895140
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 414777405,
|
||||||
|
"longitude": -740615601
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 415464475,
|
||||||
|
"longitude": -747175374
|
||||||
|
},
|
||||||
|
"name": "48 North Road, Forestburgh, NY 12777, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404062378,
|
||||||
|
"longitude": -746376177
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 405688272,
|
||||||
|
"longitude": -749285130
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 400342070,
|
||||||
|
"longitude": -748788996
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 401809022,
|
||||||
|
"longitude": -744157964
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404226644,
|
||||||
|
"longitude": -740517141
|
||||||
|
},
|
||||||
|
"name": "9 Thompson Avenue, Leonardo, NJ 07737, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 410322033,
|
||||||
|
"longitude": -747871659
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 407100674,
|
||||||
|
"longitude": -747742727
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 418811433,
|
||||||
|
"longitude": -741718005
|
||||||
|
},
|
||||||
|
"name": "213 Bush Road, Stone Ridge, NY 12484, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 415034302,
|
||||||
|
"longitude": -743850945
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 411349992,
|
||||||
|
"longitude": -743694161
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404839914,
|
||||||
|
"longitude": -744759616
|
||||||
|
},
|
||||||
|
"name": "1-17 Bergen Court, New Brunswick, NJ 08901, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 414638017,
|
||||||
|
"longitude": -745957854
|
||||||
|
},
|
||||||
|
"name": "35 Oakland Valley Road, Cuddebackville, NY 12729, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412127800,
|
||||||
|
"longitude": -740173578
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 401263460,
|
||||||
|
"longitude": -747964303
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 412843391,
|
||||||
|
"longitude": -749086026
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 418512773,
|
||||||
|
"longitude": -743067823
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404318328,
|
||||||
|
"longitude": -740835638
|
||||||
|
},
|
||||||
|
"name": "42-102 Main Street, Belford, NJ 07718, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 419020746,
|
||||||
|
"longitude": -741172328
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404080723,
|
||||||
|
"longitude": -746119569
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 401012643,
|
||||||
|
"longitude": -744035134
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 404306372,
|
||||||
|
"longitude": -741079661
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 403966326,
|
||||||
|
"longitude": -748519297
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 405002031,
|
||||||
|
"longitude": -748407866
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 409532885,
|
||||||
|
"longitude": -742200683
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 416851321,
|
||||||
|
"longitude": -742674555
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 406411633,
|
||||||
|
"longitude": -741722051
|
||||||
|
},
|
||||||
|
"name": "3387 Richmond Terrace, Staten Island, NY 10303, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 413069058,
|
||||||
|
"longitude": -744597778
|
||||||
|
},
|
||||||
|
"name": "261 Van Sickle Road, Goshen, NY 10924, USA"
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 418465462,
|
||||||
|
"longitude": -746859398
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 411733222,
|
||||||
|
"longitude": -744228360
|
||||||
|
},
|
||||||
|
"name": ""
|
||||||
|
}, {
|
||||||
|
"location": {
|
||||||
|
"latitude": 410248224,
|
||||||
|
"longitude": -747127767
|
||||||
|
},
|
||||||
|
"name": "3 Hasta Way, Newton, NJ 07860, USA"
|
||||||
|
}]
|
16
vendor/google.golang.org/grpc/examples/route_guide/testdata/server1.key
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/examples/route_guide/testdata/server1.key
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAOHDFScoLCVJpYDD
|
||||||
|
M4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1BgzkWF+slf
|
||||||
|
3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd9N8YwbBY
|
||||||
|
AckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAECgYAn7qGnM2vbjJNBm0VZCkOkTIWm
|
||||||
|
V10okw7EPJrdL2mkre9NasghNXbE1y5zDshx5Nt3KsazKOxTT8d0Jwh/3KbaN+YY
|
||||||
|
tTCbKGW0pXDRBhwUHRcuRzScjli8Rih5UOCiZkhefUTcRb6xIhZJuQy71tjaSy0p
|
||||||
|
dHZRmYyBYO2YEQ8xoQJBAPrJPhMBkzmEYFtyIEqAxQ/o/A6E+E4w8i+KM7nQCK7q
|
||||||
|
K4JXzyXVAjLfyBZWHGM2uro/fjqPggGD6QH1qXCkI4MCQQDmdKeb2TrKRh5BY1LR
|
||||||
|
81aJGKcJ2XbcDu6wMZK4oqWbTX2KiYn9GB0woM6nSr/Y6iy1u145YzYxEV/iMwff
|
||||||
|
DJULAkB8B2MnyzOg0pNFJqBJuH29bKCcHa8gHJzqXhNO5lAlEbMK95p/P2Wi+4Hd
|
||||||
|
aiEIAF1BF326QJcvYKmwSmrORp85AkAlSNxRJ50OWrfMZnBgzVjDx3xG6KsFQVk2
|
||||||
|
ol6VhqL6dFgKUORFUWBvnKSyhjJxurlPEahV6oo6+A+mPhFY8eUvAkAZQyTdupP3
|
||||||
|
XEFQKctGz+9+gKkemDp7LBBMEMBXrGTLPhpEfcjv/7KPdnFHYmhYeBTBnuVmTVWe
|
||||||
|
F98XJ7tIFfJq
|
||||||
|
-----END PRIVATE KEY-----
|
16
vendor/google.golang.org/grpc/examples/route_guide/testdata/server1.pem
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/examples/route_guide/testdata/server1.pem
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICnDCCAgWgAwIBAgIBBzANBgkqhkiG9w0BAQsFADBWMQswCQYDVQQGEwJBVTET
|
||||||
|
MBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQ
|
||||||
|
dHkgTHRkMQ8wDQYDVQQDEwZ0ZXN0Y2EwHhcNMTUxMTA0MDIyMDI0WhcNMjUxMTAx
|
||||||
|
MDIyMDI0WjBlMQswCQYDVQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNV
|
||||||
|
BAcTB0NoaWNhZ28xFTATBgNVBAoTDEV4YW1wbGUsIENvLjEaMBgGA1UEAxQRKi50
|
||||||
|
ZXN0Lmdvb2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOHDFSco
|
||||||
|
LCVJpYDDM4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1Bg
|
||||||
|
zkWF+slf3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd
|
||||||
|
9N8YwbBYAckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAGjazBpMAkGA1UdEwQCMAAw
|
||||||
|
CwYDVR0PBAQDAgXgME8GA1UdEQRIMEaCECoudGVzdC5nb29nbGUuZnKCGHdhdGVy
|
||||||
|
em9vaS50ZXN0Lmdvb2dsZS5iZYISKi50ZXN0LnlvdXR1YmUuY29thwTAqAEDMA0G
|
||||||
|
CSqGSIb3DQEBCwUAA4GBAJFXVifQNub1LUP4JlnX5lXNlo8FxZ2a12AFQs+bzoJ6
|
||||||
|
hM044EDjqyxUqSbVePK0ni3w1fHQB5rY9yYC5f8G7aqqTY1QOhoUk8ZTSTRpnkTh
|
||||||
|
y4jjdvTZeLDVBlueZUTDRmy2feY5aZIU18vFDK08dTG0A87pppuv1LNIR3loveU8
|
||||||
|
-----END CERTIFICATE-----
|
557
vendor/google.golang.org/grpc/grpclb/grpc_lb_v1/grpclb.pb.go
generated
vendored
Normal file
557
vendor/google.golang.org/grpc/grpclb/grpc_lb_v1/grpclb.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,557 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: grpclb.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpc_lb_v1 is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
grpclb.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
Duration
|
||||||
|
LoadBalanceRequest
|
||||||
|
InitialLoadBalanceRequest
|
||||||
|
ClientStats
|
||||||
|
LoadBalanceResponse
|
||||||
|
InitialLoadBalanceResponse
|
||||||
|
ServerList
|
||||||
|
Server
|
||||||
|
*/
|
||||||
|
package grpc_lb_v1
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
type Duration struct {
|
||||||
|
// Signed seconds of the span of time. Must be from -315,576,000,000
|
||||||
|
// to +315,576,000,000 inclusive.
|
||||||
|
Seconds int64 `protobuf:"varint,1,opt,name=seconds" json:"seconds,omitempty"`
|
||||||
|
// Signed fractions of a second at nanosecond resolution of the span
|
||||||
|
// of time. Durations less than one second are represented with a 0
|
||||||
|
// `seconds` field and a positive or negative `nanos` field. For durations
|
||||||
|
// of one second or more, a non-zero value for the `nanos` field must be
|
||||||
|
// of the same sign as the `seconds` field. Must be from -999,999,999
|
||||||
|
// to +999,999,999 inclusive.
|
||||||
|
Nanos int32 `protobuf:"varint,2,opt,name=nanos" json:"nanos,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Duration) Reset() { *m = Duration{} }
|
||||||
|
func (m *Duration) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Duration) ProtoMessage() {}
|
||||||
|
func (*Duration) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
type LoadBalanceRequest struct {
|
||||||
|
// Types that are valid to be assigned to LoadBalanceRequestType:
|
||||||
|
// *LoadBalanceRequest_InitialRequest
|
||||||
|
// *LoadBalanceRequest_ClientStats
|
||||||
|
LoadBalanceRequestType isLoadBalanceRequest_LoadBalanceRequestType `protobuf_oneof:"load_balance_request_type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadBalanceRequest) Reset() { *m = LoadBalanceRequest{} }
|
||||||
|
func (m *LoadBalanceRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*LoadBalanceRequest) ProtoMessage() {}
|
||||||
|
func (*LoadBalanceRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
type isLoadBalanceRequest_LoadBalanceRequestType interface {
|
||||||
|
isLoadBalanceRequest_LoadBalanceRequestType()
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoadBalanceRequest_InitialRequest struct {
|
||||||
|
InitialRequest *InitialLoadBalanceRequest `protobuf:"bytes,1,opt,name=initial_request,oneof"`
|
||||||
|
}
|
||||||
|
type LoadBalanceRequest_ClientStats struct {
|
||||||
|
ClientStats *ClientStats `protobuf:"bytes,2,opt,name=client_stats,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*LoadBalanceRequest_InitialRequest) isLoadBalanceRequest_LoadBalanceRequestType() {}
|
||||||
|
func (*LoadBalanceRequest_ClientStats) isLoadBalanceRequest_LoadBalanceRequestType() {}
|
||||||
|
|
||||||
|
func (m *LoadBalanceRequest) GetLoadBalanceRequestType() isLoadBalanceRequest_LoadBalanceRequestType {
|
||||||
|
if m != nil {
|
||||||
|
return m.LoadBalanceRequestType
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadBalanceRequest) GetInitialRequest() *InitialLoadBalanceRequest {
|
||||||
|
if x, ok := m.GetLoadBalanceRequestType().(*LoadBalanceRequest_InitialRequest); ok {
|
||||||
|
return x.InitialRequest
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadBalanceRequest) GetClientStats() *ClientStats {
|
||||||
|
if x, ok := m.GetLoadBalanceRequestType().(*LoadBalanceRequest_ClientStats); ok {
|
||||||
|
return x.ClientStats
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*LoadBalanceRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _LoadBalanceRequest_OneofMarshaler, _LoadBalanceRequest_OneofUnmarshaler, _LoadBalanceRequest_OneofSizer, []interface{}{
|
||||||
|
(*LoadBalanceRequest_InitialRequest)(nil),
|
||||||
|
(*LoadBalanceRequest_ClientStats)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadBalanceRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*LoadBalanceRequest)
|
||||||
|
// load_balance_request_type
|
||||||
|
switch x := m.LoadBalanceRequestType.(type) {
|
||||||
|
case *LoadBalanceRequest_InitialRequest:
|
||||||
|
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.InitialRequest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *LoadBalanceRequest_ClientStats:
|
||||||
|
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.ClientStats); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("LoadBalanceRequest.LoadBalanceRequestType has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadBalanceRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*LoadBalanceRequest)
|
||||||
|
switch tag {
|
||||||
|
case 1: // load_balance_request_type.initial_request
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(InitialLoadBalanceRequest)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.LoadBalanceRequestType = &LoadBalanceRequest_InitialRequest{msg}
|
||||||
|
return true, err
|
||||||
|
case 2: // load_balance_request_type.client_stats
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ClientStats)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.LoadBalanceRequestType = &LoadBalanceRequest_ClientStats{msg}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadBalanceRequest_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*LoadBalanceRequest)
|
||||||
|
// load_balance_request_type
|
||||||
|
switch x := m.LoadBalanceRequestType.(type) {
|
||||||
|
case *LoadBalanceRequest_InitialRequest:
|
||||||
|
s := proto.Size(x.InitialRequest)
|
||||||
|
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *LoadBalanceRequest_ClientStats:
|
||||||
|
s := proto.Size(x.ClientStats)
|
||||||
|
n += proto.SizeVarint(2<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
type InitialLoadBalanceRequest struct {
|
||||||
|
// Name of load balanced service (IE, service.grpc.gslb.google.com)
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *InitialLoadBalanceRequest) Reset() { *m = InitialLoadBalanceRequest{} }
|
||||||
|
func (m *InitialLoadBalanceRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*InitialLoadBalanceRequest) ProtoMessage() {}
|
||||||
|
func (*InitialLoadBalanceRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||||
|
|
||||||
|
// Contains client level statistics that are useful to load balancing. Each
|
||||||
|
// count should be reset to zero after reporting the stats.
|
||||||
|
type ClientStats struct {
|
||||||
|
// The total number of requests sent by the client since the last report.
|
||||||
|
TotalRequests int64 `protobuf:"varint,1,opt,name=total_requests" json:"total_requests,omitempty"`
|
||||||
|
// The number of client rpc errors since the last report.
|
||||||
|
ClientRpcErrors int64 `protobuf:"varint,2,opt,name=client_rpc_errors" json:"client_rpc_errors,omitempty"`
|
||||||
|
// The number of dropped requests since the last report.
|
||||||
|
DroppedRequests int64 `protobuf:"varint,3,opt,name=dropped_requests" json:"dropped_requests,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ClientStats) Reset() { *m = ClientStats{} }
|
||||||
|
func (m *ClientStats) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ClientStats) ProtoMessage() {}
|
||||||
|
func (*ClientStats) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||||
|
|
||||||
|
type LoadBalanceResponse struct {
|
||||||
|
// Types that are valid to be assigned to LoadBalanceResponseType:
|
||||||
|
// *LoadBalanceResponse_InitialResponse
|
||||||
|
// *LoadBalanceResponse_ServerList
|
||||||
|
LoadBalanceResponseType isLoadBalanceResponse_LoadBalanceResponseType `protobuf_oneof:"load_balance_response_type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadBalanceResponse) Reset() { *m = LoadBalanceResponse{} }
|
||||||
|
func (m *LoadBalanceResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*LoadBalanceResponse) ProtoMessage() {}
|
||||||
|
func (*LoadBalanceResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||||
|
|
||||||
|
type isLoadBalanceResponse_LoadBalanceResponseType interface {
|
||||||
|
isLoadBalanceResponse_LoadBalanceResponseType()
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoadBalanceResponse_InitialResponse struct {
|
||||||
|
InitialResponse *InitialLoadBalanceResponse `protobuf:"bytes,1,opt,name=initial_response,oneof"`
|
||||||
|
}
|
||||||
|
type LoadBalanceResponse_ServerList struct {
|
||||||
|
ServerList *ServerList `protobuf:"bytes,2,opt,name=server_list,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*LoadBalanceResponse_InitialResponse) isLoadBalanceResponse_LoadBalanceResponseType() {}
|
||||||
|
func (*LoadBalanceResponse_ServerList) isLoadBalanceResponse_LoadBalanceResponseType() {}
|
||||||
|
|
||||||
|
func (m *LoadBalanceResponse) GetLoadBalanceResponseType() isLoadBalanceResponse_LoadBalanceResponseType {
|
||||||
|
if m != nil {
|
||||||
|
return m.LoadBalanceResponseType
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadBalanceResponse) GetInitialResponse() *InitialLoadBalanceResponse {
|
||||||
|
if x, ok := m.GetLoadBalanceResponseType().(*LoadBalanceResponse_InitialResponse); ok {
|
||||||
|
return x.InitialResponse
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LoadBalanceResponse) GetServerList() *ServerList {
|
||||||
|
if x, ok := m.GetLoadBalanceResponseType().(*LoadBalanceResponse_ServerList); ok {
|
||||||
|
return x.ServerList
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*LoadBalanceResponse) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _LoadBalanceResponse_OneofMarshaler, _LoadBalanceResponse_OneofUnmarshaler, _LoadBalanceResponse_OneofSizer, []interface{}{
|
||||||
|
(*LoadBalanceResponse_InitialResponse)(nil),
|
||||||
|
(*LoadBalanceResponse_ServerList)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadBalanceResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*LoadBalanceResponse)
|
||||||
|
// load_balance_response_type
|
||||||
|
switch x := m.LoadBalanceResponseType.(type) {
|
||||||
|
case *LoadBalanceResponse_InitialResponse:
|
||||||
|
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.InitialResponse); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *LoadBalanceResponse_ServerList:
|
||||||
|
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.ServerList); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("LoadBalanceResponse.LoadBalanceResponseType has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadBalanceResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*LoadBalanceResponse)
|
||||||
|
switch tag {
|
||||||
|
case 1: // load_balance_response_type.initial_response
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(InitialLoadBalanceResponse)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.LoadBalanceResponseType = &LoadBalanceResponse_InitialResponse{msg}
|
||||||
|
return true, err
|
||||||
|
case 2: // load_balance_response_type.server_list
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ServerList)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.LoadBalanceResponseType = &LoadBalanceResponse_ServerList{msg}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadBalanceResponse_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*LoadBalanceResponse)
|
||||||
|
// load_balance_response_type
|
||||||
|
switch x := m.LoadBalanceResponseType.(type) {
|
||||||
|
case *LoadBalanceResponse_InitialResponse:
|
||||||
|
s := proto.Size(x.InitialResponse)
|
||||||
|
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *LoadBalanceResponse_ServerList:
|
||||||
|
s := proto.Size(x.ServerList)
|
||||||
|
n += proto.SizeVarint(2<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
type InitialLoadBalanceResponse struct {
|
||||||
|
// This is an application layer redirect that indicates the client should use
|
||||||
|
// the specified server for load balancing. When this field is non-empty in
|
||||||
|
// the response, the client should open a separate connection to the
|
||||||
|
// load_balancer_delegate and call the BalanceLoad method.
|
||||||
|
LoadBalancerDelegate string `protobuf:"bytes,1,opt,name=load_balancer_delegate" json:"load_balancer_delegate,omitempty"`
|
||||||
|
// This interval defines how often the client should send the client stats
|
||||||
|
// to the load balancer. Stats should only be reported when the duration is
|
||||||
|
// positive.
|
||||||
|
ClientStatsReportInterval *Duration `protobuf:"bytes,3,opt,name=client_stats_report_interval" json:"client_stats_report_interval,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *InitialLoadBalanceResponse) Reset() { *m = InitialLoadBalanceResponse{} }
|
||||||
|
func (m *InitialLoadBalanceResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*InitialLoadBalanceResponse) ProtoMessage() {}
|
||||||
|
func (*InitialLoadBalanceResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||||
|
|
||||||
|
func (m *InitialLoadBalanceResponse) GetClientStatsReportInterval() *Duration {
|
||||||
|
if m != nil {
|
||||||
|
return m.ClientStatsReportInterval
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerList struct {
|
||||||
|
// Contains a list of servers selected by the load balancer. The list will
|
||||||
|
// be updated when server resolutions change or as needed to balance load
|
||||||
|
// across more servers. The client should consume the server list in order
|
||||||
|
// unless instructed otherwise via the client_config.
|
||||||
|
Servers []*Server `protobuf:"bytes,1,rep,name=servers" json:"servers,omitempty"`
|
||||||
|
// Indicates the amount of time that the client should consider this server
|
||||||
|
// list as valid. It may be considered stale after waiting this interval of
|
||||||
|
// time after receiving the list. If the interval is not positive, the
|
||||||
|
// client can assume the list is valid until the next list is received.
|
||||||
|
ExpirationInterval *Duration `protobuf:"bytes,3,opt,name=expiration_interval" json:"expiration_interval,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerList) Reset() { *m = ServerList{} }
|
||||||
|
func (m *ServerList) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServerList) ProtoMessage() {}
|
||||||
|
func (*ServerList) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||||
|
|
||||||
|
func (m *ServerList) GetServers() []*Server {
|
||||||
|
if m != nil {
|
||||||
|
return m.Servers
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerList) GetExpirationInterval() *Duration {
|
||||||
|
if m != nil {
|
||||||
|
return m.ExpirationInterval
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
// A resolved address for the server, serialized in network-byte-order. It may
|
||||||
|
// either be an IPv4 or IPv6 address.
|
||||||
|
IpAddress []byte `protobuf:"bytes,1,opt,name=ip_address,proto3" json:"ip_address,omitempty"`
|
||||||
|
// A resolved port number for the server.
|
||||||
|
Port int32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
|
||||||
|
// An opaque but printable token given to the frontend for each pick. All
|
||||||
|
// frontend requests for that pick must include the token in its initial
|
||||||
|
// metadata. The token is used by the backend to verify the request and to
|
||||||
|
// allow the backend to report load to the gRPC LB system.
|
||||||
|
LoadBalanceToken string `protobuf:"bytes,3,opt,name=load_balance_token" json:"load_balance_token,omitempty"`
|
||||||
|
// Indicates whether this particular request should be dropped by the client
|
||||||
|
// when this server is chosen from the list.
|
||||||
|
DropRequest bool `protobuf:"varint,4,opt,name=drop_request" json:"drop_request,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Server) Reset() { *m = Server{} }
|
||||||
|
func (m *Server) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Server) ProtoMessage() {}
|
||||||
|
func (*Server) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*Duration)(nil), "grpc.lb.v1.Duration")
|
||||||
|
proto.RegisterType((*LoadBalanceRequest)(nil), "grpc.lb.v1.LoadBalanceRequest")
|
||||||
|
proto.RegisterType((*InitialLoadBalanceRequest)(nil), "grpc.lb.v1.InitialLoadBalanceRequest")
|
||||||
|
proto.RegisterType((*ClientStats)(nil), "grpc.lb.v1.ClientStats")
|
||||||
|
proto.RegisterType((*LoadBalanceResponse)(nil), "grpc.lb.v1.LoadBalanceResponse")
|
||||||
|
proto.RegisterType((*InitialLoadBalanceResponse)(nil), "grpc.lb.v1.InitialLoadBalanceResponse")
|
||||||
|
proto.RegisterType((*ServerList)(nil), "grpc.lb.v1.ServerList")
|
||||||
|
proto.RegisterType((*Server)(nil), "grpc.lb.v1.Server")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for LoadBalancer service
|
||||||
|
|
||||||
|
type LoadBalancerClient interface {
|
||||||
|
// Bidirectional rpc to get a list of servers.
|
||||||
|
BalanceLoad(ctx context.Context, opts ...grpc.CallOption) (LoadBalancer_BalanceLoadClient, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type loadBalancerClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLoadBalancerClient(cc *grpc.ClientConn) LoadBalancerClient {
|
||||||
|
return &loadBalancerClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *loadBalancerClient) BalanceLoad(ctx context.Context, opts ...grpc.CallOption) (LoadBalancer_BalanceLoadClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_LoadBalancer_serviceDesc.Streams[0], c.cc, "/grpc.lb.v1.LoadBalancer/BalanceLoad", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &loadBalancerBalanceLoadClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoadBalancer_BalanceLoadClient interface {
|
||||||
|
Send(*LoadBalanceRequest) error
|
||||||
|
Recv() (*LoadBalanceResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type loadBalancerBalanceLoadClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *loadBalancerBalanceLoadClient) Send(m *LoadBalanceRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *loadBalancerBalanceLoadClient) Recv() (*LoadBalanceResponse, error) {
|
||||||
|
m := new(LoadBalanceResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for LoadBalancer service
|
||||||
|
|
||||||
|
type LoadBalancerServer interface {
|
||||||
|
// Bidirectional rpc to get a list of servers.
|
||||||
|
BalanceLoad(LoadBalancer_BalanceLoadServer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterLoadBalancerServer(s *grpc.Server, srv LoadBalancerServer) {
|
||||||
|
s.RegisterService(&_LoadBalancer_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _LoadBalancer_BalanceLoad_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(LoadBalancerServer).BalanceLoad(&loadBalancerBalanceLoadServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoadBalancer_BalanceLoadServer interface {
|
||||||
|
Send(*LoadBalanceResponse) error
|
||||||
|
Recv() (*LoadBalanceRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type loadBalancerBalanceLoadServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *loadBalancerBalanceLoadServer) Send(m *LoadBalanceResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *loadBalancerBalanceLoadServer) Recv() (*LoadBalanceRequest, error) {
|
||||||
|
m := new(LoadBalanceRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _LoadBalancer_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "grpc.lb.v1.LoadBalancer",
|
||||||
|
HandlerType: (*LoadBalancerServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "BalanceLoad",
|
||||||
|
Handler: _LoadBalancer_BalanceLoad_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: fileDescriptor0,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("grpclb.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 471 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x93, 0x51, 0x6f, 0xd3, 0x3e,
|
||||||
|
0x14, 0xc5, 0x9b, 0x7f, 0xb7, 0xfd, 0xb7, 0x9b, 0xc0, 0xc6, 0xdd, 0x54, 0xda, 0x32, 0x8d, 0x2a,
|
||||||
|
0x08, 0x54, 0x90, 0x08, 0x2c, 0xbc, 0xf1, 0x84, 0x0a, 0x0f, 0x45, 0xda, 0xd3, 0xf6, 0x86, 0x90,
|
||||||
|
0x2c, 0x27, 0xb9, 0x9a, 0x2c, 0x82, 0x6d, 0x6c, 0xaf, 0x1a, 0xdf, 0x07, 0xf1, 0x39, 0x91, 0xe3,
|
||||||
|
0x94, 0x64, 0x54, 0x15, 0xbc, 0xc5, 0xbe, 0x3e, 0xf7, 0x1e, 0xff, 0x7c, 0x02, 0xc9, 0xb5, 0xd1,
|
||||||
|
0x65, 0x5d, 0x64, 0xda, 0x28, 0xa7, 0x10, 0xfc, 0x2a, 0xab, 0x8b, 0x6c, 0x75, 0x9e, 0xbe, 0x80,
|
||||||
|
0xfd, 0x0f, 0x37, 0x86, 0x3b, 0xa1, 0x24, 0x1e, 0xc2, 0xff, 0x96, 0x4a, 0x25, 0x2b, 0x3b, 0x8e,
|
||||||
|
0x66, 0xd1, 0x7c, 0x88, 0xf7, 0x60, 0x57, 0x72, 0xa9, 0xec, 0xf8, 0xbf, 0x59, 0x34, 0xdf, 0x4d,
|
||||||
|
0x7f, 0x44, 0x80, 0x17, 0x8a, 0x57, 0x0b, 0x5e, 0x73, 0x59, 0xd2, 0x25, 0x7d, 0xbb, 0x21, 0xeb,
|
||||||
|
0xf0, 0x1d, 0x1c, 0x0a, 0x29, 0x9c, 0xe0, 0x35, 0x33, 0x61, 0xab, 0x91, 0xc7, 0xf9, 0xd3, 0xac,
|
||||||
|
0x1b, 0x94, 0x7d, 0x0c, 0x47, 0x36, 0xf5, 0xcb, 0x01, 0xbe, 0x82, 0xa4, 0xac, 0x05, 0x49, 0xc7,
|
||||||
|
0xac, 0xe3, 0x2e, 0x8c, 0x8b, 0xf3, 0x87, 0x7d, 0xf9, 0xfb, 0xa6, 0x7e, 0xe5, 0xcb, 0xcb, 0xc1,
|
||||||
|
0xe2, 0x11, 0x4c, 0x6a, 0xc5, 0x2b, 0x56, 0x84, 0x4e, 0xeb, 0xb9, 0xcc, 0x7d, 0xd7, 0x94, 0x3e,
|
||||||
|
0x87, 0xc9, 0xd6, 0x61, 0x98, 0xc0, 0x8e, 0xe4, 0x5f, 0xa9, 0x71, 0x78, 0x90, 0x7e, 0x82, 0xb8,
|
||||||
|
0xd7, 0x18, 0x47, 0x70, 0xdf, 0x29, 0xd7, 0xdd, 0x63, 0xcd, 0x61, 0x02, 0x0f, 0x5a, 0x7f, 0x46,
|
||||||
|
0x97, 0x8c, 0x8c, 0x51, 0x26, 0x98, 0x1c, 0xe2, 0x18, 0x8e, 0x2a, 0xa3, 0xb4, 0xa6, 0xaa, 0x13,
|
||||||
|
0x0d, 0x7d, 0x25, 0xfd, 0x19, 0xc1, 0xf1, 0x1d, 0x03, 0x56, 0x2b, 0x69, 0x09, 0x17, 0x70, 0xd4,
|
||||||
|
0xe1, 0x0a, 0x7b, 0x2d, 0xaf, 0x67, 0x7f, 0xe3, 0x15, 0x4e, 0x2f, 0x07, 0xf8, 0x12, 0x62, 0x4b,
|
||||||
|
0x66, 0x45, 0x86, 0xd5, 0xc2, 0xba, 0x96, 0xd7, 0xa8, 0x2f, 0xbf, 0x6a, 0xca, 0x17, 0xc2, 0xf3,
|
||||||
|
0x5d, 0x9c, 0xc2, 0xf4, 0x0f, 0x5c, 0xa1, 0x53, 0xe0, 0x75, 0x0b, 0xd3, 0xed, 0xc3, 0xf0, 0x0c,
|
||||||
|
0x46, 0x7d, 0xad, 0x61, 0x15, 0xd5, 0x74, 0xcd, 0x5d, 0x8b, 0x10, 0xdf, 0xc2, 0x69, 0xff, 0xed,
|
||||||
|
0x98, 0x21, 0xad, 0x8c, 0x63, 0x42, 0x3a, 0x32, 0x2b, 0x5e, 0x37, 0x30, 0xe2, 0xfc, 0xa4, 0xef,
|
||||||
|
0x6d, 0x1d, 0xb8, 0xb4, 0x02, 0xe8, 0x7c, 0xe2, 0x13, 0x1f, 0x3f, 0xbf, 0xf2, 0xd8, 0x87, 0xf3,
|
||||||
|
0x38, 0xc7, 0xcd, 0x0b, 0xe1, 0x39, 0x1c, 0xd3, 0xad, 0x16, 0xa1, 0xc1, 0xbf, 0x4d, 0xf9, 0x0c,
|
||||||
|
0x7b, 0xad, 0x18, 0x01, 0x84, 0x66, 0xbc, 0xaa, 0x0c, 0xd9, 0xf0, 0xb6, 0x89, 0x0f, 0x84, 0x37,
|
||||||
|
0x1c, 0x22, 0x8e, 0x53, 0xc0, 0x3b, 0xa4, 0x9c, 0xfa, 0x42, 0xb2, 0xe9, 0x7e, 0x80, 0x27, 0x90,
|
||||||
|
0xf8, 0xa7, 0xfe, 0x1d, 0xf2, 0x9d, 0x59, 0x34, 0xdf, 0xcf, 0x0b, 0x48, 0x7a, 0xd8, 0x0c, 0x5e,
|
||||||
|
0x42, 0xdc, 0x7e, 0xfb, 0x6d, 0x3c, 0xeb, 0x5b, 0xda, 0xcc, 0xe3, 0xf4, 0xf1, 0xd6, 0x7a, 0xe0,
|
||||||
|
0x3f, 0x8f, 0x5e, 0x47, 0xc5, 0x5e, 0xf3, 0xdf, 0xbe, 0xf9, 0x15, 0x00, 0x00, 0xff, 0xff, 0x01,
|
||||||
|
0x8b, 0xc9, 0x26, 0xc7, 0x03, 0x00, 0x00,
|
||||||
|
}
|
109
vendor/google.golang.org/grpc/grpclb/grpc_lb_v1/grpclb.proto
generated
vendored
Normal file
109
vendor/google.golang.org/grpc/grpclb/grpc_lb_v1/grpclb.proto
generated
vendored
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package grpc.lb.v1;
|
||||||
|
|
||||||
|
message Duration {
|
||||||
|
// Signed seconds of the span of time. Must be from -315,576,000,000
|
||||||
|
// to +315,576,000,000 inclusive.
|
||||||
|
int64 seconds = 1;
|
||||||
|
|
||||||
|
// Signed fractions of a second at nanosecond resolution of the span
|
||||||
|
// of time. Durations less than one second are represented with a 0
|
||||||
|
// `seconds` field and a positive or negative `nanos` field. For durations
|
||||||
|
// of one second or more, a non-zero value for the `nanos` field must be
|
||||||
|
// of the same sign as the `seconds` field. Must be from -999,999,999
|
||||||
|
// to +999,999,999 inclusive.
|
||||||
|
int32 nanos = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
service LoadBalancer {
|
||||||
|
// Bidirectional rpc to get a list of servers.
|
||||||
|
rpc BalanceLoad(stream LoadBalanceRequest)
|
||||||
|
returns (stream LoadBalanceResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
message LoadBalanceRequest {
|
||||||
|
oneof load_balance_request_type {
|
||||||
|
// This message should be sent on the first request to the load balancer.
|
||||||
|
InitialLoadBalanceRequest initial_request = 1;
|
||||||
|
|
||||||
|
// The client stats should be periodically reported to the load balancer
|
||||||
|
// based on the duration defined in the InitialLoadBalanceResponse.
|
||||||
|
ClientStats client_stats = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message InitialLoadBalanceRequest {
|
||||||
|
// Name of load balanced service (IE, service.grpc.gslb.google.com)
|
||||||
|
string name = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contains client level statistics that are useful to load balancing. Each
|
||||||
|
// count should be reset to zero after reporting the stats.
|
||||||
|
message ClientStats {
|
||||||
|
// The total number of requests sent by the client since the last report.
|
||||||
|
int64 total_requests = 1;
|
||||||
|
|
||||||
|
// The number of client rpc errors since the last report.
|
||||||
|
int64 client_rpc_errors = 2;
|
||||||
|
|
||||||
|
// The number of dropped requests since the last report.
|
||||||
|
int64 dropped_requests = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LoadBalanceResponse {
|
||||||
|
oneof load_balance_response_type {
|
||||||
|
// This message should be sent on the first response to the client.
|
||||||
|
InitialLoadBalanceResponse initial_response = 1;
|
||||||
|
|
||||||
|
// Contains the list of servers selected by the load balancer. The client
|
||||||
|
// should send requests to these servers in the specified order.
|
||||||
|
ServerList server_list = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message InitialLoadBalanceResponse {
|
||||||
|
// This is an application layer redirect that indicates the client should use
|
||||||
|
// the specified server for load balancing. When this field is non-empty in
|
||||||
|
// the response, the client should open a separate connection to the
|
||||||
|
// load_balancer_delegate and call the BalanceLoad method.
|
||||||
|
string load_balancer_delegate = 1;
|
||||||
|
|
||||||
|
// This interval defines how often the client should send the client stats
|
||||||
|
// to the load balancer. Stats should only be reported when the duration is
|
||||||
|
// positive.
|
||||||
|
Duration client_stats_report_interval = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ServerList {
|
||||||
|
// Contains a list of servers selected by the load balancer. The list will
|
||||||
|
// be updated when server resolutions change or as needed to balance load
|
||||||
|
// across more servers. The client should consume the server list in order
|
||||||
|
// unless instructed otherwise via the client_config.
|
||||||
|
repeated Server servers = 1;
|
||||||
|
|
||||||
|
// Indicates the amount of time that the client should consider this server
|
||||||
|
// list as valid. It may be considered stale after waiting this interval of
|
||||||
|
// time after receiving the list. If the interval is not positive, the
|
||||||
|
// client can assume the list is valid until the next list is received.
|
||||||
|
Duration expiration_interval = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Server {
|
||||||
|
// A resolved address for the server, serialized in network-byte-order. It may
|
||||||
|
// either be an IPv4 or IPv6 address.
|
||||||
|
bytes ip_address = 1;
|
||||||
|
|
||||||
|
// A resolved port number for the server.
|
||||||
|
int32 port = 2;
|
||||||
|
|
||||||
|
// An opaque but printable token given to the frontend for each pick. All
|
||||||
|
// frontend requests for that pick must include the token in its initial
|
||||||
|
// metadata. The token is used by the backend to verify the request and to
|
||||||
|
// allow the backend to report load to the gRPC LB system.
|
||||||
|
string load_balance_token = 3;
|
||||||
|
|
||||||
|
// Indicates whether this particular request should be dropped by the client
|
||||||
|
// when this server is chosen from the list.
|
||||||
|
bool drop_request = 4;
|
||||||
|
}
|
450
vendor/google.golang.org/grpc/grpclb/grpclb.go
generated
vendored
Normal file
450
vendor/google.golang.org/grpc/grpclb/grpclb.go
generated
vendored
Normal file
|
@ -0,0 +1,450 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package grpclb implements the load balancing protocol defined at
|
||||||
|
// https://github.com/grpc/grpc/blob/master/doc/load-balancing.md.
|
||||||
|
// The implementation is currently EXPERIMENTAL.
|
||||||
|
package grpclb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
lbpb "google.golang.org/grpc/grpclb/grpc_lb_v1"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/naming"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Balancer creates a grpclb load balancer.
|
||||||
|
func Balancer(r naming.Resolver) grpc.Balancer {
|
||||||
|
return &balancer{
|
||||||
|
r: r,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type remoteBalancerInfo struct {
|
||||||
|
addr grpc.Address
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// addrInfo consists of the information of a backend server.
|
||||||
|
type addrInfo struct {
|
||||||
|
addr grpc.Address
|
||||||
|
connected bool
|
||||||
|
dropRequest bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type balancer struct {
|
||||||
|
r naming.Resolver
|
||||||
|
mu sync.Mutex
|
||||||
|
seq int // a sequence number to make sure addrCh does not get stale addresses.
|
||||||
|
w naming.Watcher
|
||||||
|
addrCh chan []grpc.Address
|
||||||
|
rbs []remoteBalancerInfo
|
||||||
|
addrs []addrInfo
|
||||||
|
next int
|
||||||
|
waitCh chan struct{}
|
||||||
|
done bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) watchAddrUpdates(w naming.Watcher, ch chan remoteBalancerInfo) error {
|
||||||
|
updates, err := w.Next()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
if b.done {
|
||||||
|
return grpc.ErrClientConnClosing
|
||||||
|
}
|
||||||
|
var bAddr remoteBalancerInfo
|
||||||
|
if len(b.rbs) > 0 {
|
||||||
|
bAddr = b.rbs[0]
|
||||||
|
}
|
||||||
|
for _, update := range updates {
|
||||||
|
addr := grpc.Address{
|
||||||
|
Addr: update.Addr,
|
||||||
|
Metadata: update.Metadata,
|
||||||
|
}
|
||||||
|
switch update.Op {
|
||||||
|
case naming.Add:
|
||||||
|
var exist bool
|
||||||
|
for _, v := range b.rbs {
|
||||||
|
// TODO: Is the same addr with different server name a different balancer?
|
||||||
|
if addr == v.addr {
|
||||||
|
exist = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
b.rbs = append(b.rbs, remoteBalancerInfo{addr: addr})
|
||||||
|
case naming.Delete:
|
||||||
|
for i, v := range b.rbs {
|
||||||
|
if addr == v.addr {
|
||||||
|
copy(b.rbs[i:], b.rbs[i+1:])
|
||||||
|
b.rbs = b.rbs[:len(b.rbs)-1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
grpclog.Println("Unknown update.Op ", update.Op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Fall back to the basic round-robin load balancing if the resulting address is
|
||||||
|
// not a load balancer.
|
||||||
|
if len(b.rbs) > 0 {
|
||||||
|
// For simplicity, always use the first one now. May revisit this decision later.
|
||||||
|
if b.rbs[0] != bAddr {
|
||||||
|
select {
|
||||||
|
case <-ch:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
ch <- b.rbs[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) processServerList(l *lbpb.ServerList, seq int) {
|
||||||
|
servers := l.GetServers()
|
||||||
|
var (
|
||||||
|
sl []addrInfo
|
||||||
|
addrs []grpc.Address
|
||||||
|
)
|
||||||
|
for _, s := range servers {
|
||||||
|
// TODO: Support ExpirationInterval
|
||||||
|
addr := grpc.Address{
|
||||||
|
Addr: fmt.Sprintf("%s:%d", s.IpAddress, s.Port),
|
||||||
|
// TODO: include LoadBalanceToken in the Metadata
|
||||||
|
}
|
||||||
|
sl = append(sl, addrInfo{
|
||||||
|
addr: addr,
|
||||||
|
// TODO: Support dropRequest feature.
|
||||||
|
})
|
||||||
|
addrs = append(addrs, addr)
|
||||||
|
}
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
if b.done || seq < b.seq {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(sl) > 0 {
|
||||||
|
// reset b.next to 0 when replacing the server list.
|
||||||
|
b.next = 0
|
||||||
|
b.addrs = sl
|
||||||
|
b.addrCh <- addrs
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) callRemoteBalancer(lbc lbpb.LoadBalancerClient) (retry bool) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
stream, err := lbc.BalanceLoad(ctx, grpc.FailFast(false))
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Printf("Failed to perform RPC to the remote balancer %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.mu.Lock()
|
||||||
|
if b.done {
|
||||||
|
b.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.seq++
|
||||||
|
seq := b.seq
|
||||||
|
b.mu.Unlock()
|
||||||
|
initReq := &lbpb.LoadBalanceRequest{
|
||||||
|
LoadBalanceRequestType: &lbpb.LoadBalanceRequest_InitialRequest{
|
||||||
|
InitialRequest: new(lbpb.InitialLoadBalanceRequest),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := stream.Send(initReq); err != nil {
|
||||||
|
// TODO: backoff on retry?
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
reply, err := stream.Recv()
|
||||||
|
if err != nil {
|
||||||
|
// TODO: backoff on retry?
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
initResp := reply.GetInitialResponse()
|
||||||
|
if initResp == nil {
|
||||||
|
grpclog.Println("Failed to receive the initial response from the remote balancer.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// TODO: Support delegation.
|
||||||
|
if initResp.LoadBalancerDelegate != "" {
|
||||||
|
// delegation
|
||||||
|
grpclog.Println("TODO: Delegation is not supported yet.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Retrieve the server list.
|
||||||
|
for {
|
||||||
|
reply, err := stream.Recv()
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if serverList := reply.GetServerList(); serverList != nil {
|
||||||
|
b.processServerList(serverList, seq)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) Start(target string, config grpc.BalancerConfig) error {
|
||||||
|
// TODO: Fall back to the basic direct connection if there is no name resolver.
|
||||||
|
if b.r == nil {
|
||||||
|
return errors.New("there is no name resolver installed")
|
||||||
|
}
|
||||||
|
b.mu.Lock()
|
||||||
|
if b.done {
|
||||||
|
b.mu.Unlock()
|
||||||
|
return grpc.ErrClientConnClosing
|
||||||
|
}
|
||||||
|
b.addrCh = make(chan []grpc.Address)
|
||||||
|
w, err := b.r.Resolve(target)
|
||||||
|
if err != nil {
|
||||||
|
b.mu.Unlock()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.w = w
|
||||||
|
b.mu.Unlock()
|
||||||
|
balancerAddrCh := make(chan remoteBalancerInfo, 1)
|
||||||
|
// Spawn a goroutine to monitor the name resolution of remote load balancer.
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if err := b.watchAddrUpdates(w, balancerAddrCh); err != nil {
|
||||||
|
grpclog.Printf("grpc: the naming watcher stops working due to %v.\n", err)
|
||||||
|
close(balancerAddrCh)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// Spawn a goroutine to talk to the remote load balancer.
|
||||||
|
go func() {
|
||||||
|
var cc *grpc.ClientConn
|
||||||
|
for {
|
||||||
|
rb, ok := <-balancerAddrCh
|
||||||
|
if cc != nil {
|
||||||
|
cc.Close()
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
// b is closing.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Talk to the remote load balancer to get the server list.
|
||||||
|
//
|
||||||
|
// TODO: override the server name in creds using Metadata in addr.
|
||||||
|
var err error
|
||||||
|
creds := config.DialCreds
|
||||||
|
if creds == nil {
|
||||||
|
cc, err = grpc.Dial(rb.addr.Addr, grpc.WithInsecure())
|
||||||
|
} else {
|
||||||
|
cc, err = grpc.Dial(rb.addr.Addr, grpc.WithTransportCredentials(creds))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Printf("Failed to setup a connection to the remote balancer %v: %v", rb.addr, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func(cc *grpc.ClientConn) {
|
||||||
|
lbc := lbpb.NewLoadBalancerClient(cc)
|
||||||
|
for {
|
||||||
|
if retry := b.callRemoteBalancer(lbc); !retry {
|
||||||
|
cc.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(cc)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) down(addr grpc.Address, err error) {
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
for _, a := range b.addrs {
|
||||||
|
if addr == a.addr {
|
||||||
|
a.connected = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) Up(addr grpc.Address) func(error) {
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
if b.done {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var cnt int
|
||||||
|
for _, a := range b.addrs {
|
||||||
|
if a.addr == addr {
|
||||||
|
if a.connected {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
a.connected = true
|
||||||
|
}
|
||||||
|
if a.connected {
|
||||||
|
cnt++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// addr is the only one which is connected. Notify the Get() callers who are blocking.
|
||||||
|
if cnt == 1 && b.waitCh != nil {
|
||||||
|
close(b.waitCh)
|
||||||
|
b.waitCh = nil
|
||||||
|
}
|
||||||
|
return func(err error) {
|
||||||
|
b.down(addr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) Get(ctx context.Context, opts grpc.BalancerGetOptions) (addr grpc.Address, put func(), err error) {
|
||||||
|
var ch chan struct{}
|
||||||
|
b.mu.Lock()
|
||||||
|
if b.done {
|
||||||
|
b.mu.Unlock()
|
||||||
|
err = grpc.ErrClientConnClosing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.addrs) > 0 {
|
||||||
|
if b.next >= len(b.addrs) {
|
||||||
|
b.next = 0
|
||||||
|
}
|
||||||
|
next := b.next
|
||||||
|
for {
|
||||||
|
a := b.addrs[next]
|
||||||
|
next = (next + 1) % len(b.addrs)
|
||||||
|
if a.connected {
|
||||||
|
addr = a.addr
|
||||||
|
b.next = next
|
||||||
|
b.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if next == b.next {
|
||||||
|
// Has iterated all the possible address but none is connected.
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !opts.BlockingWait {
|
||||||
|
if len(b.addrs) == 0 {
|
||||||
|
b.mu.Unlock()
|
||||||
|
err = fmt.Errorf("there is no address available")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Returns the next addr on b.addrs for a failfast RPC.
|
||||||
|
addr = b.addrs[b.next].addr
|
||||||
|
b.next++
|
||||||
|
b.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Wait on b.waitCh for non-failfast RPCs.
|
||||||
|
if b.waitCh == nil {
|
||||||
|
ch = make(chan struct{})
|
||||||
|
b.waitCh = ch
|
||||||
|
} else {
|
||||||
|
ch = b.waitCh
|
||||||
|
}
|
||||||
|
b.mu.Unlock()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
err = ctx.Err()
|
||||||
|
return
|
||||||
|
case <-ch:
|
||||||
|
b.mu.Lock()
|
||||||
|
if b.done {
|
||||||
|
b.mu.Unlock()
|
||||||
|
err = grpc.ErrClientConnClosing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.addrs) > 0 {
|
||||||
|
if b.next >= len(b.addrs) {
|
||||||
|
b.next = 0
|
||||||
|
}
|
||||||
|
next := b.next
|
||||||
|
for {
|
||||||
|
a := b.addrs[next]
|
||||||
|
next = (next + 1) % len(b.addrs)
|
||||||
|
if a.connected {
|
||||||
|
addr = a.addr
|
||||||
|
b.next = next
|
||||||
|
b.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if next == b.next {
|
||||||
|
// Has iterated all the possible address but none is connected.
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The newly added addr got removed by Down() again.
|
||||||
|
if b.waitCh == nil {
|
||||||
|
ch = make(chan struct{})
|
||||||
|
b.waitCh = ch
|
||||||
|
} else {
|
||||||
|
ch = b.waitCh
|
||||||
|
}
|
||||||
|
b.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) Notify() <-chan []grpc.Address {
|
||||||
|
return b.addrCh
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *balancer) Close() error {
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
b.done = true
|
||||||
|
if b.waitCh != nil {
|
||||||
|
close(b.waitCh)
|
||||||
|
}
|
||||||
|
if b.addrCh != nil {
|
||||||
|
close(b.addrCh)
|
||||||
|
}
|
||||||
|
if b.w != nil {
|
||||||
|
b.w.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
215
vendor/google.golang.org/grpc/grpclb/grpclb_test.go
generated
vendored
Normal file
215
vendor/google.golang.org/grpc/grpclb/grpclb_test.go
generated
vendored
Normal file
|
@ -0,0 +1,215 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpclb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
lbpb "google.golang.org/grpc/grpclb/grpc_lb_v1"
|
||||||
|
"google.golang.org/grpc/naming"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testWatcher struct {
|
||||||
|
// the channel to receives name resolution updates
|
||||||
|
update chan *naming.Update
|
||||||
|
// the side channel to get to know how many updates in a batch
|
||||||
|
side chan int
|
||||||
|
// the channel to notifiy update injector that the update reading is done
|
||||||
|
readDone chan int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *testWatcher) Next() (updates []*naming.Update, err error) {
|
||||||
|
n, ok := <-w.side
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("w.side is closed")
|
||||||
|
}
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
u, ok := <-w.update
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if u != nil {
|
||||||
|
updates = append(updates, u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.readDone <- 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *testWatcher) Close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject naming resolution updates to the testWatcher.
|
||||||
|
func (w *testWatcher) inject(updates []*naming.Update) {
|
||||||
|
w.side <- len(updates)
|
||||||
|
for _, u := range updates {
|
||||||
|
w.update <- u
|
||||||
|
}
|
||||||
|
<-w.readDone
|
||||||
|
}
|
||||||
|
|
||||||
|
type testNameResolver struct {
|
||||||
|
w *testWatcher
|
||||||
|
addr string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *testNameResolver) Resolve(target string) (naming.Watcher, error) {
|
||||||
|
r.w = &testWatcher{
|
||||||
|
update: make(chan *naming.Update, 1),
|
||||||
|
side: make(chan int, 1),
|
||||||
|
readDone: make(chan int),
|
||||||
|
}
|
||||||
|
r.w.side <- 1
|
||||||
|
r.w.update <- &naming.Update{
|
||||||
|
Op: naming.Add,
|
||||||
|
Addr: r.addr,
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
<-r.w.readDone
|
||||||
|
}()
|
||||||
|
return r.w, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type remoteBalancer struct {
|
||||||
|
servers *lbpb.ServerList
|
||||||
|
done chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRemoteBalancer(servers *lbpb.ServerList) *remoteBalancer {
|
||||||
|
return &remoteBalancer{
|
||||||
|
servers: servers,
|
||||||
|
done: make(chan struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *remoteBalancer) stop() {
|
||||||
|
close(b.done)
|
||||||
|
}
|
||||||
|
func (b *remoteBalancer) BalanceLoad(stream lbpb.LoadBalancer_BalanceLoadServer) error {
|
||||||
|
resp := &lbpb.LoadBalanceResponse{
|
||||||
|
LoadBalanceResponseType: &lbpb.LoadBalanceResponse_InitialResponse{
|
||||||
|
InitialResponse: new(lbpb.InitialLoadBalanceResponse),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := stream.Send(resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resp = &lbpb.LoadBalanceResponse{
|
||||||
|
LoadBalanceResponseType: &lbpb.LoadBalanceResponse_ServerList{
|
||||||
|
ServerList: b.servers,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := stream.Send(resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
<-b.done
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func startBackends(lis ...net.Listener) (servers []*grpc.Server) {
|
||||||
|
for _, l := range lis {
|
||||||
|
s := grpc.NewServer()
|
||||||
|
servers = append(servers, s)
|
||||||
|
go func(s *grpc.Server, l net.Listener) {
|
||||||
|
s.Serve(l)
|
||||||
|
}(s, l)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func stopBackends(servers []*grpc.Server) {
|
||||||
|
for _, s := range servers {
|
||||||
|
s.Stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGRPCLB(t *testing.T) {
|
||||||
|
// Start a backend.
|
||||||
|
beLis, err := net.Listen("tcp", "localhost:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to listen %v", err)
|
||||||
|
}
|
||||||
|
backends := startBackends(beLis)
|
||||||
|
defer stopBackends(backends)
|
||||||
|
// Start a load balancer.
|
||||||
|
lis, err := net.Listen("tcp", "localhost:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create the listener for the load balancer %v", err)
|
||||||
|
}
|
||||||
|
lb := grpc.NewServer()
|
||||||
|
addr := strings.Split(lis.Addr().String(), ":")
|
||||||
|
port, err := strconv.Atoi(addr[1])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to generate the port number %v", err)
|
||||||
|
}
|
||||||
|
be := &lbpb.Server{
|
||||||
|
IpAddress: []byte(addr[0]),
|
||||||
|
Port: int32(port),
|
||||||
|
}
|
||||||
|
var bes []*lbpb.Server
|
||||||
|
bes = append(bes, be)
|
||||||
|
sl := &lbpb.ServerList{
|
||||||
|
Servers: bes,
|
||||||
|
}
|
||||||
|
ls := newRemoteBalancer(sl)
|
||||||
|
lbpb.RegisterLoadBalancerServer(lb, ls)
|
||||||
|
go func() {
|
||||||
|
lb.Serve(lis)
|
||||||
|
}()
|
||||||
|
defer func() {
|
||||||
|
ls.stop()
|
||||||
|
lb.Stop()
|
||||||
|
}()
|
||||||
|
cc, err := grpc.Dial("foo.bar.com", grpc.WithBalancer(Balancer(&testNameResolver{
|
||||||
|
addr: lis.Addr().String(),
|
||||||
|
})), grpc.WithInsecure(), grpc.WithBlock())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to dial to the backend %v", err)
|
||||||
|
}
|
||||||
|
// Issue an unimplemented RPC and expect codes.Unimplemented.
|
||||||
|
var (
|
||||||
|
req, reply lbpb.Duration
|
||||||
|
)
|
||||||
|
if err := grpc.Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err == nil || grpc.Code(err) != codes.Unimplemented {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want error code %s", err, codes.Unimplemented)
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
}
|
72
vendor/google.golang.org/grpc/grpclog/glogger/glogger.go
generated
vendored
Normal file
72
vendor/google.golang.org/grpc/grpclog/glogger/glogger.go
generated
vendored
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package glogger defines glog-based logging for grpc.
|
||||||
|
*/
|
||||||
|
package glogger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
grpclog.SetLogger(&glogger{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type glogger struct{}
|
||||||
|
|
||||||
|
func (g *glogger) Fatal(args ...interface{}) {
|
||||||
|
glog.Fatal(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *glogger) Fatalf(format string, args ...interface{}) {
|
||||||
|
glog.Fatalf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *glogger) Fatalln(args ...interface{}) {
|
||||||
|
glog.Fatalln(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *glogger) Print(args ...interface{}) {
|
||||||
|
glog.Info(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *glogger) Printf(format string, args ...interface{}) {
|
||||||
|
glog.Infof(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *glogger) Println(args ...interface{}) {
|
||||||
|
glog.Infoln(args...)
|
||||||
|
}
|
93
vendor/google.golang.org/grpc/grpclog/logger.go
generated
vendored
Normal file
93
vendor/google.golang.org/grpc/grpclog/logger.go
generated
vendored
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpclog defines logging for grpc.
|
||||||
|
*/
|
||||||
|
package grpclog // import "google.golang.org/grpc/grpclog"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Use golang's standard logger by default.
|
||||||
|
// Access is not mutex-protected: do not modify except in init()
|
||||||
|
// functions.
|
||||||
|
var logger Logger = log.New(os.Stderr, "", log.LstdFlags)
|
||||||
|
|
||||||
|
// Logger mimics golang's standard Logger as an interface.
|
||||||
|
type Logger interface {
|
||||||
|
Fatal(args ...interface{})
|
||||||
|
Fatalf(format string, args ...interface{})
|
||||||
|
Fatalln(args ...interface{})
|
||||||
|
Print(args ...interface{})
|
||||||
|
Printf(format string, args ...interface{})
|
||||||
|
Println(args ...interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLogger sets the logger that is used in grpc. Call only from
|
||||||
|
// init() functions.
|
||||||
|
func SetLogger(l Logger) {
|
||||||
|
logger = l
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal is equivalent to Print() followed by a call to os.Exit() with a non-zero exit code.
|
||||||
|
func Fatal(args ...interface{}) {
|
||||||
|
logger.Fatal(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf is equivalent to Printf() followed by a call to os.Exit() with a non-zero exit code.
|
||||||
|
func Fatalf(format string, args ...interface{}) {
|
||||||
|
logger.Fatalf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalln is equivalent to Println() followed by a call to os.Exit()) with a non-zero exit code.
|
||||||
|
func Fatalln(args ...interface{}) {
|
||||||
|
logger.Fatalln(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print prints to the logger. Arguments are handled in the manner of fmt.Print.
|
||||||
|
func Print(args ...interface{}) {
|
||||||
|
logger.Print(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printf prints to the logger. Arguments are handled in the manner of fmt.Printf.
|
||||||
|
func Printf(format string, args ...interface{}) {
|
||||||
|
logger.Printf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Println prints to the logger. Arguments are handled in the manner of fmt.Println.
|
||||||
|
func Println(args ...interface{}) {
|
||||||
|
logger.Println(args...)
|
||||||
|
}
|
176
vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go
generated
vendored
Normal file
176
vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: health.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpc_health_v1 is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
health.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
HealthCheckRequest
|
||||||
|
HealthCheckResponse
|
||||||
|
*/
|
||||||
|
package grpc_health_v1
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
type HealthCheckResponse_ServingStatus int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
HealthCheckResponse_UNKNOWN HealthCheckResponse_ServingStatus = 0
|
||||||
|
HealthCheckResponse_SERVING HealthCheckResponse_ServingStatus = 1
|
||||||
|
HealthCheckResponse_NOT_SERVING HealthCheckResponse_ServingStatus = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var HealthCheckResponse_ServingStatus_name = map[int32]string{
|
||||||
|
0: "UNKNOWN",
|
||||||
|
1: "SERVING",
|
||||||
|
2: "NOT_SERVING",
|
||||||
|
}
|
||||||
|
var HealthCheckResponse_ServingStatus_value = map[string]int32{
|
||||||
|
"UNKNOWN": 0,
|
||||||
|
"SERVING": 1,
|
||||||
|
"NOT_SERVING": 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x HealthCheckResponse_ServingStatus) String() string {
|
||||||
|
return proto.EnumName(HealthCheckResponse_ServingStatus_name, int32(x))
|
||||||
|
}
|
||||||
|
func (HealthCheckResponse_ServingStatus) EnumDescriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor0, []int{1, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
type HealthCheckRequest struct {
|
||||||
|
Service string `protobuf:"bytes,1,opt,name=service" json:"service,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *HealthCheckRequest) Reset() { *m = HealthCheckRequest{} }
|
||||||
|
func (m *HealthCheckRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*HealthCheckRequest) ProtoMessage() {}
|
||||||
|
func (*HealthCheckRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
type HealthCheckResponse struct {
|
||||||
|
Status HealthCheckResponse_ServingStatus `protobuf:"varint,1,opt,name=status,enum=grpc.health.v1.HealthCheckResponse_ServingStatus" json:"status,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *HealthCheckResponse) Reset() { *m = HealthCheckResponse{} }
|
||||||
|
func (m *HealthCheckResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*HealthCheckResponse) ProtoMessage() {}
|
||||||
|
func (*HealthCheckResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*HealthCheckRequest)(nil), "grpc.health.v1.HealthCheckRequest")
|
||||||
|
proto.RegisterType((*HealthCheckResponse)(nil), "grpc.health.v1.HealthCheckResponse")
|
||||||
|
proto.RegisterEnum("grpc.health.v1.HealthCheckResponse_ServingStatus", HealthCheckResponse_ServingStatus_name, HealthCheckResponse_ServingStatus_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for Health service
|
||||||
|
|
||||||
|
type HealthClient interface {
|
||||||
|
Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type healthClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHealthClient(cc *grpc.ClientConn) HealthClient {
|
||||||
|
return &healthClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *healthClient) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) {
|
||||||
|
out := new(HealthCheckResponse)
|
||||||
|
err := grpc.Invoke(ctx, "/grpc.health.v1.Health/Check", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for Health service
|
||||||
|
|
||||||
|
type HealthServer interface {
|
||||||
|
Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterHealthServer(s *grpc.Server, srv HealthServer) {
|
||||||
|
s.RegisterService(&_Health_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Health_Check_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(HealthCheckRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(HealthServer).Check(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/grpc.health.v1.Health/Check",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(HealthServer).Check(ctx, req.(*HealthCheckRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _Health_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "grpc.health.v1.Health",
|
||||||
|
HandlerType: (*HealthServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "Check",
|
||||||
|
Handler: _Health_Check_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: fileDescriptor0,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("health.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 204 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0xc9, 0x48, 0x4d, 0xcc,
|
||||||
|
0x29, 0xc9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4b, 0x2f, 0x2a, 0x48, 0xd6, 0x83,
|
||||||
|
0x0a, 0x95, 0x19, 0x2a, 0xe9, 0x71, 0x09, 0x79, 0x80, 0x39, 0xce, 0x19, 0xa9, 0xc9, 0xd9, 0x41,
|
||||||
|
0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x12, 0x5c, 0xec, 0xc5, 0xa9, 0x45, 0x65, 0x99, 0xc9,
|
||||||
|
0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0xd2, 0x1c, 0x46, 0x2e, 0x61, 0x14,
|
||||||
|
0x0d, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x9e, 0x5c, 0x6c, 0xc5, 0x25, 0x89, 0x25, 0xa5,
|
||||||
|
0xc5, 0x60, 0x0d, 0x7c, 0x46, 0x86, 0x7a, 0xa8, 0x16, 0xe9, 0x61, 0xd1, 0xa4, 0x17, 0x0c, 0x32,
|
||||||
|
0x34, 0x2f, 0x3d, 0x18, 0xac, 0x31, 0x08, 0x6a, 0x80, 0x92, 0x15, 0x17, 0x2f, 0x8a, 0x84, 0x10,
|
||||||
|
0x37, 0x17, 0x7b, 0xa8, 0x9f, 0xb7, 0x9f, 0x7f, 0xb8, 0x9f, 0x00, 0x03, 0x88, 0x13, 0xec, 0x1a,
|
||||||
|
0x14, 0xe6, 0xe9, 0xe7, 0x2e, 0xc0, 0x28, 0xc4, 0xcf, 0xc5, 0xed, 0xe7, 0x1f, 0x12, 0x0f, 0x13,
|
||||||
|
0x60, 0x32, 0x8a, 0xe2, 0x62, 0x83, 0x58, 0x24, 0x14, 0xc0, 0xc5, 0x0a, 0xb6, 0x4c, 0x48, 0x09,
|
||||||
|
0xaf, 0x4b, 0xc0, 0xfe, 0x95, 0x52, 0x26, 0xc2, 0xb5, 0x49, 0x6c, 0xe0, 0x10, 0x34, 0x06, 0x04,
|
||||||
|
0x00, 0x00, 0xff, 0xff, 0xac, 0x56, 0x2a, 0xcb, 0x51, 0x01, 0x00, 0x00,
|
||||||
|
}
|
20
vendor/google.golang.org/grpc/health/grpc_health_v1/health.proto
generated
vendored
Normal file
20
vendor/google.golang.org/grpc/health/grpc_health_v1/health.proto
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package grpc.health.v1;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
52
vendor/google.golang.org/grpc/health/health.go
generated
vendored
Normal file
52
vendor/google.golang.org/grpc/health/health.go
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// Package health provides some utility functions to health-check a server. The implementation
|
||||||
|
// is based on protobuf. Users need to write their own implementations if other IDLs are used.
|
||||||
|
package health
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server implements `service Health`.
|
||||||
|
type Server struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
// statusMap stores the serving status of the services this Server monitors.
|
||||||
|
statusMap map[string]healthpb.HealthCheckResponse_ServingStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServer returns a new Server.
|
||||||
|
func NewServer() *Server {
|
||||||
|
return &Server{
|
||||||
|
statusMap: make(map[string]healthpb.HealthCheckResponse_ServingStatus),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check implements `service Health`.
|
||||||
|
func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
if in.Service == "" {
|
||||||
|
// check the server overall health status.
|
||||||
|
return &healthpb.HealthCheckResponse{
|
||||||
|
Status: healthpb.HealthCheckResponse_SERVING,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
if status, ok := s.statusMap[in.Service]; ok {
|
||||||
|
return &healthpb.HealthCheckResponse{
|
||||||
|
Status: status,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
return nil, grpc.Errorf(codes.NotFound, "unknown service")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetServingStatus is called when need to reset the serving status of a service
|
||||||
|
// or insert a new service entry into the statusMap.
|
||||||
|
func (s *Server) SetServingStatus(service string, status healthpb.HealthCheckResponse_ServingStatus) {
|
||||||
|
s.mu.Lock()
|
||||||
|
s.statusMap[service] = status
|
||||||
|
s.mu.Unlock()
|
||||||
|
}
|
90
vendor/google.golang.org/grpc/interceptor.go
generated
vendored
Normal file
90
vendor/google.golang.org/grpc/interceptor.go
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UnaryInvoker is called by UnaryClientInterceptor to complete RPCs.
|
||||||
|
type UnaryInvoker func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error
|
||||||
|
|
||||||
|
// UnaryClientInterceptor intercepts the execution of a unary RPC on the client. inovker is the handler to complete the RPC
|
||||||
|
// and it is the responsibility of the interceptor to call it.
|
||||||
|
// This is the EXPERIMENTAL API.
|
||||||
|
type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error
|
||||||
|
|
||||||
|
// Streamer is called by StreamClientInterceptor to create a ClientStream.
|
||||||
|
type Streamer func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error)
|
||||||
|
|
||||||
|
// StreamClientInterceptor intercepts the creation of ClientStream. It may return a custom ClientStream to intercept all I/O
|
||||||
|
// operations. streamer is the handlder to create a ClientStream and it is the responsibility of the interceptor to call it.
|
||||||
|
// This is the EXPERIMENTAL API.
|
||||||
|
type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error)
|
||||||
|
|
||||||
|
// UnaryServerInfo consists of various information about a unary RPC on
|
||||||
|
// server side. All per-rpc information may be mutated by the interceptor.
|
||||||
|
type UnaryServerInfo struct {
|
||||||
|
// Server is the service implementation the user provides. This is read-only.
|
||||||
|
Server interface{}
|
||||||
|
// FullMethod is the full RPC method string, i.e., /package.service/method.
|
||||||
|
FullMethod string
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnaryHandler defines the handler invoked by UnaryServerInterceptor to complete the normal
|
||||||
|
// execution of a unary RPC.
|
||||||
|
type UnaryHandler func(ctx context.Context, req interface{}) (interface{}, error)
|
||||||
|
|
||||||
|
// UnaryServerInterceptor provides a hook to intercept the execution of a unary RPC on the server. info
|
||||||
|
// contains all the information of this RPC the interceptor can operate on. And handler is the wrapper
|
||||||
|
// of the service method implementation. It is the responsibility of the interceptor to invoke handler
|
||||||
|
// to complete the RPC.
|
||||||
|
type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error)
|
||||||
|
|
||||||
|
// StreamServerInfo consists of various information about a streaming RPC on
|
||||||
|
// server side. All per-rpc information may be mutated by the interceptor.
|
||||||
|
type StreamServerInfo struct {
|
||||||
|
// FullMethod is the full RPC method string, i.e., /package.service/method.
|
||||||
|
FullMethod string
|
||||||
|
// IsClientStream indicates whether the RPC is a client streaming RPC.
|
||||||
|
IsClientStream bool
|
||||||
|
// IsServerStream indicates whether the RPC is a server streaming RPC.
|
||||||
|
IsServerStream bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// StreamServerInterceptor provides a hook to intercept the execution of a streaming RPC on the server.
|
||||||
|
// info contains all the information of this RPC the interceptor can operate on. And handler is the
|
||||||
|
// service method implementation. It is the responsibility of the interceptor to invoke handler to
|
||||||
|
// complete the RPC.
|
||||||
|
type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error
|
49
vendor/google.golang.org/grpc/internal/internal.go
generated
vendored
Normal file
49
vendor/google.golang.org/grpc/internal/internal.go
generated
vendored
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package internal contains gRPC-internal code for testing, to avoid polluting
|
||||||
|
// the godoc of the top-level grpc package.
|
||||||
|
package internal
|
||||||
|
|
||||||
|
// TestingCloseConns closes all existing transports but keeps
|
||||||
|
// grpcServer.lis accepting new connections.
|
||||||
|
//
|
||||||
|
// The provided grpcServer must be of type *grpc.Server. It is untyped
|
||||||
|
// for circular dependency reasons.
|
||||||
|
var TestingCloseConns func(grpcServer interface{})
|
||||||
|
|
||||||
|
// TestingUseHandlerImpl enables the http.Handler-based server implementation.
|
||||||
|
// It must be called before Serve and requires TLS credentials.
|
||||||
|
//
|
||||||
|
// The provided grpcServer must be of type *grpc.Server. It is untyped
|
||||||
|
// for circular dependency reasons.
|
||||||
|
var TestingUseHandlerImpl func(grpcServer interface{})
|
186
vendor/google.golang.org/grpc/interop/client/client.go
generated
vendored
Normal file
186
vendor/google.golang.org/grpc/interop/client/client.go
generated
vendored
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/credentials/oauth"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/interop"
|
||||||
|
testpb "google.golang.org/grpc/interop/grpc_testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
useTLS = flag.Bool("use_tls", false, "Connection uses TLS if true, else plain TCP")
|
||||||
|
testCA = flag.Bool("use_test_ca", false, "Whether to replace platform root CAs with test CA as the CA root")
|
||||||
|
serviceAccountKeyFile = flag.String("service_account_key_file", "", "Path to service account json key file")
|
||||||
|
oauthScope = flag.String("oauth_scope", "", "The scope for OAuth2 tokens")
|
||||||
|
defaultServiceAccount = flag.String("default_service_account", "", "Email of GCE default service account")
|
||||||
|
serverHost = flag.String("server_host", "127.0.0.1", "The server host name")
|
||||||
|
serverPort = flag.Int("server_port", 10000, "The server port number")
|
||||||
|
tlsServerName = flag.String("server_host_override", "", "The server name use to verify the hostname returned by TLS handshake if it is not empty. Otherwise, --server_host is used.")
|
||||||
|
testCase = flag.String("test_case", "large_unary",
|
||||||
|
`Configure different test cases. Valid options are:
|
||||||
|
empty_unary : empty (zero bytes) request and response;
|
||||||
|
large_unary : single request and (large) response;
|
||||||
|
client_streaming : request streaming with single response;
|
||||||
|
server_streaming : single request with response streaming;
|
||||||
|
ping_pong : full-duplex streaming;
|
||||||
|
empty_stream : full-duplex streaming with zero message;
|
||||||
|
timeout_on_sleeping_server: fullduplex streaming on a sleeping server;
|
||||||
|
compute_engine_creds: large_unary with compute engine auth;
|
||||||
|
service_account_creds: large_unary with service account auth;
|
||||||
|
jwt_token_creds: large_unary with jwt token auth;
|
||||||
|
per_rpc_creds: large_unary with per rpc token;
|
||||||
|
oauth2_auth_token: large_unary with oauth2 token auth;
|
||||||
|
cancel_after_begin: cancellation after metadata has been sent but before payloads are sent;
|
||||||
|
cancel_after_first_response: cancellation after receiving 1st message from the server.`)
|
||||||
|
|
||||||
|
// The test CA root cert file
|
||||||
|
testCAFile = "testdata/ca.pem"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
serverAddr := net.JoinHostPort(*serverHost, strconv.Itoa(*serverPort))
|
||||||
|
var opts []grpc.DialOption
|
||||||
|
if *useTLS {
|
||||||
|
var sn string
|
||||||
|
if *tlsServerName != "" {
|
||||||
|
sn = *tlsServerName
|
||||||
|
}
|
||||||
|
var creds credentials.TransportCredentials
|
||||||
|
if *testCA {
|
||||||
|
var err error
|
||||||
|
creds, err = credentials.NewClientTLSFromFile(testCAFile, sn)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to create TLS credentials %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
creds = credentials.NewClientTLSFromCert(nil, sn)
|
||||||
|
}
|
||||||
|
opts = append(opts, grpc.WithTransportCredentials(creds))
|
||||||
|
if *testCase == "compute_engine_creds" {
|
||||||
|
opts = append(opts, grpc.WithPerRPCCredentials(oauth.NewComputeEngine()))
|
||||||
|
} else if *testCase == "service_account_creds" {
|
||||||
|
jwtCreds, err := oauth.NewServiceAccountFromFile(*serviceAccountKeyFile, *oauthScope)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to create JWT credentials: %v", err)
|
||||||
|
}
|
||||||
|
opts = append(opts, grpc.WithPerRPCCredentials(jwtCreds))
|
||||||
|
} else if *testCase == "jwt_token_creds" {
|
||||||
|
jwtCreds, err := oauth.NewJWTAccessFromFile(*serviceAccountKeyFile)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to create JWT credentials: %v", err)
|
||||||
|
}
|
||||||
|
opts = append(opts, grpc.WithPerRPCCredentials(jwtCreds))
|
||||||
|
} else if *testCase == "oauth2_auth_token" {
|
||||||
|
opts = append(opts, grpc.WithPerRPCCredentials(oauth.NewOauthAccess(interop.GetToken(*serviceAccountKeyFile, *oauthScope))))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
opts = append(opts, grpc.WithInsecure())
|
||||||
|
}
|
||||||
|
conn, err := grpc.Dial(serverAddr, opts...)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Fail to dial: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
tc := testpb.NewTestServiceClient(conn)
|
||||||
|
switch *testCase {
|
||||||
|
case "empty_unary":
|
||||||
|
interop.DoEmptyUnaryCall(tc)
|
||||||
|
grpclog.Println("EmptyUnaryCall done")
|
||||||
|
case "large_unary":
|
||||||
|
interop.DoLargeUnaryCall(tc)
|
||||||
|
grpclog.Println("LargeUnaryCall done")
|
||||||
|
case "client_streaming":
|
||||||
|
interop.DoClientStreaming(tc)
|
||||||
|
grpclog.Println("ClientStreaming done")
|
||||||
|
case "server_streaming":
|
||||||
|
interop.DoServerStreaming(tc)
|
||||||
|
grpclog.Println("ServerStreaming done")
|
||||||
|
case "ping_pong":
|
||||||
|
interop.DoPingPong(tc)
|
||||||
|
grpclog.Println("Pingpong done")
|
||||||
|
case "empty_stream":
|
||||||
|
interop.DoEmptyStream(tc)
|
||||||
|
grpclog.Println("Emptystream done")
|
||||||
|
case "timeout_on_sleeping_server":
|
||||||
|
interop.DoTimeoutOnSleepingServer(tc)
|
||||||
|
grpclog.Println("TimeoutOnSleepingServer done")
|
||||||
|
case "compute_engine_creds":
|
||||||
|
if !*useTLS {
|
||||||
|
grpclog.Fatalf("TLS is not enabled. TLS is required to execute compute_engine_creds test case.")
|
||||||
|
}
|
||||||
|
interop.DoComputeEngineCreds(tc, *defaultServiceAccount, *oauthScope)
|
||||||
|
grpclog.Println("ComputeEngineCreds done")
|
||||||
|
case "service_account_creds":
|
||||||
|
if !*useTLS {
|
||||||
|
grpclog.Fatalf("TLS is not enabled. TLS is required to execute service_account_creds test case.")
|
||||||
|
}
|
||||||
|
interop.DoServiceAccountCreds(tc, *serviceAccountKeyFile, *oauthScope)
|
||||||
|
grpclog.Println("ServiceAccountCreds done")
|
||||||
|
case "jwt_token_creds":
|
||||||
|
if !*useTLS {
|
||||||
|
grpclog.Fatalf("TLS is not enabled. TLS is required to execute jwt_token_creds test case.")
|
||||||
|
}
|
||||||
|
interop.DoJWTTokenCreds(tc, *serviceAccountKeyFile)
|
||||||
|
grpclog.Println("JWTtokenCreds done")
|
||||||
|
case "per_rpc_creds":
|
||||||
|
if !*useTLS {
|
||||||
|
grpclog.Fatalf("TLS is not enabled. TLS is required to execute per_rpc_creds test case.")
|
||||||
|
}
|
||||||
|
interop.DoPerRPCCreds(tc, *serviceAccountKeyFile, *oauthScope)
|
||||||
|
grpclog.Println("PerRPCCreds done")
|
||||||
|
case "oauth2_auth_token":
|
||||||
|
if !*useTLS {
|
||||||
|
grpclog.Fatalf("TLS is not enabled. TLS is required to execute oauth2_auth_token test case.")
|
||||||
|
}
|
||||||
|
interop.DoOauth2TokenCreds(tc, *serviceAccountKeyFile, *oauthScope)
|
||||||
|
grpclog.Println("Oauth2TokenCreds done")
|
||||||
|
case "cancel_after_begin":
|
||||||
|
interop.DoCancelAfterBegin(tc)
|
||||||
|
grpclog.Println("CancelAfterBegin done")
|
||||||
|
case "cancel_after_first_response":
|
||||||
|
interop.DoCancelAfterFirstResponse(tc)
|
||||||
|
grpclog.Println("CancelAfterFirstResponse done")
|
||||||
|
default:
|
||||||
|
grpclog.Fatal("Unsupported test case: ", *testCase)
|
||||||
|
}
|
||||||
|
}
|
15
vendor/google.golang.org/grpc/interop/client/testdata/ca.pem
generated
vendored
Normal file
15
vendor/google.golang.org/grpc/interop/client/testdata/ca.pem
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICSjCCAbOgAwIBAgIJAJHGGR4dGioHMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV
|
||||||
|
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||||
|
aWRnaXRzIFB0eSBMdGQxDzANBgNVBAMTBnRlc3RjYTAeFw0xNDExMTEyMjMxMjla
|
||||||
|
Fw0yNDExMDgyMjMxMjlaMFYxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0
|
||||||
|
YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxDzANBgNVBAMT
|
||||||
|
BnRlc3RjYTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwEDfBV5MYdlHVHJ7
|
||||||
|
+L4nxrZy7mBfAVXpOc5vMYztssUI7mL2/iYujiIXM+weZYNTEpLdjyJdu7R5gGUu
|
||||||
|
g1jSVK/EPHfc74O7AyZU34PNIP4Sh33N+/A5YexrNgJlPY+E3GdVYi4ldWJjgkAd
|
||||||
|
Qah2PH5ACLrIIC6tRka9hcaBlIECAwEAAaMgMB4wDAYDVR0TBAUwAwEB/zAOBgNV
|
||||||
|
HQ8BAf8EBAMCAgQwDQYJKoZIhvcNAQELBQADgYEAHzC7jdYlzAVmddi/gdAeKPau
|
||||||
|
sPBG/C2HCWqHzpCUHcKuvMzDVkY/MP2o6JIW2DBbY64bO/FceExhjcykgaYtCH/m
|
||||||
|
oIU63+CFOTtR7otyQAWHqXa7q4SbCDlG7DyRFxqG0txPtGvy12lgldA2+RgcigQG
|
||||||
|
Dfcog5wrJytaQ6UA0wE=
|
||||||
|
-----END CERTIFICATE-----
|
16
vendor/google.golang.org/grpc/interop/client/testdata/server1.key
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/interop/client/testdata/server1.key
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAOHDFScoLCVJpYDD
|
||||||
|
M4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1BgzkWF+slf
|
||||||
|
3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd9N8YwbBY
|
||||||
|
AckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAECgYAn7qGnM2vbjJNBm0VZCkOkTIWm
|
||||||
|
V10okw7EPJrdL2mkre9NasghNXbE1y5zDshx5Nt3KsazKOxTT8d0Jwh/3KbaN+YY
|
||||||
|
tTCbKGW0pXDRBhwUHRcuRzScjli8Rih5UOCiZkhefUTcRb6xIhZJuQy71tjaSy0p
|
||||||
|
dHZRmYyBYO2YEQ8xoQJBAPrJPhMBkzmEYFtyIEqAxQ/o/A6E+E4w8i+KM7nQCK7q
|
||||||
|
K4JXzyXVAjLfyBZWHGM2uro/fjqPggGD6QH1qXCkI4MCQQDmdKeb2TrKRh5BY1LR
|
||||||
|
81aJGKcJ2XbcDu6wMZK4oqWbTX2KiYn9GB0woM6nSr/Y6iy1u145YzYxEV/iMwff
|
||||||
|
DJULAkB8B2MnyzOg0pNFJqBJuH29bKCcHa8gHJzqXhNO5lAlEbMK95p/P2Wi+4Hd
|
||||||
|
aiEIAF1BF326QJcvYKmwSmrORp85AkAlSNxRJ50OWrfMZnBgzVjDx3xG6KsFQVk2
|
||||||
|
ol6VhqL6dFgKUORFUWBvnKSyhjJxurlPEahV6oo6+A+mPhFY8eUvAkAZQyTdupP3
|
||||||
|
XEFQKctGz+9+gKkemDp7LBBMEMBXrGTLPhpEfcjv/7KPdnFHYmhYeBTBnuVmTVWe
|
||||||
|
F98XJ7tIFfJq
|
||||||
|
-----END PRIVATE KEY-----
|
16
vendor/google.golang.org/grpc/interop/client/testdata/server1.pem
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/interop/client/testdata/server1.pem
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICnDCCAgWgAwIBAgIBBzANBgkqhkiG9w0BAQsFADBWMQswCQYDVQQGEwJBVTET
|
||||||
|
MBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQ
|
||||||
|
dHkgTHRkMQ8wDQYDVQQDEwZ0ZXN0Y2EwHhcNMTUxMTA0MDIyMDI0WhcNMjUxMTAx
|
||||||
|
MDIyMDI0WjBlMQswCQYDVQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNV
|
||||||
|
BAcTB0NoaWNhZ28xFTATBgNVBAoTDEV4YW1wbGUsIENvLjEaMBgGA1UEAxQRKi50
|
||||||
|
ZXN0Lmdvb2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOHDFSco
|
||||||
|
LCVJpYDDM4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1Bg
|
||||||
|
zkWF+slf3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd
|
||||||
|
9N8YwbBYAckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAGjazBpMAkGA1UdEwQCMAAw
|
||||||
|
CwYDVR0PBAQDAgXgME8GA1UdEQRIMEaCECoudGVzdC5nb29nbGUuZnKCGHdhdGVy
|
||||||
|
em9vaS50ZXN0Lmdvb2dsZS5iZYISKi50ZXN0LnlvdXR1YmUuY29thwTAqAEDMA0G
|
||||||
|
CSqGSIb3DQEBCwUAA4GBAJFXVifQNub1LUP4JlnX5lXNlo8FxZ2a12AFQs+bzoJ6
|
||||||
|
hM044EDjqyxUqSbVePK0ni3w1fHQB5rY9yYC5f8G7aqqTY1QOhoUk8ZTSTRpnkTh
|
||||||
|
y4jjdvTZeLDVBlueZUTDRmy2feY5aZIU18vFDK08dTG0A87pppuv1LNIR3loveU8
|
||||||
|
-----END CERTIFICATE-----
|
788
vendor/google.golang.org/grpc/interop/grpc_testing/test.pb.go
generated
vendored
Executable file
788
vendor/google.golang.org/grpc/interop/grpc_testing/test.pb.go
generated
vendored
Executable file
|
@ -0,0 +1,788 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: test.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpc_testing is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
test.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
Empty
|
||||||
|
Payload
|
||||||
|
SimpleRequest
|
||||||
|
SimpleResponse
|
||||||
|
StreamingInputCallRequest
|
||||||
|
StreamingInputCallResponse
|
||||||
|
ResponseParameters
|
||||||
|
StreamingOutputCallRequest
|
||||||
|
StreamingOutputCallResponse
|
||||||
|
*/
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
// The type of payload that should be returned.
|
||||||
|
type PayloadType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Compressable text format.
|
||||||
|
PayloadType_COMPRESSABLE PayloadType = 0
|
||||||
|
// Uncompressable binary format.
|
||||||
|
PayloadType_UNCOMPRESSABLE PayloadType = 1
|
||||||
|
// Randomly chosen from all other formats defined in this enum.
|
||||||
|
PayloadType_RANDOM PayloadType = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var PayloadType_name = map[int32]string{
|
||||||
|
0: "COMPRESSABLE",
|
||||||
|
1: "UNCOMPRESSABLE",
|
||||||
|
2: "RANDOM",
|
||||||
|
}
|
||||||
|
var PayloadType_value = map[string]int32{
|
||||||
|
"COMPRESSABLE": 0,
|
||||||
|
"UNCOMPRESSABLE": 1,
|
||||||
|
"RANDOM": 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x PayloadType) Enum() *PayloadType {
|
||||||
|
p := new(PayloadType)
|
||||||
|
*p = x
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
func (x PayloadType) String() string {
|
||||||
|
return proto.EnumName(PayloadType_name, int32(x))
|
||||||
|
}
|
||||||
|
func (x *PayloadType) UnmarshalJSON(data []byte) error {
|
||||||
|
value, err := proto.UnmarshalJSONEnum(PayloadType_value, data, "PayloadType")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*x = PayloadType(value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (PayloadType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
type Empty struct {
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Empty) Reset() { *m = Empty{} }
|
||||||
|
func (m *Empty) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Empty) ProtoMessage() {}
|
||||||
|
func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
// A block of data, to simply increase gRPC message size.
|
||||||
|
type Payload struct {
|
||||||
|
// The type of data in body.
|
||||||
|
Type *PayloadType `protobuf:"varint,1,opt,name=type,enum=grpc.testing.PayloadType" json:"type,omitempty"`
|
||||||
|
// Primary contents of payload.
|
||||||
|
Body []byte `protobuf:"bytes,2,opt,name=body" json:"body,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Payload) Reset() { *m = Payload{} }
|
||||||
|
func (m *Payload) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Payload) ProtoMessage() {}
|
||||||
|
func (*Payload) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
func (m *Payload) GetType() PayloadType {
|
||||||
|
if m != nil && m.Type != nil {
|
||||||
|
return *m.Type
|
||||||
|
}
|
||||||
|
return PayloadType_COMPRESSABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Payload) GetBody() []byte {
|
||||||
|
if m != nil {
|
||||||
|
return m.Body
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unary request.
|
||||||
|
type SimpleRequest struct {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, server randomly chooses one from other formats.
|
||||||
|
ResponseType *PayloadType `protobuf:"varint,1,opt,name=response_type,json=responseType,enum=grpc.testing.PayloadType" json:"response_type,omitempty"`
|
||||||
|
// Desired payload size in the response from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
ResponseSize *int32 `protobuf:"varint,2,opt,name=response_size,json=responseSize" json:"response_size,omitempty"`
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload *Payload `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
// Whether SimpleResponse should include username.
|
||||||
|
FillUsername *bool `protobuf:"varint,4,opt,name=fill_username,json=fillUsername" json:"fill_username,omitempty"`
|
||||||
|
// Whether SimpleResponse should include OAuth scope.
|
||||||
|
FillOauthScope *bool `protobuf:"varint,5,opt,name=fill_oauth_scope,json=fillOauthScope" json:"fill_oauth_scope,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleRequest) Reset() { *m = SimpleRequest{} }
|
||||||
|
func (m *SimpleRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SimpleRequest) ProtoMessage() {}
|
||||||
|
func (*SimpleRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||||
|
|
||||||
|
func (m *SimpleRequest) GetResponseType() PayloadType {
|
||||||
|
if m != nil && m.ResponseType != nil {
|
||||||
|
return *m.ResponseType
|
||||||
|
}
|
||||||
|
return PayloadType_COMPRESSABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleRequest) GetResponseSize() int32 {
|
||||||
|
if m != nil && m.ResponseSize != nil {
|
||||||
|
return *m.ResponseSize
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleRequest) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleRequest) GetFillUsername() bool {
|
||||||
|
if m != nil && m.FillUsername != nil {
|
||||||
|
return *m.FillUsername
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleRequest) GetFillOauthScope() bool {
|
||||||
|
if m != nil && m.FillOauthScope != nil {
|
||||||
|
return *m.FillOauthScope
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unary response, as configured by the request.
|
||||||
|
type SimpleResponse struct {
|
||||||
|
// Payload to increase message size.
|
||||||
|
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
// The user the request came from, for verifying authentication was
|
||||||
|
// successful when the client expected it.
|
||||||
|
Username *string `protobuf:"bytes,2,opt,name=username" json:"username,omitempty"`
|
||||||
|
// OAuth scope.
|
||||||
|
OauthScope *string `protobuf:"bytes,3,opt,name=oauth_scope,json=oauthScope" json:"oauth_scope,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleResponse) Reset() { *m = SimpleResponse{} }
|
||||||
|
func (m *SimpleResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SimpleResponse) ProtoMessage() {}
|
||||||
|
func (*SimpleResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||||
|
|
||||||
|
func (m *SimpleResponse) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleResponse) GetUsername() string {
|
||||||
|
if m != nil && m.Username != nil {
|
||||||
|
return *m.Username
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SimpleResponse) GetOauthScope() string {
|
||||||
|
if m != nil && m.OauthScope != nil {
|
||||||
|
return *m.OauthScope
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming request.
|
||||||
|
type StreamingInputCallRequest struct {
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingInputCallRequest) Reset() { *m = StreamingInputCallRequest{} }
|
||||||
|
func (m *StreamingInputCallRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingInputCallRequest) ProtoMessage() {}
|
||||||
|
func (*StreamingInputCallRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||||
|
|
||||||
|
func (m *StreamingInputCallRequest) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming response.
|
||||||
|
type StreamingInputCallResponse struct {
|
||||||
|
// Aggregated size of payloads received from the client.
|
||||||
|
AggregatedPayloadSize *int32 `protobuf:"varint,1,opt,name=aggregated_payload_size,json=aggregatedPayloadSize" json:"aggregated_payload_size,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingInputCallResponse) Reset() { *m = StreamingInputCallResponse{} }
|
||||||
|
func (m *StreamingInputCallResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingInputCallResponse) ProtoMessage() {}
|
||||||
|
func (*StreamingInputCallResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||||
|
|
||||||
|
func (m *StreamingInputCallResponse) GetAggregatedPayloadSize() int32 {
|
||||||
|
if m != nil && m.AggregatedPayloadSize != nil {
|
||||||
|
return *m.AggregatedPayloadSize
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration for a particular response.
|
||||||
|
type ResponseParameters struct {
|
||||||
|
// Desired payload sizes in responses from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
Size *int32 `protobuf:"varint,1,opt,name=size" json:"size,omitempty"`
|
||||||
|
// Desired interval between consecutive responses in the response stream in
|
||||||
|
// microseconds.
|
||||||
|
IntervalUs *int32 `protobuf:"varint,2,opt,name=interval_us,json=intervalUs" json:"interval_us,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponseParameters) Reset() { *m = ResponseParameters{} }
|
||||||
|
func (m *ResponseParameters) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ResponseParameters) ProtoMessage() {}
|
||||||
|
func (*ResponseParameters) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||||
|
|
||||||
|
func (m *ResponseParameters) GetSize() int32 {
|
||||||
|
if m != nil && m.Size != nil {
|
||||||
|
return *m.Size
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponseParameters) GetIntervalUs() int32 {
|
||||||
|
if m != nil && m.IntervalUs != nil {
|
||||||
|
return *m.IntervalUs
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-streaming request.
|
||||||
|
type StreamingOutputCallRequest struct {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, the payload from each response in the stream
|
||||||
|
// might be of different types. This is to simulate a mixed type of payload
|
||||||
|
// stream.
|
||||||
|
ResponseType *PayloadType `protobuf:"varint,1,opt,name=response_type,json=responseType,enum=grpc.testing.PayloadType" json:"response_type,omitempty"`
|
||||||
|
// Configuration for each expected response message.
|
||||||
|
ResponseParameters []*ResponseParameters `protobuf:"bytes,2,rep,name=response_parameters,json=responseParameters" json:"response_parameters,omitempty"`
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
Payload *Payload `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) Reset() { *m = StreamingOutputCallRequest{} }
|
||||||
|
func (m *StreamingOutputCallRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingOutputCallRequest) ProtoMessage() {}
|
||||||
|
func (*StreamingOutputCallRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) GetResponseType() PayloadType {
|
||||||
|
if m != nil && m.ResponseType != nil {
|
||||||
|
return *m.ResponseType
|
||||||
|
}
|
||||||
|
return PayloadType_COMPRESSABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) GetResponseParameters() []*ResponseParameters {
|
||||||
|
if m != nil {
|
||||||
|
return m.ResponseParameters
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallRequest) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-streaming response, as configured by the request and parameters.
|
||||||
|
type StreamingOutputCallResponse struct {
|
||||||
|
// Payload to increase response size.
|
||||||
|
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallResponse) Reset() { *m = StreamingOutputCallResponse{} }
|
||||||
|
func (m *StreamingOutputCallResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*StreamingOutputCallResponse) ProtoMessage() {}
|
||||||
|
func (*StreamingOutputCallResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
|
||||||
|
|
||||||
|
func (m *StreamingOutputCallResponse) GetPayload() *Payload {
|
||||||
|
if m != nil {
|
||||||
|
return m.Payload
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*Empty)(nil), "grpc.testing.Empty")
|
||||||
|
proto.RegisterType((*Payload)(nil), "grpc.testing.Payload")
|
||||||
|
proto.RegisterType((*SimpleRequest)(nil), "grpc.testing.SimpleRequest")
|
||||||
|
proto.RegisterType((*SimpleResponse)(nil), "grpc.testing.SimpleResponse")
|
||||||
|
proto.RegisterType((*StreamingInputCallRequest)(nil), "grpc.testing.StreamingInputCallRequest")
|
||||||
|
proto.RegisterType((*StreamingInputCallResponse)(nil), "grpc.testing.StreamingInputCallResponse")
|
||||||
|
proto.RegisterType((*ResponseParameters)(nil), "grpc.testing.ResponseParameters")
|
||||||
|
proto.RegisterType((*StreamingOutputCallRequest)(nil), "grpc.testing.StreamingOutputCallRequest")
|
||||||
|
proto.RegisterType((*StreamingOutputCallResponse)(nil), "grpc.testing.StreamingOutputCallResponse")
|
||||||
|
proto.RegisterEnum("grpc.testing.PayloadType", PayloadType_name, PayloadType_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for TestService service
|
||||||
|
|
||||||
|
type TestServiceClient interface {
|
||||||
|
// One empty request followed by one empty response.
|
||||||
|
EmptyCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error)
|
||||||
|
// One request followed by a sequence of responses (streamed download).
|
||||||
|
// The server returns the payload with client desired type and sizes.
|
||||||
|
StreamingOutputCall(ctx context.Context, in *StreamingOutputCallRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error)
|
||||||
|
// A sequence of requests followed by one response (streamed upload).
|
||||||
|
// The server returns the aggregated size of client payload as the result.
|
||||||
|
StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error)
|
||||||
|
// A sequence of requests with each request served by the server immediately.
|
||||||
|
// As one request could lead to multiple responses, this interface
|
||||||
|
// demonstrates the idea of full duplexing.
|
||||||
|
FullDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_FullDuplexCallClient, error)
|
||||||
|
// A sequence of requests followed by a sequence of responses.
|
||||||
|
// The server buffers all the client requests and then serves them in order. A
|
||||||
|
// stream of responses are returned to the client when the server starts with
|
||||||
|
// first request.
|
||||||
|
HalfDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_HalfDuplexCallClient, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTestServiceClient(cc *grpc.ClientConn) TestServiceClient {
|
||||||
|
return &testServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testServiceClient) EmptyCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
|
out := new(Empty)
|
||||||
|
err := grpc.Invoke(ctx, "/grpc.testing.TestService/EmptyCall", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testServiceClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) {
|
||||||
|
out := new(SimpleResponse)
|
||||||
|
err := grpc.Invoke(ctx, "/grpc.testing.TestService/UnaryCall", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testServiceClient) StreamingOutputCall(ctx context.Context, in *StreamingOutputCallRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_TestService_serviceDesc.Streams[0], c.cc, "/grpc.testing.TestService/StreamingOutputCall", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &testServiceStreamingOutputCallClient{stream}
|
||||||
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_StreamingOutputCallClient interface {
|
||||||
|
Recv() (*StreamingOutputCallResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceStreamingOutputCallClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
|
m := new(StreamingOutputCallResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testServiceClient) StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_TestService_serviceDesc.Streams[1], c.cc, "/grpc.testing.TestService/StreamingInputCall", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &testServiceStreamingInputCallClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_StreamingInputCallClient interface {
|
||||||
|
Send(*StreamingInputCallRequest) error
|
||||||
|
CloseAndRecv() (*StreamingInputCallResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceStreamingInputCallClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
|
||||||
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m := new(StreamingInputCallResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testServiceClient) FullDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_FullDuplexCallClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_TestService_serviceDesc.Streams[2], c.cc, "/grpc.testing.TestService/FullDuplexCall", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &testServiceFullDuplexCallClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_FullDuplexCallClient interface {
|
||||||
|
Send(*StreamingOutputCallRequest) error
|
||||||
|
Recv() (*StreamingOutputCallResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceFullDuplexCallClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
|
m := new(StreamingOutputCallResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testServiceClient) HalfDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_HalfDuplexCallClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_TestService_serviceDesc.Streams[3], c.cc, "/grpc.testing.TestService/HalfDuplexCall", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &testServiceHalfDuplexCallClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_HalfDuplexCallClient interface {
|
||||||
|
Send(*StreamingOutputCallRequest) error
|
||||||
|
Recv() (*StreamingOutputCallResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceHalfDuplexCallClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
|
m := new(StreamingOutputCallResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for TestService service
|
||||||
|
|
||||||
|
type TestServiceServer interface {
|
||||||
|
// One empty request followed by one empty response.
|
||||||
|
EmptyCall(context.Context, *Empty) (*Empty, error)
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
UnaryCall(context.Context, *SimpleRequest) (*SimpleResponse, error)
|
||||||
|
// One request followed by a sequence of responses (streamed download).
|
||||||
|
// The server returns the payload with client desired type and sizes.
|
||||||
|
StreamingOutputCall(*StreamingOutputCallRequest, TestService_StreamingOutputCallServer) error
|
||||||
|
// A sequence of requests followed by one response (streamed upload).
|
||||||
|
// The server returns the aggregated size of client payload as the result.
|
||||||
|
StreamingInputCall(TestService_StreamingInputCallServer) error
|
||||||
|
// A sequence of requests with each request served by the server immediately.
|
||||||
|
// As one request could lead to multiple responses, this interface
|
||||||
|
// demonstrates the idea of full duplexing.
|
||||||
|
FullDuplexCall(TestService_FullDuplexCallServer) error
|
||||||
|
// A sequence of requests followed by a sequence of responses.
|
||||||
|
// The server buffers all the client requests and then serves them in order. A
|
||||||
|
// stream of responses are returned to the client when the server starts with
|
||||||
|
// first request.
|
||||||
|
HalfDuplexCall(TestService_HalfDuplexCallServer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) {
|
||||||
|
s.RegisterService(&_TestService_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(Empty)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(TestServiceServer).EmptyCall(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/grpc.testing.TestService/EmptyCall",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(TestServiceServer).EmptyCall(ctx, req.(*Empty))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SimpleRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(TestServiceServer).UnaryCall(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/grpc.testing.TestService/UnaryCall",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(TestServiceServer).UnaryCall(ctx, req.(*SimpleRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
m := new(StreamingOutputCallRequest)
|
||||||
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_StreamingOutputCallServer interface {
|
||||||
|
Send(*StreamingOutputCallResponse) error
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceStreamingOutputCallServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(TestServiceServer).StreamingInputCall(&testServiceStreamingInputCallServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_StreamingInputCallServer interface {
|
||||||
|
SendAndClose(*StreamingInputCallResponse) error
|
||||||
|
Recv() (*StreamingInputCallRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceStreamingInputCallServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
|
||||||
|
m := new(StreamingInputCallRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _TestService_FullDuplexCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(TestServiceServer).FullDuplexCall(&testServiceFullDuplexCallServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_FullDuplexCallServer interface {
|
||||||
|
Send(*StreamingOutputCallResponse) error
|
||||||
|
Recv() (*StreamingOutputCallRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceFullDuplexCallServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
|
m := new(StreamingOutputCallRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _TestService_HalfDuplexCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(TestServiceServer).HalfDuplexCall(&testServiceHalfDuplexCallServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestService_HalfDuplexCallServer interface {
|
||||||
|
Send(*StreamingOutputCallResponse) error
|
||||||
|
Recv() (*StreamingOutputCallRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServiceHalfDuplexCallServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
|
m := new(StreamingOutputCallRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _TestService_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "grpc.testing.TestService",
|
||||||
|
HandlerType: (*TestServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "EmptyCall",
|
||||||
|
Handler: _TestService_EmptyCall_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UnaryCall",
|
||||||
|
Handler: _TestService_UnaryCall_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "StreamingOutputCall",
|
||||||
|
Handler: _TestService_StreamingOutputCall_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
StreamName: "StreamingInputCall",
|
||||||
|
Handler: _TestService_StreamingInputCall_Handler,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
StreamName: "FullDuplexCall",
|
||||||
|
Handler: _TestService_FullDuplexCall_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
StreamName: "HalfDuplexCall",
|
||||||
|
Handler: _TestService_HalfDuplexCall_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: fileDescriptor0,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("test.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 567 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xbc, 0x54, 0x51, 0x6f, 0xd2, 0x50,
|
||||||
|
0x14, 0xb6, 0x03, 0x64, 0x1c, 0x58, 0x43, 0x0e, 0x59, 0x64, 0x9d, 0x89, 0x4b, 0x7d, 0xb0, 0x9a,
|
||||||
|
0x88, 0x86, 0x44, 0x1f, 0x35, 0x73, 0x63, 0x71, 0x09, 0x03, 0x6c, 0xe1, 0x99, 0x5c, 0xe1, 0x0e,
|
||||||
|
0x9b, 0x94, 0xb6, 0xb6, 0xb7, 0x46, 0x7c, 0xf0, 0x8f, 0xf9, 0x67, 0xfc, 0x11, 0xfe, 0x00, 0xef,
|
||||||
|
0xbd, 0x6d, 0xa1, 0x40, 0x17, 0x99, 0xc6, 0xbd, 0xb5, 0xdf, 0xf9, 0xce, 0x77, 0xbe, 0xef, 0x9e,
|
||||||
|
0xdb, 0x02, 0x30, 0x1a, 0xb2, 0x96, 0x1f, 0x78, 0xcc, 0xc3, 0xda, 0x2c, 0xf0, 0x27, 0x2d, 0x01,
|
||||||
|
0xd8, 0xee, 0x4c, 0x2f, 0x43, 0xa9, 0x33, 0xf7, 0xd9, 0x42, 0xef, 0x42, 0x79, 0x40, 0x16, 0x8e,
|
||||||
|
0x47, 0xa6, 0xf8, 0x1c, 0x8a, 0x6c, 0xe1, 0xd3, 0xa6, 0x72, 0xa2, 0x18, 0x6a, 0xfb, 0xa8, 0x95,
|
||||||
|
0x6d, 0x68, 0x25, 0xa4, 0x21, 0x27, 0x98, 0x92, 0x86, 0x08, 0xc5, 0x8f, 0xde, 0x74, 0xd1, 0xdc,
|
||||||
|
0xe3, 0xf4, 0x9a, 0x29, 0x9f, 0xf5, 0x5f, 0x0a, 0x1c, 0x58, 0xf6, 0xdc, 0x77, 0xa8, 0x49, 0x3f,
|
||||||
|
0x47, 0xbc, 0x15, 0xdf, 0xc0, 0x41, 0x40, 0x43, 0xdf, 0x73, 0x43, 0x3a, 0xde, 0x4d, 0xbd, 0x96,
|
||||||
|
0xf2, 0xc5, 0x1b, 0x3e, 0xce, 0xf4, 0x87, 0xf6, 0x37, 0x2a, 0xc7, 0x95, 0x56, 0x24, 0x8b, 0x63,
|
||||||
|
0xf8, 0x02, 0xca, 0x7e, 0xac, 0xd0, 0x2c, 0xf0, 0x72, 0xb5, 0x7d, 0x98, 0x2b, 0x6f, 0xa6, 0x2c,
|
||||||
|
0xa1, 0x7a, 0x6d, 0x3b, 0xce, 0x38, 0x0a, 0x69, 0xe0, 0x92, 0x39, 0x6d, 0x16, 0x79, 0xdb, 0xbe,
|
||||||
|
0x59, 0x13, 0xe0, 0x28, 0xc1, 0xd0, 0x80, 0xba, 0x24, 0x79, 0x24, 0x62, 0x9f, 0xc6, 0xe1, 0xc4,
|
||||||
|
0xe3, 0xee, 0x4b, 0x92, 0xa7, 0x0a, 0xbc, 0x2f, 0x60, 0x4b, 0xa0, 0xfa, 0x77, 0x50, 0xd3, 0xd4,
|
||||||
|
0xb1, 0xab, 0xac, 0x23, 0x65, 0x27, 0x47, 0x1a, 0xec, 0x2f, 0xcd, 0x88, 0x88, 0x15, 0x73, 0xf9,
|
||||||
|
0x8e, 0x8f, 0xa0, 0x9a, 0xf5, 0x50, 0x90, 0x65, 0xf0, 0x56, 0xf3, 0xbb, 0x70, 0x64, 0xb1, 0x80,
|
||||||
|
0x92, 0x39, 0x97, 0xbe, 0x74, 0xfd, 0x88, 0x9d, 0x11, 0xc7, 0x49, 0x37, 0x70, 0x5b, 0x2b, 0xfa,
|
||||||
|
0x10, 0xb4, 0x3c, 0xb5, 0x24, 0xd9, 0x6b, 0x78, 0x40, 0x66, 0xb3, 0x80, 0xce, 0x08, 0xa3, 0xd3,
|
||||||
|
0x71, 0xd2, 0x13, 0xaf, 0x46, 0x91, 0xab, 0x39, 0x5c, 0x95, 0x13, 0x69, 0xb1, 0x23, 0xfd, 0x12,
|
||||||
|
0x30, 0xd5, 0x18, 0x90, 0x80, 0xc7, 0x62, 0x34, 0x08, 0xc5, 0x25, 0xca, 0xb4, 0xca, 0x67, 0x11,
|
||||||
|
0xd7, 0x76, 0x79, 0xf5, 0x0b, 0x11, 0x0b, 0x4a, 0x16, 0x0e, 0x29, 0x34, 0x0a, 0xf5, 0x9f, 0x4a,
|
||||||
|
0xc6, 0x61, 0x3f, 0x62, 0x1b, 0x81, 0xff, 0xf5, 0xca, 0x7d, 0x80, 0xc6, 0xb2, 0xdf, 0x5f, 0x5a,
|
||||||
|
0xe5, 0x3e, 0x0a, 0xfc, 0xf0, 0x4e, 0xd6, 0x55, 0xb6, 0x23, 0x99, 0x18, 0x6c, 0xc7, 0xbc, 0xed,
|
||||||
|
0x05, 0xd5, 0x7b, 0x70, 0x9c, 0x9b, 0xf0, 0x2f, 0xaf, 0xd7, 0xb3, 0xb7, 0x50, 0xcd, 0x04, 0xc6,
|
||||||
|
0x3a, 0xd4, 0xce, 0xfa, 0x57, 0x03, 0xb3, 0x63, 0x59, 0xa7, 0xef, 0xba, 0x9d, 0xfa, 0x3d, 0xbe,
|
||||||
|
0x08, 0x75, 0xd4, 0x5b, 0xc3, 0x14, 0x04, 0xb8, 0x6f, 0x9e, 0xf6, 0xce, 0xfb, 0x57, 0xf5, 0xbd,
|
||||||
|
0xf6, 0x8f, 0x22, 0x54, 0x87, 0x5c, 0xdd, 0xe2, 0x4b, 0xb0, 0x27, 0x14, 0x5f, 0x41, 0x45, 0xfe,
|
||||||
|
0x40, 0x84, 0x2d, 0x6c, 0xac, 0x4f, 0x97, 0x05, 0x2d, 0x0f, 0xc4, 0x0b, 0xa8, 0x8c, 0x5c, 0x12,
|
||||||
|
0xc4, 0x6d, 0xc7, 0xeb, 0x8c, 0xb5, 0x1f, 0x87, 0xf6, 0x30, 0xbf, 0x98, 0x1c, 0x80, 0x03, 0x8d,
|
||||||
|
0x9c, 0xf3, 0x41, 0x63, 0xa3, 0xe9, 0xc6, 0x4b, 0xa2, 0x3d, 0xdd, 0x81, 0x19, 0xcf, 0x7a, 0xa9,
|
||||||
|
0xa0, 0x0d, 0xb8, 0xfd, 0x45, 0xe0, 0x93, 0x1b, 0x24, 0x36, 0xbf, 0x40, 0xcd, 0xf8, 0x33, 0x31,
|
||||||
|
0x1e, 0x65, 0x88, 0x51, 0xea, 0x45, 0xe4, 0x38, 0xe7, 0x11, 0x4f, 0xfb, 0xf5, 0xbf, 0x65, 0x32,
|
||||||
|
0x14, 0x99, 0x4a, 0x7d, 0x4f, 0x9c, 0xeb, 0x3b, 0x18, 0xf5, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x4c,
|
||||||
|
0x41, 0xfe, 0xb6, 0x89, 0x06, 0x00, 0x00,
|
||||||
|
}
|
140
vendor/google.golang.org/grpc/interop/grpc_testing/test.proto
generated
vendored
Normal file
140
vendor/google.golang.org/grpc/interop/grpc_testing/test.proto
generated
vendored
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
// An integration test service that covers all the method signature permutations
|
||||||
|
// of unary/streaming requests/responses.
|
||||||
|
syntax = "proto2";
|
||||||
|
|
||||||
|
package grpc.testing;
|
||||||
|
|
||||||
|
message Empty {}
|
||||||
|
|
||||||
|
// The type of payload that should be returned.
|
||||||
|
enum PayloadType {
|
||||||
|
// Compressable text format.
|
||||||
|
COMPRESSABLE = 0;
|
||||||
|
|
||||||
|
// Uncompressable binary format.
|
||||||
|
UNCOMPRESSABLE = 1;
|
||||||
|
|
||||||
|
// Randomly chosen from all other formats defined in this enum.
|
||||||
|
RANDOM = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A block of data, to simply increase gRPC message size.
|
||||||
|
message Payload {
|
||||||
|
// The type of data in body.
|
||||||
|
optional PayloadType type = 1;
|
||||||
|
// Primary contents of payload.
|
||||||
|
optional bytes body = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unary request.
|
||||||
|
message SimpleRequest {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, server randomly chooses one from other formats.
|
||||||
|
optional PayloadType response_type = 1;
|
||||||
|
|
||||||
|
// Desired payload size in the response from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
optional int32 response_size = 2;
|
||||||
|
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
optional Payload payload = 3;
|
||||||
|
|
||||||
|
// Whether SimpleResponse should include username.
|
||||||
|
optional bool fill_username = 4;
|
||||||
|
|
||||||
|
// Whether SimpleResponse should include OAuth scope.
|
||||||
|
optional bool fill_oauth_scope = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unary response, as configured by the request.
|
||||||
|
message SimpleResponse {
|
||||||
|
// Payload to increase message size.
|
||||||
|
optional Payload payload = 1;
|
||||||
|
|
||||||
|
// The user the request came from, for verifying authentication was
|
||||||
|
// successful when the client expected it.
|
||||||
|
optional string username = 2;
|
||||||
|
|
||||||
|
// OAuth scope.
|
||||||
|
optional string oauth_scope = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming request.
|
||||||
|
message StreamingInputCallRequest {
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
optional Payload payload = 1;
|
||||||
|
|
||||||
|
// Not expecting any payload from the response.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client-streaming response.
|
||||||
|
message StreamingInputCallResponse {
|
||||||
|
// Aggregated size of payloads received from the client.
|
||||||
|
optional int32 aggregated_payload_size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration for a particular response.
|
||||||
|
message ResponseParameters {
|
||||||
|
// Desired payload sizes in responses from the server.
|
||||||
|
// If response_type is COMPRESSABLE, this denotes the size before compression.
|
||||||
|
optional int32 size = 1;
|
||||||
|
|
||||||
|
// Desired interval between consecutive responses in the response stream in
|
||||||
|
// microseconds.
|
||||||
|
optional int32 interval_us = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-streaming request.
|
||||||
|
message StreamingOutputCallRequest {
|
||||||
|
// Desired payload type in the response from the server.
|
||||||
|
// If response_type is RANDOM, the payload from each response in the stream
|
||||||
|
// might be of different types. This is to simulate a mixed type of payload
|
||||||
|
// stream.
|
||||||
|
optional PayloadType response_type = 1;
|
||||||
|
|
||||||
|
// Configuration for each expected response message.
|
||||||
|
repeated ResponseParameters response_parameters = 2;
|
||||||
|
|
||||||
|
// Optional input payload sent along with the request.
|
||||||
|
optional Payload payload = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-streaming response, as configured by the request and parameters.
|
||||||
|
message StreamingOutputCallResponse {
|
||||||
|
// Payload to increase response size.
|
||||||
|
optional Payload payload = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A simple service to test the various types of RPCs and experiment with
|
||||||
|
// performance with various types of payload.
|
||||||
|
service TestService {
|
||||||
|
// One empty request followed by one empty response.
|
||||||
|
rpc EmptyCall(Empty) returns (Empty);
|
||||||
|
|
||||||
|
// One request followed by one response.
|
||||||
|
// The server returns the client payload as-is.
|
||||||
|
rpc UnaryCall(SimpleRequest) returns (SimpleResponse);
|
||||||
|
|
||||||
|
// One request followed by a sequence of responses (streamed download).
|
||||||
|
// The server returns the payload with client desired type and sizes.
|
||||||
|
rpc StreamingOutputCall(StreamingOutputCallRequest)
|
||||||
|
returns (stream StreamingOutputCallResponse);
|
||||||
|
|
||||||
|
// A sequence of requests followed by one response (streamed upload).
|
||||||
|
// The server returns the aggregated size of client payload as the result.
|
||||||
|
rpc StreamingInputCall(stream StreamingInputCallRequest)
|
||||||
|
returns (StreamingInputCallResponse);
|
||||||
|
|
||||||
|
// A sequence of requests with each request served by the server immediately.
|
||||||
|
// As one request could lead to multiple responses, this interface
|
||||||
|
// demonstrates the idea of full duplexing.
|
||||||
|
rpc FullDuplexCall(stream StreamingOutputCallRequest)
|
||||||
|
returns (stream StreamingOutputCallResponse);
|
||||||
|
|
||||||
|
// A sequence of requests followed by a sequence of responses.
|
||||||
|
// The server buffers all the client requests and then serves them in order. A
|
||||||
|
// stream of responses are returned to the client when the server starts with
|
||||||
|
// first request.
|
||||||
|
rpc HalfDuplexCall(stream StreamingOutputCallRequest)
|
||||||
|
returns (stream StreamingOutputCallResponse);
|
||||||
|
}
|
73
vendor/google.golang.org/grpc/interop/server/server.go
generated
vendored
Normal file
73
vendor/google.golang.org/grpc/interop/server/server.go
generated
vendored
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/interop"
|
||||||
|
testpb "google.golang.org/grpc/interop/grpc_testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
useTLS = flag.Bool("use_tls", false, "Connection uses TLS if true, else plain TCP")
|
||||||
|
certFile = flag.String("tls_cert_file", "testdata/server1.pem", "The TLS cert file")
|
||||||
|
keyFile = flag.String("tls_key_file", "testdata/server1.key", "The TLS key file")
|
||||||
|
port = flag.Int("port", 10000, "The server port")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
p := strconv.Itoa(*port)
|
||||||
|
lis, err := net.Listen("tcp", ":"+p)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
var opts []grpc.ServerOption
|
||||||
|
if *useTLS {
|
||||||
|
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to generate credentials %v", err)
|
||||||
|
}
|
||||||
|
opts = []grpc.ServerOption{grpc.Creds(creds)}
|
||||||
|
}
|
||||||
|
server := grpc.NewServer(opts...)
|
||||||
|
testpb.RegisterTestServiceServer(server, interop.NewTestServer())
|
||||||
|
server.Serve(lis)
|
||||||
|
}
|
15
vendor/google.golang.org/grpc/interop/server/testdata/ca.pem
generated
vendored
Normal file
15
vendor/google.golang.org/grpc/interop/server/testdata/ca.pem
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICSjCCAbOgAwIBAgIJAJHGGR4dGioHMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV
|
||||||
|
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||||
|
aWRnaXRzIFB0eSBMdGQxDzANBgNVBAMTBnRlc3RjYTAeFw0xNDExMTEyMjMxMjla
|
||||||
|
Fw0yNDExMDgyMjMxMjlaMFYxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0
|
||||||
|
YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxDzANBgNVBAMT
|
||||||
|
BnRlc3RjYTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwEDfBV5MYdlHVHJ7
|
||||||
|
+L4nxrZy7mBfAVXpOc5vMYztssUI7mL2/iYujiIXM+weZYNTEpLdjyJdu7R5gGUu
|
||||||
|
g1jSVK/EPHfc74O7AyZU34PNIP4Sh33N+/A5YexrNgJlPY+E3GdVYi4ldWJjgkAd
|
||||||
|
Qah2PH5ACLrIIC6tRka9hcaBlIECAwEAAaMgMB4wDAYDVR0TBAUwAwEB/zAOBgNV
|
||||||
|
HQ8BAf8EBAMCAgQwDQYJKoZIhvcNAQELBQADgYEAHzC7jdYlzAVmddi/gdAeKPau
|
||||||
|
sPBG/C2HCWqHzpCUHcKuvMzDVkY/MP2o6JIW2DBbY64bO/FceExhjcykgaYtCH/m
|
||||||
|
oIU63+CFOTtR7otyQAWHqXa7q4SbCDlG7DyRFxqG0txPtGvy12lgldA2+RgcigQG
|
||||||
|
Dfcog5wrJytaQ6UA0wE=
|
||||||
|
-----END CERTIFICATE-----
|
16
vendor/google.golang.org/grpc/interop/server/testdata/server1.key
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/interop/server/testdata/server1.key
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAOHDFScoLCVJpYDD
|
||||||
|
M4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1BgzkWF+slf
|
||||||
|
3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd9N8YwbBY
|
||||||
|
AckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAECgYAn7qGnM2vbjJNBm0VZCkOkTIWm
|
||||||
|
V10okw7EPJrdL2mkre9NasghNXbE1y5zDshx5Nt3KsazKOxTT8d0Jwh/3KbaN+YY
|
||||||
|
tTCbKGW0pXDRBhwUHRcuRzScjli8Rih5UOCiZkhefUTcRb6xIhZJuQy71tjaSy0p
|
||||||
|
dHZRmYyBYO2YEQ8xoQJBAPrJPhMBkzmEYFtyIEqAxQ/o/A6E+E4w8i+KM7nQCK7q
|
||||||
|
K4JXzyXVAjLfyBZWHGM2uro/fjqPggGD6QH1qXCkI4MCQQDmdKeb2TrKRh5BY1LR
|
||||||
|
81aJGKcJ2XbcDu6wMZK4oqWbTX2KiYn9GB0woM6nSr/Y6iy1u145YzYxEV/iMwff
|
||||||
|
DJULAkB8B2MnyzOg0pNFJqBJuH29bKCcHa8gHJzqXhNO5lAlEbMK95p/P2Wi+4Hd
|
||||||
|
aiEIAF1BF326QJcvYKmwSmrORp85AkAlSNxRJ50OWrfMZnBgzVjDx3xG6KsFQVk2
|
||||||
|
ol6VhqL6dFgKUORFUWBvnKSyhjJxurlPEahV6oo6+A+mPhFY8eUvAkAZQyTdupP3
|
||||||
|
XEFQKctGz+9+gKkemDp7LBBMEMBXrGTLPhpEfcjv/7KPdnFHYmhYeBTBnuVmTVWe
|
||||||
|
F98XJ7tIFfJq
|
||||||
|
-----END PRIVATE KEY-----
|
16
vendor/google.golang.org/grpc/interop/server/testdata/server1.pem
generated
vendored
Normal file
16
vendor/google.golang.org/grpc/interop/server/testdata/server1.pem
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICnDCCAgWgAwIBAgIBBzANBgkqhkiG9w0BAQsFADBWMQswCQYDVQQGEwJBVTET
|
||||||
|
MBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQ
|
||||||
|
dHkgTHRkMQ8wDQYDVQQDEwZ0ZXN0Y2EwHhcNMTUxMTA0MDIyMDI0WhcNMjUxMTAx
|
||||||
|
MDIyMDI0WjBlMQswCQYDVQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNV
|
||||||
|
BAcTB0NoaWNhZ28xFTATBgNVBAoTDEV4YW1wbGUsIENvLjEaMBgGA1UEAxQRKi50
|
||||||
|
ZXN0Lmdvb2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOHDFSco
|
||||||
|
LCVJpYDDM4HYtIdV6Ake/sMNaaKdODjDMsux/4tDydlumN+fm+AjPEK5GHhGn1Bg
|
||||||
|
zkWF+slf3BxhrA/8dNsnunstVA7ZBgA/5qQxMfGAq4wHNVX77fBZOgp9VlSMVfyd
|
||||||
|
9N8YwbBYAckOeUQadTi2X1S6OgJXgQ0m3MWhAgMBAAGjazBpMAkGA1UdEwQCMAAw
|
||||||
|
CwYDVR0PBAQDAgXgME8GA1UdEQRIMEaCECoudGVzdC5nb29nbGUuZnKCGHdhdGVy
|
||||||
|
em9vaS50ZXN0Lmdvb2dsZS5iZYISKi50ZXN0LnlvdXR1YmUuY29thwTAqAEDMA0G
|
||||||
|
CSqGSIb3DQEBCwUAA4GBAJFXVifQNub1LUP4JlnX5lXNlo8FxZ2a12AFQs+bzoJ6
|
||||||
|
hM044EDjqyxUqSbVePK0ni3w1fHQB5rY9yYC5f8G7aqqTY1QOhoUk8ZTSTRpnkTh
|
||||||
|
y4jjdvTZeLDVBlueZUTDRmy2feY5aZIU18vFDK08dTG0A87pppuv1LNIR3loveU8
|
||||||
|
-----END CERTIFICATE-----
|
592
vendor/google.golang.org/grpc/interop/test_utils.go
generated
vendored
Normal file
592
vendor/google.golang.org/grpc/interop/test_utils.go
generated
vendored
Normal file
|
@ -0,0 +1,592 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package interop
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/google"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
testpb "google.golang.org/grpc/interop/grpc_testing"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
reqSizes = []int{27182, 8, 1828, 45904}
|
||||||
|
respSizes = []int{31415, 9, 2653, 58979}
|
||||||
|
largeReqSize = 271828
|
||||||
|
largeRespSize = 314159
|
||||||
|
)
|
||||||
|
|
||||||
|
func clientNewPayload(t testpb.PayloadType, size int) *testpb.Payload {
|
||||||
|
if size < 0 {
|
||||||
|
grpclog.Fatalf("Requested a response with invalid length %d", size)
|
||||||
|
}
|
||||||
|
body := make([]byte, size)
|
||||||
|
switch t {
|
||||||
|
case testpb.PayloadType_COMPRESSABLE:
|
||||||
|
case testpb.PayloadType_UNCOMPRESSABLE:
|
||||||
|
grpclog.Fatalf("PayloadType UNCOMPRESSABLE is not supported")
|
||||||
|
default:
|
||||||
|
grpclog.Fatalf("Unsupported payload type: %d", t)
|
||||||
|
}
|
||||||
|
return &testpb.Payload{
|
||||||
|
Type: t.Enum(),
|
||||||
|
Body: body,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoEmptyUnaryCall performs a unary RPC with empty request and response messages.
|
||||||
|
func DoEmptyUnaryCall(tc testpb.TestServiceClient) {
|
||||||
|
reply, err := tc.EmptyCall(context.Background(), &testpb.Empty{})
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatal("/TestService/EmptyCall RPC failed: ", err)
|
||||||
|
}
|
||||||
|
if !proto.Equal(&testpb.Empty{}, reply) {
|
||||||
|
grpclog.Fatalf("/TestService/EmptyCall receives %v, want %v", reply, testpb.Empty{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoLargeUnaryCall performs a unary RPC with large payload in the request and response.
|
||||||
|
func DoLargeUnaryCall(tc testpb.TestServiceClient) {
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseSize: proto.Int32(int32(largeRespSize)),
|
||||||
|
Payload: pl,
|
||||||
|
}
|
||||||
|
reply, err := tc.UnaryCall(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err)
|
||||||
|
}
|
||||||
|
t := reply.GetPayload().GetType()
|
||||||
|
s := len(reply.GetPayload().GetBody())
|
||||||
|
if t != testpb.PayloadType_COMPRESSABLE || s != largeRespSize {
|
||||||
|
grpclog.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, largeRespSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoClientStreaming performs a client streaming RPC.
|
||||||
|
func DoClientStreaming(tc testpb.TestServiceClient) {
|
||||||
|
stream, err := tc.StreamingInputCall(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.StreamingInputCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
var sum int
|
||||||
|
for _, s := range reqSizes {
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, s)
|
||||||
|
req := &testpb.StreamingInputCallRequest{
|
||||||
|
Payload: pl,
|
||||||
|
}
|
||||||
|
if err := stream.Send(req); err != nil {
|
||||||
|
grpclog.Fatalf("%v.Send(%v) = %v", stream, req, err)
|
||||||
|
}
|
||||||
|
sum += s
|
||||||
|
grpclog.Printf("Sent a request of size %d, aggregated size %d", s, sum)
|
||||||
|
|
||||||
|
}
|
||||||
|
reply, err := stream.CloseAndRecv()
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
|
||||||
|
}
|
||||||
|
if reply.GetAggregatedPayloadSize() != int32(sum) {
|
||||||
|
grpclog.Fatalf("%v.CloseAndRecv().GetAggregatePayloadSize() = %v; want %v", stream, reply.GetAggregatedPayloadSize(), sum)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoServerStreaming performs a server streaming RPC.
|
||||||
|
func DoServerStreaming(tc testpb.TestServiceClient) {
|
||||||
|
respParam := make([]*testpb.ResponseParameters, len(respSizes))
|
||||||
|
for i, s := range respSizes {
|
||||||
|
respParam[i] = &testpb.ResponseParameters{
|
||||||
|
Size: proto.Int32(int32(s)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
req := &testpb.StreamingOutputCallRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseParameters: respParam,
|
||||||
|
}
|
||||||
|
stream, err := tc.StreamingOutputCall(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.StreamingOutputCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
var rpcStatus error
|
||||||
|
var respCnt int
|
||||||
|
var index int
|
||||||
|
for {
|
||||||
|
reply, err := stream.Recv()
|
||||||
|
if err != nil {
|
||||||
|
rpcStatus = err
|
||||||
|
break
|
||||||
|
}
|
||||||
|
t := reply.GetPayload().GetType()
|
||||||
|
if t != testpb.PayloadType_COMPRESSABLE {
|
||||||
|
grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
|
||||||
|
}
|
||||||
|
size := len(reply.GetPayload().GetBody())
|
||||||
|
if size != int(respSizes[index]) {
|
||||||
|
grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
|
||||||
|
}
|
||||||
|
index++
|
||||||
|
respCnt++
|
||||||
|
}
|
||||||
|
if rpcStatus != io.EOF {
|
||||||
|
grpclog.Fatalf("Failed to finish the server streaming rpc: %v", err)
|
||||||
|
}
|
||||||
|
if respCnt != len(respSizes) {
|
||||||
|
grpclog.Fatalf("Got %d reply, want %d", len(respSizes), respCnt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoPingPong performs ping-pong style bi-directional streaming RPC.
|
||||||
|
func DoPingPong(tc testpb.TestServiceClient) {
|
||||||
|
stream, err := tc.FullDuplexCall(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
var index int
|
||||||
|
for index < len(reqSizes) {
|
||||||
|
respParam := []*testpb.ResponseParameters{
|
||||||
|
{
|
||||||
|
Size: proto.Int32(int32(respSizes[index])),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, reqSizes[index])
|
||||||
|
req := &testpb.StreamingOutputCallRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseParameters: respParam,
|
||||||
|
Payload: pl,
|
||||||
|
}
|
||||||
|
if err := stream.Send(req); err != nil {
|
||||||
|
grpclog.Fatalf("%v.Send(%v) = %v", stream, req, err)
|
||||||
|
}
|
||||||
|
reply, err := stream.Recv()
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.Recv() = %v", stream, err)
|
||||||
|
}
|
||||||
|
t := reply.GetPayload().GetType()
|
||||||
|
if t != testpb.PayloadType_COMPRESSABLE {
|
||||||
|
grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
|
||||||
|
}
|
||||||
|
size := len(reply.GetPayload().GetBody())
|
||||||
|
if size != int(respSizes[index]) {
|
||||||
|
grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
|
||||||
|
}
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
if err := stream.CloseSend(); err != nil {
|
||||||
|
grpclog.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil)
|
||||||
|
}
|
||||||
|
if _, err := stream.Recv(); err != io.EOF {
|
||||||
|
grpclog.Fatalf("%v failed to complele the ping pong test: %v", stream, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoEmptyStream sets up a bi-directional streaming with zero message.
|
||||||
|
func DoEmptyStream(tc testpb.TestServiceClient) {
|
||||||
|
stream, err := tc.FullDuplexCall(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
if err := stream.CloseSend(); err != nil {
|
||||||
|
grpclog.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil)
|
||||||
|
}
|
||||||
|
if _, err := stream.Recv(); err != io.EOF {
|
||||||
|
grpclog.Fatalf("%v failed to complete the empty stream test: %v", stream, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoTimeoutOnSleepingServer performs an RPC on a sleep server which causes RPC timeout.
|
||||||
|
func DoTimeoutOnSleepingServer(tc testpb.TestServiceClient) {
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), 1*time.Millisecond)
|
||||||
|
stream, err := tc.FullDuplexCall(ctx)
|
||||||
|
if err != nil {
|
||||||
|
if grpc.Code(err) == codes.DeadlineExceeded {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, 27182)
|
||||||
|
req := &testpb.StreamingOutputCallRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
Payload: pl,
|
||||||
|
}
|
||||||
|
if err := stream.Send(req); err != nil {
|
||||||
|
grpclog.Fatalf("%v.Send(%v) = %v", stream, req, err)
|
||||||
|
}
|
||||||
|
if _, err := stream.Recv(); grpc.Code(err) != codes.DeadlineExceeded {
|
||||||
|
grpclog.Fatalf("%v.Recv() = _, %v, want error code %d", stream, err, codes.DeadlineExceeded)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoComputeEngineCreds performs a unary RPC with compute engine auth.
|
||||||
|
func DoComputeEngineCreds(tc testpb.TestServiceClient, serviceAccount, oauthScope string) {
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseSize: proto.Int32(int32(largeRespSize)),
|
||||||
|
Payload: pl,
|
||||||
|
FillUsername: proto.Bool(true),
|
||||||
|
FillOauthScope: proto.Bool(true),
|
||||||
|
}
|
||||||
|
reply, err := tc.UnaryCall(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err)
|
||||||
|
}
|
||||||
|
user := reply.GetUsername()
|
||||||
|
scope := reply.GetOauthScope()
|
||||||
|
if user != serviceAccount {
|
||||||
|
grpclog.Fatalf("Got user name %q, want %q.", user, serviceAccount)
|
||||||
|
}
|
||||||
|
if !strings.Contains(oauthScope, scope) {
|
||||||
|
grpclog.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, oauthScope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getServiceAccountJSONKey(keyFile string) []byte {
|
||||||
|
jsonKey, err := ioutil.ReadFile(keyFile)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to read the service account key file: %v", err)
|
||||||
|
}
|
||||||
|
return jsonKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoServiceAccountCreds performs a unary RPC with service account auth.
|
||||||
|
func DoServiceAccountCreds(tc testpb.TestServiceClient, serviceAccountKeyFile, oauthScope string) {
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseSize: proto.Int32(int32(largeRespSize)),
|
||||||
|
Payload: pl,
|
||||||
|
FillUsername: proto.Bool(true),
|
||||||
|
FillOauthScope: proto.Bool(true),
|
||||||
|
}
|
||||||
|
reply, err := tc.UnaryCall(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err)
|
||||||
|
}
|
||||||
|
jsonKey := getServiceAccountJSONKey(serviceAccountKeyFile)
|
||||||
|
user := reply.GetUsername()
|
||||||
|
scope := reply.GetOauthScope()
|
||||||
|
if !strings.Contains(string(jsonKey), user) {
|
||||||
|
grpclog.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey)
|
||||||
|
}
|
||||||
|
if !strings.Contains(oauthScope, scope) {
|
||||||
|
grpclog.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, oauthScope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoJWTTokenCreds performs a unary RPC with JWT token auth.
|
||||||
|
func DoJWTTokenCreds(tc testpb.TestServiceClient, serviceAccountKeyFile string) {
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseSize: proto.Int32(int32(largeRespSize)),
|
||||||
|
Payload: pl,
|
||||||
|
FillUsername: proto.Bool(true),
|
||||||
|
}
|
||||||
|
reply, err := tc.UnaryCall(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err)
|
||||||
|
}
|
||||||
|
jsonKey := getServiceAccountJSONKey(serviceAccountKeyFile)
|
||||||
|
user := reply.GetUsername()
|
||||||
|
if !strings.Contains(string(jsonKey), user) {
|
||||||
|
grpclog.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetToken obtains an OAUTH token from the input.
|
||||||
|
func GetToken(serviceAccountKeyFile string, oauthScope string) *oauth2.Token {
|
||||||
|
jsonKey := getServiceAccountJSONKey(serviceAccountKeyFile)
|
||||||
|
config, err := google.JWTConfigFromJSON(jsonKey, oauthScope)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to get the config: %v", err)
|
||||||
|
}
|
||||||
|
token, err := config.TokenSource(context.Background()).Token()
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("Failed to get the token: %v", err)
|
||||||
|
}
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoOauth2TokenCreds performs a unary RPC with OAUTH2 token auth.
|
||||||
|
func DoOauth2TokenCreds(tc testpb.TestServiceClient, serviceAccountKeyFile, oauthScope string) {
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseSize: proto.Int32(int32(largeRespSize)),
|
||||||
|
Payload: pl,
|
||||||
|
FillUsername: proto.Bool(true),
|
||||||
|
FillOauthScope: proto.Bool(true),
|
||||||
|
}
|
||||||
|
reply, err := tc.UnaryCall(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err)
|
||||||
|
}
|
||||||
|
jsonKey := getServiceAccountJSONKey(serviceAccountKeyFile)
|
||||||
|
user := reply.GetUsername()
|
||||||
|
scope := reply.GetOauthScope()
|
||||||
|
if !strings.Contains(string(jsonKey), user) {
|
||||||
|
grpclog.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey)
|
||||||
|
}
|
||||||
|
if !strings.Contains(oauthScope, scope) {
|
||||||
|
grpclog.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, oauthScope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoPerRPCCreds performs a unary RPC with per RPC OAUTH2 token.
|
||||||
|
func DoPerRPCCreds(tc testpb.TestServiceClient, serviceAccountKeyFile, oauthScope string) {
|
||||||
|
jsonKey := getServiceAccountJSONKey(serviceAccountKeyFile)
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
|
||||||
|
req := &testpb.SimpleRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseSize: proto.Int32(int32(largeRespSize)),
|
||||||
|
Payload: pl,
|
||||||
|
FillUsername: proto.Bool(true),
|
||||||
|
FillOauthScope: proto.Bool(true),
|
||||||
|
}
|
||||||
|
token := GetToken(serviceAccountKeyFile, oauthScope)
|
||||||
|
kv := map[string]string{"authorization": token.TokenType + " " + token.AccessToken}
|
||||||
|
ctx := metadata.NewContext(context.Background(), metadata.MD{"authorization": []string{kv["authorization"]}})
|
||||||
|
reply, err := tc.UnaryCall(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err)
|
||||||
|
}
|
||||||
|
user := reply.GetUsername()
|
||||||
|
scope := reply.GetOauthScope()
|
||||||
|
if !strings.Contains(string(jsonKey), user) {
|
||||||
|
grpclog.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey)
|
||||||
|
}
|
||||||
|
if !strings.Contains(oauthScope, scope) {
|
||||||
|
grpclog.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, oauthScope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
testMetadata = metadata.MD{
|
||||||
|
"key1": []string{"value1"},
|
||||||
|
"key2": []string{"value2"},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// DoCancelAfterBegin cancels the RPC after metadata has been sent but before payloads are sent.
|
||||||
|
func DoCancelAfterBegin(tc testpb.TestServiceClient) {
|
||||||
|
ctx, cancel := context.WithCancel(metadata.NewContext(context.Background(), testMetadata))
|
||||||
|
stream, err := tc.StreamingInputCall(ctx)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.StreamingInputCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
cancel()
|
||||||
|
_, err = stream.CloseAndRecv()
|
||||||
|
if grpc.Code(err) != codes.Canceled {
|
||||||
|
grpclog.Fatalf("%v.CloseAndRecv() got error code %d, want %d", stream, grpc.Code(err), codes.Canceled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoCancelAfterFirstResponse cancels the RPC after receiving the first message from the server.
|
||||||
|
func DoCancelAfterFirstResponse(tc testpb.TestServiceClient) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
stream, err := tc.FullDuplexCall(ctx)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err)
|
||||||
|
}
|
||||||
|
respParam := []*testpb.ResponseParameters{
|
||||||
|
{
|
||||||
|
Size: proto.Int32(31415),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, 27182)
|
||||||
|
req := &testpb.StreamingOutputCallRequest{
|
||||||
|
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||||
|
ResponseParameters: respParam,
|
||||||
|
Payload: pl,
|
||||||
|
}
|
||||||
|
if err := stream.Send(req); err != nil {
|
||||||
|
grpclog.Fatalf("%v.Send(%v) = %v", stream, req, err)
|
||||||
|
}
|
||||||
|
if _, err := stream.Recv(); err != nil {
|
||||||
|
grpclog.Fatalf("%v.Recv() = %v", stream, err)
|
||||||
|
}
|
||||||
|
cancel()
|
||||||
|
if _, err := stream.Recv(); grpc.Code(err) != codes.Canceled {
|
||||||
|
grpclog.Fatalf("%v compleled with error code %d, want %d", stream, grpc.Code(err), codes.Canceled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type testServer struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTestServer creates a test server for test service.
|
||||||
|
func NewTestServer() testpb.TestServiceServer {
|
||||||
|
return &testServer{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
|
||||||
|
return new(testpb.Empty), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func serverNewPayload(t testpb.PayloadType, size int32) (*testpb.Payload, error) {
|
||||||
|
if size < 0 {
|
||||||
|
return nil, fmt.Errorf("requested a response with invalid length %d", size)
|
||||||
|
}
|
||||||
|
body := make([]byte, size)
|
||||||
|
switch t {
|
||||||
|
case testpb.PayloadType_COMPRESSABLE:
|
||||||
|
case testpb.PayloadType_UNCOMPRESSABLE:
|
||||||
|
return nil, fmt.Errorf("payloadType UNCOMPRESSABLE is not supported")
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported payload type: %d", t)
|
||||||
|
}
|
||||||
|
return &testpb.Payload{
|
||||||
|
Type: t.Enum(),
|
||||||
|
Body: body,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||||
|
pl, err := serverNewPayload(in.GetResponseType(), in.GetResponseSize())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &testpb.SimpleResponse{
|
||||||
|
Payload: pl,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) StreamingOutputCall(args *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error {
|
||||||
|
cs := args.GetResponseParameters()
|
||||||
|
for _, c := range cs {
|
||||||
|
if us := c.GetIntervalUs(); us > 0 {
|
||||||
|
time.Sleep(time.Duration(us) * time.Microsecond)
|
||||||
|
}
|
||||||
|
pl, err := serverNewPayload(args.GetResponseType(), c.GetSize())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := stream.Send(&testpb.StreamingOutputCallResponse{
|
||||||
|
Payload: pl,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInputCallServer) error {
|
||||||
|
var sum int
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
return stream.SendAndClose(&testpb.StreamingInputCallResponse{
|
||||||
|
AggregatedPayloadSize: proto.Int32(int32(sum)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p := in.GetPayload().GetBody()
|
||||||
|
sum += len(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
// read done.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cs := in.GetResponseParameters()
|
||||||
|
for _, c := range cs {
|
||||||
|
if us := c.GetIntervalUs(); us > 0 {
|
||||||
|
time.Sleep(time.Duration(us) * time.Microsecond)
|
||||||
|
}
|
||||||
|
pl, err := serverNewPayload(in.GetResponseType(), c.GetSize())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := stream.Send(&testpb.StreamingOutputCallResponse{
|
||||||
|
Payload: pl,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testServer) HalfDuplexCall(stream testpb.TestService_HalfDuplexCallServer) error {
|
||||||
|
var msgBuf []*testpb.StreamingOutputCallRequest
|
||||||
|
for {
|
||||||
|
in, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
// read done.
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
msgBuf = append(msgBuf, in)
|
||||||
|
}
|
||||||
|
for _, m := range msgBuf {
|
||||||
|
cs := m.GetResponseParameters()
|
||||||
|
for _, c := range cs {
|
||||||
|
if us := c.GetIntervalUs(); us > 0 {
|
||||||
|
time.Sleep(time.Duration(us) * time.Microsecond)
|
||||||
|
}
|
||||||
|
pl, err := serverNewPayload(m.GetResponseType(), c.GetSize())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := stream.Send(&testpb.StreamingOutputCallResponse{
|
||||||
|
Payload: pl,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
147
vendor/google.golang.org/grpc/metadata/metadata.go
generated
vendored
Normal file
147
vendor/google.golang.org/grpc/metadata/metadata.go
generated
vendored
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package metadata define the structure of the metadata supported by gRPC library.
|
||||||
|
package metadata // import "google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
binHdrSuffix = "-bin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// encodeKeyValue encodes key and value qualified for transmission via gRPC.
|
||||||
|
// Transmitting binary headers violates HTTP/2 spec.
|
||||||
|
// TODO(zhaoq): Maybe check if k is ASCII also.
|
||||||
|
func encodeKeyValue(k, v string) (string, string) {
|
||||||
|
k = strings.ToLower(k)
|
||||||
|
if strings.HasSuffix(k, binHdrSuffix) {
|
||||||
|
val := base64.StdEncoding.EncodeToString([]byte(v))
|
||||||
|
v = string(val)
|
||||||
|
}
|
||||||
|
return k, v
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodeKeyValue returns the original key and value corresponding to the
|
||||||
|
// encoded data in k, v.
|
||||||
|
// If k is a binary header and v contains comma, v is split on comma before decoded,
|
||||||
|
// and the decoded v will be joined with comma before returned.
|
||||||
|
func DecodeKeyValue(k, v string) (string, string, error) {
|
||||||
|
if !strings.HasSuffix(k, binHdrSuffix) {
|
||||||
|
return k, v, nil
|
||||||
|
}
|
||||||
|
vvs := strings.Split(v, ",")
|
||||||
|
for i, vv := range vvs {
|
||||||
|
val, err := base64.StdEncoding.DecodeString(vv)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
vvs[i] = string(val)
|
||||||
|
}
|
||||||
|
return k, strings.Join(vvs, ","), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MD is a mapping from metadata keys to values. Users should use the following
|
||||||
|
// two convenience functions New and Pairs to generate MD.
|
||||||
|
type MD map[string][]string
|
||||||
|
|
||||||
|
// New creates a MD from given key-value map.
|
||||||
|
func New(m map[string]string) MD {
|
||||||
|
md := MD{}
|
||||||
|
for k, v := range m {
|
||||||
|
key, val := encodeKeyValue(k, v)
|
||||||
|
md[key] = append(md[key], val)
|
||||||
|
}
|
||||||
|
return md
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pairs returns an MD formed by the mapping of key, value ...
|
||||||
|
// Pairs panics if len(kv) is odd.
|
||||||
|
func Pairs(kv ...string) MD {
|
||||||
|
if len(kv)%2 == 1 {
|
||||||
|
panic(fmt.Sprintf("metadata: Pairs got the odd number of input pairs for metadata: %d", len(kv)))
|
||||||
|
}
|
||||||
|
md := MD{}
|
||||||
|
var k string
|
||||||
|
for i, s := range kv {
|
||||||
|
if i%2 == 0 {
|
||||||
|
k = s
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key, val := encodeKeyValue(k, s)
|
||||||
|
md[key] = append(md[key], val)
|
||||||
|
}
|
||||||
|
return md
|
||||||
|
}
|
||||||
|
|
||||||
|
// Len returns the number of items in md.
|
||||||
|
func (md MD) Len() int {
|
||||||
|
return len(md)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy returns a copy of md.
|
||||||
|
func (md MD) Copy() MD {
|
||||||
|
return Join(md)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join joins any number of MDs into a single MD.
|
||||||
|
// The order of values for each key is determined by the order in which
|
||||||
|
// the MDs containing those values are presented to Join.
|
||||||
|
func Join(mds ...MD) MD {
|
||||||
|
out := MD{}
|
||||||
|
for _, md := range mds {
|
||||||
|
for k, v := range md {
|
||||||
|
out[k] = append(out[k], v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
type mdKey struct{}
|
||||||
|
|
||||||
|
// NewContext creates a new context with md attached.
|
||||||
|
func NewContext(ctx context.Context, md MD) context.Context {
|
||||||
|
return context.WithValue(ctx, mdKey{}, md)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromContext returns the MD in ctx if it exists.
|
||||||
|
func FromContext(ctx context.Context) (md MD, ok bool) {
|
||||||
|
md, ok = ctx.Value(mdKey{}).(MD)
|
||||||
|
return
|
||||||
|
}
|
139
vendor/google.golang.org/grpc/metadata/metadata_test.go
generated
vendored
Normal file
139
vendor/google.golang.org/grpc/metadata/metadata_test.go
generated
vendored
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package metadata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const binaryValue = string(128)
|
||||||
|
|
||||||
|
func TestEncodeKeyValue(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
// input
|
||||||
|
kin string
|
||||||
|
vin string
|
||||||
|
// output
|
||||||
|
kout string
|
||||||
|
vout string
|
||||||
|
}{
|
||||||
|
{"key", "abc", "key", "abc"},
|
||||||
|
{"KEY", "abc", "key", "abc"},
|
||||||
|
{"key-bin", "abc", "key-bin", "YWJj"},
|
||||||
|
{"key-bin", binaryValue, "key-bin", "woA="},
|
||||||
|
} {
|
||||||
|
k, v := encodeKeyValue(test.kin, test.vin)
|
||||||
|
if k != test.kout || !reflect.DeepEqual(v, test.vout) {
|
||||||
|
t.Fatalf("encodeKeyValue(%q, %q) = %q, %q, want %q, %q", test.kin, test.vin, k, v, test.kout, test.vout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDecodeKeyValue(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
// input
|
||||||
|
kin string
|
||||||
|
vin string
|
||||||
|
// output
|
||||||
|
kout string
|
||||||
|
vout string
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
{"a", "abc", "a", "abc", nil},
|
||||||
|
{"key-bin", "Zm9vAGJhcg==", "key-bin", "foo\x00bar", nil},
|
||||||
|
{"key-bin", "woA=", "key-bin", binaryValue, nil},
|
||||||
|
{"a", "abc,efg", "a", "abc,efg", nil},
|
||||||
|
{"key-bin", "Zm9vAGJhcg==,Zm9vAGJhcg==", "key-bin", "foo\x00bar,foo\x00bar", nil},
|
||||||
|
} {
|
||||||
|
k, v, err := DecodeKeyValue(test.kin, test.vin)
|
||||||
|
if k != test.kout || !reflect.DeepEqual(v, test.vout) || !reflect.DeepEqual(err, test.err) {
|
||||||
|
t.Fatalf("DecodeKeyValue(%q, %q) = %q, %q, %v, want %q, %q, %v", test.kin, test.vin, k, v, err, test.kout, test.vout, test.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPairsMD(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
// input
|
||||||
|
kv []string
|
||||||
|
// output
|
||||||
|
md MD
|
||||||
|
size int
|
||||||
|
}{
|
||||||
|
{[]string{}, MD{}, 0},
|
||||||
|
{[]string{"k1", "v1", "k2-bin", binaryValue}, New(map[string]string{
|
||||||
|
"k1": "v1",
|
||||||
|
"k2-bin": binaryValue,
|
||||||
|
}), 2},
|
||||||
|
} {
|
||||||
|
md := Pairs(test.kv...)
|
||||||
|
if !reflect.DeepEqual(md, test.md) {
|
||||||
|
t.Fatalf("Pairs(%v) = %v, want %v", test.kv, md, test.md)
|
||||||
|
}
|
||||||
|
if md.Len() != test.size {
|
||||||
|
t.Fatalf("Pairs(%v) generates md of size %d, want %d", test.kv, md.Len(), test.size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCopy(t *testing.T) {
|
||||||
|
const key, val = "key", "val"
|
||||||
|
orig := Pairs(key, val)
|
||||||
|
copy := orig.Copy()
|
||||||
|
if !reflect.DeepEqual(orig, copy) {
|
||||||
|
t.Errorf("copied value not equal to the original, got %v, want %v", copy, orig)
|
||||||
|
}
|
||||||
|
orig[key][0] = "foo"
|
||||||
|
if v := copy[key][0]; v != val {
|
||||||
|
t.Errorf("change in original should not affect copy, got %q, want %q", v, val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJoin(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
mds []MD
|
||||||
|
want MD
|
||||||
|
}{
|
||||||
|
{[]MD{}, MD{}},
|
||||||
|
{[]MD{Pairs("foo", "bar")}, Pairs("foo", "bar")},
|
||||||
|
{[]MD{Pairs("foo", "bar"), Pairs("foo", "baz")}, Pairs("foo", "bar", "foo", "baz")},
|
||||||
|
{[]MD{Pairs("foo", "bar"), Pairs("foo", "baz"), Pairs("zip", "zap")}, Pairs("foo", "bar", "foo", "baz", "zip", "zap")},
|
||||||
|
} {
|
||||||
|
md := Join(test.mds...)
|
||||||
|
if !reflect.DeepEqual(md, test.want) {
|
||||||
|
t.Errorf("context's metadata is %v, want %v", md, test.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
74
vendor/google.golang.org/grpc/naming/naming.go
generated
vendored
Normal file
74
vendor/google.golang.org/grpc/naming/naming.go
generated
vendored
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package naming defines the naming API and related data structures for gRPC.
|
||||||
|
// The interface is EXPERIMENTAL and may be suject to change.
|
||||||
|
package naming
|
||||||
|
|
||||||
|
// Operation defines the corresponding operations for a name resolution change.
|
||||||
|
type Operation uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Add indicates a new address is added.
|
||||||
|
Add Operation = iota
|
||||||
|
// Delete indicates an exisiting address is deleted.
|
||||||
|
Delete
|
||||||
|
)
|
||||||
|
|
||||||
|
// Update defines a name resolution update. Notice that it is not valid having both
|
||||||
|
// empty string Addr and nil Metadata in an Update.
|
||||||
|
type Update struct {
|
||||||
|
// Op indicates the operation of the update.
|
||||||
|
Op Operation
|
||||||
|
// Addr is the updated address. It is empty string if there is no address update.
|
||||||
|
Addr string
|
||||||
|
// Metadata is the updated metadata. It is nil if there is no metadata update.
|
||||||
|
// Metadata is not required for a custom naming implementation.
|
||||||
|
Metadata interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolver creates a Watcher for a target to track its resolution changes.
|
||||||
|
type Resolver interface {
|
||||||
|
// Resolve creates a Watcher for target.
|
||||||
|
Resolve(target string) (Watcher, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Watcher watches for the updates on the specified target.
|
||||||
|
type Watcher interface {
|
||||||
|
// Next blocks until an update or error happens. It may return one or more
|
||||||
|
// updates. The first call should get the full set of the results. It should
|
||||||
|
// return an error if and only if Watcher cannot recover.
|
||||||
|
Next() ([]*Update, error)
|
||||||
|
// Close closes the Watcher.
|
||||||
|
Close()
|
||||||
|
}
|
65
vendor/google.golang.org/grpc/peer/peer.go
generated
vendored
Normal file
65
vendor/google.golang.org/grpc/peer/peer.go
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2014, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package peer defines various peer information associated with RPCs and
|
||||||
|
// corresponding utils.
|
||||||
|
package peer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Peer contains the information of the peer for an RPC.
|
||||||
|
type Peer struct {
|
||||||
|
// Addr is the peer address.
|
||||||
|
Addr net.Addr
|
||||||
|
// AuthInfo is the authentication information of the transport.
|
||||||
|
// It is nil if there is no transport security being used.
|
||||||
|
AuthInfo credentials.AuthInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type peerKey struct{}
|
||||||
|
|
||||||
|
// NewContext creates a new context with peer information attached.
|
||||||
|
func NewContext(ctx context.Context, p *Peer) context.Context {
|
||||||
|
return context.WithValue(ctx, peerKey{}, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromContext returns the peer information in ctx if it exists.
|
||||||
|
func FromContext(ctx context.Context) (p *Peer, ok bool) {
|
||||||
|
p, ok = ctx.Value(peerKey{}).(*Peer)
|
||||||
|
return
|
||||||
|
}
|
18
vendor/google.golang.org/grpc/reflection/README.md
generated
vendored
Normal file
18
vendor/google.golang.org/grpc/reflection/README.md
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Reflection
|
||||||
|
|
||||||
|
Package reflection implements server reflection service.
|
||||||
|
|
||||||
|
The service implemented is defined in: https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto.
|
||||||
|
|
||||||
|
To register server reflection on a gRPC server:
|
||||||
|
```go
|
||||||
|
import "google.golang.org/grpc/reflection"
|
||||||
|
|
||||||
|
s := grpc.NewServer()
|
||||||
|
pb.RegisterYourOwnServer(s, &server{})
|
||||||
|
|
||||||
|
// Register reflection service on gRPC server.
|
||||||
|
reflection.Register(s)
|
||||||
|
|
||||||
|
s.Serve(lis)
|
||||||
|
```
|
694
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go
generated
vendored
Normal file
694
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,694 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: reflection.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpc_reflection_v1alpha is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
reflection.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
ServerReflectionRequest
|
||||||
|
ExtensionRequest
|
||||||
|
ServerReflectionResponse
|
||||||
|
FileDescriptorResponse
|
||||||
|
ExtensionNumberResponse
|
||||||
|
ListServiceResponse
|
||||||
|
ServiceResponse
|
||||||
|
ErrorResponse
|
||||||
|
*/
|
||||||
|
package grpc_reflection_v1alpha
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
// The message sent by the client when calling ServerReflectionInfo method.
|
||||||
|
type ServerReflectionRequest struct {
|
||||||
|
Host string `protobuf:"bytes,1,opt,name=host" json:"host,omitempty"`
|
||||||
|
// To use reflection service, the client should set one of the following
|
||||||
|
// fields in message_request. The server distinguishes requests by their
|
||||||
|
// defined field and then handles them using corresponding methods.
|
||||||
|
//
|
||||||
|
// Types that are valid to be assigned to MessageRequest:
|
||||||
|
// *ServerReflectionRequest_FileByFilename
|
||||||
|
// *ServerReflectionRequest_FileContainingSymbol
|
||||||
|
// *ServerReflectionRequest_FileContainingExtension
|
||||||
|
// *ServerReflectionRequest_AllExtensionNumbersOfType
|
||||||
|
// *ServerReflectionRequest_ListServices
|
||||||
|
MessageRequest isServerReflectionRequest_MessageRequest `protobuf_oneof:"message_request"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionRequest) Reset() { *m = ServerReflectionRequest{} }
|
||||||
|
func (m *ServerReflectionRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServerReflectionRequest) ProtoMessage() {}
|
||||||
|
func (*ServerReflectionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
type isServerReflectionRequest_MessageRequest interface {
|
||||||
|
isServerReflectionRequest_MessageRequest()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerReflectionRequest_FileByFilename struct {
|
||||||
|
FileByFilename string `protobuf:"bytes,3,opt,name=file_by_filename,json=fileByFilename,oneof"`
|
||||||
|
}
|
||||||
|
type ServerReflectionRequest_FileContainingSymbol struct {
|
||||||
|
FileContainingSymbol string `protobuf:"bytes,4,opt,name=file_containing_symbol,json=fileContainingSymbol,oneof"`
|
||||||
|
}
|
||||||
|
type ServerReflectionRequest_FileContainingExtension struct {
|
||||||
|
FileContainingExtension *ExtensionRequest `protobuf:"bytes,5,opt,name=file_containing_extension,json=fileContainingExtension,oneof"`
|
||||||
|
}
|
||||||
|
type ServerReflectionRequest_AllExtensionNumbersOfType struct {
|
||||||
|
AllExtensionNumbersOfType string `protobuf:"bytes,6,opt,name=all_extension_numbers_of_type,json=allExtensionNumbersOfType,oneof"`
|
||||||
|
}
|
||||||
|
type ServerReflectionRequest_ListServices struct {
|
||||||
|
ListServices string `protobuf:"bytes,7,opt,name=list_services,json=listServices,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ServerReflectionRequest_FileByFilename) isServerReflectionRequest_MessageRequest() {}
|
||||||
|
func (*ServerReflectionRequest_FileContainingSymbol) isServerReflectionRequest_MessageRequest() {}
|
||||||
|
func (*ServerReflectionRequest_FileContainingExtension) isServerReflectionRequest_MessageRequest() {}
|
||||||
|
func (*ServerReflectionRequest_AllExtensionNumbersOfType) isServerReflectionRequest_MessageRequest() {}
|
||||||
|
func (*ServerReflectionRequest_ListServices) isServerReflectionRequest_MessageRequest() {}
|
||||||
|
|
||||||
|
func (m *ServerReflectionRequest) GetMessageRequest() isServerReflectionRequest_MessageRequest {
|
||||||
|
if m != nil {
|
||||||
|
return m.MessageRequest
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionRequest) GetFileByFilename() string {
|
||||||
|
if x, ok := m.GetMessageRequest().(*ServerReflectionRequest_FileByFilename); ok {
|
||||||
|
return x.FileByFilename
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionRequest) GetFileContainingSymbol() string {
|
||||||
|
if x, ok := m.GetMessageRequest().(*ServerReflectionRequest_FileContainingSymbol); ok {
|
||||||
|
return x.FileContainingSymbol
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionRequest) GetFileContainingExtension() *ExtensionRequest {
|
||||||
|
if x, ok := m.GetMessageRequest().(*ServerReflectionRequest_FileContainingExtension); ok {
|
||||||
|
return x.FileContainingExtension
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionRequest) GetAllExtensionNumbersOfType() string {
|
||||||
|
if x, ok := m.GetMessageRequest().(*ServerReflectionRequest_AllExtensionNumbersOfType); ok {
|
||||||
|
return x.AllExtensionNumbersOfType
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionRequest) GetListServices() string {
|
||||||
|
if x, ok := m.GetMessageRequest().(*ServerReflectionRequest_ListServices); ok {
|
||||||
|
return x.ListServices
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*ServerReflectionRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _ServerReflectionRequest_OneofMarshaler, _ServerReflectionRequest_OneofUnmarshaler, _ServerReflectionRequest_OneofSizer, []interface{}{
|
||||||
|
(*ServerReflectionRequest_FileByFilename)(nil),
|
||||||
|
(*ServerReflectionRequest_FileContainingSymbol)(nil),
|
||||||
|
(*ServerReflectionRequest_FileContainingExtension)(nil),
|
||||||
|
(*ServerReflectionRequest_AllExtensionNumbersOfType)(nil),
|
||||||
|
(*ServerReflectionRequest_ListServices)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerReflectionRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*ServerReflectionRequest)
|
||||||
|
// message_request
|
||||||
|
switch x := m.MessageRequest.(type) {
|
||||||
|
case *ServerReflectionRequest_FileByFilename:
|
||||||
|
b.EncodeVarint(3<<3 | proto.WireBytes)
|
||||||
|
b.EncodeStringBytes(x.FileByFilename)
|
||||||
|
case *ServerReflectionRequest_FileContainingSymbol:
|
||||||
|
b.EncodeVarint(4<<3 | proto.WireBytes)
|
||||||
|
b.EncodeStringBytes(x.FileContainingSymbol)
|
||||||
|
case *ServerReflectionRequest_FileContainingExtension:
|
||||||
|
b.EncodeVarint(5<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.FileContainingExtension); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *ServerReflectionRequest_AllExtensionNumbersOfType:
|
||||||
|
b.EncodeVarint(6<<3 | proto.WireBytes)
|
||||||
|
b.EncodeStringBytes(x.AllExtensionNumbersOfType)
|
||||||
|
case *ServerReflectionRequest_ListServices:
|
||||||
|
b.EncodeVarint(7<<3 | proto.WireBytes)
|
||||||
|
b.EncodeStringBytes(x.ListServices)
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("ServerReflectionRequest.MessageRequest has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerReflectionRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*ServerReflectionRequest)
|
||||||
|
switch tag {
|
||||||
|
case 3: // message_request.file_by_filename
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
x, err := b.DecodeStringBytes()
|
||||||
|
m.MessageRequest = &ServerReflectionRequest_FileByFilename{x}
|
||||||
|
return true, err
|
||||||
|
case 4: // message_request.file_containing_symbol
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
x, err := b.DecodeStringBytes()
|
||||||
|
m.MessageRequest = &ServerReflectionRequest_FileContainingSymbol{x}
|
||||||
|
return true, err
|
||||||
|
case 5: // message_request.file_containing_extension
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ExtensionRequest)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.MessageRequest = &ServerReflectionRequest_FileContainingExtension{msg}
|
||||||
|
return true, err
|
||||||
|
case 6: // message_request.all_extension_numbers_of_type
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
x, err := b.DecodeStringBytes()
|
||||||
|
m.MessageRequest = &ServerReflectionRequest_AllExtensionNumbersOfType{x}
|
||||||
|
return true, err
|
||||||
|
case 7: // message_request.list_services
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
x, err := b.DecodeStringBytes()
|
||||||
|
m.MessageRequest = &ServerReflectionRequest_ListServices{x}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerReflectionRequest_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*ServerReflectionRequest)
|
||||||
|
// message_request
|
||||||
|
switch x := m.MessageRequest.(type) {
|
||||||
|
case *ServerReflectionRequest_FileByFilename:
|
||||||
|
n += proto.SizeVarint(3<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(len(x.FileByFilename)))
|
||||||
|
n += len(x.FileByFilename)
|
||||||
|
case *ServerReflectionRequest_FileContainingSymbol:
|
||||||
|
n += proto.SizeVarint(4<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(len(x.FileContainingSymbol)))
|
||||||
|
n += len(x.FileContainingSymbol)
|
||||||
|
case *ServerReflectionRequest_FileContainingExtension:
|
||||||
|
s := proto.Size(x.FileContainingExtension)
|
||||||
|
n += proto.SizeVarint(5<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *ServerReflectionRequest_AllExtensionNumbersOfType:
|
||||||
|
n += proto.SizeVarint(6<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(len(x.AllExtensionNumbersOfType)))
|
||||||
|
n += len(x.AllExtensionNumbersOfType)
|
||||||
|
case *ServerReflectionRequest_ListServices:
|
||||||
|
n += proto.SizeVarint(7<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(len(x.ListServices)))
|
||||||
|
n += len(x.ListServices)
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
// The type name and extension number sent by the client when requesting
|
||||||
|
// file_containing_extension.
|
||||||
|
type ExtensionRequest struct {
|
||||||
|
// Fully-qualified type name. The format should be <package>.<type>
|
||||||
|
ContainingType string `protobuf:"bytes,1,opt,name=containing_type,json=containingType" json:"containing_type,omitempty"`
|
||||||
|
ExtensionNumber int32 `protobuf:"varint,2,opt,name=extension_number,json=extensionNumber" json:"extension_number,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ExtensionRequest) Reset() { *m = ExtensionRequest{} }
|
||||||
|
func (m *ExtensionRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ExtensionRequest) ProtoMessage() {}
|
||||||
|
func (*ExtensionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
// The message sent by the server to answer ServerReflectionInfo method.
|
||||||
|
type ServerReflectionResponse struct {
|
||||||
|
ValidHost string `protobuf:"bytes,1,opt,name=valid_host,json=validHost" json:"valid_host,omitempty"`
|
||||||
|
OriginalRequest *ServerReflectionRequest `protobuf:"bytes,2,opt,name=original_request,json=originalRequest" json:"original_request,omitempty"`
|
||||||
|
// The server set one of the following fields accroding to the message_request
|
||||||
|
// in the request.
|
||||||
|
//
|
||||||
|
// Types that are valid to be assigned to MessageResponse:
|
||||||
|
// *ServerReflectionResponse_FileDescriptorResponse
|
||||||
|
// *ServerReflectionResponse_AllExtensionNumbersResponse
|
||||||
|
// *ServerReflectionResponse_ListServicesResponse
|
||||||
|
// *ServerReflectionResponse_ErrorResponse
|
||||||
|
MessageResponse isServerReflectionResponse_MessageResponse `protobuf_oneof:"message_response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionResponse) Reset() { *m = ServerReflectionResponse{} }
|
||||||
|
func (m *ServerReflectionResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServerReflectionResponse) ProtoMessage() {}
|
||||||
|
func (*ServerReflectionResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||||
|
|
||||||
|
type isServerReflectionResponse_MessageResponse interface {
|
||||||
|
isServerReflectionResponse_MessageResponse()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerReflectionResponse_FileDescriptorResponse struct {
|
||||||
|
FileDescriptorResponse *FileDescriptorResponse `protobuf:"bytes,4,opt,name=file_descriptor_response,json=fileDescriptorResponse,oneof"`
|
||||||
|
}
|
||||||
|
type ServerReflectionResponse_AllExtensionNumbersResponse struct {
|
||||||
|
AllExtensionNumbersResponse *ExtensionNumberResponse `protobuf:"bytes,5,opt,name=all_extension_numbers_response,json=allExtensionNumbersResponse,oneof"`
|
||||||
|
}
|
||||||
|
type ServerReflectionResponse_ListServicesResponse struct {
|
||||||
|
ListServicesResponse *ListServiceResponse `protobuf:"bytes,6,opt,name=list_services_response,json=listServicesResponse,oneof"`
|
||||||
|
}
|
||||||
|
type ServerReflectionResponse_ErrorResponse struct {
|
||||||
|
ErrorResponse *ErrorResponse `protobuf:"bytes,7,opt,name=error_response,json=errorResponse,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ServerReflectionResponse_FileDescriptorResponse) isServerReflectionResponse_MessageResponse() {}
|
||||||
|
func (*ServerReflectionResponse_AllExtensionNumbersResponse) isServerReflectionResponse_MessageResponse() {
|
||||||
|
}
|
||||||
|
func (*ServerReflectionResponse_ListServicesResponse) isServerReflectionResponse_MessageResponse() {}
|
||||||
|
func (*ServerReflectionResponse_ErrorResponse) isServerReflectionResponse_MessageResponse() {}
|
||||||
|
|
||||||
|
func (m *ServerReflectionResponse) GetMessageResponse() isServerReflectionResponse_MessageResponse {
|
||||||
|
if m != nil {
|
||||||
|
return m.MessageResponse
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionResponse) GetOriginalRequest() *ServerReflectionRequest {
|
||||||
|
if m != nil {
|
||||||
|
return m.OriginalRequest
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionResponse) GetFileDescriptorResponse() *FileDescriptorResponse {
|
||||||
|
if x, ok := m.GetMessageResponse().(*ServerReflectionResponse_FileDescriptorResponse); ok {
|
||||||
|
return x.FileDescriptorResponse
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionResponse) GetAllExtensionNumbersResponse() *ExtensionNumberResponse {
|
||||||
|
if x, ok := m.GetMessageResponse().(*ServerReflectionResponse_AllExtensionNumbersResponse); ok {
|
||||||
|
return x.AllExtensionNumbersResponse
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionResponse) GetListServicesResponse() *ListServiceResponse {
|
||||||
|
if x, ok := m.GetMessageResponse().(*ServerReflectionResponse_ListServicesResponse); ok {
|
||||||
|
return x.ListServicesResponse
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServerReflectionResponse) GetErrorResponse() *ErrorResponse {
|
||||||
|
if x, ok := m.GetMessageResponse().(*ServerReflectionResponse_ErrorResponse); ok {
|
||||||
|
return x.ErrorResponse
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||||
|
func (*ServerReflectionResponse) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||||
|
return _ServerReflectionResponse_OneofMarshaler, _ServerReflectionResponse_OneofUnmarshaler, _ServerReflectionResponse_OneofSizer, []interface{}{
|
||||||
|
(*ServerReflectionResponse_FileDescriptorResponse)(nil),
|
||||||
|
(*ServerReflectionResponse_AllExtensionNumbersResponse)(nil),
|
||||||
|
(*ServerReflectionResponse_ListServicesResponse)(nil),
|
||||||
|
(*ServerReflectionResponse_ErrorResponse)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerReflectionResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||||
|
m := msg.(*ServerReflectionResponse)
|
||||||
|
// message_response
|
||||||
|
switch x := m.MessageResponse.(type) {
|
||||||
|
case *ServerReflectionResponse_FileDescriptorResponse:
|
||||||
|
b.EncodeVarint(4<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.FileDescriptorResponse); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *ServerReflectionResponse_AllExtensionNumbersResponse:
|
||||||
|
b.EncodeVarint(5<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.AllExtensionNumbersResponse); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *ServerReflectionResponse_ListServicesResponse:
|
||||||
|
b.EncodeVarint(6<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.ListServicesResponse); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case *ServerReflectionResponse_ErrorResponse:
|
||||||
|
b.EncodeVarint(7<<3 | proto.WireBytes)
|
||||||
|
if err := b.EncodeMessage(x.ErrorResponse); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("ServerReflectionResponse.MessageResponse has unexpected type %T", x)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerReflectionResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||||
|
m := msg.(*ServerReflectionResponse)
|
||||||
|
switch tag {
|
||||||
|
case 4: // message_response.file_descriptor_response
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(FileDescriptorResponse)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.MessageResponse = &ServerReflectionResponse_FileDescriptorResponse{msg}
|
||||||
|
return true, err
|
||||||
|
case 5: // message_response.all_extension_numbers_response
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ExtensionNumberResponse)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.MessageResponse = &ServerReflectionResponse_AllExtensionNumbersResponse{msg}
|
||||||
|
return true, err
|
||||||
|
case 6: // message_response.list_services_response
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ListServiceResponse)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.MessageResponse = &ServerReflectionResponse_ListServicesResponse{msg}
|
||||||
|
return true, err
|
||||||
|
case 7: // message_response.error_response
|
||||||
|
if wire != proto.WireBytes {
|
||||||
|
return true, proto.ErrInternalBadWireType
|
||||||
|
}
|
||||||
|
msg := new(ErrorResponse)
|
||||||
|
err := b.DecodeMessage(msg)
|
||||||
|
m.MessageResponse = &ServerReflectionResponse_ErrorResponse{msg}
|
||||||
|
return true, err
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerReflectionResponse_OneofSizer(msg proto.Message) (n int) {
|
||||||
|
m := msg.(*ServerReflectionResponse)
|
||||||
|
// message_response
|
||||||
|
switch x := m.MessageResponse.(type) {
|
||||||
|
case *ServerReflectionResponse_FileDescriptorResponse:
|
||||||
|
s := proto.Size(x.FileDescriptorResponse)
|
||||||
|
n += proto.SizeVarint(4<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *ServerReflectionResponse_AllExtensionNumbersResponse:
|
||||||
|
s := proto.Size(x.AllExtensionNumbersResponse)
|
||||||
|
n += proto.SizeVarint(5<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *ServerReflectionResponse_ListServicesResponse:
|
||||||
|
s := proto.Size(x.ListServicesResponse)
|
||||||
|
n += proto.SizeVarint(6<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case *ServerReflectionResponse_ErrorResponse:
|
||||||
|
s := proto.Size(x.ErrorResponse)
|
||||||
|
n += proto.SizeVarint(7<<3 | proto.WireBytes)
|
||||||
|
n += proto.SizeVarint(uint64(s))
|
||||||
|
n += s
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialized FileDescriptorProto messages sent by the server answering
|
||||||
|
// a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||||
|
// request.
|
||||||
|
type FileDescriptorResponse struct {
|
||||||
|
// Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||||
|
// descriptor.proto, which uses proto2 only features, by making them opaque
|
||||||
|
// bytes instead.
|
||||||
|
FileDescriptorProto [][]byte `protobuf:"bytes,1,rep,name=file_descriptor_proto,json=fileDescriptorProto,proto3" json:"file_descriptor_proto,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FileDescriptorResponse) Reset() { *m = FileDescriptorResponse{} }
|
||||||
|
func (m *FileDescriptorResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*FileDescriptorResponse) ProtoMessage() {}
|
||||||
|
func (*FileDescriptorResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||||
|
|
||||||
|
// A list of extension numbers sent by the server answering
|
||||||
|
// all_extension_numbers_of_type request.
|
||||||
|
type ExtensionNumberResponse struct {
|
||||||
|
// Full name of the base type, including the package name. The format
|
||||||
|
// is <package>.<type>
|
||||||
|
BaseTypeName string `protobuf:"bytes,1,opt,name=base_type_name,json=baseTypeName" json:"base_type_name,omitempty"`
|
||||||
|
ExtensionNumber []int32 `protobuf:"varint,2,rep,name=extension_number,json=extensionNumber" json:"extension_number,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ExtensionNumberResponse) Reset() { *m = ExtensionNumberResponse{} }
|
||||||
|
func (m *ExtensionNumberResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ExtensionNumberResponse) ProtoMessage() {}
|
||||||
|
func (*ExtensionNumberResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||||
|
|
||||||
|
// A list of ServiceResponse sent by the server answering list_services request.
|
||||||
|
type ListServiceResponse struct {
|
||||||
|
// The information of each service may be expanded in the future, so we use
|
||||||
|
// ServiceResponse message to encapsulate it.
|
||||||
|
Service []*ServiceResponse `protobuf:"bytes,1,rep,name=service" json:"service,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ListServiceResponse) Reset() { *m = ListServiceResponse{} }
|
||||||
|
func (m *ListServiceResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ListServiceResponse) ProtoMessage() {}
|
||||||
|
func (*ListServiceResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||||
|
|
||||||
|
func (m *ListServiceResponse) GetService() []*ServiceResponse {
|
||||||
|
if m != nil {
|
||||||
|
return m.Service
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// The information of a single service used by ListServiceResponse to answer
|
||||||
|
// list_services request.
|
||||||
|
type ServiceResponse struct {
|
||||||
|
// Full name of a registered service, including its package name. The format
|
||||||
|
// is <package>.<service>
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ServiceResponse) Reset() { *m = ServiceResponse{} }
|
||||||
|
func (m *ServiceResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ServiceResponse) ProtoMessage() {}
|
||||||
|
func (*ServiceResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||||
|
|
||||||
|
// The error code and error message sent by the server when an error occurs.
|
||||||
|
type ErrorResponse struct {
|
||||||
|
// This field uses the error codes defined in grpc::StatusCode.
|
||||||
|
ErrorCode int32 `protobuf:"varint,1,opt,name=error_code,json=errorCode" json:"error_code,omitempty"`
|
||||||
|
ErrorMessage string `protobuf:"bytes,2,opt,name=error_message,json=errorMessage" json:"error_message,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ErrorResponse) Reset() { *m = ErrorResponse{} }
|
||||||
|
func (m *ErrorResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ErrorResponse) ProtoMessage() {}
|
||||||
|
func (*ErrorResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*ServerReflectionRequest)(nil), "grpc.reflection.v1alpha.ServerReflectionRequest")
|
||||||
|
proto.RegisterType((*ExtensionRequest)(nil), "grpc.reflection.v1alpha.ExtensionRequest")
|
||||||
|
proto.RegisterType((*ServerReflectionResponse)(nil), "grpc.reflection.v1alpha.ServerReflectionResponse")
|
||||||
|
proto.RegisterType((*FileDescriptorResponse)(nil), "grpc.reflection.v1alpha.FileDescriptorResponse")
|
||||||
|
proto.RegisterType((*ExtensionNumberResponse)(nil), "grpc.reflection.v1alpha.ExtensionNumberResponse")
|
||||||
|
proto.RegisterType((*ListServiceResponse)(nil), "grpc.reflection.v1alpha.ListServiceResponse")
|
||||||
|
proto.RegisterType((*ServiceResponse)(nil), "grpc.reflection.v1alpha.ServiceResponse")
|
||||||
|
proto.RegisterType((*ErrorResponse)(nil), "grpc.reflection.v1alpha.ErrorResponse")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for ServerReflection service
|
||||||
|
|
||||||
|
type ServerReflectionClient interface {
|
||||||
|
// The reflection service is structured as a bidirectional stream, ensuring
|
||||||
|
// all related requests go to a single server.
|
||||||
|
ServerReflectionInfo(ctx context.Context, opts ...grpc.CallOption) (ServerReflection_ServerReflectionInfoClient, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type serverReflectionClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServerReflectionClient(cc *grpc.ClientConn) ServerReflectionClient {
|
||||||
|
return &serverReflectionClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *serverReflectionClient) ServerReflectionInfo(ctx context.Context, opts ...grpc.CallOption) (ServerReflection_ServerReflectionInfoClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_ServerReflection_serviceDesc.Streams[0], c.cc, "/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &serverReflectionServerReflectionInfoClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerReflection_ServerReflectionInfoClient interface {
|
||||||
|
Send(*ServerReflectionRequest) error
|
||||||
|
Recv() (*ServerReflectionResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type serverReflectionServerReflectionInfoClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *serverReflectionServerReflectionInfoClient) Send(m *ServerReflectionRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *serverReflectionServerReflectionInfoClient) Recv() (*ServerReflectionResponse, error) {
|
||||||
|
m := new(ServerReflectionResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for ServerReflection service
|
||||||
|
|
||||||
|
type ServerReflectionServer interface {
|
||||||
|
// The reflection service is structured as a bidirectional stream, ensuring
|
||||||
|
// all related requests go to a single server.
|
||||||
|
ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterServerReflectionServer(s *grpc.Server, srv ServerReflectionServer) {
|
||||||
|
s.RegisterService(&_ServerReflection_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ServerReflection_ServerReflectionInfo_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(ServerReflectionServer).ServerReflectionInfo(&serverReflectionServerReflectionInfoServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerReflection_ServerReflectionInfoServer interface {
|
||||||
|
Send(*ServerReflectionResponse) error
|
||||||
|
Recv() (*ServerReflectionRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type serverReflectionServerReflectionInfoServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *serverReflectionServerReflectionInfoServer) Send(m *ServerReflectionResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *serverReflectionServerReflectionInfoServer) Recv() (*ServerReflectionRequest, error) {
|
||||||
|
m := new(ServerReflectionRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ServerReflection_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "grpc.reflection.v1alpha.ServerReflection",
|
||||||
|
HandlerType: (*ServerReflectionServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "ServerReflectionInfo",
|
||||||
|
Handler: _ServerReflection_ServerReflectionInfo_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: fileDescriptor0,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("reflection.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 646 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x54, 0xdd, 0x6e, 0xd3, 0x4c,
|
||||||
|
0x10, 0xfd, 0xd2, 0xe6, 0x47, 0x99, 0xfc, 0xf9, 0xdb, 0x86, 0xc4, 0x05, 0x15, 0x21, 0x43, 0x21,
|
||||||
|
0x45, 0x28, 0xb4, 0x46, 0xe2, 0x01, 0x52, 0x40, 0x45, 0x2a, 0x2d, 0x72, 0xb8, 0x41, 0x5c, 0x58,
|
||||||
|
0x8e, 0xb3, 0x4e, 0x0d, 0x8e, 0xd7, 0xec, 0xba, 0x81, 0x5c, 0xf1, 0x10, 0x3c, 0x14, 0xaf, 0xc4,
|
||||||
|
0x25, 0xbb, 0xeb, 0x9f, 0x38, 0xae, 0x0d, 0xea, 0x95, 0xad, 0xb3, 0x33, 0x7b, 0x66, 0xe6, 0x9c,
|
||||||
|
0x59, 0x50, 0x28, 0x76, 0x3c, 0x6c, 0x87, 0x2e, 0xf1, 0xc7, 0x01, 0x25, 0x21, 0x41, 0xc3, 0x05,
|
||||||
|
0x0d, 0xec, 0x71, 0x06, 0x5e, 0x9d, 0x58, 0x5e, 0x70, 0x65, 0x69, 0xbf, 0x77, 0x60, 0x38, 0xc5,
|
||||||
|
0x74, 0x85, 0xa9, 0x91, 0x1e, 0x1a, 0xf8, 0xeb, 0x35, 0x66, 0x21, 0x42, 0x50, 0xbd, 0x22, 0x2c,
|
||||||
|
0x54, 0x2b, 0x0f, 0x2a, 0xa3, 0xa6, 0x21, 0xff, 0xd1, 0x53, 0x50, 0x1c, 0xd7, 0xc3, 0xe6, 0x6c,
|
||||||
|
0x6d, 0x8a, 0xaf, 0x6f, 0x2d, 0xb1, 0xba, 0x2b, 0xce, 0xcf, 0xfe, 0x33, 0xba, 0x02, 0x99, 0xac,
|
||||||
|
0xdf, 0xc4, 0x38, 0x7a, 0x09, 0x03, 0x19, 0x6b, 0x13, 0x3f, 0xb4, 0x5c, 0xdf, 0xf5, 0x17, 0x26,
|
||||||
|
0x5b, 0x2f, 0x67, 0xc4, 0x53, 0xab, 0x71, 0x46, 0x5f, 0x9c, 0x9f, 0xa6, 0xc7, 0x53, 0x79, 0x8a,
|
||||||
|
0x16, 0xb0, 0x9f, 0xcf, 0xc3, 0xdf, 0x43, 0xec, 0x33, 0x5e, 0x9b, 0x5a, 0xe3, 0xa9, 0x2d, 0xfd,
|
||||||
|
0x68, 0x5c, 0xd2, 0xd0, 0xf8, 0x75, 0x12, 0x19, 0x77, 0xc1, 0x59, 0x86, 0xdb, 0x2c, 0x69, 0x04,
|
||||||
|
0x9a, 0xc0, 0x81, 0xe5, 0x79, 0x9b, 0xcb, 0x4d, 0xff, 0x7a, 0x39, 0xc3, 0x94, 0x99, 0xc4, 0x31,
|
||||||
|
0xc3, 0x75, 0x80, 0xd5, 0x7a, 0x5c, 0xe7, 0x3e, 0x0f, 0x4b, 0xd3, 0x2e, 0xa2, 0xa0, 0x4b, 0xe7,
|
||||||
|
0x03, 0x0f, 0x41, 0x87, 0xd0, 0xf1, 0x5c, 0x16, 0x9a, 0x8c, 0x0f, 0xd1, 0xb5, 0x31, 0x53, 0x1b,
|
||||||
|
0x71, 0x4e, 0x5b, 0xc0, 0xd3, 0x18, 0x9d, 0xfc, 0x0f, 0xbd, 0x25, 0x66, 0xcc, 0x5a, 0x60, 0x93,
|
||||||
|
0x46, 0x85, 0x69, 0x0e, 0x28, 0xf9, 0x62, 0xd1, 0x13, 0xe8, 0x65, 0xba, 0x96, 0x35, 0x44, 0xd3,
|
||||||
|
0xef, 0x6e, 0x60, 0x49, 0x7b, 0x04, 0x4a, 0xbe, 0x6c, 0x75, 0x87, 0x47, 0xd6, 0x8c, 0x1e, 0xde,
|
||||||
|
0x2e, 0x54, 0xfb, 0x55, 0x05, 0xf5, 0xa6, 0xc4, 0x2c, 0x20, 0x3e, 0xc3, 0xe8, 0x00, 0x60, 0x65,
|
||||||
|
0x79, 0xee, 0xdc, 0xcc, 0x28, 0xdd, 0x94, 0xc8, 0x99, 0x90, 0xfb, 0x13, 0x28, 0x84, 0xba, 0x0b,
|
||||||
|
0xd7, 0xb7, 0xbc, 0xa4, 0x6e, 0x49, 0xd3, 0xd2, 0x8f, 0x4b, 0x15, 0x28, 0xb1, 0x93, 0xd1, 0x4b,
|
||||||
|
0x6e, 0x4a, 0x9a, 0xfd, 0x02, 0xaa, 0xd4, 0x79, 0x8e, 0x99, 0x4d, 0xdd, 0x20, 0x24, 0x94, 0x73,
|
||||||
|
0x44, 0x75, 0x49, 0x87, 0xb4, 0xf4, 0xe7, 0xa5, 0x24, 0xc2, 0x64, 0xaf, 0xd2, 0xbc, 0xa4, 0x1d,
|
||||||
|
0x3e, 0x76, 0x69, 0xb9, 0x9b, 0x27, 0xe8, 0x1b, 0xdc, 0x2f, 0xd6, 0x3a, 0xa5, 0xac, 0xfd, 0xa3,
|
||||||
|
0xaf, 0x9c, 0x01, 0x32, 0x9c, 0xf7, 0x0a, 0xec, 0x91, 0x12, 0xcf, 0x61, 0xb0, 0x65, 0x90, 0x0d,
|
||||||
|
0x61, 0x5d, 0x12, 0x3e, 0x2b, 0x25, 0x3c, 0xdf, 0x18, 0x28, 0x43, 0xd6, 0xcf, 0xfa, 0x2a, 0x65,
|
||||||
|
0xb9, 0x84, 0x2e, 0xa6, 0x34, 0x3b, 0xc1, 0x86, 0xbc, 0xfd, 0x71, 0x79, 0x3b, 0x22, 0x3c, 0x73,
|
||||||
|
0x6f, 0x07, 0x67, 0x81, 0x09, 0x02, 0x65, 0x63, 0xd8, 0x08, 0xd3, 0xce, 0x61, 0x50, 0x3c, 0x77,
|
||||||
|
0xa4, 0xc3, 0x9d, 0xbc, 0x94, 0xf2, 0xe1, 0xe1, 0x8e, 0xda, 0x1d, 0xb5, 0x8d, 0xbd, 0x6d, 0x51,
|
||||||
|
0xde, 0x8b, 0x23, 0xed, 0x33, 0x0c, 0x4b, 0x46, 0x8a, 0x1e, 0x41, 0x77, 0x66, 0x31, 0x2c, 0x17,
|
||||||
|
0xc0, 0x94, 0x6f, 0x4c, 0xe4, 0xcc, 0xb6, 0x40, 0x85, 0xff, 0x2f, 0xc4, 0xfb, 0x52, 0xbc, 0x03,
|
||||||
|
0xbb, 0x45, 0x3b, 0xf0, 0x11, 0xf6, 0x0a, 0xa6, 0xc9, 0x1f, 0x80, 0x46, 0x2c, 0x8b, 0x2c, 0xb4,
|
||||||
|
0xa5, 0x8f, 0xfe, 0xea, 0xea, 0x4c, 0xaa, 0x91, 0x24, 0x6a, 0x87, 0xd0, 0xcb, 0x5f, 0xcb, 0x1f,
|
||||||
|
0xce, 0x4c, 0xd1, 0xf2, 0x5f, 0x9b, 0x42, 0x67, 0x6b, 0xe2, 0x62, 0xf3, 0x22, 0xc5, 0x6c, 0x32,
|
||||||
|
0x8f, 0x42, 0x6b, 0x46, 0x53, 0x22, 0xa7, 0x1c, 0x40, 0x0f, 0x21, 0x12, 0xc4, 0x8c, 0x55, 0x90,
|
||||||
|
0x6b, 0xc7, 0x27, 0x20, 0xc1, 0x77, 0x11, 0xa6, 0xff, 0xac, 0x80, 0x92, 0x5f, 0x37, 0xf4, 0x03,
|
||||||
|
0xfa, 0x79, 0xec, 0xad, 0xef, 0x10, 0x74, 0xeb, 0x8d, 0xbd, 0x7b, 0x72, 0x8b, 0x8c, 0xa8, 0xab,
|
||||||
|
0x51, 0xe5, 0xb8, 0x32, 0xab, 0x4b, 0xe9, 0x5f, 0xfc, 0x09, 0x00, 0x00, 0xff, 0xff, 0xe9, 0x3f,
|
||||||
|
0x7b, 0x08, 0x87, 0x06, 0x00, 0x00,
|
||||||
|
}
|
151
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.proto
generated
vendored
Normal file
151
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.proto
generated
vendored
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
// Copyright 2016, 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.
|
||||||
|
|
||||||
|
// Service exported by server reflection
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package grpc.reflection.v1alpha;
|
||||||
|
|
||||||
|
service ServerReflection {
|
||||||
|
// The reflection service is structured as a bidirectional stream, ensuring
|
||||||
|
// all related requests go to a single server.
|
||||||
|
rpc ServerReflectionInfo(stream ServerReflectionRequest)
|
||||||
|
returns (stream ServerReflectionResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The message sent by the client when calling ServerReflectionInfo method.
|
||||||
|
message ServerReflectionRequest {
|
||||||
|
string host = 1;
|
||||||
|
// To use reflection service, the client should set one of the following
|
||||||
|
// fields in message_request. The server distinguishes requests by their
|
||||||
|
// defined field and then handles them using corresponding methods.
|
||||||
|
oneof message_request {
|
||||||
|
// Find a proto file by the file name.
|
||||||
|
string file_by_filename = 3;
|
||||||
|
|
||||||
|
// Find the proto file that declares the given fully-qualified symbol name.
|
||||||
|
// This field should be a fully-qualified symbol name
|
||||||
|
// (e.g. <package>.<service>[.<method>] or <package>.<type>).
|
||||||
|
string file_containing_symbol = 4;
|
||||||
|
|
||||||
|
// Find the proto file which defines an extension extending the given
|
||||||
|
// message type with the given field number.
|
||||||
|
ExtensionRequest file_containing_extension = 5;
|
||||||
|
|
||||||
|
// Finds the tag numbers used by all known extensions of extendee_type, and
|
||||||
|
// appends them to ExtensionNumberResponse in an undefined order.
|
||||||
|
// Its corresponding method is best-effort: it's not guaranteed that the
|
||||||
|
// reflection service will implement this method, and it's not guaranteed
|
||||||
|
// that this method will provide all extensions. Returns
|
||||||
|
// StatusCode::UNIMPLEMENTED if it's not implemented.
|
||||||
|
// This field should be a fully-qualified type name. The format is
|
||||||
|
// <package>.<type>
|
||||||
|
string all_extension_numbers_of_type = 6;
|
||||||
|
|
||||||
|
// List the full names of registered services. The content will not be
|
||||||
|
// checked.
|
||||||
|
string list_services = 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The type name and extension number sent by the client when requesting
|
||||||
|
// file_containing_extension.
|
||||||
|
message ExtensionRequest {
|
||||||
|
// Fully-qualified type name. The format should be <package>.<type>
|
||||||
|
string containing_type = 1;
|
||||||
|
int32 extension_number = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The message sent by the server to answer ServerReflectionInfo method.
|
||||||
|
message ServerReflectionResponse {
|
||||||
|
string valid_host = 1;
|
||||||
|
ServerReflectionRequest original_request = 2;
|
||||||
|
// The server set one of the following fields accroding to the message_request
|
||||||
|
// in the request.
|
||||||
|
oneof message_response {
|
||||||
|
// This message is used to answer file_by_filename, file_containing_symbol,
|
||||||
|
// file_containing_extension requests with transitive dependencies. As
|
||||||
|
// the repeated label is not allowed in oneof fields, we use a
|
||||||
|
// FileDescriptorResponse message to encapsulate the repeated fields.
|
||||||
|
// The reflection service is allowed to avoid sending FileDescriptorProtos
|
||||||
|
// that were previously sent in response to earlier requests in the stream.
|
||||||
|
FileDescriptorResponse file_descriptor_response = 4;
|
||||||
|
|
||||||
|
// This message is used to answer all_extension_numbers_of_type requst.
|
||||||
|
ExtensionNumberResponse all_extension_numbers_response = 5;
|
||||||
|
|
||||||
|
// This message is used to answer list_services request.
|
||||||
|
ListServiceResponse list_services_response = 6;
|
||||||
|
|
||||||
|
// This message is used when an error occurs.
|
||||||
|
ErrorResponse error_response = 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialized FileDescriptorProto messages sent by the server answering
|
||||||
|
// a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||||
|
// request.
|
||||||
|
message FileDescriptorResponse {
|
||||||
|
// Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||||
|
// descriptor.proto, which uses proto2 only features, by making them opaque
|
||||||
|
// bytes instead.
|
||||||
|
repeated bytes file_descriptor_proto = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A list of extension numbers sent by the server answering
|
||||||
|
// all_extension_numbers_of_type request.
|
||||||
|
message ExtensionNumberResponse {
|
||||||
|
// Full name of the base type, including the package name. The format
|
||||||
|
// is <package>.<type>
|
||||||
|
string base_type_name = 1;
|
||||||
|
repeated int32 extension_number = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A list of ServiceResponse sent by the server answering list_services request.
|
||||||
|
message ListServiceResponse {
|
||||||
|
// The information of each service may be expanded in the future, so we use
|
||||||
|
// ServiceResponse message to encapsulate it.
|
||||||
|
repeated ServiceResponse service = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The information of a single service used by ListServiceResponse to answer
|
||||||
|
// list_services request.
|
||||||
|
message ServiceResponse {
|
||||||
|
// Full name of a registered service, including its package name. The format
|
||||||
|
// is <package>.<service>
|
||||||
|
string name = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The error code and error message sent by the server when an error occurs.
|
||||||
|
message ErrorResponse {
|
||||||
|
// This field uses the error codes defined in grpc::StatusCode.
|
||||||
|
int32 error_code = 1;
|
||||||
|
string error_message = 2;
|
||||||
|
}
|
56
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2.pb.go
generated
vendored
Normal file
56
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: proto2.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
type ToBeExtened struct {
|
||||||
|
Foo *int32 `protobuf:"varint,1,req,name=foo" json:"foo,omitempty"`
|
||||||
|
proto.XXX_InternalExtensions `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ToBeExtened) Reset() { *m = ToBeExtened{} }
|
||||||
|
func (m *ToBeExtened) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*ToBeExtened) ProtoMessage() {}
|
||||||
|
func (*ToBeExtened) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
||||||
|
|
||||||
|
var extRange_ToBeExtened = []proto.ExtensionRange{
|
||||||
|
{10, 20},
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ToBeExtened) ExtensionRangeArray() []proto.ExtensionRange {
|
||||||
|
return extRange_ToBeExtened
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ToBeExtened) GetFoo() int32 {
|
||||||
|
if m != nil && m.Foo != nil {
|
||||||
|
return *m.Foo
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*ToBeExtened)(nil), "grpc.testing.ToBeExtened")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("proto2.proto", fileDescriptor1) }
|
||||||
|
|
||||||
|
var fileDescriptor1 = []byte{
|
||||||
|
// 85 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x28, 0xca, 0x2f,
|
||||||
|
0xc9, 0x37, 0xd2, 0x03, 0x53, 0x42, 0x3c, 0xe9, 0x45, 0x05, 0xc9, 0x7a, 0x25, 0xa9, 0xc5, 0x25,
|
||||||
|
0x99, 0x79, 0xe9, 0x4a, 0xaa, 0x5c, 0xdc, 0x21, 0xf9, 0x4e, 0xa9, 0xae, 0x15, 0x25, 0xa9, 0x79,
|
||||||
|
0xa9, 0x29, 0x42, 0x02, 0x5c, 0xcc, 0x69, 0xf9, 0xf9, 0x12, 0x8c, 0x0a, 0x4c, 0x1a, 0xac, 0x41,
|
||||||
|
0x20, 0xa6, 0x16, 0x0b, 0x07, 0x97, 0x80, 0x28, 0x20, 0x00, 0x00, 0xff, 0xff, 0xc9, 0xed, 0xbc,
|
||||||
|
0xc2, 0x43, 0x00, 0x00, 0x00,
|
||||||
|
}
|
8
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2.proto
generated
vendored
Normal file
8
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2.proto
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
syntax = "proto2";
|
||||||
|
|
||||||
|
package grpc.testing;
|
||||||
|
|
||||||
|
message ToBeExtened {
|
||||||
|
required int32 foo = 1;
|
||||||
|
extensions 10 to 20;
|
||||||
|
}
|
88
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2_ext.pb.go
generated
vendored
Normal file
88
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2_ext.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: proto2_ext.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpc_testing is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
proto2_ext.proto
|
||||||
|
proto2.proto
|
||||||
|
test.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
Extension
|
||||||
|
ToBeExtened
|
||||||
|
SearchResponse
|
||||||
|
SearchRequest
|
||||||
|
*/
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
type Extension struct {
|
||||||
|
Baz *int32 `protobuf:"varint,1,opt,name=baz" json:"baz,omitempty"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Extension) Reset() { *m = Extension{} }
|
||||||
|
func (m *Extension) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Extension) ProtoMessage() {}
|
||||||
|
func (*Extension) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
func (m *Extension) GetBaz() int32 {
|
||||||
|
if m != nil && m.Baz != nil {
|
||||||
|
return *m.Baz
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var E_Bar = &proto.ExtensionDesc{
|
||||||
|
ExtendedType: (*ToBeExtened)(nil),
|
||||||
|
ExtensionType: (*int32)(nil),
|
||||||
|
Field: 13,
|
||||||
|
Name: "grpc.testing.bar",
|
||||||
|
Tag: "varint,13,opt,name=bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
var E_Baz = &proto.ExtensionDesc{
|
||||||
|
ExtendedType: (*ToBeExtened)(nil),
|
||||||
|
ExtensionType: (*Extension)(nil),
|
||||||
|
Field: 17,
|
||||||
|
Name: "grpc.testing.baz",
|
||||||
|
Tag: "bytes,17,opt,name=baz",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*Extension)(nil), "grpc.testing.Extension")
|
||||||
|
proto.RegisterExtension(E_Bar)
|
||||||
|
proto.RegisterExtension(E_Baz)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("proto2_ext.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 130 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x12, 0x28, 0x28, 0xca, 0x2f,
|
||||||
|
0xc9, 0x37, 0x8a, 0x4f, 0xad, 0x28, 0xd1, 0x03, 0x33, 0x85, 0x78, 0xd2, 0x8b, 0x0a, 0x92, 0xf5,
|
||||||
|
0x4a, 0x52, 0x8b, 0x4b, 0x32, 0xf3, 0xd2, 0xa5, 0x78, 0x20, 0xf2, 0x10, 0x39, 0x25, 0x59, 0x2e,
|
||||||
|
0x4e, 0xd7, 0x8a, 0x92, 0xd4, 0xbc, 0xe2, 0xcc, 0xfc, 0x3c, 0x21, 0x01, 0x2e, 0xe6, 0xa4, 0xc4,
|
||||||
|
0x2a, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xd6, 0x20, 0x10, 0xd3, 0x4a, 0x1b, 0x24, 0x52, 0x24, 0x24,
|
||||||
|
0xa9, 0x87, 0x6c, 0x84, 0x5e, 0x48, 0xbe, 0x53, 0x2a, 0x58, 0x57, 0x6a, 0x8a, 0x04, 0x2f, 0x4c,
|
||||||
|
0x71, 0x91, 0x95, 0x0b, 0x58, 0x3b, 0x3e, 0xc5, 0x82, 0x40, 0xc5, 0xdc, 0x46, 0xe2, 0xa8, 0x0a,
|
||||||
|
0xe0, 0xf6, 0x83, 0xad, 0x04, 0x04, 0x00, 0x00, 0xff, 0xff, 0x59, 0xfa, 0x16, 0xbc, 0xc0, 0x00,
|
||||||
|
0x00, 0x00,
|
||||||
|
}
|
13
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2_ext.proto
generated
vendored
Normal file
13
vendor/google.golang.org/grpc/reflection/grpc_testing/proto2_ext.proto
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
syntax = "proto2";
|
||||||
|
|
||||||
|
package grpc.testing;
|
||||||
|
|
||||||
|
import "proto2.proto";
|
||||||
|
extend ToBeExtened {
|
||||||
|
optional int32 bar = 13;
|
||||||
|
optional Extension baz = 17;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Extension {
|
||||||
|
optional int32 baz = 1;
|
||||||
|
}
|
220
vendor/google.golang.org/grpc/reflection/grpc_testing/test.pb.go
generated
vendored
Normal file
220
vendor/google.golang.org/grpc/reflection/grpc_testing/test.pb.go
generated
vendored
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
// Code generated by protoc-gen-go.
|
||||||
|
// source: test.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
package grpc_testing
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
type SearchResponse struct {
|
||||||
|
Results []*SearchResponse_Result `protobuf:"bytes,1,rep,name=results" json:"results,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SearchResponse) Reset() { *m = SearchResponse{} }
|
||||||
|
func (m *SearchResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SearchResponse) ProtoMessage() {}
|
||||||
|
func (*SearchResponse) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
|
||||||
|
|
||||||
|
func (m *SearchResponse) GetResults() []*SearchResponse_Result {
|
||||||
|
if m != nil {
|
||||||
|
return m.Results
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchResponse_Result struct {
|
||||||
|
Url string `protobuf:"bytes,1,opt,name=url" json:"url,omitempty"`
|
||||||
|
Title string `protobuf:"bytes,2,opt,name=title" json:"title,omitempty"`
|
||||||
|
Snippets []string `protobuf:"bytes,3,rep,name=snippets" json:"snippets,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SearchResponse_Result) Reset() { *m = SearchResponse_Result{} }
|
||||||
|
func (m *SearchResponse_Result) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SearchResponse_Result) ProtoMessage() {}
|
||||||
|
func (*SearchResponse_Result) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0, 0} }
|
||||||
|
|
||||||
|
type SearchRequest struct {
|
||||||
|
Query string `protobuf:"bytes,1,opt,name=query" json:"query,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SearchRequest) Reset() { *m = SearchRequest{} }
|
||||||
|
func (m *SearchRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*SearchRequest) ProtoMessage() {}
|
||||||
|
func (*SearchRequest) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{1} }
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*SearchResponse)(nil), "grpc.testing.SearchResponse")
|
||||||
|
proto.RegisterType((*SearchResponse_Result)(nil), "grpc.testing.SearchResponse.Result")
|
||||||
|
proto.RegisterType((*SearchRequest)(nil), "grpc.testing.SearchRequest")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion3
|
||||||
|
|
||||||
|
// Client API for SearchService service
|
||||||
|
|
||||||
|
type SearchServiceClient interface {
|
||||||
|
Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*SearchResponse, error)
|
||||||
|
StreamingSearch(ctx context.Context, opts ...grpc.CallOption) (SearchService_StreamingSearchClient, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type searchServiceClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSearchServiceClient(cc *grpc.ClientConn) SearchServiceClient {
|
||||||
|
return &searchServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *searchServiceClient) Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*SearchResponse, error) {
|
||||||
|
out := new(SearchResponse)
|
||||||
|
err := grpc.Invoke(ctx, "/grpc.testing.SearchService/Search", in, out, c.cc, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *searchServiceClient) StreamingSearch(ctx context.Context, opts ...grpc.CallOption) (SearchService_StreamingSearchClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_SearchService_serviceDesc.Streams[0], c.cc, "/grpc.testing.SearchService/StreamingSearch", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &searchServiceStreamingSearchClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchService_StreamingSearchClient interface {
|
||||||
|
Send(*SearchRequest) error
|
||||||
|
Recv() (*SearchResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type searchServiceStreamingSearchClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *searchServiceStreamingSearchClient) Send(m *SearchRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *searchServiceStreamingSearchClient) Recv() (*SearchResponse, error) {
|
||||||
|
m := new(SearchResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for SearchService service
|
||||||
|
|
||||||
|
type SearchServiceServer interface {
|
||||||
|
Search(context.Context, *SearchRequest) (*SearchResponse, error)
|
||||||
|
StreamingSearch(SearchService_StreamingSearchServer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterSearchServiceServer(s *grpc.Server, srv SearchServiceServer) {
|
||||||
|
s.RegisterService(&_SearchService_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _SearchService_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SearchRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(SearchServiceServer).Search(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/grpc.testing.SearchService/Search",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(SearchServiceServer).Search(ctx, req.(*SearchRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _SearchService_StreamingSearch_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(SearchServiceServer).StreamingSearch(&searchServiceStreamingSearchServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchService_StreamingSearchServer interface {
|
||||||
|
Send(*SearchResponse) error
|
||||||
|
Recv() (*SearchRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type searchServiceStreamingSearchServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *searchServiceStreamingSearchServer) Send(m *SearchResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *searchServiceStreamingSearchServer) Recv() (*SearchRequest, error) {
|
||||||
|
m := new(SearchRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _SearchService_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "grpc.testing.SearchService",
|
||||||
|
HandlerType: (*SearchServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "Search",
|
||||||
|
Handler: _SearchService_Search_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "StreamingSearch",
|
||||||
|
Handler: _SearchService_StreamingSearch_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: fileDescriptor2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("test.proto", fileDescriptor2) }
|
||||||
|
|
||||||
|
var fileDescriptor2 = []byte{
|
||||||
|
// 227 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x2a, 0x49, 0x2d, 0x2e,
|
||||||
|
0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x49, 0x2f, 0x2a, 0x48, 0xd6, 0x03, 0x09, 0x64,
|
||||||
|
0xe6, 0xa5, 0x2b, 0xcd, 0x65, 0xe4, 0xe2, 0x0b, 0x4e, 0x4d, 0x2c, 0x4a, 0xce, 0x08, 0x4a, 0x2d,
|
||||||
|
0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x15, 0xb2, 0xe5, 0x62, 0x2f, 0x4a, 0x2d, 0x2e, 0xcd, 0x29, 0x29,
|
||||||
|
0x96, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0x52, 0xd6, 0x43, 0xd6, 0xa2, 0x87, 0xaa, 0x5c, 0x2f,
|
||||||
|
0x08, 0xac, 0x36, 0x08, 0xa6, 0x47, 0xca, 0x87, 0x8b, 0x0d, 0x22, 0x24, 0x24, 0xc0, 0xc5, 0x5c,
|
||||||
|
0x5a, 0x94, 0x03, 0x34, 0x84, 0x51, 0x83, 0x33, 0x08, 0xc4, 0x14, 0x12, 0xe1, 0x62, 0x2d, 0xc9,
|
||||||
|
0x2c, 0xc9, 0x49, 0x95, 0x60, 0x02, 0x8b, 0x41, 0x38, 0x42, 0x52, 0x5c, 0x1c, 0xc5, 0x79, 0x99,
|
||||||
|
0x05, 0x05, 0xa9, 0x40, 0x1b, 0x99, 0x81, 0x36, 0x72, 0x06, 0xc1, 0xf9, 0x4a, 0xaa, 0x5c, 0xbc,
|
||||||
|
0x30, 0xfb, 0x0a, 0x4b, 0x81, 0x0e, 0x00, 0x19, 0x01, 0x64, 0x14, 0x55, 0x42, 0x8d, 0x85, 0x70,
|
||||||
|
0x8c, 0x96, 0x31, 0xc2, 0xd4, 0x05, 0xa7, 0x16, 0x95, 0x65, 0x26, 0xa7, 0x0a, 0x39, 0x73, 0xb1,
|
||||||
|
0x41, 0x04, 0x84, 0xa4, 0xb1, 0x3b, 0x1f, 0x6c, 0x9c, 0x94, 0x0c, 0x3e, 0xbf, 0x09, 0x05, 0x70,
|
||||||
|
0xf1, 0x07, 0x97, 0x14, 0xa5, 0x26, 0xe6, 0x02, 0xe5, 0x28, 0x36, 0x4d, 0x83, 0xd1, 0x80, 0x31,
|
||||||
|
0x89, 0x0d, 0x1c, 0x09, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x20, 0xd6, 0x09, 0xb8, 0x92,
|
||||||
|
0x01, 0x00, 0x00,
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue