public InitialLaunchState(bool fromLauncher, string?connectAddress, string?ss14Address, DnsEndPoint?connectEndpoint) { FromLauncher = fromLauncher; ConnectAddress = connectAddress; Ss14Address = ss14Address; ConnectEndpoint = connectEndpoint; }
public override bool Equals([NotNullWhen(true)] object?comparand) { DnsEndPoint?dnsComparand = comparand as DnsEndPoint; if (dnsComparand == null) { return(false); } return(_family == dnsComparand._family && _port == dnsComparand._port && _host == dnsComparand._host); }
/*/ Methods /*/ /// <inheritdoc/> public void Connect(string host, int port) { this.host = host; this.port = port; this.remoteEndPoint = new DnsEndPoint(host, port); this.argsConnect.RemoteEndPoint = this.remoteEndPoint; this.argsReceive.RemoteEndPoint = this.remoteEndPoint; foreach (var sae in this.argsSend) { sae.RemoteEndPoint = this.remoteEndPoint; } this.Connect(); }
// Called by Socket to kick off the ConnectAsync process. We'll complete the user's SAEA when it's done. // Returns true if the operation is pending, false if it completed synchronously. public bool StartConnectAsync(SocketAsyncEventArgs args, DnsEndPoint endPoint) { IAsyncResult result; Debug.Assert(!Monitor.IsEntered(_lockObject)); lock (_lockObject) { if (endPoint.AddressFamily != AddressFamily.Unspecified && endPoint.AddressFamily != AddressFamily.InterNetwork && endPoint.AddressFamily != AddressFamily.InterNetworkV6) { NetEventSource.Fail(this, $"Unexpected endpoint address family: {endPoint.AddressFamily}"); } _userArgs = args; _endPoint = endPoint; // If Cancel() was called before we got the lock, it only set the state to Canceled: we need to // fail synchronously from here. Once State.DnsQuery is set, the Cancel() call will handle calling AsyncFail. if (_state == State.Canceled) { SyncFail(new SocketException((int)SocketError.OperationAborted)); return(false); } if (_state != State.NotStarted) { NetEventSource.Fail(this, "MultipleConnectAsync.StartConnectAsync(): Unexpected object state"); } _state = State.DnsQuery; result = Dns.BeginGetHostAddresses(endPoint.Host, new AsyncCallback(DnsCallback), null); } if (result.CompletedSynchronously) { return(DoDnsCallback(result, true)); } else { return(true); } }
private static void WriteConnectRequest(IBufferWriter <byte> writer, EndPoint endPoint) { IPEndPoint? ipEndPoint = endPoint as IPEndPoint; DnsEndPoint?dnsEndPoint = endPoint as DnsEndPoint; if (ipEndPoint is null && dnsEndPoint is null) { throw new InvalidOperationException(); } if (ipEndPoint is null) { Debug.Assert(!(dnsEndPoint is null)); string host = s_idnMapping.GetAscii(dnsEndPoint.Host); int hostLength = Encoding.ASCII.GetByteCount(host); if (hostLength > byte.MaxValue) { throw new InvalidOperationException(); } int length = 7 + hostLength; Span <byte> span = writer.GetSpan(length); span[0] = 5; span[1] = 1; span[2] = 0; span[3] = 3; span[4] = (byte)Encoding.ASCII.GetBytes(host, span.Slice(5)); BinaryPrimitives.WriteUInt16BigEndian(span.Slice(5 + hostLength), (ushort)dnsEndPoint.Port); writer.Advance(length); } else if (ipEndPoint.AddressFamily == AddressFamily.InterNetwork) { const int length = 10; Span <byte> span = writer.GetSpan(length); span[0] = 5; span[1] = 1; span[2] = 0; span[3] = 1; ipEndPoint.Address.TryWriteBytes(span.Slice(4), out _); BinaryPrimitives.WriteUInt16BigEndian(span.Slice(8), (ushort)ipEndPoint.Port); writer.Advance(length); } else if (ipEndPoint.AddressFamily == AddressFamily.InterNetworkV6) { const int length = 22; Span <byte> span = writer.GetSpan(length); span[0] = 5; span[1] = 1; span[2] = 0; span[3] = 4; ipEndPoint.Address.TryWriteBytes(span.Slice(4), out _); BinaryPrimitives.WriteUInt16BigEndian(span.Slice(20), (ushort)ipEndPoint.Port); writer.Advance(length); } else { throw new InvalidOperationException(); } }
public static IDnsEndPoint?ToInterface(this DnsEndPoint?endPoint) { return(endPoint == null ? null : new DnsEndPointAdapter(endPoint)); }