mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-05 00:45:12 +08:00
优化代码
This commit is contained in:
@@ -32,7 +32,6 @@ type ClientConn struct {
|
||||
|
||||
isTLS bool
|
||||
isHTTP bool
|
||||
isLn bool // 是否为Ln连接
|
||||
hasRead bool
|
||||
|
||||
isLO bool // 是否为环路
|
||||
@@ -67,7 +66,9 @@ func NewClientConn(rawConn net.Conn, isHTTP bool, isTLS bool, isInAllowList bool
|
||||
createdAt: fasttime.Now().Unix(),
|
||||
}
|
||||
|
||||
conn.isLn = existsLnNodeIP(conn.RawIP())
|
||||
if existsLnNodeIP(conn.RawIP()) {
|
||||
conn.SetIsPersistent(true)
|
||||
}
|
||||
|
||||
// 超时等设置
|
||||
var globalServerConfig = sharedNodeConfig.GlobalServerConfig
|
||||
@@ -112,7 +113,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
// 设置读超时时间
|
||||
if !this.isLn && this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout {
|
||||
if this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout {
|
||||
this.setHTTPReadTimeout()
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
// 忽略白名单和局域网
|
||||
if !this.isLn && this.isHTTP && !this.isInAllowList && !utils.IsLocalIP(this.RawIP()) {
|
||||
if !this.isPersistent && this.isHTTP && !this.isInAllowList && !utils.IsLocalIP(this.RawIP()) {
|
||||
// SYN Flood检测
|
||||
if this.serverId == 0 || !this.hasResetSYNFlood {
|
||||
var synFloodConfig = sharedNodeConfig.SYNFloodConfig()
|
||||
@@ -169,8 +170,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
// 设置写超时时间
|
||||
if !this.isLn && this.autoWriteTimeout {
|
||||
// TODO L2 -> L1 写入时不限制时间
|
||||
if !this.isPersistent && this.autoWriteTimeout {
|
||||
var timeoutSeconds = len(b) / 1024
|
||||
if timeoutSeconds < 3 {
|
||||
timeoutSeconds = 3
|
||||
@@ -179,7 +179,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
// 延长读超时时间
|
||||
if !this.isLn && this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
||||
if this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
||||
this.setHTTPReadTimeout()
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ func (this *ClientConn) SetDeadline(t time.Time) error {
|
||||
|
||||
func (this *ClientConn) SetReadDeadline(t time.Time) error {
|
||||
// 如果开启了HTTP自动读超时选项,则自动控制超时时间
|
||||
if !this.isLn && this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
||||
if this.isHTTP && !this.isPersistent && this.autoReadTimeout {
|
||||
this.isShortReading = false
|
||||
|
||||
var unixTime = t.Unix()
|
||||
|
||||
@@ -480,6 +480,17 @@ func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bo
|
||||
// remote addr
|
||||
if web.RemoteAddr != nil && (web.RemoteAddr.IsPrior || isTop) && web.RemoteAddr.IsOn {
|
||||
this.web.RemoteAddr = web.RemoteAddr
|
||||
|
||||
// check if from proxy
|
||||
if len(this.web.RemoteAddr.Value) > 0 && this.web.RemoteAddr.Value != "${rawRemoteAddr}" {
|
||||
var requestConn = this.RawReq.Context().Value(HTTPConnContextKey)
|
||||
if requestConn != nil {
|
||||
requestClientConn, ok := requestConn.(ClientConnInterface)
|
||||
if ok {
|
||||
requestClientConn.SetIsPersistent(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// charset
|
||||
|
||||
Reference in New Issue
Block a user