hysteria: Accept inbound configuration without users

This commit is contained in:
世界 2023-03-20 19:22:46 +08:00
parent f680d0acaf
commit fe4b429fc2
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 16 additions and 20 deletions

View file

@ -74,14 +74,10 @@ Hysteria users
#### users.auth #### users.auth
==Required if `auth_str` is empty==
Authentication password, in base64. Authentication password, in base64.
#### users.auth_str #### users.auth_str
==Required if `auth` is empty==
Authentication password. Authentication password.
#### recv_window_conn #### recv_window_conn

View file

@ -74,14 +74,10 @@ Hysteria 用户
#### users.auth #### users.auth
==与 auth_str 必填一个==
base64 编码的认证密码。 base64 编码的认证密码。
#### users.auth_str #### users.auth_str
==与 auth 必填一个==
认证密码。 认证密码。
#### recv_window_conn #### recv_window_conn

View file

@ -187,20 +187,24 @@ func (h *Hysteria) accept(ctx context.Context, conn quic.Connection) error {
if err != nil { if err != nil {
return err return err
} }
userIndex := slices.Index(h.authKey, string(clientHello.Auth)) if len(h.authKey) > 0 {
if userIndex == -1 { userIndex := slices.Index(h.authKey, string(clientHello.Auth))
err = hysteria.WriteServerHello(controlStream, hysteria.ServerHello{ if userIndex == -1 {
Message: "wrong password", err = hysteria.WriteServerHello(controlStream, hysteria.ServerHello{
}) Message: "wrong password",
return E.Errors(E.New("wrong password: ", string(clientHello.Auth)), err) })
} return E.Errors(E.New("wrong password: ", string(clientHello.Auth)), err)
user := h.authUser[userIndex] }
if user == "" { user := h.authUser[userIndex]
user = F.ToString(userIndex) if user == "" {
user = F.ToString(userIndex)
} else {
ctx = auth.ContextWithUser(ctx, user)
}
h.logger.InfoContext(ctx, "[", user, "] inbound connection from ", conn.RemoteAddr())
} else { } else {
ctx = auth.ContextWithUser(ctx, user) h.logger.InfoContext(ctx, "inbound connection from ", conn.RemoteAddr())
} }
h.logger.InfoContext(ctx, "[", user, "] inbound connection from ", conn.RemoteAddr())
h.logger.DebugContext(ctx, "peer send speed: ", clientHello.SendBPS/1024/1024, " MBps, peer recv speed: ", clientHello.RecvBPS/1024/1024, " MBps") h.logger.DebugContext(ctx, "peer send speed: ", clientHello.SendBPS/1024/1024, " MBps, peer recv speed: ", clientHello.RecvBPS/1024/1024, " MBps")
if clientHello.SendBPS == 0 || clientHello.RecvBPS == 0 { if clientHello.SendBPS == 0 || clientHello.RecvBPS == 0 {
return E.New("invalid rate from client") return E.New("invalid rate from client")