dns config

This commit is contained in:
v2ray
2015-12-10 22:08:36 +01:00
parent 95c8910f87
commit 5b3e84ede6
6 changed files with 67 additions and 20 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
package dns
type CacheConfig interface {
TrustedSource() []string
IsTrustedSource(tag string) bool
}
+3 -2
View File
@@ -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
View File
@@ -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()
+35
View File
@@ -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
}