documentation

This commit is contained in:
Miek Gieben 2012-05-08 14:17:17 +02:00
parent b37c5b4646
commit 95c1154930
5 changed files with 32 additions and 27 deletions

View File

@ -293,7 +293,7 @@ func (c *Client) exchangeBuffer(inbuf []byte, a string, outbuf []byte) (n int, w
// Exchange performs an synchronous query. It sends the message m to the address
// contained in a and waits for an reply. Basic use pattern with a *Client:
//
// c := NewClient()
// c := dns.NewClient()
// in, err := c.Exchange(message, "127.0.0.1:53")
//
// See Client.ExchangeFull(...) to get the round trip time.
@ -305,7 +305,7 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, err error) {
// ExchangeFull performs an synchronous query. It sends the message m to the address
// contained in a and waits for an reply. Basic use pattern with a *Client:
//
// c := NewClient()
// c := dns.NewClient()
// in, rtt, addr, err := c.Exchange(message, "127.0.0.1:53")
//
// The 'addr' return value is superfluous in this case, but it is here to retain symmetry

24
dns.go
View File

@ -17,53 +17,53 @@
// Resource records are native types. They are not stored in wire format.
// Basic usage pattern for creating a new resource record:
//
// r := new(RR_TXT)
// r.Hdr = RR_Header{Name: "miek.nl.", Rrtype: TypeMX, Class: ClassINET, Ttl: 3600}
// r := new(dns.RR_TXT)
// r.Hdr = dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: 3600}
// r.Pref = 10
// r.Mx = "mx.miek.nl."
//
// Or directly from a string:
//
// mx, err := NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
// mx, err := dns.NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
//
// Or when the default TTL (3600) and class (IN) suit you:
//
// mx, err := NewRR("miek.nl. MX 10 mx.miek.nl.")
// mx, err := dns.NewRR("miek.nl. MX 10 mx.miek.nl.")
//
// Or even:
//
// mx, err := NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
// mx, err := dns.NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
//
//
// In the DNS messages are exchanged, these messages contain resource
// records (sets). Use pattern for creating a message:
//
// m := new(Msg)
// m.SetQuestion("miek.nl.", TypeMX)
// m := dns.new(Msg)
// m.SetQuestion("miek.nl.", dns.TypeMX)
//
// The message m is now a message with the question section set to ask
// the MX records for the miek.nl. zone.
//
// The following is slightly more verbose, but more flexible:
//
// m1 := new(Msg)
// m1 := new(dns.Msg)
// m1.MsgHdr.Id = Id()
// m1.MsgHdr.RecursionDesired = false
// m1.Question = make([]Question, 1)
// m1.Question[0] = Question{"miek.nl.", TypeMX, ClassINET}
// m1.Question[0] = dns.Question{"miek.nl.", dns.TypeMX, dns.ClassINET}
//
// After creating a message it can be send.
// Basic use pattern for synchronous querying the DNS at a
// server configured on 127.0.0.1 and port 53:
//
// c := NewClient()
// c := dns.NewClient()
// in, err := c.Exchange(m1, "127.0.0.1:53")
//
// An asynchronous query is also possible, setting up is more elaborate then
// a synchronous query. The Basic use pattern is:
//
// HandleQuery(".", handler)
// ListenAndQuery(nil, nil)
// dns.HandleQuery(".", handler)
// dns.ListenAndQuery(nil, nil)
// c.Do(m1, "127.0.0.1:53")
// // Do something else
// r := <- DefaultReplyChan

View File

@ -14,8 +14,6 @@ import (
type Handler interface {
ServeDNS(w ResponseWriter, r *Msg)
// IP based ACL mapping. The contains the string representation
// of the IP address and a boolean saying it may connect (true) or not.
}
// A ResponseWriter interface is used by an DNS handler to
@ -30,7 +28,7 @@ type ResponseWriter interface {
}
type conn struct {
remoteAddr net.Addr // address of remote side
remoteAddr net.Addr // address of the client
handler Handler // request handler
request []byte // bytes read
_UDP *net.UDPConn // i/o connection if UDP was used
@ -113,6 +111,7 @@ func (mux *ServeMux) match(zone string) Handler {
return h
}
// Handle adds a handler to the ServeMux for pattern.
func (mux *ServeMux) Handle(pattern string, handler Handler) {
if pattern == "" {
panic("dns: invalid pattern " + pattern)
@ -120,10 +119,12 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
mux.m[pattern] = handler
}
// Handle adds a handler to the ServeMux for pattern.
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Msg)) {
mux.Handle(pattern, HandlerFunc(handler))
}
// HandleRemove deregistrars the handler specific for pattern from the ServeMux.
func (mux *ServeMux) HandleRemove(pattern string) {
if pattern == "" {
panic("dns: invalid pattern " + pattern)
@ -168,7 +169,7 @@ type Server struct {
TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>
}
// ListenAndServe starts a nameserver on the configured addressin *Server.
// ListenAndServe starts a nameserver on the configured address in *Server.
func (srv *Server) ListenAndServe() error {
addr := srv.Addr
if addr == "" {

15
tsig.go
View File

@ -6,11 +6,11 @@
// Basic use pattern when querying with a TSIG name "axfr." and the base64
// secret "so6ZGir4GPAqINNh9U5c3A==":
//
// m := new(Msg)
// c := NewClient()
// m := dns.new(Msg)
// c := dns.NewClient()
// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
// m.SetQuestion("miek.nl.", TypeMX)
// m.SetTsig("axfr.", HmacMD5, 300, time.Now().Unix())
// m.SetQuestion("miek.nl.", dns.TypeMX)
// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
// ...
// // When sending the TSIG RR is calculated and filled in before sending
//
@ -19,11 +19,11 @@
// miek.nl. with TSIG key named "axfr." and secret "so6ZGir4GPAqINNh9U5c3A=="
// and using the server 85.223.71.124
//
// c := NewClient()
// c := dns.NewClient()
// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
// m := New(Msg)
// m := new(dns.Msg)
// m.SetAxfr("miek.nl.")
// m.SetTsig("axfr.", HmacMD5, 300, time.Now().Unix())
// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
// err := c.XfrReceive(m, "85.223.71.124:53")
//
// You can now read the records from the AXFR as they come in. Each envelope is checked with TSIG.
@ -88,6 +88,7 @@ func (rr *RR_TSIG) Header() *RR_Header {
}
// TSIG has no official presentation format, but this will suffice.
func (rr *RR_TSIG) String() string {
s := "\n;; TSIG PSEUDOSECTION:\n"
s += rr.Hdr.String() +

View File

@ -57,7 +57,7 @@ const (
_EXPECT_DIRINCLUDE // Directive $INCLUDE
)
// ParseError contains the parse error and the location in the io.Reader
// ParseError is a parsing error. It contains the parse error and the location in the io.Reader
// where the error occured.
type ParseError struct {
file string
@ -119,7 +119,7 @@ func ReadRR(q io.Reader, filename string) (RR, error) {
// Basic usage pattern when reading from a string (z) containing the
// zone data:
//
// to := ParseZone(strings.NewReader(z), "", "testzone")
// to := dns.ParseZone(strings.NewReader(z), "", "testzone")
// for x := range to {
// if x.Error != nil {
// // Do something with x.RR
@ -410,6 +410,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
}
}
/*
func (l lex) _string() string {
switch l.value {
case _STRING:
@ -435,6 +436,7 @@ func (l lex) _string() string {
}
return "**"
}
*/
// zlexer scans the sourcefile and returns tokens on the channel c.
func zlexer(s *scan, c chan lex) {
@ -811,6 +813,7 @@ func locCheckEast(token string, longitude uint32) (uint32, bool) {
return longitude, false
}
// "Eat" the rest of the "line"
func slurpRemainder(c chan lex, f string) *ParseError {
l := <-c
switch l.value {