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