not used yet

This commit is contained in:
Miek Gieben 2010-12-18 23:46:37 +01:00
parent b5640dba89
commit 8a88afca54
5 changed files with 26 additions and 57 deletions

View File

@ -7,7 +7,6 @@ include $(GOROOT)/src/Make.inc
TARG=dns
GOFILES=\
parse.go\
dns.go\
msg.go\
resolver.go \
types.go\

7
README Normal file
View File

@ -0,0 +1,7 @@
Alternate aproach to DNS
Net::DNS
ldns

37
dns.go
View File

@ -1,37 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// DNS client: see RFC 1035.
// Has to be linked into package net for Dial.
// TODO(rsc):
// Check periodically whether /etc/resolv.conf has changed.
// Could potentially handle many outstanding lookups faster.
// Could have a small cache.
// Random UDP source port (net.Dial should do that for us).
// Random request IDs.
package dns
// DnsError represents a DNS lookup error.
type DnsError struct {
Error string // description of the error
Name string // name looked for
Server string // server used
IsTimeout bool
}
func (e *DnsError) String() string {
s := "lookup " + e.Name
if e.Server != "" {
s += " on " + e.Server
}
s += ": " + e.Error
return s
}
func (e *DnsError) Timeout() bool { return e.IsTimeout }
func (e *DnsError) Temporary() bool { return e.IsTimeout }
const noSuchHost = "no such host"

View File

@ -16,9 +16,9 @@ import (
"net"
)
type MsgErr struct {
M *Msg
E os.Error
type DnsMsg struct {
Dns *Msg
Error os.Error
}
type Resolver struct {
@ -35,22 +35,22 @@ type Resolver struct {
// Start a new querier as a goroutine, return
// the communication channel
func NewQuerier(res *Resolver) (ch chan MsgErr) {
ch = make(chan MsgErr)
func NewQuerier(res *Resolver) (ch chan DnsMsg) {
ch = make(chan DnsMsg)
go query(res, ch)
return
}
// do it
func query(res *Resolver, msg chan MsgErr) {
func query(res *Resolver, msg chan DnsMsg) {
var c net.Conn
var err os.Error
var in *Msg
for {
select {
case out := <-msg: //msg received
if out.M == nil {
if out.Dns == nil {
// nil message, quit the goroutine
return
}
@ -58,10 +58,10 @@ func query(res *Resolver, msg chan MsgErr) {
var cerr os.Error
// Set an id
//if len(name) >= 256 {
out.M.Id = uint16(rand.Int()) ^ uint16(time.Nanoseconds())
sending, ok := out.M.Pack()
out.Dns.Id = uint16(rand.Int()) ^ uint16(time.Nanoseconds())
sending, ok := out.Dns.Pack()
if !ok {
msg <- MsgErr{nil, nil} // todo error
msg <- DnsMsg{nil, nil} // todo error
}
for i := 0; i < len(res.Servers); i++ {
@ -81,9 +81,9 @@ func query(res *Resolver, msg chan MsgErr) {
}
}
if err != nil {
msg <- MsgErr{nil, err}
msg <- DnsMsg{nil, err}
} else {
msg <- MsgErr{in, nil}
msg <- DnsMsg{in, nil}
}
}
}

View File

@ -28,23 +28,23 @@ func main() {
for i:=0; i< NLOOP; i++ {
// ask something
m.Question[0] = dns.Question{"miek.nl", dns.TypeSOA, dns.ClassINET}
ch <- dns.MsgErr{m, nil}
ch <- dns.DnsMsg{m, nil}
// wait for an reply
in := <-ch
fmt.Printf("%v\n", in.M)
fmt.Printf("%v\n", in.Dns)
m.Question[0] = dns.Question{"a.miek.nl", dns.TypeTXT, dns.ClassINET}
ch <- dns.MsgErr{m, nil}
ch <- dns.DnsMsg{m, nil}
in = <-ch
fmt.Printf("%v\n", in.M)
fmt.Printf("%v\n", in.Dns)
m.Question[0] = dns.Question{"miek.nl", dns.TypeTXT, dns.ClassINET}
ch <- dns.MsgErr{m, nil}
ch <- dns.DnsMsg{m, nil}
in = <-ch
fmt.Printf("%v\n", in.M)
fmt.Printf("%v\n", in.Dns)
}
ch <- dns.MsgErr{nil, nil}
ch <- dns.DnsMsg{nil, nil}
time.Sleep(2.0e9) // wait for Go routine to do something
}