handleRequest method

  1. @override
void handleRequest(
  1. RequestState requestState
)
override

If you request anything from the nostr network put it here and the relay jit manager will try to find the right relay and use it if no relay is found the request will be blasted to all connected relays (on start seed Relays)

Implementation

@override
void handleRequest(
  RequestState requestState,
) async {
  await relayManagerLight.seedRelaysConnected;

  final ndkRequest = requestState.request;

  //clean ignore relays
  List<String> cleanIgnoreRelays = cleanRelayUrls(ignoreRelays);

  /// ["REQ", <subscription_id>, <filters1>, <filters2>, ...]
  /// user can provide multiple filters
  for (var filter in requestState.unresolvedFilters) {
    // filter different types of filters/requests because each requires a different strategy

    if ((filter.authors != null && filter.authors!.isNotEmpty)) {
      RelayJitPubkeyStrategy.handleRequest(
        globalState: globalState,
        relayManager: relayManagerLight,
        requestState: requestState,
        cacheManager: cache,
        filter: filter,
        connectedRelays: relayManagerLight.connectedRelays
            .whereType<RelayConnectivity<JitEngineRelayConnectivityData>>()
            .toList(),
        desiredCoverage: ndkRequest.desiredCoverage,
        closeOnEOSE: ndkRequest.closeOnEOSE,
        direction: ReadWriteMarker
            .writeOnly, // the author should write on the persons write relays
        ignoreRelays: cleanIgnoreRelays,
      );
      continue;
    }

    if (filter.pTags?.isNotEmpty != null && filter.pTags!.isNotEmpty) {
      RelayJitPubkeyStrategy.handleRequest(
        relayManager: relayManagerLight,
        globalState: globalState,
        requestState: requestState,
        cacheManager: cache,
        filter: filter,
        connectedRelays: relayManagerLight.connectedRelays
            .whereType<RelayConnectivity<JitEngineRelayConnectivityData>>()
            .toList(),
        desiredCoverage: ndkRequest.desiredCoverage,
        closeOnEOSE: ndkRequest.closeOnEOSE,
        direction: ReadWriteMarker
            .readOnly, // others should mention on the persons read relays
        ignoreRelays: cleanIgnoreRelays,
      );
      continue;
    }

    if (filter.search != null) {
      throw UnimplementedError("search filter not implemented yet");
    }

    // if (filter.ids != null) {
    //   throw UnimplementedError("ids filter not implemented yet");
    // }

    /// unknown filter strategy, blast to all connected relays
    RelayJitBlastAllStrategy.handleRequest(
      relayManager: relayManagerLight,
      requestState: requestState,
      filter: filter,
      connectedRelays: relayManagerLight.connectedRelays
          .whereType<RelayConnectivity<JitEngineRelayConnectivityData>>()
          .toList(),
      closeOnEOSE: requestState.request.closeOnEOSE,
    );
  }
}