make cmd_send/cmd_receive basically work again

This commit is contained in:
Brian Warner 2017-03-04 11:44:40 +01:00
parent e9f3107127
commit 8ee342ad82
2 changed files with 21 additions and 5 deletions

View File

@ -76,18 +76,23 @@ class TwistedReceiver:
# as coming from the "yield self._go" line, which wasn't very useful
# for tracking it down.
d = self._go(w)
d.addBoth(w.close)
@inlineCallbacks
def _close(res):
yield w.close()
returnValue(res)
d.addBoth(_close)
yield d
@inlineCallbacks
def _go(self, w):
yield self._handle_code(w)
verifier = yield w.when_verifier()
def on_slow_connection():
print(u"Key established, waiting for confirmation...",
file=self.args.stderr)
notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection)
try:
verifier = yield w.when_verifier()
yield w.when_version()
finally:
if not notify.called:
notify.cancel()
@ -143,8 +148,10 @@ class TwistedReceiver:
if code:
w.set_code(code)
else:
raise NotImplemented
yield w.input_code("Enter receive wormhole code: ", # TODO
self.args.code_length)
yield w.when_code()
def _show_verifier(self, verifier):
verifier_hex = bytes_to_hexstr(verifier)

View File

@ -57,7 +57,11 @@ class Sender:
tor_manager=self._tor_manager,
timing=self._timing)
d = self._go(w)
d.addBoth(w.close) # must wait for ack from close()
@inlineCallbacks
def _close(res):
yield w.close() # must wait for ack from close()
returnValue(res)
d.addBoth(_close)
yield d
def _send_data(self, data, w):
@ -94,15 +98,20 @@ class Sender:
args.stderr.flush()
print(u"", file=args.stderr)
verifier_bytes = yield w.when_verifier()
# we've seen PAKE, but not yet VERSION, so we don't know if they got
# the right password or not
def on_slow_connection():
print(u"Key established, waiting for confirmation...",
file=args.stderr)
notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection)
# TODO: maybe don't stall on verifier unless they want it
# TODO: maybe don't stall for VERSION, if they don't want
# verification, to save a roundtrip?
try:
yield w.when_version()
# this may raise WrongPasswordError
verifier_bytes = yield w.when_verifier()
finally:
if not notify.called:
notify.cancel()