mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 10:40:26 +08:00
优化Ln连接性能
This commit is contained in:
@@ -32,6 +32,7 @@ type ClientConn struct {
|
|||||||
|
|
||||||
isTLS bool
|
isTLS bool
|
||||||
isHTTP bool
|
isHTTP bool
|
||||||
|
isLn bool // 是否为Ln连接
|
||||||
hasRead bool
|
hasRead bool
|
||||||
|
|
||||||
isLO bool // 是否为环路
|
isLO bool // 是否为环路
|
||||||
@@ -61,11 +62,14 @@ func NewClientConn(rawConn net.Conn, isHTTP bool, isTLS bool, isInAllowList bool
|
|||||||
isTLS: isTLS,
|
isTLS: isTLS,
|
||||||
isHTTP: isHTTP,
|
isHTTP: isHTTP,
|
||||||
isLO: strings.HasPrefix(remoteAddr, "127.0.0.1:") || strings.HasPrefix(remoteAddr, "[::1]:"),
|
isLO: strings.HasPrefix(remoteAddr, "127.0.0.1:") || strings.HasPrefix(remoteAddr, "[::1]:"),
|
||||||
isNoStat: connutils.IsNoStatConn(rawConn.RemoteAddr().String()),
|
isNoStat: connutils.IsNoStatConn(remoteAddr),
|
||||||
isInAllowList: isInAllowList,
|
isInAllowList: isInAllowList,
|
||||||
createdAt: fasttime.Now().Unix(),
|
createdAt: fasttime.Now().Unix(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn.isLn = existsLnNodeIP(conn.RawIP())
|
||||||
|
|
||||||
|
// 超时等设置
|
||||||
var globalServerConfig = sharedNodeConfig.GlobalServerConfig
|
var globalServerConfig = sharedNodeConfig.GlobalServerConfig
|
||||||
if globalServerConfig != nil {
|
if globalServerConfig != nil {
|
||||||
var performanceConfig = globalServerConfig.Performance
|
var performanceConfig = globalServerConfig.Performance
|
||||||
@@ -108,7 +112,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置读超时时间
|
// 设置读超时时间
|
||||||
if this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout {
|
if !this.isLn && this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout {
|
||||||
this.setHTTPReadTimeout()
|
this.setHTTPReadTimeout()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +133,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 忽略白名单和局域网
|
// 忽略白名单和局域网
|
||||||
if this.isHTTP && !this.isInAllowList && !utils.IsLocalIP(this.RawIP()) {
|
if !this.isLn && this.isHTTP && !this.isInAllowList && !utils.IsLocalIP(this.RawIP()) {
|
||||||
// SYN Flood检测
|
// SYN Flood检测
|
||||||
if this.serverId == 0 || !this.hasResetSYNFlood {
|
if this.serverId == 0 || !this.hasResetSYNFlood {
|
||||||
var synFloodConfig = sharedNodeConfig.SYNFloodConfig()
|
var synFloodConfig = sharedNodeConfig.SYNFloodConfig()
|
||||||
@@ -165,7 +169,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置写超时时间
|
// 设置写超时时间
|
||||||
if this.autoWriteTimeout {
|
if !this.isLn && this.autoWriteTimeout {
|
||||||
// TODO L2 -> L1 写入时不限制时间
|
// TODO L2 -> L1 写入时不限制时间
|
||||||
var timeoutSeconds = len(b) / 1024
|
var timeoutSeconds = len(b) / 1024
|
||||||
if timeoutSeconds < 3 {
|
if timeoutSeconds < 3 {
|
||||||
@@ -175,7 +179,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 延长读超时时间
|
// 延长读超时时间
|
||||||
if this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
if !this.isLn && this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
||||||
this.setHTTPReadTimeout()
|
this.setHTTPReadTimeout()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +246,7 @@ func (this *ClientConn) SetDeadline(t time.Time) error {
|
|||||||
|
|
||||||
func (this *ClientConn) SetReadDeadline(t time.Time) error {
|
func (this *ClientConn) SetReadDeadline(t time.Time) error {
|
||||||
// 如果开启了HTTP自动读超时选项,则自动控制超时时间
|
// 如果开启了HTTP自动读超时选项,则自动控制超时时间
|
||||||
if this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
if !this.isLn && this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
||||||
this.isShortReading = false
|
this.isShortReading = false
|
||||||
|
|
||||||
var unixTime = t.Unix()
|
var unixTime = t.Unix()
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ const (
|
|||||||
LNExpiresHeader = "X-Edge-Ln-Expires"
|
LNExpiresHeader = "X-Edge-Ln-Expires"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func existsLnNodeIP(nodeIP string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (this *HTTPRequest) checkLnRequest() bool {
|
func (this *HTTPRequest) checkLnRequest() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user