Skip to content

Commit 742c40d

Browse files
committed
New Feature: Act as global resolver
- Fixes #240
1 parent 6184ec6 commit 742c40d

5 files changed

Lines changed: 372 additions & 336 deletions

File tree

SimpleDnsCrypt/Config/Global.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public static class Global
7575
public const string BlacklistRuleFileName = "domain-blacklist.txt";
7676
public const string BlacklistFileName = "blacklist.txt";
7777

78+
public const string GlobalResolver = "0.0.0.0:53";
79+
public const string DefaultResolverIpv4 = "127.0.0.1:53";
80+
public const string DefaultResolverIpv6 = "[::1]:53";
7881

7982
/// <summary>
8083
/// List of files must exist.

SimpleDnsCrypt/Helper/LocalNetworkInterfaceManager.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.Linq;
66
using System.Net.NetworkInformation;
7+
using Caliburn.Micro;
78
using SimpleDnsCrypt.Config;
89
using SimpleDnsCrypt.Models;
910

@@ -14,6 +15,8 @@ namespace SimpleDnsCrypt.Helper
1415
/// </summary>
1516
public static class LocalNetworkInterfaceManager
1617
{
18+
private static readonly ILog Log = LogManagerHelper.Factory();
19+
1720
/// <summary>
1821
/// Get a list of the local network interfaces.
1922
/// </summary>
@@ -120,8 +123,9 @@ internal static List<DnsServer> GetDnsServerList(string localNetworkInterface)
120123
}));
121124
}
122125
}
123-
catch (Exception)
126+
catch (Exception exception)
124127
{
128+
Log.Error(exception);
125129
}
126130
return serverAddresses;
127131
}
@@ -213,8 +217,9 @@ public static bool SetNameservers(LocalNetworkInterface localNetworkInterface, L
213217
}
214218
return true;
215219
}
216-
catch (Exception)
220+
catch (Exception exception)
217221
{
222+
Log.Error(exception);
218223
return false;
219224
}
220225
}

SimpleDnsCrypt/ViewModels/LoaderViewModel.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,22 @@ private async void InitializeApplication()
150150
}
151151

152152
ProgressText = LocalizationEx.GetUiString("loader_loading_network_cards", Thread.CurrentThread.CurrentCulture);
153-
var localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(
154-
DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.ToList());
153+
154+
List<LocalNetworkInterface> localNetworkInterfaces;
155+
if (DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.Contains(Global.GlobalResolver))
156+
{
157+
var dnsServer = new List<string>
158+
{
159+
Global.DefaultResolverIpv4,
160+
Global.DefaultResolverIpv6
161+
};
162+
localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(dnsServer);
163+
}
164+
else
165+
{
166+
localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(
167+
DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.ToList());
168+
}
155169
_mainViewModel.LocalNetworkInterfaces = new BindableCollection<LocalNetworkInterface>();
156170
_mainViewModel.LocalNetworkInterfaces.AddRange(localNetworkInterfaces);
157171
_mainViewModel.Initialize();

0 commit comments

Comments
 (0)