| skipped 186 lines |
187 | 187 | | if err != nil { |
188 | 188 | | return err |
189 | 189 | | } |
190 | | - | userIndex := slices.Index(h.authKey, string(clientHello.Auth)) |
191 | | - | if userIndex == -1 { |
192 | | - | err = hysteria.WriteServerHello(controlStream, hysteria.ServerHello{ |
193 | | - | Message: "wrong password", |
194 | | - | }) |
195 | | - | return E.Errors(E.New("wrong password: ", string(clientHello.Auth)), err) |
196 | | - | } |
197 | | - | user := h.authUser[userIndex] |
198 | | - | if user == "" { |
199 | | - | user = F.ToString(userIndex) |
| 190 | + | if len(h.authKey) > 0 { |
| 191 | + | userIndex := slices.Index(h.authKey, string(clientHello.Auth)) |
| 192 | + | if userIndex == -1 { |
| 193 | + | err = hysteria.WriteServerHello(controlStream, hysteria.ServerHello{ |
| 194 | + | Message: "wrong password", |
| 195 | + | }) |
| 196 | + | return E.Errors(E.New("wrong password: ", string(clientHello.Auth)), err) |
| 197 | + | } |
| 198 | + | user := h.authUser[userIndex] |
| 199 | + | if user == "" { |
| 200 | + | user = F.ToString(userIndex) |
| 201 | + | } else { |
| 202 | + | ctx = auth.ContextWithUser(ctx, user) |
| 203 | + | } |
| 204 | + | h.logger.InfoContext(ctx, "[", user, "] inbound connection from ", conn.RemoteAddr()) |
200 | 205 | | } else { |
201 | | - | ctx = auth.ContextWithUser(ctx, user) |
| 206 | + | h.logger.InfoContext(ctx, "inbound connection from ", conn.RemoteAddr()) |
202 | 207 | | } |
203 | | - | h.logger.InfoContext(ctx, "[", user, "] inbound connection from ", conn.RemoteAddr()) |
204 | 208 | | h.logger.DebugContext(ctx, "peer send speed: ", clientHello.SendBPS/1024/1024, " MBps, peer recv speed: ", clientHello.RecvBPS/1024/1024, " MBps") |
205 | 209 | | if clientHello.SendBPS == 0 || clientHello.RecvBPS == 0 { |
206 | 210 | | return E.New("invalid rate from client") |
| skipped 129 lines |