API works, but it is not very nice (yet)
This commit is contained in:
parent
7cc589d52a
commit
5c28696357
1
TODO
1
TODO
|
@ -5,6 +5,7 @@ o fast data structures (rb-tree, when they come available)
|
|||
o api-use should be self documenting
|
||||
o multiple queries in api
|
||||
|
||||
o build simple: just query function, built on the cool stuff
|
||||
o make questions fqdns -- add last dot
|
||||
o zone structure -- only as rb-tree or other radix tree
|
||||
o compression (only ownernames?)
|
||||
|
|
20
dns.go
20
dns.go
|
@ -16,24 +16,30 @@
|
|||
// The package dns supports querying, incoming/outgoing Axfr/Ixfr, TSIG, EDNS0,
|
||||
// dynamic updates, notifies and DNSSEC validation/signing.
|
||||
//
|
||||
// Querying the DNS is done by using a Resolver structure. Basic use pattern for creating
|
||||
// Querying the DNS is done by using the Conn structure. Basic use pattern for creating
|
||||
// a resolver:
|
||||
//
|
||||
// res := new(Resolver)
|
||||
// res.Servers = []string{"127.0.0.1"}
|
||||
// func handle(d *Conn, m *Msg, q chan Query) { /* handle query */ }
|
||||
//
|
||||
// in := make(chan Query)
|
||||
// out := QueryAndServeUDP(in, handle)
|
||||
// d := new(Conn)
|
||||
// d.RemoteAddr = "8.8.8.8:53"
|
||||
// m := new(Msg)
|
||||
// m.MsgHdr.Recursion_desired = true
|
||||
// m.Question = make([]Question, 1)
|
||||
// m.Question[0] = Question{"miek.nl", TypeSOA, ClassINET}
|
||||
// in, err := res.Query(m)
|
||||
//
|
||||
// Server side programming is also supported.
|
||||
// in <- Query{Msg: m, Conn: d} // Send query
|
||||
// reply := <-out // Listen for replie(s)
|
||||
//
|
||||
// Server side programming is also supported also by using a Conn structure.
|
||||
// Basic use pattern for creating an UDP DNS server:
|
||||
//
|
||||
// func handle(d *dns.Conn, i *dns.Msg) { /* handle request */ }
|
||||
// func handle(d *Conn, m *Msg) { /* handle request */ }
|
||||
//
|
||||
// func listen(addr string, e chan os.Error) {
|
||||
// err := dns.ListenAndServeUDP(addr, handle)
|
||||
// err := ListenAndServeUDP(addr, handle)
|
||||
// e <- err
|
||||
// }
|
||||
// err := make(chan os.Error)
|
||||
|
|
36
resolver.go
36
resolver.go
|
@ -8,20 +8,20 @@ package dns
|
|||
|
||||
import (
|
||||
"os"
|
||||
"net"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Query is used to communicate with the Query* functions.
|
||||
type Query struct {
|
||||
// The query message.
|
||||
Msg *Msg
|
||||
// A Conn. Its only required to fill out Conn.RemoteAddr.
|
||||
// The rest of the structure is filled in by the Query Functions.
|
||||
// The query message.
|
||||
Msg *Msg
|
||||
// A Conn. Its only required to fill out Conn.RemoteAddr.
|
||||
// The rest of the structure is filled in by the Query Functions.
|
||||
Conn *Conn
|
||||
// Any erros when querying are returned in Err. The caller
|
||||
// should just set this to nil.
|
||||
Err os.Error
|
||||
// Any erros when querying are returned in Err. The caller
|
||||
// should just set this to nil.
|
||||
Err os.Error
|
||||
}
|
||||
|
||||
// QueryUDP handles one query. It reads an incoming request from
|
||||
|
@ -47,16 +47,16 @@ func query(n string, in, out chan Query, f func(*Conn, *Msg, chan Query)) {
|
|||
if err != nil {
|
||||
//out <- nil
|
||||
}
|
||||
if n == "tcp" {
|
||||
q.Conn.SetTCPConn(c.(*net.TCPConn), nil)
|
||||
} else {
|
||||
q.Conn.SetUDPConn(c.(*net.UDPConn), nil)
|
||||
}
|
||||
if f == nil {
|
||||
out <- Query{Err: ErrHandle}
|
||||
} else {
|
||||
go f(q.Conn, q.Msg, out)
|
||||
}
|
||||
if n == "tcp" {
|
||||
q.Conn.SetTCPConn(c.(*net.TCPConn), nil)
|
||||
} else {
|
||||
q.Conn.SetUDPConn(c.(*net.UDPConn), nil)
|
||||
}
|
||||
if f == nil {
|
||||
out <- Query{Err: ErrHandle}
|
||||
} else {
|
||||
go f(q.Conn, q.Msg, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
panic("not reached")
|
||||
|
|
Loading…
Reference in New Issue