mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
Introduce separate Serve protocol serialisers
To start, it is just a clone of the common protocol. But now that we
have the separate protocol implementations, we can add versioning
information without the versions of one protocol leaking into another.
Using the infrastructure from the previous commit, we don't have to
duplicate code for shared behavior.
Motivation: No more perverse incentives. [0] did some awkward things
because the serialisers did not store the version. I don't want anyone
making changes to be pushed towards keeping the serialization logic with
the core data types just because it's easier or the alternative is
tedious.
The actual versioning of the Worker and Serve protocol serialisers
(Common remains unversioned as the underlying mini-protocols are not
versioned) will happen in subsequent commits / PRs.
[0]: fe1f34fa60
This commit is contained in:
parent
c7f1d86b80
commit
f7b8f8aff6
15 changed files with 344 additions and 39 deletions
|
@ -9,10 +9,9 @@
|
|||
#include "local-store.hh"
|
||||
#include "monitor-fd.hh"
|
||||
#include "serve-protocol.hh"
|
||||
#include "serve-protocol-impl.hh"
|
||||
#include "shared.hh"
|
||||
#include "util.hh"
|
||||
#include "common-protocol.hh"
|
||||
#include "common-protocol-impl.hh"
|
||||
#include "graphml.hh"
|
||||
#include "legacy.hh"
|
||||
#include "path-with-outputs.hh"
|
||||
|
@ -821,8 +820,8 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
out.flush();
|
||||
unsigned int clientVersion = readInt(in);
|
||||
|
||||
CommonProto::ReadConn rconn { .from = in };
|
||||
CommonProto::WriteConn wconn { .to = out };
|
||||
ServeProto::ReadConn rconn { .from = in };
|
||||
ServeProto::WriteConn wconn { .to = out };
|
||||
|
||||
auto getBuildSettings = [&]() {
|
||||
// FIXME: changing options here doesn't work if we're
|
||||
|
@ -867,7 +866,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
case ServeProto::Command::QueryValidPaths: {
|
||||
bool lock = readInt(in);
|
||||
bool substitute = readInt(in);
|
||||
auto paths = CommonProto::Serialise<StorePathSet>::read(*store, rconn);
|
||||
auto paths = ServeProto::Serialise<StorePathSet>::read(*store, rconn);
|
||||
if (lock && writeAllowed)
|
||||
for (auto & path : paths)
|
||||
store->addTempRoot(path);
|
||||
|
@ -876,19 +875,19 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
store->substitutePaths(paths);
|
||||
}
|
||||
|
||||
CommonProto::write(*store, wconn, store->queryValidPaths(paths));
|
||||
ServeProto::write(*store, wconn, store->queryValidPaths(paths));
|
||||
break;
|
||||
}
|
||||
|
||||
case ServeProto::Command::QueryPathInfos: {
|
||||
auto paths = CommonProto::Serialise<StorePathSet>::read(*store, rconn);
|
||||
auto paths = ServeProto::Serialise<StorePathSet>::read(*store, rconn);
|
||||
// !!! Maybe we want a queryPathInfos?
|
||||
for (auto & i : paths) {
|
||||
try {
|
||||
auto info = store->queryPathInfo(i);
|
||||
out << store->printStorePath(info->path)
|
||||
<< (info->deriver ? store->printStorePath(*info->deriver) : "");
|
||||
CommonProto::write(*store, wconn, info->references);
|
||||
ServeProto::write(*store, wconn, info->references);
|
||||
// !!! Maybe we want compression?
|
||||
out << info->narSize // downloadSize
|
||||
<< info->narSize;
|
||||
|
@ -916,7 +915,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
|
||||
case ServeProto::Command::ExportPaths: {
|
||||
readInt(in); // obsolete
|
||||
store->exportPaths(CommonProto::Serialise<StorePathSet>::read(*store, rconn), out);
|
||||
store->exportPaths(ServeProto::Serialise<StorePathSet>::read(*store, rconn), out);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -962,7 +961,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
DrvOutputs builtOutputs;
|
||||
for (auto & [output, realisation] : status.builtOutputs)
|
||||
builtOutputs.insert_or_assign(realisation.id, realisation);
|
||||
CommonProto::write(*store, wconn, builtOutputs);
|
||||
ServeProto::write(*store, wconn, builtOutputs);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -971,9 +970,9 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
case ServeProto::Command::QueryClosure: {
|
||||
bool includeOutputs = readInt(in);
|
||||
StorePathSet closure;
|
||||
store->computeFSClosure(CommonProto::Serialise<StorePathSet>::read(*store, rconn),
|
||||
store->computeFSClosure(ServeProto::Serialise<StorePathSet>::read(*store, rconn),
|
||||
closure, false, includeOutputs);
|
||||
CommonProto::write(*store, wconn, closure);
|
||||
ServeProto::write(*store, wconn, closure);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -988,7 +987,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
};
|
||||
if (deriver != "")
|
||||
info.deriver = store->parseStorePath(deriver);
|
||||
info.references = CommonProto::Serialise<StorePathSet>::read(*store, rconn);
|
||||
info.references = ServeProto::Serialise<StorePathSet>::read(*store, rconn);
|
||||
in >> info.registrationTime >> info.narSize >> info.ultimate;
|
||||
info.sigs = readStrings<StringSet>(in);
|
||||
info.ca = ContentAddress::parseOpt(readString(in));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue