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

This commit is contained in:
Nixevol
2026-09-30 15:00:06 +08:00
parent ac90495137
commit af8278d2a9
7 changed files with 155 additions and 13 deletions
+13
View File
@@ -67,6 +67,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 {
@@ -77,6 +81,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: