diff --git a/app/dnscircuit/dns_circuit.go b/app/dnscircuit/dns_circuit.go index 39c4255518c..3875a309582 100644 --- a/app/dnscircuit/dns_circuit.go +++ b/app/dnscircuit/dns_circuit.go @@ -3,6 +3,7 @@ package dnscircuit import ( "context" "fmt" + "time" "github.com/v2fly/v2ray-core/v5/app/dnscircuit/ospf" "github.com/v2fly/v2ray-core/v5/app/router/routercommon" @@ -24,10 +25,11 @@ type dnsCircuit struct { ohm outbound.Manager obDNSOut proxy.ObservableDNSOutBound - ospfIfName string - ospfIfAddr net.IPNet - ospfRtId string - ospf *ospf.Router + ospfIfName string + ospfIfAddr net.IPNet + ospfRtId string + ospf *ospf.Router + inactiveClean time.Duration ob *observer persistentRoute []*routercommon.GeoIP @@ -64,6 +66,7 @@ func (s *dnsCircuit) Init(ctx context.Context, c *Config, router routing.Router, return newError("err init ospf router instance").Base(err) } s.ospf = rt + s.inactiveClean = time.Duration(c.InactiveClean) * time.Second // all other fields s.persistentRoute = c.PersistentRoute diff --git a/app/dnscircuit/observer.go b/app/dnscircuit/observer.go index 6bac698d101..e3a44d9ebac 100644 --- a/app/dnscircuit/observer.go +++ b/app/dnscircuit/observer.go @@ -285,9 +285,6 @@ func (s *observer) initObStatGC() { } func (s *observer) doObStatGC() { - const ( - inactiveDur = 6 * time.Hour - ) var ( revokeIPs []net.IPNet revokedKeys []obDestMetaKey @@ -301,13 +298,13 @@ func (s *observer) doObStatGC() { s.obDestStatRw.Lock() for k, meta := range s.obDestStat { - if !meta.isPersistent && meta.durSinceLastAnnounce() >= inactiveDur { + if !meta.isPersistent && meta.durSinceLastAnnounce() >= s.c.inactiveClean { ipNet := k.ipNet() revokeIPs = append(revokeIPs, ipNet) revokedKeys = append(revokedKeys, k) meta.isOutdated = true ospf.LogImportant("revoking domain: %s due to %s inactive. route CIDR: %s", - meta.domain, inactiveDur.String(), PrettyPrintIPNet(ipNet)) + meta.domain, s.c.inactiveClean.String(), PrettyPrintIPNet(ipNet)) } } for _, k := range revokedKeys { @@ -327,7 +324,7 @@ func (s *observer) doObStatGC() { toDeleteDest []obDestMetaKey ) for destIPNet, destMeta := range clientMeta.destMeta { - if destMeta.g.isOutdated || destMeta.durSinceLastAccess() >= inactiveDur { + if destMeta.g.isOutdated || destMeta.durSinceLastAccess() >= s.c.inactiveClean { tag := destMeta.getOutTag() ips := revokeDestTracks[tag] ips = append(ips, destIPNet.ipNet()) @@ -350,7 +347,7 @@ func (s *observer) doObStatGC() { continue } ospf.LogImportant("revoking conn-track ip rule for outbound:%s due to %s inactive: %s -> %s", - tag, inactiveDur.String(), clientAddr.String(), PrettyPrintIPNet(ips...)) + tag, s.c.inactiveClean.String(), clientAddr.String(), PrettyPrintIPNet(ips...)) s.dynDestRuleIP[dns_feature.DynamicIPSetDNSCircuitConnTrackDestPrefix+tag].RemoveIPNetConnTrack(clientAddr.AsSlice(), ips...) } clear(revokeDestTracks)