error out if server gives a "sorry we're closed" error
This commit is contained in:
parent
3a728d4a06
commit
e881d169a6
|
@ -7,6 +7,7 @@ from nacl.exceptions import CryptoError
|
|||
from nacl import utils
|
||||
from .. import __version__
|
||||
from .. import codes
|
||||
from ..errors import ServerError
|
||||
from ..util.hkdf import HKDF
|
||||
|
||||
SECOND = 1
|
||||
|
@ -98,12 +99,14 @@ class Common:
|
|||
version_warning_displayed = False
|
||||
|
||||
def handle_welcome(self, welcome):
|
||||
if self.version_warning_displayed:
|
||||
return
|
||||
if "error" in welcome:
|
||||
raise ServerError(welcome["error"], self.relay)
|
||||
if "-" in __version__:
|
||||
# only warn if we're running a release version (e.g. 0.0.6, not
|
||||
# 0.0.6-DISTANCE-gHASH)
|
||||
return
|
||||
if self.version_warning_displayed:
|
||||
return
|
||||
if welcome["current_version"] != __version__:
|
||||
print("Warning: errors may occur unless both sides are running the same version", file=sys.stderr)
|
||||
print("Server claims %s is current, but ours is %s"
|
||||
|
@ -139,7 +142,10 @@ class Common:
|
|||
def _allocate(self):
|
||||
r = requests.post(self.relay + "allocate")
|
||||
r.raise_for_status()
|
||||
channel_id = r.json()["channel-id"]
|
||||
data = r.json()
|
||||
if "welcome" in data:
|
||||
self.handle_welcome(data["welcome"])
|
||||
channel_id = data["channel-id"]
|
||||
return channel_id
|
||||
|
||||
def _post_pake(self):
|
||||
|
|
18
src/wormhole/errors.py
Normal file
18
src/wormhole/errors.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import functools
|
||||
|
||||
class ServerError(Exception):
|
||||
def __init__(self, message, relay):
|
||||
self.message = message
|
||||
self.relay = relay
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
def handle_server_error(func):
|
||||
@functools.wraps(func)
|
||||
def _wrap(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except ServerError as e:
|
||||
print("Server error (from %s):\n%s" % (e.relay, e.message))
|
||||
return 1
|
||||
return _wrap
|
|
@ -1,12 +1,14 @@
|
|||
from __future__ import print_function
|
||||
import sys, os, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/file-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def receive_file(args):
|
||||
# we're receiving
|
||||
import sys, os, json, binascii
|
||||
from wormhole.blocking.transcribe import Receiver, WrongPasswordError
|
||||
from wormhole.blocking.transit import TransitReceiver, TransitError
|
||||
from ..blocking.transcribe import Receiver, WrongPasswordError
|
||||
from ..blocking.transit import TransitReceiver, TransitError
|
||||
from .progress import start_progress, update_progress, finish_progress
|
||||
|
||||
transit_receiver = TransitReceiver(args.transit_helper)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
from __future__ import print_function
|
||||
import sys, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/text-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def receive_text(args):
|
||||
# we're receiving
|
||||
import sys, json, binascii
|
||||
from wormhole.blocking.transcribe import Receiver, WrongPasswordError
|
||||
from ..blocking.transcribe import Receiver, WrongPasswordError
|
||||
|
||||
r = Receiver(APPID, args.relay_url)
|
||||
code = args.code
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
from __future__ import print_function
|
||||
import os, sys, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/file-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def send_file(args):
|
||||
# we're sending
|
||||
import os, sys, json, binascii
|
||||
from wormhole.blocking.transcribe import Initiator, WrongPasswordError
|
||||
from wormhole.blocking.transit import TransitSender
|
||||
from ..blocking.transcribe import Initiator, WrongPasswordError
|
||||
from ..blocking.transit import TransitSender
|
||||
from .progress import start_progress, update_progress, finish_progress
|
||||
|
||||
filename = args.filename
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
from __future__ import print_function
|
||||
import sys, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/text-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def send_text(args):
|
||||
# we're sending
|
||||
import sys, json, binascii
|
||||
from wormhole.blocking.transcribe import Initiator, WrongPasswordError
|
||||
from ..blocking.transcribe import Initiator, WrongPasswordError
|
||||
|
||||
i = Initiator(APPID, args.relay_url)
|
||||
code = i.get_code(args.code_length)
|
||||
|
|
|
@ -49,6 +49,8 @@ class EventsProtocol:
|
|||
WELCOME = {
|
||||
"current_version": __version__,
|
||||
"motd": "Welcome to the public relay.",
|
||||
# adding .error will cause all clients to fail, with this message
|
||||
#"error": "This server has been disabled, see URL for details.",
|
||||
}
|
||||
|
||||
# relay URLs are:
|
||||
|
|
Loading…
Reference in New Issue
Block a user