resolvePeerId method
Resolves a Peer ID to a set of network addresses.
This method attempts to find the network addresses associated with a given
Peer ID. If the Peer ID is known and has a route, the method returns the
actual addresses associated with the route, filtering out stale addresses
based on the peerAddressTTL.
If the Peer ID is unknown or has no route, the method returns the
addresses of forwarder peers that can potentially relay messages to the
target peer. The number of forwarder addresses returned is limited by
the useForwardersLimit property.
peerId The ID of the peer to resolve.
Returns an iterable of FullAddress objects representing the resolved
addresses.
Implementation
Iterable<FullAddress> resolvePeerId(PeerId peerId) {
final route = routes[peerId];
if (route == null || route.isEmpty) {
final result = <FullAddress>{};
for (final a in routes.values.where((e) => e.canForward)) {
result.addAll(a.addresses.keys);
}
return result.take(useForwardersLimit);
} else {
return route.getActualAddresses(
staleAt: _now - peerAddressTTL.inMilliseconds,
);
}
}