From c89d6b9b63b629ff936a56855be5689523910c58 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 10 Feb 2014 07:43:13 -0500 Subject: nix-store --serve: Use a versioned protocol Signed-off-by: Shea Levy --- src/download-via-ssh/download-via-ssh.cc | 28 +++++++++++++++++++++------- src/download-via-ssh/local.mk | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src/download-via-ssh') diff --git a/src/download-via-ssh/download-via-ssh.cc b/src/download-via-ssh/download-via-ssh.cc index 003d7de2bf86..be70a374fe77 100644 --- a/src/download-via-ssh/download-via-ssh.cc +++ b/src/download-via-ssh/download-via-ssh.cc @@ -4,6 +4,7 @@ #include "archive.hh" #include "affinity.hh" #include "globals.hh" +#include "serve-protocol.hh" #include #include @@ -54,7 +55,7 @@ static pair connect(string conn) { } static void substitute(pair & pipes, Path storePath, Path destPath) { - writeString("substitute", pipes.first); + writeInt(cmdSubstitute, pipes.first); writeString(storePath, pipes.first); pipes.first.flush(); restorePath(destPath, pipes.second); @@ -63,20 +64,24 @@ static void substitute(pair & pipes, Path storePath, Path dest static void query(pair & pipes) { using std::cin; - writeString("query", pipes.first); + writeInt(cmdQuery, pipes.first); for (string line; getline(cin, line);) { Strings tokenized = tokenizeString(line); string cmd = tokenized.front(); - writeString(cmd, pipes.first); tokenized.pop_front(); - foreach (Strings::iterator, i, tokenized) - writeStrings(tokenized, pipes.first); - pipes.first.flush(); if (cmd == "have") { + writeInt(qCmdHave, pipes.first); + foreach (Strings::iterator, i, tokenized) + writeStrings(tokenized, pipes.first); + pipes.first.flush(); PathSet paths = readStrings(pipes.second); foreach (PathSet::iterator, i, paths) cout << *i << endl; } else if (cmd == "info") { + writeInt(qCmdInfo, pipes.first); + foreach (Strings::iterator, i, tokenized) + writeStrings(tokenized, pipes.first); + pipes.first.flush(); for (Path path = readString(pipes.second); !path.empty(); path = readString(pipes.second)) { cout << path << endl; cout << readString(pipes.second) << endl; @@ -91,7 +96,6 @@ static void query(pair & pipes) { throw Error(format("Unknown substituter query `%1%'") % cmd); cout << endl; } - writeString("", pipes.first); } void run(Strings args) @@ -106,6 +110,16 @@ void run(Strings args) pair pipes = connect(settings.sshSubstituterHosts.front()); + /* Exchange the greeting */ + writeInt(SERVE_MAGIC_1, pipes.first); + pipes.first.flush(); + unsigned int magic = readInt(pipes.second); + if (magic != SERVE_MAGIC_2) + throw Error("protocol mismatch"); + readInt(pipes.second); // Server version, unused for now + writeInt(SERVE_PROTOCOL_VERSION, pipes.first); + pipes.first.flush(); + Strings::iterator i = args.begin(); if (*i == "--query") query(pipes); diff --git a/src/download-via-ssh/local.mk b/src/download-via-ssh/local.mk index 92bf1159469d..80f4c385acb3 100644 --- a/src/download-via-ssh/local.mk +++ b/src/download-via-ssh/local.mk @@ -6,4 +6,6 @@ download-via-ssh_SOURCES := $(d)/download-via-ssh.cc download-via-ssh_INSTALL_DIR := $(libexecdir)/nix/substituters +download-via-ssh_CXXFLAGS = -Isrc/nix-store + download-via-ssh_LIBS = libmain libstore libutil libformat -- cgit 1.4.1