remove WormholeClosedError, simplify control paths in cmd_send/receive

lgtm.com noticed some unreachable code paths, and it turns out that nothing
in the rest of the code base could ever raise WormholeClosedError (I guess it
was leftover from before the big API refactoring). Both sender and receiver
are simpler without the unnecessary checks and state variables.
This commit is contained in:
Brian Warner 2018-01-01 16:56:18 +01:00
parent e13f3e3e13
commit 443c402f60
3 changed files with 5 additions and 20 deletions

View File

@ -7,7 +7,7 @@ from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.python import log
from wormhole import create, input_with_completion, __version__
from ..transit import TransitReceiver
from ..errors import TransferError, WormholeClosedError
from ..errors import TransferError
from ..util import (dict_to_bytes, bytes_to_dict, bytes_to_hexstr,
estimate_free_space)
from .welcome import handle_welcome
@ -152,15 +152,9 @@ class Receiver:
self._show_verifier(verifier_bytes)
want_offer = True
done = False
while True:
try:
them_d = yield self._get_data(w)
except WormholeClosedError:
if done:
returnValue(None)
raise TransferError("unexpected close")
them_d = yield self._get_data(w)
#print("GOT", them_d)
recognized = False
if u"transit" in them_d:

View File

@ -6,7 +6,7 @@ from twisted.python import log
from twisted.protocols import basic
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from ..errors import (TransferError, WormholeClosedError, UnsendableFileError)
from ..errors import TransferError, UnsendableFileError
from wormhole import create, __version__
from ..transit import TransitSender
from ..util import dict_to_bytes, bytes_to_dict, bytes_to_hexstr
@ -169,15 +169,9 @@ class Sender:
self._send_data({"offer": offer}, w)
want_answer = True
done = False
while True:
try:
them_d_bytes = yield w.get_message()
except WormholeClosedError:
if done:
returnValue(None)
raise TransferError("unexpected close")
them_d_bytes = yield w.get_message()
# TODO: get_message() fired, so get_verifier must have fired, so
# now it's safe to use w.derive_key()
them_d = bytes_to_dict(them_d_bytes)
@ -193,8 +187,8 @@ class Sender:
recognized = True
if not want_answer:
raise TransferError("duplicate answer")
want_answer = True
yield self._handle_answer(them_d[u"answer"])
done = True
returnValue(None)
if not recognized:
log.msg("unrecognized message %r" % (them_d,))

View File

@ -61,9 +61,6 @@ class ReflectionAttack(WormholeError):
class InternalError(WormholeError):
"""The programmer did something wrong."""
class WormholeClosedError(InternalError):
"""API calls may not be made after close() is called."""
class TransferError(WormholeError):
"""Something bad happened and the transfer failed."""