github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/direct/packet_test.go (about)

     1  package direct
     2  
     3  import (
     4  	"net/netip"
     5  	"testing"
     6  
     7  	"github.com/database64128/shadowsocks-go/conn"
     8  	"github.com/database64128/shadowsocks-go/zerocopy"
     9  )
    10  
    11  const (
    12  	mtu        = 1500
    13  	packetSize = 1452
    14  )
    15  
    16  var (
    17  	targetAddr     = conn.AddrFromIPPort(targetAddrPort)
    18  	targetAddrPort = netip.AddrPortFrom(netip.IPv6Unspecified(), 53)
    19  	serverAddrPort = netip.AddrPortFrom(netip.IPv6Unspecified(), 1080)
    20  )
    21  
    22  func TestDirectPacketPackUnpacker(t *testing.T) {
    23  	c := NewDirectPacketClientPacker("ip", mtu)
    24  	s := NewDirectPacketServerPackUnpacker(targetAddr, false) // Cheat a little bit, because we have to. :P
    25  	zerocopy.ClientServerPackerUnpackerTestFunc(t, c, DirectPacketClientUnpacker{}, s, s)
    26  }
    27  
    28  func TestShadowsocksNonePacketPackUnpacker(t *testing.T) {
    29  	clientPacker := NewShadowsocksNonePacketClientPacker(serverAddrPort, packetSize)
    30  	clientUnpacker := NewShadowsocksNonePacketClientUnpacker(serverAddrPort)
    31  	zerocopy.ClientServerPackerUnpackerTestFunc(t, clientPacker, clientUnpacker, ShadowsocksNonePacketServerPacker{}, &ShadowsocksNonePacketServerUnpacker{})
    32  }
    33  
    34  func TestSocks5PacketPackUnpacker(t *testing.T) {
    35  	clientPacker := NewSocks5PacketClientPacker(serverAddrPort, packetSize)
    36  	clientUnpacker := NewSocks5PacketClientUnpacker(serverAddrPort)
    37  	zerocopy.ClientServerPackerUnpackerTestFunc(t, clientPacker, clientUnpacker, Socks5PacketServerPacker{}, &Socks5PacketServerUnpacker{})
    38  }