diff --git a/experimental/clashapi/cachefile/cache.go b/experimental/clashapi/cachefile/cache.go index e2ef364d..d2850067 100644 --- a/experimental/clashapi/cachefile/cache.go +++ b/experimental/clashapi/cachefile/cache.go @@ -3,6 +3,7 @@ package cachefile import ( "net/netip" "os" + "strings" "sync" "time" @@ -40,6 +41,18 @@ func Open(path string, cacheID string) (*CacheFile, error) { if cacheID != "" { cacheIDBytes = append([]byte{0}, []byte(cacheID)...) } + err = db.Batch(func(tx *bbolt.Tx) error { + return tx.ForEach(func(name []byte, b *bbolt.Bucket) error { + bucketName := string(name) + if !(bucketName == string(bucketSelected) || strings.HasPrefix(bucketName, fakeipBucketPrefix)) { + delErr := tx.DeleteBucket(name) + if delErr != nil { + return delErr + } + } + return nil + }) + }) return &CacheFile{ DB: db, cacheID: cacheIDBytes, diff --git a/experimental/clashapi/cachefile/fakeip.go b/experimental/clashapi/cachefile/fakeip.go index e99588e9..a180ccd3 100644 --- a/experimental/clashapi/cachefile/fakeip.go +++ b/experimental/clashapi/cachefile/fakeip.go @@ -11,11 +11,13 @@ import ( "go.etcd.io/bbolt" ) +const fakeipBucketPrefix = "fakeip_" + var ( - bucketFakeIP = []byte("fakeip") - bucketFakeIPDomain4 = []byte("fakeip_domain4") - bucketFakeIPDomain6 = []byte("fakeip_domain6") - keyMetadata = []byte("metadata") + bucketFakeIP = []byte(fakeipBucketPrefix + "address") + bucketFakeIPDomain4 = []byte(fakeipBucketPrefix + "domain4") + bucketFakeIPDomain6 = []byte(fakeipBucketPrefix + "domain6") + keyMetadata = []byte(fakeipBucketPrefix + "metadata") ) func (c *CacheFile) FakeIPMetadata() *adapter.FakeIPMetadata { diff --git a/transport/fakeip/store.go b/transport/fakeip/store.go index 3223f00b..7571161c 100644 --- a/transport/fakeip/store.go +++ b/transport/fakeip/store.go @@ -50,6 +50,7 @@ func (s *Store) Start() error { if s.inet6Range.IsValid() { s.inet6Current = s.inet6Range.Addr().Next().Next() } + _ = storage.FakeIPReset() } s.storage = storage return nil