aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/legacy-ssh-store.cc24
-rw-r--r--src/libstore/serve-protocol.cc44
-rw-r--r--src/libstore/serve-protocol.hh3
3 files changed, 53 insertions, 18 deletions
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 7e119ce49..890c8a149 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -172,24 +172,12 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
if (p.empty()) return callback(nullptr);
auto path2 = parseStorePath(p);
assert(path == path2);
- /* Hash will be set below. FIXME construct ValidPathInfo at end. */
- auto info = std::make_shared<ValidPathInfo>(path, Hash::dummy);
-
- auto deriver = readString(conn->from);
- if (deriver != "")
- info->deriver = parseStorePath(deriver);
- info->references = ServeProto::Serialise<StorePathSet>::read(*this, *conn);
- readLongLong(conn->from); // download size
- info->narSize = readLongLong(conn->from);
-
- {
- auto s = readString(conn->from);
- if (s == "")
- throw Error("NAR hash is now mandatory");
- info->narHash = Hash::parseAnyPrefixed(s);
- }
- info->ca = ContentAddress::parseOpt(readString(conn->from));
- info->sigs = readStrings<StringSet>(conn->from);
+ auto info = std::make_shared<ValidPathInfo>(
+ path,
+ ServeProto::Serialise<UnkeyedValidPathInfo>::read(*this, *conn));
+
+ if (info->narHash == Hash::dummy)
+ throw Error("NAR hash is now mandatory");
auto s = readString(conn->from);
assert(s == "");
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;
+}
+
}
diff --git a/src/libstore/serve-protocol.hh b/src/libstore/serve-protocol.hh
index ba159f6e9..3f82c8177 100644
--- a/src/libstore/serve-protocol.hh
+++ b/src/libstore/serve-protocol.hh
@@ -18,6 +18,7 @@ struct Source;
// items being serialised
struct BuildResult;
+struct UnkeyedValidPathInfo;
/**
@@ -141,6 +142,8 @@ inline std::ostream & operator << (std::ostream & s, ServeProto::Command op)
template<>
DECLARE_SERVE_SERIALISER(BuildResult);
+template<>
+DECLARE_SERVE_SERIALISER(UnkeyedValidPathInfo);
template<typename T>
DECLARE_SERVE_SERIALISER(std::vector<T>);