// constructor for inbound connections public MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, SafeMsQuicConnectionHandle handle, bool remoteCertificateRequired = false, X509RevocationMode revocationMode = X509RevocationMode.Offline, RemoteCertificateValidationCallback?remoteCertificateValidationCallback = null, ServerCertificateSelectionCallback?serverCertificateSelectionCallback = null) { _state.Handle = handle; _state.StateGCHandle = GCHandle.Alloc(_state); _state.Connected = true; _state.RemoteCertificateRequired = remoteCertificateRequired; _state.RevocationMode = revocationMode; _state.RemoteCertificateValidationCallback = remoteCertificateValidationCallback; _state.IsServer = true; _localEndPoint = localEndPoint; _remoteEndPoint = remoteEndPoint; try { Debug.Assert(!Monitor.IsEntered(_state)); MsQuicApi.Api.SetCallbackHandlerDelegate( _state.Handle, s_connectionDelegate, GCHandle.ToIntPtr(_state.StateGCHandle)); } catch { _state.StateGCHandle.Free(); throw; } _state.TraceId = MsQuicTraceHelper.GetTraceId(_state.Handle); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(_state, $"{TraceId()} Inbound connection created"); } }
internal MsQuicListener(QuicListenerOptions options) { ArgumentNullException.ThrowIfNull(options.ListenEndPoint, nameof(options.ListenEndPoint)); _state = new State(options); _stateHandle = GCHandle.Alloc(_state); try { uint status = MsQuicApi.Api.ListenerOpenDelegate( MsQuicApi.Api.Registration, s_listenerDelegate, GCHandle.ToIntPtr(_stateHandle), out _state.Handle); QuicExceptionHelpers.ThrowIfFailed(status, "ListenerOpen failed."); } catch { _stateHandle.Free(); throw; } _state.TraceId = MsQuicTraceHelper.GetTraceId(_state.Handle); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(_state, $"{_state.TraceId} Listener created"); } _listenEndPoint = Start(options); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(_state, $"{_state.TraceId} Listener started"); } }
// constructor for outbound connections public MsQuicConnection(QuicClientConnectionOptions options) { _remoteEndPoint = options.RemoteEndPoint !; _configuration = SafeMsQuicConfigurationHandle.Create(options); _isServer = false; _remoteCertificateRequired = true; if (options.ClientAuthenticationOptions != null) { _revocationMode = options.ClientAuthenticationOptions.CertificateRevocationCheckMode; _remoteCertificateValidationCallback = options.ClientAuthenticationOptions.RemoteCertificateValidationCallback; } _state.StateGCHandle = GCHandle.Alloc(_state); try { uint status = MsQuicApi.Api.ConnectionOpenDelegate( MsQuicApi.Api.Registration, s_connectionDelegate, GCHandle.ToIntPtr(_state.StateGCHandle), out _state.Handle); QuicExceptionHelpers.ThrowIfFailed(status, "Could not open the connection."); } catch { _state.StateGCHandle.Free(); throw; } _state.TraceId = MsQuicTraceHelper.GetTraceId(_state.Handle); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(_state, $"{TraceId()} Outbound connection created"); } }
// constructor for inbound connections public MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, SafeMsQuicConnectionHandle handle, bool remoteCertificateRequired = false, X509RevocationMode revocationMode = X509RevocationMode.Offline, RemoteCertificateValidationCallback?remoteCertificateValidationCallback = null) { _state.Handle = handle; _state.StateGCHandle = GCHandle.Alloc(_state); _state.Connected = true; _isServer = true; _localEndPoint = localEndPoint; _remoteEndPoint = remoteEndPoint; _remoteCertificateRequired = remoteCertificateRequired; _revocationMode = revocationMode; _remoteCertificateValidationCallback = remoteCertificateValidationCallback; if (_remoteCertificateRequired) { // We need to link connection for the validation callback. // We need to be able to find the connection in HandleEventPeerCertificateReceived // and dispatch it as sender to validation callback. // After that Connection will be set back to null. _state.Connection = this; } try { MsQuicApi.Api.SetCallbackHandlerDelegate( _state.Handle, s_connectionDelegate, GCHandle.ToIntPtr(_state.StateGCHandle)); } catch { _state.StateGCHandle.Free(); throw; } _state.TraceId = MsQuicTraceHelper.GetTraceId(_state.Handle); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(_state, $"{TraceId()} Inbound connection created"); } }