Skip to content

refactor relay_manager connectRelay() #289

@1-leo

Description

@1-leo

the connectRelay() has this code, returning true even when it's still connecting.
This is confusing and causes issues where you think it's connected while it's not.
We should refactor to using rxdart streams(behavior subjects) here to communicate state changes clearly to consuming functions.
I remember that we need the state of is connecting and has not failed yet

Future<Tuple<bool, String>> connectRelay({
    required String dirtyUrl,
    required ConnectionSource connectionSource,
    int connectTimeout = DEFAULT_WEB_SOCKET_CONNECT_TIMEOUT,
  }) async {
    String? url = cleanRelayUrl(dirtyUrl);
    if (url == null) {
      updateRelayConnectivity();
      return Tuple(false, "unclean url");
    }
    if (globalState.blockedRelays.contains(url)) {
      updateRelayConnectivity();
      return Tuple(false, "relay is blocked");
    }

    if (isRelayConnected(url)) {
      Logger.log.t("relay already connected: $url");
      updateRelayConnectivity();
      return Tuple(true, "");
    }

    if (isRelayConnecting(url)) {
      Logger.log.t("relay is already connecting: $url");
      updateRelayConnectivity();
      return Tuple(true, "relay is still connecting"); //<-- bad
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtoTriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions