diff --git a/all.go b/all.go index 77444fac..19e06c6b 100644 --- a/all.go +++ b/all.go @@ -3,7 +3,7 @@ package core import ( // The following are necessary as they register handlers in their init functions. _ "v2ray.com/core/app/dispatcher/impl" - _ "v2ray.com/core/app/dns" + _ "v2ray.com/core/app/dns/server" _ "v2ray.com/core/app/proxy" _ "v2ray.com/core/app/router" diff --git a/app/dns/nameserver.go b/app/dns/server/nameserver.go similarity index 99% rename from app/dns/nameserver.go rename to app/dns/server/nameserver.go index 01ff4c78..f381447b 100644 --- a/app/dns/nameserver.go +++ b/app/dns/server/nameserver.go @@ -1,4 +1,4 @@ -package dns +package server import ( "net" diff --git a/app/dns/server.go b/app/dns/server/server.go similarity index 88% rename from app/dns/server.go rename to app/dns/server/server.go index b1e63161..beb1e618 100644 --- a/app/dns/server.go +++ b/app/dns/server/server.go @@ -1,4 +1,4 @@ -package dns +package server import ( "net" @@ -7,12 +7,13 @@ import ( "v2ray.com/core/app" "v2ray.com/core/app/dispatcher" + "v2ray.com/core/app/dns" "v2ray.com/core/common/errors" "v2ray.com/core/common/log" v2net "v2ray.com/core/common/net" "v2ray.com/core/common/serial" - "github.com/miekg/dns" + dnsmsg "github.com/miekg/dns" ) const ( @@ -31,7 +32,7 @@ type CacheServer struct { servers []NameServer } -func NewCacheServer(space app.Space, config *Config) *CacheServer { +func NewCacheServer(space app.Space, config *dns.Config) *CacheServer { server := &CacheServer{ records: make(map[string]*DomainRecord), servers: make([]NameServer, len(config.NameServers)), @@ -85,7 +86,7 @@ func (v *CacheServer) Get(domain string) []net.IP { return []net.IP{ip} } - domain = dns.Fqdn(domain) + domain = dnsmsg.Fqdn(domain) ips := v.GetCached(domain) if ips != nil { return ips @@ -116,14 +117,14 @@ func (v *CacheServer) Get(domain string) []net.IP { type CacheServerFactory struct{} func (v CacheServerFactory) Create(space app.Space, config interface{}) (app.Application, error) { - server := NewCacheServer(space, config.(*Config)) + server := NewCacheServer(space, config.(*dns.Config)) return server, nil } func (v CacheServerFactory) AppId() app.ID { - return APP_ID + return dns.APP_ID } func init() { - app.RegisterApplicationFactory(serial.GetMessageType(new(Config)), CacheServerFactory{}) + app.RegisterApplicationFactory(serial.GetMessageType(new(dns.Config)), CacheServerFactory{}) } diff --git a/v2ray.go b/v2ray.go index 14327fc1..d09c1ea0 100644 --- a/v2ray.go +++ b/v2ray.go @@ -59,14 +59,14 @@ func NewPoint(pConfig *Config) (*Point, error) { } if !space.HasApp(dns.APP_ID) { - dnsServer := dns.NewCacheServer(space, &dns.Config{ - NameServers: []*v2net.Endpoint{ - { - Address: v2net.NewIPOrDomain(v2net.LocalHostDomain), - }, - }, - }) - space.BindApp(dns.APP_ID, dnsServer) + dnsConfig := &dns.Config{ + NameServers: []*v2net.Endpoint{{ + Address: v2net.NewIPOrDomain(v2net.LocalHostDomain), + }}, + } + if err := space.BindFromConfig(serial.GetMessageType(dnsConfig), dnsConfig); err != nil { + return nil, err + } } dispatcherConfig := new(dispatcher.Config)