libstore daemon: remove very old protocol support (<2.3)

Change-Id: Ic05f478a659c199a66fe78ae05d357d317ac41b0
This commit is contained in:
jade 2024-05-24 20:45:05 -06:00
parent 24255748b4
commit 7b1d38bc4f
2 changed files with 33 additions and 50 deletions

View file

@ -47,10 +47,15 @@ struct TunnelLogger : public Logger
Sync<State> state_; Sync<State> 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) 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) void enqueueMsg(const std::string & s)
{ {
@ -129,12 +134,6 @@ struct TunnelLogger : public Logger
void startActivity(ActivityId act, Verbosity lvl, ActivityType type, void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent) override 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; StringSink buf;
buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent; buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent;
enqueueMsg(buf.s); enqueueMsg(buf.s);
@ -142,7 +141,6 @@ struct TunnelLogger : public Logger
void stopActivity(ActivityId act) override void stopActivity(ActivityId act) override
{ {
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf; StringSink buf;
buf << STDERR_STOP_ACTIVITY << act; buf << STDERR_STOP_ACTIVITY << act;
enqueueMsg(buf.s); enqueueMsg(buf.s);
@ -150,7 +148,6 @@ struct TunnelLogger : public Logger
void result(ActivityId act, ResultType type, const Fields & fields) override void result(ActivityId act, ResultType type, const Fields & fields) override
{ {
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf; StringSink buf;
buf << STDERR_RESULT << act << type << fields; buf << STDERR_RESULT << act << type << fields;
enqueueMsg(buf.s); enqueueMsg(buf.s);
@ -527,22 +524,19 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case WorkerProto::Op::BuildPaths: { case WorkerProto::Op::BuildPaths: {
auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn); auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn);
BuildMode mode = bmNormal; BuildMode mode = buildModeFromInteger(readInt(from));
if (GET_PROTOCOL_MINOR(clientVersion) >= 15) {
mode = buildModeFromInteger(readInt(from));
/* Repairing is not atomic, so disallowed for "untrusted" /* Repairing is not atomic, so disallowed for "untrusted"
clients. clients.
FIXME: layer violation in this message: the daemon code (i.e. FIXME: layer violation in this message: the daemon code (i.e.
this file) knows whether a client/connection is trusted, but it this file) knows whether a client/connection is trusted, but it
does not how how the client was authenticated. The mechanism does not how how the client was authenticated. The mechanism
need not be getting the UID of the other end of a Unix Domain need not be getting the UID of the other end of a Unix Domain
Socket. Socket.
*/ */
if (mode == bmRepair && !trusted) if (mode == bmRepair && !trusted)
throw Error("repairing is not allowed because you are not in 'trusted-users'"); throw Error("repairing is not allowed because you are not in 'trusted-users'");
}
logger->startWork(); logger->startWork();
store->buildPaths(drvs, mode); store->buildPaths(drvs, mode);
logger->stopWork(); logger->stopWork();
@ -746,13 +740,11 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
clientSettings.buildCores = readInt(from); clientSettings.buildCores = readInt(from);
clientSettings.useSubstitutes = readInt(from); clientSettings.useSubstitutes = readInt(from);
if (GET_PROTOCOL_MINOR(clientVersion) >= 12) { unsigned int n = readInt(from);
unsigned int n = readInt(from); for (unsigned int i = 0; i < n; i++) {
for (unsigned int i = 0; i < n; i++) { auto name = readString(from);
auto name = readString(from); auto value = readString(from);
auto value = readString(from); clientSettings.overrides.emplace(name, value);
clientSettings.overrides.emplace(name, value);
}
} }
logger->startWork(); logger->startWork();
@ -822,15 +814,14 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
try { try {
info = store->queryPathInfo(path); info = store->queryPathInfo(path);
} catch (InvalidPath &) { } 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(); logger->stopWork();
if (info) { if (info) {
if (GET_PROTOCOL_MINOR(clientVersion) >= 17) to << 1;
to << 1;
WorkerProto::write(*store, wconn, static_cast<const UnkeyedValidPathInfo &>(*info)); WorkerProto::write(*store, wconn, static_cast<const UnkeyedValidPathInfo &>(*info));
} else { } else {
assert(GET_PROTOCOL_MINOR(clientVersion) >= 17);
to << 0; to << 0;
} }
break; break;
@ -904,12 +895,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
else { else {
std::unique_ptr<Source> source; std::unique_ptr<Source> source;
StringSink saved; StringSink saved;
if (GET_PROTOCOL_MINOR(clientVersion) >= 21) source = std::make_unique<TunnelSource>(from, to);
source = std::make_unique<TunnelSource>(from, to);
else {
copyNAR(from, saved);
source = std::make_unique<StringSource>(saved.s);
}
logger->startWork(); logger->startWork();
@ -1011,7 +997,7 @@ void processConnection(
to.flush(); to.flush();
WorkerProto::Version clientVersion = readInt(from); WorkerProto::Version clientVersion = readInt(from);
if (clientVersion < 0x10a) if (clientVersion < MIN_SUPPORTED_WORKER_PROTO_VERSION)
throw Error("the Nix client version is too old"); throw Error("the Nix client version is too old");
auto tunnelLogger = new TunnelLogger(to, clientVersion); auto tunnelLogger = new TunnelLogger(to, clientVersion);
@ -1027,13 +1013,13 @@ void processConnection(
printMsgUsing(prevLogger, lvlDebug, "%d operations", opCount); 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. // Obsolete CPU affinity.
readInt(from); readInt(from);
} }
if (GET_PROTOCOL_MINOR(clientVersion) >= 11) readInt(from); // obsolete reserveSpace
readInt(from); // obsolete reserveSpace
if (GET_PROTOCOL_MINOR(clientVersion) >= 33) if (GET_PROTOCOL_MINOR(clientVersion) >= 33)
to << nixVersion; to << nixVersion;

View file

@ -27,11 +27,8 @@ struct RemoteStore::Connection
FdSource from; FdSource from;
/** /**
* Worker protocol version used for the connection. * The worker protocol version of the connected daemon. This may be newer
* * than this Lix supports.
* 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.)
*/ */
WorkerProto::Version daemonVersion; WorkerProto::Version daemonVersion;