1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-31 14:35:37 -05:00

dns client implementation

This commit is contained in:
v2ray
2016-05-15 23:09:28 -07:00
parent ac4d92a186
commit 3b545abe02
8 changed files with 292 additions and 96 deletions

View File

@@ -5,19 +5,21 @@ package internal
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/serial"
v2net "github.com/v2ray/v2ray-core/common/net"
)
func (this *CacheConfig) UnmarshalJSON(data []byte) error {
var strlist serial.StringLiteralList
if err := json.Unmarshal(data, strlist); err != nil {
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Servers []v2net.Address `json:"servers"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
config := &CacheConfig{
TrustedTags: make(map[serial.StringLiteral]bool, strlist.Len()),
}
for _, str := range strlist {
config.TrustedTags[str.TrimSpace()] = true
this.NameServers = make([]v2net.Destination, len(jsonConfig.Servers))
for idx, server := range jsonConfig.Servers {
this.NameServers[idx] = v2net.UDPDestination(server, v2net.Port(53))
}
return nil
}