github.com/chwjbn/xclash@v0.2.0/component/fakeip/cachefile.go (about) 1 package fakeip 2 3 import ( 4 "net" 5 6 "github.com/chwjbn/xclash/component/profile/cachefile" 7 ) 8 9 type cachefileStore struct { 10 cache *cachefile.CacheFile 11 } 12 13 // GetByHost implements store.GetByHost 14 func (c *cachefileStore) GetByHost(host string) (net.IP, bool) { 15 elm := c.cache.GetFakeip([]byte(host)) 16 if elm == nil { 17 return nil, false 18 } 19 return net.IP(elm), true 20 } 21 22 // PutByHost implements store.PutByHost 23 func (c *cachefileStore) PutByHost(host string, ip net.IP) { 24 c.cache.PutFakeip([]byte(host), ip) 25 } 26 27 // GetByIP implements store.GetByIP 28 func (c *cachefileStore) GetByIP(ip net.IP) (string, bool) { 29 elm := c.cache.GetFakeip(ip.To4()) 30 if elm == nil { 31 return "", false 32 } 33 return string(elm), true 34 } 35 36 // PutByIP implements store.PutByIP 37 func (c *cachefileStore) PutByIP(ip net.IP, host string) { 38 c.cache.PutFakeip(ip.To4(), []byte(host)) 39 } 40 41 // DelByIP implements store.DelByIP 42 func (c *cachefileStore) DelByIP(ip net.IP) { 43 ip = ip.To4() 44 c.cache.DelFakeipPair(ip, c.cache.GetFakeip(ip.To4())) 45 } 46 47 // Exist implements store.Exist 48 func (c *cachefileStore) Exist(ip net.IP) bool { 49 _, exist := c.GetByIP(ip) 50 return exist 51 } 52 53 // CloneTo implements store.CloneTo 54 // already persistence 55 func (c *cachefileStore) CloneTo(store store) {}