reedb 0.10.rc1 → 0.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 +1 -12
- data/Gemfile.lock +17 -11
- data/bin/reedbd +65 -23
- data/lib/reedb/constants.rb +11 -23
- data/lib/reedb/daemon_wrapper.rb +138 -121
- data/lib/reedb/debouncer.rb +129 -0
- data/lib/reedb/errors/daemon_errors.rb +4 -4
- data/lib/reedb/errors/exit_errors.rb +12 -0
- data/lib/reedb/errors/reedb_errors.rb +21 -0
- data/lib/reedb/errors/vault_errors.rb +8 -6
- data/lib/reedb/reevault.rb +84 -72
- data/lib/reedb/security/encryption.rb +1 -5
- data/lib/reedb/security/tokens.rb +21 -0
- data/lib/reedb/utils/logger.rb +5 -5
- data/lib/reedb/utils/uuids.rb +40 -132
- data/lib/reedb.rb +518 -272
- data/reedb.gemspec +32 -24
- data/tests/embeddedc/MyTest/Makefile +238 -0
- data/tests/embeddedc/MyTest/MyTest.c +27 -0
- data/tests/embeddedc/MyTest/MyTest.o +0 -0
- data/tests/embeddedc/MyTest/extconf.rb +11 -0
- data/tests/embeddedc/MyTest/mytest.so +0 -0
- data/tests/embeddedc/mytest.rb +8 -0
- data/tests/http_tester.py +208 -0
- data/tests/play.rb +60 -4
- data/tests/tests.rb +7 -59
- data/tmp/gems/aes-0.5.0.spec +80 -0
- data/tmp/gems/digest-tiger-1.0.2.spec +85 -0
- data/tmp/gems/main.template +118 -0
- data/tmp/gems/twofish-1.0.5.spec +75 -0
- metadata +45 -16
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
data/lib/reedb/utils/uuids.rb
CHANGED
@@ -35,21 +35,21 @@ class UUID
|
|
35
35
|
private_class_method :new
|
36
36
|
|
37
37
|
class << self
|
38
|
-
def mask19
|
39
|
-
|
38
|
+
def mask19(v, str) # :nodoc
|
39
|
+
new_string = str.bytes.to_a
|
40
40
|
version = [0, 16, 32, 48, 64, 80][v]
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
41
|
+
new_string[6] &= 0b00001111
|
42
|
+
new_string[6] |= version
|
43
|
+
# new_string[7] &= 0b00001111
|
44
|
+
# new_string[7] |= 0b01010000
|
45
|
+
new_string[8] &= 0b00111111
|
46
|
+
new_string[8] |= 0b10000000
|
47
47
|
str = ''
|
48
|
-
|
48
|
+
new_string.each { |s| str << s.chr }
|
49
49
|
str
|
50
50
|
end
|
51
51
|
|
52
|
-
def mask18
|
52
|
+
def mask18(v, str) # :nodoc
|
53
53
|
version = [0, 16, 32, 48, 64, 80][v]
|
54
54
|
str[6] &= 0b00001111
|
55
55
|
str[6] |= version
|
@@ -60,8 +60,8 @@ class UUID
|
|
60
60
|
str
|
61
61
|
end
|
62
62
|
|
63
|
-
def mask
|
64
|
-
if RUBY_VERSION >=
|
63
|
+
def mask(v, str)
|
64
|
+
if RUBY_VERSION >= '1.9.0'
|
65
65
|
return mask19 v, str
|
66
66
|
else
|
67
67
|
return mask18 v, str
|
@@ -71,7 +71,7 @@ class UUID
|
|
71
71
|
|
72
72
|
# UUID generation using SHA1. Recommended over create_md5.
|
73
73
|
# Namespace object is another UUID, some of them are pre-defined below.
|
74
|
-
def create_sha1
|
74
|
+
def create_sha1(str, namespace)
|
75
75
|
sha1 = Digest::SHA1.new
|
76
76
|
sha1.update namespace.raw_bytes
|
77
77
|
sha1.update str
|
@@ -84,7 +84,7 @@ class UUID
|
|
84
84
|
alias :create_v5 :create_sha1
|
85
85
|
|
86
86
|
# UUID generation using MD5 (for backward compat.)
|
87
|
-
def create_md5
|
87
|
+
def create_md5(str, namespace)
|
88
88
|
md5 = Digest::MD5.new
|
89
89
|
md5.update namespace.raw_bytes
|
90
90
|
md5.update str
|
@@ -134,7 +134,7 @@ class UUID
|
|
134
134
|
# invokation. If you want to speed this up, try remounting tmpdir with a
|
135
135
|
# memory based filesystem (such as tmpfs). STILL slow? then no way but
|
136
136
|
# rewrite it with c :)
|
137
|
-
def create
|
137
|
+
def create(clock=nil, time=nil, mac_addr=nil)
|
138
138
|
c = t = m = nil
|
139
139
|
Dir.chdir Dir.tmpdir do
|
140
140
|
unless FileTest.exist? STATE_FILE then
|
@@ -144,17 +144,17 @@ class UUID
|
|
144
144
|
# see Section 4.5 of RFC4122 for details.
|
145
145
|
sha1 = Digest::SHA1.new
|
146
146
|
256.times do
|
147
|
-
r = [rand(0x100000000)].pack
|
147
|
+
r = [rand(0x100000000)].pack 'N'
|
148
148
|
sha1.update r
|
149
149
|
end
|
150
150
|
str = sha1.digest
|
151
151
|
r = rand 14 # 20-6
|
152
152
|
node = str[r, 6] || str
|
153
|
-
if RUBY_VERSION >=
|
154
|
-
|
155
|
-
|
153
|
+
if RUBY_VERSION >= '1.9.0'
|
154
|
+
n_node = node.bytes.to_a
|
155
|
+
n_node[0] |= 0x01
|
156
156
|
node = ''
|
157
|
-
|
157
|
+
n_node.each { |s| node << s.chr }
|
158
158
|
else
|
159
159
|
node[0] |= 0x01 # multicast bit
|
160
160
|
end
|
@@ -162,9 +162,12 @@ class UUID
|
|
162
162
|
open STATE_FILE, 'w' do |fp|
|
163
163
|
fp.flock IO::LOCK_EX
|
164
164
|
write_state fp, k, node
|
165
|
-
fp.chmod
|
165
|
+
fp.chmod(777) # must be world writable
|
166
166
|
end
|
167
167
|
end
|
168
|
+
|
169
|
+
puts "TRYING TO OPEN: #{STATE_FILE}"
|
170
|
+
|
168
171
|
open STATE_FILE, 'r+' do |fp|
|
169
172
|
fp.flock IO::LOCK_EX
|
170
173
|
c, m = read_state fp
|
@@ -197,7 +200,7 @@ class UUID
|
|
197
200
|
|
198
201
|
# A simple GUID parser: just ignores unknown characters and convert
|
199
202
|
# hexadecimal dump into 16-octet object.
|
200
|
-
def parse
|
203
|
+
def parse(obj)
|
201
204
|
str = obj.to_s.sub %r/\Aurn:uuid:/, ''
|
202
205
|
str.gsub! %r/[^0-9A-Fa-f]/, ''
|
203
206
|
raw = str[0..31].lines.to_a.pack 'H*'
|
@@ -208,8 +211,8 @@ class UUID
|
|
208
211
|
|
209
212
|
# The 'primitive constructor' of this class
|
210
213
|
# Note UUID.pack(uuid.unpack) == uuid
|
211
|
-
def pack
|
212
|
-
raw = [tl, tm, th, ch, cl, n].pack
|
214
|
+
def pack(tl, tm, th, ch, cl, n)
|
215
|
+
raw = [tl, tm, th, ch, cl, n].pack 'NnnCCa6'
|
213
216
|
ret = new raw
|
214
217
|
ret.freeze
|
215
218
|
ret
|
@@ -219,7 +222,7 @@ class UUID
|
|
219
222
|
# The 'primitive deconstructor', or the dual to pack.
|
220
223
|
# Note UUID.pack(uuid.unpack) == uuid
|
221
224
|
def unpack
|
222
|
-
raw_bytes.unpack
|
225
|
+
raw_bytes.unpack 'NnnCCa6'
|
223
226
|
end
|
224
227
|
|
225
228
|
# Generate the string representation (a.k.a GUID) of this UUID
|
@@ -227,20 +230,20 @@ class UUID
|
|
227
230
|
a = unpack
|
228
231
|
tmp = a[-1].unpack 'C*'
|
229
232
|
a[-1] = sprintf '%02x%02x%02x%02x%02x%02x', *tmp
|
230
|
-
|
233
|
+
return ('%08x-%04x-%04x-%02x%02x-%s' % a)
|
231
234
|
end
|
232
235
|
alias guid to_s
|
233
236
|
|
234
|
-
# Convert into a RFC4122-
|
237
|
+
# Convert into a RFC4122-conforming URN representation
|
235
238
|
def to_uri
|
236
|
-
|
239
|
+
return ('urn:uuid:' + self.to_s)
|
237
240
|
end
|
238
241
|
alias urn to_uri
|
239
242
|
|
240
243
|
# Convert into 128-bit unsigned integer
|
241
244
|
# Typically a Bignum instance, but can be a Fixnum.
|
242
245
|
def to_int
|
243
|
-
tmp = self.raw_bytes.unpack
|
246
|
+
tmp = self.raw_bytes.unpack 'C*'
|
244
247
|
tmp.inject do |r, i|
|
245
248
|
r * 256 | i
|
246
249
|
end
|
@@ -257,119 +260,24 @@ class UUID
|
|
257
260
|
end
|
258
261
|
|
259
262
|
# Two UUIDs are said to be equal if and only if their (byte-order
|
260
|
-
# canonicalized) integer representations are
|
263
|
+
# canonicalized) integer representations are equivalent. Refer RFC4122 for
|
261
264
|
# details.
|
262
|
-
def == other
|
265
|
+
def == (other)
|
263
266
|
to_i == other.to_i
|
264
267
|
end
|
265
268
|
|
266
269
|
include Comparable
|
267
270
|
# UUIDs are comparable (don't know what benefits are there, though).
|
268
|
-
def <=> other
|
271
|
+
def <=> (other)
|
269
272
|
to_s <=> other.to_s
|
270
273
|
end
|
271
274
|
|
272
275
|
# Pre-defined UUID Namespaces described in RFC4122 Appendix C.
|
273
|
-
NameSpace_DNS = parse
|
274
|
-
NameSpace_URL = parse
|
275
|
-
NameSpace_OID = parse
|
276
|
-
NameSpace_X500 = parse
|
276
|
+
NameSpace_DNS = parse '6ba7b810-9dad-11d1-80b4-00c04fd430c8'
|
277
|
+
NameSpace_URL = parse '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
|
278
|
+
NameSpace_OID = parse '6ba7b812-9dad-11d1-80b4-00c04fd430c8'
|
279
|
+
NameSpace_X500 = parse '6ba7b814-9dad-11d1-80b4-00c04fd430c8'
|
277
280
|
|
278
281
|
# The Nil UUID in RFC4122 Section 4.1.7
|
279
|
-
Nil = parse
|
280
|
-
end
|
281
|
-
|
282
|
-
__END__
|
283
|
-
|
284
|
-
if __FILE__ == $0 then
|
285
|
-
require 'test/unit'
|
286
|
-
|
287
|
-
class TC_UUID < Test::Unit::TestCase
|
288
|
-
def test_v1
|
289
|
-
u1 = UUID.create
|
290
|
-
u2 = UUID.create
|
291
|
-
assert_not_equal u1, u2
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_v1_repeatability
|
295
|
-
u1 = UUID.create 1, 2, "345678"
|
296
|
-
u2 = UUID.create 1, 2, "345678"
|
297
|
-
assert_equal u1, u2
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_v3
|
301
|
-
u1 = UUID.create_md5 "foo", UUID::NameSpace_DNS
|
302
|
-
u2 = UUID.create_md5 "foo", UUID::NameSpace_DNS
|
303
|
-
u3 = UUID.create_md5 "foo", UUID::NameSpace_URL
|
304
|
-
assert_equal u1, u2
|
305
|
-
assert_not_equal u1, u3
|
306
|
-
end
|
307
|
-
|
308
|
-
def test_v5
|
309
|
-
u1 = UUID.create_sha1 "foo", UUID::NameSpace_DNS
|
310
|
-
u2 = UUID.create_sha1 "foo", UUID::NameSpace_DNS
|
311
|
-
u3 = UUID.create_sha1 "foo", UUID::NameSpace_URL
|
312
|
-
assert_equal u1, u2
|
313
|
-
assert_not_equal u1, u3
|
314
|
-
end
|
315
|
-
|
316
|
-
def test_v4
|
317
|
-
# This test is not perfect, because the random nature of version 4
|
318
|
-
# UUID it is not always true that the three objects below really
|
319
|
-
# differ. But in real life it's enough to say we're OK when this
|
320
|
-
# passes.
|
321
|
-
u1 = UUID.create_random
|
322
|
-
u2 = UUID.create_random
|
323
|
-
u3 = UUID.create_random
|
324
|
-
assert_not_equal u1.raw_bytes, u2.raw_bytes
|
325
|
-
assert_not_equal u1.raw_bytes, u3.raw_bytes
|
326
|
-
assert_not_equal u2.raw_bytes, u3.raw_bytes
|
327
|
-
end
|
328
|
-
|
329
|
-
def test_pack
|
330
|
-
u1 = UUID.pack 0x6ba7b810, 0x9dad, 0x11d1, 0x80, 0xb4,
|
331
|
-
"\000\300O\3240\310"
|
332
|
-
assert_equal UUID::NameSpace_DNS, u1
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_unpack
|
336
|
-
tl, tm, th, cl, ch, m = UUID::NameSpace_DNS.unpack
|
337
|
-
assert_equal 0x6ba7b810, tl
|
338
|
-
assert_equal 0x9dad, tm
|
339
|
-
assert_equal 0x11d1, th
|
340
|
-
assert_equal 0x80, cl
|
341
|
-
assert_equal 0xb4, ch
|
342
|
-
assert_equal "\000\300O\3240\310", m
|
343
|
-
end
|
344
|
-
|
345
|
-
def test_parse
|
346
|
-
u1 = UUID.pack 0x6ba7b810, 0x9dad, 0x11d1, 0x80, 0xb4,
|
347
|
-
"\000\300O\3240\310"
|
348
|
-
u2 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
|
349
|
-
u3 = UUID.parse "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
|
350
|
-
assert_equal u1, u2
|
351
|
-
assert_equal u1, u3
|
352
|
-
end
|
353
|
-
|
354
|
-
def test_to_s
|
355
|
-
u1 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
|
356
|
-
assert_equal "6ba7b810-9dad-11d1-80b4-00c04fd430c8", u1.to_s
|
357
|
-
end
|
358
|
-
|
359
|
-
def test_to_i
|
360
|
-
u1 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
|
361
|
-
assert_equal 0x6ba7b8109dad11d180b400c04fd430c8, u1.to_i
|
362
|
-
end
|
363
|
-
|
364
|
-
def test_version
|
365
|
-
u1 = UUID.create_v1
|
366
|
-
assert_equal 1, u1.version
|
367
|
-
u3 = UUID.create_v3 "foo", UUID::NameSpace_DNS
|
368
|
-
assert_equal 3, u3.version
|
369
|
-
u4 = UUID.create_v4
|
370
|
-
assert_equal 4, u4.version
|
371
|
-
u5 = UUID.create_v5 "foo", UUID::NameSpace_DNS
|
372
|
-
assert_equal 5, u5.version
|
373
|
-
end
|
374
|
-
end
|
282
|
+
Nil = parse '00000000-0000-0000-0000-000000000000'
|
375
283
|
end
|