public static void DirectHandle( ProxyClient client, string clientConnectionAddress, ushort clientConnectionPort, byte[] firstResponse) { if (client.IsSmartForwarderEnable && client.Controller.SmartPear.ForwarderHttpsEnable && client.Controller.SmartPear.ForwarderSocksEnable) { // Is Forwarder is Enable and Client need to be forwarded by NoServer ServerType ac = new NoServer { NoDataTimeout = client.Controller.ActiveServer.NoDataTimeout }; if (client.Controller.SmartPear.DetectorTimeoutEnable) { // If we have Timeout Detector then let change timeout ac.NoDataTimeout = client.Controller.SmartPear.DetectorTimeout; } client.SmartDataSentCallbackForDirectConnections(firstResponse, true); ac.Establish( clientConnectionAddress, clientConnectionPort, client, firstResponse, (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) => thisclient.SmartDataSentCallbackForDirectConnections(data, true), (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) => thisclient.SmartDataReceivedCallbackForDirrectConnections(ref data, thisactiveServer, true), (success, thisactiveServer, thisclient) => thisclient.SmartStatusCallbackForDirectConnections(thisactiveServer, success, true)); } else { // Forwarder is Disable or Client is in proxy connection mode ServerType ac = client.Controller.ActiveServer.Clone(); if (client.Controller.SmartPear.ForwarderHttpsEnable && client.Controller.SmartPear.ForwarderSocksEnable) { // If we have forwarding enable then we need to have the receive callback ac.Establish( clientConnectionAddress, clientConnectionPort, client, firstResponse, null, (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) => thisclient.SmartDataReceivedCallbackForDirrectConnections(ref data, thisactiveServer, true)); } else { // If we don't so SmartPear is disabled ac.Establish(clientConnectionAddress, clientConnectionPort, client, firstResponse); } } }
/// <summary> /// Test the specified server /// </summary> /// <param name="activeServer"> /// The server /// </param> /// <exception cref="Exception"> /// Failed to connect to the server or server response is invalid /// </exception> public void TestServer(ServerType activeServer) { try { activeServer = activeServer.Clone(); activeServer.Establish( "google.com", 80, new ProxyClient(null, this), Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n")); int timeout = 25000; while (timeout != 0) { Thread.Sleep(100); if (activeServer.ParentClient.LastError != string.Empty) { throw new Exception(activeServer.ParentClient.LastError); } if (activeServer.IsServerValid) { return; } if (activeServer.ParentClient.IsClosed) { throw new Exception("Connection dropped by server."); } timeout -= 100; } throw new Exception("No acceptable response."); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
public static void DirectHandle( ProxyClient client, string clientConnectionAddress, ushort clientConnectionPort, byte[] firstResponse) { if (client.Controller.SmartPear.ForwarderHttpEnable && client.IsSmartForwarderEnable) { ServerType ac = new NoServer(); if (client.Controller.SmartPear.DetectorHttpCheckEnable) { ac.NoDataTimeout = client.Controller.ActiveServer.NoDataTimeout; if (client.Controller.SmartPear.DetectorTimeoutEnable) { // If we have Timeout Detector then let change timeout ac.NoDataTimeout = client.Controller.SmartPear.DetectorTimeout; } client.SmartDataSentCallbackForHttpConnections(firstResponse); ac.Establish( clientConnectionAddress, clientConnectionPort, client, firstResponse, delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) { if (IsHttp(data, true)) { thisclient.SmartCleanTheForwarder(); Handle(data, thisclient, true); return(false); } return(thisclient.SmartDataSentCallbackForHttpConnections(data)); }, (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) => thisclient.SmartDataReceivedCallbackForHttpConnections(ref data, thisactiveServer), (success, thisactiveServer, thisclient) => thisclient.SmartStatusCallbackForHttpConnections(thisactiveServer, success)); } else { ac.NoDataTimeout = client.Controller.ActiveServer.NoDataTimeout; if (client.Controller.SmartPear.DetectorTimeoutEnable) { // If we have Timeout Detector then let change timeout ac.NoDataTimeout = client.Controller.SmartPear.DetectorTimeout; } client.SmartDataSentCallbackForHttpConnections(firstResponse); ac.Establish( clientConnectionAddress, clientConnectionPort, client, firstResponse, delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) { if (IsHttp(data, true)) { Handle(data, thisclient, true); return(false); } return(thisclient.SmartDataSentCallbackForHttpConnections(data)); }, (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) => thisclient.SmartDataReceivedCallbackForHttpConnections(ref data, thisactiveServer), (success, thisactiveServer, thisclient) => thisclient.SmartStatusCallbackForHttpConnections(thisactiveServer, success)); } } else { ServerType ac = client.Controller.ActiveServer.Clone(); if (!client.IsSmartForwarderEnable && client.Controller.SmartPear.ForwarderHttpEnable && (client.Controller.SmartPear.DetectorHttpCheckEnable || client.Controller.SmartPear.DetectorDnsPoisoningEnable)) { ac.Establish( clientConnectionAddress, clientConnectionPort, client, firstResponse, delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) { if (IsHttp(data, true)) { if (client.Controller.SmartPear.ForwarderHttpEnable && !client.IsSmartForwarderEnable) { thisclient.SmartCleanTheForwarder(); } Handle(data, thisclient, true); return(false); } return(true); }, (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) => thisclient.SmartDataReceivedCallbackForHttpConnections(ref data, thisactiveServer)); } else { ac.Establish( clientConnectionAddress, clientConnectionPort, client, firstResponse, delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) { if (IsHttp(data, true)) { if (client.Controller.SmartPear.ForwarderHttpEnable && !client.IsSmartForwarderEnable) { thisclient.SmartCleanTheForwarder(); } Handle(data, thisclient, true); return(false); } return(true); }); } } }