aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/serve-protocol.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-07 12:37:33 +0100
committereldritch horrors <pennae@lix.systems>2024-03-07 12:37:33 +0100
commit8a268359b06471b463a8f3fc46c83a1fced8ab75 (patch)
treeb9a854b5faf432d158a449ec3f14146e4e6db00d /src/libstore/serve-protocol.cc
parent9eb58f5209f9cd1fd18f33b691c6a613075dffc4 (diff)
Merge pull request #9560 from obsidiansystems/serve-proto-unkeyed-valid-path-info-serializer
Factor out `ServeProto::Serialiser<UnkeyedValidPathInfo>` and test (cherry picked from commit 139982997eec493a0f74105c427953f6be77da6d) Change-Id: I28e4ba5a681a90d81915a56e6dbaa5456d64f96d
Diffstat (limited to 'src/libstore/serve-protocol.cc')
-rw-r--r--src/libstore/serve-protocol.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/libstore/serve-protocol.cc b/src/libstore/serve-protocol.cc
index 97a0ddf0e..2e15d28d5 100644
--- a/src/libstore/serve-protocol.cc
+++ b/src/libstore/serve-protocol.cc
@@ -6,6 +6,7 @@
#include "serve-protocol.hh"
#include "serve-protocol-impl.hh"
#include "archive.hh"
+#include "path-info.hh"
#include <nlohmann/json.hpp>
@@ -55,4 +56,47 @@ void ServeProto::Serialise<BuildResult>::write(const Store & store, ServeProto::
}
}
+
+UnkeyedValidPathInfo ServeProto::Serialise<UnkeyedValidPathInfo>::read(const Store & store, ReadConn conn)
+{
+ /* Hash should be set below unless very old `nix-store --serve`.
+ Caller should assert that it did set it. */
+ UnkeyedValidPathInfo info { Hash::dummy };
+
+ auto deriver = readString(conn.from);
+ if (deriver != "")
+ info.deriver = store.parseStorePath(deriver);
+ info.references = ServeProto::Serialise<StorePathSet>::read(store, conn);
+
+ readLongLong(conn.from); // download size, unused
+ info.narSize = readLongLong(conn.from);
+
+ if (GET_PROTOCOL_MINOR(conn.version) >= 4) {
+ auto s = readString(conn.from);
+ if (!s.empty())
+ info.narHash = Hash::parseAnyPrefixed(s);
+ info.ca = ContentAddress::parseOpt(readString(conn.from));
+ info.sigs = readStrings<StringSet>(conn.from);
+ }
+
+ return info;
+}
+
+void ServeProto::Serialise<UnkeyedValidPathInfo>::write(const Store & store, WriteConn conn, const UnkeyedValidPathInfo & info)
+{
+ conn.to
+ << (info.deriver ? store.printStorePath(*info.deriver) : "");
+
+ ServeProto::write(store, conn, info.references);
+ // !!! Maybe we want compression?
+ conn.to
+ << info.narSize // downloadSize, lie a little
+ << info.narSize;
+ if (GET_PROTOCOL_MINOR(conn.version) >= 4)
+ conn.to
+ << info.narHash.to_string(Base32, true)
+ << renderContentAddress(info.ca)
+ << info.sigs;
+}
+
}