private async Task LoadAdapterConfigs() { loadProgressBar.Visibility = Visibility.Visible; try { var directory = await ConfigUtils.AdapterConfigFolderTask; var files = await directory.GetFilesAsync(); adapterConfigs.Clear(); foreach (var config in await Task.WhenAll(files.Select( f => AdapterConfig.GetConfigFromFilePath(f.Path).AsTask()))) { adapterConfigs.Add(config); } } catch (Exception ex) { await UiUtils.NotifyUser("Error loading config list: " + ex.ToString()); Frame.GoBack(); } finally { loadProgressBar.Visibility = Visibility.Collapsed; } }
private async Task LoadAdapterConfigs() { var directory = await Utils.GetAdapterConfigDirectory(); var files = await directory.GetFilesAsync(); adapterConfigs.Clear(); foreach (var config in files.Select(f => AdapterConfig.GetConfigFromFilePath(f.Path))) { adapterConfigs.Add(config); } }
public void Connect(VpnChannel channel) { State = VpnPluginState.Connecting; LogLine("Connecting", channel); try { var transport = new DatagramSocket(); channel.AssociateTransport(transport, null); DebugVpnContext context = null; if (channel.PlugInContext == null) { LogLine("Initializing new context", channel); #if YT_MOCK channel.PlugInContext = context = new DebugVpnContext(); #else var configPath = AdapterConfig.GetDefaultConfigFilePath(); if (string.IsNullOrEmpty(configPath)) { channel.TerminateConnection("Config not set"); return; } try { var config = AdapterConfig.GetConfigFromFilePath(configPath); if (config == null) { throw new Exception("Cannot read config file."); } } catch (Exception ex) { channel.TerminateConnection("Error reading config file:" + ex.Message); } channel.PlugInContext = context = new DebugVpnContext("9008"); #endif } else { LogLine("Context exists", channel); context = (DebugVpnContext)channel.PlugInContext; } transport.BindEndpointAsync(new HostName("127.0.0.1"), "9007").AsTask().ContinueWith(t => { LogLine("Binded", channel); }).Wait(); #if !YT_MOCK context.Init(); #endif /* var rport = context.Init(transport.Information.LocalPort, str => * { * LogLine(str, channel); * return null; * }); */ var rport = "9008"; transport.ConnectAsync(new HostName("127.0.0.1"), rport).AsTask().ContinueWith(t => { LogLine("r Connected", channel); }); VpnRouteAssignment routeScope = new VpnRouteAssignment() { ExcludeLocalSubnets = true }; var inclusionRoutes = routeScope.Ipv4InclusionRoutes; // myip.ipip.net //inclusionRoutes.Add(new VpnRoute(new HostName("36.99.18.134"), 32)); // qzworld.net //inclusionRoutes.Add(new VpnRoute(new HostName("188.166.248.242"), 32)); // DNS server inclusionRoutes.Add(new VpnRoute(new HostName("1.1.1.1"), 32)); // main CIDR inclusionRoutes.Add(new VpnRoute(new HostName("172.17.0.0"), 16)); var assignment = new VpnDomainNameAssignment(); var dnsServers = new[] { // DNS servers new HostName("1.1.1.1"), }; assignment.DomainNameList.Add(new VpnDomainNameInfo(".", VpnDomainNameType.Suffix, dnsServers, new HostName[] { })); var now = DateTime.Now; LogLine("Starting transport", channel); channel.StartWithMainTransport( new[] { new HostName("192.168.3.1") }, null, null, routeScope, assignment, 1500u, 1512u, false, transport ); var delta = DateTime.Now - now; LogLine($"Finished starting transport in {delta.TotalMilliseconds} ms.", channel); LogLine("Connected", channel); State = VpnPluginState.Connected; } catch (Exception ex) { LogLine("Error connecting", channel); LogLine(ex.Message, channel); LogLine(ex.StackTrace, channel); channel.TerminateConnection("Cannot connect to local tunnel"); State = VpnPluginState.Disconnected; } }
public void Connect(VpnChannel channel) { State = VpnPluginState.Connecting; DebugLogger.Logger = s => { channel.LogDiagnosticMessage(s); }; DebugLogger.Log("Starting connection to VPN tunnel"); try { var transport = new DatagramSocket(); channel.AssociateTransport(transport, null); DebugLogger.Log("Initializing context"); #if !YT_MOCK var configPath = AdapterConfig.GetDefaultConfigFilePath(); if (string.IsNullOrEmpty(configPath)) { channel.TerminateConnection("Default server configuration not set. Please launch YtFlow app and select a server configuration as default."); return; } try { var config = AdapterConfig.GetConfigFromFilePath(configPath); if (config == null) { channel.TerminateConnection("Could not read server configuration."); return; } } catch (Exception ex) { channel.TerminateConnection("Error reading server configuration: " + ex.ToString()); return; } #endif DebugLogger.Log("Config read, binding endpoint"); if (!transport.BindEndpointAsync(new HostName("127.0.0.1"), string.Empty).AsTask().ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { DebugLogger.Log("Error binding endpoint: " + t.Exception.ToString()); return(false); } else { DebugLogger.Log("Binded"); return(true); } }).Result) { return; } DebugLogger.Log("Endpoint binded, init context"); var rport = context.Init(int.Parse(transport.Information.LocalPort)).ToString(); DebugLogger.Log("Context initialized"); /* var rport = context.Init(transport.Information.LocalPort, str => * { * LogLine(str, channel); * return null; * }); */ DebugLogger.Log("Connecting to local packet processor"); if (!transport.ConnectAsync(new HostName("127.0.0.1"), rport).AsTask().ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { channel.TerminateConnection("Error connecting to local packet processor: " + t.Exception.ToString()); DebugLogger.Log("Local packet processor connected"); return(false); } else { return(true); } }).Result) { return; } DebugLogger.Log("Connected to local packet processor"); VpnRouteAssignment routeScope = new VpnRouteAssignment() { ExcludeLocalSubnets = true }; var inclusionRoutes = routeScope.Ipv4InclusionRoutes; // DNS server inclusionRoutes.Add(new VpnRoute(new HostName("1.1.1.1"), 32)); // main CIDR inclusionRoutes.Add(new VpnRoute(new HostName("11.17.0.0"), 16)); // proxy inclusionRoutes.Add(new VpnRoute(new HostName("172.17.255.0"), 24)); var assignment = new VpnDomainNameAssignment(); assignment.DomainNameList.Add(new VpnDomainNameInfo( ".", VpnDomainNameType.Suffix, new[] { new HostName("1.1.1.1") }, Array.Empty <HostName>())); var now = DateTime.Now; DebugLogger.Log("Starting transport"); channel.StartWithMainTransport( new[] { new HostName("192.168.3.1") }, null, null, routeScope, assignment, 1500u, 1512u, false, transport ); var delta = DateTime.Now - now; _ = context.u.SendAsync(new byte[] { 0 }, 1, context.pluginEndpoint); DebugLogger.Log($"Transport started in {delta.TotalMilliseconds} ms."); State = VpnPluginState.Connected; } catch (Exception ex) { var msg = "Error connecting to VPN tunnel: " + ex.ToString(); channel.TerminateConnection(msg); DebugLogger.Log(msg); State = VpnPluginState.Disconnected; } }