Don't put servers on the list if they report the wrong link version.
authorCarl Hetherington <cth@carlh.net>
Wed, 20 May 2015 15:29:15 +0000 (16:29 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 20 May 2015 15:29:15 +0000 (16:29 +0100)
src/lib/server.cc
src/lib/server_finder.cc

index 9b3b3808b3886eabd44f36d5db9176039bdb1763..50ac4e786b6258a16f366a77dbfb4eaff674c82e 100644 (file)
@@ -104,6 +104,9 @@ Server::process (shared_ptr<Socket> socket, struct timeval& after_read, struct t
        string s (buffer.get());
        shared_ptr<cxml::Document> xml (new cxml::Document ("EncodingRequest"));
        xml->read_string (s);
+       /* This is a double-check; the server shouldn't even be on the candidate list
+          if it is the wrong version, but it doesn't hurt to make sure here.
+       */
        if (xml->number_child<int> ("Version") != SERVER_LINK_VERSION) {
                cerr << "Mismatched server/client versions\n";
                LOG_ERROR_NC ("Mismatched server/client versions");
@@ -248,6 +251,7 @@ Server::broadcast_received ()
                xmlpp::Document doc;
                xmlpp::Element* root = doc.create_root_node ("ServerAvailable");
                root->add_child("Threads")->add_child_text (raw_convert<string> (_worker_threads.size ()));
+               root->add_child("Version")->add_child_text (raw_convert<string> (SERVER_LINK_VERSION));
                string xml = doc.write_to_string ("UTF-8");
 
                if (_verbose) {
index 979046dabdd701829e176c86ddcc675eb860d9a9..f347132e452a7f3dc0fa1caf996d4ea5e4988c31 100644 (file)
@@ -167,7 +167,7 @@ ServerFinder::handle_accept (boost::system::error_code ec, shared_ptr<Socket> so
        xml->read_string (s);
        
        string const ip = socket->socket().remote_endpoint().address().to_string ();
-       if (!server_found (ip)) {
+       if (!server_found (ip) && xml->optional_number_child<int>("Version").get_value_or (0) == SERVER_LINK_VERSION) {
                ServerDescription sd (ip, xml->number_child<int> ("Threads"));
                {
                        boost::mutex::scoped_lock lm (_mutex);