Refresh prepared domain every 30 minutes

This commit is contained in:
yuhan6665
2020-06-19 23:42:02 -04:00
parent 6577c46a31
commit 903352ec9c
2 changed files with 14 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ type resolved struct {
domain string
IPs []net.IP
Port int
lastResolved time.Time
ipIdx uint8
ipLock sync.Mutex
lastSwitched time.Time
@@ -97,7 +98,7 @@ func (d *ProtectedDialer) PrepareResolveChan() {
d.resolveChan = make(chan struct{})
}
func (d *ProtectedDialer) ResolveChan() <-chan struct{} {
func (d *ProtectedDialer) ResolveChan() chan struct{} {
return d.resolveChan
}
@@ -137,9 +138,10 @@ func (d *ProtectedDialer) lookupAddr(addr string) (*resolved, error) {
}
rs := &resolved{
domain: host,
IPs: IPs,
Port: portnum,
domain: host,
IPs: IPs,
Port: portnum,
lastResolved: time.Now(),
}
return rs, nil
@@ -150,7 +152,6 @@ func (d *ProtectedDialer) PrepareDomain(domainName string, closeCh <-chan struct
log.Printf("Preparing Domain: %s", domainName)
d.currentServer = domainName
defer close(d.resolveChan)
maxRetry := 10
for {
if maxRetry == 0 {
@@ -212,6 +213,10 @@ func (d *ProtectedDialer) Dial(ctx context.Context,
}
}
if time.Now().Sub(d.vServer.lastResolved) > time.Minute * 30 {
d.PrepareDomain(Address, nil)
}
fd, err := d.getFd(dest.Network)
if err != nil {
return nil, err