XTCP

了解 frp XTCP 类型的代理。

XTCP 的配置方式和 STCP 很类似。但是会采用 P2P 的方式进行打洞穿透,如果成功,后续的流量将不会经过 frps,而是直接通信,不再受到 frps 所在服务器的带宽限制。

由于打洞成功率取决于所处网络的 NAT 类型,所以 XTCP 的可用性和稳定性无法保证。在需要可靠连接的情况下,建议使用 STCP 替代。

当 visitor 配置了 keepTunnelOpen = true 时,frpc 会定期检测隧道是否打开,如果没有,则会尝试打洞建立隧道,这样可以始终保持隧道打开,在需要连接对端服务时,可以避免延迟。

默认情况下,visitor 会在接收到用户连接后尝试打洞,如果打洞失败,可以尝试多次建立连接,程序会尝试其他的打洞策略,有可能在多次重试后成功打洞。一旦打洞成功,后续新增连接不必重复打洞,而是可以复用隧道。

Fallback 机制

可以通过配置 fallback 到 stcp visitor 实现在打洞失败时,回退到 stcp 建立连接。

示例配置:

[[visitors]]
    name = "stcp-visitor"
    type = "stcp"
    serverName = "stcp-test"
    secretKey = "abc"
    bindPort = -1
    
    [[visitors]]
    name = "xtcp-visitor"
    type = "xtcp"
    serverName = "xtcp-test"
    secretKey = "abc"
    bindAddr = "127.0.0.1"
    bindPort = 9002
    fallbackTo = "stcp-visitor"
    fallbackTimeoutMs = 200
    

当连接 127.0.0.1:9002 超过 200ms p2p 打洞还未成功的话,会回退到使用 stcp-visitor 建立连接。fallback 后,之前触发的打洞操作仍然会继续,一般来说打洞完成需要的耗时会比较长。

如果打洞成功,下次建立新的连接时,将不需要再次打洞,会很快完成连接建立,不会触发 fallback。

需要注意根据访问端和被访问端的延迟情况来合理设置超时时间,以避免超时时间太短,即使打洞成功连接也来不及建立,而一直触发 fallback。

stcp-visitor 的 bindPort 设置为 -1 表示不需要监听物理端口,只接受 fallback 的连接即可。

最后修改 November 15, 2023: fix 404 (#71) (626ce4d)

XTCP

Understand agents of type frpXTCP.

The configuration method of XTCP is very similar to STCP. But it will adopt P2P If successful, the subsequent traffic will not pass through the method of drilling holes for penetration FRPS, instead of direct communication, is no longer limited by the bandwidth of the server where FRPS is located.

Due to the fact that the success rate of drilling depends on the NAT type of the network, XTCP The availability and stability of cannot be guaranteed. When reliable connection is required, it is recommended to use STCP Substitution.

When the visitor is configured WhenkeepTunnelOpen=true, frpc We will regularly check if the tunnel is open. If not, we will try to create a tunnel by drilling a hole, which can always keep the tunnel open and avoid delays when connecting to the opposite service.

By default, the visitor After receiving the user's connection, the program will attempt to make a hole. If the hole fails, multiple attempts can be made to establish the connection. The program will try other hole making strategies, and it is possible to successfully make a hole after multiple retries. Once the hole is successfully drilled, subsequent new connections do not need to be drilled repeatedly, but can reuse the tunnel.

Fallback mechanism

Can be accessed through Configuration fallback to stcp visitor Implement a rollback to STCP to establish a connection when drilling fails.

ExampleConfiguration:

[[visitors]]
    name = "stcp-visitor"
    type = "stcp"
    serverName = "stcp-test"
    secretKey = "abc"
    bindPort = -1
    
    [[visitors]]
    name = "xtcp-visitor"
    type = "xtcp"
    serverName = "xtcp-test"
    secretKey = "abc"
    bindAddr = "127.0.0.1"
    bindPort = 9002
    fallbackTo = "stcp-visitor"
    fallbackTimeoutMs = 200
    

When the connection127.0.0.1:9002exceeds 200ms P2P If the drilling is not successful yet, it will fall back to Use stcp visitor to establish a connection. Fallback Afterwards, the previously triggered hole drilling operation will still continue, and generally speaking, the time required to complete the hole drilling will be relatively long.

If the hole is successfully drilled, the next time a new connection is established, there will be no need to drill a hole again, and the connection will be established quickly without triggering it Fallback.

It is necessary to pay attention to setting the timeout time reasonably based on the delay situation of the accessing and being accessed ends, in order to avoid the timeout time being too short, even if the hole is successfully drilled and the connection is not established in time, and it will be triggered continuously Fallback.

Set thebindPortof stcp visitor to -1 Indicates that there is no need to listen to physical ports, only accept connections for fallback.

Last modified November 15, 2023: fix 404 (#71) (626ce4d)