| 1 | package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.25.0 context/" |
| 5 | "crypto/tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/" |
| 6 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 8 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 9 | "netscip-go gomod github.com/golang/go/src go1.25.0 net/" |
| 10 | "runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/" |
| 11 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 12 | "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/" |
| 13 | "sync/atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/" |
| 14 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 15 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 16 | |
| 17 | "golang.org/x/sync/errgroupscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/" |
| 18 | ) |
| 19 | |
| 20 | func HelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServer().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 21 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 22 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 23 | |
| 24 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 25 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{"Hello world"}} |
| 26 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 27 | } |
| 28 | |
| 29 | func HelloServerBadIDscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServerBadID().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 30 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 31 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 32 | m.Idscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Id.++ |
| 33 | |
| 34 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 35 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{"Hello world"}} |
| 36 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 37 | } |
| 38 | |
| 39 | func HelloServerBadThenGoodIDscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServerBadThenGoodID().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 40 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 41 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 42 | m.Idscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Id.++ |
| 43 | |
| 44 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 45 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{"Hello world"}} |
| 46 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 47 | |
| 48 | m.Idscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Id.-- |
| 49 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 50 | } |
| 51 | |
| 52 | func HelloServerEchoAddrPortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServerEchoAddrPort().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 53 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 54 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 55 | |
| 56 | remoteAddr := w.RemoteAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#RemoteAddr.().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().() |
| 57 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 58 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{remoteAddr}} |
| 59 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 60 | } |
| 61 | |
| 62 | func AnotherHelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AnotherHelloServer().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 63 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 64 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 65 | |
| 66 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 67 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{"Hello example"}} |
| 68 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 69 | } |
| 70 | |
| 71 | func RunLocalServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalServer().(pc netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#, l netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenerscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#, opts ...func(*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#)) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) { |
| 72 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{ |
| 73 | PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn.: pc, |
| 74 | Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener.: l, |
| 75 | |
| 76 | ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReadTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., |
| 77 | WriteTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#WriteTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., |
| 78 | } |
| 79 | |
| 80 | waitLock := syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#{} |
| 81 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 82 | server.NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc. = waitLock.Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock(). |
| 83 | |
| 84 | for _, opt := range opts { |
| 85 | opt(server) |
| 86 | } |
| 87 | |
| 88 | var ( |
| 89 | addr string |
| 90 | closer ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Closerscip-go gomod github.com/golang/go/src go1.25.0 io/Closer# |
| 91 | ) |
| 92 | if l != nil { |
| 93 | addr = l.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Addr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().() |
| 94 | closer = l |
| 95 | } else { |
| 96 | addr = pc.LocalAddrscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#LocalAddr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().() |
| 97 | closer = pc |
| 98 | } |
| 99 | |
| 100 | // fin must be buffered so the goroutine below won't block |
| 101 | // forever if fin is never read from. This always happens |
| 102 | // if the channel is discarded and can happen in TestShutdownUDP. |
| 103 | fin := make(chan error, 1) |
| 104 | |
| 105 | go func() { |
| 106 | fin <- server.ActivateAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ActivateAndServe().() |
| 107 | closer.Closescip-go gomod github.com/golang/go/src go1.25.0 io/Closer#Close().() |
| 108 | }() |
| 109 | |
| 110 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 111 | return server, addr, fin, nil |
| 112 | } |
| 113 | |
| 114 | func RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(laddr string, opts ...func(*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#)) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) { |
| 115 | pc, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.ListenPacketscip-go gomod github.com/golang/go/src go1.25.0 net/ListenPacket().("udp", laddr) |
| 116 | if err != nil { |
| 117 | return nil, "", nil, err |
| 118 | } |
| 119 | |
| 120 | return RunLocalServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalServer().(pc, nil, opts...) |
| 121 | } |
| 122 | |
| 123 | func RunLocalPacketConnServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalPacketConnServer().(laddr string, opts ...func(*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#)) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) { |
| 124 | return RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(laddr, append(opts, func(srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) { |
| 125 | // Make srv.PacketConn opaque to trigger the generic code paths. |
| 126 | srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn. = struct{ netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn# }{srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn.} |
| 127 | })...) |
| 128 | } |
| 129 | |
| 130 | func RunLocalTCPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTCPServer().(laddr string, opts ...func(*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#)) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) { |
| 131 | l, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenscip-go gomod github.com/golang/go/src go1.25.0 net/Listen().("tcp", laddr) |
| 132 | if err != nil { |
| 133 | return nil, "", nil, err |
| 134 | } |
| 135 | |
| 136 | return RunLocalServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalServer().(nil, l, opts...) |
| 137 | } |
| 138 | |
| 139 | func RunLocalTLSServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTLSServer().(laddr string, config *tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) { |
| 140 | return RunLocalTCPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTCPServer().(laddr, func(srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) { |
| 141 | srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener. = tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.NewListenerscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/NewListener().(srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener., config) |
| 142 | }) |
| 143 | } |
| 144 | |
| 145 | func RunLocalUnixServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUnixServer().(laddr string, opts ...func(*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#)) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) { |
| 146 | l, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenscip-go gomod github.com/golang/go/src go1.25.0 net/Listen().("unix", laddr) |
| 147 | if err != nil { |
| 148 | return nil, "", nil, err |
| 149 | } |
| 150 | |
| 151 | return RunLocalServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalServer().(nil, l, opts...) |
| 152 | } |
| 153 | |
| 154 | func RunLocalUnixGramServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUnixGramServer().(laddr string, opts ...func(*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#)) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) { |
| 155 | pc, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.ListenPacketscip-go gomod github.com/golang/go/src go1.25.0 net/ListenPacket().("unixgram", laddr) |
| 156 | if err != nil { |
| 157 | return nil, "", nil, err |
| 158 | } |
| 159 | |
| 160 | return RunLocalServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalServer().(pc, nil, opts...) |
| 161 | } |
| 162 | |
| 163 | func RunLocalUnixSeqPacketServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUnixSeqPacketServer().(laddr string) (chan interface{}, string, error) { |
| 164 | pc, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenscip-go gomod github.com/golang/go/src go1.25.0 net/Listen().("unixpacket", laddr) |
| 165 | if err != nil { |
| 166 | return nil, "", err |
| 167 | } |
| 168 | |
| 169 | shutdownChan := make(chan interface{}) |
| 170 | go func() { |
| 171 | pc.Acceptscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Accept().() |
| 172 | <-shutdownChan |
| 173 | }() |
| 174 | |
| 175 | return shutdownChan, pc.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Addr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().(), nil |
| 176 | } |
| 177 | |
| 178 | func TestServingscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServing().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 179 | for _, tc := range []struct { |
| 180 | name string |
| 181 | network string |
| 182 | runServer func(laddr string, opts ...func(*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#)) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, string, chan error, error) |
| 183 | }{ |
| 184 | {"udp", "udp", RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().}, |
| 185 | {"tcp", "tcp", RunLocalTCPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTCPServer().}, |
| 186 | {"PacketConn", "udp", RunLocalPacketConnServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalPacketConnServer().}, |
| 187 | } { |
| 188 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 189 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("miek.nl.", HelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServer().) |
| 190 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", AnotherHelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AnotherHelloServer().) |
| 191 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("miek.nl.") |
| 192 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("example.com.") |
| 193 | |
| 194 | s, addrstr, _, err := tc.runServer(":0") |
| 195 | if err != nil { |
| 196 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 197 | } |
| 198 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 199 | |
| 200 | c := &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{ |
| 201 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: tc.network, |
| 202 | } |
| 203 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 204 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 205 | r, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 206 | if err != nil || len(r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.) == 0 { |
| 207 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange miek.nl", err) |
| 208 | } |
| 209 | txt := r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 210 | if txt != "Hello world" { |
| 211 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for miek.nl", txt, "!= Hello world") |
| 212 | } |
| 213 | |
| 214 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 215 | r, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 216 | if err != nil { |
| 217 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange example.com", err) |
| 218 | } |
| 219 | txt = r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 220 | if txt != "Hello example" { |
| 221 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for example.com", txt, "!= Hello example") |
| 222 | } |
| 223 | |
| 224 | // Test Mixes cased as noticed by Ask. |
| 225 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("eXaMplE.cOm.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 226 | r, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 227 | if err != nil { |
| 228 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("failed to exchange eXaMplE.cOm", err) |
| 229 | } |
| 230 | txt = r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 231 | if txt != "Hello example" { |
| 232 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for example.com", txt, "!= Hello example") |
| 233 | } |
| 234 | }) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // Verify that the server responds to a query with Z flag on, ignoring the flag, and does not echoes it back |
| 239 | func TestServeIgnoresZFlagscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServeIgnoresZFlag().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 240 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", AnotherHelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AnotherHelloServer().) |
| 241 | |
| 242 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 243 | if err != nil { |
| 244 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 245 | } |
| 246 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 247 | |
| 248 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 249 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 250 | |
| 251 | // Test the Z flag is not echoed |
| 252 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 253 | m.Zeroscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Zero. = true |
| 254 | r, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 255 | if err != nil { |
| 256 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange example.com with +zflag", err) |
| 257 | } |
| 258 | if r.Zeroscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Zero. { |
| 259 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("the response should not have Z flag set - even for a query which does") |
| 260 | } |
| 261 | if r.Rcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Rcode. != RcodeSuccessscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RcodeSuccess. { |
| 262 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected rcode %v, got %v", RcodeSuccessscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RcodeSuccess., r.Rcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Rcode.) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // Verify that the server responds to a query with unsupported Opcode with a NotImplemented error and that Opcode is unchanged. |
| 267 | func TestServeNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServeNotImplemented().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 268 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", AnotherHelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AnotherHelloServer().) |
| 269 | opcode := 15 |
| 270 | |
| 271 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 272 | if err != nil { |
| 273 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 274 | } |
| 275 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 276 | |
| 277 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 278 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 279 | |
| 280 | // Test that Opcode is like the unchanged from request Opcode and that Rcode is set to NotImplemented |
| 281 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 282 | m.Opcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Opcode. = opcode |
| 283 | r, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 284 | if err != nil { |
| 285 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange example.com with +zflag", err) |
| 286 | } |
| 287 | if r.Opcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Opcode. != opcode { |
| 288 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected opcode %v, got %v", opcode, r.Opcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Opcode.) |
| 289 | } |
| 290 | if r.Rcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Rcode. != RcodeNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RcodeNotImplemented. { |
| 291 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected rcode %v, got %v", RcodeNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RcodeNotImplemented., r.Rcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Rcode.) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | func TestServingTLSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServingTLS().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 296 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("miek.nl.", HelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServer().) |
| 297 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", AnotherHelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AnotherHelloServer().) |
| 298 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("miek.nl.") |
| 299 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("example.com.") |
| 300 | |
| 301 | cert, err := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.X509KeyPairscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/X509KeyPair().(CertPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertPEMBlock., KeyPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/KeyPEMBlock.) |
| 302 | if err != nil { |
| 303 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to build certificate: %v", err) |
| 304 | } |
| 305 | |
| 306 | config := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 307 | Certificatesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#Certificates.: []tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Certificate#{cert}, |
| 308 | } |
| 309 | |
| 310 | s, addrstr, _, err := RunLocalTLSServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTLSServer().(":0", &config) |
| 311 | if err != nil { |
| 312 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 313 | } |
| 314 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 315 | |
| 316 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 317 | c.Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net. = "tcp-tls" |
| 318 | c.TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#TLSConfig. = &tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 319 | InsecureSkipVerifyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#InsecureSkipVerify.: true, |
| 320 | } |
| 321 | |
| 322 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 323 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 324 | r, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 325 | if err != nil || len(r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.) == 0 { |
| 326 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange miek.nl", err) |
| 327 | } |
| 328 | txt := r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 329 | if txt != "Hello world" { |
| 330 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for miek.nl", txt, "!= Hello world") |
| 331 | } |
| 332 | |
| 333 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 334 | r, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 335 | if err != nil { |
| 336 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange example.com", err) |
| 337 | } |
| 338 | txt = r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 339 | if txt != "Hello example" { |
| 340 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for example.com", txt, "!= Hello example") |
| 341 | } |
| 342 | |
| 343 | // Test Mixes cased as noticed by Ask. |
| 344 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("eXaMplE.cOm.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 345 | r, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 346 | if err != nil { |
| 347 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("failed to exchange eXaMplE.cOm", err) |
| 348 | } |
| 349 | txt = r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 350 | if txt != "Hello example" { |
| 351 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for example.com", txt, "!= Hello example") |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | // TestServingTLSConnectionState tests that we only can access |
| 356 | // tls.ConnectionState under a DNS query handled by a TLS DNS server. |
| 357 | // This test will sequentially create a TLS, UDP and TCP server, attach a custom |
| 358 | // handler which will set a testing error if tls.ConnectionState is available |
| 359 | // when it is not expected, or the other way around. |
| 360 | func TestServingTLSConnectionStatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServingTLSConnectionState().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 361 | handlerResponse := "Hello example" |
| 362 | // tlsHandlerTLS is a HandlerFunc that can be set to expect or not TLS |
| 363 | // connection state. |
| 364 | tlsHandlerTLS := func(tlsExpected bool) func(ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 365 | return func(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 366 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 367 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 368 | tlsFound := true |
| 369 | if connState := w.(ConnectionStaterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ConnectionStater#).ConnectionStatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ConnectionStater#ConnectionState.(); connState == nil { |
| 370 | tlsFound = false |
| 371 | } |
| 372 | if tlsFound != tlsExpected { |
| 373 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("TLS connection state available: %t, expected: %t", tlsFound, tlsExpected) |
| 374 | } |
| 375 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 376 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{handlerResponse}} |
| 377 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // Question used in tests |
| 382 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 383 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("tlsstate.example.net.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 384 | |
| 385 | // TLS DNS server |
| 386 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().(".", tlsHandlerTLS(true)) |
| 387 | cert, err := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.X509KeyPairscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/X509KeyPair().(CertPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertPEMBlock., KeyPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/KeyPEMBlock.) |
| 388 | if err != nil { |
| 389 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to build certificate: %v", err) |
| 390 | } |
| 391 | |
| 392 | config := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 393 | Certificatesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#Certificates.: []tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Certificate#{cert}, |
| 394 | } |
| 395 | |
| 396 | s, addrstr, _, err := RunLocalTLSServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTLSServer().(":0", &config) |
| 397 | if err != nil { |
| 398 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 399 | } |
| 400 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 401 | |
| 402 | // TLS DNS query |
| 403 | c := &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{ |
| 404 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: "tcp-tls", |
| 405 | TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#TLSConfig.: &tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 406 | InsecureSkipVerifyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#InsecureSkipVerify.: true, |
| 407 | }, |
| 408 | } |
| 409 | |
| 410 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 411 | if err != nil { |
| 412 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("failed to exchange tlsstate.example.net", err) |
| 413 | } |
| 414 | |
| 415 | HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().(".") |
| 416 | // UDP DNS Server |
| 417 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().(".", tlsHandlerTLS(false)) |
| 418 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().(".") |
| 419 | s, addrstr, _, err = RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 420 | if err != nil { |
| 421 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 422 | } |
| 423 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 424 | |
| 425 | // UDP DNS query |
| 426 | c = new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 427 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 428 | if err != nil { |
| 429 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("failed to exchange tlsstate.example.net", err) |
| 430 | } |
| 431 | |
| 432 | // TCP DNS Server |
| 433 | s, addrstr, _, err = RunLocalTCPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTCPServer().(":0") |
| 434 | if err != nil { |
| 435 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 436 | } |
| 437 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 438 | |
| 439 | // TCP DNS query |
| 440 | c = &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: "tcp"} |
| 441 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 442 | if err != nil { |
| 443 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("failed to exchange tlsstate.example.net", err) |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | func TestServingListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServingListenAndServe().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 448 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", AnotherHelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AnotherHelloServer().) |
| 449 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("example.com.") |
| 450 | |
| 451 | waitLock := syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#{} |
| 452 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: ":0", Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: "udp", ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReadTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., WriteTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#WriteTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc.: waitLock.Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock().} |
| 453 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 454 | |
| 455 | go func() { |
| 456 | server.ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() |
| 457 | }() |
| 458 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 459 | |
| 460 | c, m := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#), new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 461 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 462 | addr := server.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn..LocalAddrscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#LocalAddr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().() // Get address via the PacketConn that gets set. |
| 463 | r, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addr) |
| 464 | if err != nil { |
| 465 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange example.com", err) |
| 466 | } |
| 467 | txt := r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 468 | if txt != "Hello example" { |
| 469 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for example.com", txt, "!= Hello example") |
| 470 | } |
| 471 | server.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 472 | } |
| 473 | |
| 474 | func TestServingListenAndServeTLSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServingListenAndServeTLS().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 475 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", AnotherHelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AnotherHelloServer().) |
| 476 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("example.com.") |
| 477 | |
| 478 | cert, err := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.X509KeyPairscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/X509KeyPair().(CertPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertPEMBlock., KeyPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/KeyPEMBlock.) |
| 479 | if err != nil { |
| 480 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to build certificate: %v", err) |
| 481 | } |
| 482 | |
| 483 | config := &tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 484 | Certificatesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#Certificates.: []tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Certificate#{cert}, |
| 485 | } |
| 486 | |
| 487 | waitLock := syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#{} |
| 488 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: ":0", Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: "tcp", TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TLSConfig.: config, ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReadTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., WriteTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#WriteTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc.: waitLock.Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock().} |
| 489 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 490 | |
| 491 | go func() { |
| 492 | server.ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() |
| 493 | }() |
| 494 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 495 | |
| 496 | c, m := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#), new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 497 | c.Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net. = "tcp" |
| 498 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 499 | addr := server.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener..Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Addr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().() // Get address via the Listener that gets set. |
| 500 | r, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addr) |
| 501 | if err != nil { |
| 502 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 503 | } |
| 504 | txt := r.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0].(*TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#).Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.[0] |
| 505 | if txt != "Hello example" { |
| 506 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("unexpected result for example.com", txt, "!= Hello example") |
| 507 | } |
| 508 | server.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 509 | } |
| 510 | |
| 511 | func BenchmarkServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkServe().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 512 | b.StopTimerscip-go gomod github.com/golang/go/src go1.25.0 testing/B#StopTimer().() |
| 513 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("miek.nl.", HelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServer().) |
| 514 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("miek.nl.") |
| 515 | a := runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOMAXPROCS().(4) |
| 516 | |
| 517 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 518 | if err != nil { |
| 519 | b.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 520 | } |
| 521 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 522 | |
| 523 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 524 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 525 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeSOAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeSOA.) |
| 526 | |
| 527 | b.StartTimerscip-go gomod github.com/golang/go/src go1.25.0 testing/B#StartTimer().() |
| 528 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ { |
| 529 | _, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 530 | if err != nil { |
| 531 | b.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Exchange failed: %v", err) |
| 532 | } |
| 533 | } |
| 534 | runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOMAXPROCS().(a) |
| 535 | } |
| 536 | |
| 537 | func BenchmarkServe6scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkServe6().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 538 | b.StopTimerscip-go gomod github.com/golang/go/src go1.25.0 testing/B#StopTimer().() |
| 539 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("miek.nl.", HelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServer().) |
| 540 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("miek.nl.") |
| 541 | a := runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOMAXPROCS().(4) |
| 542 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().("[::1]:0") |
| 543 | if err != nil { |
| 544 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), "bind: cannot assign requested address") { |
| 545 | b.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("missing IPv6 support") |
| 546 | } |
| 547 | b.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 548 | } |
| 549 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 550 | |
| 551 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 552 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 553 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeSOAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeSOA.) |
| 554 | |
| 555 | b.StartTimerscip-go gomod github.com/golang/go/src go1.25.0 testing/B#StartTimer().() |
| 556 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ { |
| 557 | _, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 558 | if err != nil { |
| 559 | b.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Exchange failed: %v", err) |
| 560 | } |
| 561 | } |
| 562 | runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOMAXPROCS().(a) |
| 563 | } |
| 564 | |
| 565 | func HelloServerCompressscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServerCompress().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 566 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 567 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 568 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 569 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{"Hello world"}} |
| 570 | m.Compressscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Compress. = true |
| 571 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 572 | } |
| 573 | |
| 574 | func BenchmarkServeCompressscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkServeCompress().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 575 | b.StopTimerscip-go gomod github.com/golang/go/src go1.25.0 testing/B#StopTimer().() |
| 576 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("miek.nl.", HelloServerCompressscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServerCompress().) |
| 577 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("miek.nl.") |
| 578 | a := runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOMAXPROCS().(4) |
| 579 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 580 | if err != nil { |
| 581 | b.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 582 | } |
| 583 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 584 | |
| 585 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 586 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 587 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeSOAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeSOA.) |
| 588 | b.StartTimerscip-go gomod github.com/golang/go/src go1.25.0 testing/B#StartTimer().() |
| 589 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ { |
| 590 | _, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 591 | if err != nil { |
| 592 | b.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Exchange failed: %v", err) |
| 593 | } |
| 594 | } |
| 595 | runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOMAXPROCS().(a) |
| 596 | } |
| 597 | |
| 598 | type maxRecscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxRec# struct { |
| 599 | maxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxRec#max. int |
| 600 | syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.RWMutexscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxRec#RWMutex. |
| 601 | } |
| 602 | |
| 603 | var Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M. = new(maxRecscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxRec#) |
| 604 | |
| 605 | func HelloServerLargeResponsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServerLargeResponse().(resp ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 606 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 607 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 608 | m.Authoritativescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Authoritative. = true |
| 609 | m1 := 0 |
| 610 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 611 | m1 = Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..maxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxRec#max. |
| 612 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 613 | for i := 0; i < m1; i++ { |
| 614 | aRec := &Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#{ |
| 615 | Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{ |
| 616 | Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: req.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., |
| 617 | Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeA., |
| 618 | Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., |
| 619 | Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0, |
| 620 | }, |
| 621 | Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.: netscip-go gomod github.com/golang/go/src go1.25.0 net/.ParseIPscip-go gomod github.com/golang/go/src go1.25.0 net/ParseIP().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("127.0.0.%d", i+1)).To4scip-go gomod github.com/golang/go/src go1.25.0 net/IP#To4().(), |
| 622 | } |
| 623 | m.Answerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Answer. = append(m.Answerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Answer., aRec) |
| 624 | } |
| 625 | resp.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 626 | } |
| 627 | |
| 628 | func TestServingLargeResponsesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServingLargeResponses().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 629 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.", HelloServerLargeResponsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServerLargeResponse().) |
| 630 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("example.") |
| 631 | |
| 632 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 633 | if err != nil { |
| 634 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 635 | } |
| 636 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 637 | |
| 638 | // Create request |
| 639 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 640 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("web.service.example.", TypeANYscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeANY.) |
| 641 | |
| 642 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 643 | c.Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net. = "udp" |
| 644 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 645 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..maxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxRec#max. = 2 |
| 646 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 647 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 648 | if err != nil { |
| 649 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to exchange: %v", err) |
| 650 | } |
| 651 | // This must fail |
| 652 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 653 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..maxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxRec#max. = 20 |
| 654 | Mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/M..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 655 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 656 | if err == nil { |
| 657 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("failed to fail exchange, this should generate packet error") |
| 658 | } |
| 659 | // But this must work again |
| 660 | c.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#UDPSize. = 7000 |
| 661 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 662 | if err != nil { |
| 663 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to exchange: %v", err) |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | func TestServingResponsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServingResponse().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 668 | if testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Shortscip-go gomod github.com/golang/go/src go1.25.0 testing/Short().() { |
| 669 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("skipping test in short mode.") |
| 670 | } |
| 671 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("miek.nl.", HelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServer().) |
| 672 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 673 | if err != nil { |
| 674 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 675 | } |
| 676 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 677 | |
| 678 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 679 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 680 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 681 | m.Responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Response. = false |
| 682 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 683 | if err != nil { |
| 684 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange", err) |
| 685 | } |
| 686 | m.Responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Response. = true // this holds up the reply, set short read time out to avoid waiting too long |
| 687 | c.ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#ReadTimeout. = 100 * timescip-go gomod github.com/golang/go/src go1.25.0 time/.Millisecondscip-go gomod github.com/golang/go/src go1.25.0 time/Millisecond. |
| 688 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 689 | if err == nil { |
| 690 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("exchanged response message") |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | func TestShutdownTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestShutdownTCP().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 695 | s, _, fin, err := RunLocalTCPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTCPServer().(":0") |
| 696 | if err != nil { |
| 697 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 698 | } |
| 699 | err = s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 700 | if err != nil { |
| 701 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not shutdown test TCP server, %v", err) |
| 702 | } |
| 703 | select { |
| 704 | case err := <-fin: |
| 705 | if err != nil { |
| 706 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("error returned from ActivateAndServe, %v", err) |
| 707 | } |
| 708 | case <-timescip-go gomod github.com/golang/go/src go1.25.0 time/.Afterscip-go gomod github.com/golang/go/src go1.25.0 time/After().(2 * timescip-go gomod github.com/golang/go/src go1.25.0 time/.Secondscip-go gomod github.com/golang/go/src go1.25.0 time/Second.): |
| 709 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("could not shutdown test TCP server. Gave up waiting") |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | func initscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/init().() { |
| 714 | testShutdownNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testShutdownNotify. = &syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Condscip-go gomod github.com/golang/go/src go1.25.0 sync/Cond#{ |
| 715 | Lscip-go gomod github.com/golang/go/src go1.25.0 sync/Cond#L.: new(syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#), |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | func checkInProgressQueriesAtShutdownServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/checkInProgressQueriesAtShutdownServer().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, addr string, client *Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) { |
| 720 | const requests = 15 // enough to make this interesting? TODO: find a proper value |
| 721 | |
| 722 | var errOnce syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Oncescip-go gomod github.com/golang/go/src go1.25.0 sync/Once# |
| 723 | // t.Fail will panic if it's called after the test function has |
| 724 | // finished. Burning the sync.Once with a defer will prevent the |
| 725 | // handler from calling t.Errorf after we've returned. |
| 726 | defer errOnce.Doscip-go gomod github.com/golang/go/src go1.25.0 sync/Once#Do().(func() {}) |
| 727 | |
| 728 | toHandle := int32(requests) |
| 729 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", func(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 730 | defer atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/AddInt32().(&toHandle, -1) |
| 731 | |
| 732 | // Wait until ShutdownContext is called before replying. |
| 733 | testShutdownNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testShutdownNotify..Lscip-go gomod github.com/golang/go/src go1.25.0 sync/Cond#L..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Locker#Lock().() |
| 734 | testShutdownNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testShutdownNotify..Waitscip-go gomod github.com/golang/go/src go1.25.0 sync/Cond#Wait().() |
| 735 | testShutdownNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testShutdownNotify..Lscip-go gomod github.com/golang/go/src go1.25.0 sync/Cond#L..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Locker#Unlock().() |
| 736 | |
| 737 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 738 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(req) |
| 739 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = make([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#, 1) |
| 740 | m.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra.[0] = &TXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: m.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0}, Txtscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TXT#Txt.: []string{"Hello world"}} |
| 741 | |
| 742 | if err := w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m); err != nil { |
| 743 | errOnce.Doscip-go gomod github.com/golang/go/src go1.25.0 sync/Once#Do().(func() { |
| 744 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("ResponseWriter.WriteMsg error: %s", err) |
| 745 | }) |
| 746 | } |
| 747 | }) |
| 748 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().("example.com.") |
| 749 | |
| 750 | client.Timeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Timeout. = 1 * timescip-go gomod github.com/golang/go/src go1.25.0 time/.Secondscip-go gomod github.com/golang/go/src go1.25.0 time/Second. |
| 751 | |
| 752 | conns := make([]*Connscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Conn#, requests) |
| 753 | eg := new(errgroupscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/.Groupscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#) |
| 754 | |
| 755 | for i := range conns { |
| 756 | conn := &conns[i] |
| 757 | eg.Goscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Go().(func() error { |
| 758 | var err error |
| 759 | *conn, err = client.Dialscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Dial().(addr) |
| 760 | return err |
| 761 | }) |
| 762 | } |
| 763 | |
| 764 | if eg.Waitscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Wait().() != nil { |
| 765 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("client.Dial error: %v", eg.Waitscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Wait().()) |
| 766 | } |
| 767 | |
| 768 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 769 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 770 | eg = new(errgroupscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/.Groupscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#) |
| 771 | |
| 772 | for _, conn := range conns { |
| 773 | conn := conn |
| 774 | eg.Goscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Go().(func() error { |
| 775 | conn.SetWriteDeadlinescip-go gomod github.com/golang/go/src go1.25.0 net/Conn#SetWriteDeadline().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Add().(client.Timeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Timeout.)) |
| 776 | |
| 777 | return conn.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Conn#WriteMsg().(m) |
| 778 | }) |
| 779 | } |
| 780 | |
| 781 | if eg.Waitscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Wait().() != nil { |
| 782 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("conn.WriteMsg error: %v", eg.Waitscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Wait().()) |
| 783 | } |
| 784 | |
| 785 | // This sleep is needed to allow time for the requests to |
| 786 | // pass from the client through the kernel and back into |
| 787 | // the server. Without it, some requests may still be in |
| 788 | // the kernel's buffer when ShutdownContext is called. |
| 789 | timescip-go gomod github.com/golang/go/src go1.25.0 time/.Sleepscip-go gomod github.com/golang/go/src go1.25.0 time/Sleep().(100 * timescip-go gomod github.com/golang/go/src go1.25.0 time/.Millisecondscip-go gomod github.com/golang/go/src go1.25.0 time/Millisecond.) |
| 790 | |
| 791 | eg = new(errgroupscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/.Groupscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#) |
| 792 | |
| 793 | for _, conn := range conns { |
| 794 | conn := conn |
| 795 | eg.Goscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Go().(func() error { |
| 796 | conn.SetReadDeadlinescip-go gomod github.com/golang/go/src go1.25.0 net/Conn#SetReadDeadline().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Add().(client.Timeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Timeout.)) |
| 797 | |
| 798 | _, err := conn.ReadMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Conn#ReadMsg().() |
| 799 | return err |
| 800 | }) |
| 801 | } |
| 802 | |
| 803 | ctx, cancel := contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.25.0 context/WithTimeout().(contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.0 context/Background().(), client.Timeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Timeout.) |
| 804 | defer cancel() |
| 805 | |
| 806 | if err := srv.ShutdownContextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ShutdownContext().(ctx); err != nil { |
| 807 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("could not shutdown test server: %v", err) |
| 808 | } |
| 809 | |
| 810 | if left := atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.LoadInt32scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/LoadInt32().(&toHandle); left != 0 { |
| 811 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("ShutdownContext returned before %d replies", left) |
| 812 | } |
| 813 | |
| 814 | if eg.Waitscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Wait().() != nil { |
| 815 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("conn.ReadMsg error: %v", eg.Waitscip-go gomod golang.org/x/sync v0.22.0 `golang.org/x/sync/errgroup`/Group#Wait().()) |
| 816 | } |
| 817 | |
| 818 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 819 | defer srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 820 | if len(srv.connsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#conns.) != 0 { |
| 821 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("TCP connection tracking map not empty after ShutdownContext; map still contains %d connections", len(srv.connsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#conns.)) |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | func TestInProgressQueriesAtShutdownTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestInProgressQueriesAtShutdownTCP().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 826 | s, addr, _, err := RunLocalTCPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTCPServer().(":0") |
| 827 | if err != nil { |
| 828 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 829 | } |
| 830 | |
| 831 | c := &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: "tcp"} |
| 832 | checkInProgressQueriesAtShutdownServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/checkInProgressQueriesAtShutdownServer().(t, s, addr, c) |
| 833 | } |
| 834 | |
| 835 | func TestShutdownTLSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestShutdownTLS().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 836 | cert, err := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.X509KeyPairscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/X509KeyPair().(CertPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertPEMBlock., KeyPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/KeyPEMBlock.) |
| 837 | if err != nil { |
| 838 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to build certificate: %v", err) |
| 839 | } |
| 840 | |
| 841 | config := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 842 | Certificatesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#Certificates.: []tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Certificate#{cert}, |
| 843 | } |
| 844 | |
| 845 | s, _, _, err := RunLocalTLSServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTLSServer().(":0", &config) |
| 846 | if err != nil { |
| 847 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 848 | } |
| 849 | err = s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 850 | if err != nil { |
| 851 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("could not shutdown test TLS server, %v", err) |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | func TestInProgressQueriesAtShutdownTLSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestInProgressQueriesAtShutdownTLS().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 856 | cert, err := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.X509KeyPairscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/X509KeyPair().(CertPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertPEMBlock., KeyPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/KeyPEMBlock.) |
| 857 | if err != nil { |
| 858 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to build certificate: %v", err) |
| 859 | } |
| 860 | |
| 861 | config := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 862 | Certificatesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#Certificates.: []tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Certificate#{cert}, |
| 863 | } |
| 864 | |
| 865 | s, addr, _, err := RunLocalTLSServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalTLSServer().(":0", &config) |
| 866 | if err != nil { |
| 867 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 868 | } |
| 869 | |
| 870 | c := &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{ |
| 871 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: "tcp-tls", |
| 872 | TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#TLSConfig.: &tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 873 | InsecureSkipVerifyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#InsecureSkipVerify.: true, |
| 874 | }, |
| 875 | } |
| 876 | checkInProgressQueriesAtShutdownServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/checkInProgressQueriesAtShutdownServer().(t, s, addr, c) |
| 877 | } |
| 878 | |
| 879 | func TestHandlerCloseTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestHandlerCloseTCP().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 880 | ln, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenscip-go gomod github.com/golang/go/src go1.25.0 net/Listen().("tcp", ":0") |
| 881 | if err != nil { |
| 882 | panic(err) |
| 883 | } |
| 884 | addr := ln.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Addr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().() |
| 885 | |
| 886 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: addr, Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: "tcp", Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener.: ln} |
| 887 | |
| 888 | hname := "testhandlerclosetcp." |
| 889 | triggered := make(chan struct{}) |
| 890 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().(hname, func(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, r *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 891 | close(triggered) |
| 892 | w.Closescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#Close.() |
| 893 | }) |
| 894 | defer HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().(hname) |
| 895 | |
| 896 | go func() { |
| 897 | defer server.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 898 | c := &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: "tcp"} |
| 899 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#).SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().(hname, 1) |
| 900 | tries := 0 |
| 901 | exchange: |
| 902 | _, _, err := c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addr) |
| 903 | if err != nil && err != ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF. { |
| 904 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("exchange failed: %v", err) |
| 905 | if tries == 3 { |
| 906 | return |
| 907 | } |
| 908 | timescip-go gomod github.com/golang/go/src go1.25.0 time/.Sleepscip-go gomod github.com/golang/go/src go1.25.0 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Secondscip-go gomod github.com/golang/go/src go1.25.0 time/Second. / 10) |
| 909 | tries++ |
| 910 | goto exchange |
| 911 | } |
| 912 | }() |
| 913 | if err := server.ActivateAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ActivateAndServe().(); err != nil { |
| 914 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("ActivateAndServe failed: %v", err) |
| 915 | } |
| 916 | select { |
| 917 | case <-triggered: |
| 918 | default: |
| 919 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("handler never called") |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | func TestShutdownUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestShutdownUDP().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 924 | s, _, fin, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 925 | if err != nil { |
| 926 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 927 | } |
| 928 | err = s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 929 | if err != nil { |
| 930 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("could not shutdown test UDP server, %v", err) |
| 931 | } |
| 932 | select { |
| 933 | case err := <-fin: |
| 934 | if err != nil { |
| 935 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("error returned from ActivateAndServe, %v", err) |
| 936 | } |
| 937 | case <-timescip-go gomod github.com/golang/go/src go1.25.0 time/.Afterscip-go gomod github.com/golang/go/src go1.25.0 time/After().(2 * timescip-go gomod github.com/golang/go/src go1.25.0 time/.Secondscip-go gomod github.com/golang/go/src go1.25.0 time/Second.): |
| 938 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("could not shutdown test UDP server. Gave up waiting") |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | func TestShutdownPacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestShutdownPacketConn().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 943 | s, _, fin, err := RunLocalPacketConnServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalPacketConnServer().(":0") |
| 944 | if err != nil { |
| 945 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 946 | } |
| 947 | err = s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 948 | if err != nil { |
| 949 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("could not shutdown test UDP server, %v", err) |
| 950 | } |
| 951 | select { |
| 952 | case err := <-fin: |
| 953 | if err != nil { |
| 954 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("error returned from ActivateAndServe, %v", err) |
| 955 | } |
| 956 | case <-timescip-go gomod github.com/golang/go/src go1.25.0 time/.Afterscip-go gomod github.com/golang/go/src go1.25.0 time/After().(2 * timescip-go gomod github.com/golang/go/src go1.25.0 time/.Secondscip-go gomod github.com/golang/go/src go1.25.0 time/Second.): |
| 957 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("could not shutdown test UDP server. Gave up waiting") |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | func TestInProgressQueriesAtShutdownUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestInProgressQueriesAtShutdownUDP().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 962 | s, addr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 963 | if err != nil { |
| 964 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 965 | } |
| 966 | |
| 967 | c := &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: "udp"} |
| 968 | checkInProgressQueriesAtShutdownServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/checkInProgressQueriesAtShutdownServer().(t, s, addr, c) |
| 969 | } |
| 970 | |
| 971 | func TestInProgressQueriesAtShutdownPacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestInProgressQueriesAtShutdownPacketConn().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 972 | s, addr, _, err := RunLocalPacketConnServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalPacketConnServer().(":0") |
| 973 | if err != nil { |
| 974 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 975 | } |
| 976 | |
| 977 | c := &Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#{Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Net.: "udp"} |
| 978 | checkInProgressQueriesAtShutdownServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/checkInProgressQueriesAtShutdownServer().(t, s, addr, c) |
| 979 | } |
| 980 | |
| 981 | func TestServerStartStopRacescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServerStartStopRace().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 982 | var wg syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup# |
| 983 | for i := 0; i < 10; i++ { |
| 984 | wg.Addscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Add().(1) |
| 985 | s, _, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0") |
| 986 | if err != nil { |
| 987 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not start server: %s", err) |
| 988 | } |
| 989 | go func() { |
| 990 | defer wg.Donescip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Done().() |
| 991 | if err := s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 992 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("could not stop server: %s", err) |
| 993 | } |
| 994 | }() |
| 995 | } |
| 996 | wg.Waitscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Wait().() |
| 997 | } |
| 998 | |
| 999 | func TestSocketOptionsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestSocketOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1000 | if !supportsReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/supportsReuseAddr. || !supportsReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/supportsReusePort. { |
| 1001 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("reuseaddr or reuseport is not supported") |
| 1002 | } |
| 1003 | |
| 1004 | testSocketOptions := func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, reuseAddr bool, reusePort bool) { |
| 1005 | wait := make(chan struct{}) |
| 1006 | |
| 1007 | srv := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{ |
| 1008 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: "udp", |
| 1009 | Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: ":0", |
| 1010 | ReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReuseAddr.: reuseAddr, |
| 1011 | ReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReusePort.: reusePort, |
| 1012 | } |
| 1013 | |
| 1014 | srv.NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc. = func() { |
| 1015 | defer close(wait) |
| 1016 | |
| 1017 | conn, ok := srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn..(*netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#) |
| 1018 | if !ok { |
| 1019 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("unexpected conn type: %T", srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn.) |
| 1020 | return |
| 1021 | } |
| 1022 | |
| 1023 | syscallConn, err := conn.SyscallConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#SyscallConn().() |
| 1024 | if err != nil { |
| 1025 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("cannot cast UDP conn to syscall conn: %v", err) |
| 1026 | return |
| 1027 | |
| 1028 | } |
| 1029 | |
| 1030 | err = syscallConn.Controlscip-go gomod github.com/golang/go/src go1.25.0 syscall/RawConn#Control().(func(fd uintptr) { |
| 1031 | actualReusePort, err := checkReuseportscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/checkReuseport().(fd) |
| 1032 | if err != nil { |
| 1033 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("cannot get SO_REUSEPORT socket option: %v", err) |
| 1034 | return |
| 1035 | } |
| 1036 | |
| 1037 | if actualReusePort != reusePort { |
| 1038 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("SO_REUSEPORT is %v instead of %v", actualReusePort, reusePort) |
| 1039 | } |
| 1040 | |
| 1041 | actualReuseAddr, err := checkReuseaddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/checkReuseaddr().(fd) |
| 1042 | if err != nil { |
| 1043 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("cannot get SO_REUSEADDR socket option: %v", err) |
| 1044 | return |
| 1045 | } |
| 1046 | |
| 1047 | if actualReuseAddr != reuseAddr { |
| 1048 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("SO_REUSEADDR is %v instead of %v", actualReuseAddr, reusePort) |
| 1049 | } |
| 1050 | }) |
| 1051 | if err != nil { |
| 1052 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("cannot check socket options: %v", err) |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | fin := make(chan error, 1) |
| 1057 | go func() { |
| 1058 | fin <- srv.ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() |
| 1059 | }() |
| 1060 | |
| 1061 | select { |
| 1062 | case <-wait: |
| 1063 | err := srv.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 1064 | if err != nil { |
| 1065 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("cannot shutdown server: %v", err) |
| 1066 | } |
| 1067 | |
| 1068 | err = <-fin |
| 1069 | if err != nil { |
| 1070 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("listen adn serve: %v", err) |
| 1071 | } |
| 1072 | case err := <-fin: |
| 1073 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("listen adn serve: %v", err) |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("no socket options", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1078 | testSocketOptions(t, false, false) |
| 1079 | }) |
| 1080 | |
| 1081 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("SO_REUSEPORT", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1082 | testSocketOptions(t, false, true) |
| 1083 | }) |
| 1084 | |
| 1085 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("SO_REUSEADDR", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1086 | testSocketOptions(t, true, false) |
| 1087 | }) |
| 1088 | |
| 1089 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("SO_REUSEADDR and SO_REUSEPORT", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1090 | testSocketOptions(t, true, true) |
| 1091 | }) |
| 1092 | } |
| 1093 | |
| 1094 | func TestServerReuseportscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServerReuseport().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1095 | if !supportsReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/supportsReusePort. { |
| 1096 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("reuseport is not supported") |
| 1097 | } |
| 1098 | |
| 1099 | startServer := func(addr string) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, chan error) { |
| 1100 | wait := make(chan struct{}) |
| 1101 | srv := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{ |
| 1102 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: "udp", |
| 1103 | Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: addr, |
| 1104 | NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc.: func() { close(wait) }, |
| 1105 | ReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReusePort.: true, |
| 1106 | } |
| 1107 | |
| 1108 | fin := make(chan error, 1) |
| 1109 | go func() { |
| 1110 | fin <- srv.ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() |
| 1111 | }() |
| 1112 | |
| 1113 | select { |
| 1114 | case <-wait: |
| 1115 | case err := <-fin: |
| 1116 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to start server: %v", err) |
| 1117 | } |
| 1118 | |
| 1119 | return srv, fin |
| 1120 | } |
| 1121 | |
| 1122 | srv1, fin1 := startServer(":0") // :0 is resolved to a random free port by the kernel |
| 1123 | srv2, fin2 := startServer(srv1.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn..LocalAddrscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#LocalAddr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().()) |
| 1124 | |
| 1125 | if err := srv1.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 1126 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to shutdown first server: %v", err) |
| 1127 | } |
| 1128 | if err := srv2.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 1129 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to shutdown second server: %v", err) |
| 1130 | } |
| 1131 | |
| 1132 | if err := <-fin1; err != nil { |
| 1133 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("first ListenAndServe returned error after Shutdown: %v", err) |
| 1134 | } |
| 1135 | if err := <-fin2; err != nil { |
| 1136 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("second ListenAndServe returned error after Shutdown: %v", err) |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | func TestServerReuseaddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServerReuseaddr().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1141 | startServerFn := func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, network, addr string, expectSuccess bool) (*Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#, chan error) { |
| 1142 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 1143 | wait := make(chan struct{}) |
| 1144 | srv := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{ |
| 1145 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: network, |
| 1146 | Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: addr, |
| 1147 | NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc.: func() { close(wait) }, |
| 1148 | ReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReuseAddr.: true, |
| 1149 | } |
| 1150 | |
| 1151 | fin := make(chan error, 1) |
| 1152 | go func() { |
| 1153 | fin <- srv.ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() |
| 1154 | }() |
| 1155 | |
| 1156 | select { |
| 1157 | case <-wait: |
| 1158 | case err := <-fin: |
| 1159 | switch { |
| 1160 | case expectSuccess: |
| 1161 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s: failed to start server: %v", t.Namescip-go gomod github.com/golang/go/src go1.25.0 testing/common#Name().(), err) |
| 1162 | default: |
| 1163 | fin <- err |
| 1164 | return nil, fin |
| 1165 | } |
| 1166 | } |
| 1167 | return srv, fin |
| 1168 | } |
| 1169 | |
| 1170 | externalIPFn := func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) (string, error) { |
| 1171 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 1172 | ifaces, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.Interfacesscip-go gomod github.com/golang/go/src go1.25.0 net/Interfaces().() |
| 1173 | if err != nil { |
| 1174 | return "", err |
| 1175 | } |
| 1176 | for _, iface := range ifaces { |
| 1177 | if iface.Flagsscip-go gomod github.com/golang/go/src go1.25.0 net/Interface#Flags.&netscip-go gomod github.com/golang/go/src go1.25.0 net/.FlagUpscip-go gomod github.com/golang/go/src go1.25.0 net/FlagUp. == 0 { |
| 1178 | continue // interface down |
| 1179 | } |
| 1180 | if iface.Flagsscip-go gomod github.com/golang/go/src go1.25.0 net/Interface#Flags.&netscip-go gomod github.com/golang/go/src go1.25.0 net/.FlagLoopbackscip-go gomod github.com/golang/go/src go1.25.0 net/FlagLoopback. != 0 { |
| 1181 | continue // loopback interface |
| 1182 | } |
| 1183 | addrs, err := iface.Addrsscip-go gomod github.com/golang/go/src go1.25.0 net/Interface#Addrs().() |
| 1184 | if err != nil { |
| 1185 | return "", err |
| 1186 | } |
| 1187 | for _, addr := range addrs { |
| 1188 | var ip netscip-go gomod github.com/golang/go/src go1.25.0 net/.IPscip-go gomod github.com/golang/go/src go1.25.0 net/IP# |
| 1189 | switch v := addr.(type) { |
| 1190 | case *netscip-go gomod github.com/golang/go/src go1.25.0 net/.IPNetscip-go gomod github.com/golang/go/src go1.25.0 net/IPNet#: |
| 1191 | ip = v.IPscip-go gomod github.com/golang/go/src go1.25.0 net/IPNet#IP. |
| 1192 | case *netscip-go gomod github.com/golang/go/src go1.25.0 net/.IPAddrscip-go gomod github.com/golang/go/src go1.25.0 net/IPAddr#: |
| 1193 | ip = v.IPscip-go gomod github.com/golang/go/src go1.25.0 net/IPAddr#IP. |
| 1194 | } |
| 1195 | if ip == nil || ip.IsLoopbackscip-go gomod github.com/golang/go/src go1.25.0 net/IP#IsLoopback().() { |
| 1196 | continue |
| 1197 | } |
| 1198 | ip = ip.To4scip-go gomod github.com/golang/go/src go1.25.0 net/IP#To4().() |
| 1199 | if ip == nil { |
| 1200 | continue // not an ipv4 address |
| 1201 | } |
| 1202 | return ip.Stringscip-go gomod github.com/golang/go/src go1.25.0 net/IP#String().(), nil |
| 1203 | } |
| 1204 | } |
| 1205 | return "", errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("are you connected to the network?") |
| 1206 | } |
| 1207 | |
| 1208 | freePortFn := func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) int { |
| 1209 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 1210 | addr, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.ResolveTCPAddrscip-go gomod github.com/golang/go/src go1.25.0 net/ResolveTCPAddr().("tcp", "localhost:0") |
| 1211 | if err != nil { |
| 1212 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable resolve tcp addr: %s", err) |
| 1213 | } |
| 1214 | |
| 1215 | l, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.ListenTCPscip-go gomod github.com/golang/go/src go1.25.0 net/ListenTCP().("tcp", addr) |
| 1216 | if err != nil { |
| 1217 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable listen tcp: %s", err) |
| 1218 | } |
| 1219 | defer l.Closescip-go gomod github.com/golang/go/src go1.25.0 net/TCPListener#Close().() |
| 1220 | return l.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/TCPListener#Addr().().(*netscip-go gomod github.com/golang/go/src go1.25.0 net/.TCPAddrscip-go gomod github.com/golang/go/src go1.25.0 net/TCPAddr#).Portscip-go gomod github.com/golang/go/src go1.25.0 net/TCPAddr#Port. |
| 1221 | } |
| 1222 | |
| 1223 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("should-fail-tcp", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1224 | // ReuseAddr should fail if you try to bind to exactly the same |
| 1225 | // combination of source address and port. |
| 1226 | // This should fail whether or not ReuseAddr is supported on a |
| 1227 | // particular OS |
| 1228 | ip, err := externalIPFn(t) |
| 1229 | if err != nil { |
| 1230 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("no external IPs found") |
| 1231 | return |
| 1232 | } |
| 1233 | port := freePortFn(t) |
| 1234 | srv1, fin1 := startServerFn(t, "tcp", fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s:%d", ip, port), true) |
| 1235 | srv2, fin2 := startServerFn(t, "tcp", fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s:%d", ip, port), false) |
| 1236 | switch { |
| 1237 | case srv2 != nil && srv2.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started.: |
| 1238 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("second ListenAndServe should not have started") |
| 1239 | default: |
| 1240 | if err := <-fin2; err == nil { |
| 1241 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("second ListenAndServe should have returned a startup error: %v", err) |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | if err := srv1.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 1246 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to shutdown first server: %v", err) |
| 1247 | } |
| 1248 | if err := <-fin1; err != nil { |
| 1249 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("first ListenAndServe returned error after Shutdown: %v", err) |
| 1250 | } |
| 1251 | }) |
| 1252 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("should-succeed-tcp", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1253 | if !supportsReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/supportsReuseAddr. { |
| 1254 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("reuseaddr is not supported") |
| 1255 | } |
| 1256 | ip, err := externalIPFn(t) |
| 1257 | if err != nil { |
| 1258 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("no external IPs found") |
| 1259 | return |
| 1260 | } |
| 1261 | port := freePortFn(t) |
| 1262 | |
| 1263 | // ReuseAddr should succeed if you try to bind to the same port but a different source address |
| 1264 | srv1, fin1 := startServerFn(t, "tcp", fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("localhost:%d", port), true) |
| 1265 | srv2, fin2 := startServerFn(t, "tcp", fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s:%d", ip, port), true) |
| 1266 | |
| 1267 | if err := srv1.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 1268 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to shutdown first server: %v", err) |
| 1269 | } |
| 1270 | if err := srv2.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 1271 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to shutdown second server: %v", err) |
| 1272 | } |
| 1273 | if err := <-fin1; err != nil { |
| 1274 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("first ListenAndServe returned error after Shutdown: %v", err) |
| 1275 | } |
| 1276 | if err := <-fin2; err != nil { |
| 1277 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("second ListenAndServe returned error after Shutdown: %v", err) |
| 1278 | } |
| 1279 | }) |
| 1280 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("should-succeed-udp", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1281 | if !supportsReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/supportsReuseAddr. { |
| 1282 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("reuseaddr is not supported") |
| 1283 | } |
| 1284 | ip, err := externalIPFn(t) |
| 1285 | if err != nil { |
| 1286 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("no external IPs found") |
| 1287 | return |
| 1288 | } |
| 1289 | port := freePortFn(t) |
| 1290 | |
| 1291 | // ReuseAddr should succeed if you try to bind to the same port but a different source address |
| 1292 | srv1, fin1 := startServerFn(t, "udp", fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("localhost:%d", port), true) |
| 1293 | srv2, fin2 := startServerFn(t, "udp", fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s:%d", ip, port), true) |
| 1294 | |
| 1295 | if err := srv1.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 1296 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to shutdown first server: %v", err) |
| 1297 | } |
| 1298 | if err := srv2.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().(); err != nil { |
| 1299 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to shutdown second server: %v", err) |
| 1300 | } |
| 1301 | if err := <-fin1; err != nil { |
| 1302 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("first ListenAndServe returned error after Shutdown: %v", err) |
| 1303 | } |
| 1304 | if err := <-fin2; err != nil { |
| 1305 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("second ListenAndServe returned error after Shutdown: %v", err) |
| 1306 | } |
| 1307 | }) |
| 1308 | } |
| 1309 | |
| 1310 | func TestServerRoundtripTsigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestServerRoundtripTsig().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1311 | secret := map[string]string{"test.": "so6ZGir4GPAqINNh9U5c3A=="} |
| 1312 | |
| 1313 | s, addrstr, _, err := RunLocalUDPServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RunLocalUDPServer().(":0", func(srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) { |
| 1314 | srv.TsigSecretscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TsigSecret. = secret |
| 1315 | srv.MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgAcceptFunc. = func(dh Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#) MsgAcceptActionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAcceptAction# { |
| 1316 | // defaultMsgAcceptFunc does reject UPDATE queries |
| 1317 | return MsgAcceptscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAccept. |
| 1318 | } |
| 1319 | }) |
| 1320 | if err != nil { |
| 1321 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to run test server: %v", err) |
| 1322 | } |
| 1323 | defer s.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 1324 | |
| 1325 | handlerFired := make(chan struct{}) |
| 1326 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("example.com.", func(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, r *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 1327 | close(handlerFired) |
| 1328 | |
| 1329 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 1330 | m.SetReplyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetReply().(r) |
| 1331 | if r.IsTsigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#IsTsig().() != nil { |
| 1332 | status := w.TsigStatusscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#TsigStatus.() |
| 1333 | if status == nil { |
| 1334 | // *Msg r has an TSIG record and it was validated |
| 1335 | m.SetTsigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetTsig().("test.", HmacSHA256scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HmacSHA256., 300, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Unixscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Unix().()) |
| 1336 | } else { |
| 1337 | // *Msg r has an TSIG records and it was not validated |
| 1338 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("invalid TSIG: %v", status) |
| 1339 | } |
| 1340 | } else { |
| 1341 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("missing TSIG") |
| 1342 | } |
| 1343 | if err := w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m); err != nil { |
| 1344 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("writemsg failed", err) |
| 1345 | } |
| 1346 | }) |
| 1347 | |
| 1348 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 1349 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 1350 | m.Opcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Opcode. = OpcodeUpdatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/OpcodeUpdate. |
| 1351 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("example.com.", TypeSOAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeSOA.) |
| 1352 | m.Nsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Ns. = []RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{&CNAMEscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CNAME#{ |
| 1353 | Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CNAME#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{ |
| 1354 | Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: "foo.example.com.", |
| 1355 | Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: TypeCNAMEscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeCNAME., |
| 1356 | Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassINETscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassINET., |
| 1357 | Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 300, |
| 1358 | }, |
| 1359 | Targetscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CNAME#Target.: "bar.example.com.", |
| 1360 | }} |
| 1361 | c.TsigSecretscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#TsigSecret. = secret |
| 1362 | m.SetTsigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetTsig().("test.", HmacSHA256scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HmacSHA256., 300, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Unixscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Unix().()) |
| 1363 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, addrstr) |
| 1364 | if err != nil { |
| 1365 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to exchange", err) |
| 1366 | } |
| 1367 | select { |
| 1368 | case <-handlerFired: |
| 1369 | // ok, handler was actually called |
| 1370 | default: |
| 1371 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("handler was not called") |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | func TestResponseAfterClosescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestResponseAfterClose().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1376 | testError := func(name string, err error) { |
| 1377 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 1378 | |
| 1379 | expect := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("dns: %s called after Close", name) |
| 1380 | if err == nil { |
| 1381 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected error from %s after Close", name) |
| 1382 | } else if err.Error() != expect { |
| 1383 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected explicit error from %s after Close, expected %q, got %q", name, expect, err) |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | rw := &responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#{ |
| 1388 | closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed.: true, |
| 1389 | } |
| 1390 | |
| 1391 | _, err := rw.Writescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#Write().(make([]byte, 2)) |
| 1392 | testError("Write", err) |
| 1393 | |
| 1394 | testError("WriteMsg", rw.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#WriteMsg().(new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#))) |
| 1395 | } |
| 1396 | |
| 1397 | func TestResponseDoubleClosescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestResponseDoubleClose().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1398 | rw := &responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#{ |
| 1399 | closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed.: true, |
| 1400 | } |
| 1401 | if err, expect := rw.Closescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#Close().(), "dns: connection already closed"; err == nil || err.Error() != expect { |
| 1402 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Close did not return expected: error %q, got: %v", expect, err) |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | type countingConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn# struct { |
| 1407 | netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn#Conn. |
| 1408 | writesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn#writes. int |
| 1409 | } |
| 1410 | |
| 1411 | func (c *countingConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn#) Writescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn#Write().(p []byte) (int, error) { |
| 1412 | c.writesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn#writes.++ |
| 1413 | return len(p), nil |
| 1414 | } |
| 1415 | |
| 1416 | func TestResponseWriteSinglePacketscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestResponseWriteSinglePacket().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 1417 | c := &countingConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn#{} |
| 1418 | rw := &responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#{ |
| 1419 | tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp.: c, |
| 1420 | } |
| 1421 | rw.writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer. = rw |
| 1422 | |
| 1423 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 1424 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 1425 | m.Responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Response. = true |
| 1426 | err := rw.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#WriteMsg().(m) |
| 1427 | if err != nil { |
| 1428 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to write: %v", err) |
| 1429 | } |
| 1430 | |
| 1431 | if c.writesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/countingConn#writes. != 1 { |
| 1432 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("incorrect number of Write calls") |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | type ExampleFrameLengthWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ExampleFrameLengthWriter# struct { |
| 1437 | Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ExampleFrameLengthWriter#Writer. |
| 1438 | } |
| 1439 | |
| 1440 | func (e *ExampleFrameLengthWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ExampleFrameLengthWriter#) Writescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ExampleFrameLengthWriter#Write().(m []byte) (int, error) { |
| 1441 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Println().("writing raw DNS message of length", len(m)) |
| 1442 | return e.Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ExampleFrameLengthWriter#Writer..Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().(m) |
| 1443 | } |
| 1444 | |
| 1445 | func ExampleDecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ExampleDecorateWriter().() { |
| 1446 | // instrument raw DNS message writing |
| 1447 | wf := DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DecorateWriter#(func(w Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Writer#) Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Writer# { |
| 1448 | return &ExampleFrameLengthWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ExampleFrameLengthWriter#{w} |
| 1449 | }) |
| 1450 | |
| 1451 | // simple UDP server |
| 1452 | pc, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.ListenPacketscip-go gomod github.com/golang/go/src go1.25.0 net/ListenPacket().("udp", ":0") |
| 1453 | if err != nil { |
| 1454 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Println().(err.Error()) |
| 1455 | return |
| 1456 | } |
| 1457 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{ |
| 1458 | PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn.: pc, |
| 1459 | DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateWriter.: wf, |
| 1460 | ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReadTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., WriteTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#WriteTimeout.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Hourscip-go gomod github.com/golang/go/src go1.25.0 time/Hour., |
| 1461 | } |
| 1462 | |
| 1463 | waitLock := syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#{} |
| 1464 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 1465 | server.NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc. = waitLock.Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock(). |
| 1466 | defer server.Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() |
| 1467 | |
| 1468 | go func() { |
| 1469 | server.ActivateAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ActivateAndServe().() |
| 1470 | pc.Closescip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#Close().() |
| 1471 | }() |
| 1472 | |
| 1473 | waitLock.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 1474 | |
| 1475 | HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().("miek.nl.", HelloServerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HelloServer().) |
| 1476 | |
| 1477 | c := new(Clientscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#) |
| 1478 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 1479 | m.SetQuestionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetQuestion().("miek.nl.", TypeTXTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeTXT.) |
| 1480 | _, _, err = c.Exchangescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Client#Exchange().(m, pc.LocalAddrscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#LocalAddr().().Stringscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#String().()) |
| 1481 | if err != nil { |
| 1482 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Println().("failed to exchange", err.Error()) |
| 1483 | return |
| 1484 | } |
| 1485 | // Output: writing raw DNS message of length 56 |
| 1486 | } |
| 1487 | |
| 1488 | var ( |
| 1489 | // CertPEMBlock is a X509 data used to test TLS servers (used with tls.X509KeyPair) |
| 1490 | CertPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertPEMBlock. = []byte(`-----BEGIN CERTIFICATE----- |
| 1491 | MIIDAzCCAeugAwIBAgIRAJFYMkcn+b8dpU15wjf++GgwDQYJKoZIhvcNAQELBQAw |
| 1492 | EjEQMA4GA1UEChMHQWNtZSBDbzAeFw0xNjAxMDgxMjAzNTNaFw0xNzAxMDcxMjAz |
| 1493 | NTNaMBIxEDAOBgNVBAoTB0FjbWUgQ28wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw |
| 1494 | ggEKAoIBAQDXjqO6skvP03k58CNjQggd9G/mt+Wa+xRU+WXiKCCHttawM8x+slq5 |
| 1495 | yfsHCwxlwsGn79HmJqecNqgHb2GWBXAvVVokFDTcC1hUP4+gp2gu9Ny27UHTjlLm |
| 1496 | O0l/xZ5MN8tfKyYlFw18tXu3fkaPyHj8v/D1RDkuo4ARdFvGSe8TqisbhLk2+9ow |
| 1497 | xfIGbEM9Fdiw8qByC2+d+FfvzIKz3GfQVwn0VoRom8L6NBIANq1IGrB5JefZB6nv |
| 1498 | DnfuxkBmY7F1513HKuEJ8KsLWWZWV9OPU4j4I4Rt+WJNlKjbD2srHxyrS2RDsr91 |
| 1499 | 8nCkNoWVNO3sZq0XkWKecdc921vL4ginAgMBAAGjVDBSMA4GA1UdDwEB/wQEAwIC |
| 1500 | pDATBgNVHSUEDDAKBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MBoGA1UdEQQT |
| 1501 | MBGCCWxvY2FsaG9zdIcEfwAAATANBgkqhkiG9w0BAQsFAAOCAQEAGcU3iyLBIVZj |
| 1502 | aDzSvEDHUd1bnLBl1C58Xu/CyKlPqVU7mLfK0JcgEaYQTSX6fCJVNLbbCrcGLsPJ |
| 1503 | fbjlBbyeLjTV413fxPVuona62pBFjqdtbli2Qe8FRH2KBdm41JUJGdo+SdsFu7nc |
| 1504 | BFOcubdw6LLIXvsTvwndKcHWx1rMX709QU1Vn1GAIsbJV/DWI231Jyyb+lxAUx/C |
| 1505 | 8vce5uVxiKcGS+g6OjsN3D3TtiEQGSXLh013W6Wsih8td8yMCMZ3w8LQ38br1GUe |
| 1506 | ahLIgUJ9l6HDguM17R7kGqxNvbElsMUHfTtXXP7UDQUiYXDakg8xDP6n9DCDhJ8Y |
| 1507 | bSt7OLB7NQ== |
| 1508 | -----END CERTIFICATE-----`) |
| 1509 | |
| 1510 | // KeyPEMBlock is a X509 data used to test TLS servers (used with tls.X509KeyPair) |
| 1511 | KeyPEMBlockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/KeyPEMBlock. = []byte(`-----BEGIN RSA PRIVATE KEY----- |
| 1512 | MIIEpQIBAAKCAQEA146jurJLz9N5OfAjY0IIHfRv5rflmvsUVPll4iggh7bWsDPM |
| 1513 | frJaucn7BwsMZcLBp+/R5iannDaoB29hlgVwL1VaJBQ03AtYVD+PoKdoLvTctu1B |
| 1514 | 045S5jtJf8WeTDfLXysmJRcNfLV7t35Gj8h4/L/w9UQ5LqOAEXRbxknvE6orG4S5 |
| 1515 | NvvaMMXyBmxDPRXYsPKgcgtvnfhX78yCs9xn0FcJ9FaEaJvC+jQSADatSBqweSXn |
| 1516 | 2Qep7w537sZAZmOxdeddxyrhCfCrC1lmVlfTj1OI+COEbfliTZSo2w9rKx8cq0tk |
| 1517 | Q7K/dfJwpDaFlTTt7GatF5FinnHXPdtby+IIpwIDAQABAoIBAAJK4RDmPooqTJrC |
| 1518 | JA41MJLo+5uvjwCT9QZmVKAQHzByUFw1YNJkITTiognUI0CdzqNzmH7jIFs39ZeG |
| 1519 | proKusO2G6xQjrNcZ4cV2fgyb5g4QHStl0qhs94A+WojduiGm2IaumAgm6Mc5wDv |
| 1520 | ld6HmknN3Mku/ZCyanVFEIjOVn2WB7ZQLTBs6ZYaebTJG2Xv6p9t2YJW7pPQ9Xce |
| 1521 | s9ohAWohyM4X/OvfnfnLtQp2YLw/BxwehBsCR5SXM3ibTKpFNtxJC8hIfTuWtxZu |
| 1522 | 2ywrmXShYBRB1WgtZt5k04bY/HFncvvcHK3YfI1+w4URKtwdaQgPUQRbVwDwuyBn |
| 1523 | flfkCJECgYEA/eWt01iEyE/lXkGn6V9lCocUU7lCU6yk5UT8VXVUc5If4KZKPfCk |
| 1524 | p4zJDOqwn2eM673aWz/mG9mtvAvmnugaGjcaVCyXOp/D/GDmKSoYcvW5B/yjfkLy |
| 1525 | dK6Yaa5LDRVYlYgyzcdCT5/9Qc626NzFwKCZNI4ncIU8g7ViATRxWJ8CgYEA2Ver |
| 1526 | vZ0M606sfgC0H3NtwNBxmuJ+lIF5LNp/wDi07lDfxRR1rnZMX5dnxjcpDr/zvm8J |
| 1527 | WtJJX3xMgqjtHuWKL3yKKony9J5ZPjichSbSbhrzfovgYIRZLxLLDy4MP9L3+CX/ |
| 1528 | yBXnqMWuSnFX+M5fVGxdDWiYF3V+wmeOv9JvavkCgYEAiXAPDFzaY+R78O3xiu7M |
| 1529 | r0o3wqqCMPE/wav6O/hrYrQy9VSO08C0IM6g9pEEUwWmzuXSkZqhYWoQFb8Lc/GI |
| 1530 | T7CMXAxXQLDDUpbRgG79FR3Wr3AewHZU8LyiXHKwxcBMV4WGmsXGK3wbh8fyU1NO |
| 1531 | 6NsGk+BvkQVOoK1LBAPzZ1kCgYEAsBSmD8U33T9s4dxiEYTrqyV0lH3g/SFz8ZHH |
| 1532 | pAyNEPI2iC1ONhyjPWKlcWHpAokiyOqeUpVBWnmSZtzC1qAydsxYB6ShT+sl9BHb |
| 1533 | RMix/QAauzBJhQhUVJ3OIys0Q1UBDmqCsjCE8SfOT4NKOUnA093C+YT+iyrmmktZ |
| 1534 | zDCJkckCgYEAndqM5KXGk5xYo+MAA1paZcbTUXwaWwjLU+XSRSSoyBEi5xMtfvUb |
| 1535 | 7+a1OMhLwWbuz+pl64wFKrbSUyimMOYQpjVE/1vk/kb99pxbgol27hdKyTH1d+ov |
| 1536 | kFsxKCqxAnBVGEWAvVZAiiTOxleQFjz5RnL0BQp9Lg2cQe+dvuUmIAA= |
| 1537 | -----END RSA PRIVATE KEY-----`) |
| 1538 | ) |