complete rewrite the resolver side
make it mirror the server side and thus async and concurrent
This commit is contained in:
parent
b4ee9829bc
commit
135772de9f
4
TODO
4
TODO
|
@ -1,12 +1,12 @@
|
|||
|
||||
Guidelines for the API:
|
||||
o symmetrical, client side should be mirrored in the server
|
||||
o clean, small API
|
||||
o fast data structures (rb-tree, when they come available)
|
||||
o api-use should be self documenting
|
||||
o multiple queries in api
|
||||
|
||||
o make questions fqdns -- add last dot
|
||||
o zone structure -- only as rb-tree
|
||||
o zone structure -- only as rb-tree or other radix tree
|
||||
o compression (only ownernames?)
|
||||
|
||||
o Key2DS, also for offline keys -- need to parse them ofcourse
|
||||
|
|
5
dns.go
5
dns.go
|
@ -86,7 +86,11 @@ type Conn struct {
|
|||
// The remote port number of the connection.
|
||||
Port int
|
||||
|
||||
// Remove server (for resolver)
|
||||
RemoteAddr string
|
||||
|
||||
// If TSIG is used, this holds all the information.
|
||||
// If unused is must be nil.
|
||||
Tsig *Tsig
|
||||
|
||||
// Timeout in sec before giving up on a connection.
|
||||
|
@ -366,7 +370,6 @@ func (d *Conn) Exchange(request []byte, nosend bool) (reply []byte, err os.Error
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
// Layer violation to save memory. Its okay then...
|
||||
reply = d.NewBuffer()
|
||||
n, err = d.Read(reply)
|
||||
if err != nil {
|
||||
|
|
1
msg.go
1
msg.go
|
@ -44,6 +44,7 @@ var (
|
|||
ErrSigGen os.Error = &Error{Error: "bad signature generation"}
|
||||
ErrAuth os.Error = &Error{Error: "bad authentication"}
|
||||
ErrXfrSoa os.Error = &Error{Error: "no SOA seen"}
|
||||
ErrHandle os.Error = &Error{Error: "the handle is nill"}
|
||||
)
|
||||
|
||||
// A manually-unpacked version of (id, bits).
|
||||
|
|
49
resolver.go
49
resolver.go
|
@ -8,9 +8,58 @@ package dns
|
|||
|
||||
import (
|
||||
"os"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Query struct {
|
||||
Msg *Msg
|
||||
Conn *Conn
|
||||
Err os.Error
|
||||
}
|
||||
|
||||
// A query implementation that is asyn. and concurrent. Is also
|
||||
// completely mirrors the server side implementation
|
||||
|
||||
func QueryTCP(in, out chan Query, f func(*Conn, *Msg, chan Query)) {
|
||||
query("tcp", in, out, f)
|
||||
}
|
||||
|
||||
func QueryUDP(in, out chan Query, f func(*Conn, *Msg, chan Query)) {
|
||||
query("udp", in, out, f)
|
||||
}
|
||||
|
||||
func query(n string, in, out chan Query, f func(*Conn, *Msg, chan Query)) {
|
||||
for {
|
||||
select {
|
||||
case q := <-in:
|
||||
c, err := net.Dial(n, "", q.Conn.RemoteAddr)
|
||||
if err != nil {
|
||||
//out <- nil
|
||||
}
|
||||
if n == "tcp" {
|
||||
q.Conn.SetTCPConn(c.(*net.TCPConn), nil)
|
||||
} else {
|
||||
q.Conn.SetUDPConn(c.(*net.UDPConn), nil)
|
||||
}
|
||||
go f(q.Conn, q.Msg, out)
|
||||
}
|
||||
}
|
||||
panic("not reached")
|
||||
}
|
||||
|
||||
func QueryAndServeTCP(in chan Query, f func(*Conn, *Msg, chan Query)) chan Query {
|
||||
out := make(chan Query)
|
||||
go QueryTCP(in, out, f)
|
||||
return out
|
||||
}
|
||||
|
||||
func QueryAndServeUDP(in chan Query, f func(*Conn, *Msg, chan Query)) chan Query {
|
||||
out := make(chan Query)
|
||||
go QueryUDP(in, out, f)
|
||||
return out
|
||||
}
|
||||
|
||||
type Resolver struct {
|
||||
Servers []string // servers to use
|
||||
Search []string // suffixes to append to local name (not implemented)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// DNS server implementation
|
||||
// DNS server implementation.
|
||||
|
||||
package dns
|
||||
|
||||
|
@ -67,7 +67,7 @@ func HandleTCP(l *net.TCPListener, f func(*Conn, *Msg)) os.Error {
|
|||
// connections. The function f may not be nil.
|
||||
func ListenAndServeTCP(addr string, f func(*Conn, *Msg)) os.Error {
|
||||
if f == nil {
|
||||
return &Error{Error: "The handle function may not be nil"}
|
||||
return ErrHandle
|
||||
}
|
||||
a, err := net.ResolveTCPAddr(addr)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue