[Spice-commits] client/red_channel.cpp client/red_client.cpp

Alexander Larsson alexl at kemper.freedesktop.org
Wed Jun 23 03:20:58 PDT 2010


 client/red_channel.cpp |   18 +++++++++++++-----
 client/red_client.cpp  |    4 ++--
 2 files changed, 15 insertions(+), 7 deletions(-)

New commits:
commit eb3fe11d944acf32d7795fb6d0d69c25ce800d54
Author: Alexander Larsson <alexl at redhat.com>
Date:   Wed Jun 23 12:18:41 2010 +0200

    Fix version mismatch error on connect
    
    Protocol is 0 (auto), 1 (old), or 2 (new). This is (apart from 0) the
    same as the major number for the stable protocol. However, the current major
    is ~(-1) to signify it being unstable, so don't use the major number as source
    for setting or comparing protocol.

diff --git a/client/red_channel.cpp b/client/red_channel.cpp
index d499e8c..3fa3f51 100644
--- a/client/red_channel.cpp
+++ b/client/red_channel.cpp
@@ -56,17 +56,20 @@ void RedChannelBase::link(uint32_t connection_id, const std::string& password,
     BIO *bioKey;
     RSA *rsa;
     uint8_t *buffer, *p;
+    uint32_t expected_major;
 
     header.magic = SPICE_MAGIC;
     header.size = sizeof(link_mess);
     if (protocol == 1) {
         /* protocol 1 == major 1, old 0.4 protocol, last active minor */
-        header.major_version = 1;
+        expected_major = header.major_version = 1;
         header.minor_version = 3;
     } else if (protocol == 2) {
         /* protocol 2 == current */
-        header.major_version = SPICE_VERSION_MAJOR;
+        expected_major = header.major_version = SPICE_VERSION_MAJOR;
         header.minor_version = SPICE_VERSION_MINOR;
+    } else {
+        THROW("unsupported protocol version specified");
     }
     link_mess.connection_id = connection_id;
     link_mess.channel_type = _type;
@@ -105,10 +108,10 @@ void RedChannelBase::link(uint32_t connection_id, const std::string& password,
         THROW_ERR(SPICEC_ERROR_CODE_CONNECT_FAILED, "bad magic");
     }
 
-    if (header.major_version != protocol) {
+    if (header.major_version != expected_major) {
         THROW_ERR(SPICEC_ERROR_CODE_VERSION_MISMATCH,
                   "version mismatch: expect %u got %u",
-                  protocol,
+                  expected_major,
                   header.major_version);
     }
 
@@ -447,7 +450,12 @@ void RedChannel::run()
                                         _client.get_password().c_str());
                 /* If automatic protocol, remember the first connect protocol type */
                 if (_client.get_protocol() == 0) {
-                    _client.set_protocol(get_peer_major());
+                    if (get_peer_major() == 1) {
+                        _client.set_protocol(1);
+                    } else {
+                        /* Major is 2 or unstable high value, use 2 */
+                        _client.set_protocol(2);
+                    }
                 }
                 /* Initialize when we know the remote major version */
                 if (_client.get_peer_major() == 1) {
diff --git a/client/red_client.cpp b/client/red_client.cpp
index 573e4b2..c2be58c 100644
--- a/client/red_client.cpp
+++ b/client/red_client.cpp
@@ -172,7 +172,7 @@ void Migrate::run()
     try {
         conn_type = _client.get_connection_options(SPICE_CHANNEL_MAIN);
         RedPeer::ConnectionOptions con_opt(conn_type, _port, _sport,
-					   _client.get_peer_major(),
+					   _client.get_protocol(),
 					   _auth_options, _con_ciphers);
         MigChannels::iterator iter = _channels.begin();
         connection_id = _client.get_connection_id();
@@ -181,7 +181,7 @@ void Migrate::run()
         for (++iter; iter != _channels.end(); ++iter) {
             conn_type = _client.get_connection_options((*iter)->get_type());
             con_opt = RedPeer::ConnectionOptions(conn_type, _port, _sport,
-						 _client.get_peer_major(),
+						 _client.get_protocol(),
                                                  _auth_options, _con_ciphers);
             connect_one(**iter, con_opt, connection_id);
         }


More information about the Spice-commits mailing list