Improve "Connect to desktop" diagnostic step

Summary:
This does two things:
1. Change "Connect to desktop" to say which connection it's establishing instead, which makes it clearer what's actually happening. This step really does mean establishing a connection, because what happens during that connection is asynchronous after this step completes.
2. Call step->complete() after certificate exchange connection is established. This wasn't happening before, so you'd always get "[Failed] Connect to desktop" even after a successful cert exchange.

Reviewed By: priteshrnandgaonkar

Differential Revision: D13256783

fbshipit-source-id: 5e8e3a54f52d2e0adbde4c6d82d1acc840f1eb59
This commit is contained in:
John Knox
2018-11-30 07:02:33 -08:00
committed by Facebook Github Bot
parent f15fe48fa9
commit 28e2190635

View File

@@ -1,9 +1,8 @@
/* /**
* Copyright (c) Facebook, Inc. * Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
* *
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/ */
#include "FlipperConnectionManagerImpl.h" #include "FlipperConnectionManagerImpl.h"
#include <folly/String.h> #include <folly/String.h>
@@ -117,29 +116,31 @@ void FlipperConnectionManagerImpl::startSync() {
log("Already connected"); log("Already connected");
return; return;
} }
auto connect = flipperState_->start("Connect to desktop"); bool isClientSetupStep = isCertificateExchangeNeeded();
auto step = flipperState_->start(
isClientSetupStep ? "Establish pre-setup connection"
: "Establish main connection");
try { try {
if (isCertificateExchangeNeeded()) { if (isClientSetupStep) {
doCertificateExchange(); doCertificateExchange();
return; } else {
connectSecurely();
} }
step->complete();
connectSecurely();
connect->complete();
} catch (const folly::AsyncSocketException& e) { } catch (const folly::AsyncSocketException& e) {
if (e.getType() == folly::AsyncSocketException::NOT_OPEN) { if (e.getType() == folly::AsyncSocketException::NOT_OPEN) {
// The expected code path when flipper desktop is not running. // The expected code path when flipper desktop is not running.
// Don't count as a failed attempt. // Don't count as a failed attempt.
connect->fail("Port not open"); step->fail("Port not open");
} else { } else {
log(e.what()); log(e.what());
failedConnectionAttempts_++; failedConnectionAttempts_++;
connect->fail(e.what()); step->fail(e.what());
} }
reconnect(); reconnect();
} catch (const std::exception& e) { } catch (const std::exception& e) {
log(e.what()); log(e.what());
connect->fail(e.what()); step->fail(e.what());
failedConnectionAttempts_++; failedConnectionAttempts_++;
reconnect(); reconnect();
} }