2024-03-04 03:35:39 +00:00
|
|
|
#include "serialise.hh"
|
|
|
|
#include "util.hh"
|
|
|
|
#include "path-with-outputs.hh"
|
|
|
|
#include "store-api.hh"
|
2024-03-04 03:59:31 +00:00
|
|
|
#include "build-result.hh"
|
2024-03-04 03:35:39 +00:00
|
|
|
#include "serve-protocol.hh"
|
|
|
|
#include "serve-protocol-impl.hh"
|
|
|
|
#include "archive.hh"
|
2024-03-07 11:37:33 +00:00
|
|
|
#include "path-info.hh"
|
2024-03-04 03:35:39 +00:00
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
/* protocol-specific definitions */
|
|
|
|
|
2024-03-04 03:59:31 +00:00
|
|
|
BuildResult ServeProto::Serialise<BuildResult>::read(const Store & store, ServeProto::ReadConn conn)
|
|
|
|
{
|
|
|
|
BuildResult status;
|
|
|
|
status.status = (BuildResult::Status) readInt(conn.from);
|
|
|
|
conn.from >> status.errorMsg;
|
|
|
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn.version) >= 3)
|
|
|
|
conn.from
|
|
|
|
>> status.timesBuilt
|
|
|
|
>> status.isNonDeterministic
|
|
|
|
>> status.startTime
|
|
|
|
>> status.stopTime;
|
|
|
|
if (GET_PROTOCOL_MINOR(conn.version) >= 6) {
|
|
|
|
auto builtOutputs = ServeProto::Serialise<DrvOutputs>::read(store, conn);
|
|
|
|
for (auto && [output, realisation] : builtOutputs)
|
|
|
|
status.builtOutputs.insert_or_assign(
|
|
|
|
std::move(output.outputName),
|
|
|
|
std::move(realisation));
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServeProto::Serialise<BuildResult>::write(const Store & store, ServeProto::WriteConn conn, const BuildResult & status)
|
|
|
|
{
|
|
|
|
conn.to
|
|
|
|
<< status.status
|
|
|
|
<< status.errorMsg;
|
|
|
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn.version) >= 3)
|
|
|
|
conn.to
|
|
|
|
<< status.timesBuilt
|
|
|
|
<< status.isNonDeterministic
|
|
|
|
<< status.startTime
|
|
|
|
<< status.stopTime;
|
|
|
|
if (GET_PROTOCOL_MINOR(conn.version) >= 6) {
|
|
|
|
DrvOutputs builtOutputs;
|
|
|
|
for (auto & [output, realisation] : status.builtOutputs)
|
|
|
|
builtOutputs.insert_or_assign(realisation.id, realisation);
|
|
|
|
ServeProto::write(store, conn, builtOutputs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-07 11:37:33 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-03-04 03:35:39 +00:00
|
|
|
}
|