iotas 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ 2012-05-24 Jérémy Zurcher <jeremy@asynk.ch>
2
+ * release : 0.0.3
3
+ * change routing algo, use Spin@world hash when door is not found locally
4
+
1
5
  2012-05-18 Jérémy Zurcher <jeremy@asynk.ch>
2
6
  * first release : v0.0.2
3
7
 
@@ -24,13 +24,16 @@ module Iotas
24
24
  class Iota
25
25
  #
26
26
  def initialize n, p
27
+ raise Iotas::Exception.new "Iota name #{n} is not valid" if n.include? Iotas::PATH_SEP
27
28
  @name = n # unique in it's room
28
29
  @parent = p # single direct parent
29
30
  @viewer = nil # particle going through that position will be sent there readonly
30
31
  @path = ( @parent ? @parent.path+Iotas::PATH_SEP : '') + @name
31
32
  @spin = ( @parent ? @parent.spin : self )
32
- @parent.add_iota self if @parent
33
- raise Iotas::Exception.new "Iota name #{name} is not valid" if @name.include? Iotas::PATH_SEP
33
+ if @parent
34
+ @parent.add_iota self
35
+ @spin.add_to_world self if @spin.is_a? Iotas::Spin
36
+ end
34
37
  end
35
38
  #
36
39
  attr_reader :name, :path, :spin
@@ -23,8 +23,7 @@ module Iotas
23
23
  #
24
24
  ERROR_ROUTE_NS = 'routing error: no source'.freeze
25
25
  ERROR_ROUTE_RRWD = 'routing error: right room, wrong door'.freeze
26
- ERROR_ROUTE_DDWR = 'routing error: drill down, wrong room'.freeze
27
- ERROR_ROUTE_TRWR = 'routing error: top room, wrong room'.freeze
26
+ ERROR_ROUTE_DNE = 'routing error: does not exists'.freeze
28
27
  ERROR_ROUTE_NDNL = 'routing error: no destination, no link'.freeze
29
28
  ERROR_ROUTE_SND = 'routing error: system no destination'.freeze
30
29
  #
@@ -126,17 +125,10 @@ module Iotas
126
125
  else
127
126
  p.error! Iotas::ERROR_ROUTE_RRWD
128
127
  end
129
- elsif (p.room=~/^#{path}\/(.*)/)==0
130
- room, *more = $1.split Iotas::PATH_SEP
131
- if child=@iotas[room]
132
- child.route_p p
133
- else
134
- p.error! Iotas::ERROR_ROUTE_DDWR
135
- end
136
- elsif @parent
137
- @parent.route_p p
128
+ elsif door = @spin.search_world(p.room+Iotas::PATH_SEP+p.door)
129
+ p.dst_routed! door
138
130
  else
139
- p.error! Iotas::ERROR_ROUTE_TRWR
131
+ p.error! Iotas::ERROR_ROUTE_DNE
140
132
  end
141
133
  end
142
134
  #
@@ -27,6 +27,7 @@ module Iotas
27
27
  super n, nil
28
28
  #
29
29
  @pool = {} # per particle class free list
30
+ @world = {} # global iotas index
30
31
  @sys_fifo = [] # system particles fifo list
31
32
  @app_fifo = [] # application particles fifo list
32
33
  #
@@ -70,6 +71,14 @@ module Iotas
70
71
  self.new o['name'], o
71
72
  end
72
73
  #
74
+ def add_to_world iota
75
+ @world[iota.path] = iota
76
+ end
77
+ #
78
+ def search_world path
79
+ @world[path]
80
+ end
81
+ #
73
82
  def clear!
74
83
  @iotas.clear
75
84
  @pool.clear
@@ -21,7 +21,7 @@
21
21
  #
22
22
  module Iotas
23
23
  #
24
- VERSION = "0.0.2"
24
+ VERSION = "0.0.3"
25
25
  #
26
26
  end
27
27
  #
@@ -58,6 +58,29 @@ describe Iotas::Room do
58
58
  r4.search_down('dom0/r0/r1/r2').should be nil
59
59
  end
60
60
  #
61
+ it "routing success (direct)" do
62
+ room0 = Iotas::Room.new 'room0', @spin
63
+ door0 = Iotas::Door.new 'door0', room0
64
+ p = @spin.require_p Iotas::Particle
65
+ p.src = Fake.new 'fake', @spin
66
+ p.set_dst! 'get', 'door0'
67
+ room0.send_p p
68
+ p.action.should eql 'get'
69
+ p.dst.should be door0
70
+ end
71
+ #
72
+ it "routing success through Spin@world" do
73
+ room0 = Iotas::Room.new 'room0', @spin
74
+ room1 = Iotas::Room.new 'room1', room0
75
+ door0 = Iotas::Door.new 'door0', room1
76
+ p = @spin.require_p Iotas::Particle
77
+ p.src = Fake.new 'fake', @spin
78
+ p.set_dst! 'get', 'dom0/room0/room1/door0'
79
+ room0.send_p p
80
+ p.action.should eql 'get'
81
+ p.dst.should be door0
82
+ end
83
+ #
61
84
  it "route error: no source" do
62
85
  room = Iotas::Room.new 'room', @spin
63
86
  p = @spin.require_p Iotas::Particle
@@ -78,96 +101,53 @@ describe Iotas::Room do
78
101
  p.dst.should be p.src
79
102
  end
80
103
  #
81
- it "route error: top room, wrong room" do
104
+ it "route error: no rooom, wrong door -> right room wrong door" do
82
105
  room0 = Iotas::Room.new 'room0', @spin
83
- room1 = Iotas::Room.new 'room1', room0
84
106
  p = @spin.require_p Iotas::Particle
85
107
  p.src = Fake.new 'fake', @spin
86
- p.set_dst! 'get', 'noroom/door'
87
- room1.send_p p
108
+ p.set_dst! 'get', 'nodoor'
109
+ room0.send_p p
88
110
  p.action.should eql Iotas::ACT_ERROR
89
- p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_TRWR
111
+ p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_RRWD
90
112
  p.dst.should be p.src
91
113
  end
92
114
  #
93
- it "route error: right room, wrong door" do
94
- room = Iotas::Room.new 'room', @spin
115
+ it "route error: right rooom, wrong door -> right room wrong door" do
116
+ room0 = Iotas::Room.new 'room0', @spin
95
117
  p = @spin.require_p Iotas::Particle
96
118
  p.src = Fake.new 'fake', @spin
97
- p.set_dst! 'get', 'dom0/room/nodoor'
98
- room.send_p p
119
+ p.set_dst! 'get', 'dom0/room0/nodoor'
120
+ room0.send_p p
99
121
  p.action.should eql Iotas::ACT_ERROR
100
122
  p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_RRWD
101
123
  p.dst.should be p.src
102
124
  end
103
125
  #
104
- it "route error: right room, wrong door (bubble up)" do
126
+ it "route error: right room, wrong door through Spin@world -> does not exists" do
105
127
  room0 = Iotas::Room.new 'room0', @spin
106
128
  room1 = Iotas::Room.new 'room1', room0
107
129
  p = @spin.require_p Iotas::Particle
108
- p.src = Fake.new 'fake', @spin
130
+ p.src = Fake.new 'fake', room0
109
131
  p.set_dst! 'get', 'dom0/room0/nodoor'
110
132
  room1.send_p p
111
133
  p.action.should eql Iotas::ACT_ERROR
112
- p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_RRWD
134
+ p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_DNE
113
135
  p.dst.should be p.src
114
136
  end
115
137
  #
116
- it "routing success (direct)" do
117
- room0 = Iotas::Room.new 'room0', @spin
118
- door0 = Iotas::Door.new 'door0', room0
119
- p = @spin.require_p Iotas::Particle
120
- p.src = Fake.new 'fake', @spin
121
- p.set_dst! 'get', 'door0'
122
- room0.send_p p
123
- p.action.should eql 'get'
124
- p.dst.should be door0
125
- end
126
- #
127
- it "routing success (bubble up the direct door)" do
138
+ it "route error: wrong room, right door through Spin@world -> does not exists" do
128
139
  room0 = Iotas::Room.new 'room0', @spin
129
140
  room1 = Iotas::Room.new 'room1', room0
130
- door0 = Iotas::Door.new 'door0', room0
131
141
  p = @spin.require_p Iotas::Particle
132
142
  p.src = Fake.new 'fake', @spin
133
- p.set_dst! 'get', 'dom0/room0/door0'
143
+ p.set_dst! 'get', 'dom0/noroom/fake'
134
144
  room1.send_p p
135
- p.action.should eql 'get'
136
- p.dst.should be door0
137
- end
138
- #
139
- it "route success: bubble up x2, drill down x3" do
140
- room00 = Iotas::Room.new 'room00', @spin
141
- room01 = Iotas::Room.new 'room01', room00
142
- room02 = Iotas::Room.new 'room02', room01
143
- door000 = Iotas::Door.new 'door000', room02
144
- room10 = Iotas::Room.new 'room10', @spin
145
- room11 = Iotas::Room.new 'room11', room10
146
- p = @spin.require_p Iotas::Particle
147
- p.src = Fake.new 'fake', @spin
148
- p.set_dst! 'get', 'dom0/room00/room01/room02/door000'
149
- room11.send_p p
150
- p.action.should eql 'get'
151
- p.dst.should be door000
152
- end
153
- #
154
- it "route error: bubble up x2 drill down x2" do
155
- room00 = Iotas::Room.new 'room00', @spin
156
- room01 = Iotas::Room.new 'room01', room00
157
- room02 = Iotas::Room.new 'room02', room01
158
- door000 = Iotas::Door.new 'door000', room02
159
- room10 = Iotas::Room.new 'room10', @spin
160
- room11 = Iotas::Room.new 'room11', room10
161
- p = @spin.require_p Iotas::Particle
162
- p.src = Fake.new 'fake', @spin
163
- p.set_dst! 'get', 'dom0/room00/room01/wrong/door000'
164
- room11.send_p p
165
145
  p.action.should eql Iotas::ACT_ERROR
166
- p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_DDWR
146
+ p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_DNE
167
147
  p.dst.should be p.src
168
148
  end
169
149
  #
170
- it "routing success: no door name -> src" do
150
+ it "routing ~failure: no door name -> src" do
171
151
  room0 = Iotas::Room.new 'room0', @spin
172
152
  door0 = Iotas::Door.new 'door0', room0
173
153
  p = @spin.require_p Iotas::Particle
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iotas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-18 00:00:00.000000000 Z
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json