journeta 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +20 -0
- data/{History.txt → HISTORY} +13 -1
- data/LICENSE +51 -0
- data/License.txt +2 -2
- data/{README.txt → README.rdoc} +12 -17
- data/Rakefile +46 -112
- data/VERSION +1 -0
- data/{examples/instant_messenger.rb → bin/journeta_instant_messenger.rb} +13 -0
- data/bin/journeta_mock_peers.rb +32 -0
- data/{examples/network_status.rb → bin/journeta_network_status.rb} +0 -0
- data/bin/journeta_peer_fuzzer.rb +54 -0
- data/{examples/queue_client.rb → bin/journeta_queue_client.rb} +0 -0
- data/{examples/queue_server.rb → bin/journeta_queue_server.rb} +0 -0
- data/bin/journeta_thread_leak_check.rb +16 -0
- data/bin/journeta_top.rb +73 -0
- data/{examples/instant_messenger_gui.rb → broken/journeta_instant_messenger_gui.rb} +0 -2
- data/broken/journeta_instant_messenger_shoes.rb +52 -0
- data/lib/diff.rb +280 -0
- data/lib/journeta.rb +1 -0
- data/lib/journeta/asynchronous.rb +2 -2
- data/lib/journeta/exception.rb +8 -0
- data/lib/journeta/journeta_engine.rb +4 -5
- data/lib/journeta/logger.rb +1 -1
- data/lib/journeta/peer_connection.rb +2 -2
- data/lib/journeta/peer_listener.rb +2 -2
- data/lib/journeta/presence_broadcaster.rb +19 -5
- data/lib/journeta/presence_listener.rb +8 -4
- data/lib/journeta/version.rb +6 -4
- data/rdoc/Array.html +199 -0
- data/rdoc/Diff.html +714 -0
- data/rdoc/Diffable.html +409 -0
- data/rdoc/Journeta.html +288 -0
- data/rdoc/Journeta/Asynchronous.html +429 -0
- data/rdoc/Journeta/Common.html +205 -0
- data/rdoc/Journeta/Common/BasicMessage.html +228 -0
- data/rdoc/Journeta/Common/DummyPeerHandler.html +237 -0
- data/rdoc/Journeta/Common/Job.html +279 -0
- data/rdoc/Journeta/Common/Shutdown.html +236 -0
- data/rdoc/Journeta/DefaultPeerHandler.html +248 -0
- data/rdoc/Journeta/DefaultPeerRegisteredHandler.html +249 -0
- data/rdoc/Journeta/DefaultPeerUnregisteredHandler.html +249 -0
- data/rdoc/Journeta/DefaultPeerUpdatedHandler.html +249 -0
- data/rdoc/Journeta/Engine.html +953 -0
- data/rdoc/Journeta/Logger.html +237 -0
- data/rdoc/Journeta/NotImplementedException.html +188 -0
- data/rdoc/Journeta/PeerConnection.html +549 -0
- data/rdoc/Journeta/PeerListener.html +276 -0
- data/rdoc/Journeta/PeerRegistry.html +804 -0
- data/rdoc/Journeta/PresenceBroadcaster.html +306 -0
- data/rdoc/Journeta/PresenceListener.html +300 -0
- data/rdoc/Journeta/PresenceMessage.html +321 -0
- data/rdoc/Journeta/VERSION.html +181 -0
- data/rdoc/README_rdoc.html +196 -0
- data/rdoc/String.html +199 -0
- data/rdoc/created.rid +20 -0
- data/rdoc/index.html +212 -0
- data/rdoc/lib/diff_rb.html +52 -0
- data/rdoc/lib/journeta/asynchronous_rb.html +60 -0
- data/rdoc/lib/journeta/common/basic_message_rb.html +52 -0
- data/rdoc/lib/journeta/common/dummy_peer_handler_rb.html +52 -0
- data/rdoc/lib/journeta/common/job_rb.html +52 -0
- data/rdoc/lib/journeta/common/shutdown_rb.html +52 -0
- data/rdoc/lib/journeta/exception_rb.html +55 -0
- data/rdoc/lib/journeta/journeta_engine_rb.html +62 -0
- data/rdoc/lib/journeta/logger_rb.html +55 -0
- data/rdoc/lib/journeta/peer_connection_rb.html +58 -0
- data/rdoc/lib/journeta/peer_handler_rb.html +52 -0
- data/rdoc/lib/journeta/peer_listener_rb.html +60 -0
- data/rdoc/lib/journeta/peer_registry_rb.html +54 -0
- data/rdoc/lib/journeta/presence_broadcaster_rb.html +57 -0
- data/rdoc/lib/journeta/presence_listener_rb.html +62 -0
- data/rdoc/lib/journeta/presence_message_rb.html +52 -0
- data/rdoc/lib/journeta/version_rb.html +52 -0
- data/rdoc/lib/journeta_rb.html +91 -0
- data/rdoc/rdoc.css +706 -0
- data/test/helper.rb +19 -0
- data/test/test_lifecycle.rb +49 -9
- data/website/images/arrow.png +0 -0
- data/website/images/banner.jpg +0 -0
- data/website/images/content_shadow.png +0 -0
- data/website/images/content_side.png +0 -0
- data/website/images/header.jpg +0 -0
- data/website/images/header_side.jpg +0 -0
- data/website/index.html +1 -1
- data/website/index.txt +1 -1
- data/website/stylesheets/reset.css +30 -0
- data/website/stylesheets/screen.css +1 -1
- metadata +152 -46
- data/test/test_event_broadcaster.rb +0 -15
- data/test/test_helper.rb +0 -4
- data/test/test_journeta.rb +0 -11
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
current_dir = File.dirname(File.expand_path(__FILE__))
|
3
|
+
lib_path = File.join(current_dir, '..', 'lib')
|
4
|
+
$LOAD_PATH.unshift lib_path
|
5
|
+
|
6
|
+
require 'journeta'
|
7
|
+
include Journeta
|
8
|
+
|
9
|
+
#puts "Threads before start: #{Thread.count}"
|
10
|
+
|
11
|
+
j = Engine.new
|
12
|
+
j.start
|
13
|
+
sleep 10
|
14
|
+
j.stop
|
15
|
+
|
16
|
+
#puts "Threads after stop: #{Thread.count}"
|
data/bin/journeta_top.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
banner =<<EOL
|
4
|
+
A "top"-like tool for monitoring network status.
|
5
|
+
Will not run on JRuby due to native dependencies.
|
6
|
+
Copyright 2011, Preston Lee. http://prestonlee.com
|
7
|
+
|
8
|
+
Usage: #{$0}
|
9
|
+
|
10
|
+
EOL
|
11
|
+
|
12
|
+
puts banner
|
13
|
+
|
14
|
+
current_dir = File.dirname(File.expand_path(__FILE__))
|
15
|
+
lib_path = File.join(current_dir, '..', 'lib')
|
16
|
+
$LOAD_PATH.unshift lib_path
|
17
|
+
|
18
|
+
require 'journeta'
|
19
|
+
include Journeta
|
20
|
+
include Journeta::Common
|
21
|
+
include Journeta::Common::Shutdown
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
begin
|
25
|
+
require 'curses'
|
26
|
+
rescue
|
27
|
+
puts 'Please install the curses gem to use this example.'
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
peer_port = (2048 + rand( 2 ** 8))
|
32
|
+
@journeta = Journeta::Engine.new(:peer_port => peer_port)
|
33
|
+
@journeta.start
|
34
|
+
stop_on_shutdown(@journeta)
|
35
|
+
|
36
|
+
Curses.init_screen
|
37
|
+
Curses.setpos(0,0)
|
38
|
+
Curses::addstr("Press ^C to quit. ENTER to refresh.\n")
|
39
|
+
|
40
|
+
@run = true
|
41
|
+
@run_lock = Mutex.new
|
42
|
+
|
43
|
+
refresh = Thread.new do
|
44
|
+
keep_going = true
|
45
|
+
begin
|
46
|
+
@run_lock.synchronize do
|
47
|
+
keep_going = @run
|
48
|
+
end
|
49
|
+
all = @journeta.known_peers
|
50
|
+
|
51
|
+
Curses.clear
|
52
|
+
Curses.setpos(0,0)
|
53
|
+
Curses.addstr "UUID\t\tVersion\tIP Address\tDiscovered\t\t\tUpdated\t\t\t\tGroups\n"
|
54
|
+
all.keys.sort.each do |uuid|
|
55
|
+
Curses.addstr "#{all[uuid].uuid}\t#{all[uuid].version}\t#{all[uuid].ip_address}\t#{all[uuid].created_at}\t#{all[uuid].updated_at}\t#{all[uuid].groups}\n"
|
56
|
+
end
|
57
|
+
sleep(0.1)
|
58
|
+
end while keep_going
|
59
|
+
end
|
60
|
+
|
61
|
+
begin
|
62
|
+
c = nil
|
63
|
+
begin
|
64
|
+
c = Curses.getch
|
65
|
+
end until c == ?C or c == ?\e
|
66
|
+
Curses.setpos(0,0)
|
67
|
+
Curses.clear
|
68
|
+
Curses.setpos(0,0)
|
69
|
+
end until c == ?\e
|
70
|
+
|
71
|
+
@run_lock.synchronize do
|
72
|
+
@run = false
|
73
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
current_dir = File.dirname(File.expand_path(__FILE__))
|
3
|
+
lib_path = File.join(current_dir, '..', 'lib')
|
4
|
+
$LOAD_PATH.unshift lib_path
|
5
|
+
|
6
|
+
#require File.dirname(__FILE__) + '/../lib/journeta'
|
7
|
+
# require 'shoes'
|
8
|
+
|
9
|
+
Shoes.setup do
|
10
|
+
gem 'journeta'
|
11
|
+
gem 'hoe'
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
class EditorEvent
|
17
|
+
attr_accessor :diff
|
18
|
+
end
|
19
|
+
|
20
|
+
class EditorEventHandler
|
21
|
+
|
22
|
+
def call(event)
|
23
|
+
if data && data.class == EditorEvent && data.diff.class == Diff
|
24
|
+
d = event.diff
|
25
|
+
# @edit_box.text = ''
|
26
|
+
else
|
27
|
+
# ignore it
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
peer_port = (2048 + rand( 2 ** 8))
|
33
|
+
@journeta = ::Journeta::Engine.new(:peer_port => peer_port, :peer_handler => EditorEventHandler.new, :groups => ['shoes_editor'])
|
34
|
+
@journeta.start
|
35
|
+
|
36
|
+
#Shoes.app :title => 'Shoes Instant Messenger' do
|
37
|
+
#
|
38
|
+
#
|
39
|
+
# stack :margin => '20' do
|
40
|
+
#
|
41
|
+
# @edit_box = edit_box :width => '100%' do |t|
|
42
|
+
# pp t
|
43
|
+
# e = EditorEvent.new
|
44
|
+
# e.diff = t.text
|
45
|
+
## @edit_box2.text = t.text
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
#end
|
51
|
+
|
52
|
+
@journeta.stop
|
data/lib/diff.rb
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
class Diff
|
2
|
+
|
3
|
+
VERSION = 0.3
|
4
|
+
|
5
|
+
def Diff.lcs(a, b)
|
6
|
+
astart = 0
|
7
|
+
bstart = 0
|
8
|
+
afinish = a.length-1
|
9
|
+
bfinish = b.length-1
|
10
|
+
mvector = []
|
11
|
+
|
12
|
+
# First we prune off any common elements at the beginning
|
13
|
+
while (astart <= afinish && bstart <= afinish && a[astart] == b[bstart])
|
14
|
+
mvector[astart] = bstart
|
15
|
+
astart += 1
|
16
|
+
bstart += 1
|
17
|
+
end
|
18
|
+
|
19
|
+
# now the end
|
20
|
+
while (astart <= afinish && bstart <= bfinish && a[afinish] == b[bfinish])
|
21
|
+
mvector[afinish] = bfinish
|
22
|
+
afinish -= 1
|
23
|
+
bfinish -= 1
|
24
|
+
end
|
25
|
+
|
26
|
+
bmatches = b.reverse_hash(bstart..bfinish)
|
27
|
+
thresh = []
|
28
|
+
links = []
|
29
|
+
|
30
|
+
(astart..afinish).each { |aindex|
|
31
|
+
aelem = a[aindex]
|
32
|
+
next unless bmatches.has_key? aelem
|
33
|
+
k = nil
|
34
|
+
bmatches[aelem].reverse.each { |bindex|
|
35
|
+
if k && (thresh[k] > bindex) && (thresh[k-1] < bindex)
|
36
|
+
thresh[k] = bindex
|
37
|
+
else
|
38
|
+
k = thresh.replacenextlarger(bindex, k)
|
39
|
+
end
|
40
|
+
links[k] = [ (k==0) ? nil : links[k-1], aindex, bindex ] if k
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
if !thresh.empty?
|
45
|
+
link = links[thresh.length-1]
|
46
|
+
while link
|
47
|
+
mvector[link[1]] = link[2]
|
48
|
+
link = link[0]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
return mvector
|
53
|
+
end
|
54
|
+
|
55
|
+
def makediff(a, b)
|
56
|
+
mvector = Diff.lcs(a, b)
|
57
|
+
ai = bi = 0
|
58
|
+
while ai < mvector.length
|
59
|
+
bline = mvector[ai]
|
60
|
+
if bline
|
61
|
+
while bi < bline
|
62
|
+
discardb(bi, b[bi])
|
63
|
+
bi += 1
|
64
|
+
end
|
65
|
+
match(ai, bi)
|
66
|
+
bi += 1
|
67
|
+
else
|
68
|
+
discarda(ai, a[ai])
|
69
|
+
end
|
70
|
+
ai += 1
|
71
|
+
end
|
72
|
+
while ai < a.length
|
73
|
+
discarda(ai, a[ai])
|
74
|
+
ai += 1
|
75
|
+
end
|
76
|
+
while bi < b.length
|
77
|
+
discardb(bi, b[bi])
|
78
|
+
bi += 1
|
79
|
+
end
|
80
|
+
match(ai, bi)
|
81
|
+
1
|
82
|
+
end
|
83
|
+
|
84
|
+
def compactdiffs
|
85
|
+
diffs = []
|
86
|
+
@diffs.each { |df|
|
87
|
+
i = 0
|
88
|
+
curdiff = []
|
89
|
+
while i < df.length
|
90
|
+
whot = df[i][0]
|
91
|
+
s = @isstring ? df[i][2].chr : [df[i][2]]
|
92
|
+
p = df[i][1]
|
93
|
+
last = df[i][1]
|
94
|
+
i += 1
|
95
|
+
while df[i] && df[i][0] == whot && df[i][1] == last+1
|
96
|
+
s << df[i][2]
|
97
|
+
last = df[i][1]
|
98
|
+
i += 1
|
99
|
+
end
|
100
|
+
curdiff.push [whot, p, s]
|
101
|
+
end
|
102
|
+
diffs.push curdiff
|
103
|
+
}
|
104
|
+
return diffs
|
105
|
+
end
|
106
|
+
|
107
|
+
attr_reader :diffs, :difftype
|
108
|
+
|
109
|
+
def initialize(diffs_or_a, b = nil, isstring = nil)
|
110
|
+
if b.nil?
|
111
|
+
@diffs = diffs_or_a
|
112
|
+
@isstring = isstring
|
113
|
+
else
|
114
|
+
@diffs = []
|
115
|
+
@curdiffs = []
|
116
|
+
makediff(diffs_or_a, b)
|
117
|
+
@difftype = diffs_or_a.type
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def match(ai, bi)
|
122
|
+
@diffs.push @curdiffs unless @curdiffs.empty?
|
123
|
+
@curdiffs = []
|
124
|
+
end
|
125
|
+
|
126
|
+
def discarda(i, elem)
|
127
|
+
@curdiffs.push ['-', i, elem]
|
128
|
+
end
|
129
|
+
|
130
|
+
def discardb(i, elem)
|
131
|
+
@curdiffs.push ['+', i, elem]
|
132
|
+
end
|
133
|
+
|
134
|
+
def compact
|
135
|
+
return Diff.new(compactdiffs)
|
136
|
+
end
|
137
|
+
|
138
|
+
def compact!
|
139
|
+
@diffs = compactdiffs
|
140
|
+
end
|
141
|
+
|
142
|
+
def inspect
|
143
|
+
@diffs.inspect
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
module Diffable
|
149
|
+
def diff(b)
|
150
|
+
Diff.new(self, b)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Create a hash that maps elements of the array to arrays of indices
|
154
|
+
# where the elements are found.
|
155
|
+
|
156
|
+
def reverse_hash(range = (0...self.length))
|
157
|
+
revmap = {}
|
158
|
+
range.each { |i|
|
159
|
+
elem = self[i]
|
160
|
+
if revmap.has_key? elem
|
161
|
+
revmap[elem].push i
|
162
|
+
else
|
163
|
+
revmap[elem] = [i]
|
164
|
+
end
|
165
|
+
}
|
166
|
+
return revmap
|
167
|
+
end
|
168
|
+
|
169
|
+
def replacenextlarger(value, high = nil)
|
170
|
+
high ||= self.length
|
171
|
+
if self.empty? || value > self[-1]
|
172
|
+
push value
|
173
|
+
return high
|
174
|
+
end
|
175
|
+
# binary search for replacement point
|
176
|
+
low = 0
|
177
|
+
while low < high
|
178
|
+
index = (high+low)/2
|
179
|
+
found = self[index]
|
180
|
+
return nil if value == found
|
181
|
+
if value > found
|
182
|
+
low = index + 1
|
183
|
+
else
|
184
|
+
high = index
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
self[low] = value
|
189
|
+
# $stderr << "replace #{value} : 0/#{low}/#{init_high} (#{steps} steps) (#{init_high-low} off )\n"
|
190
|
+
# $stderr.puts self.inspect
|
191
|
+
#gets
|
192
|
+
#p length - low
|
193
|
+
return low
|
194
|
+
end
|
195
|
+
|
196
|
+
def patch(diff)
|
197
|
+
newary = nil
|
198
|
+
if diff.difftype == String
|
199
|
+
newary = diff.difftype.new('')
|
200
|
+
else
|
201
|
+
newary = diff.difftype.new
|
202
|
+
end
|
203
|
+
ai = 0
|
204
|
+
bi = 0
|
205
|
+
diff.diffs.each { |d|
|
206
|
+
d.each { |mod|
|
207
|
+
case mod[0]
|
208
|
+
when '-'
|
209
|
+
while ai < mod[1]
|
210
|
+
newary << self[ai]
|
211
|
+
ai += 1
|
212
|
+
bi += 1
|
213
|
+
end
|
214
|
+
ai += 1
|
215
|
+
when '+'
|
216
|
+
while bi < mod[1]
|
217
|
+
newary << self[ai]
|
218
|
+
ai += 1
|
219
|
+
bi += 1
|
220
|
+
end
|
221
|
+
newary << mod[2]
|
222
|
+
bi += 1
|
223
|
+
else
|
224
|
+
raise "Unknown diff action"
|
225
|
+
end
|
226
|
+
}
|
227
|
+
}
|
228
|
+
while ai < self.length
|
229
|
+
newary << self[ai]
|
230
|
+
ai += 1
|
231
|
+
bi += 1
|
232
|
+
end
|
233
|
+
return newary
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class Array
|
238
|
+
include Diffable
|
239
|
+
end
|
240
|
+
|
241
|
+
class String
|
242
|
+
include Diffable
|
243
|
+
end
|
244
|
+
|
245
|
+
=begin
|
246
|
+
= Diff
|
247
|
+
(({diff.rb})) - computes the differences between two arrays or
|
248
|
+
strings. Copyright (C) 2001 Lars Christensen
|
249
|
+
|
250
|
+
== Synopsis
|
251
|
+
|
252
|
+
diff = Diff.new(a, b)
|
253
|
+
b = a.patch(diff)
|
254
|
+
|
255
|
+
== Class Diff
|
256
|
+
=== Class Methods
|
257
|
+
--- Diff.new(a, b)
|
258
|
+
--- a.diff(b)
|
259
|
+
Creates a Diff object which represent the differences between
|
260
|
+
((|a|)) and ((|b|)). ((|a|)) and ((|b|)) can be either be arrays
|
261
|
+
of any objects, strings, or object of any class that include
|
262
|
+
module ((|Diffable|))
|
263
|
+
|
264
|
+
== Module Diffable
|
265
|
+
The module ((|Diffable|)) is intended to be included in any class for
|
266
|
+
which differences are to be computed. Diffable is included into String
|
267
|
+
and Array when (({diff.rb})) is (({require}))'d.
|
268
|
+
|
269
|
+
Classes including Diffable should implement (({[]})) to get element at
|
270
|
+
integer indices, (({<<})) to append elements to the object and
|
271
|
+
(({ClassName#new})) should accept 0 arguments to create a new empty
|
272
|
+
object.
|
273
|
+
|
274
|
+
=== Instance Methods
|
275
|
+
--- Diffable#patch(diff)
|
276
|
+
Applies the differences from ((|diff|)) to the object ((|obj|))
|
277
|
+
and return the result. ((|obj|)) is not changed. ((|obj|)) and
|
278
|
+
can be either an array or a string, but must match the object
|
279
|
+
from which the ((|diff|)) was created.
|
280
|
+
=end
|
data/lib/journeta.rb
CHANGED