From 9b7e2657623621f7b9bf168d05cc5ce925ddc08b Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 18 Jul 2015 01:29:24 -0700 Subject: [PATCH] Continue implementing client. --- src/Dispatcher.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 187e2ff06b..bb79e27126 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -200,7 +200,7 @@ void Dispatcher::ClientThreadMain(const char* server_name, unsigned int port) { continue; } - if (proto_rev == 0x0300) { + if (proto_rev >= 0x0300) { // should be server hello; if not, disconnect, but keep trying to connect if (!msg->Is(Message::kServerHello)) continue; conn.remote_id = msg->str(); @@ -208,6 +208,8 @@ void Dispatcher::ClientThreadMain(const char* server_name, unsigned int port) { msg = conn.net->incoming().pop(); } + // receive initial assignments + std::vector> incoming; while (true) { if (!msg) { // disconnected, retry @@ -216,8 +218,26 @@ void Dispatcher::ClientThreadMain(const char* server_name, unsigned int port) { continue; } if (msg->Is(Message::kServerHelloDone)) break; + if (!msg->Is(Message::kEntryAssign)) { + // unexpected message + DEBUG("received message other than entry assignment during initial handshake"); + proto_rev = 0x0300; + continue; + } + incoming.push_back(msg); + // get the next message (blocks) + msg = conn.net->incoming().pop(); } + // generate outgoing assignments + NetworkConnection::Outgoing outgoing; + + if (proto_rev >= 0x0300) + outgoing.push_back(Message::ClientHelloDone()); + + if (!outgoing.empty()) + conn.net->outgoing().push(std::move(outgoing)); + // add to connections list (the dispatcher thread will handle from here) AddConnection(std::move(conn));