Fix async FakeIP save

This commit is contained in:
世界
2023-07-08 16:08:46 +08:00
parent 1c526feec1
commit 9d75385bbb
5 changed files with 41 additions and 9 deletions

View File

@@ -1,7 +1,9 @@
package cachefile
import (
"net/netip"
"os"
"sync"
"time"
"github.com/sagernet/sing-box/adapter"
@@ -14,8 +16,10 @@ var bucketSelected = []byte("selected")
var _ adapter.ClashCacheFile = (*CacheFile)(nil)
type CacheFile struct {
DB *bbolt.DB
cacheID []byte
DB *bbolt.DB
cacheID []byte
saveAccess sync.RWMutex
saveCache map[netip.Addr]string
}
func Open(path string, cacheID string) (*CacheFile, error) {
@@ -36,7 +40,11 @@ func Open(path string, cacheID string) (*CacheFile, error) {
if cacheID != "" {
cacheIDBytes = append([]byte{0}, []byte(cacheID)...)
}
return &CacheFile{db, cacheIDBytes}, nil
return &CacheFile{
DB: db,
cacheID: cacheIDBytes,
saveCache: make(map[netip.Addr]string),
}, nil
}
func (c *CacheFile) bucket(t *bbolt.Tx, key []byte) *bbolt.Bucket {