improve: use stream reduce auth check time

This commit is contained in:
naiba
2024-11-23 12:43:02 +08:00
parent cd42b1b9d5
commit 22738b6244
10 changed files with 249 additions and 141 deletions

View File

@@ -2,6 +2,7 @@ package rpc
import (
"context"
"strings"
"sync"
petname "github.com/dustinkirkland/golang-petname"
@@ -27,13 +28,22 @@ func (a *authHandler) Check(ctx context.Context) (uint64, error) {
var clientSecret string
if value, ok := md["client_secret"]; ok {
clientSecret = value[0]
clientSecret = strings.TrimSpace(value[0])
}
if clientSecret != singleton.Conf.AgentSecretKey {
if clientSecret == "" {
return 0, status.Error(codes.Unauthenticated, "客户端认证失败")
}
ip, _ := ctx.Value(model.CtxKeyRealIP{}).(string)
if clientSecret != singleton.Conf.AgentSecretKey {
model.BlockIP(singleton.DB, ip, model.WAFBlockReasonTypeAgentAuthFail)
return 0, status.Error(codes.Unauthenticated, "客户端认证失败")
}
model.ClearIP(singleton.DB, ip)
var clientUUID string
if value, ok := md["client_uuid"]; ok {
clientUUID = value[0]