openStream method

  1. @override
Future<StreamManagementScope> openStream(
  1. PeerId peer,
  2. Direction direction
)
override

OpenStream creates a new stream scope, initially unnegotiated. An unnegotiated stream will be initially unattached to any protocol scope and constrained by the transient scope. The caller owns the returned scope and is responsible for calling Done in order to signify the end of th scope's span.

Implementation

@override
Future<StreamManagementScope> openStream(PeerId peer, Direction direction) async {
  final concretePeerId = peer ;
  final peerScope = getPeerScopeInternal(concretePeerId); // Corrected method name

  final streamLimit = _limiter.getStreamLimits(concretePeerId);
  final streamName = 'stream-${DateTime.now().millisecondsSinceEpoch}-${peer.toString().hashCode % 10000}';
  final concreteStreamScope = StreamScopeImpl(
    this, // Pass ResourceManagerImpl instance
    streamLimit,
    streamName,
    direction,
    peerScope, // Pass the concrete PeerScopeImpl
    edges: [peerScope, _transientScope], // Reverted: PeerScope and TransientScope will propagate to SystemScope
  );

  try {
    concreteStreamScope.addStream(direction);
  } catch (e) {
    _logger.severe('$e');
    concreteStreamScope.done();
    // TODO: metrics.BlockStream(p, dir);
    rethrow; // Rethrow the exception caught from addStream
  }

  // TODO: metrics.AllowStream(p, dir);
  _logger.fine('Opened stream scope: ${concreteStreamScope.name} for peer ${peer.toString()}');
  return concreteStreamScope;
}