From 77c679fe65d1bc36f5fb675ae7078600c74c782e Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 2 Dec 2012 08:41:49 +0100 Subject: [PATCH] Rename XfrToken to XfrMsg --- xfr.go | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/xfr.go b/xfr.go index 5b8a5135..84b47be3 100644 --- a/xfr.go +++ b/xfr.go @@ -1,13 +1,13 @@ package dns -// XfrToken is used when doing [IA]xfr with a remote server. -type XfrToken struct { - 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 +// XfrMsg is used when doing [IA]xfr with a remote server. +type XfrMsg struct { + 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. } // 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. // 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 @@ -20,7 +20,7 @@ type XfrToken struct { // for r := range t { // // ... 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.client = c 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 { return nil, err } - e := make(chan *XfrToken) + e := make(chan *XfrMsg) switch q.Question[0].Qtype { case TypeAXFR: go w.axfrReceive(q, e) @@ -45,23 +45,23 @@ func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrToken, error) { panic("dns: not reached") } -func (w *reply) axfrReceive(q *Msg, c chan *XfrToken) { +func (w *reply) axfrReceive(q *Msg, c chan *XfrMsg) { first := true defer w.conn.Close() defer close(c) for { in, err := w.receive() if err != nil { - c <- &XfrToken{nil, err} + c <- &XfrMsg{nil, err} return } if in.Id != q.Id { - c <- &XfrToken{in.Answer, ErrId} + c <- &XfrMsg{in.Answer, ErrId} return } if first { if !checkXfrSOA(in, true) { - c <- &XfrToken{in.Answer, ErrSoa} + c <- &XfrMsg{in.Answer, ErrSoa} return } first = !first @@ -70,16 +70,16 @@ func (w *reply) axfrReceive(q *Msg, c chan *XfrToken) { if !first { w.tsigTimersOnly = true // Subsequent envelopes use this. if checkXfrSOA(in, false) { - c <- &XfrToken{in.Answer, nil} + c <- &XfrMsg{in.Answer, nil} return } - c <- &XfrToken{in.Answer, nil} + c <- &XfrMsg{in.Answer, nil} } } 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 first := true defer w.conn.Close() @@ -87,23 +87,23 @@ func (w *reply) ixfrReceive(q *Msg, c chan *XfrToken) { for { in, err := w.receive() if err != nil { - c <- &XfrToken{in.Answer, err} + c <- &XfrMsg{in.Answer, err} return } if q.Id != in.Id { - c <- &XfrToken{in.Answer, ErrId} + c <- &XfrMsg{in.Answer, ErrId} return } if first { // A single SOA RR signals "no changes" if len(in.Answer) == 1 && checkXfrSOA(in, true) { - c <- &XfrToken{in.Answer, nil} + c <- &XfrMsg{in.Answer, nil} return } // Check if the returned answer is ok if !checkXfrSOA(in, true) { - c <- &XfrToken{in.Answer, ErrSoa} + c <- &XfrMsg{in.Answer, ErrSoa} return } // 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 v, ok := in.Answer[len(in.Answer)-1].(*RR_SOA); ok { if v.Serial == serial { - c <- &XfrToken{in.Answer, nil} + c <- &XfrMsg{in.Answer, nil} return } } - c <- &XfrToken{in.Answer, nil} + c <- &XfrMsg{in.Answer, nil} } } 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 // 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 // sets the error and returns (it does not close the channel). // 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: // // // q contains the AXFR request -// c := make(chan *XfrToken) +// c := make(chan *XfrMsg) // var e *error // err := XfrSend(w, q, c, e) // w.Hijack() // hijack the connection so that the library doesn't close it // for _, rrset := range rrsets { // rrset is a []RR -// c <- &{XfrToken{RR: rrset} +// c <- &{XfrMsg{RR: rrset} // if e != nil { // close(c) // break // } // } // // 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 { case TypeAXFR, TypeIXFR: 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. -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.SetReply(req) rep.Authoritative = true