Don't send progress messages to older clients

This commit is contained in:
Eelco Dolstra 2017-08-28 18:54:23 +02:00
parent fe34b91289
commit cfc8132391
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 19 additions and 12 deletions

View file

@ -6,7 +6,7 @@ namespace nix {
#define WORKER_MAGIC_1 0x6e697863 #define WORKER_MAGIC_1 0x6e697863
#define WORKER_MAGIC_2 0x6478696f #define WORKER_MAGIC_2 0x6478696f
#define PROTOCOL_VERSION 0x113 #define PROTOCOL_VERSION 0x114
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)

View file

@ -84,6 +84,10 @@ struct TunnelLogger : public Logger
Sync<State> state_; Sync<State> state_;
unsigned int clientVersion;
TunnelLogger(unsigned int clientVersion) : clientVersion(clientVersion) { }
void enqueueMsg(const std::string & s) void enqueueMsg(const std::string & s)
{ {
auto state(state_.lock()); auto state(state_.lock());
@ -148,6 +152,7 @@ struct TunnelLogger : public Logger
void startActivity(ActivityId act, ActivityType type, void startActivity(ActivityId act, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent) override const std::string & s, const Fields & fields, ActivityId parent) override
{ {
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf; StringSink buf;
buf << STDERR_START_ACTIVITY << act << type << s << fields << parent; buf << STDERR_START_ACTIVITY << act << type << s << fields << parent;
enqueueMsg(*buf.s); enqueueMsg(*buf.s);
@ -155,6 +160,7 @@ struct TunnelLogger : public Logger
void stopActivity(ActivityId act) override void stopActivity(ActivityId act) override
{ {
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf; StringSink buf;
buf << STDERR_STOP_ACTIVITY << act; buf << STDERR_STOP_ACTIVITY << act;
enqueueMsg(*buf.s); enqueueMsg(*buf.s);
@ -162,6 +168,7 @@ struct TunnelLogger : public Logger
void result(ActivityId act, ResultType type, const Fields & fields) override void result(ActivityId act, ResultType type, const Fields & fields) override
{ {
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf; StringSink buf;
buf << STDERR_RESULT << act << type << fields; buf << STDERR_RESULT << act << type << fields;
enqueueMsg(*buf.s); enqueueMsg(*buf.s);
@ -710,17 +717,6 @@ static void processConnection(bool trusted)
{ {
MonitorFdHup monitor(from.fd); MonitorFdHup monitor(from.fd);
auto tunnelLogger = new TunnelLogger();
auto prevLogger = nix::logger;
logger = tunnelLogger;
unsigned int opCount = 0;
Finally finally([&]() {
_isInterrupted = false;
prevLogger->log(lvlDebug, fmt("%d operations", opCount));
});
/* Exchange the greeting. */ /* Exchange the greeting. */
unsigned int magic = readInt(from); unsigned int magic = readInt(from);
if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch"); if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch");
@ -731,6 +727,17 @@ static void processConnection(bool trusted)
if (clientVersion < 0x10a) if (clientVersion < 0x10a)
throw Error("the Nix client version is too old"); throw Error("the Nix client version is too old");
auto tunnelLogger = new TunnelLogger(clientVersion);
auto prevLogger = nix::logger;
logger = tunnelLogger;
unsigned int opCount = 0;
Finally finally([&]() {
_isInterrupted = false;
prevLogger->log(lvlDebug, fmt("%d operations", opCount));
});
if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from))
setAffinityTo(readInt(from)); setAffinityTo(readInt(from));