Clash.Meta/component/fakeip/cachefile.go

56 lines
1.3 KiB
Go
Raw Normal View History

2021-10-11 20:48:58 +08:00
package fakeip
import (
"net/netip"
2021-10-11 20:48:58 +08:00
2023-11-03 21:01:45 +08:00
"github.com/metacubex/mihomo/component/profile/cachefile"
2021-10-11 20:48:58 +08:00
)
type cachefileStore struct {
cache *cachefile.FakeIpStore
2021-10-11 20:48:58 +08:00
}
// GetByHost implements store.GetByHost
func (c *cachefileStore) GetByHost(host string) (netip.Addr, bool) {
return c.cache.GetByHost(host)
2021-10-11 20:48:58 +08:00
}
// PutByHost implements store.PutByHost
func (c *cachefileStore) PutByHost(host string, ip netip.Addr) {
c.cache.PutByHost(host, ip)
2021-10-11 20:48:58 +08:00
}
// GetByIP implements store.GetByIP
func (c *cachefileStore) GetByIP(ip netip.Addr) (string, bool) {
return c.cache.GetByIP(ip)
2021-10-11 20:48:58 +08:00
}
// PutByIP implements store.PutByIP
func (c *cachefileStore) PutByIP(ip netip.Addr, host string) {
c.cache.PutByIP(ip, host)
2021-10-11 20:48:58 +08:00
}
2021-11-23 22:01:49 +08:00
// DelByIP implements store.DelByIP
func (c *cachefileStore) DelByIP(ip netip.Addr) {
c.cache.DelByIP(ip)
2021-11-23 22:01:49 +08:00
}
2021-10-11 20:48:58 +08:00
// Exist implements store.Exist
func (c *cachefileStore) Exist(ip netip.Addr) bool {
2021-10-11 20:48:58 +08:00
_, exist := c.GetByIP(ip)
return exist
}
// CloneTo implements store.CloneTo
// already persistence
func (c *cachefileStore) CloneTo(store store) {}
2022-03-23 01:05:43 +08:00
// FlushFakeIP implements store.FlushFakeIP
func (c *cachefileStore) FlushFakeIP() error {
return c.cache.FlushFakeIP()
}
func newCachefileStore(cache *cachefile.CacheFile) *cachefileStore {
return &cachefileStore{cache.FakeIpStore()}
}