undo some changes

This commit is contained in:
Egon Elbre 2014-07-17 20:48:28 +03:00
parent 1d5e55d9b6
commit dc06b3bde1
5 changed files with 54 additions and 44 deletions

View File

@ -44,36 +44,41 @@ func TestServing(t *testing.T) {
time.Sleep(4e8)
c := new(Client)
m := new(Msg)
m.SetQuestion("miek.nl.", TypeTXT)
r, _, err := c.Exchange(m, "127.0.0.1:8053")
if err != nil {
t.Fatal("Failed to exchange miek.nl", err)
t.Log("Failed to exchange miek.nl", err)
t.Fail()
}
txt := r.Extra[0].(*TXT).Txt[0]
if txt != "Hello world" {
t.Fatal("Unexpected result for miek.nl", txt, "!= Hello world")
t.Log("Unexpected result for miek.nl", txt, "!= Hello world")
t.Fail()
}
m.SetQuestion("example.com.", TypeTXT)
r, _, err = c.Exchange(m, "127.0.0.1:8053")
if err != nil {
t.Fatal("Failed to exchange example.com", err)
t.Log("Failed to exchange example.com", err)
t.Fail()
}
txt = r.Extra[0].(*TXT).Txt[0]
if txt != "Hello example" {
t.Fatal("Unexpected result for example.com", txt, "!= Hello example")
t.Log("Unexpected result for example.com", txt, "!= Hello example")
t.Fail()
}
// Test Mixes cased as noticed by Ask.
m.SetQuestion("eXaMplE.cOm.", TypeTXT)
r, _, err = c.Exchange(m, "127.0.0.1:8053")
if err != nil {
t.Fatal("Failed to exchange eXaMplE.cOm", err)
t.Log("Failed to exchange eXaMplE.cOm", err)
t.Fail()
}
txt = r.Extra[0].(*TXT).Txt[0]
if txt != "Hello example" {
t.Fatal("Unexpected result for example.com", txt, "!= Hello example")
t.Log("Unexpected result for example.com", txt, "!= Hello example")
t.Fail()
}
}
@ -247,7 +252,8 @@ func TestServingLargeResponses(t *testing.T) {
M.Unlock()
_, _, err := c.Exchange(m, "127.0.0.1:10000")
if err != nil {
t.Fatalf("Failed to exchange: %s", err.Error())
t.Logf("Failed to exchange: %s", err.Error())
t.Fail()
}
// This must fail
M.Lock()
@ -255,12 +261,14 @@ func TestServingLargeResponses(t *testing.T) {
M.Unlock()
_, _, err = c.Exchange(m, "127.0.0.1:10000")
if err == nil {
t.Fatalf("Failed to fail exchange, this should generate packet error")
t.Logf("Failed to fail exchange, this should generate packet error")
t.Fail()
}
// But this must work again
c.UDPSize = 7000
_, _, err = c.Exchange(m, "127.0.0.1:10000")
if err != nil {
t.Fatalf("Failed to exchange: %s", err.Error())
t.Logf("Failed to exchange: %s", err.Error())
t.Fail()
}
}

20
udp.go
View File

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !windows
package dns
import (
@ -38,3 +40,21 @@ func setUDPSocketOptions(conn *net.UDPConn) error {
}
return nil
}
// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
// net.UDPAddr.
func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) {
oob := make([]byte, 40)
n, oobn, _, raddr, err := conn.ReadMsgUDP(b, oob)
if err != nil {
return n, nil, err
}
session := &sessionUDP{raddr, oob[:oobn]}
return n, session, err
}
// writeToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *sessionUDP instead of a net.Addr.
func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, error) {
n, _, err := conn.WriteMsgUDP(b, session.context, session.raddr)
return n, err
}

View File

@ -19,24 +19,6 @@ import (
"syscall"
)
// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
// net.UDPAddr.
func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) {
oob := make([]byte, 40)
n, oobn, _, raddr, err := conn.ReadMsgUDP(b, oob)
if err != nil {
return n, nil, err
}
session := &sessionUDP{raddr, oob[:oobn]}
return n, session, err
}
// writeToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *sessionUDP instead of a net.Addr.
func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, error) {
n, _, err := conn.WriteMsgUDP(b, session.context, session.raddr)
return n, err
}
// setUDPSocketOptions4 prepares the v4 socket for sessions.
func setUDPSocketOptions4(conn *net.UDPConn) error {
file, err := conn.File()

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !linux, !windows
// +build !linux
package dns
@ -15,7 +15,7 @@ import (
// We tried to adhire to some kind of naming scheme.
func setUDPSocketOptions4(conn *net.UDPConn) error { return nil }
func setUDPSocketOptions6(conn *net.UDPConn) error { return nil }
func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil }
func setUDPSocketOptions4(conn *net.UDPConn) error { return nil }
func setUDPSocketOptions6(conn *net.UDPConn) error { return nil }
func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil }
func getUDPSocketName(conn *net.UDPConn) (syscall.Sockaddr, error) { return nil, nil }

View File

@ -6,10 +6,11 @@
package dns
import (
"net"
"syscall"
)
import "net"
type sessionUDP struct {
raddr *net.UDPAddr
}
// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
// net.UDPAddr.
@ -18,7 +19,7 @@ func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) {
if err != nil {
return n, nil, err
}
session := &sessionUDP{raddr.(*net.UDPAddr), nil}
session := &sessionUDP{raddr.(*net.UDPAddr)}
return n, session, err
}
@ -28,11 +29,10 @@ func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, e
return n, err
}
// These do nothing. See udp_linux.go for an example of how to implement this.
func (s *sessionUDP) RemoteAddr() net.Addr { return s.raddr }
// We tried to adhire to some kind of naming scheme.
func setUDPSocketOptions4(conn *net.UDPConn) error { return nil }
func setUDPSocketOptions6(conn *net.UDPConn) error { return nil }
func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil }
func getUDPSocketName(conn *net.UDPConn) (syscall.Sockaddr, error) { return nil, nil }
// setUDPSocketOptions sets the UDP socket options.
// This function is implemented on a per platform basis. See udp_*.go for more details
func setUDPSocketOptions(conn *net.UDPConn) error {
return nil
}