diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/iotas/particle.rb | 16 | ||||
-rw-r--r-- | lib/iotas/room.rb | 52 |
2 files changed, 39 insertions, 29 deletions
diff --git a/lib/iotas/particle.rb b/lib/iotas/particle.rb index 295d505..79cebfb 100644 --- a/lib/iotas/particle.rb +++ b/lib/iotas/particle.rb @@ -86,9 +86,9 @@ module Iotas # # called when sent def init! src - @dst = nil @src = src @ts = Time.now + @dst = @room = @door = @action = nil end # attr_reader :ts, :src, :dst, :room, :door, :action, :link_value, :payload @@ -118,15 +118,22 @@ module Iotas end # def set_dst! a, d - @room = @door = nil @action = a - @dst = d + if d.is_a? Iotas::Iota + @dst = d + else + _split_path! d + end end # def split_dst! @dst = @room = @door = @action = nil return if (n = next_dst).nil? p, @action = n.split Iotas::ACT_SEP + _split_path! p + end + # + def _split_path! p i = p.rindex Iotas::PATH_SEP if i.nil? @room = nil @@ -137,6 +144,7 @@ module Iotas end @door = nil if @door.empty? end + private :_split_path! # def dst_routed! dst @dst = dst @@ -150,7 +158,7 @@ module Iotas end # def apply_link! lnk - @src = lnk.door + init! lnk.door clear_dsts! add_dsts lnk.dsts set_link_fields lnk.fields diff --git a/lib/iotas/room.rb b/lib/iotas/room.rb index a64d46f..7ffc5f4 100644 --- a/lib/iotas/room.rb +++ b/lib/iotas/room.rb @@ -91,7 +91,7 @@ module Iotas nil end # - def try_links p + def _try_links p puts " -> try_links ..." if @spin.debug_routing links = @links[p.src.name] return false if links.nil? @@ -113,12 +113,13 @@ module Iotas end if pending_link p.apply_link! pending_link - send_p p + _send false, p end - (not pending_link.nil?) + pending_link end + private :_try_links # - def route_p p + def _route p if p.room.nil? or p.room==path if door = @iotas[p.door] p.dst_routed! door @@ -131,45 +132,46 @@ module Iotas p.error! Iotas::ERROR_ROUTE_DNE end end + private :_route # - def send_p p - puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing - if p.src.nil? - # do not route orphan particles !! + def _send sys, p + if not sys and p.src.nil? + # do not route non system orphan particles !! p.error! Iotas::ERROR_ROUTE_NS, @spin elsif p.dst - # direct routing, nothing to do + # direct routing through pointer + return + elsif p.door + # direct routing through path + _route p elsif p.next_dst p.split_dst! if p.door - route_p p - else + _route p + elsif not sys # boomerang p.dst_routed! p.src + elsif p.action + p.dst_routed! @spin end - elsif try_links p + elsif not sys and _try_links p return else - p.error! Iotas::ERROR_ROUTE_NDNL + p.error!( sys ? Iotas::ERROR_ROUTE_SND : Iotas::ERROR_ROUTE_NDNL) end + end + private :_send + # + def send_p p + puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing + _send false, p puts " -> #{p.dst.path}#{Iotas::ACT_SEP}#{p.action}" if @spin.debug_routing @spin.post_p p end # def send_sys_p p puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing - if p.dst - # direct routing, nothing to do - elsif p.next_dst - p.split_dst! - if p.door - route_p p - elsif p.action - p.dst_routed! @spin - end - else - p.error! Iotas::ERROR_ROUTE_SND - end + _send true, p puts " -> #{p.dst.path}#{Iotas::ACT_SEP}#{p.action}" if @spin.debug_routing @spin.post_sys_p p end |