diff --git a/TODO b/TODO index 54925e30..205005dc 100644 --- a/TODO +++ b/TODO @@ -17,3 +17,41 @@ Todo: Examples: * Test impl of nameserver, with a small zone, 1 KSK and online signing + +ListenAndServer(addr, Handler, map[string]string, tsig secrets) + + add tis record to mesag when sending -> tsig will be calculated + up to the aolloer .Msg TsigGenerate + + handler Handler === interface that + + Hanlder interface { + ServeDNS + + QueryDNS +} + +ResponseWriter + UsingTsig() domain/ip/key + UsingTCP() + + RemoteAddr string + + Write(byte) n os.Error + + +125 // Create new connection from rwc. +126 func newConn(rwc net.Conn, handler Handler) (c *conn, err os.Error) { +127 c = new(conn) +128 c.remoteAddr = rwc.RemoteAddr().String() +129 c.handler = handler +130 c.rwc = rwc +131 _, c.usingTLS = rwc.(*tls.Conn) +132 br := bufio.NewReader(rwc) +133 bw := bufio.NewWriter(rwc) +134 c.buf = bufio.NewReadWriter(br, bw) +135 return c, nil + +func HelloServer(w dns.ResponseWriter, req *dns.Msg) + +dns.HandleFunc("zonename", HelloServer) diff --git a/server.go b/server.go index 65bb091c..3347a031 100644 --- a/server.go +++ b/server.go @@ -11,6 +11,10 @@ import ( "net" ) +type Handler interface { + ServeDNS(w ResponseWriter, r *Msg) +} + // Handle register the handler the given pattern // in the DefaultServeMux. The documentation for // ServeMux explains how patters are matched. @@ -18,7 +22,28 @@ func Handle(pattern string, handler Hander) { } -type S +// ServeMux is an DNS request multiplexer. It matches the +// zone name of each incoming request against a list of +// registered patterns add calls the handler for the pattern +// that most closely matches the zone name. +type ServeMux struct { + m map[string]Handler +} + +func NewServeMux() *ServeMux { + +} + +func (mux *ServeMux) Handle(pattern string, handler Handler) { + +} + +// ServeDNS dispatches the request to the handler whose +// pattern most closely matches the request message. +func (mux *ServeMux) ServeDNS(w ReponseWriter, request *Msg) { + + +} // HandleUDP handles one UDP connection. It reads the incoming // message and then calls the function f. @@ -108,3 +133,33 @@ func ListenAndServeUDP(addr string, f func(*Conn, *Msg)) os.Error { err = HandleUDP(l, f) return err } + +func zoneMatch(pattern, zone string) bool { + if len(patter) == 0 { + return false + } + n := len(pattern) + return zone[:n] == pattern +} + +func (mux *ServeMux) match(zone string) Handler { + var h Handler + var n = 0 + for k, v := range mux.m { + if !zoneMatch(k, zone) { + continue + } + if h == nil || len(k) > n { + n = len(k) + h = v + } + } + return h +} + +func (mux *ServeMux) Handle(pattern string, handler Handler) { + if pattern == "" { + panic("dns: invalid pattern " + pattern) + } + mux.m[pattern] = handler +}