mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Fix cache file
This commit is contained in:
parent
e075bb5c8d
commit
98bf696d01
|
@ -3,6 +3,7 @@ package cachefile
|
||||||
import (
|
import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -40,6 +41,18 @@ func Open(path string, cacheID string) (*CacheFile, error) {
|
||||||
if cacheID != "" {
|
if cacheID != "" {
|
||||||
cacheIDBytes = append([]byte{0}, []byte(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{
|
return &CacheFile{
|
||||||
DB: db,
|
DB: db,
|
||||||
cacheID: cacheIDBytes,
|
cacheID: cacheIDBytes,
|
||||||
|
|
|
@ -11,11 +11,13 @@ import (
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const fakeipBucketPrefix = "fakeip_"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bucketFakeIP = []byte("fakeip")
|
bucketFakeIP = []byte(fakeipBucketPrefix + "address")
|
||||||
bucketFakeIPDomain4 = []byte("fakeip_domain4")
|
bucketFakeIPDomain4 = []byte(fakeipBucketPrefix + "domain4")
|
||||||
bucketFakeIPDomain6 = []byte("fakeip_domain6")
|
bucketFakeIPDomain6 = []byte(fakeipBucketPrefix + "domain6")
|
||||||
keyMetadata = []byte("metadata")
|
keyMetadata = []byte(fakeipBucketPrefix + "metadata")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *CacheFile) FakeIPMetadata() *adapter.FakeIPMetadata {
|
func (c *CacheFile) FakeIPMetadata() *adapter.FakeIPMetadata {
|
||||||
|
|
|
@ -50,6 +50,7 @@ func (s *Store) Start() error {
|
||||||
if s.inet6Range.IsValid() {
|
if s.inet6Range.IsValid() {
|
||||||
s.inet6Current = s.inet6Range.Addr().Next().Next()
|
s.inet6Current = s.inet6Range.Addr().Next().Next()
|
||||||
}
|
}
|
||||||
|
_ = storage.FakeIPReset()
|
||||||
}
|
}
|
||||||
s.storage = storage
|
s.storage = storage
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue