配置重命名
This commit is contained in:
parent
8df6d3d368
commit
eef6d573f4
@ -8,9 +8,9 @@ namespace FastGithub
|
|||||||
public class DomainConfig
|
public class DomainConfig
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否不发送SNI
|
/// 是否发送SNI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool NoSni { get; set; } = true;
|
public bool TlsSni { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 目的地
|
/// 目的地
|
||||||
|
|||||||
@ -20,16 +20,16 @@ namespace FastGithub
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取信任dns
|
/// 未污染的dns
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AllowNull]
|
[AllowNull]
|
||||||
public IPEndPoint TrustedDns { get; private set; }
|
public IPEndPoint PureDns { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取非信任dns
|
/// 速度快的dns
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AllowNull]
|
[AllowNull]
|
||||||
public IPEndPoint UnTrustedDns { get; private set; }
|
public IPEndPoint FastDns { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取域名配置
|
/// 获取域名配置
|
||||||
@ -54,8 +54,8 @@ namespace FastGithub
|
|||||||
private void Init(FastGithubOptions options)
|
private void Init(FastGithubOptions options)
|
||||||
{
|
{
|
||||||
this.domainConfigCache = new ConcurrentDictionary<string, DomainConfig?>();
|
this.domainConfigCache = new ConcurrentDictionary<string, DomainConfig?>();
|
||||||
this.TrustedDns = options.TrustedDns.ToIPEndPoint();
|
this.PureDns = options.PureDns.ToIPEndPoint();
|
||||||
this.UnTrustedDns = options.UntrustedDns.ToIPEndPoint();
|
this.FastDns = options.FastDns.ToIPEndPoint();
|
||||||
this.DomainConfigs = options.DomainConfigs.ToDictionary(kv => new DomainMatch(kv.Key), kv => kv.Value);
|
this.DomainConfigs = options.DomainConfigs.ToDictionary(kv => new DomainMatch(kv.Key), kv => kv.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,14 +8,14 @@ namespace FastGithub
|
|||||||
public class FastGithubOptions
|
public class FastGithubOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 受信任的dns服务
|
/// 未污染的dns
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DnsConfig TrustedDns { get; set; } = new DnsConfig { IPAddress = "127.0.0.1", Port = 5533 };
|
public DnsConfig PureDns { get; set; } = new DnsConfig { IPAddress = "127.0.0.1", Port = 5533 };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 不受信任的dns服务
|
/// 速度快的dns
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DnsConfig UntrustedDns { get; set; } = new DnsConfig { IPAddress = "114.114.114.114", Port = 53 };
|
public DnsConfig FastDns { get; set; } = new DnsConfig { IPAddress = "114.114.114.114", Port = 53 };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 代理的域名配置
|
/// 代理的域名配置
|
||||||
|
|||||||
@ -82,7 +82,7 @@ namespace FastGithub.Dns
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.LogInformation("dns服务启动成功");
|
this.logger.LogInformation("dns服务启动成功");
|
||||||
var secondary = this.fastGithubConfig.UnTrustedDns.Address;
|
var secondary = this.fastGithubConfig.FastDns.Address;
|
||||||
this.dnsAddresses = this.SetNameServers(IPAddress.Loopback, secondary);
|
this.dnsAddresses = this.SetNameServers(IPAddress.Loopback, secondary);
|
||||||
FlushResolverCache();
|
FlushResolverCache();
|
||||||
|
|
||||||
|
|||||||
@ -36,12 +36,12 @@ namespace FastGithub.Dns
|
|||||||
this.fastGithubConfig = fastGithubConfig;
|
this.fastGithubConfig = fastGithubConfig;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
this.requestResolver = new UdpRequestResolver(fastGithubConfig.UnTrustedDns);
|
this.requestResolver = new UdpRequestResolver(fastGithubConfig.FastDns);
|
||||||
options.OnChange(opt => DnsConfigChanged(opt.UntrustedDns));
|
options.OnChange(opt => OptionsChanged(opt));
|
||||||
|
|
||||||
void DnsConfigChanged(DnsConfig config)
|
void OptionsChanged(FastGithubOptions opt)
|
||||||
{
|
{
|
||||||
var dns = config.ToIPEndPoint();
|
var dns = opt.FastDns.ToIPEndPoint();
|
||||||
this.requestResolver = new UdpRequestResolver(dns);
|
this.requestResolver = new UdpRequestResolver(dns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ namespace FastGithub.ReverseProxy
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var dns = this.fastGithubConfig.TrustedDns;
|
var dns = this.fastGithubConfig.PureDns;
|
||||||
var dnsClient = new DnsClient(dns);
|
var dnsClient = new DnsClient(dns);
|
||||||
var addresses = await dnsClient.Lookup(domain, DNS.Protocol.RecordType.A, cancellationToken);
|
var addresses = await dnsClient.Lookup(domain, DNS.Protocol.RecordType.A, cancellationToken);
|
||||||
var address = addresses?.FirstOrDefault();
|
var address = addresses?.FirstOrDefault();
|
||||||
@ -80,7 +80,7 @@ namespace FastGithub.ReverseProxy
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var dns = this.fastGithubConfig.TrustedDns;
|
var dns = this.fastGithubConfig.PureDns;
|
||||||
throw new FastGithubException($"dns({dns}):{ex.Message}", ex);
|
throw new FastGithubException($"dns({dns}):{ex.Message}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,9 +47,9 @@ namespace FastGithub.ReverseProxy
|
|||||||
}
|
}
|
||||||
|
|
||||||
var destinationPrefix = GetDestinationPrefix(host, domainConfig.Destination);
|
var destinationPrefix = GetDestinationPrefix(host, domainConfig.Destination);
|
||||||
var httpClient = domainConfig.NoSni
|
var httpClient = domainConfig.TlsSni
|
||||||
? new HttpMessageInvoker(this.noSniHttpClientHanlder, disposeHandler: false)
|
? new HttpMessageInvoker(this.sniHttpClientHanlder, disposeHandler: false)
|
||||||
: new HttpMessageInvoker(this.sniHttpClientHanlder, disposeHandler: false);
|
: new HttpMessageInvoker(this.noSniHttpClientHanlder, disposeHandler: false);
|
||||||
|
|
||||||
var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient);
|
var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient);
|
||||||
await ResponseErrorAsync(context, error);
|
await ResponseErrorAsync(context, error);
|
||||||
|
|||||||
@ -1,68 +1,68 @@
|
|||||||
{
|
{
|
||||||
"FastGithub": {
|
"FastGithub": {
|
||||||
"TrustedDns": { // 用于解析DomainConfigs的域名,解析准确
|
"PureDns": { // 用于解析DomainConfigs的域名
|
||||||
"IPAddress": "127.0.0.1",
|
"IPAddress": "127.0.0.1",
|
||||||
"Port": 5533 // 5533指向dnscrypt-proxy
|
"Port": 5533 // 5533指向dnscrypt-proxy
|
||||||
},
|
},
|
||||||
"UnTrustedDns": { // 用于解析不在DomainConfigs的域名,解析速度快
|
"FastDns": { // 用于解析不在DomainConfigs的域名
|
||||||
"IPAddress": "114.114.114.114",
|
"IPAddress": "114.114.114.114",
|
||||||
"Port": 53
|
"Port": 53
|
||||||
},
|
},
|
||||||
"DomainConfigs": { // 域名的*表示0到多个任意字符
|
"DomainConfigs": { // 域名的*表示0到多个任意字符
|
||||||
"github.com": {
|
"github.com": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"githubstatus.com": {
|
"githubstatus.com": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"*.github.com": {
|
"*.github.com": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"*.github.io": {
|
"*.github.io": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"*.githubapp.com": {
|
"*.githubapp.com": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"*.githubassets.com": {
|
"*.githubassets.com": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"*.githubusercontent.com": {
|
"*.githubusercontent.com": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"*github*.s3.amazonaws.com": {
|
"*github*.s3.amazonaws.com": {
|
||||||
"NoSni": true,
|
"TlsSni": false,
|
||||||
"Destination": null
|
"Destination": null
|
||||||
},
|
},
|
||||||
"ajax.googleapis.com": {
|
"ajax.googleapis.com": {
|
||||||
"NoSni": false,
|
"TlsSni": true,
|
||||||
"Destination": "https://gapis.geekzu.org/ajax/"
|
"Destination": "https://gapis.geekzu.org/ajax/"
|
||||||
},
|
},
|
||||||
"fonts.googleapis.com": {
|
"fonts.googleapis.com": {
|
||||||
"NoSni": false,
|
"TlsSni": true,
|
||||||
"Destination": "https://fonts.geekzu.org/"
|
"Destination": "https://fonts.geekzu.org/"
|
||||||
},
|
},
|
||||||
"themes.googleusercontent.com": {
|
"themes.googleusercontent.com": {
|
||||||
"NoSni": false,
|
"TlsSni": true,
|
||||||
"Destination": "https://gapis.geekzu.org/g-themes/"
|
"Destination": "https://gapis.geekzu.org/g-themes/"
|
||||||
},
|
},
|
||||||
"fonts.gstatic.com": {
|
"fonts.gstatic.com": {
|
||||||
"NoSni": false,
|
"TlsSni": true,
|
||||||
"Destination": "https://gapis.geekzu.org/g-fonts/"
|
"Destination": "https://gapis.geekzu.org/g-fonts/"
|
||||||
},
|
},
|
||||||
"secure.gravatar.com": {
|
"secure.gravatar.com": {
|
||||||
"NoSni": false,
|
"TlsSni": true,
|
||||||
"Destination": "https://sdn.geekzu.org/"
|
"Destination": "https://sdn.geekzu.org/"
|
||||||
},
|
},
|
||||||
"*.gravatar.com": {
|
"*.gravatar.com": {
|
||||||
"NoSni": false,
|
"TlsSni": true,
|
||||||
"Destination": "https://fdn.geekzu.org/"
|
"Destination": "https://fdn.geekzu.org/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user