mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-24 17:41:29 +00:00
Fix fake-ip mapping
This commit is contained in:
parent
8b8fb4344c
commit
3c85b8bc48
|
@ -74,6 +74,7 @@ func (c *CacheFile) FakeIPStore(address netip.Addr, domain string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
oldDomain := bucket.Get(address.AsSlice())
|
||||||
err = bucket.Put(address.AsSlice(), []byte(domain))
|
err = bucket.Put(address.AsSlice(), []byte(domain))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -86,12 +87,24 @@ func (c *CacheFile) FakeIPStore(address netip.Addr, domain string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if oldDomain != nil {
|
||||||
|
if err := bucket.Delete(oldDomain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return bucket.Put([]byte(domain), address.AsSlice())
|
return bucket.Put([]byte(domain), address.AsSlice())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CacheFile) FakeIPStoreAsync(address netip.Addr, domain string, logger logger.Logger) {
|
func (c *CacheFile) FakeIPStoreAsync(address netip.Addr, domain string, logger logger.Logger) {
|
||||||
c.saveAccess.Lock()
|
c.saveAccess.Lock()
|
||||||
|
if oldDomain, loaded := c.saveDomain[address]; loaded {
|
||||||
|
if address.Is4() {
|
||||||
|
delete(c.saveAddress4, oldDomain)
|
||||||
|
} else {
|
||||||
|
delete(c.saveAddress6, oldDomain)
|
||||||
|
}
|
||||||
|
}
|
||||||
c.saveDomain[address] = domain
|
c.saveDomain[address] = domain
|
||||||
if address.Is4() {
|
if address.Is4() {
|
||||||
c.saveAddress4[domain] = address
|
c.saveAddress4[domain] = address
|
||||||
|
|
|
@ -40,6 +40,13 @@ func (s *MemoryStorage) FakeIPSaveMetadataAsync(metadata *adapter.FakeIPMetadata
|
||||||
func (s *MemoryStorage) FakeIPStore(address netip.Addr, domain string) error {
|
func (s *MemoryStorage) FakeIPStore(address netip.Addr, domain string) error {
|
||||||
s.addressAccess.Lock()
|
s.addressAccess.Lock()
|
||||||
s.domainAccess.Lock()
|
s.domainAccess.Lock()
|
||||||
|
if oldDomain, loaded := s.addressCache[address]; loaded {
|
||||||
|
if address.Is4() {
|
||||||
|
delete(s.domainCache4, oldDomain)
|
||||||
|
} else {
|
||||||
|
delete(s.domainCache6, oldDomain)
|
||||||
|
}
|
||||||
|
}
|
||||||
s.addressCache[address] = domain
|
s.addressCache[address] = domain
|
||||||
if address.Is4() {
|
if address.Is4() {
|
||||||
s.domainCache4[domain] = address
|
s.domainCache4[domain] = address
|
||||||
|
|
Loading…
Reference in a new issue