Rename Exchange struct to XfrMsg - which better tells what it does
This commit is contained in:
parent
a282683f7c
commit
946e3a09ca
14
dns.go
14
dns.go
|
@ -59,8 +59,7 @@
|
||||||
// c := new(Client)
|
// c := new(Client)
|
||||||
// in, err := c.Exchange(m1, "127.0.0.1:53")
|
// in, err := c.Exchange(m1, "127.0.0.1:53")
|
||||||
//
|
//
|
||||||
// An asynchronous query is also possible, setting up is more elaborate then
|
// An asynchronous query is also possible, see client.Do and client.DoRtt.
|
||||||
// a synchronous query.
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -109,17 +108,6 @@ type RR interface {
|
||||||
Copy() RR
|
Copy() RR
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exchange is used in (asynchronous) communication with the resolver. If the
|
|
||||||
// client has trust anchors configured the Nxdomain, Secure and Bogus settings
|
|
||||||
// are derived from those anchors.
|
|
||||||
type Exchange struct {
|
|
||||||
Request *Msg // the question sent
|
|
||||||
Reply *Msg // the answer to the question that was sent
|
|
||||||
Rtt time.Duration // round trip time
|
|
||||||
RemoteAddr net.Addr // address of the server
|
|
||||||
Error error // if something went wrong, this contains the error
|
|
||||||
}
|
|
||||||
|
|
||||||
// DNS resource records.
|
// DNS resource records.
|
||||||
// There are many types of messages,
|
// There are many types of messages,
|
||||||
// but they all share the same header.
|
// but they all share the same header.
|
||||||
|
|
40
xfr.go
40
xfr.go
|
@ -13,7 +13,17 @@ package dns
|
||||||
// for r := range t {
|
// for r := range t {
|
||||||
// // ... deal with r.Reply or r.Error
|
// // ... deal with r.Reply or r.Error
|
||||||
// }
|
// }
|
||||||
func (c *Client) XfrReceive(q *Msg, a string) (chan *Exchange, error) {
|
|
||||||
|
// XfrMsg is used when doing [IA]xfr with a remote server.
|
||||||
|
type XfrMsg struct {
|
||||||
|
Request *Msg // the question sent
|
||||||
|
Reply *Msg // the answer to the question that was sent
|
||||||
|
Rtt time.Duration // round trip time
|
||||||
|
RemoteAddr net.Addr // address of the server
|
||||||
|
Error error // if something went wrong, this contains the error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrMsg, error) {
|
||||||
w := new(reply)
|
w := new(reply)
|
||||||
w.client = c
|
w.client = c
|
||||||
w.addr = a
|
w.addr = a
|
||||||
|
@ -24,7 +34,7 @@ func (c *Client) XfrReceive(q *Msg, a string) (chan *Exchange, error) {
|
||||||
if err := w.send(q); err != nil {
|
if err := w.send(q); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
e := make(chan *Exchange)
|
e := make(chan *XfrMsg)
|
||||||
switch q.Question[0].Qtype {
|
switch q.Question[0].Qtype {
|
||||||
case TypeAXFR:
|
case TypeAXFR:
|
||||||
go w.axfrReceive(e)
|
go w.axfrReceive(e)
|
||||||
|
@ -38,23 +48,23 @@ func (c *Client) XfrReceive(q *Msg, a string) (chan *Exchange, error) {
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *reply) axfrReceive(c chan *Exchange) {
|
func (w *reply) axfrReceive(c chan *XfrMsg) {
|
||||||
first := true
|
first := true
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
defer close(c)
|
defer close(c)
|
||||||
for {
|
for {
|
||||||
in, err := w.receive()
|
in, err := w.receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: err}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.req.Id != in.Id {
|
if w.req.Id != in.Id {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrId}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrId}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if first {
|
if first {
|
||||||
if !checkXfrSOA(in, true) {
|
if !checkXfrSOA(in, true) {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrXfrSoa}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrXfrSoa}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
first = !first
|
first = !first
|
||||||
|
@ -63,16 +73,16 @@ func (w *reply) axfrReceive(c chan *Exchange) {
|
||||||
if !first {
|
if !first {
|
||||||
w.tsigTimersOnly = true // Subsequent envelopes use this.
|
w.tsigTimersOnly = true // Subsequent envelopes use this.
|
||||||
if checkXfrSOA(in, false) {
|
if checkXfrSOA(in, false) {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *reply) ixfrReceive(c chan *Exchange) {
|
func (w *reply) ixfrReceive(c chan *XfrMsg) {
|
||||||
var serial uint32 // The first serial seen is the current server serial
|
var serial uint32 // The first serial seen is the current server serial
|
||||||
first := true
|
first := true
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
|
@ -80,23 +90,23 @@ func (w *reply) ixfrReceive(c chan *Exchange) {
|
||||||
for {
|
for {
|
||||||
in, err := w.receive()
|
in, err := w.receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: err}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.req.Id != in.Id {
|
if w.req.Id != in.Id {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrId}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrId}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if first {
|
if first {
|
||||||
// A single SOA RR signals "no changes"
|
// A single SOA RR signals "no changes"
|
||||||
if len(in.Answer) == 1 && checkXfrSOA(in, true) {
|
if len(in.Answer) == 1 && checkXfrSOA(in, true) {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the returned answer is ok
|
// Check if the returned answer is ok
|
||||||
if !checkXfrSOA(in, true) {
|
if !checkXfrSOA(in, true) {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrXfrSoa}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: ErrXfrSoa}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// This serial is important
|
// This serial is important
|
||||||
|
@ -110,11 +120,11 @@ func (w *reply) ixfrReceive(c chan *Exchange) {
|
||||||
// If the last record in the IXFR contains the servers' SOA, we should quit
|
// 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, ok := in.Answer[len(in.Answer)-1].(*RR_SOA); ok {
|
||||||
if v.Serial == serial {
|
if v.Serial == serial {
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr(), Error: nil}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c <- &Exchange{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr()}
|
c <- &XfrMsg{Request: w.req, Reply: in, Rtt: w.rtt, RemoteAddr: w.conn.RemoteAddr()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
|
|
Loading…
Reference in New Issue