Skip to content

Commit 137a551

Browse files
committed
Remove support for daemon protocol version < 18
Version 18 was introduced in November 2016 (4b8f1b0).
1 parent 7658f00 commit 137a551

File tree

2 files changed

+77
-151
lines changed

2 files changed

+77
-151
lines changed

src/libstore/daemon.cc

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -572,21 +572,19 @@ static void performOp(
572572
case WorkerProto::Op::BuildPaths: {
573573
auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn);
574574
BuildMode mode = bmNormal;
575-
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 15) {
576-
mode = WorkerProto::Serialise<BuildMode>::read(*store, rconn);
577-
578-
/* Repairing is not atomic, so disallowed for "untrusted"
579-
clients.
580-
581-
FIXME: layer violation in this message: the daemon code (i.e.
582-
this file) knows whether a client/connection is trusted, but it
583-
does not how how the client was authenticated. The mechanism
584-
need not be getting the UID of the other end of a Unix Domain
585-
Socket.
586-
*/
587-
if (mode == bmRepair && !trusted)
588-
throw Error("repairing is not allowed because you are not in 'trusted-users'");
589-
}
575+
mode = WorkerProto::Serialise<BuildMode>::read(*store, rconn);
576+
577+
/* Repairing is not atomic, so disallowed for "untrusted"
578+
clients.
579+
580+
FIXME: layer violation in this message: the daemon code (i.e.
581+
this file) knows whether a client/connection is trusted, but it
582+
does not how how the client was authenticated. The mechanism
583+
need not be getting the UID of the other end of a Unix Domain
584+
Socket.
585+
*/
586+
if (mode == bmRepair && !trusted)
587+
throw Error("repairing is not allowed because you are not in 'trusted-users'");
590588
logger->startWork();
591589
store->buildPaths(drvs, mode);
592590
logger->stopWork();
@@ -805,13 +803,11 @@ static void performOp(
805803
clientSettings.buildCores = readInt(conn.from);
806804
clientSettings.useSubstitutes = readInt(conn.from);
807805

808-
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 12) {
809-
unsigned int n = readInt(conn.from);
810-
for (unsigned int i = 0; i < n; i++) {
811-
auto name = readString(conn.from);
812-
auto value = readString(conn.from);
813-
clientSettings.overrides.emplace(name, value);
814-
}
806+
unsigned int n = readInt(conn.from);
807+
for (unsigned int i = 0; i < n; i++) {
808+
auto name = readString(conn.from);
809+
auto value = readString(conn.from);
810+
clientSettings.overrides.emplace(name, value);
815811
}
816812

817813
logger->startWork();
@@ -876,19 +872,12 @@ static void performOp(
876872
auto path = store->parseStorePath(readString(conn.from));
877873
std::shared_ptr<const ValidPathInfo> info;
878874
logger->startWork();
879-
try {
880-
info = store->queryPathInfo(path);
881-
} catch (InvalidPath &) {
882-
if (GET_PROTOCOL_MINOR(conn.protoVersion) < 17)
883-
throw;
884-
}
875+
info = store->queryPathInfo(path);
885876
logger->stopWork();
886877
if (info) {
887-
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 17)
888-
conn.to << 1;
878+
conn.to << 1;
889879
WorkerProto::write(*store, wconn, static_cast<const UnkeyedValidPathInfo &>(*info));
890880
} else {
891-
assert(GET_PROTOCOL_MINOR(conn.protoVersion) >= 17);
892881
conn.to << 0;
893882
}
894883
break;
@@ -1063,7 +1052,7 @@ void processConnection(ref<Store> store, FdSource && from, FdSink && to, Trusted
10631052
auto [protoVersion, features] =
10641053
WorkerProto::BasicServerConnection::handshake(to, from, PROTOCOL_VERSION, WorkerProto::allFeatures);
10651054

1066-
if (protoVersion < 0x10a)
1055+
if (protoVersion < 256 + 18)
10671056
throw Error("the Nix client version is too old");
10681057

10691058
WorkerProto::BasicServerConnection conn;

src/libstore/remote-store.cc

Lines changed: 56 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ void RemoteStore::initConnection(Connection & conn)
7373
try {
7474
auto [protoVersion, features] =
7575
WorkerProto::BasicClientConnection::handshake(conn.to, tee, PROTOCOL_VERSION, WorkerProto::allFeatures);
76+
if (protoVersion < 256 + 18)
77+
throw Error("the Nix daemon version is too old");
7678
conn.protoVersion = protoVersion;
7779
conn.features = features;
7880
} catch (SerialisationError & e) {
@@ -109,24 +111,22 @@ void RemoteStore::setOptions(Connection & conn)
109111
<< 0 /* obsolete print build trace */
110112
<< settings.buildCores << settings.useSubstitutes;
111113

112-
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 12) {
113-
std::map<std::string, nix::Config::SettingInfo> overrides;
114-
settings.getSettings(overrides, true); // libstore settings
115-
fileTransferSettings.getSettings(overrides, true);
116-
overrides.erase(settings.keepFailed.name);
117-
overrides.erase(settings.keepGoing.name);
118-
overrides.erase(settings.tryFallback.name);
119-
overrides.erase(settings.maxBuildJobs.name);
120-
overrides.erase(settings.maxSilentTime.name);
121-
overrides.erase(settings.buildCores.name);
122-
overrides.erase(settings.useSubstitutes.name);
123-
overrides.erase(loggerSettings.showTrace.name);
124-
overrides.erase(experimentalFeatureSettings.experimentalFeatures.name);
125-
overrides.erase("plugin-files");
126-
conn.to << overrides.size();
127-
for (auto & i : overrides)
128-
conn.to << i.first << i.second.value;
129-
}
114+
std::map<std::string, nix::Config::SettingInfo> overrides;
115+
settings.getSettings(overrides, true); // libstore settings
116+
fileTransferSettings.getSettings(overrides, true);
117+
overrides.erase(settings.keepFailed.name);
118+
overrides.erase(settings.keepGoing.name);
119+
overrides.erase(settings.tryFallback.name);
120+
overrides.erase(settings.maxBuildJobs.name);
121+
overrides.erase(settings.maxSilentTime.name);
122+
overrides.erase(settings.buildCores.name);
123+
overrides.erase(settings.useSubstitutes.name);
124+
overrides.erase(loggerSettings.showTrace.name);
125+
overrides.erase(experimentalFeatureSettings.experimentalFeatures.name);
126+
overrides.erase("plugin-files");
127+
conn.to << overrides.size();
128+
for (auto & i : overrides)
129+
conn.to << i.first << i.second.value;
130130

131131
auto ex = conn.processStderrReturn();
132132
if (ex)
@@ -167,15 +167,7 @@ bool RemoteStore::isValidPathUncached(const StorePath & path)
167167
StorePathSet RemoteStore::queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute)
168168
{
169169
auto conn(getConnection());
170-
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 12) {
171-
StorePathSet res;
172-
for (auto & i : paths)
173-
if (isValidPath(i))
174-
res.insert(i);
175-
return res;
176-
} else {
177-
return conn->queryValidPaths(*this, &conn.daemonException, paths, maybeSubstitute);
178-
}
170+
return conn->queryValidPaths(*this, &conn.daemonException, paths, maybeSubstitute);
179171
}
180172

181173
StorePathSet RemoteStore::queryAllValidPaths()
@@ -189,21 +181,10 @@ StorePathSet RemoteStore::queryAllValidPaths()
189181
StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths)
190182
{
191183
auto conn(getConnection());
192-
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 12) {
193-
StorePathSet res;
194-
for (auto & i : paths) {
195-
conn->to << WorkerProto::Op::HasSubstitutes << printStorePath(i);
196-
conn.processStderr();
197-
if (readInt(conn->from))
198-
res.insert(i);
199-
}
200-
return res;
201-
} else {
202-
conn->to << WorkerProto::Op::QuerySubstitutablePaths;
203-
WorkerProto::write(*this, *conn, paths);
204-
conn.processStderr();
205-
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
206-
}
184+
conn->to << WorkerProto::Op::QuerySubstitutablePaths;
185+
WorkerProto::write(*this, *conn, paths);
186+
conn.processStderr();
187+
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
207188
}
208189

209190
void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, SubstitutablePathInfos & infos)
@@ -213,45 +194,24 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
213194

214195
auto conn(getConnection());
215196

216-
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 12) {
217-
218-
for (auto & i : pathsMap) {
219-
SubstitutablePathInfo info;
220-
conn->to << WorkerProto::Op::QuerySubstitutablePathInfo << printStorePath(i.first);
221-
conn.processStderr();
222-
unsigned int reply = readInt(conn->from);
223-
if (reply == 0)
224-
continue;
225-
auto deriver = readString(conn->from);
226-
if (deriver != "")
227-
info.deriver = parseStorePath(deriver);
228-
info.references = WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
229-
info.downloadSize = readLongLong(conn->from);
230-
info.narSize = readLongLong(conn->from);
231-
infos.insert_or_assign(i.first, std::move(info));
232-
}
233-
234-
} else {
235-
236-
conn->to << WorkerProto::Op::QuerySubstitutablePathInfos;
237-
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 22) {
238-
StorePathSet paths;
239-
for (auto & path : pathsMap)
240-
paths.insert(path.first);
241-
WorkerProto::write(*this, *conn, paths);
242-
} else
243-
WorkerProto::write(*this, *conn, pathsMap);
244-
conn.processStderr();
245-
size_t count = readNum<size_t>(conn->from);
246-
for (size_t n = 0; n < count; n++) {
247-
SubstitutablePathInfo & info(infos[parseStorePath(readString(conn->from))]);
248-
auto deriver = readString(conn->from);
249-
if (deriver != "")
250-
info.deriver = parseStorePath(deriver);
251-
info.references = WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
252-
info.downloadSize = readLongLong(conn->from);
253-
info.narSize = readLongLong(conn->from);
254-
}
197+
conn->to << WorkerProto::Op::QuerySubstitutablePathInfos;
198+
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 22) {
199+
StorePathSet paths;
200+
for (auto & path : pathsMap)
201+
paths.insert(path.first);
202+
WorkerProto::write(*this, *conn, paths);
203+
} else
204+
WorkerProto::write(*this, *conn, pathsMap);
205+
conn.processStderr();
206+
size_t count = readNum<size_t>(conn->from);
207+
for (size_t n = 0; n < count; n++) {
208+
SubstitutablePathInfo & info(infos[parseStorePath(readString(conn->from))]);
209+
auto deriver = readString(conn->from);
210+
if (deriver != "")
211+
info.deriver = parseStorePath(deriver);
212+
info.references = WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
213+
info.downloadSize = readLongLong(conn->from);
214+
info.narSize = readLongLong(conn->from);
255215
}
256216
}
257217

@@ -466,36 +426,20 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, Repair
466426
{
467427
auto conn(getConnection());
468428

469-
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 18) {
470-
auto source2 = sinkToSource([&](Sink & sink) {
471-
sink << 1 // == path follows
472-
;
473-
copyNAR(source, sink);
474-
sink << exportMagic << printStorePath(info.path);
475-
WorkerProto::write(*this, *conn, info.references);
476-
sink << (info.deriver ? printStorePath(*info.deriver) : "") << 0 // == no legacy signature
477-
<< 0 // == no path follows
478-
;
479-
});
480-
conn->importPaths(*this, &conn.daemonException, *source2);
481-
}
482-
483-
else {
484-
conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path)
485-
<< (info.deriver ? printStorePath(*info.deriver) : "")
486-
<< info.narHash.to_string(HashFormat::Base16, false);
487-
WorkerProto::write(*this, *conn, info.references);
488-
conn->to << info.registrationTime << info.narSize << info.ultimate << info.sigs << renderContentAddress(info.ca)
489-
<< repair << !checkSigs;
490-
491-
if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 23) {
492-
conn.withFramedSink([&](Sink & sink) { copyNAR(source, sink); });
493-
} else if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 21) {
494-
conn.processStderr(0, &source);
495-
} else {
496-
copyNAR(source, conn->to);
497-
conn.processStderr(0, nullptr);
498-
}
429+
conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path)
430+
<< (info.deriver ? printStorePath(*info.deriver) : "")
431+
<< info.narHash.to_string(HashFormat::Base16, false);
432+
WorkerProto::write(*this, *conn, info.references);
433+
conn->to << info.registrationTime << info.narSize << info.ultimate << info.sigs << renderContentAddress(info.ca)
434+
<< repair << !checkSigs;
435+
436+
if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 23) {
437+
conn.withFramedSink([&](Sink & sink) { copyNAR(source, sink); });
438+
} else if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 21) {
439+
conn.processStderr(0, &source);
440+
} else {
441+
copyNAR(source, conn->to);
442+
conn.processStderr(0, nullptr);
499443
}
500444
}
501445

@@ -618,15 +562,8 @@ void RemoteStore::buildPaths(
618562

619563
auto conn(getConnection());
620564
conn->to << WorkerProto::Op::BuildPaths;
621-
assert(GET_PROTOCOL_MINOR(conn->protoVersion) >= 13);
622565
WorkerProto::write(*this, *conn, drvPaths);
623-
if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 15)
624-
conn->to << buildMode;
625-
else
626-
/* Old daemons did not take a 'buildMode' parameter, so we
627-
need to validate it here on the client side. */
628-
if (buildMode != bmNormal)
629-
throw Error("repairing or checking is not supported when building through the Nix daemon");
566+
conn->to << buildMode;
630567
conn.processStderr();
631568
readInt(conn->from);
632569
}

0 commit comments

Comments
 (0)