feat: remote dns for sing

This commit is contained in:
cubemaze
2023-09-21 12:34:03 +08:00
parent b85a78209a
commit cecfffd081
10 changed files with 136 additions and 16 deletions

View File

@@ -5,9 +5,10 @@ import (
)
type SingConfig struct {
LogConfig SingLogConfig `json:"Log"`
NtpConfig SingNtpConfig `json:"NTP"`
OriginalPath string `json:"OriginalPath"`
LogConfig SingLogConfig `json:"Log"`
NtpConfig SingNtpConfig `json:"NTP"`
DnsConfigPath string `json:"DnsConfigPath"`
OriginalPath string `json:"OriginalPath"`
}
type SingLogConfig struct {
@@ -35,6 +36,7 @@ type SingOptions struct {
EnableProxyProtocol bool `json:"EnableProxyProtocol"`
TCPFastOpen bool `json:"EnableTFO"`
SniffEnabled bool `json:"EnableSniff"`
EnableDNS bool `json:"EnableDNS"`
DomainStrategy option.DomainStrategy `json:"DomainStrategy"`
SniffOverrideDestination bool `json:"SniffOverrideDestination"`
FallBackConfigs *FallBackConfigForSing `json:"FallBackConfigs"`
@@ -59,6 +61,7 @@ type FallBack struct {
func NewSingOptions() *SingOptions {
return &SingOptions{
EnableDNS: false,
EnableProxyProtocol: false,
TCPFastOpen: false,
SniffEnabled: true,

View File

@@ -5,10 +5,12 @@ import (
"github.com/fsnotify/fsnotify"
"log"
"path"
"path/filepath"
"strings"
"time"
)
func (p *Conf) Watch(filePath, dnsPath string, reload func()) error {
func (p *Conf) Watch(filePath, xDnsPath string, sDnsPath string, reload func()) error {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return fmt.Errorf("new watcher error: %s", err)
@@ -28,9 +30,10 @@ func (p *Conf) Watch(filePath, dnsPath string, reload func()) error {
pre = time.Now()
go func() {
time.Sleep(5 * time.Second)
if e.Name == dnsPath {
switch filepath.Base(strings.TrimSuffix(e.Name, "~")) {
case filepath.Base(xDnsPath), filepath.Base(sDnsPath):
log.Println("DNS file changed, reloading...")
} else {
default:
log.Println("config dir changed, reloading...")
}
*p = *New()
@@ -52,8 +55,14 @@ func (p *Conf) Watch(filePath, dnsPath string, reload func()) error {
if err != nil {
return fmt.Errorf("watch file error: %s", err)
}
if dnsPath != "" {
err = watcher.Add(path.Dir(dnsPath))
if xDnsPath != "" {
err = watcher.Add(path.Dir(xDnsPath))
if err != nil {
return fmt.Errorf("watch dns file error: %s", err)
}
}
if sDnsPath != "" {
err = watcher.Add(path.Dir(sDnsPath))
if err != nil {
return fmt.Errorf("watch dns file error: %s", err)
}