func (p *Proxy) Resolve(d *DNSContext) error {
	if p.cache != nil {
		val, ok := p.cache.Get(d.Req)
		if ok && val != nil {
			d.Res = val
			log.Tracef("Serving cached response")
			return nil
		}
	}

	// execute the DNS request
	var reply *dns.Msg
	var err error
	var u upstream.Upstream
	startTime := time.Now()

	// use parallel exchange if "--all-servers" option was configured
	// otherwise try to exchange the request with all upstreams one-by-one
	if p.AllServers {
		reply, u, err = upstream.ExchangeParallel(p.Upstreams, d.Req)
	} else {
		reply, u, err = p.exchange(d.Req)
	}
	rtt := int(time.Since(startTime) / time.Millisecond)
	log.Tracef("RTT: %d ms", rtt)

	if err != nil && p.Fallbacks != nil {
		log.Tracef("Using the fallback upstream due to %s", err)
		reply, u, err = upstream.ExchangeParallel(p.Fallbacks, d.Req)
	}

	// set Upstream that resolved DNS request to DNSContext
	if reply != nil {
		d.Upstream = u

		// Saving cached response
		if p.cache != nil {
			p.cache.Set(reply)
		}
	}

	if reply == nil {
		d.Res = p.genServerFailure(d.Req)
	} else {
		d.Res = reply
	}

	return err
}
// Resolve is the default resolving method used by the DNS proxy to query upstreams
Resolve is the default resolving method used by the DNS proxy to query upstreams
// Resolve is the default resolving method used by the DNS proxy to query upstreams
func (p *Proxy) Resolve(d *DNSContext) error {
	if p.cache != nil {
		val, ok := p.cache.Get(d.Req)
		if ok && val != nil {
			d.Res = val
			log.Tracef("Serving cached response")
			return nil
		}
	}
	var reply *dns.Msg
	var err error
	var u upstream.Upstream
	startTime := time.Now()
	if p.AllServers {
		reply, u, err = upstream.ExchangeParallel(p.Upstreams, d.Req)
	} else {
		reply, u, err = p.exchange(d.Req)
	}
	rtt := int(time.Since(startTime) / time.Millisecond)
	log.Tracef("RTT: %d ms", rtt)
	if err != nil && p.Fallbacks != nil {
		log.Tracef("Using the fallback upstream due to %s", err)
		reply, u, err = upstream.ExchangeParallel(p.Fallbacks, d.Req)
	}
	if reply != nil {
		d.Upstream = u
		if p.cache != nil {
			p.cache.Set(reply)
		}
	}
	if reply == nil {
		d.Res = p.genServerFailure(d.Req)
	} else {
		d.Res = reply
	}
	return err
}
func ( p * Proxy ) Resolve ( d * DNSContext ) error { if p . cache != nil { val , ok := p . cache . Get ( d . Req ) if ok && val != nil { d . Res = val log . Tracef ( " " ) return nil } } var reply * dns . Msg var err error var u upstream . Upstream startTime := time . Now ( ) if p . AllServers { reply , u , err = upstream . ExchangeParallel ( p . Upstreams , d . Req ) } else { reply , u , err = p . exchange ( d . Req ) } rtt := int ( time . Since ( startTime ) / time . Millisecond ) log . Tracef ( " " , rtt ) if err != nil && p . Fallbacks != nil { log . Tracef ( " " , err ) reply , u , err = upstream . ExchangeParallel ( p . Fallbacks , d . Req ) } if reply != nil { d . Upstream = u if p . cache != nil { p . cache . Set ( reply ) } } if reply == nil { d . Res = p . genServerFailure ( d . Req ) } else { d . Res = reply } return err }
Resolve is the default resolving method used by the DNS proxy to query upstreams
Resolve is the default resolving method used by the DNS proxy to query upstreams
// execute the DNS request // use parallel exchange if "--all-servers" option was configured // otherwise try to exchange the request with all upstreams one-by-one // set Upstream that resolved DNS request to DNSContext // Saving cached response