call method

List<AddrDelay> call(
  1. List<MultiAddr> addrs
)

Call method to make this class callable as a function

Implementation

List<AddrDelay> call(List<MultiAddr> addrs) {
  final nonRelayAddrs = <MultiAddr>[];
  final relayAddrs = <MultiAddr>[];

  for (final addr in addrs) {
    bool isRelay = false;
    for (final p in addr.protocols) { // This 'p' is of type multiaddr_protocol.Protocol
      if (p.code == multiaddr_protocol.Protocols.circuit.code) { // Corrected access to P_CIRCUIT code
        isRelay = true;
        break;
      }
    }

    if (isRelay) {
      relayAddrs.add(addr);
    } else {
      nonRelayAddrs.add(addr);
    }
  }

  final result = <AddrDelay>[];
  // Add non-relay addresses first, with zero delay
  for (final addr in nonRelayAddrs) {
    result.add(AddrDelay(addr: addr, delay: Duration.zero));
  }
  // Add relay addresses next, also with zero delay for now (could add a slight delay later)
  for (final addr in relayAddrs) {
    result.add(AddrDelay(addr: addr, delay: Duration.zero));
  }

  return result;
}