more tests, still failing
This commit is contained in:
parent
8a2810ba70
commit
b7df5e21eb
|
@ -4,12 +4,12 @@ digraph {
|
||||||
{rank=same; start S0}
|
{rank=same; start S0}
|
||||||
start -> S0 [style="invis"]
|
start -> S0 [style="invis"]
|
||||||
S0 [label="S0:\nunknown\ndisconnected"]
|
S0 [label="S0:\nunknown\ndisconnected"]
|
||||||
S0 -> P0_got_code [label="set"]
|
S0 -> P0_got_code [label="set_code"]
|
||||||
P0_got_code [shape="box" label="B.got_code"]
|
P0_got_code [shape="box" label="B.got_code"]
|
||||||
P0_got_code -> S4
|
P0_got_code -> S4
|
||||||
S4 [label="S4: known" color="green"]
|
S4 [label="S4: known" color="green"]
|
||||||
|
|
||||||
S0 -> P0_list_nameplates [label="input"]
|
S0 -> P0_list_nameplates [label="input_code"]
|
||||||
S2 [label="S2: typing\nnameplate"]
|
S2 [label="S2: typing\nnameplate"]
|
||||||
|
|
||||||
S2 -> P2_completion [label="<tab>"]
|
S2 -> P2_completion [label="<tab>"]
|
||||||
|
@ -32,7 +32,7 @@ digraph {
|
||||||
S3 -> P0_got_code [label="<return>"
|
S3 -> P0_got_code [label="<return>"
|
||||||
color="orange" fontcolor="orange"]
|
color="orange" fontcolor="orange"]
|
||||||
|
|
||||||
S0 -> S1A [label="allocate"]
|
S0 -> S1A [label="allocate_code"]
|
||||||
S1A [label="S1A:\nconnecting"]
|
S1A [label="S1A:\nconnecting"]
|
||||||
S1A -> P1_allocate [label="connected"]
|
S1A -> P1_allocate [label="connected"]
|
||||||
P1_allocate [shape="box" label="RC.tx_allocate"]
|
P1_allocate [shape="box" label="RC.tx_allocate"]
|
||||||
|
|
|
@ -18,7 +18,7 @@ digraph {
|
||||||
Connection -> websocket [color="blue"]
|
Connection -> websocket [color="blue"]
|
||||||
#Connection -> Order [color="blue"]
|
#Connection -> Order [color="blue"]
|
||||||
|
|
||||||
Wormhole -> Boss [style="dashed" label="allocate\ninput\nset_code\nsend\nclose\n(once)"]
|
Wormhole -> Boss [style="dashed" label="allocate_code\ninput_code\nset_code\nsend\nclose\n(once)"]
|
||||||
#Wormhole -> Boss [color="blue"]
|
#Wormhole -> Boss [color="blue"]
|
||||||
Boss -> Wormhole [style="dashed" label="got_code\ngot_verifier\nreceived (seq)\nclosed\n(once)"]
|
Boss -> Wormhole [style="dashed" label="got_code\ngot_verifier\nreceived (seq)\nclosed\n(once)"]
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ digraph {
|
||||||
label="refresh_nameplates"
|
label="refresh_nameplates"
|
||||||
]
|
]
|
||||||
Boss -> Code [style="dashed"
|
Boss -> Code [style="dashed"
|
||||||
label="allocate\ninput\nset_code"]
|
label="allocate_code\ninput_code\nset_code_code"]
|
||||||
Code -> Boss [style="dashed"
|
Code -> Boss [style="dashed"
|
||||||
label="got_code"]
|
label="got_code"]
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,10 @@ class Boss(object):
|
||||||
# would require the Wormhole to be aware of Code (whereas right now
|
# would require the Wormhole to be aware of Code (whereas right now
|
||||||
# Wormhole only knows about this Boss instance, and everything else is
|
# Wormhole only knows about this Boss instance, and everything else is
|
||||||
# hidden away).
|
# hidden away).
|
||||||
def input(self, stdio):
|
def input_code(self, stdio):
|
||||||
self._C.input(stdio)
|
self._C.input_code(stdio)
|
||||||
def allocate(self, code_length):
|
def allocate_code(self, code_length):
|
||||||
self._C.allocate(code_length)
|
self._C.allocate_code(code_length)
|
||||||
def set_code(self, code):
|
def set_code(self, code):
|
||||||
self._C.set_code(code)
|
self._C.set_code(code)
|
||||||
|
|
||||||
|
@ -165,8 +165,7 @@ class Boss(object):
|
||||||
# we call Wormhole.received() in strict phase order, with no gaps
|
# we call Wormhole.received() in strict phase order, with no gaps
|
||||||
self._rx_phases[phase] = plaintext
|
self._rx_phases[phase] = plaintext
|
||||||
while self._next_rx_phase in self._rx_phases:
|
while self._next_rx_phase in self._rx_phases:
|
||||||
self._W.received(self._next_rx_phase,
|
self._W.received(self._rx_phases.pop(self._next_rx_phase))
|
||||||
self._rx_phases.pop(self._next_rx_phase))
|
|
||||||
self._next_rx_phase += 1
|
self._next_rx_phase += 1
|
||||||
|
|
||||||
@m.output()
|
@m.output()
|
||||||
|
|
|
@ -46,11 +46,11 @@ class Code(object):
|
||||||
|
|
||||||
# from App
|
# from App
|
||||||
@m.input()
|
@m.input()
|
||||||
def allocate(self, code_length): pass
|
def allocate_code(self, code_length): pass
|
||||||
@m.input()
|
@m.input()
|
||||||
def input(self, stdio): pass
|
def input_code(self, stdio): pass
|
||||||
@m.input()
|
@m.input()
|
||||||
def set(self, code): pass
|
def set_code(self, code): pass
|
||||||
|
|
||||||
# from RendezvousConnector
|
# from RendezvousConnector
|
||||||
@m.input()
|
@m.input()
|
||||||
|
@ -111,16 +111,17 @@ class Code(object):
|
||||||
def _B_got_code(self):
|
def _B_got_code(self):
|
||||||
self._B.got_code(self._code)
|
self._B.got_code(self._code)
|
||||||
|
|
||||||
S0_unknown.upon(set, enter=S4_known, outputs=[B_got_code])
|
S0_unknown.upon(set_code, enter=S4_known, outputs=[B_got_code])
|
||||||
|
|
||||||
S0_unknown.upon(allocate, enter=S1A_connecting, outputs=[stash_code_length])
|
S0_unknown.upon(allocate_code, enter=S1A_connecting,
|
||||||
|
outputs=[stash_code_length])
|
||||||
S1A_connecting.upon(connected, enter=S1B_allocating,
|
S1A_connecting.upon(connected, enter=S1B_allocating,
|
||||||
outputs=[RC_tx_allocate])
|
outputs=[RC_tx_allocate])
|
||||||
S1B_allocating.upon(lost, enter=S1A_connecting, outputs=[])
|
S1B_allocating.upon(lost, enter=S1A_connecting, outputs=[])
|
||||||
S1B_allocating.upon(rx_allocated, enter=S4_known,
|
S1B_allocating.upon(rx_allocated, enter=S4_known,
|
||||||
outputs=[generate_and_B_got_code])
|
outputs=[generate_and_B_got_code])
|
||||||
|
|
||||||
S0_unknown.upon(input, enter=S2_typing_nameplate,
|
S0_unknown.upon(input_code, enter=S2_typing_nameplate,
|
||||||
outputs=[start_input_and_NL_refresh_nameplates])
|
outputs=[start_input_and_NL_refresh_nameplates])
|
||||||
S2_typing_nameplate.upon(tab, enter=S2_typing_nameplate,
|
S2_typing_nameplate.upon(tab, enter=S2_typing_nameplate,
|
||||||
outputs=[do_completion_nameplates])
|
outputs=[do_completion_nameplates])
|
||||||
|
|
|
@ -23,15 +23,36 @@ class Delegate:
|
||||||
self.closed = result
|
self.closed = result
|
||||||
|
|
||||||
class New(ServerBase, unittest.TestCase):
|
class New(ServerBase, unittest.TestCase):
|
||||||
def test_basic(self):
|
@inlineCallbacks
|
||||||
|
def test_allocate(self):
|
||||||
|
w = wormhole.deferred_wormhole(APPID, self.relayurl, reactor)
|
||||||
|
w.allocate_code(2)
|
||||||
|
code = yield w.when_code()
|
||||||
|
print("code:", code)
|
||||||
|
yield w.close()
|
||||||
|
test_allocate.timeout = 2
|
||||||
|
|
||||||
|
def test_delegated(self):
|
||||||
dg = Delegate()
|
dg = Delegate()
|
||||||
w = wormhole.delegated_wormhole(APPID, self.relayurl, reactor, dg)
|
w = wormhole.delegated_wormhole(APPID, self.relayurl, reactor, dg)
|
||||||
w.close()
|
w.close()
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def test_allocate(self):
|
def test_basic(self):
|
||||||
w = wormhole.deferred_wormhole(APPID, self.relayurl, reactor)
|
w1 = wormhole.deferred_wormhole(APPID, self.relayurl, reactor)
|
||||||
code = yield w.when_code()
|
w1.allocate_code(2)
|
||||||
|
code = yield w1.when_code()
|
||||||
print("code:", code)
|
print("code:", code)
|
||||||
yield w.close()
|
w2 = wormhole.deferred_wormhole(APPID, self.relayurl, reactor)
|
||||||
test_allocate.timeout = 2
|
w2.set_code(code)
|
||||||
|
code2 = yield w2.when_code()
|
||||||
|
self.assertEqual(code, code2)
|
||||||
|
|
||||||
|
w1.send(b"data")
|
||||||
|
|
||||||
|
data = yield w2.when_received()
|
||||||
|
self.assertEqual(data, b"data")
|
||||||
|
|
||||||
|
yield w1.close()
|
||||||
|
yield w2.close()
|
||||||
|
test_basic.timeout = 2
|
||||||
|
|
|
@ -38,6 +38,14 @@ class _DelegatedWormhole(object):
|
||||||
self._boss = boss
|
self._boss = boss
|
||||||
|
|
||||||
# from above
|
# from above
|
||||||
|
|
||||||
|
def allocate_code(self, code_length=2):
|
||||||
|
self._boss.allocate_code(code_length)
|
||||||
|
def input_code(self, stdio):
|
||||||
|
self._boss.input_code(stdio)
|
||||||
|
def set_code(self, code):
|
||||||
|
self._boss.set_code(code)
|
||||||
|
|
||||||
def send(self, plaintext):
|
def send(self, plaintext):
|
||||||
self._boss.send(plaintext)
|
self._boss.send(plaintext)
|
||||||
def close(self):
|
def close(self):
|
||||||
|
@ -48,9 +56,8 @@ class _DelegatedWormhole(object):
|
||||||
self._delegate.wormhole_got_code(code)
|
self._delegate.wormhole_got_code(code)
|
||||||
def got_verifier(self, verifier):
|
def got_verifier(self, verifier):
|
||||||
self._delegate.wormhole_got_verifier(verifier)
|
self._delegate.wormhole_got_verifier(verifier)
|
||||||
def received(self, phase, plaintext):
|
def received(self, plaintext):
|
||||||
# TODO: deliver phases in order
|
self._delegate.wormhole_received(plaintext)
|
||||||
self._delegate.wormhole_received(phase, plaintext)
|
|
||||||
def closed(self, result):
|
def closed(self, result):
|
||||||
self._delegate.wormhole_closed(result)
|
self._delegate.wormhole_closed(result)
|
||||||
|
|
||||||
|
@ -61,6 +68,8 @@ class _DeferredWormhole(object):
|
||||||
self._code_observers = []
|
self._code_observers = []
|
||||||
self._verifier = None
|
self._verifier = None
|
||||||
self._verifier_observers = []
|
self._verifier_observers = []
|
||||||
|
self._received_data = []
|
||||||
|
self._received_observers = []
|
||||||
|
|
||||||
def _set_boss(self, boss):
|
def _set_boss(self, boss):
|
||||||
self._boss = boss
|
self._boss = boss
|
||||||
|
@ -80,6 +89,20 @@ class _DeferredWormhole(object):
|
||||||
self._verifier_observers.append(d)
|
self._verifier_observers.append(d)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def when_received(self):
|
||||||
|
if self._received_data:
|
||||||
|
return defer.succeed(self._received_data.pop(0))
|
||||||
|
d = defer.Deferred()
|
||||||
|
self._received_observers.append(d)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def allocate_code(self, code_length=2):
|
||||||
|
self._boss.allocate_code(code_length)
|
||||||
|
def input_code(self, stdio):
|
||||||
|
self._boss.input_code(stdio)
|
||||||
|
def set_code(self, code):
|
||||||
|
self._boss.set_code(code)
|
||||||
|
|
||||||
def send(self, plaintext):
|
def send(self, plaintext):
|
||||||
self._boss.send(plaintext)
|
self._boss.send(plaintext)
|
||||||
def close(self):
|
def close(self):
|
||||||
|
@ -97,8 +120,11 @@ class _DeferredWormhole(object):
|
||||||
d.callback(verifier)
|
d.callback(verifier)
|
||||||
self._verifier_observers[:] = []
|
self._verifier_observers[:] = []
|
||||||
|
|
||||||
def received(self, phase, plaintext):
|
def received(self, plaintext):
|
||||||
print(phase, plaintext)
|
if self._received_observers:
|
||||||
|
self._received_observers.pop(0).callback(plaintext)
|
||||||
|
return
|
||||||
|
self._received_data.append(plaintext)
|
||||||
|
|
||||||
def closed(self, result):
|
def closed(self, result):
|
||||||
print("closed", result)
|
print("closed", result)
|
||||||
|
@ -109,7 +135,6 @@ def _wormhole(appid, relay_url, reactor, delegate=None,
|
||||||
stderr=sys.stderr,
|
stderr=sys.stderr,
|
||||||
):
|
):
|
||||||
timing = timing or DebugTiming()
|
timing = timing or DebugTiming()
|
||||||
code_length = 2
|
|
||||||
side = bytes_to_hexstr(os.urandom(5))
|
side = bytes_to_hexstr(os.urandom(5))
|
||||||
journal = journal or ImmediateJournal()
|
journal = journal or ImmediateJournal()
|
||||||
if delegate:
|
if delegate:
|
||||||
|
@ -120,7 +145,6 @@ def _wormhole(appid, relay_url, reactor, delegate=None,
|
||||||
w._set_boss(b)
|
w._set_boss(b)
|
||||||
# force allocate for now
|
# force allocate for now
|
||||||
b.start()
|
b.start()
|
||||||
b.allocate(code_length)
|
|
||||||
return w
|
return w
|
||||||
|
|
||||||
def delegated_wormhole(appid, relay_url, reactor, delegate,
|
def delegated_wormhole(appid, relay_url, reactor, delegate,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user