Skip to content

Commit

Permalink
fix inactiveClean not working
Browse files Browse the repository at this point in the history
  • Loading branch information
povsister committed Jun 4, 2024
1 parent 6e05b83 commit f7124d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 7 additions & 4 deletions app/dnscircuit/dns_circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions app/dnscircuit/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@ func (s *observer) initObStatGC() {
}

func (s *observer) doObStatGC() {
const (
inactiveDur = 6 * time.Hour
)
var (
revokeIPs []net.IPNet
revokedKeys []obDestMetaKey
Expand All @@ -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 {
Expand All @@ -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())
Expand All @@ -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)
Expand Down

0 comments on commit f7124d1

Please sign in to comment.