2021-10-11 20:48:58 +08:00
|
|
|
package fakeip
|
|
|
|
|
|
|
|
import (
|
2022-04-12 00:31:04 +08:00
|
|
|
"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 {
|
2024-09-23 09:35:48 +08:00
|
|
|
cache *cachefile.FakeIpStore
|
2021-10-11 20:48:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetByHost implements store.GetByHost
|
2022-04-12 00:31:04 +08:00
|
|
|
func (c *cachefileStore) GetByHost(host string) (netip.Addr, bool) {
|
2024-09-23 09:35:48 +08:00
|
|
|
return c.cache.GetByHost(host)
|
2021-10-11 20:48:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutByHost implements store.PutByHost
|
2022-04-12 00:31:04 +08:00
|
|
|
func (c *cachefileStore) PutByHost(host string, ip netip.Addr) {
|
2024-09-23 09:35:48 +08:00
|
|
|
c.cache.PutByHost(host, ip)
|
2021-10-11 20:48:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetByIP implements store.GetByIP
|
2022-04-12 00:31:04 +08:00
|
|
|
func (c *cachefileStore) GetByIP(ip netip.Addr) (string, bool) {
|
2024-09-23 09:35:48 +08:00
|
|
|
return c.cache.GetByIP(ip)
|
2021-10-11 20:48:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutByIP implements store.PutByIP
|
2022-04-12 00:31:04 +08:00
|
|
|
func (c *cachefileStore) PutByIP(ip netip.Addr, host string) {
|
2024-09-23 09:35:48 +08:00
|
|
|
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
|
2022-04-12 00:31:04 +08:00
|
|
|
func (c *cachefileStore) DelByIP(ip netip.Addr) {
|
2024-09-23 09:35:48 +08:00
|
|
|
c.cache.DelByIP(ip)
|
2021-11-23 22:01:49 +08:00
|
|
|
}
|
|
|
|
|
2021-10-11 20:48:58 +08:00
|
|
|
// Exist implements store.Exist
|
2022-04-12 00:31:04 +08:00
|
|
|
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()
|
|
|
|
}
|
2024-09-23 09:35:48 +08:00
|
|
|
|
|
|
|
func newCachefileStore(cache *cachefile.CacheFile) *cachefileStore {
|
|
|
|
return &cachefileStore{cache.FakeIpStore()}
|
|
|
|
}
|