{"id":10814,"date":"2023-11-29T09:35:21","date_gmt":"2023-11-29T01:35:21","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=10814"},"modified":"2023-11-29T09:56:49","modified_gmt":"2023-11-29T01:56:49","slug":"frp%e8%87%aa%e5%ae%9a%e4%b9%89%e9%85%8d%e7%bd%ae%e9%a1%b9","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=10814","title":{"rendered":"frp\u81ea\u5b9a\u4e49\u914d\u7f6e\u9879"},"content":{"rendered":"<h4>1.\u6dfb\u52a0\u81ea\u5b9a\u4e49\u914d\u7f6e\u9879<\/h4>\n<p>1\uff09\u5728frps\/root.go\u7b2c64\u884c\u6dfb\u52a0\u53d8\u91cf<br \/>\n<code>maxProxyPadCounts    int64<\/code><br \/>\n2\uff09\u5728frps\/root.go-&gt;init\u65b9\u6cd5\u7b2c96\u884c\u6307\u5b9a\u53d8\u91cf\u7f3a\u7701\u503c<br \/>\n<code>rootCmd.PersistentFlags().Int64VarP(&maxProxyPadCounts, \"max_proxy_pad_counts\", \"\", 10, \"max proxy pad counts\") <\/code><br \/>\n3\uff09\u5728frps\/root.go-&gt;parseServerCommonCfgFromCmd\u65b9\u6cd5\u7b2c181\u884c\u5c06\u7f3a\u7701\u503c\u8d4b\u503c\u7ed9cfg<br \/>\n<code>cfg.MaxProxyPadCounts = maxProxyPadCounts<\/code><\/p>\n<p>\u7136\u540e\u5728frps.ini\u914d\u7f6e<code>max_proxy_pad_counts<\/code>\u5b57\u6bb5\u5c31\u80fd\u6307\u5b9a\u4ee3\u7406\u7684\u4e91\u673a\u4e2a\u6570<\/p>\n<h4>2.\u4fee\u6539tcp\u8fde\u63a5\u5904\u7406\u4f4d\u7f6e\u6e90\u7801\uff0c\u6839\u636e\u81ea\u5b9a\u4e49\u5b57\u6bb5\u9650\u5236\u4ee3\u7406\u4e91\u673a\u4e2a\u6570\u3002<\/h4>\n<p>1\uff09\u4fee\u6539server\/proxy\/proxy.go\uff0c\u5728tcp\u8fde\u63a5\u7684\u5730\u65b9+1<\/p>\n<pre><code class=\"language-go\">var tcp_count = 0\n\n\/\/ startCommonTCPListenersHandler start a goroutine handler for each listener.\nfunc (pxy *BaseProxy) startCommonTCPListenersHandler() {\n        tcp_count = 0\n        xl := xlog.FromContextSafe(pxy.ctx)\n        for _, listener := range pxy.listeners {\n                go func(l net.Listener) {\n                        var tempDelay time.Duration \/\/ how long to sleep on accept failure\n\n                        for {\n                                \/\/ block\n                                \/\/ if listener is closed, err returned\n                                c, err := l.Accept()\n                                if err != nil {\n                                        if err, ok := err.(interface{ Temporary() bool }); ok &amp;&amp; err.Temporary() {\n                                                if tempDelay == 0 {\n                                                        tempDelay = 5 * time.Millisecond\n                                                } else {\n                                                        tempDelay *= 2\n                                                }\n                                                if max := 1 * time.Second; tempDelay &gt; max {\n                                                        tempDelay = max\n                                                }\n                                                xl.Info(&quot;met temporary error: %s, sleep for %s ...&quot;, err, tempDelay)\n                                                time.Sleep(tempDelay)\n                                                continue\n                                        }\n\n                                        xl.Warn(&quot;listener is closed: %s&quot;, err)\n                                        return\n                               }\n\n                                xl.Info(&quot;get a user connection [%s]&quot;, c.RemoteAddr().String())\n                                if pxy.name == &quot;tcp_remote&quot; {\n                                        tcp_count++\n                                }\n                                log.Info(&quot;proxy name:%s&quot;, pxy.name)\n                                log.Info(&quot;max proxy pad counts:%d&quot;, pxy.serverCfg.MaxProxyPadCounts)\n                                log.Info(&quot;cur tcp_remote counts:%d&quot;, tcp_count)\n                                go pxy.handleUserTCPConnection(c)\n                        }\n                }(listener)\n        }\n}\n<\/code><\/pre>\n<p>2\uff09\u4fee\u6539server\/proxy\/proxy.go\uff0c\u8d85\u9650\u5219-1\u5e76\u4e3b\u52a8\u65ad\u5f00\u8fde\u63a5\u3002<\/p>\n<pre><code class=\"language-go\">func closeUsrConn(pxy *BaseProxy, userConn net.Conn) {\n        xl := xlog.FromContextSafe(pxy.Context())\n        xl.Info(&quot;closeUsrConn&quot;)\n        tcp_count--\n        userConn.Close()\n}\n\n\/\/ HandleUserTCPConnection is used for incoming user TCP connections.\nfunc (pxy *BaseProxy) handleUserTCPConnection(userConn net.Conn) {\n        xl := xlog.FromContextSafe(pxy.Context())\n        defer closeUsrConn(pxy, userConn)\n        if pxy.name == &quot;tcp_remote&quot; {\n                if tcp_count &gt; int(pxy.serverCfg.MaxProxyPadCounts) {\n                        xl.Warn(&quot;tcp connect full,cur is:&quot;, tcp_count)\n                        return\n                }\n        }\n\n        serverCfg := pxy.serverCfg\n        cfg := pxy.pxyConf.GetBaseConfig()\n        \/\/ server plugin hook\n        rc := pxy.GetResourceController()\n        content := &amp;plugin.NewUserConnContent{\n                User:       pxy.GetUserInfo(),\n                ProxyName:  pxy.GetName(),\n                ProxyType:  cfg.ProxyType,\n                RemoteAddr: userConn.RemoteAddr().String(),\n        }\n        _, err := rc.PluginManager.NewUserConn(content)\n...\n}\n<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"10814\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>1.\u6dfb\u52a0\u81ea\u5b9a\u4e49\u914d\u7f6e\u9879 1\uff09\u5728frps\/root.go\u7b2c64\u884c\u6dfb\u52a0\u53d8\u91cf maxProxyPadCoun [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[856],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/10814"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10814"}],"version-history":[{"count":3,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/10814\/revisions"}],"predecessor-version":[{"id":10817,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/10814\/revisions\/10817"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10814"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}