grenache-ruby-http 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/README.md +115 -14
- data/examples/client.rb +1 -1
- data/examples/client_ssl.rb +4 -7
- data/examples/worker_ssl.rb +5 -9
- data/grenache-ruby-http.gemspec +1 -1
- data/lib/grenache/http/http_server.rb +7 -5
- data/lib/grenache/http/version.rb +1 -1
- data/lib/grenache/http.rb +7 -0
- data/lib/grenache-ruby-http.rb +0 -1
- data/logo.png +0 -0
- metadata +5 -5
- data/lib/grenache/http/configurable.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 503d3f71f846464f73c9f1faa400598af4d319b4
|
4
|
+
data.tar.gz: 1f31fed062cb4e794df77800e3c50c626bfdcf35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4095530db6060f70b87056c4caf1ef21759ad22bd0a0d61ebe0db5f2d953311fa5d35add5db3f390dbfccfcd9a4f14411144974f4e74bf37a169429261a78904
|
7
|
+
data.tar.gz: 5a4d9035da3ecc756da66de83164323fd632223c86be26be63c74e0307aabe969d83b7fa6148e3961e5432eea3be1a89484f51cda93a6f5fc348cb1a90f74906
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,129 @@
|
|
1
1
|
# grenache-ruby-http
|
2
2
|
|
3
|
-
|
3
|
+
<img src="logo.png" width="15%" />
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
Grenache is a micro-framework for connecting microservices. Its simple and optimized for performance.
|
6
|
+
|
7
|
+
Internally, Grenache uses Distributed Hash Tables (DHT, known from Bittorrent) for Peer to Peer connections. You can find more details how Grenche internally works at the [Main Project Homepage](https://github.com/bitfinexcom/grenache)
|
8
|
+
|
9
|
+
- [Setup](#setup)
|
10
|
+
- [Examples](#examples)
|
11
|
+
- [API](#api)
|
12
|
+
|
13
|
+
## Setup
|
14
|
+
|
15
|
+
### Install
|
16
|
+
```
|
17
|
+
gem install grenache-ruby-http
|
18
|
+
```
|
19
|
+
|
20
|
+
### Other Requirements
|
21
|
+
|
22
|
+
Install `Grenache Grape`: https://github.com/bitfinexcom/grenache-grape:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
npm i -g grenache-grape
|
26
|
+
```
|
27
|
+
|
28
|
+
```
|
29
|
+
// Start 2 Grapes
|
30
|
+
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
|
31
|
+
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
|
32
|
+
```
|
33
|
+
|
34
|
+
## Examples
|
35
|
+
|
36
|
+
#### RPC Server / Client
|
37
|
+
|
38
|
+
This RPC Server example announces a service called `rpc_test`
|
39
|
+
on the overlay network. When a request from a client is received,
|
40
|
+
it replies with `world`. It receives the payload `hello` from the
|
41
|
+
client.
|
42
|
+
|
43
|
+
The client sends `hello` and receives `world` from the server.
|
44
|
+
|
45
|
+
Internally the DHT is asked for the IP of the server and then the
|
46
|
+
request is done as Peer-to-Peer request via websockets.
|
47
|
+
|
48
|
+
**Grape:**
|
49
|
+
|
50
|
+
```bash
|
51
|
+
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
|
52
|
+
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
|
9
53
|
```
|
10
54
|
|
11
|
-
|
55
|
+
**Server:**
|
56
|
+
|
57
|
+
```rb
|
58
|
+
require "grenache-ruby-http"
|
12
59
|
|
13
|
-
|
60
|
+
EM.run do
|
61
|
+
Signal.trap("INT") { EventMachine.stop }
|
62
|
+
Signal.trap("TERM") { EventMachine.stop }
|
14
63
|
|
15
|
-
|
16
|
-
|
64
|
+
c = Grenache::Http.new(grape_address: "http://127.0.0.1:40001/")
|
65
|
+
port = 5001
|
17
66
|
|
18
|
-
c.listen("
|
19
|
-
|
67
|
+
c.listen("test_service", port) do |req|
|
68
|
+
"hello #{req.payload}"
|
69
|
+
end
|
20
70
|
end
|
21
71
|
```
|
22
72
|
|
23
|
-
|
73
|
+
**Client:**
|
74
|
+
|
75
|
+
```rb
|
76
|
+
require "grenache-ruby-http"
|
77
|
+
|
78
|
+
c = Grenache::Http.new(grape_address: "http://127.0.0.1:40001/")
|
79
|
+
|
80
|
+
resp, err = c.request("test_service", "world")
|
81
|
+
|
82
|
+
puts "response: #{resp}"
|
24
83
|
|
25
|
-
```ruby
|
26
|
-
c.request('test', 'world')
|
27
84
|
```
|
28
85
|
|
86
|
+
[Code Server](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/worker.rb)
|
87
|
+
[Code Client](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/client.rb)
|
88
|
+
|
89
|
+
## API
|
90
|
+
|
91
|
+
### Class: Grenache::Http
|
92
|
+
|
93
|
+
### Grenache::Http.new(options)
|
94
|
+
- `options`
|
95
|
+
- `:grape_address` <String>
|
96
|
+
- `:timeout` <Number>
|
97
|
+
|
98
|
+
- `:auto_announce_interval` <Number>
|
99
|
+
- `:auto_announce` <Boolean>
|
100
|
+
- `:service_timeout` <Number>
|
101
|
+
- `:service_host` <String>
|
102
|
+
|
103
|
+
- `:key` <String> SSL: Path to key file
|
104
|
+
- `:cert_pem` <String> SSL: Path to chain file
|
105
|
+
- `:ca` <String> SSL: Path to ca file
|
106
|
+
- `:service_host` <String> SSL: host name, used for worker
|
107
|
+
- `:reject_unauthorized` SSL: Reject unauthorized certs
|
108
|
+
- `:verify_mode` SSL: Verification method, default `Grenache::SSL_VERIFY_PEER`
|
109
|
+
|
110
|
+
|
111
|
+
### client.request(name, payload, options)
|
112
|
+
- `name` <String> Name of the service to address
|
113
|
+
- `payload` Payload to send
|
114
|
+
- `options`
|
115
|
+
- `:timeout` Timeout for the request
|
116
|
+
|
117
|
+
Sends a single request to a RPC server/worker.
|
118
|
+
[Example](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/client.rb).
|
119
|
+
|
120
|
+
|
121
|
+
### client.listen(key, port, options)
|
122
|
+
- `name` <String> Name of the service to announce
|
123
|
+
- `port` <Number> Port to listen
|
124
|
+
- `options`
|
125
|
+
|
126
|
+
Sets up a worker which connects to the DHT.
|
127
|
+
Listens on the given `port`.
|
128
|
+
|
129
|
+
[Example](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/worker.rb).
|
data/examples/client.rb
CHANGED
data/examples/client_ssl.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require_relative '../lib/grenache-ruby-http.rb'
|
2
2
|
|
3
|
-
Grenache::Http.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
conf.ca = File.expand_path('.') + "/ssl/ca-crt.pem"
|
8
|
-
end
|
3
|
+
c = Grenache::Http.new(grape_address: "http://127.0.0.1:40002/",
|
4
|
+
key: File.expand_path('.') + "/ssl/client1-key.pem",
|
5
|
+
cert_pem: File.expand_path('.') + "/ssl/client1-crt.pem",
|
6
|
+
ca: File.expand_path('.') + "/ssl/ca-crt.pem")
|
9
7
|
|
10
|
-
c = Grenache::Http.new
|
11
8
|
start_time = Time.now
|
12
9
|
|
13
10
|
10.times do |n|
|
data/examples/worker_ssl.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
require_relative '../lib/grenache-ruby-http.rb'
|
2
2
|
|
3
|
-
Grenache::Http.configure do |conf|
|
4
|
-
conf.grape_address = "http://127.0.0.1:40002/"
|
5
|
-
conf.key = File.expand_path('.') + "/ssl/server-key.pem"
|
6
|
-
conf.cert_pem = File.expand_path('.') + "/ssl/server-chain.pem"
|
7
|
-
conf.ca = File.expand_path('.') + "/ssl/ca-crt.pem"
|
8
|
-
conf.service_host = "localhost"
|
9
|
-
end
|
10
|
-
|
11
3
|
EM.run do
|
12
4
|
|
13
5
|
Signal.trap("INT") { EventMachine.stop }
|
14
6
|
Signal.trap("TERM") { EventMachine.stop }
|
15
7
|
|
16
|
-
|
8
|
+
c = Grenache::Http.new(grape_address: "http://127.0.0.1:40002/",
|
9
|
+
key: File.expand_path('.') + "/ssl/server-key.pem",
|
10
|
+
cert_pem: File.expand_path('.') + "/ssl/server-chain.pem",
|
11
|
+
ca: File.expand_path('.') + "/ssl/ca-crt.pem",
|
12
|
+
service_host: "localhost")
|
17
13
|
|
18
14
|
c.listen('rpc_test', 5004) do |msg, fingerprint|
|
19
15
|
#[StandardError.new("Error!"),"hello #{msg.payload}"]
|
data/grenache-ruby-http.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_runtime_dependency "eventmachine", "~> 1.2"
|
20
20
|
spec.add_runtime_dependency "faye-websocket", "~> 0.10"
|
21
|
-
spec.add_runtime_dependency "grenache-ruby-base", "~> 0.2.
|
21
|
+
spec.add_runtime_dependency "grenache-ruby-base", "~> 0.2.11"
|
22
22
|
spec.add_runtime_dependency "httparty", "~> 0.14.0"
|
23
23
|
spec.add_runtime_dependency "oj", "~> 2.18"
|
24
24
|
spec.add_runtime_dependency "thin", "~> 1.7"
|
@@ -1,4 +1,10 @@
|
|
1
1
|
module Thin
|
2
|
+
module Backends
|
3
|
+
class Base
|
4
|
+
attr_accessor :ca_cert
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
2
8
|
class Connection < EventMachine::Connection
|
3
9
|
def ssl_verify_peer cert
|
4
10
|
client = OpenSSL::X509::Certificate.new cert
|
@@ -9,14 +15,10 @@ module Thin
|
|
9
15
|
private
|
10
16
|
def store
|
11
17
|
@store ||= OpenSSL::X509::Store.new.tap do |store|
|
12
|
-
root = OpenSSL::X509::Certificate.new ca_cert
|
18
|
+
root = OpenSSL::X509::Certificate.new backend.ca_cert
|
13
19
|
store.add_cert root
|
14
20
|
end
|
15
21
|
end
|
16
|
-
|
17
|
-
def ca_cert
|
18
|
-
@ca_cert ||= File.read Grenache::Http.config.ca
|
19
|
-
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
data/lib/grenache/http.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module Grenache
|
2
2
|
class Http < Grenache::Base
|
3
3
|
|
4
|
+
default_conf do |conf|
|
5
|
+
conf.thin_threaded = true
|
6
|
+
conf.threadpool_size = 10
|
7
|
+
conf.verify_mode = Grenache::SSL_VERIFY_PEER
|
8
|
+
end
|
9
|
+
|
4
10
|
def listen(key, port, opts={}, &block)
|
5
11
|
start_http_service(port,&block)
|
6
12
|
|
@@ -32,6 +38,7 @@ module Grenache
|
|
32
38
|
cert_chain_file: config.cert_pem,
|
33
39
|
verify_peer: true
|
34
40
|
}
|
41
|
+
server.backend.ca_cert = File.read config.ca
|
35
42
|
end
|
36
43
|
server.start
|
37
44
|
}
|
data/lib/grenache-ruby-http.rb
CHANGED
data/logo.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grenache-ruby-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bitfinex <info@bitfinex.com>
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2.
|
47
|
+
version: 0.2.11
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.2.
|
54
|
+
version: 0.2.11
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: httparty
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,10 +129,10 @@ files:
|
|
129
129
|
- grenache-ruby-http.gemspec
|
130
130
|
- lib/grenache-ruby-http.rb
|
131
131
|
- lib/grenache/http.rb
|
132
|
-
- lib/grenache/http/configurable.rb
|
133
132
|
- lib/grenache/http/http_client.rb
|
134
133
|
- lib/grenache/http/http_server.rb
|
135
134
|
- lib/grenache/http/version.rb
|
135
|
+
- logo.png
|
136
136
|
homepage: https://github.com/bitfinexcom/grenache-ruby-http
|
137
137
|
licenses:
|
138
138
|
- MIT
|