mirror of
https://github.com/v2fly/v2ray-core
synced 2024-02-27 03:18:06 +00:00
dns config
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
package dns
|
||||
|
||||
type CacheConfig interface {
|
||||
TrustedSource() []string
|
||||
IsTrustedSource(tag string) bool
|
||||
}
|
||||
|
||||
+3
-2
@@ -31,10 +31,11 @@ func (this *entry) Extend() {
|
||||
|
||||
type DnsCache struct {
|
||||
sync.RWMutex
|
||||
cache map[string]*entry
|
||||
cache map[string]*entry
|
||||
config CacheConfig
|
||||
}
|
||||
|
||||
func NewCache() *DnsCache {
|
||||
func NewCache(config CacheConfig) *DnsCache {
|
||||
cache := &DnsCache{
|
||||
cache: make(map[string]*entry),
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ func TestDnsAdd(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
domain := "v2ray.com"
|
||||
cache := dns.NewCache()
|
||||
cache := dns.NewCache(nil)
|
||||
ip := cache.Get(domain)
|
||||
netassert.IP(ip).IsNil()
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
serialjson "github.com/v2ray/v2ray-core/common/serial/json"
|
||||
)
|
||||
|
||||
type TagList map[string]bool
|
||||
|
||||
func NewTagList(tags []string) TagList {
|
||||
list := TagList(make(map[string]bool))
|
||||
for _, tag := range tags {
|
||||
list[strings.TrimSpace(tag)] = true
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func (this *TagList) UnmarshalJSON(data []byte) error {
|
||||
tags, err := serialjson.UnmarshalStringList(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*this = NewTagList(tags)
|
||||
return nil
|
||||
}
|
||||
|
||||
type CacheConfig struct {
|
||||
TrustedTags TagList `json:"trustedTags"`
|
||||
}
|
||||
|
||||
func (this *CacheConfig) IsTrustedSource(tag string) bool {
|
||||
_, found := this.TrustedTags[tag]
|
||||
return found
|
||||
}
|
||||
Reference in New Issue
Block a user