5
5
"context"
6
6
"crypto/rand"
7
7
"errors"
8
- "fmt"
9
8
"io"
10
9
mrand "math/rand"
11
10
"net"
@@ -564,6 +563,14 @@ func TestStatelessReset(t *testing.T) {
564
563
}
565
564
}
566
565
566
+ func newUPDConnLocalhost (t testing.TB ) * net.UDPConn {
567
+ t .Helper ()
568
+ conn , err := net .ListenUDP ("udp" , & net.UDPAddr {IP : net .IPv4 (127 , 0 , 0 , 1 ), Port : 0 })
569
+ require .NoError (t , err )
570
+ t .Cleanup (func () { conn .Close () })
571
+ return conn
572
+ }
573
+
567
574
func testStatelessReset (t * testing.T , tc * connTestCase ) {
568
575
serverID , serverKey := createPeer (t )
569
576
_ , clientKey := createPeer (t )
@@ -575,12 +582,14 @@ func testStatelessReset(t *testing.T, tc *connTestCase) {
575
582
576
583
var drop uint32
577
584
dropCallback := func (quicproxy.Direction , []byte ) bool { return atomic .LoadUint32 (& drop ) > 0 }
578
- proxy , err := quicproxy .NewQuicProxy ("localhost:0" , & quicproxy.Opts {
579
- RemoteAddr : fmt .Sprintf ("localhost:%d" , ln .Addr ().(* net.UDPAddr ).Port ),
585
+ proxyConn := newUPDConnLocalhost (t )
586
+ proxy := quicproxy.Proxy {
587
+ Conn : proxyConn ,
588
+ ServerAddr : ln .Addr ().(* net.UDPAddr ),
580
589
DropPacket : dropCallback ,
581
- })
590
+ }
591
+ err = proxy .Start ()
582
592
require .NoError (t , err )
583
- proxyLocalAddr := proxy .LocalAddr ()
584
593
585
594
// establish a connection
586
595
clientTransport , err := NewTransport (clientKey , newConnManager (t , tc .Options ... ), nil , nil , nil )
@@ -622,10 +631,12 @@ func testStatelessReset(t *testing.T, tc *connTestCase) {
622
631
atomic .StoreUint32 (& drop , 0 )
623
632
624
633
// Recreate the proxy, such that its client-facing port stays constant.
625
- proxy , err = quicproxy .NewQuicProxy (proxyLocalAddr .String (), & quicproxy.Opts {
626
- RemoteAddr : fmt .Sprintf ("localhost:%d" , ln .Addr ().(* net.UDPAddr ).Port ),
634
+ proxy = quicproxy.Proxy {
635
+ Conn : proxyConn ,
636
+ ServerAddr : ln .Addr ().(* net.UDPAddr ),
627
637
DropPacket : dropCallback ,
628
- })
638
+ }
639
+ err = proxy .Start ()
629
640
require .NoError (t , err )
630
641
defer proxy .Close ()
631
642
0 commit comments