From 05e44c121d25575e17ded0f6b407347e4b987d0d Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 25 Jul 2020 18:44:37 -0400 Subject: feat(3p/nix): Implement AddToStore proto handler Implement the proto handler for AddToStore, which adds a nix path to the store. This is implemented by adding a new (probably soon-to-be-generalized) Source concretion that wraps a grpc ServerReader for the stream of data we're receiving from the client - this is less than ideal, as it's perpetuating the source/sink thing that's going on and storing entire nars in memory, but is at the very worst an incremental step towards a functioning nix that we can refactor in the future. Paired-With: Perry Lorier Paired-With: Vincent Ambo Change-Id: I48db734e7460a47aee4a85dd5137b690980859e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1441 Tested-by: BuildkiteCI Reviewed-by: kanepyork Reviewed-by: tazjin --- third_party/nix/src/libutil/CMakeLists.txt | 1 + third_party/nix/src/libutil/hash.cc | 17 +++++++++++++++++ third_party/nix/src/libutil/hash.hh | 5 +++++ 3 files changed, 23 insertions(+) (limited to 'third_party/nix/src/libutil') diff --git a/third_party/nix/src/libutil/CMakeLists.txt b/third_party/nix/src/libutil/CMakeLists.txt index db504940a07e..ca60dd7a6ec8 100644 --- a/third_party/nix/src/libutil/CMakeLists.txt +++ b/third_party/nix/src/libutil/CMakeLists.txt @@ -47,6 +47,7 @@ target_sources(nixutil ) target_link_libraries(nixutil + nixproto absl::strings absl::statusor glog diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc index 0d5a1de07ce7..4a8904b4e058 100644 --- a/third_party/nix/src/libutil/hash.cc +++ b/third_party/nix/src/libutil/hash.cc @@ -18,6 +18,23 @@ namespace nix { +std::optional hash_type_from(nix::proto::HashType hash_type) { + switch (hash_type) { + case nix::proto::HashType::UNKNOWN: + return HashType::htUnknown; + case nix::proto::HashType::MD5: + return HashType::htMD5; + case nix::proto::HashType::SHA1: + return HashType::htSHA1; + case nix::proto::HashType::SHA256: + return HashType::htSHA256; + case nix::proto::HashType::SHA512: + return HashType::htSHA512; + default: + return {}; + } +} + void Hash::init() { if (type == htMD5) { hashSize = md5HashSize; diff --git a/third_party/nix/src/libutil/hash.hh b/third_party/nix/src/libutil/hash.hh index 4ad4ef6ada02..56845e715491 100644 --- a/third_party/nix/src/libutil/hash.hh +++ b/third_party/nix/src/libutil/hash.hh @@ -2,6 +2,7 @@ #include +#include "libproto/worker.grpc.pb.h" #include "libutil/serialise.hh" #include "libutil/types.hh" @@ -9,8 +10,12 @@ namespace nix { MakeError(BadHash, Error); +// TODO(grfn): Replace this with the hash type enum from the daemon proto so we +// don't have to juggle two different types enum HashType : char { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 }; +std::optional hash_type_from(nix::proto::HashType hash_type); + const int md5HashSize = 16; const int sha1HashSize = 20; const int sha256HashSize = 32; -- cgit 1.4.1