Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@freelists.org>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	Kirill Yukhin <kyukhin@tarantool.org>,
	Konstantin Osipov <kostja@tarantool.org>,
	Cyrill Gorcunov <gorcunov@gmail.com>
Subject: [tarantool-patches] [PATCH 3/3] box/lua/console: Verify remote protocol for compatibility
Date: Fri, 12 Jul 2019 22:04:38 +0300	[thread overview]
Message-ID: <20190712190438.32349-4-gorcunov@gmail.com> (raw)
In-Reply-To: <20190712190438.32349-1-gorcunov@gmail.com>

New versions of tarantool use binary protocol to negotiate
with remote servers where all data can be properly serialized
by the serpent engine.

In turn old instances continue shipping yaml encoded data via
text protocol which we simply can't map into lua form. Thus
when we connect to a peer make sure that the data it will
provide us is supported.

Part-of #3834
---
 src/box/lua/console.lua | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index 7c3b608cb..a9ff6f9a7 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -87,6 +87,22 @@ local function output_save(fmt, opts)
     }
 end
 
+local function output_verify_remote(greeting)
+    --
+    -- In case if remote peer is operating over
+    -- old yaml protocol we are unable to decode
+    -- it to non-yaml serializers.
+    if greeting.protocol == 'Lua console' then
+        local d = box.session.storage.console_output
+        if d ~= nil and d["fmt"] == "lua" then
+            local msg1 = "Peer uses deprecated '%s' protocol. "
+            local msg2 = "Switch output to 'yaml' format to proceed."
+            return false, msg1:format(greeting.protocol) .. msg2
+        end
+    end
+    return true, nil
+end
+
 local function format(status, ...)
     local d = box.session.storage.console_output
     --
@@ -572,6 +588,14 @@ local function connect(uri, opts)
         log.verbose(greeting)
         box.error(box.error.NO_CONNECTION)
     end
+
+    local ok, res = output_verify_remote(greeting)
+    if not ok then
+        connection:close()
+        pcall(self.on_client_disconnect, self)
+        error(res)
+    end
+
     local remote
     if greeting.protocol == 'Lua console' then
         remote = wrap_text_socket(connection, u,
-- 
2.20.1

  parent reply	other threads:[~2019-07-12 19:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-12 19:04 [tarantool-patches] [PATCH v3 0/3] box/lua/console: Add initial support for lua output format Cyrill Gorcunov
2019-07-12 19:04 ` [tarantool-patches] [PATCH 1/3] third_party/serpent: Add serpent repo Cyrill Gorcunov
2019-07-12 19:04 ` [tarantool-patches] [PATCH 2/3] box/lua/console: Add support for lua output format Cyrill Gorcunov
2019-07-12 20:45   ` [tarantool-patches] " Konstantin Osipov
2019-07-12 21:44     ` Cyrill Gorcunov
2019-07-12 19:04 ` Cyrill Gorcunov [this message]
2019-07-12 20:47   ` [tarantool-patches] Re: [PATCH 3/3] box/lua/console: Verify remote protocol for compatibility Konstantin Osipov
2019-07-12 20:49     ` Konstantin Osipov
2019-07-12 21:51       ` Cyrill Gorcunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190712190438.32349-4-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 3/3] box/lua/console: Verify remote protocol for compatibility' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox