/// <summary> /// Creates a new packet from a stream /// </summary> /// <param name="stream">The stream to read from</param> /// <param name="connection">The associated connection</param> public Packet(Stream stream, TcpConnection connection) { TransType = TransportType.TCP; Connection = connection; _fromStream(stream, true); }
private async Task BeginLoop() { TCPConnection = new TcpConnection() { Socket = _tcp.Client, Ref = this }; using (NetworkStream stream = _tcp.GetStream()) { TCPConnection.Stream = stream; if (Certificate == null) { while (true) { Packet pkt = new Packet(stream, TCPConnection); PacketWorker.Queue.Add(new PacketWorker.QueuedPacket() { Entry = this, Packet = pkt, Rx = true }); } } else { using (SslStream str2 = new SslStream(stream)) { TCPConnection.Stream = str2; X509Certificate2Collection coll = null; if (ClientCertificate != null) { coll = new X509Certificate2Collection(ClientCertificate); } SslClientAuthenticationOptions authOpt = new SslClientAuthenticationOptions() { TargetHost = Address.Address.ToString(), CertificateRevocationCheckMode = X509RevocationMode.NoCheck, ClientCertificates = coll, RemoteCertificateValidationCallback = RemoteCertificateValidationCallback }; await str2.AuthenticateAsClientAsync(authOpt); if (!str2.IsAuthenticated) { Log.Error("Authentication to entry point failed"); return; } while (true) { Packet pkt = new Packet(str2, TCPConnection); PacketWorker.Queue.Add(new PacketWorker.QueuedPacket() { Entry = this, Packet = pkt, Rx = true }); } } } } }