Permalink
Browse files

[delivery] Delivery protocol and implementations

Summary:
The delivery modules from the old sandbox.
  • Loading branch information...
1 parent 8975b71 commit aa6f4cf9af1cdcdbd3fa8a4d6137cdcc95897567 @seshness seshness committed Dec 12, 2011
View
56 new_sandbox/delivery/dastardly.rb
@@ -0,0 +1,56 @@
+require 'delivery/delivery'
+
+#randomly reorders messages, but reports success upon first send
+#may delay messages up until max_delay timesteps if no other messages are sent
+
+module DastardlyDeliveryControl
+ state do
+ interface input, :set_max_delay, [] => [:delay]
+ end
+end
+
+module DastardlyDelivery
+ include DeliveryProtocol
+ include DastardlyDeliveryControl
+
+ state do
+ table :max_delay, [] => [:delay]
+ table :buf, [:msg, :whenbuf]
+
+ channel :pipe_chan, [:@dst, :src, :ident] => [:payload]
+
+ periodic :clock, 1
+ end
+
+ bootstrap do
+ max_delay <= [[5]]
+ end
+
+ bloom :control do
+ max_delay <+- set_max_delay
+ end
+
+ bloom :queue do
+ buf <+ pipe_in { |m| [m, @budtime] }
+ end
+
+ bloom :done do
+ # Report success immediately
+ pipe_sent <= pipe_in
+ end
+
+ bloom :snd do
+ temp :do_send <= (buf.argagg(:choose_rand, [], :whenbuf)*max_delay).pairs do |b,d|
+ if (buf.length != 1) || (@budtime - b.whenbuf >= d.delay)
+ b
+ end
+ end
+
+ buf <- do_send
+ pipe_chan <~ do_send { |s| s.msg }
+ end
+
+ bloom :rcv do
+ pipe_out <= pipe_chan
+ end
+end
View
36 new_sandbox/delivery/delivery.rb
@@ -0,0 +1,36 @@
+module DeliveryProtocol
+ state do
+ # At the sender side, used to request that a new message be delivered. The
+ # recipient address is given by the "dst" field.
+ interface input, :pipe_in, [:dst, :src, :ident] => [:payload]
+
+ # At the sender side, the transport protocol will insert a corresponding
+ # "pipe_sent" fact when a message has been delivered.
+ interface output, :pipe_sent, [:dst, :src, :ident] => [:payload]
+
+ # At the recipient side, this indicates that a new message has been delivered.
+ interface output, :pipe_out, [:dst, :src, :ident] => [:payload]
+ end
+end
+
+module BestEffortDelivery
+ include DeliveryProtocol
+
+ state do
+ channel :pipe_chan, [:@dst, :src, :ident] => [:payload]
+ end
+
+ bloom :snd do
+ pipe_chan <~ pipe_in
+ end
+
+ bloom :rcv do
+ pipe_out <= pipe_chan
+ end
+
+ bloom :done do
+ # Report success immediately -- this implementation of "best effort" is more
+ # like "an effort".
+ pipe_sent <= pipe_in
+ end
+end
View
44 new_sandbox/delivery/demonic.rb
@@ -0,0 +1,44 @@
+require 'delivery/delivery'
+
+#intentionally drops messages, but reports success
+
+module DemonicDeliveryControl
+ state do
+ #percentage chance of message loss, 0 to 100
+ interface input, :set_drop_pct, [] => [:pct]
+ end
+end
+
+module DemonicDelivery
+ include DeliveryProtocol
+ include DemonicDeliveryControl
+
+ state do
+ table :drop_pct, [] => [:pct]
+ channel :pipe_chan, [:@dst, :src, :ident] => [:payload]
+ end
+
+ bootstrap do
+ drop_pct <= [[50]]
+ end
+
+ bloom :control do
+ drop_pct <+- set_drop_pct
+ end
+
+ bloom :snd do
+ pipe_chan <~ (pipe_in * drop_pct).pairs do |i, p|
+ if p.pct <= rand(100)
+ i
+ end
+ end
+ end
+
+ bloom :rcv do
+ pipe_out <= pipe_chan
+ end
+
+ bloom :done do
+ pipe_sent <= pipe_in
+ end
+end
View
32 new_sandbox/delivery/reliable.rb
@@ -0,0 +1,32 @@
+require 'delivery/delivery'
+
+# Note that this provides at-least-once delivery. If you need exactly-once, the
+# receiver-side can record the message IDs that have been received to avoid
+# processing duplicate messages.
+module ReliableDelivery
+ include DeliveryProtocol
+ import BestEffortDelivery => :bed
+
+ state do
+ table :buf, pipe_in.schema
+ channel :ack, [:@src, :dst, :ident]
+ periodic :clock, 2
+ end
+
+ bloom :remember do
+ buf <= pipe_in
+ bed.pipe_in <= pipe_in
+ bed.pipe_in <= (buf * clock).lefts
+ end
+
+ bloom :rcv do
+ pipe_out <= bed.pipe_out
+ ack <~ bed.pipe_out {|p| [p.src, p.dst, p.ident]}
+ end
+
+ bloom :done do
+ temp :msg_acked <= (buf * ack).lefts(:ident => :ident)
+ pipe_sent <= msg_acked
+ buf <- msg_acked
+ end
+end

0 comments on commit aa6f4cf

Please sign in to comment.