Convert channels to use pointers. Xfr -> *Xfr
This commit is contained in:
parent
e9e187ac89
commit
bc8186ef04
10
resolver.go
10
resolver.go
|
@ -14,9 +14,9 @@ import (
|
|||
// can send queries (or even pick them up)
|
||||
var (
|
||||
// Request an async query by sending to this channel.
|
||||
QueryRequest chan Query
|
||||
QueryRequest chan *Query
|
||||
// Listen for replies to previously sent queries on this channel.
|
||||
QueryReply chan Query
|
||||
QueryReply chan *Query
|
||||
)
|
||||
|
||||
// Query is used to communicate with the Query* functions.
|
||||
|
@ -39,8 +39,8 @@ type Query struct {
|
|||
// Initialize the QueryRequest and QueryReply channels. This
|
||||
// is only required when async. queries are wanted.
|
||||
func QueryInitChannels() {
|
||||
QueryRequest = make(chan Query)
|
||||
QueryReply = make(chan Query)
|
||||
QueryRequest = make(chan *Query)
|
||||
QueryReply = make(chan *Query)
|
||||
}
|
||||
|
||||
// QueryAndServeTCP listens for incoming requests on channel in and then calls f.
|
||||
|
@ -77,7 +77,7 @@ func query(n string, f func(*Conn, *Msg)) {
|
|||
case q := <-QueryRequest:
|
||||
err := q.Conn.Dial(n)
|
||||
if err != nil {
|
||||
QueryReply <- Query{Err: err}
|
||||
QueryReply <- &Query{Err: err}
|
||||
}
|
||||
go f(q.Conn, q.Query)
|
||||
}
|
||||
|
|
36
xfr.go
36
xfr.go
|
@ -20,11 +20,11 @@ type Xfr struct {
|
|||
// Perform an incoming Ixfr or Axfr. If the message q's question
|
||||
// section contains an AXFR type an Axfr is performed. If q's question
|
||||
// section contains an IXFR type an Ixfr is performed.
|
||||
func (d *Conn) XfrRead(q *Msg, m chan Xfr) {
|
||||
func (d *Conn) XfrRead(q *Msg, m chan *Xfr) {
|
||||
if d.TCP == nil && d.UDP == nil {
|
||||
// No connection yet
|
||||
if err := d.Dial("tcp"); err != nil {
|
||||
m <- Xfr{true, nil, err}
|
||||
m <- &Xfr{true, nil, err}
|
||||
close(m)
|
||||
return
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func (d *Conn) XfrRead(q *Msg, m chan Xfr) {
|
|||
// Send q now.
|
||||
err := d.WriteMsg(q)
|
||||
if err != nil {
|
||||
m <- Xfr{true, nil, err}
|
||||
m <- &Xfr{true, nil, err}
|
||||
close(m)
|
||||
return
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func (d *Conn) XfrRead(q *Msg, m chan Xfr) {
|
|||
case TypeIXFR:
|
||||
d.ixfrRead(q, m)
|
||||
default:
|
||||
m <- Xfr{true, nil, &Error{Error: "Xfr Qtype not recognized"}}
|
||||
m <- &Xfr{true, nil, &Error{Error: "Xfr Qtype not recognized"}}
|
||||
close(m)
|
||||
}
|
||||
}
|
||||
|
@ -51,36 +51,36 @@ func (d *Conn) XfrRead(q *Msg, m chan Xfr) {
|
|||
// section contains an AXFR type an Axfr is performed. If q's question
|
||||
// section contains an IXFR type an Ixfr is performed.
|
||||
// The message q is written to the connection in d.
|
||||
func (d *Conn) XfrWrite(q *Msg, m chan Xfr) {
|
||||
func (d *Conn) XfrWrite(q *Msg, m chan *Xfr) {
|
||||
switch q.Question[0].Qtype {
|
||||
case TypeAXFR:
|
||||
d.axfrWrite(q, m)
|
||||
case TypeIXFR:
|
||||
// d.ixfrWrite(q, m)
|
||||
default:
|
||||
m <- Xfr{true, nil, &Error{Error: "Xfr Qtype not recognized"}}
|
||||
m <- &Xfr{true, nil, &Error{Error: "Xfr Qtype not recognized"}}
|
||||
close(m)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Conn) axfrRead(q *Msg, m chan Xfr) {
|
||||
func (d *Conn) axfrRead(q *Msg, m chan *Xfr) {
|
||||
defer close(m)
|
||||
first := true
|
||||
in := new(Msg)
|
||||
for {
|
||||
err := d.ReadMsg(in)
|
||||
if err != nil {
|
||||
m <- Xfr{true, nil, err}
|
||||
m <- &Xfr{true, nil, err}
|
||||
return
|
||||
}
|
||||
if in.Id != q.Id {
|
||||
m <- Xfr{true, nil, ErrId}
|
||||
m <- &Xfr{true, nil, ErrId}
|
||||
return
|
||||
}
|
||||
|
||||
if first {
|
||||
if !checkXfrSOA(in, true) {
|
||||
m <- Xfr{true, nil, ErrXfrSoa}
|
||||
m <- &Xfr{true, nil, ErrXfrSoa}
|
||||
return
|
||||
}
|
||||
first = !first
|
||||
|
@ -105,7 +105,7 @@ func (d *Conn) axfrRead(q *Msg, m chan Xfr) {
|
|||
}
|
||||
|
||||
// Just send the zone
|
||||
func (d *Conn) axfrWrite(q *Msg, m chan Xfr) {
|
||||
func (d *Conn) axfrWrite(q *Msg, m chan *Xfr) {
|
||||
out := new(Msg)
|
||||
out.Id = q.Id
|
||||
out.Question = q.Question
|
||||
|
@ -145,21 +145,21 @@ func (d *Conn) axfrWrite(q *Msg, m chan Xfr) {
|
|||
}
|
||||
}
|
||||
|
||||
func (d *Conn) ixfrRead(q *Msg, m chan Xfr) {
|
||||
func (d *Conn) ixfrRead(q *Msg, m chan *Xfr) {
|
||||
defer close(m)
|
||||
var serial uint32 // The first serial seen is the current server serial
|
||||
var x Xfr
|
||||
var x *Xfr
|
||||
first := true
|
||||
in := new(Msg)
|
||||
for {
|
||||
|
||||
err := d.ReadMsg(in)
|
||||
if err != nil {
|
||||
m <- Xfr{true, nil, err}
|
||||
m <- &Xfr{true, nil, err}
|
||||
return
|
||||
}
|
||||
if in.Id != q.Id {
|
||||
m <- Xfr{true, nil, ErrId}
|
||||
m <- &Xfr{true, nil, ErrId}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ func (d *Conn) ixfrRead(q *Msg, m chan Xfr) {
|
|||
|
||||
// But still check if the returned answer is ok
|
||||
if !checkXfrSOA(in, true) {
|
||||
m <- Xfr{true, nil, ErrXfrSoa}
|
||||
m <- &Xfr{true, nil, ErrXfrSoa}
|
||||
return
|
||||
}
|
||||
// This serial is important
|
||||
|
@ -229,8 +229,8 @@ func checkXfrSOA(in *Msg, first bool) bool {
|
|||
}
|
||||
|
||||
// Send the answer section to the channel
|
||||
func sendMsg(in *Msg, c chan Xfr, nosoa bool) {
|
||||
x := Xfr{Add: true}
|
||||
func sendMsg(in *Msg, c chan *Xfr, nosoa bool) {
|
||||
x := &Xfr{Add: true}
|
||||
for k, r := range in.Answer {
|
||||
if nosoa && k == len(in.Answer)-1 {
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue