allow MOTD to be displayed multiple times
(one displayed message per received welcome["motd"]) There's not much value in prohibiting the server from sending multiple MOTD messages, and it would prevent us from using it to display a "your client is using an old API, please upgrade" message after having already sent a regular "please donate" MOTD message. (We could send a second welcome message with ["error"] to kill the client, but ["motd"] is the most convenient way to deliver a non-fatal warning).
This commit is contained in:
parent
ea6619bc46
commit
00277c22cf
|
@ -47,10 +47,13 @@ class Welcome(unittest.TestCase):
|
|||
[mock.call.write(u"Server (at relay_url) says:\n"
|
||||
" message of\n the day"),
|
||||
mock.call.write(u"\n")])
|
||||
# motd is only displayed once
|
||||
# motd can be displayed multiple times
|
||||
with mock.patch("sys.stderr") as stderr2:
|
||||
w.handle_welcome({u"motd": u"second message"})
|
||||
self.assertEqual(stderr2.method_calls, [])
|
||||
self.assertEqual(stderr2.method_calls,
|
||||
[mock.call.write(u"Server (at relay_url) says:\n"
|
||||
" second message"),
|
||||
mock.call.write(u"\n")])
|
||||
|
||||
def test_current_version(self):
|
||||
w = wormhole._WelcomeHandler(u"relay_url", u"2.0", None)
|
||||
|
|
|
@ -178,18 +178,15 @@ class _WelcomeHandler:
|
|||
def __init__(self, url, current_version, signal_error):
|
||||
self._ws_url = url
|
||||
self._version_warning_displayed = False
|
||||
self._motd_displayed = False
|
||||
self._current_version = current_version
|
||||
self._signal_error = signal_error
|
||||
|
||||
def handle_welcome(self, welcome):
|
||||
if ("motd" in welcome and
|
||||
not self._motd_displayed):
|
||||
if "motd" in welcome:
|
||||
motd_lines = welcome["motd"].splitlines()
|
||||
motd_formatted = "\n ".join(motd_lines)
|
||||
print("Server (at %s) says:\n %s" %
|
||||
(self._ws_url, motd_formatted), file=sys.stderr)
|
||||
self._motd_displayed = True
|
||||
|
||||
# Only warn if we're running a release version (e.g. 0.0.6, not
|
||||
# 0.0.6-DISTANCE-gHASH). Only warn once.
|
||||
|
|
Loading…
Reference in New Issue
Block a user