Summary: This change makes WebSockets the default for Flipper on iOS. Having said that, we are introducing some logic to deal with clients connecting to older Flipper Desktop versions. The mobile client will first attempt to connect via WebSocket with the Desktop. This connection can either be secure or insecure. If that fails, it will attempt to connect via RSocket. Connection failure logic: The mobile client will attempt to connect up-to 3 times via a WebSocket. If it fails to connect, then the socket provider is switched to RSocket. As before, the mobile client will attempt to connect up-to 3 times via a RSocket. If it fails to connect, then the socket provider is switched back to WebSocket. Process repeats until a successful connection is established. Some logs that can be seen from iOS: 2021-09-15 14:31:51.193503+0100 Sample[92026:92107440] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed 2021-09-15 14:31:51.878257+0100 Sample[92026:92107440] [connection] nw_socket_handle_socket_event [C1.1:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:31:52.553729+0100 Sample[92026:92107440] [connection] nw_socket_handle_socket_event [C1.2:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:31:52.899511+0100 Sample[92026:92107442] [connection] nw_connection_get_connected_socket [C1] Client called nw_connection_get_connected_socket on unconnected nw_connection 2021-09-15 14:31:52.899664+0100 Sample[92026:92107442] TCP Conn 0x600001d384d0 Failed : error 0:61 [61] 2021-09-15 14:31:57.120120+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C2.1:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:31:57.141785+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C2.2:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:31:57.151604+0100 Sample[92026:92107483] [connection] nw_connection_get_connected_socket [C2] Client called nw_connection_get_connected_socket on unconnected nw_connection 2021-09-15 14:31:57.154312+0100 Sample[92026:92107483] TCP Conn 0x600001d7c0b0 Failed : error 0:61 [61] 2021-09-15 14:31:59.206079+0100 Sample[92026:92107483] [connection] nw_socket_handle_socket_event [C3.1:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:31:59.236824+0100 Sample[92026:92107483] [connection] nw_socket_handle_socket_event [C3.2:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:31:59.251927+0100 Sample[92026:92107439] [connection] nw_connection_get_connected_socket [C3] Client called nw_connection_get_connected_socket on unconnected nw_connection 2021-09-15 14:31:59.255963+0100 Sample[92026:92107439] TCP Conn 0x600001d1c210 Failed : error 0:61 [61] 2021-09-15 14:32:01.291303+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C4.1:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:32:01.312406+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C4.2:1] Socket SO_ERROR [61: Connection refused] 2021-09-15 14:32:01.323099+0100 Sample[92026:92107483] [connection] nw_connection_get_connected_socket [C4] Client called nw_connection_get_connected_socket on unconnected nw_connection 2021-09-15 14:32:01.326028+0100 Sample[92026:92107483] TCP Conn 0x600001d7c0b0 Failed : error 0:61 [61] flipper: Failed to connect with the current socket provider flipper: Use legacy socket provider flipper: FlipperClient::onConnected Reviewed By: passy Differential Revision: D30900471 fbshipit-source-id: 7c242ad71306803b050d0174fc22696bb74fdba5
86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <folly/io/async/EventBase.h>
|
|
#include <memory>
|
|
|
|
namespace facebook {
|
|
namespace flipper {
|
|
|
|
class FlipperSocket;
|
|
class FlipperConnectionManager;
|
|
class ConnectionContextStore;
|
|
struct FlipperConnectionEndpoint;
|
|
struct FlipperSocketBasePayload;
|
|
|
|
/**
|
|
A socket provider is responsible of the creation of FlipperSocket instances.
|
|
It also defines static factory methods that can be used to construct such
|
|
instances.
|
|
*/
|
|
class FlipperSocketProvider {
|
|
public:
|
|
virtual ~FlipperSocketProvider() {}
|
|
/**
|
|
Create an instance of FlipperSocket.
|
|
@param endpoint Endpoint to connect to.
|
|
@param payload Any configuration payload to establish a connection with
|
|
the specified endpoint.
|
|
@param eventBase A folly event base used to execute connection operations.
|
|
*/
|
|
virtual std::unique_ptr<FlipperSocket> create(
|
|
FlipperConnectionEndpoint endpoint,
|
|
std::unique_ptr<FlipperSocketBasePayload> payload,
|
|
folly::EventBase* eventBase) = 0;
|
|
/**
|
|
Create an instance of FlipperSocket.
|
|
@param endpoint Endpoint to connect to.
|
|
@param payload Any configuration payload to establish a connection with
|
|
the specified endpoint.
|
|
@param eventBase A folly event base used to execute connection operations.
|
|
@param connectionContextStore A connection context store used for obtaining
|
|
the certificate used for secure connections.
|
|
*/
|
|
virtual std::unique_ptr<FlipperSocket> create(
|
|
FlipperConnectionEndpoint endpoint,
|
|
std::unique_ptr<FlipperSocketBasePayload> payload,
|
|
folly::EventBase* eventBase,
|
|
ConnectionContextStore* connectionContextStore) = 0;
|
|
|
|
static std::unique_ptr<FlipperSocket> socketCreate(
|
|
FlipperConnectionEndpoint endpoint,
|
|
std::unique_ptr<FlipperSocketBasePayload> payload,
|
|
folly::EventBase* eventBase);
|
|
static std::unique_ptr<FlipperSocket> socketCreate(
|
|
FlipperConnectionEndpoint endpoint,
|
|
std::unique_ptr<FlipperSocketBasePayload> payload,
|
|
folly::EventBase* eventBase,
|
|
ConnectionContextStore* connectionContextStore);
|
|
|
|
static void setDefaultProvider(
|
|
std::unique_ptr<FlipperSocketProvider> provider);
|
|
|
|
/**
|
|
Shelves the current default socket provider and promotes the internal
|
|
socket provider as default.
|
|
*/
|
|
static void shelveDefault();
|
|
/**
|
|
Restores a previously shelved socket provider.
|
|
*/
|
|
static void unshelveDefault();
|
|
|
|
private:
|
|
static std::unique_ptr<FlipperSocketProvider> provider_;
|
|
static std::unique_ptr<FlipperSocketProvider> shelvedProvider_;
|
|
};
|
|
|
|
} // namespace flipper
|
|
} // namespace facebook
|