getPeerSubScope method

ResourceScopeImpl getPeerSubScope(
  1. PeerId peerId,
  2. Limiter limiter,
  3. ResourceScopeImpl systemScope
)

Implementation

ResourceScopeImpl getPeerSubScope(PeerId peerId, Limiter limiter, ResourceScopeImpl systemScope) {
  // Logging added
  final parentStat = this.stat;
  print('DEBUG: ProtocolScopeImpl ($name) getPeerSubScope for $peerId. Parent streams: In=${parentStat.numStreamsInbound}, Out=${parentStat.numStreamsOutbound}.');

  return _peerSubScopes.putIfAbsent(peerId, () {
    print('DEBUG: ProtocolScopeImpl ($name) creating new peer sub-scope for $peerId.');
    final peerProtocolLimit = limiter.getProtocolPeerLimits(this.protocol, peerId);
    final scopeName = 'protocol:${protocol.toString()}-peer:${peerId.toString()}';

    final newPeerSubScope = ResourceScopeImpl(
      peerProtocolLimit,
      scopeName,
      edges: [this, systemScope], // Parent is this protocol scope and system scope
    );
    newPeerSubScope.incRef(); // This sub-scope is now in use
    return newPeerSubScope;
  });
}