Skip to content

Commit

Permalink
add LocalDnsServer
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaneAkaza committed May 30, 2018
1 parent 5dacd21 commit a1993b0
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 23 deletions.
6 changes: 4 additions & 2 deletions shadowsocks-csharp/Controller/Local.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class HandlerConfig : ICloneable
public Double TTL = 0; // Second
public Double connect_timeout = 0;
public int try_keep_alive = 0;
public string local_dns_servers;
public string dns_servers;
public bool fouce_local_dns_query = false;
// Server proxy
Expand All @@ -136,6 +137,7 @@ public object Clone()
obj.TTL = TTL;
obj.connect_timeout = connect_timeout;
obj.try_keep_alive = try_keep_alive;
obj.local_dns_servers = local_dns_servers;
obj.dns_servers = dns_servers;
obj.fouce_local_dns_query = fouce_local_dns_query;
obj.proxyType = proxyType;
Expand Down Expand Up @@ -873,7 +875,7 @@ private void Connect()
Logging.Info($"Connect {cfg.targetHost}:{cfg.targetPort.ToString()} via {server.server}:{server.server_port}");

ResetTimeout(cfg.TTL);
if (cfg.fouce_local_dns_query && cfg.targetHost != null)
if (cfg.targetHost != null)
{
IPAddress ipAddress;

Expand Down Expand Up @@ -948,7 +950,7 @@ private void Connect()
{
if (serverHost.IndexOf('.') >= 0)
{
ipAddress = Util.Utils.QueryDns(serverHost, cfg.dns_servers);
ipAddress = Util.Utils.QueryDns(serverHost, cfg.local_dns_servers);
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions shadowsocks-csharp/Controller/ProxyAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ private void Connect()
handler.cfg.TTL = _config.TTL;
handler.cfg.connect_timeout = _config.connectTimeout;
handler.cfg.autoSwitchOff = _config.autoBan;
if (!string.IsNullOrEmpty(_config.localDnsServer))
{
handler.cfg.local_dns_servers = _config.localDnsServer;
}
if (!string.IsNullOrEmpty(_config.dnsServer))
{
handler.cfg.dns_servers = _config.dnsServer;
Expand Down
8 changes: 4 additions & 4 deletions shadowsocks-csharp/Controller/Socks5Forwarder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ private void Connect()
}
if (ipAddress == null)
{
ipAddress = Utils.DnsBuffer.Get(_remote_host);
ipAddress = Utils.LocalDnsBuffer.Get(_remote_host);
}
}
if (ipAddress == null)
{
if (_remote_host.IndexOf('.') >= 0)
{
ipAddress = Util.Utils.QueryDns(_remote_host, _config.dnsServer);
ipAddress = Util.Utils.QueryDns(_remote_host, _config.localDnsServer);
}
else
{
Expand All @@ -318,8 +318,8 @@ private void Connect()
}
if (ipAddress != null)
{
Utils.DnsBuffer.Set(_remote_host, new IPAddress(ipAddress.GetAddressBytes()));
Utils.DnsBuffer.Sweep();
Utils.LocalDnsBuffer.Set(_remote_host, new IPAddress(ipAddress.GetAddressBytes()));
Utils.LocalDnsBuffer.Sweep();
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions shadowsocks-csharp/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class Configuration
public int localPort;
public string localAuthPassword;

public string localDnsServer;
public string dnsServer;
public int reconnectTimes;
public string balanceAlgorithm;
Expand Down Expand Up @@ -389,6 +390,7 @@ public Configuration()
keepVisitTime = 180;
connectTimeout = 5;
dnsServer = "";
localDnsServer = "";

balanceAlgorithm = "LowException";
random = true;
Expand Down Expand Up @@ -421,6 +423,7 @@ public void CopyFrom(Configuration config)
TTL = config.TTL;
connectTimeout = config.connectTimeout;
dnsServer = config.dnsServer;
localDnsServer = config.localDnsServer;
proxyEnable = config.proxyEnable;
pacDirectGoProxy = config.pacDirectGoProxy;
proxyType = config.proxyType;
Expand Down
8 changes: 8 additions & 0 deletions shadowsocks-csharp/Util/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public static LRUCache<string, IPAddress> DnsBuffer
}
}

public static LRUCache<string, IPAddress> LocalDnsBuffer
{
get
{
return dnsBuffer;
}
}

static Process current_process = Process.GetCurrentProcess();

public static void ReleaseMemory()
Expand Down
61 changes: 44 additions & 17 deletions shadowsocks-csharp/View/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions shadowsocks-csharp/View/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public SettingsForm(ShadowsocksController controller)
buttonDefault.Height = buttonDefault.Height * dpi_mul / 4;
buttonDefault.Width = buttonDefault.Width * dpi_mul / 4;
DNSText.Width = DNSText.Width * dpi_mul / 4;
LocalDNSText.Width = LocalDNSText.Width * dpi_mul / 4;
NumReconnect.Width = NumReconnect.Width * dpi_mul / 4;
NumTimeout.Width = NumTimeout.Width * dpi_mul / 4;
NumTTL.Width = NumTTL.Width * dpi_mul / 4;
Expand Down Expand Up @@ -141,6 +142,7 @@ private int SaveOldSelectedServer()
_modifiedConfiguration.TTL = Convert.ToInt32(NumTTL.Value);
_modifiedConfiguration.connectTimeout = Convert.ToInt32(NumTimeout.Value);
_modifiedConfiguration.dnsServer = DNSText.Text;
_modifiedConfiguration.localDnsServer = LocalDNSText.Text;
_modifiedConfiguration.proxyEnable = CheckSockProxy.Checked;
_modifiedConfiguration.pacDirectGoProxy = checkBoxPacProxy.Checked;
_modifiedConfiguration.proxyType = comboProxyType.SelectedIndex;
Expand Down Expand Up @@ -185,6 +187,7 @@ private void LoadSelectedServer()
NumTTL.Value = _modifiedConfiguration.TTL;
NumTimeout.Value = _modifiedConfiguration.connectTimeout;
DNSText.Text = _modifiedConfiguration.dnsServer;
LocalDNSText.Text = _modifiedConfiguration.localDnsServer;

CheckSockProxy.Checked = _modifiedConfiguration.proxyEnable;
checkBoxPacProxy.Checked = _modifiedConfiguration.pacDirectGoProxy;
Expand Down

0 comments on commit a1993b0

Please sign in to comment.