Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve protocol major macro #7523

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
48 changes: 24 additions & 24 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct TunnelLogger : public Logger
if (!ex)
to << STDERR_LAST;
else {
if (GET_PROTOCOL_MINOR(clientVersion) >= 26) {
if (PROTOCOL_MINOR(clientVersion) >= 26) {
to << STDERR_ERROR << *ex;
} else {
to << STDERR_ERROR << ex->what() << ex->status;
Expand All @@ -125,7 +125,7 @@ struct TunnelLogger : public Logger
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent) override
{
if (GET_PROTOCOL_MINOR(clientVersion) < 20) {
if (PROTOCOL_MINOR(clientVersion) < 20) {
if (!s.empty())
log(lvl, s + "...");
return;
Expand All @@ -138,15 +138,15 @@ struct TunnelLogger : public Logger

void stopActivity(ActivityId act) override
{
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
if (PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf;
buf << STDERR_STOP_ACTIVITY << act;
enqueueMsg(buf.s);
}

void result(ActivityId act, ResultType type, const Fields & fields) override
{
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
if (PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf;
buf << STDERR_RESULT << act << type << fields;
enqueueMsg(buf.s);
Expand Down Expand Up @@ -257,7 +257,7 @@ struct ClientSettings
static std::vector<DerivedPath> readDerivedPaths(Store & store, unsigned int clientVersion, Source & from)
{
std::vector<DerivedPath> reqs;
if (GET_PROTOCOL_MINOR(clientVersion) >= 30) {
if (PROTOCOL_MINOR(clientVersion) >= 30) {
reqs = worker_proto::read(store, from, Phantom<std::vector<DerivedPath>> {});
} else {
for (auto & s : readStrings<Strings>(from))
Expand Down Expand Up @@ -285,7 +285,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
auto paths = worker_proto::read(*store, from, Phantom<StorePathSet> {});

SubstituteFlag substitute = NoSubstitute;
if (GET_PROTOCOL_MINOR(clientVersion) >= 27) {
if (PROTOCOL_MINOR(clientVersion) >= 27) {
substitute = readInt(from) ? Substitute : NoSubstitute;
}

Expand Down Expand Up @@ -385,7 +385,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
}

case wopAddToStore: {
if (GET_PROTOCOL_MINOR(clientVersion) >= 25) {
if (PROTOCOL_MINOR(clientVersion) >= 25) {
auto name = readString(from);
auto camStr = readString(from);
auto refs = worker_proto::read(*store, from, Phantom<StorePathSet> {});
Expand Down Expand Up @@ -414,7 +414,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
}();
logger->stopWork();

pathInfo->write(to, *store, GET_PROTOCOL_MINOR(clientVersion));
pathInfo->write(to, *store, PROTOCOL_MINOR(clientVersion));
} else {
HashType hashAlgo;
std::string baseName;
Expand Down Expand Up @@ -520,7 +520,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case wopBuildPaths: {
auto drvs = readDerivedPaths(*store, clientVersion, from);
BuildMode mode = bmNormal;
if (GET_PROTOCOL_MINOR(clientVersion) >= 15) {
if (PROTOCOL_MINOR(clientVersion) >= 15) {
mode = (BuildMode) readInt(from);

/* Repairing is not atomic, so disallowed for "untrusted"
Expand Down Expand Up @@ -619,10 +619,10 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
auto res = store->buildDerivation(drvPath, drv, buildMode);
logger->stopWork();
to << res.status << res.errorMsg;
if (GET_PROTOCOL_MINOR(clientVersion) >= 29) {
if (PROTOCOL_MINOR(clientVersion) >= 29) {
to << res.timesBuilt << res.isNonDeterministic << res.startTime << res.stopTime;
}
if (GET_PROTOCOL_MINOR(clientVersion) >= 28) {
if (PROTOCOL_MINOR(clientVersion) >= 28) {
worker_proto::write(*store, to, res.builtOutputs);
}
break;
Expand Down Expand Up @@ -726,7 +726,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
clientSettings.buildCores = readInt(from);
clientSettings.useSubstitutes = readInt(from);

if (GET_PROTOCOL_MINOR(clientVersion) >= 12) {
if (PROTOCOL_MINOR(clientVersion) >= 12) {
unsigned int n = readInt(from);
for (unsigned int i = 0; i < n; i++) {
auto name = readString(from);
Expand Down Expand Up @@ -768,7 +768,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case wopQuerySubstitutablePathInfos: {
SubstitutablePathInfos infos;
StorePathCAMap pathsMap = {};
if (GET_PROTOCOL_MINOR(clientVersion) < 22) {
if (PROTOCOL_MINOR(clientVersion) < 22) {
auto paths = worker_proto::read(*store, from, Phantom<StorePathSet> {});
for (auto & path : paths)
pathsMap.emplace(path, std::nullopt);
Expand Down Expand Up @@ -802,15 +802,15 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
try {
info = store->queryPathInfo(path);
} catch (InvalidPath &) {
if (GET_PROTOCOL_MINOR(clientVersion) < 17) throw;
if (PROTOCOL_MINOR(clientVersion) < 17) throw;
}
logger->stopWork();
if (info) {
if (GET_PROTOCOL_MINOR(clientVersion) >= 17)
if (PROTOCOL_MINOR(clientVersion) >= 17)
to << 1;
info->write(to, *store, GET_PROTOCOL_MINOR(clientVersion), false);
info->write(to, *store, PROTOCOL_MINOR(clientVersion), false);
} else {
assert(GET_PROTOCOL_MINOR(clientVersion) >= 17);
assert(PROTOCOL_MINOR(clientVersion) >= 17);
to << 0;
}
break;
Expand Down Expand Up @@ -873,7 +873,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
if (!trusted)
info.ultimate = false;

if (GET_PROTOCOL_MINOR(clientVersion) >= 23) {
if (PROTOCOL_MINOR(clientVersion) >= 23) {
logger->startWork();
{
FramedSource source(from);
Expand All @@ -886,7 +886,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
else {
std::unique_ptr<Source> source;
StringSink saved;
if (GET_PROTOCOL_MINOR(clientVersion) >= 21)
if (PROTOCOL_MINOR(clientVersion) >= 21)
source = std::make_unique<TunnelSource>(from, to);
else {
TeeSource tee { from, saved };
Expand Down Expand Up @@ -923,7 +923,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,

case wopRegisterDrvOutput: {
logger->startWork();
if (GET_PROTOCOL_MINOR(clientVersion) < 31) {
if (PROTOCOL_MINOR(clientVersion) < 31) {
auto outputId = DrvOutput::parse(readString(from));
auto outputPath = StorePath(readString(from));
store->registerDrvOutput(Realisation{
Expand All @@ -941,7 +941,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
auto outputId = DrvOutput::parse(readString(from));
auto info = store->queryRealisation(outputId);
logger->stopWork();
if (GET_PROTOCOL_MINOR(clientVersion) < 31) {
if (PROTOCOL_MINOR(clientVersion) < 31) {
std::set<StorePath> outPaths;
if (info) outPaths.insert(info->outPath);
worker_proto::write(*store, to, outPaths);
Expand Down Expand Up @@ -1008,15 +1008,15 @@ void processConnection(
printMsgUsing(prevLogger, lvlDebug, "%d operations", opCount);
});

if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) {
if (PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) {
// Obsolete CPU affinity.
readInt(from);
}

if (GET_PROTOCOL_MINOR(clientVersion) >= 11)
if (PROTOCOL_MINOR(clientVersion) >= 11)
readInt(from); // obsolete reserveSpace

if (GET_PROTOCOL_MINOR(clientVersion) >= 33)
if (PROTOCOL_MINOR(clientVersion) >= 33)
to << nixVersion;

/* Send startup error messages to the client. */
Expand Down
16 changes: 8 additions & 8 deletions src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
host, chomp(saved.s + msg));
}
conn->remoteVersion = readInt(conn->from);
if (GET_PROTOCOL_MAJOR(conn->remoteVersion) != 0x200)
if (PROTOCOL_MAJOR(conn->remoteVersion) != 2)
throw Error("unsupported 'nix-store --serve' protocol version on '%s'", host);

} catch (EndOfFile & e) {
Expand All @@ -120,7 +120,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
auto conn(connections->get());

/* No longer support missing NAR hash */
assert(GET_PROTOCOL_MINOR(conn->remoteVersion) >= 4);
assert(PROTOCOL_MINOR(conn->remoteVersion) >= 4);

debug("querying remote host '%s' for info on '%s'", host, printStorePath(path));

Expand Down Expand Up @@ -165,7 +165,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor

auto conn(connections->get());

if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 5) {
if (PROTOCOL_MINOR(conn->remoteVersion) >= 5) {

conn->to
<< cmdAddToStoreNar
Expand Down Expand Up @@ -250,15 +250,15 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
conn.to
<< settings.maxSilentTime
<< settings.buildTimeout;
if (GET_PROTOCOL_MINOR(conn.remoteVersion) >= 2)
if (PROTOCOL_MINOR(conn.remoteVersion) >= 2)
conn.to
<< settings.maxLogSize;
if (GET_PROTOCOL_MINOR(conn.remoteVersion) >= 3)
if (PROTOCOL_MINOR(conn.remoteVersion) >= 3)
conn.to
<< 0 // buildRepeat hasn't worked for ages anyway
<< 0;

if (GET_PROTOCOL_MINOR(conn.remoteVersion) >= 7) {
if (PROTOCOL_MINOR(conn.remoteVersion) >= 7) {
conn.to << ((int) settings.keepFailed);
}
}
Expand All @@ -283,9 +283,9 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
status.status = (BuildResult::Status) readInt(conn->from);
conn->from >> status.errorMsg;

if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 3)
if (PROTOCOL_MINOR(conn->remoteVersion) >= 3)
conn->from >> status.timesBuilt >> status.isNonDeterministic >> status.startTime >> status.stopTime;
if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 6) {
if (PROTOCOL_MINOR(conn->remoteVersion) >= 6) {
status.builtOutputs = worker_proto::read(*this, conn->from, Phantom<DrvOutputs> {});
}
return status;
Expand Down
Loading