@@ -21,6 +21,7 @@ import (
2121 "io"
2222 "math/rand"
2323 "net"
24+ "net/netip"
2425 "sync"
2526 "testing"
2627 "time"
@@ -99,7 +100,7 @@ func BenchmarkTCPFindCipherFail(b *testing.B) {
99100 if err != nil {
100101 b .Fatalf ("AcceptTCP failed: %v" , err )
101102 }
102- clientIP := clientConn .RemoteAddr ().(* net.TCPAddr ).IP
103+ clientIP := clientConn .RemoteAddr ().(* net.TCPAddr ).AddrPort (). Addr ()
103104 b .StartTimer ()
104105 findAccessKey (clientConn , clientIP , cipherList )
105106 b .StopTimer ()
@@ -191,16 +192,16 @@ func BenchmarkTCPFindCipherRepeat(b *testing.B) {
191192 b .Fatal (err )
192193 }
193194 cipherEntries := [numCiphers ]* CipherEntry {}
194- snapshot := cipherList .SnapshotForClientIP (nil )
195+ snapshot := cipherList .SnapshotForClientIP (netip. Addr {} )
195196 for cipherNumber , element := range snapshot {
196197 cipherEntries [cipherNumber ] = element .Value .(* CipherEntry )
197198 }
198199 for n := 0 ; n < b .N ; n ++ {
199200 cipherNumber := byte (n % numCiphers )
200201 reader , writer := io .Pipe ()
201- clientIP := net . IPv4 ( 192 , 0 , 2 , cipherNumber )
202- addr := & net. TCPAddr { IP : clientIP , Port : 54321 }
203- c := conn {clientAddr : addr , reader : reader , writer : writer }
202+ clientIP := netip . AddrFrom4 ([ 4 ] byte { 192 , 0 , 2 , cipherNumber } )
203+ addr := netip . AddrPortFrom ( clientIP , 54321 )
204+ c := conn {clientAddr : net . TCPAddrFromAddrPort ( addr ) , reader : reader , writer : writer }
204205 cipher := cipherEntries [cipherNumber ].CryptoKey
205206 go shadowsocks .NewWriter (writer , cipher ).Write (makeTestPayload (50 ))
206207 b .StartTimer ()
@@ -345,7 +346,7 @@ func makeClientBytesCoalesced(t *testing.T, cryptoKey *shadowsocks.EncryptionKey
345346}
346347
347348func firstCipher (cipherList CipherList ) * shadowsocks.EncryptionKey {
348- snapshot := cipherList .SnapshotForClientIP (nil )
349+ snapshot := cipherList .SnapshotForClientIP (netip. Addr {} )
349350 cipherEntry := snapshot [0 ].Value .(* CipherEntry )
350351 return cipherEntry .CryptoKey
351352}
@@ -368,7 +369,6 @@ func TestProbeClientBytesBasicTruncated(t *testing.T) {
368369 discardListener , discardWait := startDiscardServer (t )
369370 initialBytes := makeClientBytesBasic (t , cipher , discardListener .Addr ().String ())
370371 for numBytesToSend := 0 ; numBytesToSend < len (initialBytes ); numBytesToSend ++ {
371- t .Logf ("Sending %v bytes" , numBytesToSend )
372372 bytesToSend := initialBytes [:numBytesToSend ]
373373 err := probe (listener .Addr ().(* net.TCPAddr ), bytesToSend )
374374 require .NoError (t , err , "Failed for %v bytes sent: %v" , numBytesToSend , err )
@@ -405,7 +405,6 @@ func TestProbeClientBytesBasicModified(t *testing.T) {
405405 initialBytes := makeClientBytesBasic (t , cipher , discardListener .Addr ().String ())
406406 bytesToSend := make ([]byte , len (initialBytes ))
407407 for byteToModify := 0 ; byteToModify < len (initialBytes ); byteToModify ++ {
408- t .Logf ("Modifying byte %v" , byteToModify )
409408 copy (bytesToSend , initialBytes )
410409 bytesToSend [byteToModify ] = 255 - bytesToSend [byteToModify ]
411410 err := probe (listener .Addr ().(* net.TCPAddr ), bytesToSend )
@@ -442,7 +441,6 @@ func TestProbeClientBytesCoalescedModified(t *testing.T) {
442441 initialBytes := makeClientBytesCoalesced (t , cipher , discardListener .Addr ().String ())
443442 bytesToSend := make ([]byte , len (initialBytes ))
444443 for byteToModify := 0 ; byteToModify < len (initialBytes ); byteToModify ++ {
445- t .Logf ("Modifying byte %v" , byteToModify )
446444 copy (bytesToSend , initialBytes )
447445 bytesToSend [byteToModify ] = 255 - bytesToSend [byteToModify ]
448446 err := probe (listener .Addr ().(* net.TCPAddr ), bytesToSend )
@@ -506,7 +504,7 @@ func TestReplayDefense(t *testing.T) {
506504 const testTimeout = 200 * time .Millisecond
507505 authFunc := NewShadowsocksStreamAuthenticator (cipherList , & replayCache , testMetrics )
508506 handler := NewTCPHandler (listener .Addr ().(* net.TCPAddr ).Port , authFunc , testMetrics , testTimeout )
509- snapshot := cipherList .SnapshotForClientIP (nil )
507+ snapshot := cipherList .SnapshotForClientIP (netip. Addr {} )
510508 cipherEntry := snapshot [0 ].Value .(* CipherEntry )
511509 cipher := cipherEntry .CryptoKey
512510 reader , writer := io .Pipe ()
@@ -585,7 +583,7 @@ func TestReverseReplayDefense(t *testing.T) {
585583 const testTimeout = 200 * time .Millisecond
586584 authFunc := NewShadowsocksStreamAuthenticator (cipherList , & replayCache , testMetrics )
587585 handler := NewTCPHandler (listener .Addr ().(* net.TCPAddr ).Port , authFunc , testMetrics , testTimeout )
588- snapshot := cipherList .SnapshotForClientIP (nil )
586+ snapshot := cipherList .SnapshotForClientIP (netip. Addr {} )
589587 cipherEntry := snapshot [0 ].Value .(* CipherEntry )
590588 cipher := cipherEntry .CryptoKey
591589 reader , writer := io .Pipe ()
0 commit comments