From 20814a65f419a117e0b845e543044443c95c7a0f Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 22 Feb 2017 13:45:18 -0800 Subject: [PATCH] rename Wormhole (machine) to Boss, leave room for higher-level thing --- docs/{wormhole.dot => boss.dot} | 2 +- docs/code.dot | 2 +- docs/machines.dot | 34 ++++++++++++------------- docs/mailbox_close.dot | 4 ++- docs/receive.dot | 6 ++--- src/wormhole/{_wormhole.py => _boss.py} | 4 +-- src/wormhole/_interfaces.py | 2 +- src/wormhole/_key.py | 16 +++++++----- src/wormhole/_mailbox.py | 8 +++--- src/wormhole/_receive.py | 18 +++++++------ src/wormhole/_rendezvous.py | 8 +++--- src/wormhole/_send.py | 2 ++ 12 files changed, 57 insertions(+), 49 deletions(-) rename docs/{wormhole.dot => boss.dot} (97%) rename src/wormhole/{_wormhole.py => _boss.py} (98%) diff --git a/docs/wormhole.dot b/docs/boss.dot similarity index 97% rename from docs/wormhole.dot rename to docs/boss.dot index 2ce81a3..b2a40f5 100644 --- a/docs/wormhole.dot +++ b/docs/boss.dot @@ -8,7 +8,7 @@ digraph { compute the key, send VERSION. Starting from the Return, this saves two round trips. OTOH it adds consequences to hitting Tab. */ - start [label="Wormhole\nMachine" style="dotted"] + start [label="Boss\n(manager)" style="dotted"] {rank=same; P0_code S0} P0_code [shape="box" style="dashed" diff --git a/docs/code.dot b/docs/code.dot index c5ada30..5f63fc1 100644 --- a/docs/code.dot +++ b/docs/code.dot @@ -8,7 +8,7 @@ digraph { start -> S0 [style="invis"] S0 [label="S0:\nunknown"] S0 -> P0_set_code [label="set"] - P0_set_code [shape="box" label="W.set_code"] + P0_set_code [shape="box" label="B.set_code"] P0_set_code -> S4 S4 [label="S4: known" color="green"] diff --git a/docs/machines.dot b/docs/machines.dot index 7be9edc..9d22173 100644 --- a/docs/machines.dot +++ b/docs/machines.dot @@ -1,6 +1,6 @@ digraph { App [shape="box" color="blue" fontcolor="blue"] - Wormhole [shape="box" label="Wormhole\n(manager)" + Boss [shape="box" label="Boss\n(manager)" color="blue" fontcolor="blue"] Mailbox [shape="box" color="blue" fontcolor="blue"] Connection [label="Rendezvous\nConnector" @@ -18,33 +18,33 @@ digraph { Connection -> websocket [color="blue"] #Connection -> Order [color="blue"] - App -> Wormhole [style="dashed" label="start\nset_code\nsend\nclose\n(once)"] - #App -> Wormhole [color="blue"] - Wormhole -> App [style="dashed" label="got_verifier\nreceived\nclosed\n(once)"] + App -> Boss [style="dashed" label="start\nset_code\nsend\nclose\n(once)"] + #App -> Boss [color="blue"] + Boss -> App [style="dashed" label="got_verifier\nreceived\nclosed\n(once)"] - #Wormhole -> Connection [color="blue"] - Wormhole -> Connection [style="dashed" label="start"] - Connection -> Wormhole [style="dashed" label="rx_welcome"] + #Boss -> Connection [color="blue"] + Boss -> Connection [style="dashed" label="start"] + Connection -> Boss [style="dashed" label="rx_welcome"] - Wormhole -> Send [style="dashed" label="send"] + Boss -> Send [style="dashed" label="send"] - Wormhole -> Mailbox [style="dashed" + Boss -> Mailbox [style="dashed" label="set_nameplate\nclose\n(once)" ] - #Wormhole -> Mailbox [color="blue"] - Mailbox -> Wormhole [style="dashed" label="closed\n(once)"] + #Boss -> Mailbox [color="blue"] + Mailbox -> Boss [style="dashed" label="closed\n(once)"] Mailbox -> Order [style="dashed" label="got_message (once)"] - Wormhole -> Key [style="dashed" label="set_code"] - Key -> Wormhole [style="dashed" label="got_verifier\nscared"] + Boss -> Key [style="dashed" label="set_code"] + Key -> Boss [style="dashed" label="got_verifier\nscared"] Order -> Key [style="dashed" label="got_pake"] Order -> Receive [style="dashed" label="got_message"] - #Wormhole -> Key [color="blue"] + #Boss -> Key [color="blue"] Key -> Mailbox [style="dashed" label="add_message (pake)\nadd_message (version)"] Receive -> Send [style="dashed" label="got_verified_key"] Send -> Mailbox [style="dashed" label="add_message (phase)"] Key -> Receive [style="dashed" label="got_key"] - Receive -> Wormhole [style="dashed" + Receive -> Boss [style="dashed" label="happy\nscared\ngot_message"] Mailbox -> Connection [style="dashed" @@ -60,7 +60,7 @@ digraph { label="tx_list" ] - #Wormhole -> Code [color="blue"] + #Boss -> Code [color="blue"] Code -> Connection [style="dashed" label="tx_allocate" ] @@ -73,7 +73,7 @@ digraph { Code -> Nameplates [style="dashed" label="refresh_nameplates" ] - Code -> Wormhole [style="dashed" + Code -> Boss [style="dashed" label="set_code"] App -> Code [style="dashed" label="allocate\ninput\nset"] diff --git a/docs/mailbox_close.dot b/docs/mailbox_close.dot index 7e521a1..6765d84 100644 --- a/docs/mailbox_close.dot +++ b/docs/mailbox_close.dot @@ -36,8 +36,10 @@ digraph { P_stop [shape="box" label="C.stop"] P_stop -> SsB - SsB -> Ss [label="stopped"] SsB [label="SsB: closed\nstopping"] + SsB -> Pss [label="stopped"] + Pss [shape="box" label="B.closed"] + Pss -> Ss Ss [label="Ss: closed" color="green"] diff --git a/docs/receive.dot b/docs/receive.dot index 3761350..3fe136d 100644 --- a/docs/receive.dot +++ b/docs/receive.dot @@ -19,7 +19,7 @@ digraph { S1 [label="S1:\nunverified key" color="orange"] S1 -> P_mood_scary [label="got_message\n(bad)"] S1 -> P1_accept_msg [label="got_message\n(good)" color="orange"] - P1_accept_msg [shape="box" label="S.got_verified_key\nW.happy\nW.got_message" + P1_accept_msg [shape="box" label="S.got_verified_key\nB.happy\nB.got_message" color="orange"] P1_accept_msg -> S2 [color="orange"] @@ -28,10 +28,10 @@ digraph { S2 -> P2_accept_msg [label="got_message\n(good)" color="orange"] S2 -> P_mood_scary [label="got_message(bad)"] - P2_accept_msg [label="W.got_message" shape="box" color="orange"] + P2_accept_msg [label="B.got_message" shape="box" color="orange"] P2_accept_msg -> S2 [color="orange"] - P_mood_scary [shape="box" label="W.scared" color="red"] + P_mood_scary [shape="box" label="B.scared" color="red"] P_mood_scary -> S3 [color="red"] S3 [label="S3:\nscared" color="red"] diff --git a/src/wormhole/_wormhole.py b/src/wormhole/_boss.py similarity index 98% rename from src/wormhole/_wormhole.py rename to src/wormhole/_boss.py index 11a250f..db5ead0 100644 --- a/src/wormhole/_wormhole.py +++ b/src/wormhole/_boss.py @@ -11,8 +11,8 @@ from ._nameplate import NameplateListing from ._code import Code from .util import bytes_to_dict -@implementer(_interfaces.IWormhole) -class Wormhole: +@implementer(_interfaces.IBoss) +class Boss: m = MethodicalMachine() def __init__(self, side, reactor, timing): diff --git a/src/wormhole/_interfaces.py b/src/wormhole/_interfaces.py index 67bec5e..b8abf49 100644 --- a/src/wormhole/_interfaces.py +++ b/src/wormhole/_interfaces.py @@ -1,6 +1,6 @@ from zope.interface import Interface -class IWormhole(Interface): +class IBoss(Interface): pass class IMailbox(Interface): pass diff --git a/src/wormhole/_key.py b/src/wormhole/_key.py index aa0863c..760d679 100644 --- a/src/wormhole/_key.py +++ b/src/wormhole/_key.py @@ -53,8 +53,8 @@ class Key(object): m = MethodicalMachine() def __init__(self, timing): self._timing = timing - def wire(self, wormhole, mailbox, receive): - self._W = _interfaces.IWormhole(wormhole) + def wire(self, boss, mailbox, receive): + self._B = _interfaces.IBoss(boss) self._M = _interfaces.IMailbox(mailbox) self._R = _interfaces.IReceive(receive) @@ -67,6 +67,11 @@ class Key(object): @m.state(terminal=True) def S3_scared(self): pass + # from Boss + @m.input() + def set_code(self, code): pass + + # from Ordering def got_pake(self, body): assert isinstance(body, type(b"")), type(body) payload = bytes_to_dict(body) @@ -74,9 +79,6 @@ class Key(object): self.got_pake_good(hexstr_to_bytes(payload["pake_v1"])) else: self.got_pake_bad() - - @m.input() - def set_code(self, code): pass @m.input() def got_pake_good(self, msg2): pass @m.input() @@ -93,7 +95,7 @@ class Key(object): @m.output() def scared(self): - self._W.scared() + self._B.scared() @m.output() def compute_key(self, msg2): assert isinstance(msg2, type(b"")) @@ -101,7 +103,7 @@ class Key(object): key = self._sp.finish(msg2) self._my_versions = {} self._M.add_message("version", self._my_versions) - self._W.got_verifier(derive_key(key, b"wormhole:verifier")) + self._B.got_verifier(derive_key(key, b"wormhole:verifier")) self._R.got_key(key) S0_know_nothing.upon(set_code, enter=S1_know_code, outputs=[build_pake]) diff --git a/src/wormhole/_mailbox.py b/src/wormhole/_mailbox.py index 51c58cb..93b5ba5 100644 --- a/src/wormhole/_mailbox.py +++ b/src/wormhole/_mailbox.py @@ -14,8 +14,8 @@ class Mailbox(object): self._pending_outbound = {} self._processed = set() - def wire(self, wormhole, rendezvous_connector, ordering): - self._W = _interfaces.IWormhole(wormhole) + def wire(self, boss, rendezvous_connector, ordering): + self._B = _interfaces.IBoss(boss) self._RC = _interfaces.IRendezvousConnector(rendezvous_connector) self._O = _interfaces.IOrder(ordering) @@ -89,7 +89,7 @@ class Mailbox(object): @m.input() def start_connected(self): pass - # from Wormhole + # from Boss @m.input() def set_nameplate(self, nameplate): pass @m.input() @@ -210,7 +210,7 @@ class Mailbox(object): self._RC_stop() @m.output() def W_closed(self): - self._W.closed() + self._B.closed() initial.upon(start_unconnected, enter=S0A, outputs=[]) initial.upon(start_connected, enter=S0B, outputs=[]) diff --git a/src/wormhole/_receive.py b/src/wormhole/_receive.py index b15cbf2..5d9e803 100644 --- a/src/wormhole/_receive.py +++ b/src/wormhole/_receive.py @@ -10,8 +10,8 @@ class Receive(object): self._side = side self._timing = timing self._key = None - def wire(self, wormhole, key, send): - self._W = _interfaces.IWormhole(wormhole) + def wire(self, boss, key, send): + self._B = _interfaces.IBoss(boss) self._K = _interfaces.IKey(key) self._S = _interfaces.ISend(send) @@ -24,6 +24,7 @@ class Receive(object): @m.state(terminal=True) def S3_scared(self): pass + # from Ordering def got_message(self, phase, body): assert isinstance(phase, type("")), type(phase) assert isinstance(body, type(b"")), type(body) @@ -35,14 +36,15 @@ class Receive(object): self.got_message_bad() return self.got_message_good(phase, plaintext) - - @m.input() - def got_key(self, key): pass @m.input() def got_message_good(self, phase, plaintext): pass @m.input() def got_message_bad(self): pass + # from Key + @m.input() + def got_key(self, key): pass + @m.output() def record_key(self, key): self._key = key @@ -52,15 +54,15 @@ class Receive(object): self._S.got_verified_key(self._key) @m.output() def W_happy(self, phase, plaintext): - self._W.happy() + self._B.happy() @m.output() def W_got_message(self, phase, plaintext): assert isinstance(phase, type("")), type(phase) assert isinstance(plaintext, type(b"")), type(plaintext) - self._W.got_message(phase, plaintext) + self._B.got_message(phase, plaintext) @m.output() def W_scared(self): - self._W.scared() + self._B.scared() S0_unknown_key.upon(got_key, enter=S1_unverified_key, outputs=[record_key]) S1_unverified_key.upon(got_message_good, enter=S2_verified_key, diff --git a/src/wormhole/_rendezvous.py b/src/wormhole/_rendezvous.py index 8eb52d4..fac6fe9 100644 --- a/src/wormhole/_rendezvous.py +++ b/src/wormhole/_rendezvous.py @@ -73,13 +73,13 @@ class RendezvousConnector(object): # TODO: Tor goes here return endpoints.HostnameEndpoint(self._reactor, hostname, port) - def wire(self, wormhole, mailbox, code, nameplate_lister): - self._W = _interfaces.IWormhole(wormhole) + def wire(self, boss, mailbox, code, nameplate_lister): + self._B = _interfaces.IBoss(boss) self._M = _interfaces.IMailbox(mailbox) self._C = _interfaces.ICode(code) self._NL = _interfaces.INameplateLister(nameplate_lister) - # from Wormhole + # from Boss def start(self): self._connector.startService() @@ -176,7 +176,7 @@ class RendezvousConnector(object): pass def _response_handle_welcome(self, msg): - self._W.rx_welcome(msg["welcome"]) + self._B.rx_welcome(msg["welcome"]) def _response_handle_claimed(self, msg): mailbox = msg["mailbox"] diff --git a/src/wormhole/_send.py b/src/wormhole/_send.py index b717d14..3d6b1e1 100644 --- a/src/wormhole/_send.py +++ b/src/wormhole/_send.py @@ -17,8 +17,10 @@ class Send(object): @m.state(terminal=True) def S1_verified_key(self): pass + # from Receive @m.input() def got_verified_key(self, key): pass + # from Boss @m.input() def send(self, phase, plaintext): pass