Пример #1
0
        public async ValueTask <QuicSecConfig> CreateSecurityConfig(X509Certificate2 certificate)
        {
            QuicSecConfig secConfig             = null;
            var           tcs                   = new TaskCompletionSource <object>();
            var           secConfigCreateStatus = MsQuicConstants.InternalError;

            var status = SecConfigCreateDelegate(
                _registrationContext,
                (uint)QUIC_SEC_CONFIG_FLAG.CERT_CONTEXT,
                certificate.Handle,
                null,
                IntPtr.Zero,
                SecCfgCreateCallbackHandler);

            MsQuicStatusException.ThrowIfFailed(status);

            void SecCfgCreateCallbackHandler(
                IntPtr context,
                uint status,
                IntPtr securityConfig)
            {
                secConfig             = new QuicSecConfig(this, securityConfig);
                secConfigCreateStatus = status;
                tcs.SetResult(null);
            }

            await tcs.Task;

            MsQuicStatusException.ThrowIfFailed(secConfigCreateStatus);

            return(secConfig);
        }
        public async Task StartAsync(CancellationToken cancellationToken = default)
        {
            _api.RegistrationOpen(Encoding.ASCII.GetBytes(_transportContext.Options.RegistrationName));

            _secConfig = await _api.CreateSecurityConfig(_transportContext.Options.Certificate);

            _session = _api.SessionOpen(_transportContext.Options.Alpn);
            _log.LogDebug(0, "Started session");

            _nativeObjPtr = _session.ListenerOpen(NativeCallbackHandler);

            SetCallbackHandler();

            _session.SetIdleTimeout(_transportContext.Options.IdleTimeout);
            _session.SetPeerBiDirectionalStreamCount(_transportContext.Options.MaxBidirectionalStreamCount);
            _session.SetPeerUnidirectionalStreamCount(_transportContext.Options.MaxBidirectionalStreamCount);

            var address = MsQuicNativeMethods.Convert(EndPoint as IPEndPoint);

            MsQuicStatusException.ThrowIfFailed(_api.ListenerStartDelegate(
                                                    _nativeObjPtr,
                                                    ref address));
        }