Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: TagBot
on:
schedule:
- cron: 0 * * * *
jobs:
TagBot:
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI
on:
push:
branches: [master]
tags: ["*"]
pull_request:
env:
GO111MODULE: on
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.3'
- '1' # automatically expands to the latest stable 1.x release of Julia
- nightly
os:
- ubuntu-latest
arch:
- x64
- x86
# include:
# # test macOS and Windows with latest Julia only
# - os: macOS-latest
# arch: x64
# version: 1
# - os: windows-latest
# arch: x64
# version: 1
# - os: windows-latest
# arch: x86
# version: 1
steps:
- uses: actions/checkout@v2
- name: setup go
uses: actions/setup-go@v2
with:
go-version: '1.12.9'
- run: go version
- name: setup protoc
uses: arduino/setup-protoc@v1
with:
version: '3.x'
- run: protoc --version
- name: generate test certificates
run: test/certgen/certgen.sh
shell: bash
- name: install protoc-gen-go
run: |
go get google.golang.org/protobuf/cmd/protoc-gen-go google.golang.org/grpc/cmd/protoc-gen-go-grpc
shell: bash
- name: start test server
run: test/runserver.sh
shell: bash
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
- name: shutdown test server
run: kill `cat test/grpc-go/examples/route_guide/server.pid`
shell: bash
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

A Julia gRPC Client.

GitHub Actions : [![Build Status](https://github.com/JuliaComputing/gRPCClient.jl/workflows/CI/badge.svg)](https://github.com/JuliaComputing/gRPCClient.jl/actions?query=workflow%3ACI+branch%3Amaster)

[![Coverage Status](https://coveralls.io/repos/JuliaComputing/gRPCClient.jl/badge.svg?branch=master)](https://coveralls.io/r/JuliaComputing/gRPCClient.jl?branch=master)
[![codecov.io](http://codecov.io/github/JuliaComputing/gRPCClient.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaComputing/gRPCClient.jl?branch=master)


## Generating gRPC Service Client

gRPC services are declared in `.proto` files. Use `gRPCClient.generate` to generate client code from specification files.
Expand Down Expand Up @@ -68,7 +74,6 @@ gRPCController(;
[ keepalive::Int64 = 60, ]
[ request_timeout::Real = Inf, ]
[ connect_timeout::Real = 0, ]
[ verify_peer::Bool = true, ]
[ verbose::Bool = false, ]
)
```
Expand All @@ -80,7 +85,6 @@ gRPCController(;
- `request_timeout`: request timeout (seconds)
- `connect_timeout`: connect timeout (seconds) (default is 300 seconds, same
as setting this to 0)
- `verify_peer`: whether to verify the peer (server) certificate (default true)
- `verbose`: whether to print out verbose communication logs (default false)

### `gRPCChannel`
Expand Down
34 changes: 25 additions & 9 deletions src/curl.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
const GRPC_STATIC_HEADERS = Ref{Ptr{Nothing}}(C_NULL)

#=
const SEND_BUFFER_SZ = 1024 * 1024
function buffer_send_data(input::Channel{T}) where T <: ProtoType
data = nothing
if isready(input)
iob = IOBuffer()
while isready(input) && (iob.size < SEND_BUFFER_SZ)
write(iob, to_delimited_message_bytes(take!(input)))
yield()
end
data = take!(iob)
elseif isopen(input)
data = UInt8[]
end
data
end
=#

function send_data(easy::Curl.Easy, input::Channel{T}) where T <: ProtoType
while true
data = isready(input) ? to_delimited_message_bytes(take!(input)) : isopen(input) ? UInt8[] : nothing
Expand All @@ -20,20 +38,19 @@ function grpc_headers()
headers
end

function easy_handle(maxage, keepalive, verify_peer)
function easy_handle(maxage::Clong, keepalive::Clong)
easy = Curl.Easy()
Curl.setopt(easy, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0)
Curl.setopt(easy, CURLOPT_PIPEWAIT, Clong(1))
Curl.setopt(easy, CURLOPT_POST, Clong(1))
Curl.setopt(easy, CURLOPT_HTTPHEADER, GRPC_STATIC_HEADERS[])
Curl.set_ssl_verify(easy, verify_peer)
if maxage > 0
Curl.setopt(easy, CURLOPT_MAXAGE_CONN, Clong(maxage))
Curl.setopt(easy, CURLOPT_MAXAGE_CONN, maxage)
end
if keepalive > 0
Curl.setopt(easy, CURLOPT_TCP_KEEPALIVE, Clong(1))
Curl.setopt(easy, CURLOPT_TCP_KEEPINTVL, Clong(keepalive));
Curl.setopt(easy, CURLOPT_TCP_KEEPIDLE, Clong(keepalive));
Curl.setopt(easy, CURLOPT_TCP_KEEPINTVL, keepalive);
Curl.setopt(easy, CURLOPT_TCP_KEEPIDLE, keepalive);
end
easy
end
Expand Down Expand Up @@ -87,13 +104,12 @@ function set_connect_timeout(easy::Curl.Easy, timeout::Real)
end

function grpc_request(downloader::Downloader, url::String, input::Channel{T1}, output::Channel{T2};
maxage::Int64 = typemax(Int64),
keepalive::Int64 = 60,
maxage::Clong = typemax(Clong),
keepalive::Clong = 60,
request_timeout::Real = Inf,
connect_timeout::Real = 0,
verify_peer::Bool = true,
verbose::Bool = false)::gRPCStatus where {T1 <: ProtoType, T2 <: ProtoType}
Curl.with_handle(easy_handle(maxage, keepalive, verify_peer)) do easy
Curl.with_handle(easy_handle(maxage, keepalive)) do easy
# setup the request
Curl.set_url(easy, url)
Curl.set_timeout(easy, request_timeout)
Expand Down
11 changes: 3 additions & 8 deletions src/grpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ end
[ keepalive::Int64 = 60, ]
[ request_timeout::Real = Inf, ]
[ connect_timeout::Real = 0, ]
[ verify_peer::Bool = true, ]
[ verbose::Bool = false, ]
)

Expand All @@ -65,26 +64,23 @@ Contains settings to control the behavior of gRPC requests.
- `request_timeout`: request timeout (seconds)
- `connect_timeout`: connect timeout (seconds) (default is 300 seconds, same
as setting this to 0)
- `verify_peer`: whether to verify the peer (server) certificate (default true)
- `verbose`: whether to print out verbose communication logs (default false)
"""
struct gRPCController <: ProtoRpcController
maxage::Clong
keepalive::Clong
request_timeout::Real
connect_timeout::Real
verify_peer::Bool
verbose::Bool

function gRPCController(;
maxage::Int = 0,
keepalive::Int64 = 60,
maxage::Integer = 0,
keepalive::Integer = 60,
request_timeout::Real = Inf,
connect_timeout::Real = 0,
verify_peer::Bool = true,
verbose::Bool = false
)
new(maxage, keepalive, request_timeout, connect_timeout, verify_peer, verbose)
new(maxage, keepalive, request_timeout, connect_timeout, verbose)
end
end

Expand Down Expand Up @@ -147,7 +143,6 @@ function call_method(channel::gRPCChannel, service::ServiceDescriptor, method::M
keepalive = controller.keepalive,
request_timeout = controller.request_timeout,
connect_timeout = controller.connect_timeout,
verify_peer = controller.verify_peer,
verbose = controller.verbose,
)
outchannel, status_future
Expand Down
2 changes: 2 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
grpc-go
server.pid
5 changes: 5 additions & 0 deletions test/certgen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.crt
*.key
*.pem
*.csr
*.srl
29 changes: 29 additions & 0 deletions test/certgen/certgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

BASEDIR=$(dirname $0)
cd $BASEDIR

HOSTNAME=`hostname -f`
# HOSTNAME=localhost

# Generate self signed root CA cert
openssl req -nodes -x509 -newkey rsa:2048 -keyout ca.key -out ca.crt -subj "/C=IN/ST=KA/L=Bangalore/O=JuliaComputing/OU=gRPCClient/CN=${HOSTNAME}/emailAddress=ca@examplegrpcclient.com"

# Generate server cert to be signed
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "/C=IN/ST=KA/L=Bangalore/O=JuliaComputing/OU=server/CN=${HOSTNAME}/emailAddress=server@examplegrpcclient.com"

# Sign the server cert
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt

# Create server PEM file
cat server.key server.crt > server.pem


# Generate client cert to be signed
openssl req -nodes -newkey rsa:2048 -keyout client.key -out client.csr -subj "/C=IN/ST=KA/L=Bangalore/O=JuliaComputing/OU=client/CN=${HOSTNAME}/emailAddress=client@examplegrpcclient.com"

# Sign the client cert
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAserial ca.srl -out client.crt

# Create client PEM file
cat client.key client.crt > client.pem
30 changes: 30 additions & 0 deletions test/runserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e

BASEDIR=$(dirname $0)
cd ${BASEDIR}

export PATH="$PATH:$(go env GOPATH)/bin"
CERT_FILE=../../../certgen/server.pem
KEY_FILE=../../../certgen/server.key
HOSTNAME=`hostname -f`

git clone -b v1.35.0 https://github.com/grpc/grpc-go
cd grpc-go/examples/route_guide
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative routeguide/route_guide.proto
sed 's/localhost/0.0.0.0/g' server/server.go > server/server.go.new
rm server/server.go
mv server/server.go.new server/server.go
go build -o runserver -i server/server.go

./runserver --tls=true --cert_file=$CERT_FILE --key_file=$KEY_FILE &
echo $! > server.pid
echo "server pid `cat server.pid`"

NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq 10 ] || nc -z 127.0.0.1 10000; do
sleep $(( NEXT_WAIT_TIME++ ))
done
[ $NEXT_WAIT_TIME -lt 5 ]

echo "server listening"
Loading