journeta 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/examples/network_status.rb +9 -3
- data/lib/journeta/asynchronous.rb +2 -6
- data/lib/journeta/journeta_engine.rb +5 -2
- data/lib/journeta/peer_connection.rb +2 -3
- data/lib/journeta/peer_listener.rb +7 -3
- data/lib/journeta/peer_registry.rb +35 -3
- data/lib/journeta/presence_listener.rb +1 -0
- data/lib/journeta/version.rb +1 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.1.2 2008-09-08
|
2
|
+
|
3
|
+
* Preemptive peer reaping. Peers now automatically "expire" from the local registry when they haven't been heard from in a while.
|
4
|
+
* Non-significant fixes.
|
5
|
+
|
6
|
+
|
7
|
+
== 0.1.1 2008-09-05
|
8
|
+
|
9
|
+
* Figuring out how to deploy properly with hoe :)
|
10
|
+
|
1
11
|
== 0.1.0 2008-09-05
|
2
12
|
|
3
13
|
* Renamed Journeta::JournetaEngine to Journeta::Engine
|
data/examples/network_status.rb
CHANGED
@@ -23,9 +23,15 @@ begin
|
|
23
23
|
puts "Displays infromation on all known peers."
|
24
24
|
puts "Updated: #{Time.now}"
|
25
25
|
puts "\n"
|
26
|
-
puts "UUID\t\tVersion\t\tIP Address\t\tPort\t\tDiscovered\t\tUpdated\t\tGroups\n"
|
27
|
-
|
28
|
-
|
26
|
+
puts "UUID\t\tVersion\t\tIP Address\t\tPort\t\tDiscovered\t\t\tUpdated\t\t\t\tGroups\n"
|
27
|
+
# require 'pp'
|
28
|
+
# pp all
|
29
|
+
all.each do |uuid, peer|
|
30
|
+
groups = '...'
|
31
|
+
if !all[uuid].groups.nil?
|
32
|
+
groups = all[uuid].groups.join(',')
|
33
|
+
end
|
34
|
+
puts "#{all[uuid].uuid}\t#{all[uuid].version}\t\t#{all[uuid].ip_address}\t\t#{all[uuid].peer_port}\t\t#{all[uuid].created_at || 'TODO'}\t#{all[uuid].updated_at || 'TODO'}\t[#{groups}]"
|
29
35
|
end
|
30
36
|
sleep(0.2)
|
31
37
|
end while true
|
@@ -15,15 +15,11 @@ module Journeta
|
|
15
15
|
|
16
16
|
attr_accessor :thread, :engine
|
17
17
|
|
18
|
-
|
19
|
-
|
20
18
|
def initialize(engine)
|
21
19
|
@engine = engine
|
22
20
|
@thread_lock = Mutex.new
|
23
21
|
@thread = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
|
22
|
+
end
|
27
23
|
|
28
24
|
# Start the +Thread+ for this instance, iff not already running.
|
29
25
|
def start
|
@@ -52,7 +48,7 @@ module Journeta
|
|
52
48
|
def stop
|
53
49
|
@thread_lock.synchronize do
|
54
50
|
if @thread
|
55
|
-
Thread.kill(@thread)
|
51
|
+
Thread.kill(@thread) # nasty pants!
|
56
52
|
@thread.join
|
57
53
|
@thread = nil
|
58
54
|
end
|
@@ -95,6 +95,8 @@ module Journeta
|
|
95
95
|
# Starts sub-comonents which have their own life-cycle requirements.
|
96
96
|
# The registry itself does not have a dedication thread, and thus does not need to be started.
|
97
97
|
def start
|
98
|
+
@peer_registry.start
|
99
|
+
|
98
100
|
# Start a peer listener first so we don't risk missing a connection attempt.
|
99
101
|
putsd "Starting #{@peer_listener.class.to_s}"
|
100
102
|
@peer_listener.start
|
@@ -121,7 +123,8 @@ module Journeta
|
|
121
123
|
# While the registry does not have its own thread, it is in charge of managing
|
122
124
|
# +PeerConnection+s which DO have individual threads. This call
|
123
125
|
# forcefully terminates all connections, which may or may not be actively passing data.
|
124
|
-
@peer_registry.unregister_all
|
126
|
+
# @peer_registry.unregister_all
|
127
|
+
@peer_registry.stop
|
125
128
|
end
|
126
129
|
|
127
130
|
# Sends the given object to all peers in one of the #groups associated with this instance.
|
@@ -148,7 +151,7 @@ module Journeta
|
|
148
151
|
def known_groups()
|
149
152
|
s = Set.new
|
150
153
|
self.known_peers(true).each do |uuid, peer|
|
151
|
-
s.merge peer.groups
|
154
|
+
s.merge peer.groups unless peer.groups.nil?
|
152
155
|
end
|
153
156
|
s.to_a
|
154
157
|
end
|
@@ -29,9 +29,13 @@ module Journeta
|
|
29
29
|
while more = session.gets
|
30
30
|
data += more
|
31
31
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
begin
|
33
|
+
msg = YAML::load(data)
|
34
|
+
h = @engine.peer_handler
|
35
|
+
h.call msg
|
36
|
+
rescue
|
37
|
+
putsd "YAML could not be deserialized! The data will not be passed up to the application."
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
37
41
|
rescue
|
@@ -3,18 +3,28 @@ require 'thread'
|
|
3
3
|
module Journeta
|
4
4
|
|
5
5
|
# Responsible for keeping in-memory metadata on known peers in the form of PeerConnections.
|
6
|
-
|
7
|
-
class PeerRegistry #<< Journeta::Asynchronous
|
6
|
+
class PeerRegistry < Journeta::Asynchronous
|
8
7
|
|
9
8
|
include Logger
|
10
9
|
|
11
10
|
# {<:uuid> => PeerConnection}
|
12
11
|
# attr_reader :peers
|
13
12
|
|
13
|
+
|
14
|
+
# Minimum period between reaper invocations, in seconds.
|
15
|
+
#attr_accessor :reaper_period
|
16
|
+
|
17
|
+
# The minimun time, in seconds, after a given presence notification arrive that it may be considered for reaping.
|
18
|
+
#attr_accessor :reaper_tolerance
|
19
|
+
|
20
|
+
@@DEFAULT_REAPER_PERIOD = 1
|
21
|
+
|
14
22
|
def initialize(engine)
|
15
|
-
|
23
|
+
super(engine)
|
16
24
|
@peers = {}
|
17
25
|
@mutex = Mutex.new
|
26
|
+
@reaper_period = @@DEFAULT_REAPER_PERIOD
|
27
|
+
@reaper_tolerance = engine.presence_period + 2.0
|
18
28
|
end
|
19
29
|
|
20
30
|
def clear
|
@@ -23,6 +33,26 @@ module Journeta
|
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
36
|
+
def go
|
37
|
+
loop do
|
38
|
+
@mutex.synchronize do
|
39
|
+
to_reap = []
|
40
|
+
@peers.each do |uuid, peer|
|
41
|
+
tolerance = Time.now - @reaper_tolerance
|
42
|
+
if peer.updated_at < tolerance
|
43
|
+
to_reap << peer
|
44
|
+
end
|
45
|
+
end
|
46
|
+
to_reap.each do |peer|
|
47
|
+
peer.stop
|
48
|
+
@peers.delete peer.uuid
|
49
|
+
end
|
50
|
+
end
|
51
|
+
sleep @reaper_period
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
26
56
|
def all(all_groups = false)
|
27
57
|
r = nil
|
28
58
|
@mutex.synchronize do
|
@@ -46,6 +76,8 @@ module Journeta
|
|
46
76
|
else
|
47
77
|
putsd "Updating peer #{peer.uuid}."
|
48
78
|
peer.stop
|
79
|
+
# Make sure we're not overriding the creation date of the original entry.
|
80
|
+
peer.created_at = nil
|
49
81
|
existing.update_settings peer
|
50
82
|
end
|
51
83
|
|
@@ -45,6 +45,7 @@ module Journeta
|
|
45
45
|
peer.uuid = m.uuid
|
46
46
|
peer.version = m.version
|
47
47
|
peer.groups = m.groups
|
48
|
+
peer.created_at = peer.updated_at = Time.now
|
48
49
|
|
49
50
|
# We should not start the #PeerConnection before registering because
|
50
51
|
# the peer might already be registered. In this case, we'd have wasted a thread,
|
data/lib/journeta/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: journeta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Preston Lee
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|