(rawConn net.Conn, isHTTP bool, isTLS bool, isInAllowList bool)
| 53 | } |
| 54 | |
| 55 | func NewClientConn(rawConn net.Conn, isHTTP bool, isTLS bool, isInAllowList bool) net.Conn { |
| 56 | // 是否为环路 |
| 57 | var remoteAddr = rawConn.RemoteAddr().String() |
| 58 | |
| 59 | var conn = &ClientConn{ |
| 60 | BaseClientConn: BaseClientConn{rawConn: rawConn}, |
| 61 | isTLS: isTLS, |
| 62 | isHTTP: isHTTP, |
| 63 | isLO: strings.HasPrefix(remoteAddr, "127.0.0.1:") || strings.HasPrefix(remoteAddr, "[::1]:"), |
| 64 | isNoStat: connutils.IsNoStatConn(remoteAddr), |
| 65 | isInAllowList: isInAllowList, |
| 66 | createdAt: fasttime.Now().Unix(), |
| 67 | } |
| 68 | |
| 69 | if existsLnNodeIP(conn.RawIP()) { |
| 70 | conn.SetIsPersistent(true) |
| 71 | } |
| 72 | |
| 73 | // 超时等设置 |
| 74 | var globalServerConfig = sharedNodeConfig.GlobalServerConfig |
| 75 | if globalServerConfig != nil { |
| 76 | var performanceConfig = globalServerConfig.Performance |
| 77 | conn.isDebugging = performanceConfig.Debug |
| 78 | conn.autoReadTimeout = performanceConfig.AutoReadTimeout |
| 79 | conn.autoWriteTimeout = performanceConfig.AutoWriteTimeout |
| 80 | } |
| 81 | |
| 82 | if isHTTP { |
| 83 | // TODO 可以在配置中设置此值 |
| 84 | _ = conn.SetLinger(nodeconfigs.DefaultTCPLinger) |
| 85 | } |
| 86 | |
| 87 | // 加入到Map |
| 88 | conns.SharedMap.Add(conn) |
| 89 | |
| 90 | return conn |
| 91 | } |
| 92 | |
| 93 | func (this *ClientConn) Read(b []byte) (n int, err error) { |
| 94 | if this.isDebugging { |
no test coverage detected