Code: don't sent tx_allocate until we're connected

So Code needs connected/lost from the RendezvousConnector
This commit is contained in:
Brian Warner 2017-02-23 17:11:54 -08:00
parent 5d6989614b
commit c95b6d402c
4 changed files with 40 additions and 26 deletions

View File

@ -2,11 +2,8 @@ digraph {
start [label="Wormhole Code\nMachine" style="dotted"]
{rank=same; start S0}
{rank=same; P0_list_nameplates P0_allocate}
{rank=same; S1 S2}
{rank=same; S3 P1_generate}
start -> S0 [style="invis"]
S0 [label="S0:\nunknown"]
S0 [label="S0:\nunknown\ndisconnected"]
S0 -> P0_got_code [label="set"]
P0_got_code [shape="box" label="B.got_code"]
P0_got_code -> S4
@ -35,11 +32,14 @@ digraph {
S3 -> P0_got_code [label="<return>"
color="orange" fontcolor="orange"]
S0 -> P0_allocate [label="allocate"]
P0_allocate [shape="box" label="RC.tx_allocate"]
P0_allocate -> S1
S1 [label="S1:\nallocating"]
S1 -> P1_generate [label="rx_allocated"]
S0 -> S1A [label="allocate"]
S1A [label="S1A:\nconnecting"]
S1A -> P1_allocate [label="connected"]
P1_allocate [shape="box" label="RC.tx_allocate"]
P1_allocate -> S1B
S1B [label="S1B:\nallocating"]
S1B -> P1_generate [label="rx_allocated"]
S1B -> S1A [label="lost"]
P1_generate [shape="box" label="generate\nrandom code"]
P1_generate -> P0_got_code

View File

@ -20,7 +20,7 @@ digraph {
Wormhole -> Boss [style="dashed" label="allocate\ninput\nset_code\nsend\nclose\n(once)"]
#Wormhole -> Boss [color="blue"]
Boss -> Wormhole [style="dashed" label="got_code\ngot_verifier\nreceived\nclosed\n(once)"]
Boss -> Wormhole [style="dashed" label="got_code\ngot_verifier\nreceived (seq)\nclosed\n(once)"]
#Boss -> Connection [color="blue"]
Boss -> Connection [style="dashed" label="start"]
@ -61,11 +61,11 @@ digraph {
]
#Boss -> Code [color="blue"]
Connection -> Code [style="dashed"
label="connected\nlost\nrx_allocated"]
Code -> Connection [style="dashed"
label="tx_allocate"
]
Connection -> Code [style="dashed"
label="rx_allocated"]
Nameplates -> Code [style="dashed"
label="got_nameplates"
]

View File

@ -25,15 +25,17 @@ class Code(object):
_timing = attrib(validator=provides(_interfaces.ITiming))
m = MethodicalMachine()
def wire(self, wormhole, rendezvous_connector, nameplate_lister):
self._W = _interfaces.IWormhole(wormhole)
def wire(self, boss, rendezvous_connector, nameplate_lister):
self._B = _interfaces.IBoss(boss)
self._RC = _interfaces.IRendezvousConnector(rendezvous_connector)
self._NL = _interfaces.INameplateLister(nameplate_lister)
@m.state(initial=True)
def S0_unknown(self): pass
@m.state()
def S1_allocating(self): pass
def S1A_connecting(self): pass
@m.state()
def S1B_allocating(self): pass
@m.state()
def S2_typing_nameplate(self): pass
@m.state()
@ -51,6 +53,10 @@ class Code(object):
# from RendezvousConnector
@m.input()
def connected(self): pass
@m.input()
def lost(self): pass
@m.input()
def rx_allocated(self, nameplate): pass
# from NameplateLister
@ -73,8 +79,10 @@ class Code(object):
self._stdio = stdio
self._NL.refresh_nameplates()
@m.output()
def RC_tx_allocate(self, code_length):
def stash_code_length(self, code_length):
self._code_length = code_length
@m.output()
def RC_tx_allocate(self):
self._RC.tx_allocate()
@m.output()
def do_completion_nameplates(self):
@ -90,22 +98,26 @@ class Code(object):
def do_completion_code(self):
pass
@m.output()
def generate_and_set(self, nameplate):
def generate_and_B_got_code(self, nameplate):
self._code = make_code(nameplate, self._code_length)
self._W_got_code()
self._B_got_code()
@m.output()
def W_got_code(self, code):
def B_got_code(self, code):
self._code = code
self._W_got_code()
self._B_got_code()
def _W_got_code(self):
self._W.got_code(self._code)
def _B_got_code(self):
self._B.got_code(self._code)
S0_unknown.upon(allocate, enter=S1_allocating, outputs=[RC_tx_allocate])
S1_allocating.upon(rx_allocated, enter=S4_known, outputs=[generate_and_set])
S0_unknown.upon(set, enter=S4_known, outputs=[B_got_code])
S0_unknown.upon(set, enter=S4_known, outputs=[W_got_code])
S0_unknown.upon(allocate, enter=S1A_connecting, outputs=[stash_code_length])
S1A_connecting.upon(connected, enter=S1B_allocating,
outputs=[RC_tx_allocate])
S1B_allocating.upon(lost, enter=S1A_connecting, outputs=[])
S1B_allocating.upon(rx_allocated, enter=S4_known,
outputs=[generate_and_B_got_code])
S0_unknown.upon(input, enter=S2_typing_nameplate,
outputs=[start_input_and_NL_refresh_nameplates])
@ -116,4 +128,4 @@ class Code(object):
S2_typing_nameplate.upon(hyphen, enter=S3_typing_code,
outputs=[lookup_wordlist])
S3_typing_code.upon(tab, enter=S3_typing_code, outputs=[do_completion_code])
S3_typing_code.upon(RETURN, enter=S4_known, outputs=[W_got_code])
S3_typing_code.upon(RETURN, enter=S4_known, outputs=[B_got_code])

View File

@ -119,6 +119,7 @@ class RendezvousConnector(object):
def ws_open(self, proto):
self._ws = proto
self._tx("bind", appid=self._appid, side=self._side)
self._C.connected()
self._M.connected()
self._NL.connected()
@ -136,6 +137,7 @@ class RendezvousConnector(object):
def ws_close(self, wasClean, code, reason):
self._ws = None
self._C.lost()
self._M.lost()
self._NL.lost()