Rename XfrToken to XfrMsg
This commit is contained in:
parent
a014286039
commit
77c679fe65
50
xfr.go
50
xfr.go
|
@ -1,13 +1,13 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
// XfrToken is used when doing [IA]xfr with a remote server.
|
// XfrMsg is used when doing [IA]xfr with a remote server.
|
||||||
type XfrToken struct {
|
type XfrMsg struct {
|
||||||
RR []RR // the set of RRs in the answer section of the AXFR reply message
|
RR []RR // The set of RRs in the answer section of the AXFR reply message.
|
||||||
Error error // if something went wrong, this contains the error
|
Error error // If something went wrong, this contains the error.
|
||||||
}
|
}
|
||||||
|
|
||||||
// XfrReceive performs a [AI]xfr request (depends on the message's Qtype). It returns
|
// XfrReceive performs a [AI]xfr request (depends on the message's Qtype). It returns
|
||||||
// a channel of XfrToken on which the replies from the server are sent. At the end of
|
// a channel of *XfrMsg on which the replies from the server are sent. At the end of
|
||||||
// the transfer the channel is closed.
|
// the transfer the channel is closed.
|
||||||
// It panics if the Qtype does not equal TypeAXFR or TypeIXFR. The messages are TSIG checked if
|
// It panics if the Qtype does not equal TypeAXFR or TypeIXFR. The messages are TSIG checked if
|
||||||
// needed, no other post-processing is performed. The caller must dissect the returned
|
// needed, no other post-processing is performed. The caller must dissect the returned
|
||||||
|
@ -20,7 +20,7 @@ type XfrToken struct {
|
||||||
// for r := range t {
|
// for r := range t {
|
||||||
// // ... deal with r.RR or r.Error
|
// // ... deal with r.RR or r.Error
|
||||||
// }
|
// }
|
||||||
func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrToken, 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
|
||||||
|
@ -31,7 +31,7 @@ func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrToken, error) {
|
||||||
if err := w.send(q); err != nil {
|
if err := w.send(q); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
e := make(chan *XfrToken)
|
e := make(chan *XfrMsg)
|
||||||
switch q.Question[0].Qtype {
|
switch q.Question[0].Qtype {
|
||||||
case TypeAXFR:
|
case TypeAXFR:
|
||||||
go w.axfrReceive(q, e)
|
go w.axfrReceive(q, e)
|
||||||
|
@ -45,23 +45,23 @@ func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrToken, error) {
|
||||||
panic("dns: not reached")
|
panic("dns: not reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *reply) axfrReceive(q *Msg, c chan *XfrToken) {
|
func (w *reply) axfrReceive(q *Msg, c chan *XfrMsg) {
|
||||||
first := true
|
first := true
|
||||||
defer w.conn.Close()
|
defer w.conn.Close()
|
||||||
defer close(c)
|
defer close(c)
|
||||||
for {
|
for {
|
||||||
in, err := w.receive()
|
in, err := w.receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c <- &XfrToken{nil, err}
|
c <- &XfrMsg{nil, err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if in.Id != q.Id {
|
if in.Id != q.Id {
|
||||||
c <- &XfrToken{in.Answer, ErrId}
|
c <- &XfrMsg{in.Answer, ErrId}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if first {
|
if first {
|
||||||
if !checkXfrSOA(in, true) {
|
if !checkXfrSOA(in, true) {
|
||||||
c <- &XfrToken{in.Answer, ErrSoa}
|
c <- &XfrMsg{in.Answer, ErrSoa}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
first = !first
|
first = !first
|
||||||
|
@ -70,16 +70,16 @@ func (w *reply) axfrReceive(q *Msg, c chan *XfrToken) {
|
||||||
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 <- &XfrToken{in.Answer, nil}
|
c <- &XfrMsg{in.Answer, nil}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c <- &XfrToken{in.Answer, nil}
|
c <- &XfrMsg{in.Answer, nil}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("dns: not reached")
|
panic("dns: not reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *reply) ixfrReceive(q *Msg, c chan *XfrToken) {
|
func (w *reply) ixfrReceive(q *Msg, 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.conn.Close()
|
defer w.conn.Close()
|
||||||
|
@ -87,23 +87,23 @@ func (w *reply) ixfrReceive(q *Msg, c chan *XfrToken) {
|
||||||
for {
|
for {
|
||||||
in, err := w.receive()
|
in, err := w.receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c <- &XfrToken{in.Answer, err}
|
c <- &XfrMsg{in.Answer, err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if q.Id != in.Id {
|
if q.Id != in.Id {
|
||||||
c <- &XfrToken{in.Answer, ErrId}
|
c <- &XfrMsg{in.Answer, 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 <- &XfrToken{in.Answer, nil}
|
c <- &XfrMsg{in.Answer, 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 <- &XfrToken{in.Answer, ErrSoa}
|
c <- &XfrMsg{in.Answer, ErrSoa}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// This serial is important
|
// This serial is important
|
||||||
|
@ -117,11 +117,11 @@ func (w *reply) ixfrReceive(q *Msg, c chan *XfrToken) {
|
||||||
// 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 <- &XfrToken{in.Answer, nil}
|
c <- &XfrMsg{in.Answer, nil}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c <- &XfrToken{in.Answer, nil}
|
c <- &XfrMsg{in.Answer, nil}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("dns: not reached")
|
panic("dns: not reached")
|
||||||
|
@ -143,7 +143,7 @@ func checkXfrSOA(in *Msg, first bool) bool {
|
||||||
|
|
||||||
// XfrSend performs an outgoing [AI]xfr depending on the request message. The
|
// XfrSend performs an outgoing [AI]xfr depending on the request message. The
|
||||||
// caller is responsible for sending the correct sequence of RR sets through
|
// caller is responsible for sending the correct sequence of RR sets through
|
||||||
// the channel c. For reasons of symmetry XfrToken is re-used.
|
// the channel c. For reasons of symmetry XfrMsg is re-used.
|
||||||
// Errors are signaled via the error pointer, when an error occurs the function
|
// Errors are signaled via the error pointer, when an error occurs the function
|
||||||
// sets the error and returns (it does not close the channel).
|
// sets the error and returns (it does not close the channel).
|
||||||
// TSIG and enveloping is handled by XfrSend.
|
// TSIG and enveloping is handled by XfrSend.
|
||||||
|
@ -151,19 +151,19 @@ func checkXfrSOA(in *Msg, first bool) bool {
|
||||||
// Basic use pattern for sending an AXFR:
|
// Basic use pattern for sending an AXFR:
|
||||||
//
|
//
|
||||||
// // q contains the AXFR request
|
// // q contains the AXFR request
|
||||||
// c := make(chan *XfrToken)
|
// c := make(chan *XfrMsg)
|
||||||
// var e *error
|
// var e *error
|
||||||
// err := XfrSend(w, q, c, e)
|
// err := XfrSend(w, q, c, e)
|
||||||
// w.Hijack() // hijack the connection so that the library doesn't close it
|
// w.Hijack() // hijack the connection so that the library doesn't close it
|
||||||
// for _, rrset := range rrsets { // rrset is a []RR
|
// for _, rrset := range rrsets { // rrset is a []RR
|
||||||
// c <- &{XfrToken{RR: rrset}
|
// c <- &{XfrMsg{RR: rrset}
|
||||||
// if e != nil {
|
// if e != nil {
|
||||||
// close(c)
|
// close(c)
|
||||||
// break
|
// break
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// // w.Close() // Don't! Let the client close the connection
|
// // w.Close() // Don't! Let the client close the connection
|
||||||
func XfrSend(w ResponseWriter, q *Msg, c chan *XfrToken, e *error) error {
|
func XfrSend(w ResponseWriter, q *Msg, c chan *XfrMsg, e *error) error {
|
||||||
switch q.Question[0].Qtype {
|
switch q.Question[0].Qtype {
|
||||||
case TypeAXFR, TypeIXFR:
|
case TypeAXFR, TypeIXFR:
|
||||||
go axfrSend(w, q, c, e)
|
go axfrSend(w, q, c, e)
|
||||||
|
@ -175,7 +175,7 @@ func XfrSend(w ResponseWriter, q *Msg, c chan *XfrToken, e *error) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mg): count the RRs and the resulting size.
|
// TODO(mg): count the RRs and the resulting size.
|
||||||
func axfrSend(w ResponseWriter, req *Msg, c chan *XfrToken, e *error) {
|
func axfrSend(w ResponseWriter, req *Msg, c chan *XfrMsg, e *error) {
|
||||||
rep := new(Msg)
|
rep := new(Msg)
|
||||||
rep.SetReply(req)
|
rep.SetReply(req)
|
||||||
rep.Authoritative = true
|
rep.Authoritative = true
|
||||||
|
|
Loading…
Reference in New Issue