From 90432ee64486a5467bed9acd99e8d4acccaefec9 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 28 Dec 2022 13:20:10 +0100 Subject: [PATCH 1/2] libstore: Add PROTOCOL_{MAJOR,MINOR} without <<8 problem PROTOCOL_MAJOR returns a simple major number, rather than the number multiplied by 256. This is what one would reasonably expect from GET_PROTOCOL_MAJOR, but we can't just change a macro in a public header; hence the "rename". --- src/libstore/serve-protocol.hh | 3 +++ src/libstore/worker-protocol.hh | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/libstore/serve-protocol.hh b/src/libstore/serve-protocol.hh index 3f76baa82ea..a2b4c2a8bd0 100644 --- a/src/libstore/serve-protocol.hh +++ b/src/libstore/serve-protocol.hh @@ -6,6 +6,9 @@ namespace nix { #define SERVE_MAGIC_2 0x5452eecb #define SERVE_PROTOCOL_VERSION (2 << 8 | 7) +#define PROTOCOL_MAJOR(x) (((x) & 0xff00) >> 8) +#define PROTOCOL_MINOR(x) ((x) & 0x00ff) +// Deprecated: #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index 87088a3ac10..114a677d062 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -10,6 +10,9 @@ namespace nix { #define WORKER_MAGIC_2 0x6478696f #define PROTOCOL_VERSION (1 << 8 | 34) +#define PROTOCOL_MAJOR(x) (((x) & 0xff00) >> 8) +#define PROTOCOL_MINOR(x) ((x) & 0x00ff) +// Deprecated: #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) From 0660d19c4a1734a15c4a02b90f4c8edfdf5663b4 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 28 Dec 2022 13:19:33 +0100 Subject: [PATCH 2/2] Use PROTOCOL_MAJOR to avoid <<8 problem PROTOCOL_MAJOR returns a simple major number, rather than the number multiplied by 256. This is what one would reasonably expect from GET_PROTOCOL_MAJOR, but we can't just change a macro in a public header; hence the "rename". --- src/libstore/daemon.cc | 48 +++++++++++----------- src/libstore/legacy-ssh-store.cc | 16 ++++---- src/libstore/remote-store.cc | 68 ++++++++++++++++---------------- src/nix-store/nix-store.cc | 12 +++--- src/nix/doctor.cc | 6 +-- 5 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 12596ba4983..2efd5528eeb 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -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; @@ -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; @@ -138,7 +138,7 @@ 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); @@ -146,7 +146,7 @@ struct TunnelLogger : public Logger 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); @@ -257,7 +257,7 @@ struct ClientSettings static std::vector readDerivedPaths(Store & store, unsigned int clientVersion, Source & from) { std::vector reqs; - if (GET_PROTOCOL_MINOR(clientVersion) >= 30) { + if (PROTOCOL_MINOR(clientVersion) >= 30) { reqs = worker_proto::read(store, from, Phantom> {}); } else { for (auto & s : readStrings(from)) @@ -285,7 +285,7 @@ static void performOp(TunnelLogger * logger, ref store, auto paths = worker_proto::read(*store, from, Phantom {}); SubstituteFlag substitute = NoSubstitute; - if (GET_PROTOCOL_MINOR(clientVersion) >= 27) { + if (PROTOCOL_MINOR(clientVersion) >= 27) { substitute = readInt(from) ? Substitute : NoSubstitute; } @@ -385,7 +385,7 @@ static void performOp(TunnelLogger * logger, ref 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 {}); @@ -414,7 +414,7 @@ static void performOp(TunnelLogger * logger, ref store, }(); logger->stopWork(); - pathInfo->write(to, *store, GET_PROTOCOL_MINOR(clientVersion)); + pathInfo->write(to, *store, PROTOCOL_MINOR(clientVersion)); } else { HashType hashAlgo; std::string baseName; @@ -520,7 +520,7 @@ static void performOp(TunnelLogger * logger, ref 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" @@ -619,10 +619,10 @@ static void performOp(TunnelLogger * logger, ref 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; @@ -726,7 +726,7 @@ static void performOp(TunnelLogger * logger, ref 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); @@ -768,7 +768,7 @@ static void performOp(TunnelLogger * logger, ref 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 {}); for (auto & path : paths) pathsMap.emplace(path, std::nullopt); @@ -802,15 +802,15 @@ static void performOp(TunnelLogger * logger, ref 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; @@ -873,7 +873,7 @@ static void performOp(TunnelLogger * logger, ref store, if (!trusted) info.ultimate = false; - if (GET_PROTOCOL_MINOR(clientVersion) >= 23) { + if (PROTOCOL_MINOR(clientVersion) >= 23) { logger->startWork(); { FramedSource source(from); @@ -886,7 +886,7 @@ static void performOp(TunnelLogger * logger, ref store, else { std::unique_ptr source; StringSink saved; - if (GET_PROTOCOL_MINOR(clientVersion) >= 21) + if (PROTOCOL_MINOR(clientVersion) >= 21) source = std::make_unique(from, to); else { TeeSource tee { from, saved }; @@ -923,7 +923,7 @@ static void performOp(TunnelLogger * logger, ref 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{ @@ -941,7 +941,7 @@ static void performOp(TunnelLogger * logger, ref 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 outPaths; if (info) outPaths.insert(info->outPath); worker_proto::write(*store, to, outPaths); @@ -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. */ diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 4d398b21d85..81d5ab49c3d 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -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) { @@ -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)); @@ -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 @@ -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); } } @@ -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 {}); } return status; diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 48cf731a89e..5c84031a7b5 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -207,21 +207,21 @@ void RemoteStore::initConnection(Connection & conn) } conn.from >> conn.daemonVersion; - if (GET_PROTOCOL_MAJOR(conn.daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION)) + if (PROTOCOL_MAJOR(conn.daemonVersion) != PROTOCOL_MAJOR(PROTOCOL_VERSION)) throw Error("Nix daemon protocol version not supported"); - if (GET_PROTOCOL_MINOR(conn.daemonVersion) < 10) + if (PROTOCOL_MINOR(conn.daemonVersion) < 10) throw Error("the Nix daemon version is too old"); conn.to << PROTOCOL_VERSION; - if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) { + if (PROTOCOL_MINOR(conn.daemonVersion) >= 14) { // Obsolete CPU affinity. conn.to << 0; } - if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11) + if (PROTOCOL_MINOR(conn.daemonVersion) >= 11) conn.to << false; // obsolete reserveSpace - if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 33) { + if (PROTOCOL_MINOR(conn.daemonVersion) >= 33) { conn.to.flush(); conn.daemonNixVersion = readString(conn.from); } @@ -253,7 +253,7 @@ void RemoteStore::setOptions(Connection & conn) << settings.buildCores << settings.useSubstitutes; - if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 12) { + if (PROTOCOL_MINOR(conn.daemonVersion) >= 12) { std::map overrides; settings.getSettings(overrides, true); // libstore settings fileTransferSettings.getSettings(overrides, true); @@ -339,7 +339,7 @@ bool RemoteStore::isValidPathUncached(const StorePath & path) StorePathSet RemoteStore::queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute) { auto conn(getConnection()); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 12) { StorePathSet res; for (auto & i : paths) if (isValidPath(i)) res.insert(i); @@ -347,7 +347,7 @@ StorePathSet RemoteStore::queryValidPaths(const StorePathSet & paths, Substitute } else { conn->to << wopQueryValidPaths; worker_proto::write(*this, conn->to, paths); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 27) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 27) { conn->to << (settings.buildersUseSubstitutes ? 1 : 0); } conn.processStderr(); @@ -368,7 +368,7 @@ StorePathSet RemoteStore::queryAllValidPaths() StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths) { auto conn(getConnection()); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 12) { StorePathSet res; for (auto & i : paths) { conn->to << wopHasSubstitutes << printStorePath(i); @@ -391,7 +391,7 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S auto conn(getConnection()); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 12) { for (auto & i : pathsMap) { SubstitutablePathInfo info; @@ -411,7 +411,7 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S } else { conn->to << wopQuerySubstitutablePathInfos; - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 22) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 22) { StorePathSet paths; for (auto & path : pathsMap) paths.insert(path.first); @@ -450,12 +450,12 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path, throw InvalidPath(std::move(e.info())); throw; } - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 17) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 17) { bool valid; conn->from >> valid; if (!valid) throw InvalidPath("path '%s' is not valid", printStorePath(path)); } info = std::make_shared( - ValidPathInfo::read(conn->from, *this, GET_PROTOCOL_MINOR(conn->daemonVersion), StorePath{path})); + ValidPathInfo::read(conn->from, *this, PROTOCOL_MINOR(conn->daemonVersion), StorePath{path})); } callback(std::move(info)); } catch (...) { callback.rethrow(); } @@ -484,7 +484,7 @@ StorePathSet RemoteStore::queryValidDerivers(const StorePath & path) StorePathSet RemoteStore::queryDerivationOutputs(const StorePath & path) { - if (GET_PROTOCOL_MINOR(getProtocol()) >= 0x16) { + if (PROTOCOL_MINOR(getProtocol()) >= 0x16) { return Store::queryDerivationOutputs(path); } auto conn(getConnection()); @@ -496,7 +496,7 @@ StorePathSet RemoteStore::queryDerivationOutputs(const StorePath & path) std::map> RemoteStore::queryPartialDerivationOutputMap(const StorePath & path) { - if (GET_PROTOCOL_MINOR(getProtocol()) >= 0x16) { + if (PROTOCOL_MINOR(getProtocol()) >= 0x16) { auto conn(getConnection()); conn->to << wopQueryDerivationOutputMap << printStorePath(path); conn.processStderr(); @@ -539,7 +539,7 @@ ref RemoteStore::addCAToStore( std::optional conn_(getConnection()); auto & conn = *conn_; - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 25) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 25) { conn->to << wopAddToStore @@ -558,7 +558,7 @@ ref RemoteStore::addCAToStore( } return make_ref( - ValidPathInfo::read(conn->from, *this, GET_PROTOCOL_MINOR(conn->daemonVersion))); + ValidPathInfo::read(conn->from, *this, PROTOCOL_MINOR(conn->daemonVersion))); } else { if (repair) throw Error("repairing is not supported when building through the Nix daemon protocol < 1.25"); @@ -623,7 +623,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, { auto conn(getConnection()); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 18) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 18) { conn->to << wopImportPaths; auto source2 = sinkToSource([&](Sink & sink) { @@ -657,11 +657,11 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, << info.ultimate << info.sigs << renderContentAddress(info.ca) << repair << !checkSigs; - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 23) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 23) { conn.withFramedSink([&](Sink & sink) { copyNAR(source, sink); }); - } else if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 21) { + } else if (PROTOCOL_MINOR(conn->daemonVersion) >= 21) { conn.processStderr(0, &source); } else { copyNAR(source, conn->to); @@ -693,7 +693,7 @@ void RemoteStore::addMultipleToStore( RepairFlag repair, CheckSigsFlag checkSigs) { - if (GET_PROTOCOL_MINOR(getConnection()->daemonVersion) >= 32) { + if (PROTOCOL_MINOR(getConnection()->daemonVersion) >= 32) { auto conn(getConnection()); conn->to << wopAddMultipleToStore @@ -721,7 +721,7 @@ void RemoteStore::registerDrvOutput(const Realisation & info) { auto conn(getConnection()); conn->to << wopRegisterDrvOutput; - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 31) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 31) { conn->to << info.id.to_string(); conn->to << std::string(info.outPath.to_string()); } else { @@ -736,7 +736,7 @@ void RemoteStore::queryRealisationUncached(const DrvOutput & id, try { auto conn(getConnection()); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 27) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 27) { warn("the daemon is too old to support content-addressed derivations, please upgrade it to 2.4"); return callback(nullptr); } @@ -746,7 +746,7 @@ void RemoteStore::queryRealisationUncached(const DrvOutput & id, conn.processStderr(); auto real = [&]() -> std::shared_ptr { - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 31) { + if (PROTOCOL_MINOR(conn->daemonVersion) < 31) { auto outPaths = worker_proto::read( *this, conn->from, Phantom> {}); if (outPaths.empty()) @@ -767,7 +767,7 @@ void RemoteStore::queryRealisationUncached(const DrvOutput & id, static void writeDerivedPaths(RemoteStore & store, ConnectionHandle & conn, const std::vector & reqs) { - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 30) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 30) { worker_proto::write(store, conn->to, reqs); } else { Strings ss; @@ -780,8 +780,8 @@ static void writeDerivedPaths(RemoteStore & store, ConnectionHandle & conn, cons [&](const StorePath & drvPath) { throw Error("trying to request '%s', but daemon protocol %d.%d is too old (< 1.29) to request a derivation file", store.printStorePath(drvPath), - GET_PROTOCOL_MAJOR(conn->daemonVersion), - GET_PROTOCOL_MINOR(conn->daemonVersion)); + PROTOCOL_MAJOR(conn->daemonVersion), + PROTOCOL_MINOR(conn->daemonVersion)); }, }, sOrDrvPath); } @@ -810,9 +810,9 @@ void RemoteStore::buildPaths(const std::vector & drvPaths, BuildMod auto conn(getConnection()); conn->to << wopBuildPaths; - assert(GET_PROTOCOL_MINOR(conn->daemonVersion) >= 13); + assert(PROTOCOL_MINOR(conn->daemonVersion) >= 13); writeDerivedPaths(*this, conn, drvPaths); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 15) + if (PROTOCOL_MINOR(conn->daemonVersion) >= 15) conn->to << buildMode; else /* Old daemons did not take a 'buildMode' parameter, so we @@ -833,7 +833,7 @@ std::vector RemoteStore::buildPathsWithResults( std::optional conn_(getConnection()); auto & conn = *conn_; - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 34) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 34) { conn->to << wopBuildPathsWithResults; writeDerivedPaths(*this, conn, paths); conn->to << buildMode; @@ -921,10 +921,10 @@ BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicD BuildResult res { .path = DerivedPath::Built { .drvPath = drvPath } }; res.status = (BuildResult::Status) readInt(conn->from); conn->from >> res.errorMsg; - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 29) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 29) { conn->from >> res.timesBuilt >> res.isNonDeterministic >> res.startTime >> res.stopTime; } - if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 28) { + if (PROTOCOL_MINOR(conn->daemonVersion) >= 28) { auto builtOutputs = worker_proto::read(*this, conn->from, Phantom {}); res.builtOutputs = builtOutputs; } @@ -1033,7 +1033,7 @@ void RemoteStore::queryMissing(const std::vector & targets, { { auto conn(getConnection()); - if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 19) + if (PROTOCOL_MINOR(conn->daemonVersion) < 19) // Don't hold the connection handle in the fallback case // to prevent a deadlock. goto fallback; @@ -1154,7 +1154,7 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source * } else if (msg == STDERR_ERROR) { - if (GET_PROTOCOL_MINOR(daemonVersion) >= 26) { + if (PROTOCOL_MINOR(daemonVersion) >= 26) { return std::make_exception_ptr(readError(from)); } else { auto error = readString(from); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 3bbefedbe07..c520245404a 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -805,9 +805,9 @@ static void opServe(Strings opFlags, Strings opArgs) settings.useSubstitutes = false; settings.maxSilentTime = readInt(in); settings.buildTimeout = readInt(in); - if (GET_PROTOCOL_MINOR(clientVersion) >= 2) + if (PROTOCOL_MINOR(clientVersion) >= 2) settings.maxLogSize = readNum(in); - if (GET_PROTOCOL_MINOR(clientVersion) >= 3) { + if (PROTOCOL_MINOR(clientVersion) >= 3) { auto nrRepeats = readInt(in); if (nrRepeats != 0) { throw Error("client requested repeating builds, but this is not currently implemented"); @@ -822,7 +822,7 @@ static void opServe(Strings opFlags, Strings opArgs) settings.runDiffHook = true; } - if (GET_PROTOCOL_MINOR(clientVersion) >= 7) { + if (PROTOCOL_MINOR(clientVersion) >= 7) { settings.keepFailed = (bool) readInt(in); } }; @@ -865,7 +865,7 @@ static void opServe(Strings opFlags, Strings opArgs) // !!! Maybe we want compression? out << info->narSize // downloadSize << info->narSize; - if (GET_PROTOCOL_MINOR(clientVersion) >= 4) + if (PROTOCOL_MINOR(clientVersion) >= 4) out << info->narHash.to_string(Base32, true) << renderContentAddress(info->ca) << info->sigs; @@ -929,9 +929,9 @@ static void opServe(Strings opFlags, Strings opArgs) out << status.status << status.errorMsg; - if (GET_PROTOCOL_MINOR(clientVersion) >= 3) + if (PROTOCOL_MINOR(clientVersion) >= 3) out << status.timesBuilt << status.isNonDeterministic << status.startTime << status.stopTime; - if (GET_PROTOCOL_MINOR(clientVersion) >= 6) { + if (PROTOCOL_MINOR(clientVersion) >= 6) { worker_proto::write(*store, out, status.builtOutputs); } diff --git a/src/nix/doctor.cc b/src/nix/doctor.cc index ea87e3d8744..4154d0b1de5 100644 --- a/src/nix/doctor.cc +++ b/src/nix/doctor.cc @@ -16,8 +16,8 @@ namespace { std::string formatProtocol(unsigned int proto) { if (proto) { - auto major = GET_PROTOCOL_MAJOR(proto) >> 8; - auto minor = GET_PROTOCOL_MINOR(proto); + auto major = PROTOCOL_MAJOR(proto); + auto minor = PROTOCOL_MINOR(proto); return (format("%1%.%2%") % major % minor).str(); } return "unknown"; @@ -114,7 +114,7 @@ struct CmdDoctor : StoreCommand bool checkStoreProtocol(unsigned int storeProto) { - unsigned int clientProto = GET_PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == GET_PROTOCOL_MAJOR(storeProto) + unsigned int clientProto = PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == PROTOCOL_MAJOR(storeProto) ? SERVE_PROTOCOL_VERSION : PROTOCOL_VERSION;