MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Read

Method Read

internal/nodes/client_conn.go:93–152  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

91}
92
93func (this *ClientConn) Read(b []byte) (n int, err error) {
94 if this.isDebugging {
95 this.lastReadAt = fasttime.Now().Unix()
96
97 defer func() {
98 if err != nil {
99 this.lastErr = fmt.Errorf("read error: %w", err)
100 } else {
101 this.lastErr = nil
102 }
103 }()
104 }
105
106 // 环路直接读取
107 if this.isLO {
108 n, err = this.rawConn.Read(b)
109 if n > 0 {
110 atomic.AddUint64(&teaconst.InTrafficBytes, uint64(n))
111 }
112 return
113 }
114
115 // 设置读超时时间
116 if this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout {
117 this.setHTTPReadTimeout()
118 }
119
120 // 开始读取
121 n, err = this.rawConn.Read(b)
122 if n > 0 {
123 atomic.AddUint64(&teaconst.InTrafficBytes, uint64(n))
124 this.hasRead = true
125 }
126
127 // 检测是否为超时错误
128 var isTimeout = err != nil && os.IsTimeout(err)
129 var isHandshakeError = isTimeout && !this.hasRead
130
131 if err != nil {
132 _ = this.SetLinger(nodeconfigs.DefaultTCPLinger)
133 }
134
135 // 忽略白名单和局域网
136 if !this.isPersistent && this.isHTTP && !this.isInAllowList && !utils.IsLocalIP(this.RawIP()) {
137 // SYN Flood检测
138 if this.serverId == 0 || !this.hasResetSYNFlood {
139 var synFloodConfig = sharedNodeConfig.SYNFloodConfig()
140 if synFloodConfig != nil && synFloodConfig.IsOn {
141 if isHandshakeError {
142 this.increaseSYNFlood(synFloodConfig)
143 } else if err == nil && !this.hasResetSYNFlood {
144 this.hasResetSYNFlood = true
145 this.resetSYNFlood()
146 }
147 }
148 }
149 }
150

Callers

nothing calls this directly

Calls 10

setHTTPReadTimeoutMethod · 0.95
increaseSYNFloodMethod · 0.95
resetSYNFloodMethod · 0.95
NowFunction · 0.92
IsLocalIPFunction · 0.92
UnixMethod · 0.80
ErrorfMethod · 0.80
RawIPMethod · 0.80
ReadMethod · 0.65
SetLingerMethod · 0.65

Tested by

no test coverage detected