internal void Accepting() { try { if (Common.IsSocketConnected(this.UnderlyingSocket)) { if (this.IsSendingStarted) { return; } if (this.UnderlyingSocket.Available > 0) { this.Status = StatusCodes.Waiting; this.currentTimeout = 0; byte[] clientData = this.Read(); if (clientData == null || clientData.Length == 0) { this.Close(); return; } Array.Resize(ref this.reqBuffer, this.reqBuffer.Length + clientData.Length); Array.Copy( clientData, 0, this.reqBuffer, this.reqBuffer.Length - clientData.Length, clientData.Length); this.IsSendingStarted = true; if (this.Controller.Status == ProxyController.ControllerStatus.None) { this.Close(); } else if (Http.IsHttp(this.reqBuffer)) { Http.Handle(this.reqBuffer, this); } else if (Https.IsHttps(this.reqBuffer)) { Https.Handle(this.reqBuffer, this); } else if (Socks.IsSocks(this.reqBuffer) && this.Controller.Status.HasFlag(ProxyController.ControllerStatus.Proxy)) { Socks.Handle(this.reqBuffer, this); } else { this.IsSendingStarted = false; } } else if (this.currentTimeout == Math.Min(this.NoDataTimeOut * 1000, 30000) || this.reqBuffer.Length >= 100) { if (this.reqBuffer.Length != 0) { this.Close( "Unknown proxy connection", "Header: " + Encoding.ASCII.GetString(this.reqBuffer), ErrorRenderer.HttpHeaderCode.C501NotImplemented); } } this.currentTimeout++; } else { this.Close(); } } catch (Exception e) { this.Close(e.Message, e.StackTrace); } }
public bool SmartStatusCallbackForDirectConnections(ServerType currentActiveServer, bool success, bool isSocks) { if (this.IsSmartForwarderEnable) { SmartPear smart = this.Controller.SmartPear; if (!success) { if (smart.ForwarderHttpsEnable && (!isSocks || smart.ForwarderSocksEnable) && smart.DetectorTimeoutEnable) { this.IsSmartForwarderEnable = false; if (isSocks) { Socks.DirectHandle( this, currentActiveServer.GetRequestedAddress(), currentActiveServer.GetRequestedPort(), this.SmartRequestBuffer); } else { Https.DirectHandle( this, currentActiveServer.GetRequestedAddress(), currentActiveServer.GetRequestedPort(), this.SmartRequestBuffer); } return(false); } } else { if (smart.ForwarderHttpsEnable && (!isSocks || smart.ForwarderSocksEnable) && smart.DetectorDnsPoisoningEnable && currentActiveServer.UnderlyingSocket != null) { if (currentActiveServer.UnderlyingSocket.RemoteEndPoint != null && smart.DetectorDnsPoisoningRegEx.IsMatch( ((IPEndPoint)currentActiveServer.UnderlyingSocket.RemoteEndPoint).Address.ToString())) { this.IsSmartForwarderEnable = false; if (isSocks) { Socks.DirectHandle( this, currentActiveServer.GetRequestedAddress(), currentActiveServer.GetRequestedPort(), this.SmartRequestBuffer); } else { Https.DirectHandle( this, currentActiveServer.GetRequestedAddress(), currentActiveServer.GetRequestedPort(), this.SmartRequestBuffer); } return(false); } } } } return(true); }