in ReceiverThread.cpp [288:368]
ReceiverState ReceiverThread::processSettingsCmd() {
WTVLOG(1) << "entered PROCESS_SETTINGS_CMD state";
Settings settings;
int senderProtocolVersion;
bool success = Protocol::decodeVersion(
buf_, off_, oldOffset_ + Protocol::kMaxVersion, senderProtocolVersion);
if (!success) {
WTLOG(ERROR) << "Unable to decode version " << threadIndex_;
threadStats_.setLocalErrorCode(PROTOCOL_ERROR);
return FINISH_WITH_ERROR;
}
if (senderProtocolVersion != threadProtocolVersion_) {
WTLOG(WARNING) << "Receiver and sender protocol version mismatch "
<< senderProtocolVersion << " " << threadProtocolVersion_;
int negotiatedProtocol = Protocol::negotiateProtocol(
senderProtocolVersion, threadProtocolVersion_);
if (negotiatedProtocol == 0) {
WTLOG(WARNING) << "Can not support sender with version "
<< senderProtocolVersion << ", aborting!";
threadStats_.setLocalErrorCode(VERSION_INCOMPATIBLE);
return SEND_ABORT_CMD;
} else {
WLOG_IF(INFO, threadProtocolVersion_ != negotiatedProtocol)
<< *this << "Changing receiver protocol version to "
<< negotiatedProtocol;
threadProtocolVersion_ = negotiatedProtocol;
if (negotiatedProtocol != senderProtocolVersion) {
threadStats_.setLocalErrorCode(VERSION_MISMATCH);
return SEND_ABORT_CMD;
}
}
}
if (threadProtocolVersion_ <
Protocol::PERIODIC_ENCRYPTION_IV_CHANGE_VERSION) {
socket_->disableIvChange();
}
success = Protocol::decodeSettings(
threadProtocolVersion_, buf_, off_,
oldOffset_ + Protocol::kMaxVersion + Protocol::kMaxSettings, settings);
if (!success) {
WTLOG(ERROR) << "Unable to decode settings cmd ";
threadStats_.setLocalErrorCode(PROTOCOL_ERROR);
return FINISH_WITH_ERROR;
}
auto senderId = settings.transferId;
auto transferId = wdtParent_->getTransferId();
if (transferId != senderId) {
WTLOG(ERROR) << "Receiver and sender id mismatch " << senderId << " "
<< transferId;
threadStats_.setLocalErrorCode(ID_MISMATCH);
return SEND_ABORT_CMD;
}
senderReadTimeout_ = settings.readTimeoutMillis;
senderWriteTimeout_ = settings.writeTimeoutMillis;
isBlockMode_ = !settings.blockModeDisabled;
enableHeartBeat_ = settings.enableHeartBeat;
if (!enableHeartBeat_) {
WTLOG(INFO) << "Disabling heart-beat as sender does not support it";
}
curConnectionVerified_ = true;
// determine footer type
if (settings.enableChecksum) {
footerType_ = CHECKSUM_FOOTER;
} else {
footerType_ = NO_FOOTER;
}
if (settings.sendFileChunks) {
// We only move to SEND_FILE_CHUNKS state, if download resumption is enabled
// in the sender side
numRead_ = off_ = 0;
return SEND_FILE_CHUNKS;
}
auto msgLen = off_ - oldOffset_;
numRead_ -= msgLen;
return READ_NEXT_CMD;
}