2024-05-23 23:40:05 +03:00
|
|
|
#pragma once
|
|
|
|
///@file
|
|
|
|
|
|
|
|
#include "worker-protocol.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2024-07-17 16:27:15 +03:00
|
|
|
struct WorkerProto::BasicConnection
|
2024-05-23 23:40:05 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Send with this.
|
|
|
|
*/
|
|
|
|
FdSink to;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive with this.
|
|
|
|
*/
|
|
|
|
FdSource from;
|
|
|
|
|
|
|
|
/**
|
2024-07-17 16:27:15 +03:00
|
|
|
* The protocol version agreed by both sides.
|
|
|
|
*/
|
|
|
|
WorkerProto::Version protoVersion;
|
|
|
|
|
2024-07-19 16:48:19 +03:00
|
|
|
/**
|
|
|
|
* The set of features that both sides support.
|
|
|
|
*/
|
|
|
|
std::set<Feature> features;
|
|
|
|
|
2024-07-17 16:27:15 +03:00
|
|
|
/**
|
|
|
|
* Coercion to `WorkerProto::ReadConn`. This makes it easy to use the
|
|
|
|
* factored out serve protocol serializers with a
|
|
|
|
* `LegacySSHStore::Connection`.
|
|
|
|
*
|
|
|
|
* The serve protocol connection types are unidirectional, unlike
|
|
|
|
* this type.
|
|
|
|
*/
|
|
|
|
operator WorkerProto::ReadConn()
|
|
|
|
{
|
|
|
|
return WorkerProto::ReadConn{
|
|
|
|
.from = from,
|
|
|
|
.version = protoVersion,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Coercion to `WorkerProto::WriteConn`. This makes it easy to use the
|
|
|
|
* factored out serve protocol serializers with a
|
|
|
|
* `LegacySSHStore::Connection`.
|
2024-05-23 23:40:05 +03:00
|
|
|
*
|
2024-07-17 16:27:15 +03:00
|
|
|
* The serve protocol connection types are unidirectional, unlike
|
|
|
|
* this type.
|
2024-05-23 23:40:05 +03:00
|
|
|
*/
|
2024-07-17 16:27:15 +03:00
|
|
|
operator WorkerProto::WriteConn()
|
|
|
|
{
|
|
|
|
return WorkerProto::WriteConn{
|
|
|
|
.to = to,
|
|
|
|
.version = protoVersion,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2024-05-23 23:40:05 +03:00
|
|
|
|
2024-07-17 16:27:15 +03:00
|
|
|
struct WorkerProto::BasicClientConnection : WorkerProto::BasicConnection
|
|
|
|
{
|
2024-05-23 23:40:05 +03:00
|
|
|
/**
|
|
|
|
* Flush to direction
|
|
|
|
*/
|
|
|
|
virtual ~BasicClientConnection();
|
|
|
|
|
|
|
|
virtual void closeWrite() = 0;
|
|
|
|
|
|
|
|
std::exception_ptr processStderrReturn(Sink * sink = 0, Source * source = 0, bool flush = true);
|
|
|
|
|
|
|
|
void processStderr(bool * daemonException, Sink * sink = 0, Source * source = 0, bool flush = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Establishes connection, negotiating version.
|
|
|
|
*
|
2024-07-19 16:48:19 +03:00
|
|
|
* @return the minimum version supported by both sides and the set
|
|
|
|
* of protocol features supported by both sides.
|
2024-05-23 23:40:05 +03:00
|
|
|
*
|
|
|
|
* @param to Taken by reference to allow for various error handling
|
|
|
|
* mechanisms.
|
|
|
|
*
|
|
|
|
* @param from Taken by reference to allow for various error
|
|
|
|
* handling mechanisms.
|
|
|
|
*
|
|
|
|
* @param localVersion Our version which is sent over
|
2024-07-19 16:48:19 +03:00
|
|
|
*
|
|
|
|
* @param features The protocol features that we support
|
2024-05-23 23:40:05 +03:00
|
|
|
*/
|
2024-07-19 16:48:19 +03:00
|
|
|
// FIXME: this should probably be a constructor.
|
|
|
|
static std::tuple<Version, std::set<Feature>> handshake(
|
|
|
|
BufferedSink & to,
|
|
|
|
Source & from,
|
|
|
|
WorkerProto::Version localVersion,
|
|
|
|
const std::set<Feature> & supportedFeatures);
|
2024-05-23 23:40:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* After calling handshake, must call this to exchange some basic
|
|
|
|
* information abou the connection.
|
|
|
|
*/
|
|
|
|
ClientHandshakeInfo postHandshake(const StoreDirConfig & store);
|
|
|
|
|
|
|
|
void addTempRoot(const StoreDirConfig & remoteStore, bool * daemonException, const StorePath & path);
|
|
|
|
|
|
|
|
StorePathSet queryValidPaths(
|
|
|
|
const StoreDirConfig & remoteStore,
|
|
|
|
bool * daemonException,
|
|
|
|
const StorePathSet & paths,
|
|
|
|
SubstituteFlag maybeSubstitute);
|
|
|
|
|
|
|
|
UnkeyedValidPathInfo queryPathInfo(const StoreDirConfig & store, bool * daemonException, const StorePath & path);
|
|
|
|
|
|
|
|
void putBuildDerivationRequest(
|
|
|
|
const StoreDirConfig & store,
|
|
|
|
bool * daemonException,
|
|
|
|
const StorePath & drvPath,
|
|
|
|
const BasicDerivation & drv,
|
|
|
|
BuildMode buildMode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the response, must be paired with
|
|
|
|
* `putBuildDerivationRequest`.
|
|
|
|
*/
|
|
|
|
BuildResult getBuildDerivationResponse(const StoreDirConfig & store, bool * daemonException);
|
|
|
|
|
|
|
|
void narFromPath(
|
|
|
|
const StoreDirConfig & store,
|
|
|
|
bool * daemonException,
|
|
|
|
const StorePath & path,
|
|
|
|
std::function<void(Source &)> fun);
|
|
|
|
|
|
|
|
void importPaths(const StoreDirConfig & store, bool * daemonException, Source & source);
|
|
|
|
};
|
|
|
|
|
2024-07-17 16:27:15 +03:00
|
|
|
struct WorkerProto::BasicServerConnection : WorkerProto::BasicConnection
|
2024-05-23 23:40:05 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Establishes connection, negotiating version.
|
|
|
|
*
|
|
|
|
* @return the version provided by the other side of the
|
|
|
|
* connection.
|
|
|
|
*
|
|
|
|
* @param to Taken by reference to allow for various error handling
|
|
|
|
* mechanisms.
|
|
|
|
*
|
|
|
|
* @param from Taken by reference to allow for various error
|
|
|
|
* handling mechanisms.
|
|
|
|
*
|
|
|
|
* @param localVersion Our version which is sent over
|
2024-07-19 16:48:19 +03:00
|
|
|
*
|
|
|
|
* @param features The protocol features that we support
|
2024-05-23 23:40:05 +03:00
|
|
|
*/
|
2024-07-19 16:48:19 +03:00
|
|
|
// FIXME: this should probably be a constructor.
|
|
|
|
static std::tuple<Version, std::set<Feature>> handshake(
|
|
|
|
BufferedSink & to,
|
|
|
|
Source & from,
|
|
|
|
WorkerProto::Version localVersion,
|
|
|
|
const std::set<Feature> & supportedFeatures);
|
2024-05-23 23:40:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* After calling handshake, must call this to exchange some basic
|
|
|
|
* information abou the connection.
|
|
|
|
*/
|
|
|
|
void postHandshake(const StoreDirConfig & store, const ClientHandshakeInfo & info);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|