From 01318d113085fa811edb51e6f126a73cd32cf1ef Mon Sep 17 00:00:00 2001 From: laharah Date: Sun, 5 Jun 2016 03:10:32 -0700 Subject: [PATCH] added notification to cmd_receive plus reactor cleanup Added a try finally block around verify to ensure notification deferreds are being cleaned out of the reactor --- src/wormhole/cli/cmd_receive.py | 11 ++++++++++- src/wormhole/cli/cmd_send.py | 15 +++++++++++---- src/wormhole/wormhole.py | 3 +-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index e458de3..07adb48 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -75,7 +75,16 @@ class TwistedReceiver: @inlineCallbacks def _go(self, w): yield self._handle_code(w) - verifier = yield w.verify() + yield w.establish_key() + def on_slow_connection(): + print(u"Key established, waiting for confirmation...", + file=self.args.stdout) + notify = self._reactor.callLater(1, on_slow_connection) + try: + verifier = yield w.verify() + finally: + if not notify.called: + notify.cancel() self._show_verifier(verifier) want_offer = True diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index 353e138..8ab914b 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -85,12 +85,19 @@ class Sender: print(u"Wormhole code is: %s" % code, file=args.stdout) print(u"", file=args.stdout) - key_established = yield w.establish_key() - print(u"Key established, waiting for confirmation...", - file=args.stdout) + yield w.establish_key() + def on_slow_connection(): + print(u"Key established, waiting for confirmation...", + file=args.stdout) + notify = self._reactor.callLater(1, on_slow_connection) # TODO: don't stall on w.verify() unless they want it - verifier_bytes = yield w.verify() # this may raise WrongPasswordError + try: + verifier_bytes = yield w.verify() # this may raise WrongPasswordError + finally: + if not notify.called: + notify.cancel() + if args.verify: verifier = bytes_to_hexstr(verifier_bytes) while True: diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index fcb1719..814f262 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -289,7 +289,6 @@ class _Wormhole: returns a Deferred that fires when we've established the shared key. When successful, the Deferred fires with a simple `True`, otherwise it fails. - """ return self._API_establish_key() @@ -582,7 +581,7 @@ class _Wormhole: def _API_establish_key(self): if self._error: return defer.fail(self._error) - if not self._key is None: + if self._key is not None: return defer.succeed(True) self._key_waiter = defer.Deferred() return self._key_waiter