direct_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. C "github.com/sagernet/sing-box/constant"
  6. "github.com/sagernet/sing-box/option"
  7. )
  8. func TestProxyProtocol(t *testing.T) {
  9. startInstance(t, option.Options{
  10. Inbounds: []option.Inbound{
  11. {
  12. Type: C.TypeMixed,
  13. Tag: "mixed-in",
  14. MixedOptions: option.HTTPMixedInboundOptions{
  15. ListenOptions: option.ListenOptions{
  16. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  17. ListenPort: clientPort,
  18. },
  19. },
  20. },
  21. {
  22. Type: C.TypeDirect,
  23. DirectOptions: option.DirectInboundOptions{
  24. ListenOptions: option.ListenOptions{
  25. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  26. ListenPort: serverPort,
  27. ProxyProtocol: true,
  28. },
  29. },
  30. },
  31. },
  32. Outbounds: []option.Outbound{
  33. {
  34. Type: C.TypeDirect,
  35. },
  36. {
  37. Type: C.TypeDirect,
  38. Tag: "trojan-out",
  39. DirectOptions: option.DirectOutboundOptions{
  40. OverrideAddress: "127.0.0.1",
  41. OverridePort: serverPort,
  42. ProxyProtocol: 2,
  43. },
  44. },
  45. },
  46. Route: &option.RouteOptions{
  47. Rules: []option.Rule{
  48. {
  49. DefaultOptions: option.DefaultRule{
  50. Inbound: []string{"mixed-in"},
  51. Outbound: "trojan-out",
  52. },
  53. },
  54. },
  55. },
  56. })
  57. testSuit(t, clientPort, testPort)
  58. }