Figured out API for server side stuff
This commit is contained in:
parent
57b1e2f714
commit
0130dde9f9
|
@ -15,7 +15,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Responder struct {
|
type Server struct {
|
||||||
Addresses []string // interfaces to use
|
Addresses []string // interfaces to use
|
||||||
Port string // what port to use
|
Port string // what port to use
|
||||||
Timeout int // seconds before giving up on packet
|
Timeout int // seconds before giving up on packet
|
||||||
|
@ -23,6 +23,14 @@ type Responder struct {
|
||||||
Mangle func([]byte) []byte // mangle the packet, before sending
|
Mangle func([]byte) []byte // mangle the packet, before sending
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Every nameserver must implement the Handler interface.
|
||||||
|
type Responder interface {
|
||||||
|
// Receives the raw message content
|
||||||
|
ResponderUDP(c *net.UDPConn, raddr net.Addr, in []byte)
|
||||||
|
// Receives the raw message content
|
||||||
|
ResponderTCP(c *net.TCPConn, raddr net.Addr, in []byte)
|
||||||
|
}
|
||||||
|
|
||||||
// When communicating with a resolver, we use this structure
|
// When communicating with a resolver, we use this structure
|
||||||
// to send packets to it, for sending Error must be nil.
|
// to send packets to it, for sending Error must be nil.
|
||||||
// A resolver responds with a reply packet and a possible error.
|
// A resolver responds with a reply packet and a possible error.
|
||||||
|
@ -34,11 +42,15 @@ type DnsMsg struct {
|
||||||
|
|
||||||
// This is a NAMESERVER
|
// This is a NAMESERVER
|
||||||
// Communicate withit via a channel
|
// Communicate withit via a channel
|
||||||
func (res *Responder) NewResponder() bool {
|
// Interface UDPhandler - has function that gets called
|
||||||
|
// Interface TCPhandler - has function that gets called
|
||||||
|
// NewResponder returns a channel, for communication (start/stop)
|
||||||
|
// caN we use the channel for other stuff??
|
||||||
|
func (res *Server) NewResponder(h Responder) (ch chan DnsMsg) {
|
||||||
var port string
|
var port string
|
||||||
if len(res.Addresses) == 0 {
|
if len(res.Addresses) == 0 {
|
||||||
// We cannot start responding with an addresss
|
// We cannot start responding with an addresss
|
||||||
return false
|
return nil
|
||||||
}
|
}
|
||||||
if res.Port == "" {
|
if res.Port == "" {
|
||||||
port = "53"
|
port = "53"
|
||||||
|
@ -60,15 +72,14 @@ func (res *Responder) NewResponder() bool {
|
||||||
m = m[:n]
|
m = m[:n]
|
||||||
// If I don't pick off the remote addr, but do it in the Go routine
|
// If I don't pick off the remote addr, but do it in the Go routine
|
||||||
// I've created a race condition?? TODO(mg)
|
// I've created a race condition?? TODO(mg)
|
||||||
handlerUDP(res, c, raddr, m)
|
h.ResponderUDP(c, raddr, m)
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
return true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerUDP(res *Responder, c *net.UDPConn, raddr net.Addr, in []byte) {
|
// The raw packet
|
||||||
|
func handlerUDP(c *net.UDPConn, raddr net.Addr, in []byte) {
|
||||||
// don't care what you've read, just blap a default, but put in the
|
// don't care what you've read, just blap a default, but put in the
|
||||||
// correct Id
|
// correct Id
|
||||||
fmt.Printf("handlerUDP called!")
|
fmt.Printf("handlerUDP called!")
|
||||||
|
@ -92,7 +103,3 @@ func handlerUDP(res *Responder, c *net.UDPConn, raddr net.Addr, in []byte) {
|
||||||
out, _ := m.Pack()
|
out, _ := m.Pack()
|
||||||
c.WriteTo(out, raddr)
|
c.WriteTo(out, raddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerTCP(res *Responder, c net.Conn, raddr net.Addr, in []byte) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue