grenache-ruby-http 0.2.9 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: beaa0126401ee4c897c7b0af26d559672c03cab8
4
- data.tar.gz: 3ef82109748a48a409903704ceedbea545409700
3
+ metadata.gz: 503d3f71f846464f73c9f1faa400598af4d319b4
4
+ data.tar.gz: 1f31fed062cb4e794df77800e3c50c626bfdcf35
5
5
  SHA512:
6
- metadata.gz: c34ecc533f8b29ce0da0b3e3f9d6f9cb6658f8f7b8e8150aaaaed9cee0d52bd676f15c992c3ac06e0fbb05c42f45af297b75bf23318c345f11ab4ec9eb04940b
7
- data.tar.gz: 1fc334c4d9050dee4541c0f7dd3d904a4f19c9cab76d4d17304838434e9b38f2fb52da6aaaa6a12aa557ebdfae8a44ebc74e188b633a39b58bc16297a1ad25dc
6
+ metadata.gz: 4095530db6060f70b87056c4caf1ef21759ad22bd0a0d61ebe0db5f2d953311fa5d35add5db3f390dbfccfcd9a4f14411144974f4e74bf37a169429261a78904
7
+ data.tar.gz: 5a4d9035da3ecc756da66de83164323fd632223c86be26be63c74e0307aabe969d83b7fa6148e3961e5432eea3be1a89484f51cda93a6f5fc348cb1a90f74906
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "grenache-ruby-base", path: "../grenache-ruby-base"
6
-
data/README.md CHANGED
@@ -1,28 +1,129 @@
1
1
  # grenache-ruby-http
2
2
 
3
- # Configuration
3
+ <img src="logo.png" width="15%" />
4
4
 
5
- ```ruby
6
- Grenache::Base.configure do |conf|
7
- conf.grape_address = "http://10.0.0.1:30002"
8
- end
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
- # Usage
55
+ **Server:**
56
+
57
+ ```rb
58
+ require "grenache-ruby-http"
12
59
 
13
- ## Announce a service
60
+ EM.run do
61
+ Signal.trap("INT") { EventMachine.stop }
62
+ Signal.trap("TERM") { EventMachine.stop }
14
63
 
15
- ```ruby
16
- c = Grenache::BaseHttp.new
64
+ c = Grenache::Http.new(grape_address: "http://127.0.0.1:40001/")
65
+ port = 5001
17
66
 
18
- c.listen("test",5001) do |req|
19
- "hello #{req.payload}"
67
+ c.listen("test_service", port) do |req|
68
+ "hello #{req.payload}"
69
+ end
20
70
  end
21
71
  ```
22
72
 
23
- ## calling a remote service
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` &lt;String&gt;
96
+ - `:timeout` &lt;Number&gt;
97
+
98
+ - `:auto_announce_interval` &lt;Number&gt;
99
+ - `:auto_announce` &lt;Boolean&gt;
100
+ - `:service_timeout` &lt;Number&gt;
101
+ - `:service_host` &lt;String&gt;
102
+
103
+ - `:key` &lt;String&gt; SSL: Path to key file
104
+ - `:cert_pem` &lt;String&gt; SSL: Path to chain file
105
+ - `:ca` &lt;String&gt; SSL: Path to ca file
106
+ - `:service_host` &lt;String&gt; 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` &lt;String&gt; 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` &lt;String&gt; Name of the service to announce
123
+ - `port` &lt;Number&gt; 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
@@ -1,7 +1,7 @@
1
1
  require_relative '../lib/grenache-ruby-http.rb'
2
2
 
3
3
 
4
- c = Grenache::Http.new grape_address: "http://127.0.0.1:40002"
4
+ c = Grenache::Http.new grape_address: "http://127.0.0.1:40002/"
5
5
 
6
6
  start_time = Time.now
7
7
 
@@ -1,13 +1,10 @@
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/client1-key.pem"
6
- conf.cert_pem = File.expand_path('.') + "/ssl/client1-crt.pem"
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|
@@ -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
- c = Grenache::Http.new
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}"]
@@ -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.9"
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
 
@@ -1,5 +1,5 @@
1
1
  module Grenache
2
2
  module HTTP
3
- VERSION = "0.2.9"
3
+ VERSION = "0.2.11"
4
4
  end
5
5
  end
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
  }
@@ -8,4 +8,3 @@ require 'grenache/http'
8
8
  require 'grenache/http/version'
9
9
  require 'grenache/http/http_client'
10
10
  require 'grenache/http/http_server'
11
- require 'grenache/http/configurable'
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.9
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-21 00:00:00.000000000 Z
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.9
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.9
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
@@ -1,6 +0,0 @@
1
- module Grenache
2
- class Configuration
3
- # thin server
4
- attr_accessor :thin_threaded, :thin_threadpool_size
5
- end
6
- end