diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index e256ad1de..c89b5f5b3 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -264,14 +264,8 @@ static void performOp(TunnelLogger * logger, ref store, TrustedFlag trusted, RecursiveFlag recursive, WorkerProto::Version clientVersion, Source & from, BufferedSink & to, WorkerProto::Op op) { - WorkerProto::ReadConn rconn { - .from = from, - .version = clientVersion, - }; - WorkerProto::WriteConn wconn { - .to = to, - .version = clientVersion, - }; + WorkerProto::ReadConn rconn{from, clientVersion}; + WorkerProto::WriteConn wconn{to, clientVersion}; switch (op) { @@ -1030,10 +1024,7 @@ void processConnection( auto temp = trusted ? store->isTrustedClient() : std::optional { NotTrusted }; - WorkerProto::WriteConn wconn { - .to = to, - .version = clientVersion, - }; + WorkerProto::WriteConn wconn {to, clientVersion}; WorkerProto::write(*store, wconn, temp); } diff --git a/src/libstore/remote-store-connection.hh b/src/libstore/remote-store-connection.hh index 082874cec..1647afd0d 100644 --- a/src/libstore/remote-store-connection.hh +++ b/src/libstore/remote-store-connection.hh @@ -68,10 +68,7 @@ struct RemoteStore::Connection */ operator WorkerProto::ReadConn () { - return WorkerProto::ReadConn { - .from = from, - .version = daemonVersion, - }; + return WorkerProto::ReadConn {from, daemonVersion}; } /** @@ -84,10 +81,7 @@ struct RemoteStore::Connection */ operator WorkerProto::WriteConn () { - return WorkerProto::WriteConn { - .to = to, - .version = daemonVersion, - }; + return WorkerProto::WriteConn {to, daemonVersion}; } virtual ~Connection(); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 82181b921..d445cbcb6 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -466,7 +466,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, sink << exportMagic << printStorePath(info.path); - WorkerProto::WriteConn nested { .to = sink, .version = conn->daemonVersion }; + WorkerProto::WriteConn nested { sink, conn->daemonVersion }; WorkerProto::write(*this, nested, info.references); sink << (info.deriver ? printStorePath(*info.deriver) : "") @@ -511,14 +511,13 @@ void RemoteStore::addMultipleToStore( RepairFlag repair, CheckSigsFlag checkSigs) { + auto remoteVersion = getProtocol(); + auto source = sinkToSource([&](Sink & sink) { sink << pathsToCopy.size(); for (auto & [pathInfo, pathSource] : pathsToCopy) { WorkerProto::Serialise::write(*this, - WorkerProto::WriteConn { - .to = sink, - .version = 16, - }, + WorkerProto::WriteConn {sink, remoteVersion}, pathInfo); pathSource->drainInto(sink); } diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index e0e842060..a10e5df0a 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -368,15 +368,14 @@ void Store::addMultipleToStore( RepairFlag repair, CheckSigsFlag checkSigs) { + auto remoteVersion = getProtocol(); + auto expected = readNum(source); for (uint64_t i = 0; i < expected; ++i) { - // FIXME we should not be using the worker protocol here, let - // alone the worker protocol with a hard-coded version! + // FIXME we should not be using the worker protocol here at all! auto info = WorkerProto::Serialise::read(*this, - WorkerProto::ReadConn { - .from = source, - .version = 16, - }); + WorkerProto::ReadConn {source, remoteVersion} + ); info.ultimate = false; addToStore(info, source, repair, checkSigs); } diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index cc083a551..5f24c189f 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -72,6 +72,10 @@ struct WorkerProto struct ReadConn { Source & from; Version version; + + ReadConn(Source & from, Version version) : from(from), version(version) { + assert(version >= MIN_SUPPORTED_WORKER_PROTO_VERSION); + } }; /** @@ -81,6 +85,10 @@ struct WorkerProto struct WriteConn { Sink & to; Version version; + + WriteConn(Sink & to, Version version) : to(to), version(version) { + assert(version >= MIN_SUPPORTED_WORKER_PROTO_VERSION); + } }; /** diff --git a/tests/unit/libstore/protocol.hh b/tests/unit/libstore/protocol.hh index 7fdd3e11c..f480f4ad1 100644 --- a/tests/unit/libstore/protocol.hh +++ b/tests/unit/libstore/protocol.hh @@ -39,10 +39,8 @@ public: StringSource from { expected }; Proto::template Serialise::read( *LibStoreTest::store, - typename Proto::ReadConn { - .from = from, - .version = version, - }); + typename Proto::ReadConn {from, version} + ); }); ASSERT_EQ(got, value); @@ -60,10 +58,7 @@ public: StringSink to; Proto::write( *LibStoreTest::store, - typename Proto::WriteConn { - .to = to, - .version = version, - }, + typename Proto::WriteConn {to, version}, value); if (testAccept())