Skip to content

Commit

Permalink
Merge pull request NixOS#27 from obsidiansystems/ipfs-git-ca
Browse files Browse the repository at this point in the history
Handle CA in ipfs-binary-cache-store
  • Loading branch information
Ericson2314 authored Jun 24, 2020
2 parents 5b22a90 + c0314c5 commit 8f09500
Show file tree
Hide file tree
Showing 20 changed files with 418 additions and 159 deletions.
6 changes: 5 additions & 1 deletion src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ std::optional<StorePath> trySubstitute(ref<Store> store, FileIngestionMethod ing
auto substitutablePath = store->makeFixedOutputPath(ingestionMethod, hash, name);

try {
store->ensurePath(substitutablePath);
auto ca = FixedOutputHash {
.method = ingestionMethod,
.hash = hash
};
store->ensurePath(substitutablePath, ca);

debug("using substituted path '%s'", store->printStorePath(substitutablePath));

Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ struct GitInput : Input
unpackTarfile(*source, tmpDir);
}

auto storePath = store->addToStore(name, tmpDir, ingestionMethod, ingestionMethod == FileIngestionMethod::Git ? htSHA1 : htSHA256, filter);
auto storePath = store->addToStore(name, tmpDir, ingestionMethod, htSHA256, filter);

// verify treeHash is what we actually obtained in the nix store
if (input->treeHash) {
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource
stats.narInfoWrite++;
}

bool BinaryCacheStore::isValidPathUncached(const StorePath & storePath)
bool BinaryCacheStore::isValidPathUncached(const StorePath & storePath, std::optional<ContentAddress> ca)
{
// FIXME: this only checks whether a .narinfo with a matching hash
// part exists. So ‘f4kb...-foo’ matches ‘f4kb...-bar’, even
// though they shouldn't. Not easily fixed.
return fileExists(narInfoFileFor(storePath));
}

void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink, std::optional<ContentAddress> ca)
{
auto info = queryPathInfo(storePath).cast<const NarInfo>();

Expand All @@ -298,7 +298,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
}

void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
Callback<std::shared_ptr<const ValidPathInfo>> callback, std::optional<ContentAddress> ca) noexcept
{
auto uri = getUri();
auto storePathS = printStorePath(storePath);
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ private:

public:

bool isValidPathUncached(const StorePath & path) override;
bool isValidPathUncached(const StorePath & path, std::optional<ContentAddress> ca) override;

void queryPathInfoUncached(const StorePath & path,
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
Callback<std::shared_ptr<const ValidPathInfo>> callback, std::optional<ContentAddress> ca) noexcept override;

std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
{ unsupported("queryPathFromHashPart"); }
Expand All @@ -85,13 +85,13 @@ public:
StorePath addTextToStore(const string & name, const string & s,
const StorePathSet & references, RepairFlag repair) override;

void narFromPath(const StorePath & path, Sink & sink) override;
void narFromPath(const StorePath & path, Sink & sink, std::optional<ContentAddress> ca) override;

BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
BuildMode buildMode) override
{ unsupported("buildDerivation"); }

void ensurePath(const StorePath & path) override
void ensurePath(const StorePath & path, std::optional<ContentAddress> ca) override
{ unsupported("ensurePath"); }

ref<FSAccessor> getFSAccessor() override;
Expand Down
22 changes: 11 additions & 11 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2729,12 +2729,12 @@ struct RestrictedStore : public LocalFSStore
}

void queryPathInfoUncached(const StorePath & path,
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override
Callback<std::shared_ptr<const ValidPathInfo>> callback, std::optional<ContentAddress> ca) noexcept override
{
if (goal.isAllowed(path)) {
try {
/* Censor impure information. */
auto info = std::make_shared<ValidPathInfo>(*next->queryPathInfo(path));
auto info = std::make_shared<ValidPathInfo>(*next->queryPathInfo(path, ca));
info->deriver.reset();
info->registrationTime = 0;
info->ultimate = false;
Expand Down Expand Up @@ -2785,14 +2785,14 @@ struct RestrictedStore : public LocalFSStore
return path;
}

void narFromPath(const StorePath & path, Sink & sink) override
void narFromPath(const StorePath & path, Sink & sink, std::optional<ContentAddress> ca) override
{
if (!goal.isAllowed(path))
throw InvalidPath("cannot dump unknown path '%s' in recursive Nix", printStorePath(path));
LocalFSStore::narFromPath(path, sink);
LocalFSStore::narFromPath(path, sink, ca);
}

void ensurePath(const StorePath & path) override
void ensurePath(const StorePath & path, std::optional<ContentAddress> ca) override
{
if (!goal.isAllowed(path))
throw InvalidPath("cannot substitute unknown path '%s' in recursive Nix", printStorePath(path));
Expand Down Expand Up @@ -4422,7 +4422,7 @@ void SubstitutionGoal::tryNext()

try {
// FIXME: make async
info = sub->queryPathInfo(subPath);
info = sub->queryPathInfo(subPath, ca);
} catch (InvalidPath &) {
tryNext();
return;
Expand Down Expand Up @@ -4550,7 +4550,7 @@ void SubstitutionGoal::tryToRun()
}

copyStorePath(ref<Store>(sub), ref<Store>(worker.store.shared_from_this()),
subPath, repair, sub->isTrusted ? NoCheckSigs : CheckSigs);
subPath, repair, sub->isTrusted ? NoCheckSigs : CheckSigs, ca);

promise.set_value();
} catch (...) {
Expand Down Expand Up @@ -5126,15 +5126,15 @@ BuildResult LocalStore::buildDerivation(const StorePath & drvPath, const BasicDe
}


void LocalStore::ensurePath(const StorePath & path)
void LocalStore::ensurePath(const StorePath & path, std::optional<ContentAddress> ca)
{
/* If the path is already valid, we're done. */
if (isValidPath(path)) return;
if (isValidPath(path, ca)) return;

primeCache(*this, {{path}});
// primeCache(*this, {{path}});

Worker worker(*this);
GoalPtr goal = worker.makeSubstitutionGoal(path);
GoalPtr goal = worker.makeSubstitutionGoal(path, NoRepair, ca);
Goals goals = {goal};

worker.run(goals);
Expand Down
16 changes: 3 additions & 13 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,24 +387,14 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
TeeSource savedNAR(from);
RetrieveRegularNARSink savedRegular;

switch (method) {
case FileIngestionMethod::Recursive: {
if (method == FileIngestionMethod::Flat)
parseDump(savedRegular, from);
else {
/* Get the entire NAR dump from the client and save it to
a string so that we can pass it to
addToStoreFromDump(). */
ParseSink sink; /* null sink; just parse the NAR */
parseDump(sink, savedNAR);
break;
}
case FileIngestionMethod::Git: {
ParseSink sink;
parseGit(sink, savedNAR, store->storeDir, store->storeDir);
break;
}
case FileIngestionMethod::Flat: {
parseDump(savedRegular, from);
break;
}
}

logger->startWork();
Expand Down
Loading

0 comments on commit 8f09500

Please sign in to comment.