swarmclient 0.1.1 → 0.1.3

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
- SHA256:
3
- metadata.gz: 7e95eff9380f3baca4790e174a8da717d24f6e0ac0f00527cb6553b9aab6f202
4
- data.tar.gz: 37cb9aa517d9c20d797f80b0fefd27a50faac32cdf2ce2efa65c3c4450ab30b1
2
+ SHA1:
3
+ metadata.gz: 78b0081e269fca254447d15622cf08ecfa779e17
4
+ data.tar.gz: '001971af13049e326c9c8bd9096bd5cb40b496a7'
5
5
  SHA512:
6
- metadata.gz: 7ce1f8bd41ebd42a81ca039bdd7e812c2bb8f6a9671cd3bd31854d488e51940036f98ce0d1d43fdf5f4e3b6254a580ae22fd18825b9913171121b0ff17c73cb5
7
- data.tar.gz: 3e6d750e25d49cce360bfed471e237753a029f0c706fb23056857b26de680c0dcc79bd061191e1c2eed10cf0194840196b3995bb190743ecf45982614fd945fb
6
+ metadata.gz: 8021ab7bb29ed5791e95d9850c79cd445a517fd63bdf7ad1673d5e2d8d2a79cf3ebab766098861ee5c51330a494a2242a96aa06714a0581b0f9dddb1e3952e72
7
+ data.tar.gz: a6eea143378cfb711ad48c80e4d090e7f03788260fbf9959484a01c5f790272492ccd0f3b68abf4ea0b38ec454ea160d15b9786cdcd3710d69aae2541caf79e0
data/.travis.yml CHANGED
@@ -2,4 +2,6 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.4.2
5
+ script:
6
+ - bundle exec rake spec
5
7
  before_install: gem install bundler -v 1.16.0
data/LICENSE.txt CHANGED
@@ -1,21 +1,201 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 Warren
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Swarmclient-rb
2
2
 
3
- - Bluzelle Hackathon 2018
3
+ [![Build Status](https://api.travis-ci.org/wlwanpan/swarmclient-rb.png?branch=master)](https://travis-ci.org/wlwanpan/swarmclient-rb)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
5
 
5
6
  ## Installation
6
7
 
@@ -27,11 +28,12 @@ Require and Initialize
27
28
  ```
28
29
  require 'swarmclient'
29
30
 
30
- bluzelle = Swarmclient::Communication.new endpoint: "127.0.0.1", port: 50001, uuid: "80174b53-2dda-49f1-9d6a-6a780d4"
31
+ bluzelle = Swarmclient::Communication.new endpoint: '127.0.0.1', port: 51010, uuid: '80174b53-2dda-49f1-9d6a-6a780d4'
31
32
  ```
32
33
 
33
- Note: The uuid is the uniq id of a referenced db hosted in the swarm.
34
- Generate a new one to generate a new store.
34
+ Note: The uuid is the unique id of a referenced db hosted in the swarm.
35
+ Generate a new one to generate a new store. The gem will default to:
36
+ '8c073d96-7291-11e8-adc0-fa7ae01bbebc' if none is provided.
35
37
  Refer to https://bluzelle.github.io/api/ for more info.
36
38
 
37
39
  Create New Entry (key-value)
@@ -45,16 +47,7 @@ bluzelle.read 'myKey'
45
47
  ```
46
48
  - Result
47
49
  ```
48
- {:value => "Your Value"}
49
- ```
50
-
51
- Read Multiple Keys
52
- ```
53
- bluzelle.read ['myKey', 'myKey2']
54
- ```
55
- - Result
56
- ```
57
- [{:myKey => "Your Value"}, {:myKey2 => nil}]
50
+ => "Your Value"
58
51
  ```
59
52
 
60
53
  Update Key value
@@ -73,7 +66,7 @@ bluzelle.has 'myKey'
73
66
  ```
74
67
  - Result
75
68
  ```
76
- => {:"key-exists" => true}
69
+ => true
77
70
  ```
78
71
 
79
72
  Read all keys stored
@@ -82,12 +75,17 @@ bluzelle.keys
82
75
  ```
83
76
  - Result
84
77
  ```
85
- => {:keys => ["myKey"]}
78
+ => ["myKey1"]
86
79
  ```
87
80
 
88
- ## Pubsub (Swarmclient::Pubsub)
89
-
90
- For data streaming -> WIP
81
+ Get size of database
82
+ ```
83
+ bluzelle.size
84
+ ```
85
+ - Result
86
+ ```
87
+ => 1
88
+ ```
91
89
 
92
90
  ## Development
93
91
 
@@ -101,4 +99,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/wlwanp
101
99
 
102
100
  ## License
103
101
 
104
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
102
+ The gem is under the terms of the [Apache License](http://www.apache.org/licenses/).
@@ -1,38 +1,43 @@
1
+ require 'google/protobuf'
2
+ require 'base64'
1
3
  require 'websocket-client-simple'
2
4
  require 'eventmachine'
3
5
  require 'json'
4
6
 
5
- DEFAULT_IP = 'ws://127.0.0.1'
6
- DEFAULT_PORT = 8080
7
+ require_relative './protobuf/bluzelle_pb'
8
+ require_relative './protobuf/database_pb'
7
9
 
8
- module Swarmclient
10
+ DEFAULT_UUID = '8c073d96-7291-11e8-adc0-fa7ae01bbebc'
11
+ DEFAULT_IP = '13.78.131.94' # '127.0.0.1'
12
+ DEFAULT_PORT = 51010 # 8100
9
13
 
14
+ module Swarmclient
10
15
  class Communication
11
16
 
12
- @req_id_range = 100
17
+ attr_accessor :transaction_id_limit, :ws_set_timeout
13
18
 
14
- def initialize endpoint:, port:, uuid:
19
+ @transaction_id_limit = 100
20
+ @ws_set_timeout = 5
15
21
 
16
- @_endpoint = endpoint || DEFAULT_IP
17
- @_port = port || DEFAULT_PORT
22
+ def initialize endpoint: DEFAULT_IP, port: DEFAULT_PORT, uuid: DEFAULT_UUID, secure: false
23
+
24
+ @_endpoint = endpoint
25
+ @_port = port
18
26
  @_uuid = uuid
27
+ @_protocol_prefix = secure ? 'wss://' : 'ws://'
19
28
 
20
29
  end
21
30
 
22
31
  def create key, value
23
- send cmd: 'create', data: { key: key, value: value }
32
+ send cmd: 'create', data: { key: key, value: value.to_s }
24
33
  end
25
34
 
26
35
  def read key
27
36
  send cmd: 'read', data: { key: key }
28
37
  end
29
38
 
30
- def read_multiple keys
31
- send_multiple cmd: 'read', keys: keys
32
- end
33
-
34
39
  def update key, value
35
- send cmd: 'update', data: { key: key, value: value }
40
+ send cmd: 'update', data: { key: key, value: value.to_s }
36
41
  end
37
42
 
38
43
  def remove key
@@ -47,61 +52,84 @@ module Swarmclient
47
52
  send cmd: 'keys', data: nil
48
53
  end
49
54
 
55
+ def size
56
+ send cmd: 'size', data: nil
57
+ end
58
+
50
59
  private
51
60
 
52
- def send_multiple cmd:, keys:
53
- keys.map do |key|
54
- res = send cmd: cmd, data: { key: key }
55
- Hash[key, res ? res[:value] : nil]
56
- end
61
+ def encoded_protobuf_msg cmd:, protobuf_cmd_data:
62
+ db_msg = Database_msg.new
63
+ db_msg.header = Database_header.new db_uuid: @_uuid, transaction_id: rand(@transaction_id_limit).to_i
64
+ db_msg[cmd] = protobuf_cmd_data
65
+ bzn_msg = Bzn_msg.new db: db_msg
66
+ Bzn_msg.encode bzn_msg
57
67
  end
58
68
 
59
- def send cmd:, data:
69
+ def generate_req cmd:, data:
70
+ protobuf_cmd = cmd_to_protobuf cmd
71
+ protobuf_cmd_msg = data.nil? ? protobuf_cmd.new : protobuf_cmd.new(data)
60
72
 
61
- endpoint, req = [
62
- [@_endpoint, ':', @_port.to_s].join(''),
63
- { "bzn-api": "crud", "cmd": cmd, "data": data, "db-uuid": @_uuid, "request-id": rand(@req_id_range) }
64
- ]
73
+ encoded_msg = encoded_protobuf_msg cmd: cmd, protobuf_cmd_data: protobuf_cmd_msg
74
+ encoded64_msg = Base64.strict_encode64 encoded_msg
65
75
 
66
- raw_data = get endpoint: endpoint, req: req
67
- err, res = raw_data.map { |data| data ? eval(data.gsub(/\s+/, "")) : false }
76
+ {"bzn-api": "database","msg": encoded64_msg}.to_json
77
+ end
68
78
 
69
- if res
70
- case res[:error]
71
- when 'NOT_THE_LEADER'
79
+ def cmd_to_protobuf cmd
80
+ processed_cmd =
81
+ case cmd
82
+ when 'keys', 'size' then 'empty'
83
+ else cmd
84
+ end
72
85
 
73
- @_endpoint, @_port = [
74
- "ws://#{res[:data][:'leader-host']}",
75
- res[:data][:'leader-port']
76
- ]
86
+ Object.const_get "Database_#{processed_cmd}"
87
+ end
77
88
 
78
- return send cmd: cmd, data: data
89
+ def generate_endpoint
90
+ [@_protocol_prefix, @_endpoint, ':', @_port.to_s].join('')
91
+ end
79
92
 
80
- when "RECORD_EXISTS", "RECORD_NOT_FOUND"
93
+ def send cmd:, data:
94
+ endpoint, req = [
95
+ generate_endpoint,
96
+ generate_req({ cmd: cmd, data: data })
97
+ ]
81
98
 
82
- return res[:error]
99
+ err, res = get req: req, endpoint: endpoint
100
+ return err if err
101
+ raise 'No Response' if res.nil?
83
102
 
84
- when nil
103
+ db_response = Database_response.decode res
85
104
 
86
- return res[:data]
105
+ if db_response.redirect
106
+ puts 'Switching leader_host: ' + db_response.redirect.leader_name
107
+ @_endpoint, @_port = [
108
+ db_response.redirect.leader_host,
109
+ db_response.redirect.leader_port
110
+ ]
87
111
 
88
- else
112
+ return send cmd: cmd, data: data
89
113
 
90
- return res[:error]
114
+ elsif !db_response.resp.nil? && !db_response.resp.error.empty?
115
+ return db_response.resp.error
91
116
 
92
- end
93
117
  else
94
- return err
118
+ case cmd
119
+ when 'create', 'update', 'delete' then nil
120
+ when 'read' then db_response.resp.value
121
+ else db_response.resp[cmd]
122
+ end
123
+
95
124
  end
125
+
96
126
  end
97
127
 
98
128
  def get req:, endpoint:
99
-
100
129
  res, err = [nil, nil]
101
130
 
102
131
  begin
103
132
  EventMachine.run do
104
-
105
133
  ws = WebSocket::Client::Simple.connect endpoint
106
134
 
107
135
  ws.on :message do |msg|
@@ -110,7 +138,7 @@ module Swarmclient
110
138
  end
111
139
 
112
140
  ws.on :open do
113
- ws.send req.to_json
141
+ ws.send req
114
142
  end
115
143
 
116
144
  ws.on :close do |e|
@@ -118,18 +146,18 @@ module Swarmclient
118
146
  end
119
147
 
120
148
  ws.on :error do |e|
121
- err = e
149
+ err ||= e
122
150
  EventMachine::stop_event_loop
123
151
  end
124
152
 
153
+ EventMachine::Timer.new(5) { ws.close }
125
154
  end
126
155
  rescue => e
127
156
  err = e
128
157
  end
129
158
 
130
- [err, res]
159
+ return [err, res]
131
160
  end
132
161
 
133
162
  end
134
-
135
163
  end
@@ -0,0 +1,17 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: bluzelle.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require_relative './database_pb'
7
+
8
+ Google::Protobuf::DescriptorPool.generated_pool.build do
9
+ add_message "bzn_msg" do
10
+ oneof :msg do
11
+ optional :db, :message, 10, "database_msg"
12
+ optional :json, :string, 11
13
+ end
14
+ end
15
+ end
16
+
17
+ Bzn_msg = Google::Protobuf::DescriptorPool.generated_pool.lookup("bzn_msg").msgclass
@@ -0,0 +1,75 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: database.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "database_msg" do
8
+ optional :header, :message, 2, "database_header"
9
+ oneof :msg do
10
+ optional :create, :message, 10, "database_create"
11
+ optional :read, :message, 11, "database_read"
12
+ optional :update, :message, 12, "database_update"
13
+ optional :delete, :message, 13, "database_delete"
14
+ optional :has, :message, 14, "database_has"
15
+ optional :keys, :message, 15, "database_empty"
16
+ optional :size, :message, 16, "database_empty"
17
+ end
18
+ end
19
+ add_message "database_redirect_response" do
20
+ optional :leader_id, :string, 1
21
+ optional :leader_name, :string, 2
22
+ optional :leader_host, :string, 3
23
+ optional :leader_port, :uint32, 4
24
+ optional :leader_http_port, :uint32, 5
25
+ end
26
+ add_message "database_header" do
27
+ optional :db_uuid, :string, 1
28
+ optional :transaction_id, :uint64, 2
29
+ end
30
+ add_message "database_create" do
31
+ optional :key, :string, 2
32
+ optional :value, :bytes, 3
33
+ end
34
+ add_message "database_read" do
35
+ optional :key, :string, 2
36
+ end
37
+ add_message "database_update" do
38
+ optional :key, :string, 2
39
+ optional :value, :bytes, 3
40
+ end
41
+ add_message "database_delete" do
42
+ optional :key, :string, 2
43
+ end
44
+ add_message "database_has" do
45
+ optional :key, :string, 2
46
+ end
47
+ add_message "database_empty" do
48
+ end
49
+ add_message "database_response" do
50
+ optional :header, :message, 1, "database_header"
51
+ oneof :success do
52
+ optional :redirect, :message, 2, "database_redirect_response"
53
+ optional :resp, :message, 3, "database_response.response"
54
+ end
55
+ end
56
+ add_message "database_response.response" do
57
+ optional :value, :bytes, 4
58
+ optional :has, :bool, 5
59
+ optional :size, :int32, 6
60
+ optional :error, :string, 7
61
+ repeated :keys, :string, 8
62
+ end
63
+ end
64
+
65
+ Database_msg = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_msg").msgclass
66
+ Database_redirect_response = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_redirect_response").msgclass
67
+ Database_header = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_header").msgclass
68
+ Database_create = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_create").msgclass
69
+ Database_read = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_read").msgclass
70
+ Database_update = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_update").msgclass
71
+ Database_delete = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_delete").msgclass
72
+ Database_has = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_has").msgclass
73
+ Database_empty = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_empty").msgclass
74
+ Database_response = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_response").msgclass
75
+ Database_response::Response = Google::Protobuf::DescriptorPool.generated_pool.lookup("database_response.response").msgclass
@@ -1,3 +1,3 @@
1
1
  module Swarmclient
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,14 @@
1
+ syntax = "proto3";
2
+
3
+ // Bluzelle message definition from:
4
+ // https://github.com/bluzelle/swarmDB/blob/devel/proto/bluzelle.proto
5
+
6
+ import "database.proto";
7
+
8
+ message bzn_msg
9
+ {
10
+ oneof msg {
11
+ database_msg db = 10;
12
+ string json = 11;
13
+ }
14
+ }
@@ -0,0 +1,83 @@
1
+ syntax = "proto3";
2
+
3
+ // Database message definition from:
4
+ // https://github.com/bluzelle/swarmDB/blob/devel/proto/database.proto
5
+
6
+ message database_msg
7
+ {
8
+ database_header header = 2;
9
+
10
+ oneof msg {
11
+ database_create create = 10;
12
+ database_read read = 11;
13
+ database_update update = 12;
14
+ database_delete delete = 13;
15
+ database_has has = 14;
16
+ database_empty keys = 15;
17
+ database_empty size = 16;
18
+ }
19
+ }
20
+
21
+ message database_redirect_response
22
+ {
23
+ string leader_id = 1;
24
+ string leader_name = 2;
25
+ string leader_host = 3;
26
+ uint32 leader_port = 4;
27
+ uint32 leader_http_port = 5;
28
+ }
29
+
30
+ message database_header
31
+ {
32
+ string db_uuid = 1;
33
+ uint64 transaction_id = 2;
34
+ }
35
+
36
+ message database_create
37
+ {
38
+ string key = 2;
39
+ bytes value = 3;
40
+ }
41
+
42
+ message database_read
43
+ {
44
+ string key = 2;
45
+ }
46
+
47
+ message database_update
48
+ {
49
+ string key = 2;
50
+ bytes value = 3;
51
+ }
52
+
53
+ message database_delete
54
+ {
55
+ string key = 2;
56
+ }
57
+
58
+ message database_has
59
+ {
60
+ string key = 2;
61
+ }
62
+
63
+ message database_empty {}
64
+
65
+ message database_response
66
+ {
67
+ database_header header = 1;
68
+
69
+ oneof success
70
+ {
71
+ database_redirect_response redirect = 2;
72
+ response resp = 3;
73
+ }
74
+
75
+ message response
76
+ {
77
+ bytes value = 4;
78
+ bool has = 5;
79
+ int32 size = 6;
80
+ string error = 7;
81
+ repeated string keys = 8;
82
+ }
83
+ }
data/swarmclient.gemspec CHANGED
@@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "eventmachine", "~> 1.2"
28
28
  spec.add_development_dependency "websocket-client-simple", "~> 0.3"
29
+ spec.add_development_dependency "google-protobuf", "~> 3.5"
29
30
  spec.add_development_dependency "json", "~> 2.1"
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swarmclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Warren
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: google-protobuf
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.5'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: json
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -113,8 +127,12 @@ files:
113
127
  - bin/setup
114
128
  - lib/swarmclient.rb
115
129
  - lib/swarmclient/communication.rb
130
+ - lib/swarmclient/protobuf/bluzelle_pb.rb
131
+ - lib/swarmclient/protobuf/database_pb.rb
116
132
  - lib/swarmclient/pubsub.rb
117
133
  - lib/swarmclient/version.rb
134
+ - proto/bluzelle.proto
135
+ - proto/database.proto
118
136
  - swarmclient.gemspec
119
137
  homepage: https://github.com/wlwanpan/swarmclient-rb
120
138
  licenses:
@@ -136,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
154
  version: '0'
137
155
  requirements: []
138
156
  rubyforge_project:
139
- rubygems_version: 2.7.6
157
+ rubygems_version: 2.6.14
140
158
  signing_key:
141
159
  specification_version: 4
142
160
  summary: A gem for the bluzele SwarmDB