Put the rrt info the Exchange struct
This commit is contained in:
parent
9cabad70a8
commit
ed1c8fa812
|
@ -33,8 +33,6 @@ type RequestWriter interface {
|
|||
Dial() error
|
||||
// TsigStatus returns the TSIG validation status.
|
||||
TsigStatus() error
|
||||
// Rtt returns the duration of the request. The value is only valid after a Send()/Receive() sequence.
|
||||
Rtt() time.Duration
|
||||
}
|
||||
|
||||
// hijacked connections...?
|
||||
|
@ -222,7 +220,7 @@ func ListenAndQuery(request chan *Request, handler QueryHandler) {
|
|||
// Write returns the original question and the answer on the
|
||||
// reply channel of the client.
|
||||
func (w *reply) Write(m *Msg) error {
|
||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: m}
|
||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: m, Rtt: w.rtt}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -505,6 +503,3 @@ func (w *reply) Request() *Msg { return w.req }
|
|||
|
||||
// TsigStatus implements the RequestWriter.TsigStatus method
|
||||
func (w *reply) TsigStatus() error { return w.tsigStatus }
|
||||
|
||||
// Rtt implements the RequestWriter.Rtt method
|
||||
func (w *reply) Rtt() time.Duration { return w.rtt }
|
||||
|
|
8
dns.go
8
dns.go
|
@ -74,6 +74,7 @@ package dns
|
|||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -116,9 +117,10 @@ type RR interface {
|
|||
|
||||
// Exchange is used in communicating with the resolver.
|
||||
type Exchange struct {
|
||||
Request *Msg // the question sent
|
||||
Reply *Msg // the answer to the question that was sent
|
||||
Error error // if something went wrong, this contains the error
|
||||
Request *Msg // the question sent
|
||||
Reply *Msg // the answer to the question that was sent
|
||||
Rtt time.Duration // Round trip time
|
||||
Error error // if something went wrong, this contains the error
|
||||
}
|
||||
|
||||
// DNS resource records.
|
||||
|
|
|
@ -28,7 +28,7 @@ func q(w dns.RequestWriter, m *dns.Msg) {
|
|||
fmt.Printf(";; Couldn't verify TSIG signature: %s\n", w.TsigStatus().Error())
|
||||
}
|
||||
// Save the Rtt in the message
|
||||
r.Rtt = w.Rtt()
|
||||
// It's better to extend dns.RequestWriter...
|
||||
w.Write(r)
|
||||
}
|
||||
|
||||
|
|
18
xfr.go
18
xfr.go
|
@ -33,16 +33,16 @@ func (w *reply) axfrReceive() {
|
|||
for {
|
||||
in, err := w.Receive()
|
||||
if err != nil {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, err}
|
||||
return
|
||||
}
|
||||
if w.req.Id != in.Id {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrId}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, ErrId}
|
||||
return
|
||||
}
|
||||
if first {
|
||||
if !checkXfrSOA(in, true) {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrSoa}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, ErrXfrSoa}
|
||||
return
|
||||
}
|
||||
first = !first
|
||||
|
@ -51,7 +51,7 @@ func (w *reply) axfrReceive() {
|
|||
if !first {
|
||||
w.tsigTimersOnly = true // Subsequent envelopes use this.
|
||||
if checkXfrSOA(in, false) {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, ErrXfrLast}
|
||||
return
|
||||
}
|
||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: in}
|
||||
|
@ -68,24 +68,24 @@ func (w *reply) ixfrReceive() {
|
|||
for {
|
||||
in, err := w.Receive()
|
||||
if err != nil {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, err}
|
||||
return
|
||||
}
|
||||
if w.req.Id != in.Id {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrId}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, ErrId}
|
||||
return
|
||||
}
|
||||
|
||||
if first {
|
||||
// A single SOA RR signals "no changes"
|
||||
if len(in.Answer) == 1 && checkXfrSOA(in, true) {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, ErrXfrLast}
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the returned answer is ok
|
||||
if !checkXfrSOA(in, true) {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrSoa}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, ErrXfrSoa}
|
||||
return
|
||||
}
|
||||
// This serial is important
|
||||
|
@ -99,7 +99,7 @@ func (w *reply) ixfrReceive() {
|
|||
// If the last record in the IXFR contains the servers' SOA, we should quit
|
||||
if v, ok := in.Answer[len(in.Answer)-1].(*RR_SOA); ok {
|
||||
if v.Serial == serial {
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, w.rtt, ErrXfrLast}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue