/// <summary> /// Internal call to create the platform specific packet diverter. In this case, we create a /// Windows-specific diverter. /// </summary> /// <param name="ipv4HttpEp"> /// The endpoint where the proxy is listening for IPV4 HTTP connections. /// </param> /// <param name="ipv4HttpsEp"> /// The endpoint where the proxy is listening for IPV4 HTTPS connections. /// </param> /// <param name="ipv6HttpEp"> /// The endpoint where the proxy is listening for IPV6 HTTP connections. /// </param> /// <param name="ipv6HttpsEp"> /// The endpoint where the proxy is listening for IPV6 HTTPS connections. /// </param> /// <returns> /// The platform specific diverter. /// </returns> protected override IDiverter CreateDiverter(IPEndPoint ipv4HttpEp, IPEndPoint ipv4HttpsEp, IPEndPoint ipv6HttpEp, IPEndPoint ipv6HttpsEp) { var diverter = new WindowsDiverter((ushort)ipv4HttpEp.Port, (ushort)ipv4HttpsEp.Port, (ushort)ipv6HttpEp.Port, (ushort)ipv6HttpsEp.Port) { DropExternalProxies = _sourceCfg != null ? _sourceCfg.BlockExternalProxies : true }; return(diverter); }
private void OnExtension(CommonFilterServiceProvider provider) { IPCServer server = provider.IPCServer; IPathProvider paths = PlatformTypes.New <IPathProvider>(); Task.Run(async() => { ConnectivityCheck.Accessible accessible = ConnectivityCheck.Accessible.Yes; try { List <ConflictReason> conflicts = ConflictDetection.SearchConflictReason(); server.Send <List <ConflictReason> >(IpcCall.ConflictsDetected, conflicts); IFilterAgent agent = PlatformTypes.New <IFilterAgent>(); accessible = agent.CheckConnectivity(); } catch (Exception ex) { m_logger.Error(ex, "Failed to check connectivity."); } try { WindowsDiverter diverter = new WindowsDiverter(14301, 14301, 14301, 14301); diverter.ConfirmDenyFirewallAccess = this.OnAppFirewallCheck; diverter.Start(1, () => { m_logger.Info("Diverter was started successfully."); IFilterAgent agent = PlatformTypes.New <IFilterAgent>(); ConnectivityCheck.Accessible afterDiverter = agent.CheckConnectivity(); if (accessible == ConnectivityCheck.Accessible.Yes && afterDiverter != ConnectivityCheck.Accessible.Yes) { server.Send <bool>(IpcCall.InternetAccessible, false); } else { server.Send <bool>(IpcCall.InternetAccessible, true); } }); } catch (Exception ex) { m_logger.Error($"Error occurred while starting the diverter."); LoggerUtil.RecursivelyLogException(m_logger, ex); } }); }