Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 9 additions & 27 deletions src/lib/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,26 +651,6 @@ void Client::handleClipboardGrabbed(const Event &event, void *)
}
}

bool Client::isCompatible(int major, int minor) const
{
const std::map<int, std::set<int>> compatibleTable{
{6, {7, 8}}, // 1.6 is compatible with 1.7 and 1.8
{7, {8}} // 1.7 is compatible with 1.8
};

bool isCompatible = false;

if (major == kProtocolMajorVersion) {
auto versions = compatibleTable.find(minor);
if (versions != compatibleTable.end()) {
auto compatibleVersions = versions->second;
isCompatible = compatibleVersions.find(kProtocolMinorVersion) != compatibleVersions.end();
}
}

return isCompatible;
}

void Client::handleHello(const Event &, void *)
{
SInt16 major, minor;
Expand All @@ -682,24 +662,26 @@ void Client::handleHello(const Event &, void *)
}

// check versions
LOG((CLOG_DEBUG1 "got hello version %d.%d", major, minor));
LOG((CLOG_DEBUG "got hello version %d.%d", major, minor));
SInt16 helloBackMajor = kProtocolMajorVersion;
SInt16 helloBackMinor = kProtocolMinorVersion;

if (isCompatible(major, minor)) {
// because 1.6 is comptable with 1.7 and 1.8 - downgrading protocol for
// server
LOG((CLOG_NOTE "downgrading protocol version for server"));
// only allow client minor version to downgrade, as major versions will likely not be compatible.
if (major == kProtocolMajorVersion && minor < kProtocolMinorVersion) {
helloBackMinor = minor;
} else if (major < kProtocolMajorVersion || (major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) {
LOG_NOTE(
"downgrading client protocol version from %d.%d to %d.%d", //
kProtocolMajorVersion, kProtocolMinorVersion, helloBackMajor, helloBackMinor
);
} else if (major != kProtocolMajorVersion) {
sendConnectionFailedEvent(XIncompatibleClient(major, minor).what());
cleanupTimer();
cleanupConnection();
return;
}

// say hello back
LOG((CLOG_DEBUG1 "say hello version %d.%d", helloBackMajor, helloBackMinor));
LOG((CLOG_DEBUG "say hello version %d.%d", helloBackMajor, helloBackMinor));
ProtocolUtil::writef(m_stream, kMsgHelloBack, helloBackMajor, helloBackMinor, &m_name);

// now connected but waiting to complete handshake
Expand Down
1 change: 0 additions & 1 deletion src/lib/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ class Client : public IClient, public INode
void handleDisconnected(const Event &, void *);
void handleShapeChanged(const Event &, void *);
void handleClipboardGrabbed(const Event &, void *);
bool isCompatible(int major, int minor) const;
void handleHello(const Event &, void *);
void handleSuspend(const Event &event, void *);
void handleResume(const Event &event, void *);
Expand Down
Loading