mirror of
https://github.com/miekg/dns.git
synced 2025-10-11 18:01:02 +02:00
pushed
This commit is contained in:
parent
fd12b8a946
commit
57f9f83091
1
TODO
1
TODO
@ -7,6 +7,7 @@ Todo:
|
|||||||
* NSEC and nsec3 closest encloser helper functions
|
* NSEC and nsec3 closest encloser helper functions
|
||||||
* Tsig generation for replies (request MAC)
|
* Tsig generation for replies (request MAC)
|
||||||
* pack/Unpack smaller. EDNS 'n stuff can be folded in
|
* pack/Unpack smaller. EDNS 'n stuff can be folded in
|
||||||
|
* server: don't need the interfaces only functions
|
||||||
|
|
||||||
Longer term:
|
Longer term:
|
||||||
* Parsing from strings, going with goyacc and own lexer
|
* Parsing from strings, going with goyacc and own lexer
|
||||||
|
@ -39,12 +39,12 @@ type Handler interface {
|
|||||||
// an UDP response. An UDP connection needs a remote
|
// an UDP response. An UDP connection needs a remote
|
||||||
// address to write to. ServeUDP() must take care of sending
|
// address to write to. ServeUDP() must take care of sending
|
||||||
// any response back to the requestor.
|
// 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
|
// Receives the raw message content and writes back
|
||||||
// a TCP response. A TCP connection does need to
|
// a TCP response. A TCP connection does need to
|
||||||
// know explicitly be told the remote address. ServeTCP() must
|
// know explicitly be told the remote address. ServeTCP() must
|
||||||
// take care of sending back a response to the requestor.
|
// 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 {
|
func ServeUDP(l *net.UDPConn, handler Handler) os.Error {
|
||||||
@ -58,7 +58,7 @@ func ServeUDP(l *net.UDPConn, handler Handler) os.Error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m = m[:n]
|
m = m[:n]
|
||||||
go handler.ServeUDP(l, radd, m)
|
go handler.ReplyUDP(l, radd, m)
|
||||||
}
|
}
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func ServeTCP(l *net.TCPListener, handler Handler) os.Error {
|
|||||||
}
|
}
|
||||||
i += n
|
i += n
|
||||||
}
|
}
|
||||||
go handler.ServeTCP(c, m)
|
go handler.ReplyTCP(c, m)
|
||||||
}
|
}
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type server Server
|
type server int
|
||||||
|
|
||||||
func createpkg(id uint16, tcp bool, remove net.Addr) []byte {
|
func createpkg(id uint16, tcp bool, remove net.Addr) []byte {
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
@ -32,7 +32,7 @@ func createpkg(id uint16, tcp bool, remove net.Addr) []byte {
|
|||||||
return out
|
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 := new(Msg)
|
||||||
inmsg.Unpack(in)
|
inmsg.Unpack(in)
|
||||||
if inmsg.MsgHdr.Response == true {
|
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)
|
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 := new(Msg)
|
||||||
inmsg.Unpack(in)
|
inmsg.Unpack(in)
|
||||||
if inmsg.MsgHdr.Response == true {
|
if inmsg.MsgHdr.Response == true {
|
||||||
@ -55,10 +55,10 @@ func (h *server) ServeTCP(c *net.TCPConn, in []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResponder(t *testing.T) {
|
func TestResponder(t *testing.T) {
|
||||||
var h server
|
var h *server
|
||||||
go ListenAndServeTCP("127.0.0.1:8053", h.(Handler))
|
go ListenAndServeTCP("127.0.0.1:8053", h)
|
||||||
go ListenAndServeUDP("127.0.0.1:8053", h.(Handler))
|
go ListenAndServeUDP("127.0.0.1:8053", h)
|
||||||
time.Sleep(1 * 1e9)
|
time.Sleep(20 * 1e9)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user