mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
libstore: Introduce WorkerProto::FeatureSet alias
Unfortunately Feature is just an alias to `std::string` and not a new-type, so a ton of code relies on it being exactly a `std::string`. Using transparent comparators just for StringSet necessitates using it here as well.
This commit is contained in:
parent
55815ec225
commit
5278cd2396
4 changed files with 20 additions and 26 deletions
|
@ -685,7 +685,7 @@ TEST_F(WorkerProtoTest, handshake_features)
|
||||||
toClient.create();
|
toClient.create();
|
||||||
toServer.create();
|
toServer.create();
|
||||||
|
|
||||||
std::tuple<WorkerProto::Version, std::set<WorkerProto::Feature>> clientResult;
|
std::tuple<WorkerProto::Version, WorkerProto::FeatureSet> clientResult;
|
||||||
|
|
||||||
auto clientThread = std::thread([&]() {
|
auto clientThread = std::thread([&]() {
|
||||||
FdSink out { toServer.writeSide.get() };
|
FdSink out { toServer.writeSide.get() };
|
||||||
|
@ -703,7 +703,7 @@ TEST_F(WorkerProtoTest, handshake_features)
|
||||||
|
|
||||||
EXPECT_EQ(clientResult, daemonResult);
|
EXPECT_EQ(clientResult, daemonResult);
|
||||||
EXPECT_EQ(std::get<0>(clientResult), 123u);
|
EXPECT_EQ(std::get<0>(clientResult), 123u);
|
||||||
EXPECT_EQ(std::get<1>(clientResult), std::set<WorkerProto::Feature>({"bar", "xyzzy"}));
|
EXPECT_EQ(std::get<1>(clientResult), WorkerProto::FeatureSet({"bar", "xyzzy"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Has to be a `BufferedSink` for handshake.
|
/// Has to be a `BufferedSink` for handshake.
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct WorkerProto::BasicConnection
|
||||||
/**
|
/**
|
||||||
* The set of features that both sides support.
|
* The set of features that both sides support.
|
||||||
*/
|
*/
|
||||||
std::set<Feature> features;
|
FeatureSet features;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coercion to `WorkerProto::ReadConn`. This makes it easy to use the
|
* Coercion to `WorkerProto::ReadConn`. This makes it easy to use the
|
||||||
|
@ -92,11 +92,8 @@ struct WorkerProto::BasicClientConnection : WorkerProto::BasicConnection
|
||||||
* @param supportedFeatures The protocol features that we support.
|
* @param supportedFeatures The protocol features that we support.
|
||||||
*/
|
*/
|
||||||
// FIXME: this should probably be a constructor.
|
// FIXME: this should probably be a constructor.
|
||||||
static std::tuple<Version, std::set<Feature>> handshake(
|
static std::tuple<Version, FeatureSet> handshake(
|
||||||
BufferedSink & to,
|
BufferedSink & to, Source & from, WorkerProto::Version localVersion, const FeatureSet & supportedFeatures);
|
||||||
Source & from,
|
|
||||||
WorkerProto::Version localVersion,
|
|
||||||
const std::set<Feature> & supportedFeatures);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After calling handshake, must call this to exchange some basic
|
* After calling handshake, must call this to exchange some basic
|
||||||
|
@ -155,11 +152,8 @@ struct WorkerProto::BasicServerConnection : WorkerProto::BasicConnection
|
||||||
* @param supportedFeatures The protocol features that we support.
|
* @param supportedFeatures The protocol features that we support.
|
||||||
*/
|
*/
|
||||||
// FIXME: this should probably be a constructor.
|
// FIXME: this should probably be a constructor.
|
||||||
static std::tuple<Version, std::set<Feature>> handshake(
|
static std::tuple<Version, FeatureSet> handshake(
|
||||||
BufferedSink & to,
|
BufferedSink & to, Source & from, WorkerProto::Version localVersion, const FeatureSet & supportedFeatures);
|
||||||
Source & from,
|
|
||||||
WorkerProto::Version localVersion,
|
|
||||||
const std::set<Feature> & supportedFeatures);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After calling handshake, must call this to exchange some basic
|
* After calling handshake, must call this to exchange some basic
|
||||||
|
|
|
@ -135,8 +135,9 @@ struct WorkerProto
|
||||||
}
|
}
|
||||||
|
|
||||||
using Feature = std::string;
|
using Feature = std::string;
|
||||||
|
using FeatureSet = std::set<Feature>;
|
||||||
|
|
||||||
static const std::set<Feature> allFeatures;
|
static const FeatureSet allFeatures;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum struct WorkerProto::Op : uint64_t
|
enum struct WorkerProto::Op : uint64_t
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
const std::set<WorkerProto::Feature> WorkerProto::allFeatures{};
|
const WorkerProto::FeatureSet WorkerProto::allFeatures{};
|
||||||
|
|
||||||
WorkerProto::BasicClientConnection::~BasicClientConnection()
|
WorkerProto::BasicClientConnection::~BasicClientConnection()
|
||||||
{
|
{
|
||||||
|
@ -146,21 +146,20 @@ void WorkerProto::BasicClientConnection::processStderr(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::set<WorkerProto::Feature>
|
static WorkerProto::FeatureSet intersectFeatures(const WorkerProto::FeatureSet & a, const WorkerProto::FeatureSet & b)
|
||||||
intersectFeatures(const std::set<WorkerProto::Feature> & a, const std::set<WorkerProto::Feature> & b)
|
|
||||||
{
|
{
|
||||||
std::set<WorkerProto::Feature> res;
|
WorkerProto::FeatureSet res;
|
||||||
for (auto & x : a)
|
for (auto & x : a)
|
||||||
if (b.contains(x))
|
if (b.contains(x))
|
||||||
res.insert(x);
|
res.insert(x);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<WorkerProto::Version, std::set<WorkerProto::Feature>> WorkerProto::BasicClientConnection::handshake(
|
std::tuple<WorkerProto::Version, WorkerProto::FeatureSet> WorkerProto::BasicClientConnection::handshake(
|
||||||
BufferedSink & to,
|
BufferedSink & to,
|
||||||
Source & from,
|
Source & from,
|
||||||
WorkerProto::Version localVersion,
|
WorkerProto::Version localVersion,
|
||||||
const std::set<WorkerProto::Feature> & supportedFeatures)
|
const WorkerProto::FeatureSet & supportedFeatures)
|
||||||
{
|
{
|
||||||
to << WORKER_MAGIC_1 << localVersion;
|
to << WORKER_MAGIC_1 << localVersion;
|
||||||
to.flush();
|
to.flush();
|
||||||
|
@ -178,21 +177,21 @@ std::tuple<WorkerProto::Version, std::set<WorkerProto::Feature>> WorkerProto::Ba
|
||||||
auto protoVersion = std::min(daemonVersion, localVersion);
|
auto protoVersion = std::min(daemonVersion, localVersion);
|
||||||
|
|
||||||
/* Exchange features. */
|
/* Exchange features. */
|
||||||
std::set<WorkerProto::Feature> daemonFeatures;
|
WorkerProto::FeatureSet daemonFeatures;
|
||||||
if (GET_PROTOCOL_MINOR(protoVersion) >= 38) {
|
if (GET_PROTOCOL_MINOR(protoVersion) >= 38) {
|
||||||
to << supportedFeatures;
|
to << supportedFeatures;
|
||||||
to.flush();
|
to.flush();
|
||||||
daemonFeatures = readStrings<std::set<WorkerProto::Feature>>(from);
|
daemonFeatures = readStrings<WorkerProto::FeatureSet>(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {protoVersion, intersectFeatures(daemonFeatures, supportedFeatures)};
|
return {protoVersion, intersectFeatures(daemonFeatures, supportedFeatures)};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<WorkerProto::Version, std::set<WorkerProto::Feature>> WorkerProto::BasicServerConnection::handshake(
|
std::tuple<WorkerProto::Version, WorkerProto::FeatureSet> WorkerProto::BasicServerConnection::handshake(
|
||||||
BufferedSink & to,
|
BufferedSink & to,
|
||||||
Source & from,
|
Source & from,
|
||||||
WorkerProto::Version localVersion,
|
WorkerProto::Version localVersion,
|
||||||
const std::set<WorkerProto::Feature> & supportedFeatures)
|
const WorkerProto::FeatureSet & supportedFeatures)
|
||||||
{
|
{
|
||||||
unsigned int magic = readInt(from);
|
unsigned int magic = readInt(from);
|
||||||
if (magic != WORKER_MAGIC_1)
|
if (magic != WORKER_MAGIC_1)
|
||||||
|
@ -204,9 +203,9 @@ std::tuple<WorkerProto::Version, std::set<WorkerProto::Feature>> WorkerProto::Ba
|
||||||
auto protoVersion = std::min(clientVersion, localVersion);
|
auto protoVersion = std::min(clientVersion, localVersion);
|
||||||
|
|
||||||
/* Exchange features. */
|
/* Exchange features. */
|
||||||
std::set<WorkerProto::Feature> clientFeatures;
|
WorkerProto::FeatureSet clientFeatures;
|
||||||
if (GET_PROTOCOL_MINOR(protoVersion) >= 38) {
|
if (GET_PROTOCOL_MINOR(protoVersion) >= 38) {
|
||||||
clientFeatures = readStrings<std::set<WorkerProto::Feature>>(from);
|
clientFeatures = readStrings<WorkerProto::FeatureSet>(from);
|
||||||
to << supportedFeatures;
|
to << supportedFeatures;
|
||||||
to.flush();
|
to.flush();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue