proxy.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. // Copyright 2017 fatedier, fatedier@gmail.com
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package server
  15. import (
  16. "context"
  17. "fmt"
  18. "io"
  19. "net"
  20. "strings"
  21. "sync"
  22. "time"
  23. "github.com/fatedier/frp/models/config"
  24. "github.com/fatedier/frp/models/msg"
  25. "github.com/fatedier/frp/models/proto/udp"
  26. "github.com/fatedier/frp/utils/errors"
  27. frpIo "github.com/fatedier/frp/utils/io"
  28. "github.com/fatedier/frp/utils/log"
  29. frpNet "github.com/fatedier/frp/utils/net"
  30. "github.com/fatedier/frp/utils/util"
  31. "github.com/fatedier/frp/utils/vhost"
  32. )
  33. type Proxy interface {
  34. Run() (remoteAddr string, err error)
  35. GetControl() *Control
  36. GetName() string
  37. GetConf() config.ProxyConf
  38. GetWorkConnFromPool() (workConn frpNet.Conn, err error)
  39. Close()
  40. log.Logger
  41. }
  42. type BaseProxy struct {
  43. name string
  44. ctl *Control
  45. listeners []frpNet.Listener
  46. mu sync.RWMutex
  47. log.Logger
  48. }
  49. func (pxy *BaseProxy) GetName() string {
  50. return pxy.name
  51. }
  52. func (pxy *BaseProxy) GetControl() *Control {
  53. return pxy.ctl
  54. }
  55. func (pxy *BaseProxy) Close() {
  56. pxy.Info("proxy closing")
  57. for _, l := range pxy.listeners {
  58. l.Close()
  59. }
  60. }
  61. func (pxy *BaseProxy) GetWorkConnFromPool() (workConn frpNet.Conn, err error) {
  62. ctl := pxy.GetControl()
  63. // try all connections from the pool
  64. for i := 0; i < ctl.poolCount+1; i++ {
  65. if workConn, err = ctl.GetWorkConn(); err != nil {
  66. pxy.Warn("failed to get work connection: %v", err)
  67. return
  68. }
  69. pxy.Info("get a new work connection: [%s]", workConn.RemoteAddr().String())
  70. workConn.AddLogPrefix(pxy.GetName())
  71. err := msg.WriteMsg(workConn, &msg.StartWorkConn{
  72. ProxyName: pxy.GetName(),
  73. })
  74. if err != nil {
  75. workConn.Warn("failed to send message to work connection from pool: %v, times: %d", err, i)
  76. workConn.Close()
  77. } else {
  78. break
  79. }
  80. }
  81. if err != nil {
  82. pxy.Error("try to get work connection failed in the end")
  83. return
  84. }
  85. return
  86. }
  87. // startListenHandler start a goroutine handler for each listener.
  88. // p: p will just be passed to handler(Proxy, frpNet.Conn).
  89. // handler: each proxy type can set different handler function to deal with connections accepted from listeners.
  90. func (pxy *BaseProxy) startListenHandler(p Proxy, handler func(Proxy, frpNet.Conn)) {
  91. for _, listener := range pxy.listeners {
  92. go func(l frpNet.Listener) {
  93. for {
  94. // block
  95. // if listener is closed, err returned
  96. c, err := l.Accept()
  97. if err != nil {
  98. pxy.Info("listener is closed")
  99. return
  100. }
  101. pxy.Debug("get a user connection [%s]", c.RemoteAddr().String())
  102. go handler(p, c)
  103. }
  104. }(listener)
  105. }
  106. }
  107. func NewProxy(ctl *Control, pxyConf config.ProxyConf) (pxy Proxy, err error) {
  108. basePxy := BaseProxy{
  109. name: pxyConf.GetName(),
  110. ctl: ctl,
  111. listeners: make([]frpNet.Listener, 0),
  112. Logger: log.NewPrefixLogger(ctl.runId),
  113. }
  114. switch cfg := pxyConf.(type) {
  115. case *config.TcpProxyConf:
  116. pxy = &TcpProxy{
  117. BaseProxy: basePxy,
  118. cfg: cfg,
  119. }
  120. case *config.HttpProxyConf:
  121. pxy = &HttpProxy{
  122. BaseProxy: basePxy,
  123. cfg: cfg,
  124. }
  125. case *config.HttpsProxyConf:
  126. pxy = &HttpsProxy{
  127. BaseProxy: basePxy,
  128. cfg: cfg,
  129. }
  130. case *config.UdpProxyConf:
  131. pxy = &UdpProxy{
  132. BaseProxy: basePxy,
  133. cfg: cfg,
  134. }
  135. case *config.StcpProxyConf:
  136. pxy = &StcpProxy{
  137. BaseProxy: basePxy,
  138. cfg: cfg,
  139. }
  140. case *config.XtcpProxyConf:
  141. pxy = &XtcpProxy{
  142. BaseProxy: basePxy,
  143. cfg: cfg,
  144. }
  145. default:
  146. return pxy, fmt.Errorf("proxy type not support")
  147. }
  148. pxy.AddLogPrefix(pxy.GetName())
  149. return
  150. }
  151. type TcpProxy struct {
  152. BaseProxy
  153. cfg *config.TcpProxyConf
  154. realPort int
  155. }
  156. func (pxy *TcpProxy) Run() (remoteAddr string, err error) {
  157. pxy.realPort, err = pxy.ctl.svr.tcpPortManager.Acquire(pxy.name, pxy.cfg.RemotePort)
  158. if err != nil {
  159. return
  160. }
  161. defer func() {
  162. if err != nil {
  163. pxy.ctl.svr.tcpPortManager.Release(pxy.realPort)
  164. }
  165. }()
  166. remoteAddr = fmt.Sprintf(":%d", pxy.realPort)
  167. pxy.cfg.RemotePort = pxy.realPort
  168. listener, errRet := frpNet.ListenTcp(config.ServerCommonCfg.ProxyBindAddr, pxy.realPort)
  169. if errRet != nil {
  170. err = errRet
  171. return
  172. }
  173. listener.AddLogPrefix(pxy.name)
  174. pxy.listeners = append(pxy.listeners, listener)
  175. pxy.Info("tcp proxy listen port [%d]", pxy.cfg.RemotePort)
  176. pxy.startListenHandler(pxy, HandleUserTcpConnection)
  177. return
  178. }
  179. func (pxy *TcpProxy) GetConf() config.ProxyConf {
  180. return pxy.cfg
  181. }
  182. func (pxy *TcpProxy) Close() {
  183. pxy.BaseProxy.Close()
  184. pxy.ctl.svr.tcpPortManager.Release(pxy.realPort)
  185. }
  186. type HttpProxy struct {
  187. BaseProxy
  188. cfg *config.HttpProxyConf
  189. closeFuncs []func()
  190. }
  191. func (pxy *HttpProxy) Run() (remoteAddr string, err error) {
  192. routeConfig := vhost.VhostRouteConfig{
  193. RewriteHost: pxy.cfg.HostHeaderRewrite,
  194. Username: pxy.cfg.HttpUser,
  195. Password: pxy.cfg.HttpPwd,
  196. CreateConnFn: pxy.GetRealConn,
  197. }
  198. locations := pxy.cfg.Locations
  199. if len(locations) == 0 {
  200. locations = []string{""}
  201. }
  202. addrs := make([]string, 0)
  203. for _, domain := range pxy.cfg.CustomDomains {
  204. routeConfig.Domain = domain
  205. for _, location := range locations {
  206. routeConfig.Location = location
  207. err = pxy.ctl.svr.httpReverseProxy.Register(routeConfig)
  208. if err != nil {
  209. return
  210. }
  211. tmpDomain := routeConfig.Domain
  212. tmpLocation := routeConfig.Location
  213. addrs = append(addrs, util.CanonicalAddr(tmpDomain, int(config.ServerCommonCfg.VhostHttpPort)))
  214. pxy.closeFuncs = append(pxy.closeFuncs, func() {
  215. pxy.ctl.svr.httpReverseProxy.UnRegister(tmpDomain, tmpLocation)
  216. })
  217. pxy.Info("http proxy listen for host [%s] location [%s]", routeConfig.Domain, routeConfig.Location)
  218. }
  219. }
  220. if pxy.cfg.SubDomain != "" {
  221. routeConfig.Domain = pxy.cfg.SubDomain + "." + config.ServerCommonCfg.SubDomainHost
  222. for _, location := range locations {
  223. routeConfig.Location = location
  224. err = pxy.ctl.svr.httpReverseProxy.Register(routeConfig)
  225. if err != nil {
  226. return
  227. }
  228. tmpDomain := routeConfig.Domain
  229. tmpLocation := routeConfig.Location
  230. addrs = append(addrs, util.CanonicalAddr(tmpDomain, int(config.ServerCommonCfg.VhostHttpPort)))
  231. pxy.closeFuncs = append(pxy.closeFuncs, func() {
  232. pxy.ctl.svr.httpReverseProxy.UnRegister(tmpDomain, tmpLocation)
  233. })
  234. pxy.Info("http proxy listen for host [%s] location [%s]", routeConfig.Domain, routeConfig.Location)
  235. }
  236. }
  237. remoteAddr = strings.Join(addrs, ",")
  238. return
  239. }
  240. func (pxy *HttpProxy) GetConf() config.ProxyConf {
  241. return pxy.cfg
  242. }
  243. func (pxy *HttpProxy) GetRealConn() (workConn frpNet.Conn, err error) {
  244. tmpConn, errRet := pxy.GetWorkConnFromPool()
  245. if errRet != nil {
  246. err = errRet
  247. return
  248. }
  249. var rwc io.ReadWriteCloser = tmpConn
  250. if pxy.cfg.UseEncryption {
  251. rwc, err = frpIo.WithEncryption(rwc, []byte(config.ServerCommonCfg.PrivilegeToken))
  252. if err != nil {
  253. pxy.Error("create encryption stream error: %v", err)
  254. return
  255. }
  256. }
  257. if pxy.cfg.UseCompression {
  258. rwc = frpIo.WithCompression(rwc)
  259. }
  260. workConn = frpNet.WrapReadWriteCloserToConn(rwc, tmpConn)
  261. workConn = frpNet.WrapStatsConn(workConn, pxy.updateStatsAfterClosedConn)
  262. StatsOpenConnection(pxy.GetName())
  263. return
  264. }
  265. func (pxy *HttpProxy) updateStatsAfterClosedConn(totalRead, totalWrite int64) {
  266. name := pxy.GetName()
  267. StatsCloseConnection(name)
  268. StatsAddTrafficIn(name, totalWrite)
  269. StatsAddTrafficOut(name, totalRead)
  270. }
  271. func (pxy *HttpProxy) Close() {
  272. pxy.BaseProxy.Close()
  273. for _, closeFn := range pxy.closeFuncs {
  274. closeFn()
  275. }
  276. }
  277. type HttpsProxy struct {
  278. BaseProxy
  279. cfg *config.HttpsProxyConf
  280. }
  281. func (pxy *HttpsProxy) Run() (remoteAddr string, err error) {
  282. routeConfig := &vhost.VhostRouteConfig{}
  283. addrs := make([]string, 0)
  284. for _, domain := range pxy.cfg.CustomDomains {
  285. routeConfig.Domain = domain
  286. l, errRet := pxy.ctl.svr.VhostHttpsMuxer.Listen(routeConfig)
  287. if errRet != nil {
  288. err = errRet
  289. return
  290. }
  291. l.AddLogPrefix(pxy.name)
  292. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  293. pxy.listeners = append(pxy.listeners, l)
  294. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, int(config.ServerCommonCfg.VhostHttpsPort)))
  295. }
  296. if pxy.cfg.SubDomain != "" {
  297. routeConfig.Domain = pxy.cfg.SubDomain + "." + config.ServerCommonCfg.SubDomainHost
  298. l, errRet := pxy.ctl.svr.VhostHttpsMuxer.Listen(routeConfig)
  299. if errRet != nil {
  300. err = errRet
  301. return
  302. }
  303. l.AddLogPrefix(pxy.name)
  304. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  305. pxy.listeners = append(pxy.listeners, l)
  306. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, int(config.ServerCommonCfg.VhostHttpsPort)))
  307. }
  308. pxy.startListenHandler(pxy, HandleUserTcpConnection)
  309. remoteAddr = strings.Join(addrs, ",")
  310. return
  311. }
  312. func (pxy *HttpsProxy) GetConf() config.ProxyConf {
  313. return pxy.cfg
  314. }
  315. func (pxy *HttpsProxy) Close() {
  316. pxy.BaseProxy.Close()
  317. }
  318. type StcpProxy struct {
  319. BaseProxy
  320. cfg *config.StcpProxyConf
  321. }
  322. func (pxy *StcpProxy) Run() (remoteAddr string, err error) {
  323. listener, errRet := pxy.ctl.svr.visitorManager.Listen(pxy.GetName(), pxy.cfg.Sk)
  324. if errRet != nil {
  325. err = errRet
  326. return
  327. }
  328. listener.AddLogPrefix(pxy.name)
  329. pxy.listeners = append(pxy.listeners, listener)
  330. pxy.Info("stcp proxy custom listen success")
  331. pxy.startListenHandler(pxy, HandleUserTcpConnection)
  332. return
  333. }
  334. func (pxy *StcpProxy) GetConf() config.ProxyConf {
  335. return pxy.cfg
  336. }
  337. func (pxy *StcpProxy) Close() {
  338. pxy.BaseProxy.Close()
  339. pxy.ctl.svr.visitorManager.CloseListener(pxy.GetName())
  340. }
  341. type XtcpProxy struct {
  342. BaseProxy
  343. cfg *config.XtcpProxyConf
  344. closeCh chan struct{}
  345. }
  346. func (pxy *XtcpProxy) Run() (remoteAddr string, err error) {
  347. if pxy.ctl.svr.natHoleController == nil {
  348. pxy.Error("udp port for xtcp is not specified.")
  349. err = fmt.Errorf("xtcp is not supported in frps")
  350. return
  351. }
  352. sidCh := pxy.ctl.svr.natHoleController.ListenClient(pxy.GetName(), pxy.cfg.Sk)
  353. go func() {
  354. for {
  355. select {
  356. case <-pxy.closeCh:
  357. break
  358. case sid := <-sidCh:
  359. workConn, errRet := pxy.GetWorkConnFromPool()
  360. if errRet != nil {
  361. continue
  362. }
  363. m := &msg.NatHoleSid{
  364. Sid: sid,
  365. }
  366. errRet = msg.WriteMsg(workConn, m)
  367. if errRet != nil {
  368. pxy.Warn("write nat hole sid package error, %v", errRet)
  369. }
  370. }
  371. }
  372. }()
  373. return
  374. }
  375. func (pxy *XtcpProxy) GetConf() config.ProxyConf {
  376. return pxy.cfg
  377. }
  378. func (pxy *XtcpProxy) Close() {
  379. pxy.BaseProxy.Close()
  380. pxy.ctl.svr.natHoleController.CloseClient(pxy.GetName())
  381. errors.PanicToError(func() {
  382. close(pxy.closeCh)
  383. })
  384. }
  385. type UdpProxy struct {
  386. BaseProxy
  387. cfg *config.UdpProxyConf
  388. realPort int
  389. // udpConn is the listener of udp packages
  390. udpConn *net.UDPConn
  391. // there are always only one workConn at the same time
  392. // get another one if it closed
  393. workConn net.Conn
  394. // sendCh is used for sending packages to workConn
  395. sendCh chan *msg.UdpPacket
  396. // readCh is used for reading packages from workConn
  397. readCh chan *msg.UdpPacket
  398. // checkCloseCh is used for watching if workConn is closed
  399. checkCloseCh chan int
  400. isClosed bool
  401. }
  402. func (pxy *UdpProxy) Run() (remoteAddr string, err error) {
  403. pxy.realPort, err = pxy.ctl.svr.udpPortManager.Acquire(pxy.name, pxy.cfg.RemotePort)
  404. if err != nil {
  405. return
  406. }
  407. defer func() {
  408. if err != nil {
  409. pxy.ctl.svr.udpPortManager.Release(pxy.realPort)
  410. }
  411. }()
  412. remoteAddr = fmt.Sprintf(":%d", pxy.realPort)
  413. pxy.cfg.RemotePort = pxy.realPort
  414. addr, errRet := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", config.ServerCommonCfg.ProxyBindAddr, pxy.realPort))
  415. if errRet != nil {
  416. err = errRet
  417. return
  418. }
  419. udpConn, errRet := net.ListenUDP("udp", addr)
  420. if errRet != nil {
  421. err = errRet
  422. pxy.Warn("listen udp port error: %v", err)
  423. return
  424. }
  425. pxy.Info("udp proxy listen port [%d]", pxy.cfg.RemotePort)
  426. pxy.udpConn = udpConn
  427. pxy.sendCh = make(chan *msg.UdpPacket, 1024)
  428. pxy.readCh = make(chan *msg.UdpPacket, 1024)
  429. pxy.checkCloseCh = make(chan int)
  430. // read message from workConn, if it returns any error, notify proxy to start a new workConn
  431. workConnReaderFn := func(conn net.Conn) {
  432. for {
  433. var (
  434. rawMsg msg.Message
  435. errRet error
  436. )
  437. pxy.Trace("loop waiting message from udp workConn")
  438. // client will send heartbeat in workConn for keeping alive
  439. conn.SetReadDeadline(time.Now().Add(time.Duration(60) * time.Second))
  440. if rawMsg, errRet = msg.ReadMsg(conn); errRet != nil {
  441. pxy.Warn("read from workConn for udp error: %v", errRet)
  442. conn.Close()
  443. // notify proxy to start a new work connection
  444. // ignore error here, it means the proxy is closed
  445. errors.PanicToError(func() {
  446. pxy.checkCloseCh <- 1
  447. })
  448. return
  449. }
  450. conn.SetReadDeadline(time.Time{})
  451. switch m := rawMsg.(type) {
  452. case *msg.Ping:
  453. pxy.Trace("udp work conn get ping message")
  454. continue
  455. case *msg.UdpPacket:
  456. if errRet := errors.PanicToError(func() {
  457. pxy.Trace("get udp message from workConn: %s", m.Content)
  458. pxy.readCh <- m
  459. StatsAddTrafficOut(pxy.GetName(), int64(len(m.Content)))
  460. }); errRet != nil {
  461. conn.Close()
  462. pxy.Info("reader goroutine for udp work connection closed")
  463. return
  464. }
  465. }
  466. }
  467. }
  468. // send message to workConn
  469. workConnSenderFn := func(conn net.Conn, ctx context.Context) {
  470. var errRet error
  471. for {
  472. select {
  473. case udpMsg, ok := <-pxy.sendCh:
  474. if !ok {
  475. pxy.Info("sender goroutine for udp work connection closed")
  476. return
  477. }
  478. if errRet = msg.WriteMsg(conn, udpMsg); errRet != nil {
  479. pxy.Info("sender goroutine for udp work connection closed: %v", errRet)
  480. conn.Close()
  481. return
  482. } else {
  483. pxy.Trace("send message to udp workConn: %s", udpMsg.Content)
  484. StatsAddTrafficIn(pxy.GetName(), int64(len(udpMsg.Content)))
  485. continue
  486. }
  487. case <-ctx.Done():
  488. pxy.Info("sender goroutine for udp work connection closed")
  489. return
  490. }
  491. }
  492. }
  493. go func() {
  494. // Sleep a while for waiting control send the NewProxyResp to client.
  495. time.Sleep(500 * time.Millisecond)
  496. for {
  497. workConn, err := pxy.GetWorkConnFromPool()
  498. if err != nil {
  499. time.Sleep(1 * time.Second)
  500. // check if proxy is closed
  501. select {
  502. case _, ok := <-pxy.checkCloseCh:
  503. if !ok {
  504. return
  505. }
  506. default:
  507. }
  508. continue
  509. }
  510. // close the old workConn and replac it with a new one
  511. if pxy.workConn != nil {
  512. pxy.workConn.Close()
  513. }
  514. pxy.workConn = workConn
  515. ctx, cancel := context.WithCancel(context.Background())
  516. go workConnReaderFn(workConn)
  517. go workConnSenderFn(workConn, ctx)
  518. _, ok := <-pxy.checkCloseCh
  519. cancel()
  520. if !ok {
  521. return
  522. }
  523. }
  524. }()
  525. // Read from user connections and send wrapped udp message to sendCh (forwarded by workConn).
  526. // Client will transfor udp message to local udp service and waiting for response for a while.
  527. // Response will be wrapped to be forwarded by work connection to server.
  528. // Close readCh and sendCh at the end.
  529. go func() {
  530. udp.ForwardUserConn(udpConn, pxy.readCh, pxy.sendCh)
  531. pxy.Close()
  532. }()
  533. return remoteAddr, nil
  534. }
  535. func (pxy *UdpProxy) GetConf() config.ProxyConf {
  536. return pxy.cfg
  537. }
  538. func (pxy *UdpProxy) Close() {
  539. pxy.mu.Lock()
  540. defer pxy.mu.Unlock()
  541. if !pxy.isClosed {
  542. pxy.isClosed = true
  543. pxy.BaseProxy.Close()
  544. if pxy.workConn != nil {
  545. pxy.workConn.Close()
  546. }
  547. pxy.udpConn.Close()
  548. // all channels only closed here
  549. close(pxy.checkCloseCh)
  550. close(pxy.readCh)
  551. close(pxy.sendCh)
  552. }
  553. pxy.ctl.svr.udpPortManager.Release(pxy.realPort)
  554. }
  555. // HandleUserTcpConnection is used for incoming tcp user connections.
  556. // It can be used for tcp, http, https type.
  557. func HandleUserTcpConnection(pxy Proxy, userConn frpNet.Conn) {
  558. defer userConn.Close()
  559. // try all connections from the pool
  560. workConn, err := pxy.GetWorkConnFromPool()
  561. if err != nil {
  562. return
  563. }
  564. defer workConn.Close()
  565. var local io.ReadWriteCloser = workConn
  566. cfg := pxy.GetConf().GetBaseInfo()
  567. if cfg.UseEncryption {
  568. local, err = frpIo.WithEncryption(local, []byte(config.ServerCommonCfg.PrivilegeToken))
  569. if err != nil {
  570. pxy.Error("create encryption stream error: %v", err)
  571. return
  572. }
  573. }
  574. if cfg.UseCompression {
  575. local = frpIo.WithCompression(local)
  576. }
  577. pxy.Debug("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(),
  578. workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String())
  579. StatsOpenConnection(pxy.GetName())
  580. inCount, outCount := frpIo.Join(local, userConn)
  581. StatsCloseConnection(pxy.GetName())
  582. StatsAddTrafficIn(pxy.GetName(), inCount)
  583. StatsAddTrafficOut(pxy.GetName(), outCount)
  584. pxy.Debug("join connections closed")
  585. }