vmess_test.go 39 KB

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