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