This commit is contained in:
Miek Gieben 2011-02-08 22:15:21 +01:00
parent fd12b8a946
commit 57f9f83091
3 changed files with 12 additions and 11 deletions

1
TODO
View File

@ -7,6 +7,7 @@ Todo:
* NSEC and nsec3 closest encloser helper functions
* Tsig generation for replies (request MAC)
* pack/Unpack smaller. EDNS 'n stuff can be folded in
* server: don't need the interfaces only functions
Longer term:
* Parsing from strings, going with goyacc and own lexer

View File

@ -39,12 +39,12 @@ type Handler interface {
// an UDP response. An UDP connection needs a remote
// address to write to. ServeUDP() must take care of sending
// any response back to the requestor.
ServeUDP(c *net.UDPConn, a net.Addr, in []byte)
ReplyUDP(c *net.UDPConn, a net.Addr, in []byte)
// Receives the raw message content and writes back
// a TCP response. A TCP connection does need to
// know explicitly be told the remote address. ServeTCP() must
// take care of sending back a response to the requestor.
ServeTCP(c *net.TCPConn, in []byte)
ReplyTCP(c *net.TCPConn, in []byte)
}
func ServeUDP(l *net.UDPConn, handler Handler) os.Error {
@ -58,7 +58,7 @@ func ServeUDP(l *net.UDPConn, handler Handler) os.Error {
return err
}
m = m[:n]
go handler.ServeUDP(l, radd, m)
go handler.ReplyUDP(l, radd, m)
}
panic("not reached")
}
@ -96,7 +96,7 @@ func ServeTCP(l *net.TCPListener, handler Handler) os.Error {
}
i += n
}
go handler.ServeTCP(c, m)
go handler.ReplyTCP(c, m)
}
panic("not reached")
}

View File

@ -6,7 +6,7 @@ import (
"time"
)
type server Server
type server int
func createpkg(id uint16, tcp bool, remove net.Addr) []byte {
m := new(Msg)
@ -32,7 +32,7 @@ func createpkg(id uint16, tcp bool, remove net.Addr) []byte {
return out
}
func (h *server) ServeUDP(c *net.UDPConn, a net.Addr, in []byte) {
func (h *server) ReplyUDP(c *net.UDPConn, a net.Addr, in []byte) {
inmsg := new(Msg)
inmsg.Unpack(in)
if inmsg.MsgHdr.Response == true {
@ -44,7 +44,7 @@ func (h *server) ServeUDP(c *net.UDPConn, a net.Addr, in []byte) {
SendUDP(out, c, a)
}
func (h *server) ServeTCP(c *net.TCPConn, in []byte) {
func (h *server) ReplyTCP(c *net.TCPConn, in []byte) {
inmsg := new(Msg)
inmsg.Unpack(in)
if inmsg.MsgHdr.Response == true {
@ -55,10 +55,10 @@ func (h *server) ServeTCP(c *net.TCPConn, in []byte) {
}
func TestResponder(t *testing.T) {
var h server
go ListenAndServeTCP("127.0.0.1:8053", h.(Handler))
go ListenAndServeUDP("127.0.0.1:8053", h.(Handler))
time.Sleep(1 * 1e9)
var h *server
go ListenAndServeTCP("127.0.0.1:8053", h)
go ListenAndServeUDP("127.0.0.1:8053", h)
time.Sleep(20 * 1e9)
}
/*