performHandshake static method

Future<bool> performHandshake(
  1. P2PStream stream, {
  2. required bool isClient,
  3. Duration timeout = defaultTimeout,
  4. String context = 'unknown',
})

Perform protocol handshake

Client initiates handshake, server responds with acknowledgment. Returns true if handshake successful, false otherwise.

Implementation

static Future<bool> performHandshake(
  core_p2p_stream.P2PStream stream, {
  required bool isClient,
  Duration timeout = defaultTimeout,
  String context = 'unknown',
}) async {
  try {
    if (isClient) {
      return await _performClientHandshake(stream, timeout: timeout, context: context);
    } else {
      return await _performServerHandshake(stream, timeout: timeout, context: context);
    }
  } catch (e, stackTrace) {
    _logger.severe('[$context] Handshake failed: $e', e, stackTrace);
    return false;
  }
}