fraggle 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fraggle.rb +16 -2
- data/lib/fraggle/client.rb +23 -11
- data/test/fraggle_client_test.rb +1 -1
- data/test/fraggle_protocol_test.rb +1 -1
- data/test/fraggle_snap_test.rb +1 -1
- metadata +3 -3
data/lib/fraggle.rb
CHANGED
@@ -4,8 +4,22 @@ require 'uri'
|
|
4
4
|
module Fraggle
|
5
5
|
|
6
6
|
def self.connect(uri, *args)
|
7
|
-
|
8
|
-
|
7
|
+
params = uri.gsub(/^doozer:\?/, '').split("&")
|
8
|
+
addrs = []
|
9
|
+
|
10
|
+
params.each do |param|
|
11
|
+
k, v = param.split("=")
|
12
|
+
if k == "ca" && v =~ /^[\d.]+:\d+$/
|
13
|
+
addrs << v
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if addrs.empty?
|
18
|
+
fail "The URI (#{uri}) does not contain valid addresses"
|
19
|
+
end
|
20
|
+
|
21
|
+
host, port = addrs.first.split(":")
|
22
|
+
c = EM.connect(host, port, Client, addrs, *args)
|
9
23
|
Snap.new(0, c)
|
10
24
|
end
|
11
25
|
|
data/lib/fraggle/client.rb
CHANGED
@@ -3,6 +3,7 @@ require 'fraggle/meta'
|
|
3
3
|
require 'fraggle/protocol'
|
4
4
|
require 'fraggle/request'
|
5
5
|
require 'fraggle/response'
|
6
|
+
require 'set'
|
6
7
|
require 'uri'
|
7
8
|
|
8
9
|
module Fraggle
|
@@ -18,12 +19,9 @@ module Fraggle
|
|
18
19
|
MaxTag = (1<<32)
|
19
20
|
|
20
21
|
|
21
|
-
def initialize(
|
22
|
-
|
23
|
-
|
24
|
-
uri = URI(uri.to_s)
|
25
|
-
|
26
|
-
@addr = [uri.host, uri.port] * ":"
|
22
|
+
def initialize(addrs)
|
23
|
+
@addr = addrs.shift
|
24
|
+
@init = addrs
|
27
25
|
@addrs = {}
|
28
26
|
@shun = {}
|
29
27
|
@cbx = {}
|
@@ -259,8 +257,8 @@ module Fraggle
|
|
259
257
|
end
|
260
258
|
|
261
259
|
waw = Proc.new do |e|
|
262
|
-
if e.value
|
263
|
-
addr = @addrs.delete(e.
|
260
|
+
if e.value != ""
|
261
|
+
addr = @addrs.delete(e.value)
|
264
262
|
if addr
|
265
263
|
error "noticed #{addr} is gone; removing"
|
266
264
|
end
|
@@ -283,8 +281,15 @@ module Fraggle
|
|
283
281
|
end
|
284
282
|
end
|
285
283
|
|
286
|
-
watch
|
287
|
-
|
284
|
+
watch("/doozer/slot/*", &waw)
|
285
|
+
|
286
|
+
w = walk(0, "/doozer/slot/*", &waw)
|
287
|
+
w.done do
|
288
|
+
# We have the best known addrs; We can clear the initial
|
289
|
+
# ones given at inception.
|
290
|
+
debug "addrs list complete; clearing init addrs"
|
291
|
+
@init.clear
|
292
|
+
end
|
288
293
|
end
|
289
294
|
|
290
295
|
# What happens when a connection is closed for any reason.
|
@@ -300,7 +305,14 @@ module Fraggle
|
|
300
305
|
# has been complete, we'll start the timer again.
|
301
306
|
EM.cancel_timer(@timer)
|
302
307
|
|
303
|
-
|
308
|
+
# Attempt to use an addr given to us by a Doozer
|
309
|
+
_, @addr = @addrs.shift
|
310
|
+
|
311
|
+
if ! @addr
|
312
|
+
# As a last resort, try one of the addresses given
|
313
|
+
# at inception.
|
314
|
+
@addr = @init.shift
|
315
|
+
end
|
304
316
|
|
305
317
|
if ! @addr
|
306
318
|
# We are all out of addresses to try
|
data/test/fraggle_client_test.rb
CHANGED
data/test/fraggle_snap_test.rb
CHANGED