github.com/v2fly/v2ray-core/v4@v4.45.2/testing/scenarios/vmess_test.go (about) 1 package scenarios 2 3 import ( 4 "os" 5 "testing" 6 "time" 7 8 "golang.org/x/sync/errgroup" 9 10 core "github.com/v2fly/v2ray-core/v4" 11 "github.com/v2fly/v2ray-core/v4/app/log" 12 "github.com/v2fly/v2ray-core/v4/app/proxyman" 13 "github.com/v2fly/v2ray-core/v4/common" 14 clog "github.com/v2fly/v2ray-core/v4/common/log" 15 "github.com/v2fly/v2ray-core/v4/common/net" 16 "github.com/v2fly/v2ray-core/v4/common/protocol" 17 "github.com/v2fly/v2ray-core/v4/common/serial" 18 "github.com/v2fly/v2ray-core/v4/common/uuid" 19 "github.com/v2fly/v2ray-core/v4/proxy/dokodemo" 20 "github.com/v2fly/v2ray-core/v4/proxy/freedom" 21 "github.com/v2fly/v2ray-core/v4/proxy/vmess" 22 "github.com/v2fly/v2ray-core/v4/proxy/vmess/inbound" 23 "github.com/v2fly/v2ray-core/v4/proxy/vmess/outbound" 24 "github.com/v2fly/v2ray-core/v4/testing/servers/tcp" 25 "github.com/v2fly/v2ray-core/v4/testing/servers/udp" 26 "github.com/v2fly/v2ray-core/v4/transport/internet" 27 "github.com/v2fly/v2ray-core/v4/transport/internet/kcp" 28 ) 29 30 func TestVMessDynamicPort(t *testing.T) { 31 tcpServer := tcp.Server{ 32 MsgProcessor: xor, 33 } 34 dest, err := tcpServer.Start() 35 common.Must(err) 36 defer tcpServer.Close() 37 38 userID := protocol.NewID(uuid.New()) 39 40 retry := 1 41 serverPort := tcp.PickPort() 42 for { 43 serverConfig := &core.Config{ 44 App: []*serial.TypedMessage{ 45 serial.ToTypedMessage(&log.Config{ 46 ErrorLogLevel: clog.Severity_Debug, 47 ErrorLogType: log.LogType_Console, 48 }), 49 }, 50 Inbound: []*core.InboundHandlerConfig{ 51 { 52 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 53 PortRange: net.SinglePortRange(serverPort), 54 Listen: net.NewIPOrDomain(net.LocalHostIP), 55 }), 56 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 57 User: []*protocol.User{ 58 { 59 Account: serial.ToTypedMessage(&vmess.Account{ 60 Id: userID.String(), 61 }), 62 }, 63 }, 64 Detour: &inbound.DetourConfig{ 65 To: "detour", 66 }, 67 }), 68 }, 69 { 70 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 71 PortRange: net.SinglePortRange(serverPort + 100), 72 Listen: net.NewIPOrDomain(net.LocalHostIP), 73 }), 74 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 75 Address: net.NewIPOrDomain(dest.Address), 76 Port: uint32(dest.Port), 77 NetworkList: &net.NetworkList{ 78 Network: []net.Network{net.Network_TCP}, 79 }, 80 }), 81 }, 82 { 83 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 84 PortRange: &net.PortRange{ 85 From: uint32(serverPort + 1), 86 To: uint32(serverPort + 99), 87 }, 88 Listen: net.NewIPOrDomain(net.LocalHostIP), 89 AllocationStrategy: &proxyman.AllocationStrategy{ 90 Type: proxyman.AllocationStrategy_Random, 91 Concurrency: &proxyman.AllocationStrategy_AllocationStrategyConcurrency{ 92 Value: 2, 93 }, 94 Refresh: &proxyman.AllocationStrategy_AllocationStrategyRefresh{ 95 Value: 5, 96 }, 97 }, 98 }), 99 ProxySettings: serial.ToTypedMessage(&inbound.Config{}), 100 Tag: "detour", 101 }, 102 }, 103 Outbound: []*core.OutboundHandlerConfig{ 104 { 105 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 106 }, 107 }, 108 } 109 110 server, _ := InitializeServerConfig(serverConfig) 111 if server != nil && tcpConnAvailableAtPort(t, serverPort+100) { 112 defer CloseServer(server) 113 break 114 } 115 retry++ 116 if retry > 5 { 117 t.Fatal("All attempts failed to start server") 118 } 119 serverPort = tcp.PickPort() 120 } 121 122 clientPort := tcp.PickPort() 123 clientConfig := &core.Config{ 124 App: []*serial.TypedMessage{ 125 serial.ToTypedMessage(&log.Config{ 126 ErrorLogLevel: clog.Severity_Debug, 127 ErrorLogType: log.LogType_Console, 128 }), 129 }, 130 Inbound: []*core.InboundHandlerConfig{ 131 { 132 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 133 PortRange: net.SinglePortRange(clientPort), 134 Listen: net.NewIPOrDomain(net.LocalHostIP), 135 }), 136 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 137 Address: net.NewIPOrDomain(dest.Address), 138 Port: uint32(dest.Port), 139 NetworkList: &net.NetworkList{ 140 Network: []net.Network{net.Network_TCP}, 141 }, 142 }), 143 }, 144 }, 145 Outbound: []*core.OutboundHandlerConfig{ 146 { 147 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 148 Receiver: []*protocol.ServerEndpoint{ 149 { 150 Address: net.NewIPOrDomain(net.LocalHostIP), 151 Port: uint32(serverPort), 152 User: []*protocol.User{ 153 { 154 Account: serial.ToTypedMessage(&vmess.Account{ 155 Id: userID.String(), 156 }), 157 }, 158 }, 159 }, 160 }, 161 }), 162 }, 163 }, 164 } 165 166 server, err := InitializeServerConfig(clientConfig) 167 common.Must(err) 168 defer CloseServer(server) 169 170 if !tcpConnAvailableAtPort(t, clientPort) { 171 t.Fail() 172 } 173 } 174 175 func tcpConnAvailableAtPort(t *testing.T, port net.Port) bool { 176 for i := 1; ; i++ { 177 if i > 10 { 178 t.Log("All attempts failed to test tcp conn") 179 return false 180 } 181 time.Sleep(time.Millisecond * 10) 182 if err := testTCPConn(port, 1024, time.Second*2)(); err != nil { 183 t.Log("err ", err) 184 } else { 185 t.Log("success with", i, "attempts") 186 break 187 } 188 } 189 return true 190 } 191 192 func TestVMessGCM(t *testing.T) { 193 tcpServer := tcp.Server{ 194 MsgProcessor: xor, 195 } 196 dest, err := tcpServer.Start() 197 common.Must(err) 198 defer tcpServer.Close() 199 200 userID := protocol.NewID(uuid.New()) 201 serverPort := tcp.PickPort() 202 serverConfig := &core.Config{ 203 App: []*serial.TypedMessage{ 204 serial.ToTypedMessage(&log.Config{ 205 ErrorLogLevel: clog.Severity_Debug, 206 ErrorLogType: log.LogType_Console, 207 }), 208 }, 209 Inbound: []*core.InboundHandlerConfig{ 210 { 211 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 212 PortRange: net.SinglePortRange(serverPort), 213 Listen: net.NewIPOrDomain(net.LocalHostIP), 214 }), 215 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 216 User: []*protocol.User{ 217 { 218 Account: serial.ToTypedMessage(&vmess.Account{ 219 Id: userID.String(), 220 AlterId: 0, 221 }), 222 }, 223 }, 224 }), 225 }, 226 }, 227 Outbound: []*core.OutboundHandlerConfig{ 228 { 229 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 230 }, 231 }, 232 } 233 234 clientPort := tcp.PickPort() 235 clientConfig := &core.Config{ 236 App: []*serial.TypedMessage{ 237 serial.ToTypedMessage(&log.Config{ 238 ErrorLogLevel: clog.Severity_Debug, 239 ErrorLogType: log.LogType_Console, 240 }), 241 }, 242 Inbound: []*core.InboundHandlerConfig{ 243 { 244 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 245 PortRange: net.SinglePortRange(clientPort), 246 Listen: net.NewIPOrDomain(net.LocalHostIP), 247 }), 248 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 249 Address: net.NewIPOrDomain(dest.Address), 250 Port: uint32(dest.Port), 251 NetworkList: &net.NetworkList{ 252 Network: []net.Network{net.Network_TCP}, 253 }, 254 }), 255 }, 256 }, 257 Outbound: []*core.OutboundHandlerConfig{ 258 { 259 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 260 Receiver: []*protocol.ServerEndpoint{ 261 { 262 Address: net.NewIPOrDomain(net.LocalHostIP), 263 Port: uint32(serverPort), 264 User: []*protocol.User{ 265 { 266 Account: serial.ToTypedMessage(&vmess.Account{ 267 Id: userID.String(), 268 AlterId: 0, 269 SecuritySettings: &protocol.SecurityConfig{ 270 Type: protocol.SecurityType_AES128_GCM, 271 }, 272 }), 273 }, 274 }, 275 }, 276 }, 277 }), 278 }, 279 }, 280 } 281 282 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 283 if err != nil { 284 t.Fatal("Failed to initialize all servers: ", err.Error()) 285 } 286 defer CloseAllServers(servers) 287 288 var errg errgroup.Group 289 for i := 0; i < 10; i++ { 290 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40)) 291 } 292 293 if err := errg.Wait(); err != nil { 294 t.Error(err) 295 } 296 } 297 298 func TestVMessGCMReadv(t *testing.T) { 299 tcpServer := tcp.Server{ 300 MsgProcessor: xor, 301 } 302 dest, err := tcpServer.Start() 303 common.Must(err) 304 defer tcpServer.Close() 305 306 userID := protocol.NewID(uuid.New()) 307 serverPort := tcp.PickPort() 308 serverConfig := &core.Config{ 309 App: []*serial.TypedMessage{ 310 serial.ToTypedMessage(&log.Config{ 311 ErrorLogLevel: clog.Severity_Debug, 312 ErrorLogType: log.LogType_Console, 313 }), 314 }, 315 Inbound: []*core.InboundHandlerConfig{ 316 { 317 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 318 PortRange: net.SinglePortRange(serverPort), 319 Listen: net.NewIPOrDomain(net.LocalHostIP), 320 }), 321 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 322 User: []*protocol.User{ 323 { 324 Account: serial.ToTypedMessage(&vmess.Account{ 325 Id: userID.String(), 326 AlterId: 0, 327 }), 328 }, 329 }, 330 }), 331 }, 332 }, 333 Outbound: []*core.OutboundHandlerConfig{ 334 { 335 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 336 }, 337 }, 338 } 339 340 clientPort := tcp.PickPort() 341 clientConfig := &core.Config{ 342 App: []*serial.TypedMessage{ 343 serial.ToTypedMessage(&log.Config{ 344 ErrorLogLevel: clog.Severity_Debug, 345 ErrorLogType: log.LogType_Console, 346 }), 347 }, 348 Inbound: []*core.InboundHandlerConfig{ 349 { 350 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 351 PortRange: net.SinglePortRange(clientPort), 352 Listen: net.NewIPOrDomain(net.LocalHostIP), 353 }), 354 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 355 Address: net.NewIPOrDomain(dest.Address), 356 Port: uint32(dest.Port), 357 NetworkList: &net.NetworkList{ 358 Network: []net.Network{net.Network_TCP}, 359 }, 360 }), 361 }, 362 }, 363 Outbound: []*core.OutboundHandlerConfig{ 364 { 365 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 366 Receiver: []*protocol.ServerEndpoint{ 367 { 368 Address: net.NewIPOrDomain(net.LocalHostIP), 369 Port: uint32(serverPort), 370 User: []*protocol.User{ 371 { 372 Account: serial.ToTypedMessage(&vmess.Account{ 373 Id: userID.String(), 374 AlterId: 0, 375 SecuritySettings: &protocol.SecurityConfig{ 376 Type: protocol.SecurityType_AES128_GCM, 377 }, 378 }), 379 }, 380 }, 381 }, 382 }, 383 }), 384 }, 385 }, 386 } 387 388 const envName = "V2RAY_BUF_READV" 389 common.Must(os.Setenv(envName, "enable")) 390 defer os.Unsetenv(envName) 391 392 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 393 if err != nil { 394 t.Fatal("Failed to initialize all servers: ", err.Error()) 395 } 396 defer CloseAllServers(servers) 397 398 var errg errgroup.Group 399 for i := 0; i < 10; i++ { 400 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40)) 401 } 402 if err := errg.Wait(); err != nil { 403 t.Error(err) 404 } 405 } 406 407 func TestVMessGCMUDP(t *testing.T) { 408 udpServer := udp.Server{ 409 MsgProcessor: xor, 410 } 411 dest, err := udpServer.Start() 412 common.Must(err) 413 defer udpServer.Close() 414 415 userID := protocol.NewID(uuid.New()) 416 serverPort := tcp.PickPort() 417 serverConfig := &core.Config{ 418 App: []*serial.TypedMessage{ 419 serial.ToTypedMessage(&log.Config{ 420 ErrorLogLevel: clog.Severity_Debug, 421 ErrorLogType: log.LogType_Console, 422 }), 423 }, 424 Inbound: []*core.InboundHandlerConfig{ 425 { 426 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 427 PortRange: net.SinglePortRange(serverPort), 428 Listen: net.NewIPOrDomain(net.LocalHostIP), 429 }), 430 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 431 User: []*protocol.User{ 432 { 433 Account: serial.ToTypedMessage(&vmess.Account{ 434 Id: userID.String(), 435 AlterId: 0, 436 }), 437 }, 438 }, 439 }), 440 }, 441 }, 442 Outbound: []*core.OutboundHandlerConfig{ 443 { 444 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 445 }, 446 }, 447 } 448 449 clientPort := udp.PickPort() 450 clientConfig := &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(clientPort), 461 Listen: net.NewIPOrDomain(net.LocalHostIP), 462 }), 463 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 464 Address: net.NewIPOrDomain(dest.Address), 465 Port: uint32(dest.Port), 466 NetworkList: &net.NetworkList{ 467 Network: []net.Network{net.Network_UDP}, 468 }, 469 }), 470 }, 471 }, 472 Outbound: []*core.OutboundHandlerConfig{ 473 { 474 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 475 Receiver: []*protocol.ServerEndpoint{ 476 { 477 Address: net.NewIPOrDomain(net.LocalHostIP), 478 Port: uint32(serverPort), 479 User: []*protocol.User{ 480 { 481 Account: serial.ToTypedMessage(&vmess.Account{ 482 Id: userID.String(), 483 AlterId: 0, 484 SecuritySettings: &protocol.SecurityConfig{ 485 Type: protocol.SecurityType_AES128_GCM, 486 }, 487 }), 488 }, 489 }, 490 }, 491 }, 492 }), 493 }, 494 }, 495 } 496 497 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 498 common.Must(err) 499 defer CloseAllServers(servers) 500 501 var errg errgroup.Group 502 for i := 0; i < 10; i++ { 503 errg.Go(testUDPConn(clientPort, 1024, time.Second*5)) 504 } 505 if err := errg.Wait(); err != nil { 506 t.Error(err) 507 } 508 } 509 510 func TestVMessChacha20(t *testing.T) { 511 tcpServer := tcp.Server{ 512 MsgProcessor: xor, 513 } 514 dest, err := tcpServer.Start() 515 common.Must(err) 516 defer tcpServer.Close() 517 518 userID := protocol.NewID(uuid.New()) 519 serverPort := tcp.PickPort() 520 serverConfig := &core.Config{ 521 App: []*serial.TypedMessage{ 522 serial.ToTypedMessage(&log.Config{ 523 ErrorLogLevel: clog.Severity_Debug, 524 ErrorLogType: log.LogType_Console, 525 }), 526 }, 527 Inbound: []*core.InboundHandlerConfig{ 528 { 529 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 530 PortRange: net.SinglePortRange(serverPort), 531 Listen: net.NewIPOrDomain(net.LocalHostIP), 532 }), 533 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 534 User: []*protocol.User{ 535 { 536 Account: serial.ToTypedMessage(&vmess.Account{ 537 Id: userID.String(), 538 AlterId: 0, 539 }), 540 }, 541 }, 542 }), 543 }, 544 }, 545 Outbound: []*core.OutboundHandlerConfig{ 546 { 547 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 548 }, 549 }, 550 } 551 552 clientPort := tcp.PickPort() 553 clientConfig := &core.Config{ 554 App: []*serial.TypedMessage{ 555 serial.ToTypedMessage(&log.Config{ 556 ErrorLogLevel: clog.Severity_Debug, 557 ErrorLogType: log.LogType_Console, 558 }), 559 }, 560 Inbound: []*core.InboundHandlerConfig{ 561 { 562 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 563 PortRange: net.SinglePortRange(clientPort), 564 Listen: net.NewIPOrDomain(net.LocalHostIP), 565 }), 566 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 567 Address: net.NewIPOrDomain(dest.Address), 568 Port: uint32(dest.Port), 569 NetworkList: &net.NetworkList{ 570 Network: []net.Network{net.Network_TCP}, 571 }, 572 }), 573 }, 574 }, 575 Outbound: []*core.OutboundHandlerConfig{ 576 { 577 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 578 Receiver: []*protocol.ServerEndpoint{ 579 { 580 Address: net.NewIPOrDomain(net.LocalHostIP), 581 Port: uint32(serverPort), 582 User: []*protocol.User{ 583 { 584 Account: serial.ToTypedMessage(&vmess.Account{ 585 Id: userID.String(), 586 AlterId: 0, 587 SecuritySettings: &protocol.SecurityConfig{ 588 Type: protocol.SecurityType_CHACHA20_POLY1305, 589 }, 590 }), 591 }, 592 }, 593 }, 594 }, 595 }), 596 }, 597 }, 598 } 599 600 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 601 common.Must(err) 602 defer CloseAllServers(servers) 603 604 var errg errgroup.Group 605 for i := 0; i < 10; i++ { 606 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20)) 607 } 608 609 if err := errg.Wait(); err != nil { 610 t.Error(err) 611 } 612 } 613 614 func TestVMessNone(t *testing.T) { 615 tcpServer := tcp.Server{ 616 MsgProcessor: xor, 617 } 618 dest, err := tcpServer.Start() 619 common.Must(err) 620 defer tcpServer.Close() 621 622 userID := protocol.NewID(uuid.New()) 623 serverPort := tcp.PickPort() 624 serverConfig := &core.Config{ 625 App: []*serial.TypedMessage{ 626 serial.ToTypedMessage(&log.Config{ 627 ErrorLogLevel: clog.Severity_Debug, 628 ErrorLogType: log.LogType_Console, 629 }), 630 }, 631 Inbound: []*core.InboundHandlerConfig{ 632 { 633 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 634 PortRange: net.SinglePortRange(serverPort), 635 Listen: net.NewIPOrDomain(net.LocalHostIP), 636 }), 637 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 638 User: []*protocol.User{ 639 { 640 Account: serial.ToTypedMessage(&vmess.Account{ 641 Id: userID.String(), 642 AlterId: 0, 643 }), 644 }, 645 }, 646 }), 647 }, 648 }, 649 Outbound: []*core.OutboundHandlerConfig{ 650 { 651 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 652 }, 653 }, 654 } 655 656 clientPort := tcp.PickPort() 657 clientConfig := &core.Config{ 658 App: []*serial.TypedMessage{ 659 serial.ToTypedMessage(&log.Config{ 660 ErrorLogLevel: clog.Severity_Debug, 661 ErrorLogType: log.LogType_Console, 662 }), 663 }, 664 Inbound: []*core.InboundHandlerConfig{ 665 { 666 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 667 PortRange: net.SinglePortRange(clientPort), 668 Listen: net.NewIPOrDomain(net.LocalHostIP), 669 }), 670 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 671 Address: net.NewIPOrDomain(dest.Address), 672 Port: uint32(dest.Port), 673 NetworkList: &net.NetworkList{ 674 Network: []net.Network{net.Network_TCP}, 675 }, 676 }), 677 }, 678 }, 679 Outbound: []*core.OutboundHandlerConfig{ 680 { 681 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 682 Receiver: []*protocol.ServerEndpoint{ 683 { 684 Address: net.NewIPOrDomain(net.LocalHostIP), 685 Port: uint32(serverPort), 686 User: []*protocol.User{ 687 { 688 Account: serial.ToTypedMessage(&vmess.Account{ 689 Id: userID.String(), 690 AlterId: 0, 691 SecuritySettings: &protocol.SecurityConfig{ 692 Type: protocol.SecurityType_NONE, 693 }, 694 }), 695 }, 696 }, 697 }, 698 }, 699 }), 700 }, 701 }, 702 } 703 704 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 705 common.Must(err) 706 defer CloseAllServers(servers) 707 708 var errg errgroup.Group 709 for i := 0; i < 10; i++ { 710 errg.Go(testTCPConn(clientPort, 1024*1024, time.Second*30)) 711 } 712 if err := errg.Wait(); err != nil { 713 t.Error(err) 714 } 715 } 716 717 func TestVMessKCP(t *testing.T) { 718 tcpServer := tcp.Server{ 719 MsgProcessor: xor, 720 } 721 dest, err := tcpServer.Start() 722 common.Must(err) 723 defer tcpServer.Close() 724 725 userID := protocol.NewID(uuid.New()) 726 serverPort := udp.PickPort() 727 serverConfig := &core.Config{ 728 App: []*serial.TypedMessage{ 729 serial.ToTypedMessage(&log.Config{ 730 ErrorLogLevel: clog.Severity_Debug, 731 ErrorLogType: log.LogType_Console, 732 }), 733 }, 734 Inbound: []*core.InboundHandlerConfig{ 735 { 736 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 737 PortRange: net.SinglePortRange(serverPort), 738 Listen: net.NewIPOrDomain(net.LocalHostIP), 739 StreamSettings: &internet.StreamConfig{ 740 Protocol: internet.TransportProtocol_MKCP, 741 }, 742 }), 743 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 744 User: []*protocol.User{ 745 { 746 Account: serial.ToTypedMessage(&vmess.Account{ 747 Id: userID.String(), 748 AlterId: 0, 749 }), 750 }, 751 }, 752 }), 753 }, 754 }, 755 Outbound: []*core.OutboundHandlerConfig{ 756 { 757 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 758 }, 759 }, 760 } 761 762 clientPort := tcp.PickPort() 763 clientConfig := &core.Config{ 764 App: []*serial.TypedMessage{ 765 serial.ToTypedMessage(&log.Config{ 766 ErrorLogLevel: clog.Severity_Debug, 767 ErrorLogType: log.LogType_Console, 768 }), 769 }, 770 Inbound: []*core.InboundHandlerConfig{ 771 { 772 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 773 PortRange: net.SinglePortRange(clientPort), 774 Listen: net.NewIPOrDomain(net.LocalHostIP), 775 }), 776 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 777 Address: net.NewIPOrDomain(dest.Address), 778 Port: uint32(dest.Port), 779 NetworkList: &net.NetworkList{ 780 Network: []net.Network{net.Network_TCP}, 781 }, 782 }), 783 }, 784 }, 785 Outbound: []*core.OutboundHandlerConfig{ 786 { 787 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 788 Receiver: []*protocol.ServerEndpoint{ 789 { 790 Address: net.NewIPOrDomain(net.LocalHostIP), 791 Port: uint32(serverPort), 792 User: []*protocol.User{ 793 { 794 Account: serial.ToTypedMessage(&vmess.Account{ 795 Id: userID.String(), 796 AlterId: 0, 797 SecuritySettings: &protocol.SecurityConfig{ 798 Type: protocol.SecurityType_AES128_GCM, 799 }, 800 }), 801 }, 802 }, 803 }, 804 }, 805 }), 806 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 807 StreamSettings: &internet.StreamConfig{ 808 Protocol: internet.TransportProtocol_MKCP, 809 }, 810 }), 811 }, 812 }, 813 } 814 815 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 816 common.Must(err) 817 defer CloseAllServers(servers) 818 819 var errg errgroup.Group 820 for i := 0; i < 10; i++ { 821 errg.Go(testTCPConn(clientPort, 10240*1024, time.Minute*2)) 822 } 823 if err := errg.Wait(); err != nil { 824 t.Error(err) 825 } 826 } 827 828 func TestVMessKCPLarge(t *testing.T) { 829 tcpServer := tcp.Server{ 830 MsgProcessor: xor, 831 } 832 dest, err := tcpServer.Start() 833 common.Must(err) 834 defer tcpServer.Close() 835 836 userID := protocol.NewID(uuid.New()) 837 serverPort := udp.PickPort() 838 serverConfig := &core.Config{ 839 App: []*serial.TypedMessage{ 840 serial.ToTypedMessage(&log.Config{ 841 ErrorLogLevel: clog.Severity_Debug, 842 ErrorLogType: log.LogType_Console, 843 }), 844 }, 845 Inbound: []*core.InboundHandlerConfig{ 846 { 847 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 848 PortRange: net.SinglePortRange(serverPort), 849 Listen: net.NewIPOrDomain(net.LocalHostIP), 850 StreamSettings: &internet.StreamConfig{ 851 Protocol: internet.TransportProtocol_MKCP, 852 TransportSettings: []*internet.TransportConfig{ 853 { 854 Protocol: internet.TransportProtocol_MKCP, 855 Settings: serial.ToTypedMessage(&kcp.Config{ 856 ReadBuffer: &kcp.ReadBuffer{ 857 Size: 512 * 1024, 858 }, 859 WriteBuffer: &kcp.WriteBuffer{ 860 Size: 512 * 1024, 861 }, 862 UplinkCapacity: &kcp.UplinkCapacity{ 863 Value: 20, 864 }, 865 DownlinkCapacity: &kcp.DownlinkCapacity{ 866 Value: 20, 867 }, 868 }), 869 }, 870 }, 871 }, 872 }), 873 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 874 User: []*protocol.User{ 875 { 876 Account: serial.ToTypedMessage(&vmess.Account{ 877 Id: userID.String(), 878 AlterId: 0, 879 }), 880 }, 881 }, 882 }), 883 }, 884 }, 885 Outbound: []*core.OutboundHandlerConfig{ 886 { 887 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 888 }, 889 }, 890 } 891 892 clientPort := tcp.PickPort() 893 clientConfig := &core.Config{ 894 App: []*serial.TypedMessage{ 895 serial.ToTypedMessage(&log.Config{ 896 ErrorLogLevel: clog.Severity_Debug, 897 ErrorLogType: log.LogType_Console, 898 }), 899 }, 900 Inbound: []*core.InboundHandlerConfig{ 901 { 902 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 903 PortRange: net.SinglePortRange(clientPort), 904 Listen: net.NewIPOrDomain(net.LocalHostIP), 905 }), 906 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 907 Address: net.NewIPOrDomain(dest.Address), 908 Port: uint32(dest.Port), 909 NetworkList: &net.NetworkList{ 910 Network: []net.Network{net.Network_TCP}, 911 }, 912 }), 913 }, 914 }, 915 Outbound: []*core.OutboundHandlerConfig{ 916 { 917 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 918 Receiver: []*protocol.ServerEndpoint{ 919 { 920 Address: net.NewIPOrDomain(net.LocalHostIP), 921 Port: uint32(serverPort), 922 User: []*protocol.User{ 923 { 924 Account: serial.ToTypedMessage(&vmess.Account{ 925 Id: userID.String(), 926 AlterId: 0, 927 SecuritySettings: &protocol.SecurityConfig{ 928 Type: protocol.SecurityType_AES128_GCM, 929 }, 930 }), 931 }, 932 }, 933 }, 934 }, 935 }), 936 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 937 StreamSettings: &internet.StreamConfig{ 938 Protocol: internet.TransportProtocol_MKCP, 939 TransportSettings: []*internet.TransportConfig{ 940 { 941 Protocol: internet.TransportProtocol_MKCP, 942 Settings: serial.ToTypedMessage(&kcp.Config{ 943 ReadBuffer: &kcp.ReadBuffer{ 944 Size: 512 * 1024, 945 }, 946 WriteBuffer: &kcp.WriteBuffer{ 947 Size: 512 * 1024, 948 }, 949 UplinkCapacity: &kcp.UplinkCapacity{ 950 Value: 20, 951 }, 952 DownlinkCapacity: &kcp.DownlinkCapacity{ 953 Value: 20, 954 }, 955 }), 956 }, 957 }, 958 }, 959 }), 960 }, 961 }, 962 } 963 964 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 965 common.Must(err) 966 967 var errg errgroup.Group 968 for i := 0; i < 2; i++ { 969 errg.Go(testTCPConn(clientPort, 10240*1024, time.Minute*5)) 970 } 971 if err := errg.Wait(); err != nil { 972 t.Error(err) 973 } 974 975 defer func() { 976 <-time.After(5 * time.Second) 977 CloseAllServers(servers) 978 }() 979 } 980 981 func TestVMessGCMMux(t *testing.T) { 982 tcpServer := tcp.Server{ 983 MsgProcessor: xor, 984 } 985 dest, err := tcpServer.Start() 986 common.Must(err) 987 defer tcpServer.Close() 988 989 userID := protocol.NewID(uuid.New()) 990 serverPort := tcp.PickPort() 991 serverConfig := &core.Config{ 992 App: []*serial.TypedMessage{ 993 serial.ToTypedMessage(&log.Config{ 994 ErrorLogLevel: clog.Severity_Debug, 995 ErrorLogType: log.LogType_Console, 996 }), 997 }, 998 Inbound: []*core.InboundHandlerConfig{ 999 { 1000 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1001 PortRange: net.SinglePortRange(serverPort), 1002 Listen: net.NewIPOrDomain(net.LocalHostIP), 1003 }), 1004 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 1005 User: []*protocol.User{ 1006 { 1007 Account: serial.ToTypedMessage(&vmess.Account{ 1008 Id: userID.String(), 1009 AlterId: 0, 1010 }), 1011 }, 1012 }, 1013 }), 1014 }, 1015 }, 1016 Outbound: []*core.OutboundHandlerConfig{ 1017 { 1018 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 1019 }, 1020 }, 1021 } 1022 1023 clientPort := tcp.PickPort() 1024 clientConfig := &core.Config{ 1025 App: []*serial.TypedMessage{ 1026 serial.ToTypedMessage(&log.Config{ 1027 ErrorLogLevel: clog.Severity_Debug, 1028 ErrorLogType: log.LogType_Console, 1029 }), 1030 }, 1031 Inbound: []*core.InboundHandlerConfig{ 1032 { 1033 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1034 PortRange: net.SinglePortRange(clientPort), 1035 Listen: net.NewIPOrDomain(net.LocalHostIP), 1036 }), 1037 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 1038 Address: net.NewIPOrDomain(dest.Address), 1039 Port: uint32(dest.Port), 1040 NetworkList: &net.NetworkList{ 1041 Network: []net.Network{net.Network_TCP}, 1042 }, 1043 }), 1044 }, 1045 }, 1046 Outbound: []*core.OutboundHandlerConfig{ 1047 { 1048 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 1049 MultiplexSettings: &proxyman.MultiplexingConfig{ 1050 Enabled: true, 1051 Concurrency: 4, 1052 }, 1053 }), 1054 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 1055 Receiver: []*protocol.ServerEndpoint{ 1056 { 1057 Address: net.NewIPOrDomain(net.LocalHostIP), 1058 Port: uint32(serverPort), 1059 User: []*protocol.User{ 1060 { 1061 Account: serial.ToTypedMessage(&vmess.Account{ 1062 Id: userID.String(), 1063 AlterId: 0, 1064 SecuritySettings: &protocol.SecurityConfig{ 1065 Type: protocol.SecurityType_AES128_GCM, 1066 }, 1067 }), 1068 }, 1069 }, 1070 }, 1071 }, 1072 }), 1073 }, 1074 }, 1075 } 1076 1077 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 1078 common.Must(err) 1079 defer CloseAllServers(servers) 1080 1081 for range "abcd" { 1082 var errg errgroup.Group 1083 for i := 0; i < 16; i++ { 1084 errg.Go(testTCPConn(clientPort, 10240, time.Second*20)) 1085 } 1086 if err := errg.Wait(); err != nil { 1087 t.Fatal(err) 1088 } 1089 time.Sleep(time.Second) 1090 } 1091 } 1092 1093 func TestVMessGCMMuxUDP(t *testing.T) { 1094 tcpServer := tcp.Server{ 1095 MsgProcessor: xor, 1096 } 1097 dest, err := tcpServer.Start() 1098 common.Must(err) 1099 defer tcpServer.Close() 1100 1101 udpServer := udp.Server{ 1102 MsgProcessor: xor, 1103 } 1104 udpDest, err := udpServer.Start() 1105 common.Must(err) 1106 defer udpServer.Close() 1107 1108 userID := protocol.NewID(uuid.New()) 1109 serverPort := tcp.PickPort() 1110 serverConfig := &core.Config{ 1111 App: []*serial.TypedMessage{ 1112 serial.ToTypedMessage(&log.Config{ 1113 ErrorLogLevel: clog.Severity_Debug, 1114 ErrorLogType: log.LogType_Console, 1115 }), 1116 }, 1117 Inbound: []*core.InboundHandlerConfig{ 1118 { 1119 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1120 PortRange: net.SinglePortRange(serverPort), 1121 Listen: net.NewIPOrDomain(net.LocalHostIP), 1122 }), 1123 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 1124 User: []*protocol.User{ 1125 { 1126 Account: serial.ToTypedMessage(&vmess.Account{ 1127 Id: userID.String(), 1128 AlterId: 0, 1129 }), 1130 }, 1131 }, 1132 }), 1133 }, 1134 }, 1135 Outbound: []*core.OutboundHandlerConfig{ 1136 { 1137 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 1138 }, 1139 }, 1140 } 1141 1142 clientPort := tcp.PickPort() 1143 clientUDPPort := udp.PickPort() 1144 clientConfig := &core.Config{ 1145 App: []*serial.TypedMessage{ 1146 serial.ToTypedMessage(&log.Config{ 1147 ErrorLogLevel: clog.Severity_Debug, 1148 ErrorLogType: log.LogType_Console, 1149 }), 1150 }, 1151 Inbound: []*core.InboundHandlerConfig{ 1152 { 1153 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1154 PortRange: net.SinglePortRange(clientPort), 1155 Listen: net.NewIPOrDomain(net.LocalHostIP), 1156 }), 1157 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 1158 Address: net.NewIPOrDomain(dest.Address), 1159 Port: uint32(dest.Port), 1160 NetworkList: &net.NetworkList{ 1161 Network: []net.Network{net.Network_TCP}, 1162 }, 1163 }), 1164 }, 1165 { 1166 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1167 PortRange: net.SinglePortRange(clientUDPPort), 1168 Listen: net.NewIPOrDomain(net.LocalHostIP), 1169 }), 1170 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 1171 Address: net.NewIPOrDomain(udpDest.Address), 1172 Port: uint32(udpDest.Port), 1173 NetworkList: &net.NetworkList{ 1174 Network: []net.Network{net.Network_UDP}, 1175 }, 1176 }), 1177 }, 1178 }, 1179 Outbound: []*core.OutboundHandlerConfig{ 1180 { 1181 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 1182 MultiplexSettings: &proxyman.MultiplexingConfig{ 1183 Enabled: true, 1184 Concurrency: 4, 1185 }, 1186 }), 1187 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 1188 Receiver: []*protocol.ServerEndpoint{ 1189 { 1190 Address: net.NewIPOrDomain(net.LocalHostIP), 1191 Port: uint32(serverPort), 1192 User: []*protocol.User{ 1193 { 1194 Account: serial.ToTypedMessage(&vmess.Account{ 1195 Id: userID.String(), 1196 AlterId: 0, 1197 SecuritySettings: &protocol.SecurityConfig{ 1198 Type: protocol.SecurityType_AES128_GCM, 1199 }, 1200 }), 1201 }, 1202 }, 1203 }, 1204 }, 1205 }), 1206 }, 1207 }, 1208 } 1209 1210 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 1211 common.Must(err) 1212 1213 for range "abcd" { 1214 var errg errgroup.Group 1215 for i := 0; i < 16; i++ { 1216 errg.Go(testTCPConn(clientPort, 10240, time.Second*20)) 1217 errg.Go(testUDPConn(clientUDPPort, 1024, time.Second*10)) 1218 } 1219 if err := errg.Wait(); err != nil { 1220 t.Error(err) 1221 } 1222 time.Sleep(time.Second) 1223 } 1224 1225 defer func() { 1226 <-time.After(5 * time.Second) 1227 CloseAllServers(servers) 1228 }() 1229 } 1230 1231 func TestVMessZero(t *testing.T) { 1232 tcpServer := tcp.Server{ 1233 MsgProcessor: xor, 1234 } 1235 dest, err := tcpServer.Start() 1236 common.Must(err) 1237 defer tcpServer.Close() 1238 1239 userID := protocol.NewID(uuid.New()) 1240 serverPort := tcp.PickPort() 1241 serverConfig := &core.Config{ 1242 App: []*serial.TypedMessage{ 1243 serial.ToTypedMessage(&log.Config{ 1244 ErrorLogLevel: clog.Severity_Debug, 1245 ErrorLogType: log.LogType_Console, 1246 }), 1247 }, 1248 Inbound: []*core.InboundHandlerConfig{ 1249 { 1250 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1251 PortRange: net.SinglePortRange(serverPort), 1252 Listen: net.NewIPOrDomain(net.LocalHostIP), 1253 }), 1254 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 1255 User: []*protocol.User{ 1256 { 1257 Account: serial.ToTypedMessage(&vmess.Account{ 1258 Id: userID.String(), 1259 AlterId: 0, 1260 }), 1261 }, 1262 }, 1263 }), 1264 }, 1265 }, 1266 Outbound: []*core.OutboundHandlerConfig{ 1267 { 1268 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 1269 }, 1270 }, 1271 } 1272 1273 clientPort := tcp.PickPort() 1274 clientConfig := &core.Config{ 1275 App: []*serial.TypedMessage{ 1276 serial.ToTypedMessage(&log.Config{ 1277 ErrorLogLevel: clog.Severity_Debug, 1278 ErrorLogType: log.LogType_Console, 1279 }), 1280 }, 1281 Inbound: []*core.InboundHandlerConfig{ 1282 { 1283 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1284 PortRange: net.SinglePortRange(clientPort), 1285 Listen: net.NewIPOrDomain(net.LocalHostIP), 1286 }), 1287 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 1288 Address: net.NewIPOrDomain(dest.Address), 1289 Port: uint32(dest.Port), 1290 NetworkList: &net.NetworkList{ 1291 Network: []net.Network{net.Network_TCP}, 1292 }, 1293 }), 1294 }, 1295 }, 1296 Outbound: []*core.OutboundHandlerConfig{ 1297 { 1298 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 1299 Receiver: []*protocol.ServerEndpoint{ 1300 { 1301 Address: net.NewIPOrDomain(net.LocalHostIP), 1302 Port: uint32(serverPort), 1303 User: []*protocol.User{ 1304 { 1305 Account: serial.ToTypedMessage(&vmess.Account{ 1306 Id: userID.String(), 1307 AlterId: 0, 1308 SecuritySettings: &protocol.SecurityConfig{ 1309 Type: protocol.SecurityType_ZERO, 1310 }, 1311 }), 1312 }, 1313 }, 1314 }, 1315 }, 1316 }), 1317 }, 1318 }, 1319 } 1320 1321 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 1322 common.Must(err) 1323 defer CloseAllServers(servers) 1324 1325 var errg errgroup.Group 1326 for i := 0; i < 10; i++ { 1327 errg.Go(testTCPConn(clientPort, 1024*1024, time.Second*30)) 1328 } 1329 if err := errg.Wait(); err != nil { 1330 t.Error(err) 1331 } 1332 } 1333 1334 func TestVMessGCMLengthAuth(t *testing.T) { 1335 tcpServer := tcp.Server{ 1336 MsgProcessor: xor, 1337 } 1338 dest, err := tcpServer.Start() 1339 common.Must(err) 1340 defer tcpServer.Close() 1341 1342 userID := protocol.NewID(uuid.New()) 1343 serverPort := tcp.PickPort() 1344 serverConfig := &core.Config{ 1345 App: []*serial.TypedMessage{ 1346 serial.ToTypedMessage(&log.Config{ 1347 ErrorLogLevel: clog.Severity_Debug, 1348 ErrorLogType: log.LogType_Console, 1349 }), 1350 }, 1351 Inbound: []*core.InboundHandlerConfig{ 1352 { 1353 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1354 PortRange: net.SinglePortRange(serverPort), 1355 Listen: net.NewIPOrDomain(net.LocalHostIP), 1356 }), 1357 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 1358 User: []*protocol.User{ 1359 { 1360 Account: serial.ToTypedMessage(&vmess.Account{ 1361 Id: userID.String(), 1362 AlterId: 0, 1363 }), 1364 }, 1365 }, 1366 }), 1367 }, 1368 }, 1369 Outbound: []*core.OutboundHandlerConfig{ 1370 { 1371 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 1372 }, 1373 }, 1374 } 1375 1376 clientPort := tcp.PickPort() 1377 clientConfig := &core.Config{ 1378 App: []*serial.TypedMessage{ 1379 serial.ToTypedMessage(&log.Config{ 1380 ErrorLogLevel: clog.Severity_Debug, 1381 ErrorLogType: log.LogType_Console, 1382 }), 1383 }, 1384 Inbound: []*core.InboundHandlerConfig{ 1385 { 1386 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1387 PortRange: net.SinglePortRange(clientPort), 1388 Listen: net.NewIPOrDomain(net.LocalHostIP), 1389 }), 1390 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 1391 Address: net.NewIPOrDomain(dest.Address), 1392 Port: uint32(dest.Port), 1393 NetworkList: &net.NetworkList{ 1394 Network: []net.Network{net.Network_TCP}, 1395 }, 1396 }), 1397 }, 1398 }, 1399 Outbound: []*core.OutboundHandlerConfig{ 1400 { 1401 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 1402 Receiver: []*protocol.ServerEndpoint{ 1403 { 1404 Address: net.NewIPOrDomain(net.LocalHostIP), 1405 Port: uint32(serverPort), 1406 User: []*protocol.User{ 1407 { 1408 Account: serial.ToTypedMessage(&vmess.Account{ 1409 Id: userID.String(), 1410 AlterId: 0, 1411 SecuritySettings: &protocol.SecurityConfig{ 1412 Type: protocol.SecurityType_AES128_GCM, 1413 }, 1414 TestsEnabled: "AuthenticatedLength", 1415 }), 1416 }, 1417 }, 1418 }, 1419 }, 1420 }), 1421 }, 1422 }, 1423 } 1424 1425 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 1426 if err != nil { 1427 t.Fatal("Failed to initialize all servers: ", err.Error()) 1428 } 1429 defer CloseAllServers(servers) 1430 1431 var errg errgroup.Group 1432 for i := 0; i < 10; i++ { 1433 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40)) 1434 } 1435 1436 if err := errg.Wait(); err != nil { 1437 t.Error(err) 1438 } 1439 } 1440 1441 func TestVMessGCMLengthAuthPlusNoTerminationSignal(t *testing.T) { 1442 tcpServer := tcp.Server{ 1443 MsgProcessor: xor, 1444 } 1445 dest, err := tcpServer.Start() 1446 common.Must(err) 1447 defer tcpServer.Close() 1448 1449 userID := protocol.NewID(uuid.New()) 1450 serverPort := tcp.PickPort() 1451 serverConfig := &core.Config{ 1452 App: []*serial.TypedMessage{ 1453 serial.ToTypedMessage(&log.Config{ 1454 ErrorLogLevel: clog.Severity_Debug, 1455 ErrorLogType: log.LogType_Console, 1456 }), 1457 }, 1458 Inbound: []*core.InboundHandlerConfig{ 1459 { 1460 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1461 PortRange: net.SinglePortRange(serverPort), 1462 Listen: net.NewIPOrDomain(net.LocalHostIP), 1463 }), 1464 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 1465 User: []*protocol.User{ 1466 { 1467 Account: serial.ToTypedMessage(&vmess.Account{ 1468 Id: userID.String(), 1469 AlterId: 0, 1470 TestsEnabled: "AuthenticatedLength|NoTerminationSignal", 1471 }), 1472 }, 1473 }, 1474 }), 1475 }, 1476 }, 1477 Outbound: []*core.OutboundHandlerConfig{ 1478 { 1479 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 1480 }, 1481 }, 1482 } 1483 1484 clientPort := tcp.PickPort() 1485 clientConfig := &core.Config{ 1486 App: []*serial.TypedMessage{ 1487 serial.ToTypedMessage(&log.Config{ 1488 ErrorLogLevel: clog.Severity_Debug, 1489 ErrorLogType: log.LogType_Console, 1490 }), 1491 }, 1492 Inbound: []*core.InboundHandlerConfig{ 1493 { 1494 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 1495 PortRange: net.SinglePortRange(clientPort), 1496 Listen: net.NewIPOrDomain(net.LocalHostIP), 1497 }), 1498 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 1499 Address: net.NewIPOrDomain(dest.Address), 1500 Port: uint32(dest.Port), 1501 NetworkList: &net.NetworkList{ 1502 Network: []net.Network{net.Network_TCP}, 1503 }, 1504 }), 1505 }, 1506 }, 1507 Outbound: []*core.OutboundHandlerConfig{ 1508 { 1509 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 1510 Receiver: []*protocol.ServerEndpoint{ 1511 { 1512 Address: net.NewIPOrDomain(net.LocalHostIP), 1513 Port: uint32(serverPort), 1514 User: []*protocol.User{ 1515 { 1516 Account: serial.ToTypedMessage(&vmess.Account{ 1517 Id: userID.String(), 1518 AlterId: 0, 1519 SecuritySettings: &protocol.SecurityConfig{ 1520 Type: protocol.SecurityType_AES128_GCM, 1521 }, 1522 TestsEnabled: "AuthenticatedLength|NoTerminationSignal", 1523 }), 1524 }, 1525 }, 1526 }, 1527 }, 1528 }), 1529 }, 1530 }, 1531 } 1532 1533 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 1534 if err != nil { 1535 t.Fatal("Failed to initialize all servers: ", err.Error()) 1536 } 1537 defer CloseAllServers(servers) 1538 1539 var errg errgroup.Group 1540 for i := 0; i < 10; i++ { 1541 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40)) 1542 } 1543 1544 if err := errg.Wait(); err != nil { 1545 t.Error(err) 1546 } 1547 }