增加基于tap设备的桥接访问模式

This commit is contained in:
bjdgyc
2020-09-14 17:17:50 +08:00
parent 3b64de19b8
commit 31b1f12dbe
57 changed files with 2598 additions and 703 deletions

45
sessdata/limit_rate.go Normal file
View File

@@ -0,0 +1,45 @@
package sessdata
import (
"context"
"fmt"
"time"
"github.com/bjdgyc/anylink/common"
"golang.org/x/time/rate"
)
var Sess = &ConnSession{}
func init() {
return
tick := time.Tick(time.Second * 2)
go func() {
for range tick {
uP := common.HumanByte(float64(Sess.BandwidthUpPeriod / BandwidthPeriodSec))
dP := common.HumanByte(float64(Sess.BandwidthDownPeriod / BandwidthPeriodSec))
uA := common.HumanByte(float64(Sess.BandwidthUpAll))
dA := common.HumanByte(float64(Sess.BandwidthDownAll))
fmt.Printf("rateUp:%s rateDown:%s allUp %s allDown %s \n",
uP, dP, uA, dA)
}
}()
}
type LimitRater struct {
limit *rate.Limiter
}
// lim: 令牌产生速率
// burst: 允许的最大爆发速率
func NewLimitRater(lim, burst int) *LimitRater {
limit := rate.NewLimiter(rate.Limit(lim), burst)
return &LimitRater{limit: limit}
}
// bt 不能超过burst大小
func (l *LimitRater) Wait(bt int) error {
return l.limit.WaitN(context.Background(), bt)
}