aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2023-10-20 15:34:26 +0200
committereldritch horrors <pennae@lix.systems>2024-03-04 04:43:35 +0100
commitab40b2c5d0f90d6a119bf4b368f933f5331b0c15 (patch)
tree305c600d732546077701abefc9dddecdd2eadf0f /src
parent5ddd1a916667ec0d969f99a0a85a2092bf18b632 (diff)
Merge pull request #9157 from obsidiansystems/protocol-versions
Add protocol versions to `{Worker,Serve}Proto::*Conn` (cherry picked from commit 4d17c59d8d059a5b39f1d1da2b58f2ec8da44861) Change-Id: I497af39deb792e50c157a1305d8c9e722798740b
Diffstat (limited to 'src')
-rw-r--r--src/libstore/daemon.cc25
-rw-r--r--src/libstore/legacy-ssh-store.cc4
-rw-r--r--src/libstore/path-info.cc10
-rw-r--r--src/libstore/remote-store-connection.hh4
-rw-r--r--src/libstore/serve-protocol.hh15
-rw-r--r--src/libstore/worker-protocol.hh15
-rw-r--r--src/nix-store/nix-store.cc12
7 files changed, 58 insertions, 27 deletions
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index 8cbf6f044..d61e97a64 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -45,9 +45,9 @@ struct TunnelLogger : public Logger
Sync<State> state_;
- unsigned int clientVersion;
+ WorkerProto::Version clientVersion;
- TunnelLogger(FdSink & to, unsigned int clientVersion)
+ TunnelLogger(FdSink & to, WorkerProto::Version clientVersion)
: to(to), clientVersion(clientVersion) { }
void enqueueMsg(const std::string & s)
@@ -261,7 +261,7 @@ struct ClientSettings
}
};
-static std::vector<DerivedPath> readDerivedPaths(Store & store, unsigned int clientVersion, WorkerProto::ReadConn conn)
+static std::vector<DerivedPath> readDerivedPaths(Store & store, WorkerProto::Version clientVersion, WorkerProto::ReadConn conn)
{
std::vector<DerivedPath> reqs;
if (GET_PROTOCOL_MINOR(clientVersion) >= 30) {
@@ -274,11 +274,17 @@ static std::vector<DerivedPath> readDerivedPaths(Store & store, unsigned int cli
}
static void performOp(TunnelLogger * logger, ref<Store> store,
- TrustedFlag trusted, RecursiveFlag recursive, unsigned int clientVersion,
+ TrustedFlag trusted, RecursiveFlag recursive, WorkerProto::Version clientVersion,
Source & from, BufferedSink & to, WorkerProto::Op op)
{
- WorkerProto::ReadConn rconn { .from = from };
- WorkerProto::WriteConn wconn { .to = to };
+ WorkerProto::ReadConn rconn {
+ .from = from,
+ .version = clientVersion,
+ };
+ WorkerProto::WriteConn wconn {
+ .to = to,
+ .version = clientVersion,
+ };
switch (op) {
@@ -1017,7 +1023,7 @@ void processConnection(
if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch");
to << WORKER_MAGIC_2 << PROTOCOL_VERSION;
to.flush();
- unsigned int clientVersion = readInt(from);
+ WorkerProto::Version clientVersion = readInt(from);
if (clientVersion < 0x10a)
throw Error("the Nix client version is too old");
@@ -1052,7 +1058,10 @@ void processConnection(
auto temp = trusted
? store->isTrustedClient()
: std::optional { NotTrusted };
- WorkerProto::WriteConn wconn { .to = to };
+ WorkerProto::WriteConn wconn {
+ .to = to,
+ .version = clientVersion,
+ };
WorkerProto::write(*store, wconn, temp);
}
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 703ded0b2..9143be72e 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -45,7 +45,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
std::unique_ptr<SSHMaster::Connection> sshConn;
FdSink to;
FdSource from;
- int remoteVersion;
+ ServeProto::Version remoteVersion;
bool good = true;
/**
@@ -60,6 +60,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
{
return ServeProto::ReadConn {
.from = from,
+ .version = remoteVersion,
};
}
@@ -75,6 +76,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
{
return ServeProto::WriteConn {
.to = to,
+ .version = remoteVersion,
};
}
};
diff --git a/src/libstore/path-info.cc b/src/libstore/path-info.cc
index ccb57104f..a9231ce8d 100644
--- a/src/libstore/path-info.cc
+++ b/src/libstore/path-info.cc
@@ -141,7 +141,10 @@ ValidPathInfo ValidPathInfo::read(Source & source, const Store & store, unsigned
ValidPathInfo info(path, narHash);
if (deriver != "") info.deriver = store.parseStorePath(deriver);
info.references = WorkerProto::Serialise<StorePathSet>::read(store,
- WorkerProto::ReadConn { .from = source });
+ WorkerProto::ReadConn {
+ .from = source,
+ .version = format,
+ });
source >> info.registrationTime >> info.narSize;
if (format >= 16) {
source >> info.ultimate;
@@ -163,7 +166,10 @@ void ValidPathInfo::write(
sink << (deriver ? store.printStorePath(*deriver) : "")
<< narHash.to_string(Base16, false);
WorkerProto::write(store,
- WorkerProto::WriteConn { .to = sink },
+ WorkerProto::WriteConn {
+ .to = sink,
+ .version = format,
+ },
references);
sink << registrationTime << narSize;
if (format >= 16) {
diff --git a/src/libstore/remote-store-connection.hh b/src/libstore/remote-store-connection.hh
index ce4740a9c..e4a9cacb9 100644
--- a/src/libstore/remote-store-connection.hh
+++ b/src/libstore/remote-store-connection.hh
@@ -30,7 +30,7 @@ struct RemoteStore::Connection
* sides support. (If the maximum doesn't exist, we would fail to
* establish a connection and produce a value of this type.)
*/
- unsigned int daemonVersion;
+ WorkerProto::Version daemonVersion;
/**
* Whether the remote side trusts us or not.
@@ -70,6 +70,7 @@ struct RemoteStore::Connection
{
return WorkerProto::ReadConn {
.from = from,
+ .version = daemonVersion,
};
}
@@ -85,6 +86,7 @@ struct RemoteStore::Connection
{
return WorkerProto::WriteConn {
.to = to,
+ .version = daemonVersion,
};
}
diff --git a/src/libstore/serve-protocol.hh b/src/libstore/serve-protocol.hh
index e2345d450..a627c6ad6 100644
--- a/src/libstore/serve-protocol.hh
+++ b/src/libstore/serve-protocol.hh
@@ -31,25 +31,28 @@ struct ServeProto
enum struct Command : uint64_t;
/**
+ * Version type for the protocol.
+ *
+ * @todo Convert to struct with separate major vs minor fields.
+ */
+ using Version = unsigned int;
+
+ /**
* A unidirectional read connection, to be used by the read half of the
* canonical serializers below.
- *
- * This currently is just a `Source &`, but more fields will be added
- * later.
*/
struct ReadConn {
Source & from;
+ Version version;
};
/**
* A unidirectional write connection, to be used by the write half of the
* canonical serializers below.
- *
- * This currently is just a `Sink &`, but more fields will be added
- * later.
*/
struct WriteConn {
Sink & to;
+ Version version;
};
/**
diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh
index c84060103..2d55d926a 100644
--- a/src/libstore/worker-protocol.hh
+++ b/src/libstore/worker-protocol.hh
@@ -48,25 +48,28 @@ struct WorkerProto
enum struct Op : uint64_t;
/**
+ * Version type for the protocol.
+ *
+ * @todo Convert to struct with separate major vs minor fields.
+ */
+ using Version = unsigned int;
+
+ /**
* A unidirectional read connection, to be used by the read half of the
* canonical serializers below.
- *
- * This currently is just a `Source &`, but more fields will be added
- * later.
*/
struct ReadConn {
Source & from;
+ Version version;
};
/**
* A unidirectional write connection, to be used by the write half of the
* canonical serializers below.
- *
- * This currently is just a `Sink &`, but more fields will be added
- * later.
*/
struct WriteConn {
Sink & to;
+ Version version;
};
/**
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 9b6c80a75..11d2e86e3 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -818,10 +818,16 @@ static void opServe(Strings opFlags, Strings opArgs)
if (magic != SERVE_MAGIC_1) throw Error("protocol mismatch");
out << SERVE_MAGIC_2 << SERVE_PROTOCOL_VERSION;
out.flush();
- unsigned int clientVersion = readInt(in);
+ ServeProto::Version clientVersion = readInt(in);
- ServeProto::ReadConn rconn { .from = in };
- ServeProto::WriteConn wconn { .to = out };
+ ServeProto::ReadConn rconn {
+ .from = in,
+ .version = clientVersion,
+ };
+ ServeProto::WriteConn wconn {
+ .to = out,
+ .version = clientVersion,
+ };
auto getBuildSettings = [&]() {
// FIXME: changing options here doesn't work if we're