mirror of
https://github.com/miekg/dns.git
synced 2025-10-18 21:31:01 +02:00
some minor updates
This commit is contained in:
parent
3c10506681
commit
13ace2687a
51
client.go
51
client.go
@ -7,7 +7,6 @@ package dns
|
|||||||
// setup for server - a HANDLER function that gets run
|
// setup for server - a HANDLER function that gets run
|
||||||
// when the query returns.
|
// when the query returns.
|
||||||
|
|
||||||
// This completely mirrors server.go impl.
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"io"
|
"io"
|
||||||
@ -23,8 +22,8 @@ type QueryHandler interface {
|
|||||||
type RequestWriter interface {
|
type RequestWriter interface {
|
||||||
WriteMessages([]*Msg)
|
WriteMessages([]*Msg)
|
||||||
Write(*Msg)
|
Write(*Msg)
|
||||||
WriteClient(*Msg) os.Error
|
Send(*Msg) os.Error
|
||||||
ReadClient() (*Msg, os.Error)
|
Receive() (*Msg, os.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hijacked connections...?
|
// hijacked connections...?
|
||||||
@ -117,6 +116,7 @@ func (mux *QueryMux) QueryDNS(w RequestWriter, r *Msg) {
|
|||||||
h.QueryDNS(w, r)
|
h.QueryDNS(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO add: LocalAddr
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Net string // if "tcp" a TCP query will be initiated, otherwise an UDP one
|
Net string // if "tcp" a TCP query will be initiated, otherwise an UDP one
|
||||||
Addr string // address to call
|
Addr string // address to call
|
||||||
@ -176,7 +176,8 @@ func (w *reply) Write(m *Msg) {
|
|||||||
w.Client().ChannelReply <- []*Msg{w.req, m}
|
w.Client().ChannelReply <- []*Msg{w.req, m}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async querie
|
// Do performs an asynchronize query. The result is returned on the
|
||||||
|
// channel set in the c.
|
||||||
func (c *Client) Do(m *Msg, a string) {
|
func (c *Client) Do(m *Msg, a string) {
|
||||||
if c.ChannelQuery == nil {
|
if c.ChannelQuery == nil {
|
||||||
DefaultQueryChan <- &Request{Client: c, Addr: a, Request: m}
|
DefaultQueryChan <- &Request{Client: c, Addr: a, Request: m}
|
||||||
@ -185,30 +186,30 @@ func (c *Client) Do(m *Msg, a string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A synchronize query
|
// A sync query
|
||||||
func (c *Client) Exchange(m *Msg, a string) *Msg {
|
func (c *Client) Exchange(m *Msg, a string) *Msg {
|
||||||
w := new(reply)
|
w := new(reply)
|
||||||
w.client = c
|
w.client = c
|
||||||
w.addr = a
|
w.addr = a
|
||||||
out, ok := m.Pack()
|
out, ok := m.Pack()
|
||||||
if !ok {
|
if !ok {
|
||||||
//
|
//
|
||||||
|
}
|
||||||
|
_, err := w.writeClient(out)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
_, err := w.writeClient(out)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// udp / tcp
|
// udp / tcp
|
||||||
p := make([]byte, DefaultMsgSize)
|
p := make([]byte, DefaultMsgSize)
|
||||||
n, err := w.readClient(p)
|
n, err := w.readClient(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
p = p[:n]
|
p = p[:n]
|
||||||
if ok := m.Unpack(p); !ok {
|
if ok := m.Unpack(p); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +226,7 @@ func (w *reply) Request() *Msg {
|
|||||||
return w.req
|
return w.req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *reply) ReadClient() (*Msg, os.Error) {
|
func (w *reply) Receive() (*Msg, os.Error) {
|
||||||
var p []byte
|
var p []byte
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
switch w.Client().Net {
|
switch w.Client().Net {
|
||||||
@ -261,7 +262,7 @@ func (w *reply) readClient(p []byte) (n int, err os.Error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *reply) WriteClient(m *Msg) os.Error {
|
func (w *reply) Send(m *Msg) os.Error {
|
||||||
out, ok := m.Pack()
|
out, ok := m.Pack()
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrPack
|
return ErrPack
|
||||||
|
Loading…
x
Reference in New Issue
Block a user