From eb4c8717cdeeaa93f24d2c3aeca075e6928d15e5 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Thu, 16 Jul 2020 20:28:54 -0400 Subject: feat(3p/nix/nix-daemon): Implement Worker::QueryPathInfo handler Change-Id: I580bd29356f7bcd0cc2050afda11d2e115d44c94 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1230 Tested-by: BuildkiteCI Reviewed-by: tazjin --- third_party/nix/src/nix-daemon/nix-daemon-proto.cc | 40 ++++++++++++++++++++++ third_party/nix/src/proto/worker.proto | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc index 85c9a7bc1467..178386730841 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc @@ -1,3 +1,6 @@ +#include +#include + #include "libproto/worker.grpc.pb.h" #include "libproto/worker.pb.h" #include "libstore/store-api.hh" @@ -5,10 +8,14 @@ namespace nix::daemon { using ::grpc::Status; +using ::nix::proto::PathInfo; using ::nix::proto::StorePath; using ::nix::proto::StorePaths; using ::nix::proto::WorkerService; +static Status INVALID_STORE_PATH = + Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid store path"); + class WorkerServiceImpl final : public WorkerService::Service { public: WorkerServiceImpl(nix::Store* store) : store_(store) {} @@ -88,6 +95,39 @@ class WorkerServiceImpl final : public WorkerService::Service { return Status::OK; } + Status QueryPathInfo(grpc::ServerContext* context, const StorePath* request, + PathInfo* response) override { + auto path = request->path(); + try { + auto info = store_->queryPathInfo(path); + response->mutable_deriver()->set_path(info->deriver); + response->set_nar_hash( + reinterpret_cast(&info->narHash.hash[0]), + info->narHash.hashSize); + + for (const auto& reference : info->references) { + response->add_references(reference); + } + + *response->mutable_registration_time() = + google::protobuf::util::TimeUtil::TimeTToTimestamp( + info->registrationTime); + + response->set_nar_size(info->narSize); + response->set_ultimate(info->ultimate); + + for (const auto& sig : info->sigs) { + response->add_sigs(sig); + } + + response->set_ca(info->ca); + + return Status::OK; + } catch (InvalidPath&) { + return Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid store path"); + } + } + Status QueryMissing(grpc::ServerContext* context, const StorePaths* request, nix::proto::QueryMissingResponse* response) override { std::set targets; diff --git a/third_party/nix/src/proto/worker.proto b/third_party/nix/src/proto/worker.proto index 6d4b2a9547f1..90af308f85dc 100644 --- a/third_party/nix/src/proto/worker.proto +++ b/third_party/nix/src/proto/worker.proto @@ -252,7 +252,7 @@ message CollectGarbageResponse { message PathInfo { StorePath deriver = 1; - string nar_hash = 2; + bytes nar_hash = 2; repeated string references = 3; google.protobuf.Timestamp registration_time = 4; uint64 nar_size = 5; -- cgit 1.4.1