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