fix some miss

This commit is contained in:
yuzuki999 2023-05-17 01:12:46 +08:00
parent bc14e406c9
commit c6658c2ce1

View File

@ -9,7 +9,7 @@ type ConnLimiter struct {
ipLimit int ipLimit int
connLimit int connLimit int
count sync.Map // map[string]int count sync.Map // map[string]int
ip sync.Map // map[string]map[string]int or map[string]struct{} ip sync.Map // map[string]map[string]int
} }
func NewConnLimiter(conn int, ip int) *ConnLimiter { func NewConnLimiter(conn int, ip int) *ConnLimiter {
@ -55,10 +55,7 @@ func (c *ConnLimiter) AddConnCount(user string, ip string, isTcp bool) (limit bo
ips.Store(ip, online.(int)+2) ips.Store(ip, online.(int)+2)
} }
} else { } else {
// not online ip for tcp // not online ip
if _, ok = ips.Load(ip + "o"); ok {
return false
}
ips.Range(func(_, _ interface{}) bool { ips.Range(func(_, _ interface{}) bool {
cn++ cn++
if cn >= c.ipLimit { if cn >= c.ipLimit {
@ -105,7 +102,7 @@ func (c *ConnLimiter) DelConnCount(user string, ip string) {
notDel := false notDel := false
c.ip.Range(func(_, _ any) bool { c.ip.Range(func(_, _ any) bool {
notDel = true notDel = true
return true return false
}) })
if !notDel { if !notDel {
c.ip.Delete(user) c.ip.Delete(user)