Give the channels more sane names
Rename ChannelQuery to QueryChan and ChannelReply to ReplyChan, both sound much better
This commit is contained in:
parent
c939840fb2
commit
cd17a26192
28
client.go
28
client.go
|
@ -124,8 +124,8 @@ type Client struct {
|
|||
Net string // if "tcp" a TCP query will be initiated, otherwise an UDP one
|
||||
Attempts int // number of attempts
|
||||
Retry bool // retry with TCP
|
||||
ChannelQuery chan *Request // read DNS request from this channel
|
||||
ChannelReply chan *Exchange // write the reply (together with the DNS request) to this channel
|
||||
QueryChan chan *Request // read DNS request from this channel
|
||||
ReplyChan chan *Exchange // write the reply (together with the DNS request) to this channel
|
||||
ReadTimeout int64 // the net.Conn.SetReadTimeout value for new connections
|
||||
WriteTimeout int64 // the net.Conn.SetWriteTimeout value for new connections
|
||||
TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>
|
||||
|
@ -134,19 +134,19 @@ type Client struct {
|
|||
}
|
||||
|
||||
// NewClient creates a new client, with Net set to "udp" and Attempts to 1.
|
||||
// The client's ChannelReply is set to DefaultReplyChan.
|
||||
// The client's ReplyChan is set to DefaultReplyChan.
|
||||
func NewClient() *Client {
|
||||
c := new(Client)
|
||||
c.Net = "udp"
|
||||
c.Attempts = 1
|
||||
c.ChannelReply = DefaultReplyChan
|
||||
c.ReplyChan = DefaultReplyChan
|
||||
c.ReadTimeout = 5000
|
||||
c.WriteTimeout = 5000
|
||||
return c
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
ChannelQuery chan *Request // read DNS request from this channel
|
||||
QueryChan chan *Request // read DNS request from this channel
|
||||
Handler QueryHandler // handler to invoke, dns.DefaultQueryMux if nil
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ func (q *Query) Query() os.Error {
|
|||
//forever:
|
||||
for {
|
||||
select {
|
||||
case in := <-q.ChannelQuery:
|
||||
case in := <-q.QueryChan:
|
||||
w := new(reply)
|
||||
w.req = in.Request
|
||||
w.addr = in.Addr
|
||||
|
@ -170,8 +170,8 @@ func (q *Query) Query() os.Error {
|
|||
}
|
||||
|
||||
func (q *Query) ListenAndQuery() os.Error {
|
||||
if q.ChannelQuery == nil {
|
||||
q.ChannelQuery = DefaultQueryChan
|
||||
if q.QueryChan == nil {
|
||||
q.QueryChan = DefaultQueryChan
|
||||
}
|
||||
return q.Query()
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ func (q *Query) ListenAndQuery() os.Error {
|
|||
// c is nil DefaultQueryChan is used. If handler is nil
|
||||
// DefaultQueryMux is used.
|
||||
func ListenAndQuery(request chan *Request, handler QueryHandler) {
|
||||
q := &Query{ChannelQuery: request, Handler: handler}
|
||||
q := &Query{QueryChan: request, Handler: handler}
|
||||
go q.ListenAndQuery()
|
||||
}
|
||||
|
||||
|
@ -188,17 +188,13 @@ func ListenAndQuery(request chan *Request, handler QueryHandler) {
|
|||
// client.
|
||||
func (w *reply) Write(m *Msg) {
|
||||
// Check if nil??
|
||||
w.Client().ChannelReply <- &Exchange{Request: w.req, Reply: m}
|
||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: m}
|
||||
}
|
||||
|
||||
// Do performs an asynchronous query. The result is returned on the
|
||||
// channel set in the Client c. If no channel is set DefaultQueryChan is used.
|
||||
// QueryChan channel set in the Client c.
|
||||
func (c *Client) Do(m *Msg, a string) {
|
||||
if c.ChannelQuery == nil {
|
||||
DefaultQueryChan <- &Request{Client: c, Addr: a, Request: m}
|
||||
} else {
|
||||
c.ChannelQuery <- &Request{Client: c, Addr: a, Request: m}
|
||||
}
|
||||
c.QueryChan <- &Request{Client: c, Addr: a, Request: m}
|
||||
}
|
||||
|
||||
// ExchangeBuffer performs a synchronous query. It sends the buffer m to the
|
||||
|
|
20
xfr.go
20
xfr.go
|
@ -38,14 +38,14 @@ func (w *reply) axfrReceive() {
|
|||
for {
|
||||
in, err := w.Receive()
|
||||
if err != nil {
|
||||
w.Client().ChannelReply <- &Exchange{w.req, in, err}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
||||
return
|
||||
}
|
||||
/* id check */
|
||||
|
||||
if first {
|
||||
if !checkXfrSOA(in, true) {
|
||||
w.Client().ChannelReply <- &Exchange{w.req, in, ErrXfrSoa}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrSoa}
|
||||
return
|
||||
}
|
||||
first = !first
|
||||
|
@ -54,10 +54,10 @@ func (w *reply) axfrReceive() {
|
|||
if !first {
|
||||
w.tsigTimersOnly = true // Subsequent envelopes use this.
|
||||
if checkXfrSOA(in, false) {
|
||||
w.Client().ChannelReply <- &Exchange{w.req, in, ErrXfrLast}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||
return
|
||||
}
|
||||
w.Client().ChannelReply <- &Exchange{Request: w.req, Reply: in}
|
||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: in}
|
||||
}
|
||||
}
|
||||
panic("not reached")
|
||||
|
@ -71,25 +71,25 @@ func (w *reply) ixfrReceive() {
|
|||
for {
|
||||
in, err := w.Receive()
|
||||
if err != nil {
|
||||
w.Client().ChannelReply <- &Exchange{w.req, in, err}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
||||
return
|
||||
}
|
||||
|
||||
if w.req.Id != in.Id {
|
||||
w.Client().ChannelReply <- &Exchange{w.req, in, ErrId}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrId}
|
||||
return
|
||||
}
|
||||
|
||||
if first {
|
||||
// A single SOA RR signals "no changes"
|
||||
if len(in.Answer) == 1 && checkXfrSOA(in, true) {
|
||||
w.Client().ChannelReply <- &Exchange{w.req, in, ErrXfrLast}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the returned answer is ok
|
||||
if !checkXfrSOA(in, true) {
|
||||
w.Client().ChannelReply <- &Exchange{w.req, in, ErrXfrSoa}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrSoa}
|
||||
return
|
||||
}
|
||||
// This serial is important
|
||||
|
@ -103,11 +103,11 @@ 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().ChannelReply <- &Exchange{w.req, in, ErrXfrLast}
|
||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Client().ChannelReply <- &Exchange{Request: w.req, Reply: in}
|
||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: in}
|
||||
}
|
||||
}
|
||||
panic("not reached")
|
||||
|
|
Loading…
Reference in New Issue