From d12b48333608132b9ef16f5b93a22c44dc38fbaf Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Thu, 23 May 2024 20:25:05 -0700 Subject: [PATCH] libstore daemon: remove very old protocol support Change-Id: Ic05f478a659c199a66fe78ae05d357d317ac41b0 --- src/libstore/daemon.cc | 76 ++++++++++--------------- src/libstore/remote-store-connection.hh | 7 +-- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 420fc8bfe..8fd4567bf 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -45,10 +45,15 @@ struct TunnelLogger : public Logger Sync state_; - WorkerProto::Version clientVersion; + /** + * Worker protocol version of the other side. May be newer than this daemon. + */ + const WorkerProto::Version clientVersion; TunnelLogger(FdSink & to, WorkerProto::Version clientVersion) - : to(to), clientVersion(clientVersion) { } + : to(to), clientVersion(clientVersion) { + assert(clientVersion >= MIN_SUPPORTED_WORKER_PROTO_VERSION); + } void enqueueMsg(const std::string & s) { @@ -127,12 +132,6 @@ 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 (!s.empty()) - log(lvl, s + "..."); - return; - } - StringSink buf; buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent; enqueueMsg(buf.s); @@ -140,7 +139,6 @@ struct TunnelLogger : public Logger void stopActivity(ActivityId act) override { - if (GET_PROTOCOL_MINOR(clientVersion) < 20) return; StringSink buf; buf << STDERR_STOP_ACTIVITY << act; enqueueMsg(buf.s); @@ -148,7 +146,6 @@ struct TunnelLogger : public Logger void result(ActivityId act, ResultType type, const Fields & fields) override { - if (GET_PROTOCOL_MINOR(clientVersion) < 20) return; StringSink buf; buf << STDERR_RESULT << act << type << fields; enqueueMsg(buf.s); @@ -525,22 +522,19 @@ static void performOp(TunnelLogger * logger, ref store, case WorkerProto::Op::BuildPaths: { auto drvs = WorkerProto::Serialise::read(*store, rconn); - BuildMode mode = bmNormal; - if (GET_PROTOCOL_MINOR(clientVersion) >= 15) { - mode = buildModeFromInteger(readInt(from)); + BuildMode mode = buildModeFromInteger(readInt(from)); - /* Repairing is not atomic, so disallowed for "untrusted" - clients. + /* Repairing is not atomic, so disallowed for "untrusted" + clients. - FIXME: layer violation in this message: the daemon code (i.e. - this file) knows whether a client/connection is trusted, but it - does not how how the client was authenticated. The mechanism - need not be getting the UID of the other end of a Unix Domain - Socket. - */ - if (mode == bmRepair && !trusted) - throw Error("repairing is not allowed because you are not in 'trusted-users'"); - } + FIXME: layer violation in this message: the daemon code (i.e. + this file) knows whether a client/connection is trusted, but it + does not how how the client was authenticated. The mechanism + need not be getting the UID of the other end of a Unix Domain + Socket. + */ + if (mode == bmRepair && !trusted) + throw Error("repairing is not allowed because you are not in 'trusted-users'"); logger->startWork(); store->buildPaths(drvs, mode); logger->stopWork(); @@ -744,13 +738,11 @@ static void performOp(TunnelLogger * logger, ref store, clientSettings.buildCores = readInt(from); clientSettings.useSubstitutes = readInt(from); - if (GET_PROTOCOL_MINOR(clientVersion) >= 12) { - unsigned int n = readInt(from); - for (unsigned int i = 0; i < n; i++) { - auto name = readString(from); - auto value = readString(from); - clientSettings.overrides.emplace(name, value); - } + unsigned int n = readInt(from); + for (unsigned int i = 0; i < n; i++) { + auto name = readString(from); + auto value = readString(from); + clientSettings.overrides.emplace(name, value); } logger->startWork(); @@ -820,15 +812,14 @@ static void performOp(TunnelLogger * logger, ref store, try { info = store->queryPathInfo(path); } catch (InvalidPath &) { - if (GET_PROTOCOL_MINOR(clientVersion) < 17) throw; + // The path being invalid isn't fatal here since it will just be + // sent as not present. } logger->stopWork(); if (info) { - if (GET_PROTOCOL_MINOR(clientVersion) >= 17) - to << 1; + to << 1; WorkerProto::write(*store, wconn, static_cast(*info)); } else { - assert(GET_PROTOCOL_MINOR(clientVersion) >= 17); to << 0; } break; @@ -902,12 +893,7 @@ static void performOp(TunnelLogger * logger, ref store, else { std::unique_ptr source; StringSink saved; - if (GET_PROTOCOL_MINOR(clientVersion) >= 21) - source = std::make_unique(from, to); - else { - copyNAR(from, saved); - source = std::make_unique(saved.s); - } + source = std::make_unique(from, to); logger->startWork(); @@ -1009,7 +995,7 @@ void processConnection( to.flush(); WorkerProto::Version clientVersion = readInt(from); - if (clientVersion < 0x10a) + if (clientVersion < MIN_SUPPORTED_WORKER_PROTO_VERSION) throw Error("the Nix client version is too old"); auto tunnelLogger = new TunnelLogger(to, clientVersion); @@ -1025,13 +1011,13 @@ void processConnection( printMsgUsing(prevLogger, lvlDebug, "%d operations", opCount); }); - if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) { + // FIXME: what is *supposed* to be in this even? + if (readInt(from)) { // Obsolete CPU affinity. readInt(from); } - if (GET_PROTOCOL_MINOR(clientVersion) >= 11) - readInt(from); // obsolete reserveSpace + readInt(from); // obsolete reserveSpace if (GET_PROTOCOL_MINOR(clientVersion) >= 33) to << nixVersion; diff --git a/src/libstore/remote-store-connection.hh b/src/libstore/remote-store-connection.hh index 44328b06b..082874cec 100644 --- a/src/libstore/remote-store-connection.hh +++ b/src/libstore/remote-store-connection.hh @@ -27,11 +27,8 @@ struct RemoteStore::Connection FdSource from; /** - * Worker protocol version used for the connection. - * - * Despite its name, I think it is actually the maximum version both - * sides support. (If the maximum doesn't exist, we would fail to - * establish a connection and produce a value of this type.) + * The worker protocol version of the connected daemon. This may be newer + * than this Lix supports. */ WorkerProto::Version daemonVersion;