github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/testing/scenarios/shadowsocks_test.go (about) 1 package scenarios 2 3 import ( 4 "crypto/rand" 5 "testing" 6 "time" 7 8 "github.com/google/go-cmp/cmp" 9 "golang.org/x/sync/errgroup" 10 11 "v2ray.com/core" 12 "v2ray.com/core/app/log" 13 "v2ray.com/core/app/proxyman" 14 "v2ray.com/core/common" 15 "v2ray.com/core/common/errors" 16 clog "v2ray.com/core/common/log" 17 "v2ray.com/core/common/net" 18 "v2ray.com/core/common/protocol" 19 "v2ray.com/core/common/serial" 20 "v2ray.com/core/proxy/dokodemo" 21 "v2ray.com/core/proxy/freedom" 22 "v2ray.com/core/proxy/shadowsocks" 23 "v2ray.com/core/testing/servers/tcp" 24 "v2ray.com/core/testing/servers/udp" 25 ) 26 27 func TestShadowsocksAES256TCP(t *testing.T) { 28 tcpServer := tcp.Server{ 29 MsgProcessor: xor, 30 } 31 dest, err := tcpServer.Start() 32 common.Must(err) 33 defer tcpServer.Close() 34 35 account := serial.ToTypedMessage(&shadowsocks.Account{ 36 Password: "shadowsocks-password", 37 CipherType: shadowsocks.CipherType_AES_256_CFB, 38 }) 39 40 serverPort := tcp.PickPort() 41 serverConfig := &core.Config{ 42 App: []*serial.TypedMessage{ 43 serial.ToTypedMessage(&log.Config{ 44 ErrorLogLevel: clog.Severity_Debug, 45 ErrorLogType: log.LogType_Console, 46 }), 47 }, 48 Inbound: []*core.InboundHandlerConfig{ 49 { 50 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 51 PortRange: net.SinglePortRange(serverPort), 52 Listen: net.NewIPOrDomain(net.LocalHostIP), 53 }), 54 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 55 User: &protocol.User{ 56 Account: account, 57 Level: 1, 58 }, 59 Network: []net.Network{net.Network_TCP}, 60 }), 61 }, 62 }, 63 Outbound: []*core.OutboundHandlerConfig{ 64 { 65 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 66 }, 67 }, 68 } 69 70 clientPort := tcp.PickPort() 71 clientConfig := &core.Config{ 72 App: []*serial.TypedMessage{ 73 serial.ToTypedMessage(&log.Config{ 74 ErrorLogLevel: clog.Severity_Debug, 75 ErrorLogType: log.LogType_Console, 76 }), 77 }, 78 Inbound: []*core.InboundHandlerConfig{ 79 { 80 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 81 PortRange: net.SinglePortRange(clientPort), 82 Listen: net.NewIPOrDomain(net.LocalHostIP), 83 }), 84 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 85 Address: net.NewIPOrDomain(dest.Address), 86 Port: uint32(dest.Port), 87 NetworkList: &net.NetworkList{ 88 Network: []net.Network{net.Network_TCP}, 89 }, 90 }), 91 }, 92 }, 93 Outbound: []*core.OutboundHandlerConfig{ 94 { 95 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 96 Server: []*protocol.ServerEndpoint{ 97 { 98 Address: net.NewIPOrDomain(net.LocalHostIP), 99 Port: uint32(serverPort), 100 User: []*protocol.User{ 101 { 102 Account: account, 103 }, 104 }, 105 }, 106 }, 107 }), 108 }, 109 }, 110 } 111 112 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 113 common.Must(err) 114 defer CloseAllServers(servers) 115 116 var errg errgroup.Group 117 for i := 0; i < 10; i++ { 118 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20)) 119 } 120 if err := errg.Wait(); err != nil { 121 t.Fatal(err) 122 } 123 } 124 125 func TestShadowsocksAES128UDP(t *testing.T) { 126 udpServer := udp.Server{ 127 MsgProcessor: xor, 128 } 129 dest, err := udpServer.Start() 130 common.Must(err) 131 defer udpServer.Close() 132 133 account := serial.ToTypedMessage(&shadowsocks.Account{ 134 Password: "shadowsocks-password", 135 CipherType: shadowsocks.CipherType_AES_128_CFB, 136 }) 137 138 serverPort := tcp.PickPort() 139 serverConfig := &core.Config{ 140 App: []*serial.TypedMessage{ 141 serial.ToTypedMessage(&log.Config{ 142 ErrorLogLevel: clog.Severity_Debug, 143 ErrorLogType: log.LogType_Console, 144 }), 145 }, 146 Inbound: []*core.InboundHandlerConfig{ 147 { 148 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 149 PortRange: net.SinglePortRange(serverPort), 150 Listen: net.NewIPOrDomain(net.LocalHostIP), 151 }), 152 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 153 User: &protocol.User{ 154 Account: account, 155 Level: 1, 156 }, 157 Network: []net.Network{net.Network_UDP}, 158 }), 159 }, 160 }, 161 Outbound: []*core.OutboundHandlerConfig{ 162 { 163 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 164 }, 165 }, 166 } 167 168 clientPort := tcp.PickPort() 169 clientConfig := &core.Config{ 170 App: []*serial.TypedMessage{ 171 serial.ToTypedMessage(&log.Config{ 172 ErrorLogLevel: clog.Severity_Debug, 173 ErrorLogType: log.LogType_Console, 174 }), 175 }, 176 Inbound: []*core.InboundHandlerConfig{ 177 { 178 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 179 PortRange: net.SinglePortRange(clientPort), 180 Listen: net.NewIPOrDomain(net.LocalHostIP), 181 }), 182 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 183 Address: net.NewIPOrDomain(dest.Address), 184 Port: uint32(dest.Port), 185 NetworkList: &net.NetworkList{ 186 Network: []net.Network{net.Network_UDP}, 187 }, 188 }), 189 }, 190 }, 191 Outbound: []*core.OutboundHandlerConfig{ 192 { 193 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 194 Server: []*protocol.ServerEndpoint{ 195 { 196 Address: net.NewIPOrDomain(net.LocalHostIP), 197 Port: uint32(serverPort), 198 User: []*protocol.User{ 199 { 200 Account: account, 201 }, 202 }, 203 }, 204 }, 205 }), 206 }, 207 }, 208 } 209 210 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 211 common.Must(err) 212 defer CloseAllServers(servers) 213 214 var errg errgroup.Group 215 for i := 0; i < 10; i++ { 216 errg.Go(func() error { 217 conn, err := net.DialUDP("udp", nil, &net.UDPAddr{ 218 IP: []byte{127, 0, 0, 1}, 219 Port: int(clientPort), 220 }) 221 if err != nil { 222 return err 223 } 224 defer conn.Close() 225 226 payload := make([]byte, 1024) 227 common.Must2(rand.Read(payload)) 228 229 nBytes, err := conn.Write([]byte(payload)) 230 if err != nil { 231 return err 232 } 233 if nBytes != len(payload) { 234 return errors.New("expect ", len(payload), " written, but actually ", nBytes) 235 } 236 237 response := readFrom(conn, time.Second*5, 1024) 238 if r := cmp.Diff(response, xor(payload)); r != "" { 239 return errors.New(r) 240 } 241 return nil 242 }) 243 } 244 245 if err := errg.Wait(); err != nil { 246 t.Fatal(err) 247 } 248 } 249 250 func TestShadowsocksChacha20TCP(t *testing.T) { 251 tcpServer := tcp.Server{ 252 MsgProcessor: xor, 253 } 254 dest, err := tcpServer.Start() 255 common.Must(err) 256 257 defer tcpServer.Close() 258 259 account := serial.ToTypedMessage(&shadowsocks.Account{ 260 Password: "shadowsocks-password", 261 CipherType: shadowsocks.CipherType_CHACHA20_IETF, 262 }) 263 264 serverPort := tcp.PickPort() 265 serverConfig := &core.Config{ 266 App: []*serial.TypedMessage{ 267 serial.ToTypedMessage(&log.Config{ 268 ErrorLogLevel: clog.Severity_Debug, 269 ErrorLogType: log.LogType_Console, 270 }), 271 }, 272 Inbound: []*core.InboundHandlerConfig{ 273 { 274 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 275 PortRange: net.SinglePortRange(serverPort), 276 Listen: net.NewIPOrDomain(net.LocalHostIP), 277 }), 278 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 279 User: &protocol.User{ 280 Account: account, 281 Level: 1, 282 }, 283 Network: []net.Network{net.Network_TCP}, 284 }), 285 }, 286 }, 287 Outbound: []*core.OutboundHandlerConfig{ 288 { 289 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 290 }, 291 }, 292 } 293 294 clientPort := tcp.PickPort() 295 clientConfig := &core.Config{ 296 App: []*serial.TypedMessage{ 297 serial.ToTypedMessage(&log.Config{ 298 ErrorLogLevel: clog.Severity_Debug, 299 ErrorLogType: log.LogType_Console, 300 }), 301 }, 302 Inbound: []*core.InboundHandlerConfig{ 303 { 304 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 305 PortRange: net.SinglePortRange(clientPort), 306 Listen: net.NewIPOrDomain(net.LocalHostIP), 307 }), 308 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 309 Address: net.NewIPOrDomain(dest.Address), 310 Port: uint32(dest.Port), 311 NetworkList: &net.NetworkList{ 312 Network: []net.Network{net.Network_TCP}, 313 }, 314 }), 315 }, 316 }, 317 Outbound: []*core.OutboundHandlerConfig{ 318 { 319 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 320 Server: []*protocol.ServerEndpoint{ 321 { 322 Address: net.NewIPOrDomain(net.LocalHostIP), 323 Port: uint32(serverPort), 324 User: []*protocol.User{ 325 { 326 Account: account, 327 }, 328 }, 329 }, 330 }, 331 }), 332 }, 333 }, 334 } 335 336 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 337 common.Must(err) 338 defer CloseAllServers(servers) 339 340 var errg errgroup.Group 341 for i := 0; i < 10; i++ { 342 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40)) 343 } 344 345 if err := errg.Wait(); err != nil { 346 t.Error(err) 347 } 348 } 349 350 func TestShadowsocksChacha20Poly1305TCP(t *testing.T) { 351 tcpServer := tcp.Server{ 352 MsgProcessor: xor, 353 } 354 dest, err := tcpServer.Start() 355 common.Must(err) 356 defer tcpServer.Close() 357 358 account := serial.ToTypedMessage(&shadowsocks.Account{ 359 Password: "shadowsocks-password", 360 CipherType: shadowsocks.CipherType_CHACHA20_POLY1305, 361 }) 362 363 serverPort := tcp.PickPort() 364 serverConfig := &core.Config{ 365 Inbound: []*core.InboundHandlerConfig{ 366 { 367 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 368 PortRange: net.SinglePortRange(serverPort), 369 Listen: net.NewIPOrDomain(net.LocalHostIP), 370 }), 371 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 372 User: &protocol.User{ 373 Account: account, 374 Level: 1, 375 }, 376 Network: []net.Network{net.Network_TCP}, 377 }), 378 }, 379 }, 380 Outbound: []*core.OutboundHandlerConfig{ 381 { 382 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 383 }, 384 }, 385 } 386 387 clientPort := tcp.PickPort() 388 clientConfig := &core.Config{ 389 Inbound: []*core.InboundHandlerConfig{ 390 { 391 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 392 PortRange: net.SinglePortRange(clientPort), 393 Listen: net.NewIPOrDomain(net.LocalHostIP), 394 }), 395 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 396 Address: net.NewIPOrDomain(dest.Address), 397 Port: uint32(dest.Port), 398 NetworkList: &net.NetworkList{ 399 Network: []net.Network{net.Network_TCP}, 400 }, 401 }), 402 }, 403 }, 404 Outbound: []*core.OutboundHandlerConfig{ 405 { 406 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 407 Server: []*protocol.ServerEndpoint{ 408 { 409 Address: net.NewIPOrDomain(net.LocalHostIP), 410 Port: uint32(serverPort), 411 User: []*protocol.User{ 412 { 413 Account: account, 414 }, 415 }, 416 }, 417 }, 418 }), 419 }, 420 }, 421 } 422 423 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 424 common.Must(err) 425 defer CloseAllServers(servers) 426 427 var errg errgroup.Group 428 for i := 0; i < 10; i++ { 429 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20)) 430 } 431 if err := errg.Wait(); err != nil { 432 t.Error(err) 433 } 434 } 435 436 func TestShadowsocksAES256GCMTCP(t *testing.T) { 437 tcpServer := tcp.Server{ 438 MsgProcessor: xor, 439 } 440 dest, err := tcpServer.Start() 441 common.Must(err) 442 defer tcpServer.Close() 443 444 account := serial.ToTypedMessage(&shadowsocks.Account{ 445 Password: "shadowsocks-password", 446 CipherType: shadowsocks.CipherType_AES_256_GCM, 447 }) 448 449 serverPort := tcp.PickPort() 450 serverConfig := &core.Config{ 451 App: []*serial.TypedMessage{ 452 serial.ToTypedMessage(&log.Config{ 453 ErrorLogLevel: clog.Severity_Debug, 454 ErrorLogType: log.LogType_Console, 455 }), 456 }, 457 Inbound: []*core.InboundHandlerConfig{ 458 { 459 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 460 PortRange: net.SinglePortRange(serverPort), 461 Listen: net.NewIPOrDomain(net.LocalHostIP), 462 }), 463 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 464 User: &protocol.User{ 465 Account: account, 466 Level: 1, 467 }, 468 Network: []net.Network{net.Network_TCP}, 469 }), 470 }, 471 }, 472 Outbound: []*core.OutboundHandlerConfig{ 473 { 474 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 475 }, 476 }, 477 } 478 479 clientPort := tcp.PickPort() 480 clientConfig := &core.Config{ 481 App: []*serial.TypedMessage{ 482 serial.ToTypedMessage(&log.Config{ 483 ErrorLogLevel: clog.Severity_Debug, 484 ErrorLogType: log.LogType_Console, 485 }), 486 }, 487 Inbound: []*core.InboundHandlerConfig{ 488 { 489 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 490 PortRange: net.SinglePortRange(clientPort), 491 Listen: net.NewIPOrDomain(net.LocalHostIP), 492 }), 493 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 494 Address: net.NewIPOrDomain(dest.Address), 495 Port: uint32(dest.Port), 496 NetworkList: &net.NetworkList{ 497 Network: []net.Network{net.Network_TCP}, 498 }, 499 }), 500 }, 501 }, 502 Outbound: []*core.OutboundHandlerConfig{ 503 { 504 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 505 Server: []*protocol.ServerEndpoint{ 506 { 507 Address: net.NewIPOrDomain(net.LocalHostIP), 508 Port: uint32(serverPort), 509 User: []*protocol.User{ 510 { 511 Account: account, 512 }, 513 }, 514 }, 515 }, 516 }), 517 }, 518 }, 519 } 520 521 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 522 common.Must(err) 523 defer CloseAllServers(servers) 524 525 var errg errgroup.Group 526 for i := 0; i < 10; i++ { 527 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20)) 528 } 529 530 if err := errg.Wait(); err != nil { 531 t.Error(err) 532 } 533 } 534 535 func TestShadowsocksAES128GCMUDP(t *testing.T) { 536 udpServer := udp.Server{ 537 MsgProcessor: xor, 538 } 539 dest, err := udpServer.Start() 540 common.Must(err) 541 defer udpServer.Close() 542 543 account := serial.ToTypedMessage(&shadowsocks.Account{ 544 Password: "shadowsocks-password", 545 CipherType: shadowsocks.CipherType_AES_128_GCM, 546 }) 547 548 serverPort := tcp.PickPort() 549 serverConfig := &core.Config{ 550 App: []*serial.TypedMessage{ 551 serial.ToTypedMessage(&log.Config{ 552 ErrorLogLevel: clog.Severity_Debug, 553 ErrorLogType: log.LogType_Console, 554 }), 555 }, 556 Inbound: []*core.InboundHandlerConfig{ 557 { 558 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 559 PortRange: net.SinglePortRange(serverPort), 560 Listen: net.NewIPOrDomain(net.LocalHostIP), 561 }), 562 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 563 User: &protocol.User{ 564 Account: account, 565 Level: 1, 566 }, 567 Network: []net.Network{net.Network_UDP}, 568 }), 569 }, 570 }, 571 Outbound: []*core.OutboundHandlerConfig{ 572 { 573 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 574 }, 575 }, 576 } 577 578 clientPort := tcp.PickPort() 579 clientConfig := &core.Config{ 580 App: []*serial.TypedMessage{ 581 serial.ToTypedMessage(&log.Config{ 582 ErrorLogLevel: clog.Severity_Debug, 583 ErrorLogType: log.LogType_Console, 584 }), 585 }, 586 Inbound: []*core.InboundHandlerConfig{ 587 { 588 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 589 PortRange: net.SinglePortRange(clientPort), 590 Listen: net.NewIPOrDomain(net.LocalHostIP), 591 }), 592 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 593 Address: net.NewIPOrDomain(dest.Address), 594 Port: uint32(dest.Port), 595 NetworkList: &net.NetworkList{ 596 Network: []net.Network{net.Network_UDP}, 597 }, 598 }), 599 }, 600 }, 601 Outbound: []*core.OutboundHandlerConfig{ 602 { 603 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 604 Server: []*protocol.ServerEndpoint{ 605 { 606 Address: net.NewIPOrDomain(net.LocalHostIP), 607 Port: uint32(serverPort), 608 User: []*protocol.User{ 609 { 610 Account: account, 611 }, 612 }, 613 }, 614 }, 615 }), 616 }, 617 }, 618 } 619 620 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 621 common.Must(err) 622 defer CloseAllServers(servers) 623 624 var errg errgroup.Group 625 for i := 0; i < 10; i++ { 626 errg.Go(testUDPConn(clientPort, 1024, time.Second*5)) 627 } 628 if err := errg.Wait(); err != nil { 629 t.Error(err) 630 } 631 } 632 633 func TestShadowsocksAES128GCMUDPMux(t *testing.T) { 634 udpServer := udp.Server{ 635 MsgProcessor: xor, 636 } 637 dest, err := udpServer.Start() 638 common.Must(err) 639 defer udpServer.Close() 640 641 account := serial.ToTypedMessage(&shadowsocks.Account{ 642 Password: "shadowsocks-password", 643 CipherType: shadowsocks.CipherType_AES_128_GCM, 644 }) 645 646 serverPort := tcp.PickPort() 647 serverConfig := &core.Config{ 648 App: []*serial.TypedMessage{ 649 serial.ToTypedMessage(&log.Config{ 650 ErrorLogLevel: clog.Severity_Debug, 651 ErrorLogType: log.LogType_Console, 652 }), 653 }, 654 Inbound: []*core.InboundHandlerConfig{ 655 { 656 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 657 PortRange: net.SinglePortRange(serverPort), 658 Listen: net.NewIPOrDomain(net.LocalHostIP), 659 }), 660 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 661 User: &protocol.User{ 662 Account: account, 663 Level: 1, 664 }, 665 Network: []net.Network{net.Network_TCP}, 666 }), 667 }, 668 }, 669 Outbound: []*core.OutboundHandlerConfig{ 670 { 671 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 672 }, 673 }, 674 } 675 676 clientPort := tcp.PickPort() 677 clientConfig := &core.Config{ 678 App: []*serial.TypedMessage{ 679 serial.ToTypedMessage(&log.Config{ 680 ErrorLogLevel: clog.Severity_Debug, 681 ErrorLogType: log.LogType_Console, 682 }), 683 }, 684 Inbound: []*core.InboundHandlerConfig{ 685 { 686 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 687 PortRange: net.SinglePortRange(clientPort), 688 Listen: net.NewIPOrDomain(net.LocalHostIP), 689 }), 690 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 691 Address: net.NewIPOrDomain(dest.Address), 692 Port: uint32(dest.Port), 693 NetworkList: &net.NetworkList{ 694 Network: []net.Network{net.Network_UDP}, 695 }, 696 }), 697 }, 698 }, 699 Outbound: []*core.OutboundHandlerConfig{ 700 { 701 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 702 MultiplexSettings: &proxyman.MultiplexingConfig{ 703 Enabled: true, 704 Concurrency: 8, 705 }, 706 }), 707 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 708 Server: []*protocol.ServerEndpoint{ 709 { 710 Address: net.NewIPOrDomain(net.LocalHostIP), 711 Port: uint32(serverPort), 712 User: []*protocol.User{ 713 { 714 Account: account, 715 }, 716 }, 717 }, 718 }, 719 }), 720 }, 721 }, 722 } 723 724 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 725 common.Must(err) 726 defer CloseAllServers(servers) 727 728 var errg errgroup.Group 729 for i := 0; i < 10; i++ { 730 errg.Go(testUDPConn(clientPort, 1024, time.Second*5)) 731 } 732 if err := errg.Wait(); err != nil { 733 t.Error(err) 734 } 735 } 736 737 func TestShadowsocksNone(t *testing.T) { 738 tcpServer := tcp.Server{ 739 MsgProcessor: xor, 740 } 741 dest, err := tcpServer.Start() 742 common.Must(err) 743 744 defer tcpServer.Close() 745 746 account := serial.ToTypedMessage(&shadowsocks.Account{ 747 Password: "shadowsocks-password", 748 CipherType: shadowsocks.CipherType_NONE, 749 }) 750 751 serverPort := tcp.PickPort() 752 serverConfig := &core.Config{ 753 Inbound: []*core.InboundHandlerConfig{ 754 { 755 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 756 PortRange: net.SinglePortRange(serverPort), 757 Listen: net.NewIPOrDomain(net.LocalHostIP), 758 }), 759 ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ 760 User: &protocol.User{ 761 Account: account, 762 Level: 1, 763 }, 764 Network: []net.Network{net.Network_TCP}, 765 }), 766 }, 767 }, 768 Outbound: []*core.OutboundHandlerConfig{ 769 { 770 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 771 }, 772 }, 773 } 774 775 clientPort := tcp.PickPort() 776 clientConfig := &core.Config{ 777 Inbound: []*core.InboundHandlerConfig{ 778 { 779 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 780 PortRange: net.SinglePortRange(clientPort), 781 Listen: net.NewIPOrDomain(net.LocalHostIP), 782 }), 783 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 784 Address: net.NewIPOrDomain(dest.Address), 785 Port: uint32(dest.Port), 786 NetworkList: &net.NetworkList{ 787 Network: []net.Network{net.Network_TCP}, 788 }, 789 }), 790 }, 791 }, 792 Outbound: []*core.OutboundHandlerConfig{ 793 { 794 ProxySettings: serial.ToTypedMessage(&shadowsocks.ClientConfig{ 795 Server: []*protocol.ServerEndpoint{ 796 { 797 Address: net.NewIPOrDomain(net.LocalHostIP), 798 Port: uint32(serverPort), 799 User: []*protocol.User{ 800 { 801 Account: account, 802 }, 803 }, 804 }, 805 }, 806 }), 807 }, 808 }, 809 } 810 811 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 812 common.Must(err) 813 814 defer CloseAllServers(servers) 815 816 var errg errgroup.Group 817 for i := 0; i < 10; i++ { 818 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20)) 819 } 820 821 if err := errg.Wait(); err != nil { 822 t.Fatal(err) 823 } 824 }