Bandwidth quotas now work on data returned from server

This commit is contained in:
Frederick F. Kautz IV
2015-04-26 15:49:46 -07:00
parent 5fe173edf1
commit 7867ee89fa
3 changed files with 40 additions and 9 deletions

View File

@@ -47,20 +47,27 @@ func (q *quotaMap) Add(ip uint32, size int64) {
func (q *quotaMap) IsQuotaMet(ip uint32) bool {
q.clean()
if q.GetQuotaUsed(ip) >= q.limit {
return true
}
return false
}
func (q *quotaMap) GetQuotaUsed(ip uint32) (total int64) {
currentMinute := time.Now().UnixNano() / q.segmentSize.Nanoseconds()
if _, ok := q.data[currentMinute]; !ok {
q.data[currentMinute] = make(map[uint32]int64)
}
var total int64
for _, segment := range q.data {
if used, ok := segment[ip]; ok {
total += used
}
}
if total >= q.limit {
return true
}
return false
return
}
func (q *quotaMap) WillExceedQuota(ip uint32, size int64) (result bool) {
return q.GetQuotaUsed(ip)+size > q.limit
}
func (q *quotaMap) clean() {