fix: 上行分发前统一限速,send 不再单独扣桶

This commit is contained in:
Nixevol
2026-09-30 16:21:05 +08:00
parent f139b9ed9b
commit aa24e974af
7 changed files with 155 additions and 13 deletions
+13
View File
@@ -107,6 +107,10 @@ func (u *appUplink) HandleUplink(ctx context.Context, conn port.ConnInfo, payloa
u.replyErr(ctx, conn, peekRID(payload), protocol.CodeBadRequest, err.Error())
return nil
}
if !uplinkRateExempt(frame) && u.msg != nil && !u.msg.AllowRequest(conn.EndpointID) {
u.replyErr(ctx, conn, peekRID(payload), protocol.CodeRateLimited, "request rate exceeded")
return nil
}
rid, data, callErr := u.dispatch(ctx, conn, frame)
if callErr != nil {
@@ -117,6 +121,15 @@ func (u *appUplink) HandleUplink(ctx context.Context, conn port.ConnInfo, payloa
return nil
}
func uplinkRateExempt(frame any) bool {
switch frame.(type) {
case *protocol.Ack, *protocol.ReceiptAck:
return true
default:
return false
}
}
func (u *appUplink) dispatch(ctx context.Context, conn port.ConnInfo, frame any) (rid string, data any, err error) {
switch f := frame.(type) {
case *protocol.Send: