aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/daemon.cc
diff options
context:
space:
mode:
authorjade <lix@jade.fyi>2024-06-17 22:08:48 +0000
committerGerrit Code Review <gerrit@localhost>2024-06-17 22:08:48 +0000
commitce2b48aa41ed8e6f3eed60a20e3e2afb244457b6 (patch)
tree4f00ca96dfb58bcbf35ce9ccc67407e143d30fec /src/libstore/daemon.cc
parentbcb774688feea4e1fc7919d4890361f4f8ea1f60 (diff)
parentc1f2733dd63eb04a8a192da72835b15f9363869f (diff)
Merge changes from topic "protocol" into main
* changes: libstore client: remove remaining dead code libstore: refuse to serialise ancient protocols libstore client: remove support for <2.3 clients libstore daemon: remove very old protocol support (<2.3) Delete old ValidPathInfo test, fix UnkeyedValidPathInfo Set up minimum protocol version
Diffstat (limited to 'src/libstore/daemon.cc')
-rw-r--r--src/libstore/daemon.cc95
1 files changed, 36 insertions, 59 deletions
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index 4b55668cb..c89b5f5b3 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -47,10 +47,15 @@ struct TunnelLogger : public Logger
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)
- : to(to), clientVersion(clientVersion) { }
+ : to(to), clientVersion(clientVersion) {
+ assert(clientVersion >= MIN_SUPPORTED_WORKER_PROTO_VERSION);
+ }
void enqueueMsg(const std::string & s)
{
@@ -129,12 +134,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);
@@ -142,7 +141,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);
@@ -150,7 +148,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);
@@ -267,14 +264,8 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
TrustedFlag trusted, RecursiveFlag recursive, WorkerProto::Version clientVersion,
Source & from, BufferedSink & to, WorkerProto::Op op)
{
- WorkerProto::ReadConn rconn {
- .from = from,
- .version = clientVersion,
- };
- WorkerProto::WriteConn wconn {
- .to = to,
- .version = clientVersion,
- };
+ WorkerProto::ReadConn rconn{from, clientVersion};
+ WorkerProto::WriteConn wconn{to, clientVersion};
switch (op) {
@@ -527,22 +518,19 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case WorkerProto::Op::BuildPaths: {
auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn);
- BuildMode mode = bmNormal;
- if (GET_PROTOCOL_MINOR(clientVersion) >= 15) {
- mode = buildModeFromInteger(readInt(from));
-
- /* 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'");
- }
+ BuildMode mode = buildModeFromInteger(readInt(from));
+
+ /* 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'");
logger->startWork();
store->buildPaths(drvs, mode);
logger->stopWork();
@@ -746,13 +734,11 @@ static void performOp(TunnelLogger * logger, ref<Store> 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();
@@ -822,15 +808,14 @@ static void performOp(TunnelLogger * logger, ref<Store> 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<const UnkeyedValidPathInfo &>(*info));
} else {
- assert(GET_PROTOCOL_MINOR(clientVersion) >= 17);
to << 0;
}
break;
@@ -904,12 +889,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
else {
std::unique_ptr<Source> source;
StringSink saved;
- if (GET_PROTOCOL_MINOR(clientVersion) >= 21)
- source = std::make_unique<TunnelSource>(from, to);
- else {
- copyNAR(from, saved);
- source = std::make_unique<StringSource>(saved.s);
- }
+ source = std::make_unique<TunnelSource>(from, to);
logger->startWork();
@@ -1011,7 +991,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);
@@ -1027,13 +1007,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;
@@ -1044,10 +1024,7 @@ void processConnection(
auto temp = trusted
? store->isTrustedClient()
: std::optional { NotTrusted };
- WorkerProto::WriteConn wconn {
- .to = to,
- .version = clientVersion,
- };
+ WorkerProto::WriteConn wconn {to, clientVersion};
WorkerProto::write(*store, wconn, temp);
}